From 87185978c81d7d07f683f0c1a1bac5f080e88192 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 12 Nov 2007 16:34:37 +0000 Subject: [PATCH] javadoc and introduction of dasserver and fetchdas command line arguments. --- src/jalview/bin/Jalview.java | 339 +++++++++++++++++++++++++++++------------- 1 file changed, 233 insertions(+), 106 deletions(-) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 65628fb..bfd6d70 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -27,10 +27,10 @@ import jalview.gui.*; import jalview.io.AppletFormatAdapter; /** - * Main class for Jalview Application + * Main class for Jalview Application
*
- *
start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview - * + * start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview + * * @author $author$ * @version $Revision$ */ @@ -39,57 +39,58 @@ public class Jalview /** * main class for Jalview application - * - * @param args open filename + * + * @param args + * open filename */ public static void main(String[] args) { - System.out.println("Java version: " + System.getProperty("java.version")); + System.out.println("Java version: " + + System.getProperty("java.version")); System.out.println(System.getProperty("os.arch") + " " - + System.getProperty("os.name") + " " - + System.getProperty("os.version")); + + System.getProperty("os.name") + " " + + System.getProperty("os.version")); ArgsParser aparser = new ArgsParser(args); boolean headless = false; if (aparser.contains("help") || aparser.contains("h")) { - System.out.println( - "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n" - + "-nodisplay\tRun Jalview without User Interface.\n" - + - "-props FILE\tUse the given Jalview properties file instead of users default.\n" - + - "-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" - + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n" - + "-msf FILE\tCreate alignment file FILE in MSF format.\n" - + "-pileup FILE\tCreate alignment file FILE in Pileup format\n" - + "-pir FILE\tCreate alignment file FILE in PIR format.\n" - + "-blc FILE\tCreate alignment file FILE in BLC format.\n" - + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n" - + "-png FILE\tCreate PNG image FILE from alignment.\n" - + - "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n" - + "-eps FILE\tCreate EPS file FILE from alignment." - + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires." - + "\n\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n"); + System.out + .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n" + + "-nodisplay\tRun Jalview without User Interface.\n" + + "-props FILE\tUse the given Jalview properties file instead of users default.\n" + + "-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" + + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n" + + "-msf FILE\tCreate alignment file FILE in MSF format.\n" + + "-pileup FILE\tCreate alignment file FILE in Pileup format\n" + + "-pir FILE\tCreate alignment file FILE in PIR format.\n" + + "-blc FILE\tCreate alignment file FILE in BLC format.\n" + + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n" + + "-png FILE\tCreate PNG image FILE from alignment.\n" + + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n" + + "-eps FILE\tCreate EPS file FILE from alignment." + + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires." + + "-noquestionnaire\tTurn off questionnaire check." + + "-dasserver nickname=URL\tAdd and enable a das server with given nickname (alphanumeric or underscores only) for retrieval of features for all alignments." + + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them." + + "\n\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n"); System.exit(0); } - Cache.loadProperties(aparser.getValue("props")); // must do this before anything else! + Cache.loadProperties(aparser.getValue("props")); // must do this before + // anything else! if (aparser.contains("nodisplay")) { System.setProperty("java.awt.headless", "true"); } if (System.getProperty("java.awt.headless") != null - && System.getProperty("java.awt.headless").equals("true")) + && System.getProperty("java.awt.headless").equals("true")) { headless = true; } @@ -97,13 +98,12 @@ public class Jalview try { Cache.initLogger(); - } - catch (java.lang.NoClassDefFoundError error) + } catch (java.lang.NoClassDefFoundError error) { error.printStackTrace(); - System.out.println( - "\nEssential logging libraries not found." - + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview"); + System.out + .println("\nEssential logging libraries not found." + + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview"); System.exit(0); } @@ -111,48 +111,55 @@ public class Jalview try { - UIManager.setLookAndFeel( - UIManager.getSystemLookAndFeelClassName() - // UIManager.getCrossPlatformLookAndFeelClassName() - //"com.sun.java.swing.plaf.gtk.GTKLookAndFeel" - //"javax.swing.plaf.metal.MetalLookAndFeel" - //"com.sun.java.swing.plaf.windows.WindowsLookAndFeel" - //"com.sun.java.swing.plaf.motif.MotifLookAndFeel" - - ); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName() + // UIManager.getCrossPlatformLookAndFeelClassName() + // "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" + // "javax.swing.plaf.metal.MetalLookAndFeel" + // "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" + // "com.sun.java.swing.plaf.motif.MotifLookAndFeel" + + ); + } catch (Exception ex) + { } - catch (Exception ex) - {} if (!headless) { desktop = new Desktop(); desktop.setVisible(true); desktop.discoverer.start(); - String url = aparser.getValue("questionnaire"); - if (url != null) - { - // Start the desktop questionnaire prompter with the specified questionnaire - Cache.log.debug("Starting questionnaire url at " + url); - desktop.checkForQuestionnaire(url); - } - else + if (!aparser.contains("noquestionnaire")) { - if (Cache.getProperty("NOQUESTIONNAIRES") == null) + String url = aparser.getValue("questionnaire"); + if (url != null) { - // Start the desktop questionnaire prompter with the specified questionnaire - // String defurl = "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl"; // - String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl"; - Cache.log.debug("Starting questionnaire with default url: " + defurl); - desktop.checkForQuestionnaire(defurl); + // Start the desktop questionnaire prompter with the specified + // questionnaire + Cache.log.debug("Starting questionnaire url at " + url); + desktop.checkForQuestionnaire(url); + } + else + { + if (Cache.getProperty("NOQUESTIONNAIRES") == null) + { + // Start the desktop questionnaire prompter with the specified + // questionnaire + // String defurl = + // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl"; + // // + String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl"; + Cache.log.debug("Starting questionnaire with default url: " + + defurl); + desktop.checkForQuestionnaire(defurl); + } } } - } String file = null, protocol = null, format = null, data = null; jalview.io.FileLoader fileLoader = new jalview.io.FileLoader(); - + Vector getFeatures = null; // vector of das source nicknames to fetch features from + // loading is done. file = aparser.getValue("open"); if (file == null && desktop == null) @@ -167,7 +174,7 @@ public class Jalview if (!file.startsWith("http://")) { - if (! (new java.io.File(file)).exists()) + if (!(new java.io.File(file)).exists()) { System.out.println("Can't find " + file); if (headless) @@ -178,10 +185,11 @@ public class Jalview } protocol = checkProtocol(file); - + format = new jalview.io.IdentifyFile().Identify(file, protocol); - - AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format); + + AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, + format); if (af == null) { @@ -194,14 +202,13 @@ public class Jalview { data.replaceAll("%20", " "); - jalview.schemes.ColourSchemeI cs = - jalview.schemes.ColourSchemeProperty.getColour(af.getViewport(). - getAlignment(), data); + jalview.schemes.ColourSchemeI cs = jalview.schemes.ColourSchemeProperty + .getColour(af.getViewport().getAlignment(), data); if (cs == null) { - jalview.schemes.UserColourScheme ucs - = new jalview.schemes.UserColourScheme("white"); + jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme( + "white"); ucs.parseAppletParameter(data); cs = ucs; } @@ -234,21 +241,37 @@ public class Jalview if (data != null) { jalview.io.NewickFile fin = null; - try { + try + { fin = new jalview.io.NewickFile(data, checkProtocol(data)); - if (fin!=null) + if (fin != null) { - af.getViewport().setCurrentTree(af.ShowNewickTree(fin, data).getTree()); + af.getViewport().setCurrentTree( + af.ShowNewickTree(fin, data).getTree()); System.out.println("Added tree " + data); } - } - catch (IOException ex) + } catch (IOException ex) { - System.err.println("Couldn't add tree "+data); + System.err.println("Couldn't add tree " + data); ex.printStackTrace(System.err); } } - + getFeatures = checkDasArguments(aparser); + if (af != null && getFeatures!=null) + { + startFeatureFetching(getFeatures); + // need to block until fetching is complete. + while (af.operationInProgress()) + { + // wait around until fetching is finished. + try { + Thread.sleep(10); + } catch (Exception e) + { + + } + } + } String imageName = "unnamed.png"; while (aparser.getSize() > 1) { @@ -277,13 +300,13 @@ public class Jalview if (af.saveAlignment(file, format)) { - System.out.println("Written alignment in " + format + - " format to " + file); + System.out.println("Written alignment in " + format + + " format to " + file); } else { - System.out.println("Error writing file " + file + " in " + format + - " format!!"); + System.out.println("Error writing file " + file + " in " + format + + " format!!"); } } @@ -293,19 +316,15 @@ public class Jalview System.out.println("Unknown arg: " + aparser.nextValue()); } } - + AlignFrame startUpAlframe = null; // We'll only open the default file if the desktop is visible. // And the user - ////////////////////// - if ( - !headless - && file == null - && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true) - ) + // //////////////////// + if (!headless && file == null + && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true)) { - file = jalview.bin.Cache.getDefault("STARTUP_FILE", - "http://www.jalview.org/examples/exampleFile_2_3.jar"); + "http://www.jalview.org/examples/exampleFile_2_3.jar"); protocol = "File"; @@ -323,26 +342,126 @@ public class Jalview format = new jalview.io.IdentifyFile().Identify(file, protocol); } - fileLoader.LoadFile(file, protocol, format); - + startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol, + format); + getFeatures = checkDasArguments(aparser); + } + // Once all loading is done. Retrieve features. + if (getFeatures!=null) + { + if (startUpAlframe!=null) + { + startFeatureFetching(getFeatures); + } + } + } + /** + * Check commandline for any das server definitions or any fetchfrom switches + * @return vector of DAS source nicknames to retrieve from + */ + private static Vector checkDasArguments(ArgsParser aparser) + { + Vector source=null; + String data; + String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE); + while ((data = aparser.getValue("dasserver"))!=null) + { + String nickname = null; + String url = null; + int pos = data.indexOf('='); + if (pos > 0) + { + nickname = data.substring(0, pos); + } + url = data.substring(pos + 1); + if (url != null && url.startsWith("http:")) + { + if (nickname == null) + { + nickname = url; + } + if (locsources==null) + { + locsources=""; + } else { + locsources+="\t"; + } + locsources=locsources+nickname+"|"+url; + System.err + .println("NOTE! dasserver parameter not yet really supported (got args of " + + nickname + "|" + url); + if (source==null) + { + source = new Vector(); + } + source.addElement(nickname); + } + } // loop until no more server entries are found. + if (locsources!=null && locsources.indexOf('|')>-1) + { + Cache.log.debug("Setting local source list in properties file to:\n"+locsources); + Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources); } + while ((data = aparser.getValue("fetchfrom"))!=null) + { + System.out.println("adding source '"+data+"'"); + if (source==null) + { + source = new Vector(); + } + source.addElement(data); + } + return source; } + /** + * start a feature fetcher for every alignment frame + * @param dasSources + */ + private static void startFeatureFetching(final Vector dasSources) + { + AlignFrame afs[] = Desktop.getAlignframes(); + if (afs==null || afs.length==0) + { + return; + } + for (int i = 0; i -1 || file.indexOf("file:") > -1) - { - protocol = jalview.io.FormatAdapter.URL; - } - return protocol; + if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1) + { + protocol = jalview.io.FormatAdapter.URL; + } + return protocol; } } + +/** + * Notes: this argParser does not distinguish between parameter switches, + * parameter values and argument text. If an argument happens to be identical + * to a parameter, it will be taken as such (even though it didn't have a '-' prefixing it). + * + * @author Andrew Waterhouse and JBP documented. + * + */ class ArgsParser { Vector vargs = null; + public ArgsParser(String[] args) { vargs = new Vector(); @@ -356,7 +475,11 @@ class ArgsParser vargs.addElement(arg); } } - + /** + * check for and remove first occurence of arg+parameter in arglist. + * @param arg + * @return return the argument following the given arg if arg was in list. + */ public String getValue(String arg) { int index = vargs.indexOf(arg); @@ -369,7 +492,11 @@ class ArgsParser } return ret; } - + /** + * check for and remove first occurence of arg in arglist. + * @param arg + * @return true if arg was present in argslist. + */ public boolean contains(String arg) { if (vargs.contains(arg)) -- 1.7.10.2