--- /dev/null
+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