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