sequence db fetcher metadata for multiple sequence fetch capacity
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index 70dff68..2d0db64 100755 (executable)
@@ -46,6 +46,7 @@ extends JPanel implements Runnable
   AlignFrame alignFrame;
   StringBuffer result;
   final String noDbSelected = "-- Select Database --";
+  Hashtable sources = new Hashtable();
   public SequenceFetcher(AlignFrame af)
   {
     alignFrame = af;
@@ -57,24 +58,19 @@ extends JPanel implements Runnable
      * internal source to externally distinct names.
      * UNIPROT and UP_NAME are identical DB sources,
      * and should be collapsed. 
-     *
+     */
      
-     String dbs[] = sfetch.getSupportedDb();
+    String dbs[] = sfetch.getSupportedDb();
     for (int i=0; i<dbs.length;i++)
     {
-      if (DBRefSource.isPrimaryDb(dbs[i]))
+      if (!sources.containsValue(dbs[i]))
       {  
-        database.addItem(dbs[i]);
-        // should have some kind of human readable description of each database displayed when
-         * that combo is selected.
-      }
-    }*/
-    database.addItem("Uniprot");
-    database.addItem("EMBL");
-    database.addItem("EMBLCDS");
-    database.addItem("PDB");
-    database.addItem("PFAM");
+        String name = sfetch.getSourceProxy(dbs[i]).getDbName();
 
+        sources.put(name, dbs[i]);
+        database.addItem(name);
+      }
+    }
     try
     {
       jbInit();
@@ -211,7 +207,26 @@ extends JPanel implements Runnable
       resetDialog();
       return;
     }
-
+    AlignmentI aresult=null;
+    try {
+      aresult = sfetch.getSourceProxy((String)sources.get(database.getSelectedItem()))
+      .getSequenceRecords(textArea.getText());
+    }
+    catch (Exception e)
+    {
+      showErrorMessage("Error retrieving " + textArea.getText()
+              + " from " + database.getSelectedItem());
+      //error +="Couldn't retrieve sequences from "+database.getSelectedItem();
+      System.err.println("Retrieval failed for source ='"+database.getSelectedItem()+"' and query\n'"+textArea.getText()+"'\n");
+      e.printStackTrace();
+    }
+    if (aresult!=null)
+    {
+      parseResult(aresult, null, null);
+    }
+    resetDialog();
+  }
+    /*
     result = new StringBuffer();
     if (database.getSelectedItem().equals("Uniprot"))
     {
@@ -476,7 +491,7 @@ extends JPanel implements Runnable
                         + "=" + sq.getStart()
                         + "-" + sq.getEnd());
             sq.getDatasetSequence().addPDBId(entry);
-           */
+           *
           // Add PDB DB Refs
           // 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
@@ -508,9 +523,9 @@ extends JPanel implements Runnable
       results[i] = (SequenceI) result.elementAt(i);
       result.setElementAt(null,i);
     }
-    return results;
-  }
-  Alignment parseResult(String result, String title)
+    return results; 
+  }*/
+  AlignmentI parseResult(String result, String title)
   {
     String format = new IdentifyFile().Identify(result, "Paste");
     Alignment sequences = null;
@@ -539,7 +554,7 @@ extends JPanel implements Runnable
     return null;
   }
 
-  Alignment parseResult(Alignment al, String title, String currentFileFormat)
+  AlignmentI parseResult(AlignmentI al, String title, String currentFileFormat)
   {
 
     if (al != null && al.getHeight() > 0)