From 0c3e6a10ea83dc9d3591e14b1e55bc98a33dede9 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 11 Nov 2005 18:19:05 +0000 Subject: [PATCH] SequenceFetcher new class --- src/jalview/gui/AlignFrame.java | 6 + src/jalview/gui/Desktop.java | 4 + src/jalview/gui/SequenceFetcher.java | 235 ++++++++++++++++++++++++++++++++++ src/jalview/jbgui/GAlignFrame.java | 15 +++ src/jalview/jbgui/GDesktop.java | 17 ++- 5 files changed, 276 insertions(+), 1 deletion(-) create mode 100755 src/jalview/gui/SequenceFetcher.java diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index dcb3f44..cfbd186 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -260,6 +260,12 @@ public class AlignFrame } } + public void fetchSequence_actionPerformed(ActionEvent e) + { + new SequenceFetcher(this); + } + + /** * DOCUMENT ME! * diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 7569831..cc720fe 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -572,5 +572,9 @@ public class Desktop extends jalview.jbgui.GDesktop } + public void inputSequence_actionPerformed(ActionEvent e) + { + SequenceFetcher sf = new SequenceFetcher(null); + } } diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java new file mode 100755 index 0000000..74312e2 --- /dev/null +++ b/src/jalview/gui/SequenceFetcher.java @@ -0,0 +1,235 @@ +package jalview.gui; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import MCview.PDBfile; +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 jalview.datamodel.*; + +public class SequenceFetcher + extends JPanel implements Runnable +{ + JInternalFrame frame; + AlignFrame alignFrame; + public SequenceFetcher(AlignFrame af) + { + alignFrame = af; + database.addItem("-- Select Database --"); + database.addItem("Uniprot"); + database.addItem("EMBL"); + database.addItem("EMBLCDS"); + database.addItem("PDB"); + + try + { + jbInit(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + frame = new JInternalFrame(); + frame.setContentPane(this); + Desktop.addInternalFrame(frame, "Sequence Fetcher", 390, 120); + } + + private void jbInit() + throws Exception + { + this.setLayout(gridBagLayout1); + database.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); + jLabel1.setText( + "Separate multiple accession ids with semi colon \";\""); + ok.setText("OK"); + ok.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + cancel.setText("Cancel"); + cancel.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cancel_actionPerformed(e); + } + }); + textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + textfield.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + jPanel1.add(ok); + jPanel1.add(cancel); + this.add(jLabel1, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0 + , GridBagConstraints.WEST, + GridBagConstraints.NONE, + new Insets(7, 4, 0, 6), 77, 6)); + this.add(textfield, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0 + , GridBagConstraints.WEST, + GridBagConstraints.HORIZONTAL, + new Insets(0, 0, 0, 6), 221, 1)); + this.add(jPanel1, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0 + , GridBagConstraints.WEST, + GridBagConstraints.BOTH, + new Insets(7, -2, 7, 12), 241, -2)); + this.add(database, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0 + , GridBagConstraints.CENTER, + GridBagConstraints.NONE, + new Insets(0, 4, 0, 0), 1, 0)); + } + + JComboBox database = new JComboBox(); + JLabel jLabel1 = new JLabel(); + JButton ok = new JButton(); + JButton cancel = new JButton(); + JPanel jPanel1 = new JPanel(); + JTextField textfield = new JTextField(); + GridBagLayout gridBagLayout1 = new GridBagLayout(); + public void cancel_actionPerformed(ActionEvent e) + { + try + { + frame.setClosed(true); + } + catch (Exception ex) + {} + } + + public void ok_actionPerformed(ActionEvent e) + { + frame.setTitle("Sequence Fetcher - Fetching Sequence from " + + database.getSelectedItem()); + database.setEnabled(false); + textfield.setEnabled(false); + ok.setEnabled(false); + cancel.setEnabled(false); + + Thread worker = new Thread(this); + worker.start(); + + } + + public void run() + { + StringBuffer result = new StringBuffer(); + if (database.getSelectedItem().equals("Uniprot") + || 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"); + } + else if (database.getSelectedItem().equals("PDB")) + { + EBIFetchClient ebi = new EBIFetchClient(); + String[] reply = ebi.fetchData("pdb:" + textfield.getText(), "pdb", + "raw"); + PDBfile pdbfile = new PDBfile(reply); + for (int i = 0; i < pdbfile.chains.size(); i++) + { + result.append("\n>" + + ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.getName() + + "\n" + + + ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. + getSequence()); + } + } + + if (result.length() > 0) + { + String format = IdentifyFile.Identify(result.toString(), "Paste"); + SequenceI[] sequences = null; + + if (FormatAdapter.formats.contains(format)) + { + sequences = new FormatAdapter().readFile(result.toString(), "Paste", format); + if (sequences != null) + { + if(alignFrame==null) + { + AlignFrame af = new AlignFrame(new Alignment(sequences)); + af.currentFileFormat = format; + Desktop.addInternalFrame(af, "Cut & Paste input - " + format, + AlignFrame.NEW_WINDOW_WIDTH, + AlignFrame.NEW_WINDOW_HEIGHT); + af.statusBar.setText("Successfully pasted alignment file"); + try + { + af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); + } + catch (Exception ex) + {} + } + else + { + for (int i = 0; i < sequences.length; i++) + { + alignFrame.viewport.alignment.addSequence(sequences[i]); + + //////////////////////////// + //Datset needs extension; + ///////////////////////////// + Sequence ds = new Sequence(sequences[i].getName(), + AlignSeq.extractGaps("-. ", + sequences[i].getSequence()), + sequences[i].getStart(), + sequences[i].getEnd()); + sequences[i].setDatasetSequence(ds); + alignFrame.viewport.alignment.getDataset().addSequence(ds); + } + alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment. + getHeight()); + alignFrame.viewport.alignment.getWidth(); + alignFrame.viewport.firePropertyChange("alignment", null, + alignFrame.viewport.getAlignment().getSequences()); + + } + + if (database.getSelectedItem().equals("PDB")) + { + for (int i = 0; i < sequences.length; i++) + { + PDBEntry entry = new PDBEntry(); + entry.setId(textfield.getText()); + sequences[i].getDatasetSequence().addPDBId(entry); + } + } + + } + } + } + + database.setEnabled(true); + textfield.setEnabled(true); + ok.setEnabled(true); + cancel.setEnabled(true); + frame.setTitle("Sequence Fetcher"); + } +} + + + + diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 84db85b..2909727 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -118,6 +118,7 @@ public class GAlignFrame protected JTabbedPane tabbedPane = new JTabbedPane(); public JMenuItem featureSettings = new JMenuItem(); public JCheckBoxMenuItem seqDBRef = new JCheckBoxMenuItem(); + JMenuItem fetchSequence = new JMenuItem(); public GAlignFrame() { @@ -955,6 +956,14 @@ public class GAlignFrame seqDBRef_actionPerformed(e); } }); + fetchSequence.setText("Fetch Sequence..."); + fetchSequence.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + fetchSequence_actionPerformed(e); + } + }); alignFrameMenuBar.add(fileMenu); alignFrameMenuBar.add(editMenu); alignFrameMenuBar.add(searchMenu); @@ -962,6 +971,7 @@ public class GAlignFrame alignFrameMenuBar.add(colourMenu); alignFrameMenuBar.add(calculateMenu); alignFrameMenuBar.add(webService); + fileMenu.add(fetchSequence); fileMenu.add(vamsasStore); fileMenu.add(saveAlignmentMenu); fileMenu.add(jMenu2); @@ -1373,4 +1383,9 @@ public class GAlignFrame } + public void fetchSequence_actionPerformed(ActionEvent e) + { + + } + } diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index 68a7c92..335fcb8 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -49,6 +49,7 @@ public class GDesktop extends JFrame JMenuItem loadState = new JMenuItem(); JMenu jMenu1 = new JMenu(); JMenuItem vamsasLoad = new JMenuItem(); + JMenuItem inputSequence = new JMenuItem(); /** * Creates a new GDesktop object. @@ -167,13 +168,22 @@ public class GDesktop extends JFrame vamsasLoad_actionPerformed(e); } }); + inputSequence.setText("Input Sequence..."); + inputSequence.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + inputSequence_actionPerformed(e); + } + }); DesktopMenubar.add(FileMenu); DesktopMenubar.add(toolsMenu); DesktopMenubar.add(HelpMenu); DesktopMenubar.add(windowMenu); FileMenu.addSeparator(); FileMenu.add(jMenu1); - FileMenu.addSeparator(); + FileMenu.add(inputSequence); + FileMenu.addSeparator(); FileMenu.add(saveState); FileMenu.add(loadState); FileMenu.addSeparator(); @@ -288,4 +298,9 @@ public class GDesktop extends JFrame { } + + public void inputSequence_actionPerformed(ActionEvent e) + { + + } } -- 1.7.10.2