Enable lower case colours
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index e3282d8..2beb3d9 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
  * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
  *\r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
@@ -119,8 +119,8 @@ public class SequenceFetcher
                                               new Insets(0, 4, 0, 0), 1, 0));\r
     this.add(textfield, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0\r
                                                , GridBagConstraints.CENTER,\r
-                                               GridBagConstraints.HORIZONTAL,\r
-                                               new Insets(0, 0, 0, 6), 200, 1));\r
+                                               GridBagConstraints.NONE,\r
+                                               new Insets(0, 0, 0, 6), 211, 1));\r
   }\r
 \r
   JComboBox database = new JComboBox();\r
@@ -183,16 +183,26 @@ public class SequenceFetcher
     else if (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
+      StringTokenizer st = new StringTokenizer(textfield.getText(), ";");\r
+      while(st.hasMoreTokens())\r
+      {\r
+        EBIFetchClient dbFetch = new EBIFetchClient();\r
+\r
+        String[] reply = dbFetch.fetchData(\r
+            database.getSelectedItem().toString().toLowerCase(\r
+            ) + ":" + st.nextToken(),\r
+            "fasta", "raw");\r
+//\r
+        if (reply != null)\r
+        {\r
+          for (int i = 0; i < reply.length; i++)\r
+            result.append(reply[i] + "\n");\r
+        }\r
+      }\r
 \r
-      if(reply!=null)\r
+      if(result!=null)\r
       {\r
-        for (int i = 0; i < reply.length; i++)\r
-          result.append(reply[i] + "\n");\r
+        System.out.println(result.toString());\r
 \r
         parseResult(result.toString(), null);\r
       }\r
@@ -239,8 +249,9 @@ public class SequenceFetcher
   {\r
     EBIFetchClient ebi = new EBIFetchClient();\r
     File file = ebi.fetchDataAsFile("uniprot:" + id, "xml", null);\r
-    SequenceFeatureFetcher sff = new SequenceFeatureFetcher();\r
-    Vector entries = sff.getUniprotEntries(file);\r
+\r
+    DBRefFetcher dbref = new DBRefFetcher();\r
+    Vector entries = dbref.getUniprotEntries(file);\r
 \r
     if (entries != null)\r
     {\r
@@ -249,7 +260,8 @@ public class SequenceFetcher
       while (en.hasMoreElements())\r
       {\r
         UniprotEntry entry = (UniprotEntry) en.nextElement();\r
-        StringBuffer name = new StringBuffer(">Uniprot/Swiss-Prot");\r
+\r
+        StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot");\r
         Enumeration en2 = entry.getAccession().elements();\r
         while (en2.hasMoreElements())\r
         {\r
@@ -263,8 +275,10 @@ public class SequenceFetcher
           name.append(en2.nextElement());\r
         }\r
 \r
-        if (entry.getProteinName() != null)\r
-          name.append(" " + entry.getProteinName().elementAt(0));\r
+        if (entry.getProtein() != null)\r
+        {\r
+           name.append(" " + entry.getProtein().getName().elementAt(0));\r
+        }\r
 \r
         result.append(name + "\n" + entry.getUniprotSequence().getContent() +\r
                       "\n");\r
@@ -287,11 +301,27 @@ public class SequenceFetcher
           onlyPdbEntries.addElement(pdb);\r
         }\r
 \r
+        Enumeration en2 = entry.getAccession().elements();\r
+        while (en2.hasMoreElements())\r
+        {\r
+          sequence[i].getDatasetSequence().addDBRef(new DBRefEntry(DBRefSource.UNIPROT,\r
+                    "0",\r
+                    en2.nextElement().toString()));\r
+        }\r
+\r
+\r
+\r
+\r
         sequence[i].getDatasetSequence().setPDBId(onlyPdbEntries);\r
-        e = entry.getFeature().elements();\r
-        while(e.hasMoreElements())\r
+        if (entry.getFeature() != null)\r
         {\r
-          sequence[i].getDatasetSequence().addSequenceFeature((SequenceFeature)e.nextElement());\r
+          e = entry.getFeature().elements();\r
+          while (e.hasMoreElements())\r
+          {\r
+            SequenceFeature sf = (SequenceFeature) e.nextElement();\r
+            sf.setFeatureGroup("Uniprot");\r
+            sequence[i].getDatasetSequence().addSequenceFeature( sf );\r
+          }\r
         }\r
       }\r
     }\r
@@ -308,17 +338,18 @@ public class SequenceFetcher
     }\r
 \r
     EBIFetchClient ebi = new EBIFetchClient();\r
-    String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw");\r
-    if (reply == null)\r
+    String file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw").getAbsolutePath();\r
+    if (file == null)\r
       return null;\r
     try\r
     {\r
-      PDBfile pdbfile = new PDBfile(reply);\r
+      PDBfile pdbfile = new PDBfile(file, jalview.io.AppletFormatAdapter.FILE);\r
       for (int i = 0; i < pdbfile.chains.size(); i++)\r
       {\r
         if (chain == null ||\r
             ( (PDBChain) pdbfile.chains.elementAt(i)).id.\r
             toUpperCase().equals(chain))\r
+\r
           result.append("\n>PDB|" + id + "|" +\r
                         ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
                         getName() +\r
@@ -341,10 +372,10 @@ public class SequenceFetcher
 \r
   SequenceI[] parseResult(String result, String title)\r
   {\r
-    String format = IdentifyFile.Identify(result, "Paste");\r
+    String format = new IdentifyFile().Identify(result, "Paste");\r
     SequenceI[] sequences = null;\r
 \r
-    if (FormatAdapter.formats.contains(format))\r
+    if (FormatAdapter.isValidFormat(format))\r
     {\r
       sequences = null;\r
       try{ sequences = new FormatAdapter().readFile(result.toString(), "Paste",\r
@@ -355,15 +386,19 @@ public class SequenceFetcher
       {\r
         if (alignFrame == null)\r
         {\r
-          AlignFrame af = new AlignFrame(new Alignment(sequences));\r
+          AlignFrame af = new AlignFrame(new Alignment(sequences),\r
+                                           AlignFrame.DEFAULT_WIDTH,\r
+                                           AlignFrame.DEFAULT_HEIGHT\r
+);\r
           af.currentFileFormat = format;\r
           if(title==null)\r
             title = "Retrieved from " + database.getSelectedItem();\r
           Desktop.addInternalFrame(af,\r
                                    title,\r
-                                   AlignFrame.NEW_WINDOW_WIDTH,\r
-                                   AlignFrame.NEW_WINDOW_HEIGHT);\r
+                                   AlignFrame.DEFAULT_WIDTH,\r
+                                   AlignFrame.DEFAULT_HEIGHT);\r
           af.statusBar.setText("Successfully pasted alignment file");\r
+\r
           try\r
           {\r
             af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));\r
@@ -422,7 +457,7 @@ public class SequenceFetcher
 \r
               // We make a DBRefEtntry because we have obtained the PDB file from a verifiable source\r
               // JBPNote - PDB DBRefEntry should also carry the chain and mapping information\r
-              DBRefEntry dbentry = new DBRefEntry("PDB","0",pdbid);\r
+              DBRefEntry dbentry = new DBRefEntry(jalview.datamodel.DBRefSource.PDB,"0",pdbid);\r
               sequences[i].getDatasetSequence().addDBRef(dbentry);\r
             }\r
             else\r
@@ -451,13 +486,18 @@ public class SequenceFetcher
 \r
   }\r
 \r
-  void showErrorMessage(String error)\r
+  void showErrorMessage(final String error)\r
   {\r
     resetDialog();\r
-    JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                                          error, "Error Retrieving Data",\r
+    javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+    {\r
+      public void run()\r
+      {\r
+        JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+                                              error, "Error Retrieving Data",\r
                                           JOptionPane.WARNING_MESSAGE);\r
-    return;\r
+      }\r
+    });\r
   }\r
 }\r
 \r