Skip to content

Commit e0f5c73

Browse files
committed
Merge pull request #402 from abradle/master
Added class to find weekly update information from FTP site
2 parents 40a1e8f + 7abdf88 commit e0f5c73

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.biojava.nbio.structure.rcsb;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.net.MalformedURLException;
7+
import java.net.URL;
8+
import java.net.URLConnection;
9+
import java.util.ArrayList;
10+
import java.util.HashMap;
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
public class RCSBUpdates {
15+
16+
/**
17+
*
18+
* @return A map mapping each field (defined by a seperate FTP page and defined in newStringList to the PDB ids in this field
19+
* @throws IOException
20+
*/
21+
public Map<String,String[]> getUpdates() throws IOException{
22+
// The URL for acquiring the data
23+
String baseURL = "ftp://ftp.rcsb.org/pub/pdb/data/status/latest/";
24+
Map<String,String[]> outMap = new HashMap<String, String[]>();
25+
// A list of files to get
26+
String[] newStringList = {"added.models","added.nmr","added.pdb","added.sf","modified.cs","modified.models",
27+
"modified.nmr","modified.pdb","modified.sf","obsolete.cs","obsolete.models","obsolete.nmr","obsolete.pdb","obsolete.sf"};
28+
for(String fileName: newStringList){
29+
String[] thisList = readURL(baseURL+""+fileName);
30+
outMap.put(fileName, thisList);
31+
}
32+
return outMap;
33+
34+
}
35+
36+
37+
/**
38+
*
39+
* @param urlIn The url to be read
40+
* @return A list of PDB ids as strings
41+
* @throws IOException
42+
*/
43+
private String[] readURL(String urlIn) throws IOException{
44+
List<String> outList = new ArrayList<String>();
45+
// create a url object
46+
URL url = new URL(urlIn);
47+
48+
// create a urlconnection object
49+
URLConnection urlConnection = url.openConnection();
50+
51+
// wrap the urlconnection in a bufferedreader
52+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
53+
54+
String line;
55+
56+
// read from the urlconnection via the bufferedreader
57+
while ((line = bufferedReader.readLine()) != null)
58+
{
59+
outList.add(line);
60+
}
61+
bufferedReader.close();
62+
63+
return outList.toArray(new String[0]);
64+
}
65+
}

0 commit comments

Comments
 (0)