X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceFetcher.java;h=2beb3d95dfa5d58b14bbbdf62c299c413bf68b24;hb=237972562c84b83dbd287071cdd839d97aaf7d4b;hp=0884d44cc7cb7478ff870526901e10f1eb16d357;hpb=b7f7c7acc0afabdf3a6162c237094b860968219b;p=jalview.git diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 0884d44..2beb3d9 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -44,6 +44,7 @@ public class SequenceFetcher database.addItem("EMBL"); database.addItem("EMBLCDS"); database.addItem("PDB"); + database.addItem("PFAM"); try { @@ -64,8 +65,7 @@ public class SequenceFetcher private String getFrameTitle() { - return ( (alignFrame == null) ? "New " : "Additional ") + - "Sequence Fetcher (WSDBfetch@EBI)"; + return ( (alignFrame == null) ? "New " : "Additional ") + "Sequence Fetcher"; } private void jbInit() @@ -119,8 +119,8 @@ public class SequenceFetcher new Insets(0, 4, 0, 0), 1, 0)); this.add(textfield, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0 , GridBagConstraints.CENTER, - GridBagConstraints.HORIZONTAL, - new Insets(0, 0, 0, 6), 200, 1)); + GridBagConstraints.NONE, + new Insets(0, 0, 0, 6), 211, 1)); } JComboBox database = new JComboBox(); @@ -142,7 +142,6 @@ public class SequenceFetcher public void ok_actionPerformed(ActionEvent e) { - frame.setTitle("Sequence Fetcher (WSDBfetch@EBI) - Fetching Sequence..."); database.setEnabled(false); textfield.setEnabled(false); ok.setEnabled(false); @@ -158,7 +157,6 @@ public class SequenceFetcher textfield.setEnabled(true); ok.setEnabled(true); close.setEnabled(true); - frame.setTitle(getFrameTitle()); } public void run() @@ -185,18 +183,28 @@ public class SequenceFetcher 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"); + StringTokenizer st = new StringTokenizer(textfield.getText(), ";"); + while(st.hasMoreTokens()) + { + EBIFetchClient dbFetch = new EBIFetchClient(); + + String[] reply = dbFetch.fetchData( + database.getSelectedItem().toString().toLowerCase( + ) + ":" + st.nextToken(), + "fasta", "raw"); +// + if (reply != null) + { + for (int i = 0; i < reply.length; i++) + result.append(reply[i] + "\n"); + } + } - if(reply!=null) + if(result!=null) { - for (int i = 0; i < reply.length; i++) - result.append(reply[i] + "\n"); + System.out.println(result.toString()); - parseResult(result.toString()); + parseResult(result.toString(), null); } } else if (database.getSelectedItem().equals("PDB")) @@ -212,23 +220,38 @@ public class SequenceFetcher if (result.length()>0) - parseResult(result.toString()); + parseResult(result.toString(), null); + } + else if( database.getSelectedItem().equals("PFAM")) + { + try{ + result.append(new FastaFile( + "http://www.sanger.ac.uk/cgi-bin/Pfam/getalignment.pl?format=fal&acc=" + + textfield.getText().toUpperCase(), "URL").print() + ); + + if(result.length()>0) + parseResult( result.toString(), textfield.getText().toUpperCase() ); + + }catch(java.io.IOException ex) + { result = null; } } if (result == null || result.length() == 0) showErrorMessage("Error retrieving " + textfield.getText() + " from " + database.getSelectedItem()); - else - textfield.setText(""); + resetDialog(); + return; } 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); + + DBRefFetcher dbref = new DBRefFetcher(); + Vector entries = dbref.getUniprotEntries(file); if (entries != null) { @@ -237,7 +260,8 @@ public class SequenceFetcher while (en.hasMoreElements()) { UniprotEntry entry = (UniprotEntry) en.nextElement(); - StringBuffer name = new StringBuffer(">Uniprot/Swiss-Prot"); + + StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot"); Enumeration en2 = entry.getAccession().elements(); while (en2.hasMoreElements()) { @@ -251,8 +275,10 @@ public class SequenceFetcher name.append(en2.nextElement()); } - if (entry.getProteinName() != null) - name.append(" " + entry.getProteinName().elementAt(0)); + if (entry.getProtein() != null) + { + name.append(" " + entry.getProtein().getName().elementAt(0)); + } result.append(name + "\n" + entry.getUniprotSequence().getContent() + "\n"); @@ -260,7 +286,7 @@ public class SequenceFetcher } //Then read in the features and apply them to the dataset - SequenceI[] sequence = parseResult(result.toString()); + SequenceI[] sequence = parseResult(result.toString(), null); for (int i = 0; i < entries.size(); i++) { UniprotEntry entry = (UniprotEntry) entries.elementAt(i); @@ -275,9 +301,28 @@ public class SequenceFetcher onlyPdbEntries.addElement(pdb); } - sequence[i].getDatasetSequence().setPDBId(onlyPdbEntries); - sequence[i].getDatasetSequence().setSequenceFeatures(entry.getFeature()); + Enumeration en2 = entry.getAccession().elements(); + while (en2.hasMoreElements()) + { + sequence[i].getDatasetSequence().addDBRef(new DBRefEntry(DBRefSource.UNIPROT, + "0", + en2.nextElement().toString())); + } + + + + sequence[i].getDatasetSequence().setPDBId(onlyPdbEntries); + if (entry.getFeature() != null) + { + e = entry.getFeature().elements(); + while (e.hasMoreElements()) + { + SequenceFeature sf = (SequenceFeature) e.nextElement(); + sf.setFeatureGroup("Uniprot"); + sequence[i].getDatasetSequence().addSequenceFeature( sf ); + } + } } } } @@ -293,17 +338,18 @@ public class SequenceFetcher } EBIFetchClient ebi = new EBIFetchClient(); - String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw"); - if (reply == null) + String file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath(); + if (file == null) return null; try { - PDBfile pdbfile = new PDBfile(reply); + PDBfile pdbfile = new PDBfile(file, jalview.io.AppletFormatAdapter.FILE); 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() + @@ -324,26 +370,35 @@ public class SequenceFetcher return result; } - SequenceI[] parseResult(String result) + SequenceI[] parseResult(String result, String title) { - String format = IdentifyFile.Identify(result, "Paste"); + String format = new IdentifyFile().Identify(result, "Paste"); SequenceI[] sequences = null; - if (FormatAdapter.formats.contains(format)) + if (FormatAdapter.isValidFormat(format)) { - sequences = new FormatAdapter().readFile(result.toString(), "Paste", - format); + sequences = null; + try{ sequences = new FormatAdapter().readFile(result.toString(), "Paste", + format);} + catch(Exception ex){} + if (sequences != null && sequences.length > 0) { if (alignFrame == null) { - AlignFrame af = new AlignFrame(new Alignment(sequences)); + AlignFrame af = new AlignFrame(new Alignment(sequences), + AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT +); af.currentFileFormat = format; + if(title==null) + title = "Retrieved from " + database.getSelectedItem(); Desktop.addInternalFrame(af, - "Retrieved from " + database.getSelectedItem(), - AlignFrame.NEW_WINDOW_WIDTH, - AlignFrame.NEW_WINDOW_HEIGHT); + title, + AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); af.statusBar.setText("Successfully pasted alignment file"); + try { af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); @@ -358,7 +413,7 @@ public class SequenceFetcher alignFrame.viewport.alignment.addSequence(sequences[i]); //////////////////////////// - //Datset needs extension; + //Dataset needs extension; ///////////////////////////// Sequence ds = new Sequence(sequences[i].getName(), AlignSeq.extractGaps("-. ", @@ -402,7 +457,7 @@ public class SequenceFetcher // We make a DBRefEtntry because we have obtained the PDB file from a verifiable source // JBPNote - PDB DBRefEntry should also carry the chain and mapping information - DBRefEntry dbentry = new DBRefEntry("PDB","0",pdbid); + DBRefEntry dbentry = new DBRefEntry(jalview.datamodel.DBRefSource.PDB,"0",pdbid); sequences[i].getDatasetSequence().addDBRef(dbentry); } else @@ -431,11 +486,18 @@ public class SequenceFetcher } - void showErrorMessage(String error) + void showErrorMessage(final String error) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - error, "Error Retrieving Data", + resetDialog(); + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + error, "Error Retrieving Data", JOptionPane.WARNING_MESSAGE); + } + }); } }