Skip to content

Commit eee49af

Browse files
committed
Bugfix: header was wrongly specified. Better error handling
1 parent 2888f8f commit eee49af

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

biojava-ws/src/main/java/org/biojava/nbio/ws/hmmer/RemoteHmmerScan.java

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import net.sf.json.JSONArray;
2424
import net.sf.json.JSONObject;
2525
import org.biojava.nbio.core.sequence.ProteinSequence;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
2628

2729
import java.io.*;
2830
import java.net.HttpURLConnection;
@@ -31,14 +33,17 @@
3133
import java.util.TreeSet;
3234

3335

34-
/** Makes remote calls to the HMMER web service at the EBI web site and returns Pfam domain annotations for an input protein sequence.
36+
/**
37+
* Makes remote calls to the HMMER web service at the EBI web site and returns Pfam domain annotations for an input protein sequence.
3538
*
3639
* @author Andreas Prlic
3740
* @since 3.0.3
3841
*/
3942
public class RemoteHmmerScan implements HmmerScan {
4043

41-
public static String HMMER_SERVICE = "http://www.ebi.ac.uk/Tools/hmmer/search/hmmscan";
44+
private static final Logger LOGGER = LoggerFactory.getLogger(RemoteHmmerScan.class);
45+
46+
public static final String HMMER_SERVICE = "http://www.ebi.ac.uk/Tools/hmmer/search/hmmscan";
4247

4348
public RemoteHmmerScan(){
4449

@@ -54,7 +59,8 @@ public SortedSet<HmmerResult> scan(ProteinSequence sequence) throws IOException
5459

5560
}
5661

57-
/** Scans a protein sequence for Pfam profile matches.
62+
/**
63+
* Scans a protein sequence for Pfam profile matches.
5864
*
5965
* @param sequence
6066
* @param serviceLocation
@@ -68,7 +74,7 @@ public SortedSet<HmmerResult> scan(ProteinSequence sequence, URL serviceLocation
6874
postContent.append("hmmdb=pfam");
6975

7076

71-
// by default hmmscan runs with the HMMER3 cut_ga parameter enabled, the "gathering freshold", which depends on
77+
// by default hmmscan runs with the HMMER3 cut_ga parameter enabled, the "gathering threshold", which depends on
7278
// the cutoffs defined in the underlying HMM files.
7379
// to request a different cutoff by e-value this could be enabled:
7480
//postContent.append("&E=1");
@@ -86,7 +92,7 @@ public SortedSet<HmmerResult> scan(ProteinSequence sequence, URL serviceLocation
8692
connection.setRequestMethod("POST");
8793
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
8894

89-
connection.setRequestProperty("Accept:","application/json");
95+
connection.setRequestProperty("Accept","application/json");
9096

9197
connection.setRequestProperty("Content-Length", "" +
9298
Integer.toString(postContent.toString().getBytes().length));
@@ -99,13 +105,12 @@ public SortedSet<HmmerResult> scan(ProteinSequence sequence, URL serviceLocation
99105
wr.close ();
100106

101107

102-
// //Now get the redirect URL
108+
//Now get the redirect URL
103109
URL respUrl = new URL( connection.getHeaderField( "Location" ));
104110

105111
int responseCode = connection.getResponseCode();
106112
if ( responseCode == 500){
107-
System.err.println("something went wrong!" + serviceLocation);
108-
System.err.println(connection.getResponseMessage());
113+
LOGGER.warn("Got 500 response code for URL {}. Response message: {}.", serviceLocation, connection.getResponseMessage());
109114
}
110115

111116
HttpURLConnection connection2 = (HttpURLConnection) respUrl.openConnection();
@@ -122,7 +127,6 @@ public SortedSet<HmmerResult> scan(ProteinSequence sequence, URL serviceLocation
122127

123128
StringBuffer result = new StringBuffer();
124129
while ((inputLine = in.readLine()) != null) {
125-
//System.out.println(inputLine);
126130
result.append(inputLine);
127131
}
128132

@@ -141,7 +145,6 @@ public SortedSet<HmmerResult> scan(ProteinSequence sequence, URL serviceLocation
141145

142146
for(int i =0 ; i < hits.size() ; i++){
143147
JSONObject hit = hits.getJSONObject(i);
144-
//System.out.println("hit: "+ hit);
145148

146149
HmmerResult hmmResult = new HmmerResult();
147150

@@ -170,35 +173,21 @@ public SortedSet<HmmerResult> scan(ProteinSequence sequence, URL serviceLocation
170173
SortedSet<HmmerDomain> domains = new TreeSet<HmmerDomain>();
171174
for ( int j= 0 ; j < hmmdomains.size() ; j++){
172175
JSONObject d = hmmdomains.getJSONObject(j);
173-
//System.out.println(d);
174176
Integer is_included = getInteger(d.get("is_included"));
175177
if ( is_included == 0) {
176-
// System.out.println(" excluding: " + d.get("alihmmdesc") + " " + d.get("alihmmname") + " " +
177-
// hit.get("evalue") + " " +
178-
// d.get("alisqfrom") + " " +
179-
// d.get("alisqto"));
180178
continue;
181179
}
182180

183181

184182
// this filters out multiple hits to the same clan
185183
Integer outcompeted = getInteger(d.get("outcompeted"));
186184
if ( outcompeted != null && outcompeted == 1) {
187-
// System.out.println(" outcompeted: " + d.get("alihmmdesc") + " " + d.get("alihmmname")+ " " +
188-
// hit.get("evalue") + " " +
189-
// d.get("alisqfrom") + " " +
190-
// d.get("alisqto")
191-
// );
192185
continue;
193186
}
194187

195188
Integer significant = getInteger(d.get("significant"));
196189

197190
if ( significant != 1) {
198-
// System.out.println(" not significant: " + d.get("alihmmdesc") + " " + d.get("alihmmname")+ " " +
199-
// hit.get("evalue") + " " +
200-
// d.get("alisqfrom") + " " +
201-
// d.get("alisqto"));
202191
continue;
203192
}
204193

@@ -224,8 +213,8 @@ public SortedSet<HmmerResult> scan(ProteinSequence sequence, URL serviceLocation
224213

225214
results.add(hmmResult);
226215
}
227-
} catch (Exception e){
228-
e.printStackTrace();
216+
} catch (NumberFormatException e){
217+
LOGGER.warn("Could not parse number in Hmmer web service json response: {}", e.getMessage());
229218
}
230219

231220
return results;

0 commit comments

Comments
 (0)