\r
import javax.swing.*;\r
import java.awt.*;\r
-import java.awt.event.ActionListener;\r
-import java.awt.event.ActionEvent;\r
-import MCview.PDBfile;\r
+import java.awt.event.*;\r
import jalview.io.EBIFetchClient;\r
-import MCview.PDBChain;\r
-import jalview.datamodel.Alignment;\r
-import jalview.io.FormatAdapter;\r
-import jalview.datamodel.SequenceI;\r
-import jalview.io.IdentifyFile;\r
-import jalview.analysis.AlignSeq;\r
+import MCview.*;\r
import jalview.datamodel.*;\r
+import jalview.analysis.AlignSeq;\r
+import java.io.File;\r
+import jalview.io.*;\r
+import java.util.*;\r
+\r
\r
public class SequenceFetcher\r
extends JPanel implements Runnable\r
{\r
JInternalFrame frame;\r
AlignFrame alignFrame;\r
+ StringBuffer result;\r
public SequenceFetcher(AlignFrame af)\r
{\r
alignFrame = af;\r
frame = new JInternalFrame();\r
frame.setContentPane(this);\r
if(System.getProperty("os.name").startsWith("Mac"))\r
- Desktop.addInternalFrame(frame, "Sequence Fetcher", 390, 135);\r
+ Desktop.addInternalFrame(frame, "Sequence Fetcher (WSDBfetch@EBI)", 390, 135);\r
else\r
- Desktop.addInternalFrame(frame, "Sequence Fetcher", 390, 120);\r
+ Desktop.addInternalFrame(frame, "Sequence Fetcher (WSDBfetch@EBI)", 390, 120);\r
}\r
\r
private void jbInit()\r
\r
public void ok_actionPerformed(ActionEvent e)\r
{\r
- frame.setTitle("WSDBfetch@EBI Sequence Fetcher - Fetching Sequence...");\r
+ frame.setTitle("Sequence Fetcher (WSDBfetch@EBI) - Fetching Sequence...");\r
database.setEnabled(false);\r
textfield.setEnabled(false);\r
ok.setEnabled(false);\r
\r
public void run()\r
{\r
- String error = null;\r
- StringBuffer result = new StringBuffer();\r
- if (database.getSelectedItem().equals("Uniprot")\r
- || database.getSelectedItem().equals("EMBL")\r
- || database.getSelectedItem().equals("EMBLCDS"))\r
+ result = new StringBuffer();\r
+ if (database.getSelectedItem().equals("Uniprot"))\r
+ {\r
+ getUniprotFile(textfield.getText());\r
+ }\r
+ else if (database.getSelectedItem().equals("EMBL")\r
+ || database.getSelectedItem().equals("EMBLCDS"))\r
+ {\r
+ EBIFetchClient dbFetch = new EBIFetchClient();\r
+ String[] reply = dbFetch.fetchData(\r
+ database.getSelectedItem().toString().toLowerCase(\r
+ ) + ":" + textfield.getText(),\r
+ "fasta", "raw");\r
+\r
+ for (int i = 0; i < reply.length; i++)\r
+ result.append(reply[i] + "\n");\r
+\r
+ parseResult(result.toString());\r
+ }\r
+ else if (database.getSelectedItem().equals("PDB"))\r
+ {\r
+ result = getPDBFile(textfield.getText().toUpperCase());\r
+ parseResult(result.toString());\r
+ }\r
+\r
+\r
+ if (result == null || result.length() == 0)\r
+ showErrorMessage("Error retrieving " + textfield.getText()\r
+ + " from " + database.getSelectedItem());\r
+\r
+\r
+ database.setEnabled(true);\r
+ textfield.setEnabled(true);\r
+ ok.setEnabled(true);\r
+ cancel.setEnabled(true);\r
+ frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)");\r
+ }\r
+\r
+ void getUniprotFile(String id)\r
+ {\r
+ EBIFetchClient ebi = new EBIFetchClient();\r
+ File file = ebi.fetchDataAsFile("uniprot:"+id,"xml", null);\r
+ SequenceFeatureFetcher sff = new SequenceFeatureFetcher();\r
+ Vector entries = sff.getUniprotEntries(file);\r
+\r
+ if(entries!=null)\r
+ {\r
+ //First, make the new sequences\r
+ Enumeration en = entries.elements();\r
+ while (en.hasMoreElements())\r
{\r
- EBIFetchClient dbFetch = new EBIFetchClient();\r
- String[] reply = dbFetch.fetchData(\r
- database.getSelectedItem().toString().toLowerCase(\r
- ) + ":" + textfield.getText(),\r
- "fasta", "raw");\r
-\r
- for (int i = 0; i < reply.length; i++)\r
- result.append(reply[i] + "\n");\r
+ UniprotEntry entry = (UniprotEntry) en.nextElement();\r
+ StringBuffer name = new StringBuffer( ">Uniprot/Swiss-Prot" );\r
+ Enumeration en2 = entry.getAccession().elements();\r
+ while(en2.hasMoreElements())\r
+ {\r
+ name.append("|");\r
+ name.append(en2.nextElement());\r
+ }\r
+ en2 = entry.getName().elements();\r
+ while(en2.hasMoreElements())\r
+ {\r
+ name.append("|");\r
+ name.append(en2.nextElement());\r
+ }\r
+\r
+ if(entry.getProteinName()!=null)\r
+ name.append(" "+entry.getProteinName().elementAt(0));\r
+\r
+ result.append(name +"\n"+entry.getUniprotSequence().getContent());\r
+\r
}\r
- else if (database.getSelectedItem().equals("PDB"))\r
+\r
+ //Then read in the features and apply them to the dataset\r
+ SequenceI [] sequence = parseResult(result.toString());\r
+ for(int i=0; i<entries.size(); i++)\r
{\r
- String id = textfield.getText().toUpperCase();\r
- String chain=null;\r
- if(id.indexOf(":")>-1)\r
+ UniprotEntry entry = (UniprotEntry) entries.elementAt(i);\r
+ Enumeration e = entry.getDbReference().elements();\r
+ Vector onlyPdbEntries = new Vector();\r
+ while (e.hasMoreElements())\r
{\r
- chain = id.substring(id.indexOf(":")+1);\r
- id = id.substring(0,id.indexOf(":"));\r
- System.out.println(id+" "+chain);\r
+ PDBEntry pdb = (PDBEntry) e.nextElement();\r
+ if (!pdb.getType().equals("PDB"))\r
+ continue;\r
+\r
+ onlyPdbEntries.addElement(pdb);\r
}\r
\r
- EBIFetchClient ebi = new EBIFetchClient();\r
- String[] reply = ebi.fetchData("pdb:" + id, "pdb",\r
- "raw");\r
- try{\r
- PDBfile pdbfile = new PDBfile(reply);\r
- for (int i = 0; i < pdbfile.chains.size(); i++)\r
- {\r
- if( chain == null || ((PDBChain)pdbfile.chains.elementAt(i)).id.toUpperCase().equals(chain))\r
- result.append("\n>PDB|" + id+"|"+\r
+ sequence[i].getDatasetSequence().setPDBId(onlyPdbEntries);\r
+ sequence[i].getDatasetSequence().setSequenceFeatures(entry.getFeature());\r
+\r
+ }\r
+ }\r
+ }\r
+\r
+ StringBuffer getPDBFile(String id)\r
+ {\r
+ StringBuffer result = new StringBuffer();\r
+ String chain = null;\r
+ if (id.indexOf(":") > -1)\r
+ {\r
+ chain = id.substring(id.indexOf(":") + 1);\r
+ id = id.substring(0, id.indexOf(":"));\r
+ }\r
+\r
+ EBIFetchClient ebi = new EBIFetchClient();\r
+ String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw");\r
+ try\r
+ {\r
+ PDBfile pdbfile = new PDBfile(reply);\r
+ for (int i = 0; i < pdbfile.chains.size(); i++)\r
+ {\r
+ if (chain == null ||\r
+ ( (PDBChain) pdbfile.chains.elementAt(i)).id.\r
+ toUpperCase().equals(chain))\r
+ result.append("\n>PDB|" + id + "|" +\r
( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
getName() +\r
"\n"\r
+\r
( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
getSequence());\r
- }\r
- }catch(Exception ex)// Problem parsing PDB file\r
- {\r
- error = "Error retrieving "+textfield.getText()+" from "+database.getSelectedItem();\r
}\r
}\r
+ catch (Exception ex) // Problem parsing PDB file\r
+ {\r
+ showErrorMessage("Error retrieving " + textfield.getText() + " from " +\r
+ database.getSelectedItem());\r
+ return null;\r
+ }\r
\r
- if (result.length() > 0 && error==null)\r
+ return result;\r
+ }\r
+\r
+ SequenceI[] parseResult(String result)\r
{\r
- String format = IdentifyFile.Identify(result.toString(), "Paste");\r
+ String format = IdentifyFile.Identify(result, "Paste");\r
SequenceI[] sequences = null;\r
\r
if (FormatAdapter.formats.contains(format))\r
{\r
AlignFrame af = new AlignFrame(new Alignment(sequences));\r
af.currentFileFormat = format;\r
- Desktop.addInternalFrame(af, "Cut & Paste input - " + format,\r
+ Desktop.addInternalFrame(af, "Retrieved from "+database.getSelectedItem(),\r
AlignFrame.NEW_WINDOW_WIDTH,\r
AlignFrame.NEW_WINDOW_HEIGHT);\r
af.statusBar.setText("Successfully pasted alignment file");\r
getHeight());\r
alignFrame.viewport.alignment.getWidth();\r
alignFrame.viewport.firePropertyChange("alignment", null,\r
- alignFrame.viewport.getAlignment().getSequences());\r
+ alignFrame.viewport.getAlignment().getSequences());\r
\r
}\r
\r
\r
}\r
else\r
- error = "Error retrieving "+textfield.getText()+" from "+database.getSelectedItem();\r
-\r
-\r
-\r
+ showErrorMessage( "Error retrieving "+textfield.getText()\r
+ +" from "+database.getSelectedItem());\r
}\r
- }\r
\r
- if(error!=null)\r
- showErrorMessage(error);\r
+ return sequences;\r
\r
- database.setEnabled(true);\r
- textfield.setEnabled(true);\r
- ok.setEnabled(true);\r
- cancel.setEnabled(true);\r
- frame.setTitle("WSDBfetch@EBI Sequence Fetcher");\r
}\r
\r
void showErrorMessage(String error)\r