jog pixels for OSX
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index ccd0f72..34e8143 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -372,9 +372,11 @@ public class SequenceFetcher extends JPanel implements Runnable
     {
       error += "Please select the source database\n";
     }
-    com.stevesoft.pat.Regex empty = new com.stevesoft.pat.Regex("\\s+", "");
+    // TODO: make this transformation optional and configurable
+    com.stevesoft.pat.Regex empty = new com.stevesoft.pat.Regex("(\\s|[,; ])+",";"); //\\s+", "");
     textArea.setText(empty.replaceAll(textArea.getText()));
-    if (textArea.getText().length() == 0)
+    // see if there's anthing to search with
+    if (!new com.stevesoft.pat.Regex("[A-Za-z0-9_.]").search(textArea.getText()))
     {
       error += "Please enter a (semi-colon separated list of) database id(s)";
     }
@@ -385,14 +387,60 @@ public class SequenceFetcher extends JPanel implements Runnable
       return;
     }
     AlignmentI aresult = null;
+    Object source = database.getSelectedItem();
+    Enumeration en = new StringTokenizer(textArea.getText(), ";");
     try
     {
       guiWindow.setProgressBar("Fetching Sequences from "
               + database.getSelectedItem(), Thread.currentThread()
               .hashCode());
-      aresult = sfetch.getSourceProxy(
-              (String) sources.get(database.getSelectedItem()))
-              .getSequenceRecords(textArea.getText());
+      DbSourceProxy proxy = sfetch.getSourceProxy(
+              (String) sources.get(source));
+      if (proxy.getAccessionSeparator()==null)
+      {
+        while (en.hasMoreElements())
+        {
+          String item = (String) en.nextElement();
+          try {
+            if (aresult!=null)
+            {
+              try {
+                // give the server a chance to breathe
+                Thread.sleep(5);
+              } catch (Exception e)
+              {
+                //
+              }
+
+            }
+            AlignmentI indres = proxy.getSequenceRecords(item);
+            if (indres!=null)
+            {
+              if (aresult == null)
+              {
+                aresult = indres;
+              } else {
+                aresult.append(indres);
+              }
+            }
+          } catch (Exception e)
+          {
+            jalview.bin.Cache.log.info("Error retrieving "+item+" from "+source,e);
+          }
+        }
+      } else {
+        StringBuffer multiacc = new StringBuffer();
+        while (en.hasMoreElements())
+        {
+          multiacc.append(en.nextElement());
+          if (en.hasMoreElements())
+          {
+            multiacc.append(proxy.getAccessionSeparator());
+          }
+        }
+        aresult = proxy
+              .getSequenceRecords(multiacc.toString());
+      }
 
     } catch (Exception e)
     {
@@ -618,7 +666,19 @@ public class SequenceFetcher extends JPanel implements Runnable
         {
           title = "Retrieved from " + database.getSelectedItem();
         }
-
+        SequenceFeature[] sfs=null;
+        for (Enumeration sq=al.getSequences().elements(); sq.hasMoreElements();)
+        {
+          if ((sfs=((SequenceI)sq.nextElement()).getDatasetSequence().getSequenceFeatures())!=null)
+          {
+            if (sfs.length>0)
+            {
+              af.setShowSeqFeatures(true);
+              break;
+            }
+          }
+          
+        }
         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
                 AlignFrame.DEFAULT_HEIGHT);