JAL-2738 separate thread to load VCF; update FeatureSettings when done
[jalview.git] / src / jalview / io / vcf / VCFLoader.java
index 78d2ad5..ddcecfe 100644 (file)
@@ -21,6 +21,7 @@ import jalview.io.gff.Gff3Helper;
 import jalview.io.gff.SequenceOntologyI;
 import jalview.util.MapList;
 import jalview.util.MappingUtils;
+import jalview.util.MessageManager;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -66,19 +67,44 @@ public class VCFLoader
   }
 
   /**
-   * Loads VCF on to an alignment - provided it can be related to one or more
-   * sequence's chromosomal coordinates.
+   * Starts a new thread to query and load VCF variant data on to the alignment
    * <p>
    * This method is not thread safe - concurrent threads should use separate
    * instances of this class.
    * 
    * @param filePath
-   * @param status
+   * @param gui
    */
-  public void loadVCF(String filePath, AlignViewControllerGuiI status)
+  public void loadVCF(final String filePath,
+          final AlignViewControllerGuiI gui)
   {
-    VCFReader reader = null;
+    if (gui != null)
+    {
+      gui.setStatus(MessageManager.getString("label.searching_vcf"));
+    }
+
+    new Thread()
+    {
+
+      @Override
+      public void run()
+      {
+        VCFLoader.this.doLoad(filePath, gui);
+      }
+
+    }.start();
+  }
 
+  /**
+   * Loads VCF on to an alignment - provided it can be related to one or more
+   * sequence's chromosomal coordinates.
+   * 
+   * @param filePath
+   * @param gui
+   */
+  protected void doLoad(String filePath, AlignViewControllerGuiI gui)
+  {
+    VCFReader reader = null;
     try
     {
       // long start = System.currentTimeMillis();
@@ -108,17 +134,22 @@ public class VCFLoader
           transferAddedFeatures(seq);
         }
       }
-      // long elapsed = System.currentTimeMillis() - start;
-      String msg = String.format("Added %d VCF variants to %d sequence(s)",
-              varCount, seqCount);
-      if (status != null)
+      if (gui != null)
       {
-        status.setStatus(msg);
+        // long elapsed = System.currentTimeMillis() - start;
+        String msg = MessageManager.formatMessage("label.added_vcf",
+                varCount, seqCount);
+        gui.setStatus(msg);
+        gui.getFeatureSettingsUI().discoverAllFeatureData();
       }
     } catch (Throwable e)
     {
       System.err.println("Error processing VCF: " + e.getMessage());
       e.printStackTrace();
+      if (gui != null)
+      {
+        gui.setStatus("Error occurred - see console for details");
+      }
     } finally
     {
       if (reader != null)