Skip to content
Snippets Groups Projects
Commit 6800b9ae authored by tjc's avatar tjc
Browse files

rename

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@10797 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 98a4c2a1
No related branches found
No related tags found
No related merge requests found
/* RunPfamSearch.java
*
* created: 2009
*
* This file is part of Artemis
*
* Copyright(C) 2009 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or(at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
**/
package uk.ac.sanger.artemis.components;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import uk.ac.sanger.artemis.editor.BrowserControl;
public class RunPfamSearch
{
private static String pfamUrl = "http://pfam.sanger.ac.uk/search/sequence";
public RunPfamSearch(final String residues)
{
postData(residues);
}
public void postData(final String residues)
{
try
{
// Construct data
String data = URLEncoder.encode("seq", "UTF-8") + "="
+ URLEncoder.encode(residues, "UTF-8");
data += "&" + URLEncoder.encode("output", "UTF-8") + "="
+ URLEncoder.encode("xml", "UTF-8");
// Send data
URL url = new URL(pfamUrl);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String urlResults = "http://pfam.sanger.ac.uk/search/sequence/results?";
String line;
String eta = "10";
while ((line = rd.readLine()) != null)
{
int index;
if((index = line.indexOf("jobId=")) > -1)
{
urlResults = urlResults.concat(line.substring(index));
}
else if((index = line.indexOf("<estimated_time>")) > -1)
{
eta = line.substring(index+16);
index = eta.indexOf("<");
if(index > -1)
eta = eta.substring(0, index);
}
}
wr.close();
rd.close();
URL result = new URL(urlResults);
Thread.sleep(Integer.parseInt(eta)*1000);
while(((HttpURLConnection) result.openConnection()).getResponseCode() == 204)
Thread.sleep(1000);
BrowserControl.displayURL(urlResults);
}
catch (Exception e)
{
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment