thread for product retrieval
authorjprocter <Jim Procter>
Wed, 24 Oct 2007 14:11:26 +0000 (14:11 +0000)
committerjprocter <Jim Procter>
Wed, 24 Oct 2007 14:11:26 +0000 (14:11 +0000)
src/jalview/gui/AlignFrame.java

index 53b721d..7efd900 100755 (executable)
@@ -3612,6 +3612,7 @@ public class AlignFrame
 
           public void actionPerformed(ActionEvent e)
           {
+            // TODO: new thread for this call with vis-delay
             af.showProductsFor(sel, ds, isRegSel, dna, source);
           }
           
@@ -3629,33 +3630,61 @@ public class AlignFrame
   }
 protected void showProductsFor(SequenceI[] sel, Alignment ds, boolean isRegSel, boolean dna, String source)
   {
-  ds = this.getViewport().alignment.getDataset(); // update our local dataset reference
-  Alignment prods = CrossRef.findXrefSequences(sel, dna, source, ds);
-  if (prods!=null)
-  {
-    SequenceI[] sprods = new SequenceI[prods.getHeight()];
-    for (int s=0; s<sprods.length;s++)
-    {
-      sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
-      if (ds.getSequences()==null || !ds.getSequences().contains(sprods[s].getDatasetSequence()))
-        ds.addSequence(sprods[s].getDatasetSequence());
-    }
-    Alignment al = new Alignment(sprods);
-    AlignedCodonFrame[] cf = prods.getCodonFrames();
-    for (int s=0; cf!=null && s<cf.length; s++)
+  final boolean fisRegSel = isRegSel;
+  final boolean fdna = dna;
+  final String fsrc = source;
+  final AlignFrame ths = this;
+  final SequenceI[] fsel = sel;
+  Runnable foo = new Runnable() {
+
+    public void run()
     {
-      al.addCodonFrame(cf[s]);
-      cf[s] = null;
+      final long sttime = System.currentTimeMillis();
+      ths.setProgressBar("Searching for sequences from "+fsrc, sttime);
+      try {
+        Alignment ds = ths.getViewport().alignment.getDataset(); // update our local dataset reference
+      Alignment prods = CrossRef.findXrefSequences(fsel, fdna, fsrc, ds);
+      if (prods!=null)
+      {
+        SequenceI[] sprods = new SequenceI[prods.getHeight()];
+        for (int s=0; s<sprods.length;s++)
+        {
+          sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
+          if (ds.getSequences()==null || !ds.getSequences().contains(sprods[s].getDatasetSequence()))
+            ds.addSequence(sprods[s].getDatasetSequence());
+          sprods[s].updatePDBIds();
+        }
+        Alignment al = new Alignment(sprods);
+        AlignedCodonFrame[] cf = prods.getCodonFrames();
+        for (int s=0; cf!=null && s<cf.length; s++)
+        {
+          al.addCodonFrame(cf[s]);
+          cf[s] = null;
+        }
+        al.setDataset(ds);
+        AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+        String newtitle =""+((fdna) ? "Proteins " : "Nucleotides ") + " for "+((fisRegSel) ? "selected region of " : "")
+                + getTitle();
+        Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
+                DEFAULT_HEIGHT);
+      } else {
+        System.err.println("No Sequences generated for xRef type "+fsrc);
+      }
+      }
+      catch (Exception e)
+      {
+        jalview.bin.Cache.log.error("Exception when finding crossreferences",e);
+      }
+      catch (Error e)
+      {
+        jalview.bin.Cache.log.error("Error when finding crossreferences",e);
+      }
+      ths.setProgressBar("Finished searching for sequences from "+fsrc, sttime);
     }
-    al.setDataset(ds);
-    AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
-    String newtitle =""+((dna) ? "Proteins " : "Nucleotides ") + " for "+((isRegSel) ? "selected region of " : "")
-            + getTitle();
-    Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
-            DEFAULT_HEIGHT);
-  } else {
-    System.err.println("No Sequences generated for xRef type "+source);
-  }
+    
+  };
+  Thread frunner = new Thread(foo);
+  frunner.start();
   }