2 package org.forester.ws.hmmer;
4 import java.io.BufferedReader;
5 import java.io.DataOutputStream;
6 import java.io.InputStreamReader;
7 import java.net.HttpURLConnection;
9 import java.net.URLEncoder;
13 public static void main( final String[] args ) {
15 final URL url = new URL( "http://hmmer.janelia.org/search/hmmscan" );
16 final HttpURLConnection connection = ( HttpURLConnection ) url.openConnection();
17 connection.setDoOutput( true );
18 connection.setDoInput( true );
19 connection.setInstanceFollowRedirects( false );
20 connection.setRequestMethod( "POST" );
21 connection.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
22 connection.setRequestProperty( "Accept", "application/json" );
23 //Add the database and the sequence. Add more options as you wish!
24 final String urlParameters = "hmmdb=" + URLEncoder.encode( "pfam", "UTF-8" ) + "&seq="
25 + ">seq\nEMGPSENDPNLFVALYDFVASGDNTLSITKGEKLRVLGYNHNGEWCEAQTKNGQGWVPSNYITPV"
26 + "NSLEKHSWYHGPVSRNAAEYLLSSGINGSFLVRESESSPGQRSISLRYEG"
27 + "RVYHYRINTASDGKLYVSSESRFNTLAELVHHHSTVADGLITTLHYPAP";
28 connection.setRequestProperty( "Content-Length", "" + Integer.toString( urlParameters.getBytes().length ) );
30 final DataOutputStream wr = new DataOutputStream( connection.getOutputStream() );
31 wr.writeBytes( urlParameters );
34 //Now get the redirect URL
35 final URL respUrl = new URL( connection.getHeaderField( "Location" ) );
36 final HttpURLConnection connection2 = ( HttpURLConnection ) respUrl.openConnection();
37 connection2.setRequestMethod( "GET" );
38 connection2.setRequestProperty( "Accept", "text/x-yaml" );
39 //Get the response and print it to the screen
40 final BufferedReader in = new BufferedReader( new InputStreamReader( connection2.getInputStream() ) );
42 while ( ( inputLine = in.readLine() ) != null ) {
43 System.out.println( inputLine );
47 catch ( final Exception e ) {
48 throw new RuntimeException( e );