Skip to content

Commit 03929c6

Browse files
authored
Merge pull request #799 from josemduarte/issue784
Switch last ftp link to http
2 parents 5d11f63 + de9652b commit 03929c6

1 file changed

Lines changed: 34 additions & 40 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/utils/BlastClustReader.java

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
package org.biojava.nbio.structure.symmetry.utils;
2222

23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
2326
import java.io.BufferedReader;
2427
import java.io.IOException;
2528
import java.io.InputStream;
@@ -33,10 +36,14 @@ public class BlastClustReader implements Serializable {
3336

3437
private static final long serialVersionUID = 1L;
3538

39+
private static final Logger logger = LoggerFactory.getLogger(BlastClustReader.class);
40+
3641
private int sequenceIdentity = 0;
37-
private List<List<String>> clusters = new ArrayList<List<String>>();
38-
private static final String coreUrl = "ftp://resources.rcsb.org/sequence/clusters/";
39-
private static List<Integer> seqIdentities = Arrays.asList(30, 40, 50, 70, 90, 95, 100);
42+
private List<List<String>> clusters = new ArrayList<>();
43+
// https://cdn.rcsb.org/resources/sequence/clusters/bc-95.out
44+
private static final String coreUrl = "https://cdn.rcsb.org/resources/sequence/clusters/";
45+
46+
private static final List<Integer> seqIdentities = Arrays.asList(30, 40, 50, 70, 90, 95, 100);
4047

4148
public BlastClustReader(int sequenceIdentity) {
4249
this.sequenceIdentity = sequenceIdentity;
@@ -51,7 +58,7 @@ public Map<String,String> getRepresentatives(String pdbId) {
5158
loadClusters(sequenceIdentity);
5259
String pdbIdUc = pdbId.toUpperCase();
5360

54-
Map<String,String> representatives = new LinkedHashMap<String,String>();
61+
Map<String,String> representatives = new LinkedHashMap<>();
5562
for (List<String> cluster: clusters) {
5663
// map fist match to representative
5764
for (String chainId: cluster) {
@@ -138,48 +145,35 @@ private void loadClusters(int sequenceIdentity) {
138145
}
139146

140147
if (!seqIdentities.contains(sequenceIdentity)) {
141-
System.err.println("Error: representative chains are not available for %sequence identity: "
142-
+ sequenceIdentity);
148+
logger.error("Representative chains are not available for %sequence identity: {}", sequenceIdentity);
143149
return;
144150
}
145151

152+
String urlString = coreUrl + "bc-" + sequenceIdentity + ".out";
153+
146154
try {
147-
URL u = new URL(coreUrl + "bc-" + sequenceIdentity + ".out");
148-
InputStream stream = u.openStream();
149-
// URLConnection connection = u.openConnection();
150-
// connection.setConnectTimeout(60000);
151-
// InputStream stream = connection.getInputStream();
152-
153-
if (stream != null) {
154-
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
155-
156-
String line = null;
157-
try {
158-
while ((line = reader.readLine()) != null) {
159-
line = line.replaceAll("_", ".");
160-
List<String> cluster = Arrays.asList(line.split(" "));
161-
clusters.add(cluster);
162-
}
163-
reader.close();
164-
stream.close();
165-
} catch (IOException e) {
166-
//e.printStackTrace();
167-
} finally {
168-
// try {
169-
// System.out.println("closing reader");
170-
// reader.close();
171-
// stream.close();
172-
// } catch (IOException e) {
173-
// e.printStackTrace();
174-
// }
175-
}
176-
}
177155

178-
} catch (Exception e) {
179-
e.printStackTrace();
180-
}
156+
URL u = new URL(urlString);
157+
InputStream stream = u.openStream();
158+
159+
if (stream != null) {
160+
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
161+
162+
String line = null;
163+
while ((line = reader.readLine()) != null) {
164+
line = line.replaceAll("_", ".");
165+
List<String> cluster = Arrays.asList(line.split(" "));
166+
clusters.add(cluster);
167+
}
168+
reader.close();
169+
stream.close();
170+
} else {
171+
throw new IOException("Got null stream for URL " + urlString);
172+
}
173+
} catch (IOException e) {
174+
logger.error("Could not get sequence clusters from URL " + urlString + ". Error: " + e.getMessage());
175+
}
181176

182-
return;
183177
}
184178

185179
}

0 commit comments

Comments
 (0)