Skip to content
Snippets Groups Projects
Commit 98a4c2a1 authored by tjc's avatar tjc
Browse files

run pfam search option

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@10796 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 4cce70d3
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/RunMenu.java,v 1.12 2008-09-11 10:51:53 tjc Exp $ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/RunMenu.java,v 1.13 2009-05-13 15:53:14 tjc Exp $
**/ **/
package uk.ac.sanger.artemis.components; package uk.ac.sanger.artemis.components;
...@@ -45,7 +45,7 @@ import javax.swing.JOptionPane; ...@@ -45,7 +45,7 @@ import javax.swing.JOptionPane;
* A JMenu of external commands/functions. * A JMenu of external commands/functions.
* *
* @author Kim Rutherford * @author Kim Rutherford
* @version $Id: RunMenu.java,v 1.12 2008-09-11 10:51:53 tjc Exp $ * @version $Id: RunMenu.java,v 1.13 2009-05-13 15:53:14 tjc Exp $
**/ **/
public class RunMenu extends SelectionMenu public class RunMenu extends SelectionMenu
...@@ -71,7 +71,7 @@ public class RunMenu extends SelectionMenu ...@@ -71,7 +71,7 @@ public class RunMenu extends SelectionMenu
super(frame, menu_name, selection); super(frame, menu_name, selection);
addNCBISearches(selection); addNCBISearches(selection);
addPfamSearches(selection);
if(Options.isUnixHost()) if(Options.isUnixHost())
{ {
final ExternalProgramVector external_programs = Options.getOptions() final ExternalProgramVector external_programs = Options.getOptions()
...@@ -103,6 +103,31 @@ public class RunMenu extends SelectionMenu ...@@ -103,6 +103,31 @@ public class RunMenu extends SelectionMenu
this(frame, selection, "Run"); this(frame, selection, "Run");
} }
private void addPfamSearches(final Selection selection)
{
final JMenuItem ncbiSearchLinks = new JMenuItem("Pfam Search");
add(ncbiSearchLinks);
ncbiSearchLinks.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
final FeatureVector features = selection.getAllFeatures();
if(features.size() != 1)
{
JOptionPane.showMessageDialog(RunMenu.this,
"Selected a single feature to send to NCBI for searching.",
"NCBI Search", JOptionPane.INFORMATION_MESSAGE);
return;
}
final String residues = features.elementAt(0).getTranslation().toString().toUpperCase();
RunPfamSearchThread pfamSearch = new RunPfamSearchThread(residues);
pfamSearch.start();
}
});
}
/** /**
* Add menu for NCBI web searches * Add menu for NCBI web searches
* @param selection * @param selection
......
/* 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 javax.swing.JOptionPane;
import uk.ac.sanger.artemis.editor.BrowserControl;
public class RunPfamSearchThread extends Thread
{
private static String pfamUrl = "http://pfam.sanger.ac.uk/search/sequence";
private String residues;
public RunPfamSearchThread(final String residues)
{
this.residues = residues;
}
public void run()
{
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 = pfamUrl+"/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);
}
else if((index = line.indexOf("<error>")) > -1)
{
line = line.substring(index+7);
index = line.indexOf("<");
if(index > -1)
line = line.substring(0, index);
JOptionPane.showMessageDialog(null,
line, "Pfam search error", JOptionPane.INFORMATION_MESSAGE);
return;
}
}
wr.close();
rd.close();
int waitTime = Integer.parseInt(eta);
ProgressBarFrame progress = new ProgressBarFrame(waitTime, "Pfam");
URL result = new URL(urlResults);
Thread.sleep(waitTime*1000);
int cnt = 0;
while(((HttpURLConnection) result.openConnection()).getResponseCode() == 204 &&
cnt < 500)
{
cnt++;
Thread.sleep(500);
}
BrowserControl.displayURL(urlResults);
progress.dispose();
}
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