added the '-tree' parameter to open a tree from the command line
authorjprocter <Jim Procter>
Wed, 1 Aug 2007 16:29:14 +0000 (16:29 +0000)
committerjprocter <Jim Procter>
Wed, 1 Aug 2007 16:29:14 +0000 (16:29 +0000)
src/jalview/bin/Jalview.java

index f0c33a1..65628fb 100755 (executable)
  */
 package jalview.bin;
 
+import java.io.IOException;
 import java.util.*;
 
 import javax.swing.*;
 
 import jalview.gui.*;
+import jalview.io.AppletFormatAdapter;
 
 /**
  * Main class for Jalview Application
@@ -60,6 +62,8 @@ public class Jalview
           +
           "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
           +
+          "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
+          +
           "-features FILE\tUse the given file to mark features on the alignment.\n"
           + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
           + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
@@ -173,22 +177,10 @@ public class Jalview
         }
       }
 
-      protocol = "File";
-
-      if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
-      {
-        protocol = "URL";
-      }
-
-      if (file.endsWith(".jar"))
-      {
-        format = "Jalview";
-      }
-      else
-      {
-        format = new jalview.io.IdentifyFile().Identify(file, protocol);
-      }
-
+      protocol = checkProtocol(file);
+      
+      format = new jalview.io.IdentifyFile().Identify(file, protocol);
+      
       AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
 
       if (af == null)
@@ -222,13 +214,13 @@ public class Jalview
       data = aparser.getValue("groups");
       if (data != null)
       {
-        af.parseFeaturesFile(data, protocol);
+        af.parseFeaturesFile(data, checkProtocol(data));
         System.out.println("Added " + data);
       }
       data = aparser.getValue("features");
       if (data != null)
       {
-        af.parseFeaturesFile(data, protocol);
+        af.parseFeaturesFile(data, checkProtocol(data));
         System.out.println("Added " + data);
       }
 
@@ -238,6 +230,24 @@ public class Jalview
         af.loadJalviewDataFile(data);
         System.out.println("Added " + data);
       }
+      data = aparser.getValue("tree");
+      if (data != null)
+      {
+        jalview.io.NewickFile fin = null;
+        try {
+          fin = new jalview.io.NewickFile(data, checkProtocol(data));
+          if (fin!=null)
+          {
+            af.getViewport().setCurrentTree(af.ShowNewickTree(fin, data).getTree());
+            System.out.println("Added tree " + data);
+          }
+        }
+        catch (IOException ex)
+        {
+          System.err.println("Couldn't add tree "+data);
+          ex.printStackTrace(System.err);
+        }
+      }
 
       String imageName = "unnamed.png";
       while (aparser.getSize() > 1)
@@ -317,8 +327,19 @@ public class Jalview
 
     }
   }
-}
 
+
+  private static String checkProtocol(String file)
+  {
+  String protocol = jalview.io.FormatAdapter.FILE;
+
+  if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
+  {
+    protocol = jalview.io.FormatAdapter.URL;
+  }
+  return protocol;
+  }
+}
 class ArgsParser
 {
   Vector vargs = null;