From 75d17bc3d8444203906499e651df6a69f6c2f518 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 29 Nov 2005 18:00:30 +0000 Subject: [PATCH] Uniprot retrieves features from XML --- src/jalview/gui/SequenceFetcher.java | 199 +++++++++++++++++++++++----------- 1 file changed, 138 insertions(+), 61 deletions(-) diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index b0476ce..36f9a40 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -2,23 +2,22 @@ package jalview.gui; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import MCview.PDBfile; +import java.awt.event.*; import jalview.io.EBIFetchClient; -import MCview.PDBChain; -import jalview.datamodel.Alignment; -import jalview.io.FormatAdapter; -import jalview.datamodel.SequenceI; -import jalview.io.IdentifyFile; -import jalview.analysis.AlignSeq; +import MCview.*; import jalview.datamodel.*; +import jalview.analysis.AlignSeq; +import java.io.File; +import jalview.io.*; +import java.util.*; + public class SequenceFetcher extends JPanel implements Runnable { JInternalFrame frame; AlignFrame alignFrame; + StringBuffer result; public SequenceFetcher(AlignFrame af) { alignFrame = af; @@ -40,9 +39,9 @@ public class SequenceFetcher frame = new JInternalFrame(); frame.setContentPane(this); if(System.getProperty("os.name").startsWith("Mac")) - Desktop.addInternalFrame(frame, "Sequence Fetcher", 390, 135); + Desktop.addInternalFrame(frame, "Sequence Fetcher (WSDBfetch@EBI)", 390, 135); else - Desktop.addInternalFrame(frame, "Sequence Fetcher", 390, 120); + Desktop.addInternalFrame(frame, "Sequence Fetcher (WSDBfetch@EBI)", 390, 120); } private void jbInit() @@ -116,7 +115,7 @@ public class SequenceFetcher public void ok_actionPerformed(ActionEvent e) { - frame.setTitle("WSDBfetch@EBI Sequence Fetcher - Fetching Sequence..."); + frame.setTitle("Sequence Fetcher (WSDBfetch@EBI) - Fetching Sequence..."); database.setEnabled(false); textfield.setEnabled(false); ok.setEnabled(false); @@ -128,57 +127,144 @@ public class SequenceFetcher public void run() { - String error = null; - StringBuffer result = new StringBuffer(); - if (database.getSelectedItem().equals("Uniprot") - || database.getSelectedItem().equals("EMBL") - || database.getSelectedItem().equals("EMBLCDS")) + result = new StringBuffer(); + if (database.getSelectedItem().equals("Uniprot")) + { + getUniprotFile(textfield.getText()); + } + else if (database.getSelectedItem().equals("EMBL") + || database.getSelectedItem().equals("EMBLCDS")) + { + EBIFetchClient dbFetch = new EBIFetchClient(); + String[] reply = dbFetch.fetchData( + database.getSelectedItem().toString().toLowerCase( + ) + ":" + textfield.getText(), + "fasta", "raw"); + + for (int i = 0; i < reply.length; i++) + result.append(reply[i] + "\n"); + + parseResult(result.toString()); + } + else if (database.getSelectedItem().equals("PDB")) + { + result = getPDBFile(textfield.getText().toUpperCase()); + parseResult(result.toString()); + } + + + if (result == null || result.length() == 0) + showErrorMessage("Error retrieving " + textfield.getText() + + " from " + database.getSelectedItem()); + + + database.setEnabled(true); + textfield.setEnabled(true); + ok.setEnabled(true); + cancel.setEnabled(true); + frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)"); + } + + void getUniprotFile(String id) + { + EBIFetchClient ebi = new EBIFetchClient(); + File file = ebi.fetchDataAsFile("uniprot:"+id,"xml", null); + SequenceFeatureFetcher sff = new SequenceFeatureFetcher(); + Vector entries = sff.getUniprotEntries(file); + + if(entries!=null) + { + //First, make the new sequences + Enumeration en = entries.elements(); + while (en.hasMoreElements()) { - EBIFetchClient dbFetch = new EBIFetchClient(); - String[] reply = dbFetch.fetchData( - database.getSelectedItem().toString().toLowerCase( - ) + ":" + textfield.getText(), - "fasta", "raw"); - - for (int i = 0; i < reply.length; i++) - result.append(reply[i] + "\n"); + UniprotEntry entry = (UniprotEntry) en.nextElement(); + StringBuffer name = new StringBuffer( ">Uniprot/Swiss-Prot" ); + Enumeration en2 = entry.getAccession().elements(); + while(en2.hasMoreElements()) + { + name.append("|"); + name.append(en2.nextElement()); + } + en2 = entry.getName().elements(); + while(en2.hasMoreElements()) + { + name.append("|"); + name.append(en2.nextElement()); + } + + if(entry.getProteinName()!=null) + name.append(" "+entry.getProteinName().elementAt(0)); + + result.append(name +"\n"+entry.getUniprotSequence().getContent()); + } - else if (database.getSelectedItem().equals("PDB")) + + //Then read in the features and apply them to the dataset + SequenceI [] sequence = parseResult(result.toString()); + for(int i=0; i-1) + UniprotEntry entry = (UniprotEntry) entries.elementAt(i); + Enumeration e = entry.getDbReference().elements(); + Vector onlyPdbEntries = new Vector(); + while (e.hasMoreElements()) { - chain = id.substring(id.indexOf(":")+1); - id = id.substring(0,id.indexOf(":")); - System.out.println(id+" "+chain); + PDBEntry pdb = (PDBEntry) e.nextElement(); + if (!pdb.getType().equals("PDB")) + continue; + + onlyPdbEntries.addElement(pdb); } - EBIFetchClient ebi = new EBIFetchClient(); - String[] reply = ebi.fetchData("pdb:" + id, "pdb", - "raw"); - try{ - PDBfile pdbfile = new PDBfile(reply); - for (int i = 0; i < pdbfile.chains.size(); i++) - { - if( chain == null || ((PDBChain)pdbfile.chains.elementAt(i)).id.toUpperCase().equals(chain)) - result.append("\n>PDB|" + id+"|"+ + sequence[i].getDatasetSequence().setPDBId(onlyPdbEntries); + sequence[i].getDatasetSequence().setSequenceFeatures(entry.getFeature()); + + } + } + } + + StringBuffer getPDBFile(String id) + { + StringBuffer result = new StringBuffer(); + String chain = null; + if (id.indexOf(":") > -1) + { + chain = id.substring(id.indexOf(":") + 1); + id = id.substring(0, id.indexOf(":")); + } + + EBIFetchClient ebi = new EBIFetchClient(); + String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw"); + try + { + PDBfile pdbfile = new PDBfile(reply); + for (int i = 0; i < pdbfile.chains.size(); i++) + { + if (chain == null || + ( (PDBChain) pdbfile.chains.elementAt(i)).id. + toUpperCase().equals(chain)) + result.append("\n>PDB|" + id + "|" + ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. getName() + "\n" + ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. getSequence()); - } - }catch(Exception ex)// Problem parsing PDB file - { - error = "Error retrieving "+textfield.getText()+" from "+database.getSelectedItem(); } } + catch (Exception ex) // Problem parsing PDB file + { + showErrorMessage("Error retrieving " + textfield.getText() + " from " + + database.getSelectedItem()); + return null; + } - if (result.length() > 0 && error==null) + return result; + } + + SequenceI[] parseResult(String result) { - String format = IdentifyFile.Identify(result.toString(), "Paste"); + String format = IdentifyFile.Identify(result, "Paste"); SequenceI[] sequences = null; if (FormatAdapter.formats.contains(format)) @@ -190,7 +276,7 @@ public class SequenceFetcher { AlignFrame af = new AlignFrame(new Alignment(sequences)); af.currentFileFormat = format; - Desktop.addInternalFrame(af, "Cut & Paste input - " + format, + Desktop.addInternalFrame(af, "Retrieved from "+database.getSelectedItem(), AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT); af.statusBar.setText("Successfully pasted alignment file"); @@ -222,7 +308,7 @@ public class SequenceFetcher getHeight()); alignFrame.viewport.alignment.getWidth(); alignFrame.viewport.firePropertyChange("alignment", null, - alignFrame.viewport.getAlignment().getSequences()); + alignFrame.viewport.getAlignment().getSequences()); } @@ -238,21 +324,12 @@ public class SequenceFetcher } else - error = "Error retrieving "+textfield.getText()+" from "+database.getSelectedItem(); - - - + showErrorMessage( "Error retrieving "+textfield.getText() + +" from "+database.getSelectedItem()); } - } - if(error!=null) - showErrorMessage(error); + return sequences; - database.setEnabled(true); - textfield.setEnabled(true); - ok.setEnabled(true); - cancel.setEnabled(true); - frame.setTitle("WSDBfetch@EBI Sequence Fetcher"); } void showErrorMessage(String error) -- 1.7.10.2