1 package jalview.ws.ebi;
4 import java.util.regex.Matcher;
6 import org.apache.axis.transport.http.HTTPConstants;
7 import org.apache.http.Header;
8 import org.apache.http.HttpResponse;
9 import org.apache.http.client.methods.HttpGet;
10 import org.apache.http.client.methods.HttpPost;
11 import org.apache.http.entity.StringEntity;
12 import org.apache.http.impl.client.DefaultHttpClient;
13 import org.apache.http.util.EntityUtils;
14 import org.json.JSONArray;
15 import org.json.JSONObject;
17 import compbio.util.FileUtil;
19 public class hmmerClient
24 static String baseUrl = "http://www.ebi.ac.uk/Tools/hmmer",
25 jackH = "/search/jackhmmer", phmmer = "/search/phmmer",
26 hmmscan = "/search/hmmscan", hmmsearch = "/search/hmmsearch";
28 static String edseq = ">2abl_A mol:protein length:163 ABL TYROSINE KINASE\nMGPSENDPNLFVALYDFVASGDNTLSITKGEKLRVLGYNHNGEWCEAQTKNGQGWVPSNYITPVNSLEKHS\nWYHGPVSRNAAEYLLSSGINGSFLVRESESSPGQRSISLRYEGRVYHYRINTASDGKLYVSSESRFNTLAE\nLVHHHSTVADGLITTLHYPAP";
30 public static void main(String[] args)
37 instr = FileUtil.readFileToString(new File(args[0]));
44 String res = new hmmerClient().submitJackhmmerSearch(instr,
45 "jackhmmer", "pdb", 5);
48 throw new Error("Failed.");
50 System.out.println("Result\n" + res);
56 * - fasta or other formatted sequence or alignment
60 * - pdb, uniprot, etc.
62 * number of iterations
65 String submitJackhmmerSearch(String input, String algo, String db,
68 JSONObject inparam = new JSONObject();
69 HttpPost jackhp = new HttpPost(baseUrl + jackH);
70 String lastiter = null;
73 inparam.put("algo", algo);
74 inparam.put("seq", input);
75 inparam.put("seqdb", db);
76 inparam.put("iterations", niter);
77 // #Now POST the request and generate the search job.
78 // dumb json post service
79 jackhp.setHeader("content-type", "application/json");
80 jackhp.setEntity(new StringEntity(inparam.toString()));
86 HttpResponse r = null;
89 DefaultHttpClient httpCl = new DefaultHttpClient();
91 r = httpCl.execute(jackhp);
95 System.err.println("Submit failed.");
98 if (r.getStatusLine().getStatusCode() != 201)
100 throw new Error(r.toString());
103 String jobid = null, redir = null;
106 JSONObject res = new JSONObject(EntityUtils.toString(r.getEntity()));
107 jobid = res.getString("job_id");
110 if ((loc = r.getHeaders(HTTPConstants.HEADER_LOCATION)) != null
116 .println("Ignoring additional "
118 + " location(s) provided in response header ( next one is '"
119 + loc[1].getValue() + "' )");
121 redir = loc[0].getValue();
123 } catch (Exception x)
125 System.err.println("job id extraction failed.");
129 boolean finished = false;
130 JSONObject jobstate = null;
135 DefaultHttpClient httpCl = new DefaultHttpClient();
137 HttpGet jackcheck = new HttpGet(redir);
138 jackcheck.setHeader("content-type", "application/json");
139 r = httpCl.execute(jackcheck);
140 switch (r.getStatusLine().getStatusCode())
143 jobstate = new JSONObject(EntityUtils.toString(r.getEntity()));
144 String st = jobstate.getString("status");
145 if ("DONE".equals(st))
149 if ("ERROR".equals(st))
151 System.err.println("Error");
154 if ("PEND".equals(st) || "RUN".equals("st"))
156 JSONArray iters = jobstate.getJSONArray("result");
157 lastiter = iters.getJSONObject(iters.length() - 1)
159 if (lastiter.length() > 0)
161 java.util.regex.Pattern p = java.util.regex.Pattern
162 .compile(".+(\\d+)");
163 Matcher m = p.matcher(lastiter);
166 System.out.println("On iteration " + m.group(1));
176 } catch (Exception q)
181 } while (!finished && tries < 50);
185 System.err.println("Giving up with job " + jobid + " at " + redir);
189 // http://www.ebi.ac.uk/Tools/hmmer/download/60048B38-7CEC-11E5-A230-CED6D26C98AD.5/score?format=csv
190 // 1gri_A 1gri_A 217 jackhmmer - 163 4.7e-62 212.4 0.1 1 2 4.4e-46 2.1e-43
191 // 151.758316040039 0.04 11 151 3 139 1 150 0.94 GROWTH FACTOR BOUND PROTEIN
193 // 1gri_A 1gri_A 217 jackhmmer - 163 4.7e-62 212.4 0.1 2 2 1.6e-17 7.9e-15
194 // 58.8796501159668 0.01 7 66 157 215 153 216 0.95 GROWTH FACTOR BOUND
195 // PROTEIN 2 1cj1_J 1gri_B
196 // 4h1o_A 4h1o_A 560 jackhmmer - 163 2.1e-57 197.3 0.0 1 2 7.5e-28 3.6e-25
197 // 92.4921493530273 0.00 65 161 20 122 17 124 0.95 Tyrosine-protein
198 // phosphatase non-receptor typ 4h1o_A
200 // 4h1o_A 4h1o_A 560 jackhmmer - 163 2.1e-57 197.3 0.0 2 2 7.6e-31 3.7e-28
201 // 102.219146728516 0.03 66 161 127 236 124 238 0.94 Tyrosine-protein
202 // phosphatase non-receptor typ 4h1o_A
204 // $ua->get( $rootUrl."/results/".$lastIteration->{uuid} . "/score"
207 * * #Job should have finished, but we may have converged, so get the last
208 * job. my $results = $json->decode( $response->content ); my $lastIteration
209 * = pop( @{ $results->{result} } ); #Now fetch the results of the last
210 * iteration my $searchResult = $ua->get( $rootUrl."/results/" .
211 * $lastIteration->{uuid} . "/score", 'Accept' => 'application/json' );
212 * unless( $searchResult->status_line eq "200 OK"){ die
213 * "Failed to get search results\n"; }
215 * #Decode the content of the full set of results $results = $json->decode(
216 * $searchResult->content ); print
217 * "Matched ".$results->{'results'}->{'stats'}->{'nincluded'}." sequences
218 * ($lastIteration->{uuid})!\n"; #Now do something more interesting with the