SequenceFetcher new class
authoramwaterhouse <Andrew Waterhouse>
Fri, 11 Nov 2005 18:19:05 +0000 (18:19 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 11 Nov 2005 18:19:05 +0000 (18:19 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java
src/jalview/gui/SequenceFetcher.java [new file with mode: 0755]
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GDesktop.java

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