2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.io.BufferedReader;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28 import java.io.OutputStreamWriter;
29 import java.io.PrintWriter;
30 import java.net.MalformedURLException;
32 import java.net.URISyntaxException;
34 import java.security.AllPermission;
35 import java.security.CodeSource;
36 import java.security.PermissionCollection;
37 import java.security.Permissions;
38 import java.security.Policy;
39 import java.util.HashMap;
41 import java.util.Vector;
42 import java.util.logging.ConsoleHandler;
43 import java.util.logging.Level;
44 import java.util.logging.Logger;
46 import javax.swing.UIManager;
47 import javax.swing.UIManager.LookAndFeelInfo;
49 import com.threerings.getdown.util.LaunchUtil;
51 import groovy.lang.Binding;
52 import groovy.util.GroovyScriptEngine;
53 import jalview.ext.so.SequenceOntology;
54 import jalview.gui.AlignFrame;
55 import jalview.gui.Desktop;
56 import jalview.gui.PromptUserConfig;
57 import jalview.io.AppletFormatAdapter;
58 import jalview.io.BioJsHTMLOutput;
59 import jalview.io.DataSourceType;
60 import jalview.io.FileFormat;
61 import jalview.io.FileFormatException;
62 import jalview.io.FileFormatI;
63 import jalview.io.FileLoader;
64 import jalview.io.HtmlSvgOutput;
65 import jalview.io.IdentifyFile;
66 import jalview.io.NewickFile;
67 import jalview.io.gff.SequenceOntologyFactory;
68 import jalview.schemes.ColourSchemeI;
69 import jalview.schemes.ColourSchemeProperty;
70 import jalview.util.HttpUtils;
71 import jalview.util.MessageManager;
72 import jalview.util.Platform;
73 import jalview.ws.jws2.Jws2Discoverer;
76 * Main class for Jalview Application <br>
78 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
81 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
82 * jalview.bin.Jalview jalview.bin.Jalview
84 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
85 * embellish '*' to e.g. '*.jar')
94 Platform.getURLCommandArguments();
98 * singleton instance of this class
100 private static Jalview instance;
102 private Desktop desktop;
104 public static AlignFrame currentAlignFrame;
108 if (!Platform.isJS())
115 // grab all the rights we can for the JVM
116 Policy.setPolicy(new Policy()
119 public PermissionCollection getPermissions(CodeSource codesource)
121 Permissions perms = new Permissions();
122 perms.add(new AllPermission());
127 public void refresh()
135 * keep track of feature fetching tasks.
143 * TODO: generalise to track all jalview events to orchestrate batch processing
147 private int queued = 0;
149 private int running = 0;
151 public FeatureFetcher()
156 public void addFetcher(final AlignFrame af,
157 final Vector<String> dasSources)
159 final long id = System.currentTimeMillis();
161 final FeatureFetcher us = this;
162 new Thread(new Runnable()
174 af.setProgressBar(MessageManager
175 .getString("status.das_features_being_retrived"), id);
176 af.featureSettings_actionPerformed(null);
177 af.setProgressBar(null, id);
186 public synchronized boolean allFinished()
188 return queued == 0 && running == 0;
193 public static Jalview getInstance()
199 * main class for Jalview application
202 * open <em>filename</em>
204 public static void main(String[] args)
206 // setLogging(); // BH - for event debugging in JavaScript
207 instance = new Jalview();
208 instance.doMain(args);
211 private static void logClass(String name)
213 // BH - for event debugging in JavaScript
214 ConsoleHandler consoleHandler = new ConsoleHandler();
215 consoleHandler.setLevel(Level.ALL);
216 Logger logger = Logger.getLogger(name);
217 logger.setLevel(Level.ALL);
218 logger.addHandler(consoleHandler);
221 @SuppressWarnings("unused")
222 private static void setLogging()
230 System.out.println("not in js");
233 // BH - for event debugging in JavaScript (Java mode only)
234 if (!Platform.isJS())
241 Logger.getLogger("").setLevel(Level.ALL);
242 logClass("java.awt.EventDispatchThread");
243 logClass("java.awt.EventQueue");
244 logClass("java.awt.Component");
245 logClass("java.awt.focus.Component");
246 logClass("java.awt.focus.DefaultKeyboardFocusManager");
254 void doMain(String[] args)
257 if (!Platform.isJS())
259 System.setSecurityManager(null);
263 .println("Java version: " + System.getProperty("java.version"));
264 System.out.println("Java Home: " + System.getProperty("java.home"));
265 System.out.println(System.getProperty("os.arch") + " "
266 + System.getProperty("os.name") + " "
267 + System.getProperty("os.version"));
268 String val = System.getProperty("sys.install4jVersion");
271 System.out.println("Install4j version: " + val);
273 val = System.getProperty("installer_template_version");
276 System.out.println("Install4j template version: " + val);
278 val = System.getProperty("launcher_version");
281 System.out.println("Launcher version: " + val);
284 // report Jalview version
285 Cache.loadBuildProperties(true);
287 ArgsParser aparser = new ArgsParser(args);
288 boolean headless = false;
290 if (aparser.contains("help") || aparser.contains("h"))
295 if (aparser.contains("nodisplay") || aparser.contains("nogui")
296 || aparser.contains("headless"))
298 System.setProperty("java.awt.headless", "true");
301 String usrPropsFile = aparser.getValue("props");
302 Cache.loadProperties(usrPropsFile); // must do this before
303 if (usrPropsFile != null)
306 "CMD [-props " + usrPropsFile + "] executed successfully!");
309 if (!Platform.isJS())
316 if (aparser.contains("help") || aparser.contains("h"))
321 if (aparser.contains("nodisplay") || aparser.contains("nogui")
322 || aparser.contains("headless"))
324 System.setProperty("java.awt.headless", "true");
329 final String jabawsUrl = aparser.getValue("jabaws");
330 if (jabawsUrl != null)
334 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
336 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
337 } catch (MalformedURLException e)
340 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
345 String defs = aparser.getValue("setprop");
348 int p = defs.indexOf('=');
351 System.err.println("Ignoring invalid setprop argument : " + defs);
355 System.out.println("Executing setprop argument: " + defs);
358 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
360 // DISABLED FOR SECURITY REASONS
361 // TODO: add a property to allow properties to be overriden by cli args
362 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
364 defs = aparser.getValue("setprop");
366 if (System.getProperty("java.awt.headless") != null
367 && System.getProperty("java.awt.headless").equals("true"))
371 System.setProperty("http.agent",
372 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
376 } catch (NoClassDefFoundError error)
378 error.printStackTrace();
379 System.out.println("\nEssential logging libraries not found."
380 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
389 * configure 'full' SO model if preferences say to, else use the default (full SO)
390 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
392 boolean soDefault = !Platform.isJS();
393 if (Cache.getDefault("USE_FULL_SO", soDefault))
395 SequenceOntologyFactory.setInstance(new SequenceOntology());
400 desktop = new Desktop();
401 desktop.setInBatchMode(true); // indicate we are starting up
405 JalviewTaskbar.setTaskbar(this);
406 } catch (Exception e)
408 Cache.log.info("Cannot set Taskbar");
409 Cache.log.error(e.getMessage());
410 // e.printStackTrace();
411 } catch (Throwable t)
413 Cache.log.info("Cannot set Taskbar");
414 Cache.log.error(t.getMessage());
415 // t.printStackTrace();
418 // set Proxy settings before all the internet calls
419 Cache.setProxyPropertiesFromPreferences();
421 desktop.setVisible(true);
423 if (!Platform.isJS())
430 desktop.startServiceDiscovery();
431 if (!aparser.contains("nousagestats"))
433 startUsageStats(desktop);
437 System.err.println("CMD [-nousagestats] executed successfully!");
440 if (!aparser.contains("noquestionnaire"))
442 String url = aparser.getValue("questionnaire");
445 // Start the desktop questionnaire prompter with the specified
447 Cache.log.debug("Starting questionnaire url at " + url);
448 desktop.checkForQuestionnaire(url);
449 System.out.println("CMD questionnaire[-" + url
450 + "] executed successfully!");
454 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
456 // Start the desktop questionnaire prompter with the specified
459 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
461 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
463 "Starting questionnaire with default url: " + defurl);
464 desktop.checkForQuestionnaire(defurl);
471 .println("CMD [-noquestionnaire] executed successfully!");
474 if (!aparser.contains("nonews"))
476 desktop.checkForNews();
479 BioJsHTMLOutput.updateBioJS();
483 // Move any new getdown-launcher-new.jar into place over old
484 // getdown-launcher.jar
485 String appdirString = System.getProperty("getdownappdir");
486 if (appdirString != null && appdirString.length() > 0)
488 final File appdir = new File(appdirString);
494 LaunchUtil.upgradeGetdown(
495 new File(appdir, "getdown-launcher-old.jar"),
496 new File(appdir, "getdown-launcher.jar"),
497 new File(appdir, "getdown-launcher-new.jar"));
502 String file = null, data = null;
503 FileFormatI format = null;
504 DataSourceType protocol = null;
505 FileLoader fileLoader = new FileLoader(!headless);
507 String groovyscript = null; // script to execute after all loading is
508 // completed one way or another
509 // extract groovy argument and execute if necessary
510 groovyscript = aparser.getValue("groovy", true);
511 file = aparser.getValue("open", true);
513 if (file == null && desktop == null)
515 System.out.println("No files to open!");
519 // Finally, deal with the remaining input data.
524 desktop.setProgressBar(
526 .getString("status.processing_commandline_args"),
527 progress = System.currentTimeMillis());
529 System.out.println("CMD [-open " + file + "] executed successfully!");
531 if (!Platform.isJS())
533 * ignore in JavaScript -- can't just file existence - could load it?
538 if (!HttpUtils.startsWithHttpOrHttps(file))
540 if (!(new File(file)).exists())
542 System.out.println("Can't find " + file);
551 protocol = AppletFormatAdapter.checkProtocol(file);
555 format = new IdentifyFile().identify(file, protocol);
556 } catch (FileFormatException e1)
561 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
565 System.out.println("error");
569 setCurrentAlignFrame(af);
570 data = aparser.getValue("colour", true);
573 data.replaceAll("%20", " ");
575 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
576 af.getViewport(), af.getViewport().getAlignment(), data);
581 "CMD [-color " + data + "] executed successfully!");
586 // Must maintain ability to use the groups flag
587 data = aparser.getValue("groups", true);
590 af.parseFeaturesFile(data,
591 AppletFormatAdapter.checkProtocol(data));
592 // System.out.println("Added " + data);
594 "CMD groups[-" + data + "] executed successfully!");
596 data = aparser.getValue("features", true);
599 af.parseFeaturesFile(data,
600 AppletFormatAdapter.checkProtocol(data));
601 // System.out.println("Added " + data);
603 "CMD [-features " + data + "] executed successfully!");
606 data = aparser.getValue("annotations", true);
609 af.loadJalviewDataFile(data, null, null, null);
610 // System.out.println("Added " + data);
612 "CMD [-annotations " + data + "] executed successfully!");
614 // set or clear the sortbytree flag.
615 if (aparser.contains("sortbytree"))
617 af.getViewport().setSortByTree(true);
618 if (af.getViewport().getSortByTree())
620 System.out.println("CMD [-sortbytree] executed successfully!");
623 if (aparser.contains("no-annotation"))
625 af.getViewport().setShowAnnotation(false);
626 if (!af.getViewport().isShowAnnotation())
628 System.out.println("CMD no-annotation executed successfully!");
631 if (aparser.contains("nosortbytree"))
633 af.getViewport().setSortByTree(false);
634 if (!af.getViewport().getSortByTree())
637 .println("CMD [-nosortbytree] executed successfully!");
640 data = aparser.getValue("tree", true);
646 "CMD [-tree " + data + "] executed successfully!");
647 NewickFile nf = new NewickFile(data,
648 AppletFormatAdapter.checkProtocol(data));
650 .setCurrentTree(af.showNewickTree(nf, data).getTree());
651 } catch (IOException ex)
653 System.err.println("Couldn't add tree " + data);
654 ex.printStackTrace(System.err);
657 // TODO - load PDB structure(s) to alignment JAL-629
658 // (associate with identical sequence in alignment, or a specified
660 if (groovyscript != null)
662 // Execute the groovy script after we've done all the rendering stuff
663 // and before any images or figures are generated.
664 System.out.println("Executing script " + groovyscript);
665 executeGroovyScript(groovyscript, af);
666 System.out.println("CMD groovy[" + groovyscript
667 + "] executed successfully!");
670 String imageName = "unnamed.png";
671 while (aparser.getSize() > 1)
673 String outputFormat = aparser.nextValue();
674 file = aparser.nextValue();
676 if (outputFormat.equalsIgnoreCase("png"))
678 af.createPNG(new File(file));
679 imageName = (new File(file)).getName();
680 System.out.println("Creating PNG image: " + file);
683 else if (outputFormat.equalsIgnoreCase("svg"))
685 File imageFile = new File(file);
686 imageName = imageFile.getName();
687 af.createSVG(imageFile);
688 System.out.println("Creating SVG image: " + file);
691 else if (outputFormat.equalsIgnoreCase("html"))
693 File imageFile = new File(file);
694 imageName = imageFile.getName();
695 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
696 htmlSVG.exportHTML(file);
698 System.out.println("Creating HTML image: " + file);
701 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
705 System.err.println("The output html file must not be null");
710 BioJsHTMLOutput.refreshVersionInfo(
711 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
712 } catch (URISyntaxException e)
716 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
717 bjs.exportHTML(file);
719 .println("Creating BioJS MSA Viwer HTML file: " + file);
722 else if (outputFormat.equalsIgnoreCase("imgMap"))
724 af.createImageMap(new File(file), imageName);
725 System.out.println("Creating image map: " + file);
728 else if (outputFormat.equalsIgnoreCase("eps"))
730 File outputFile = new File(file);
732 "Creating EPS file: " + outputFile.getAbsolutePath());
733 af.createEPS(outputFile);
737 af.saveAlignment(file, format);
738 if (af.isSaveAlignmentSuccessful())
740 System.out.println("Written alignment in " + format
741 + " format to " + file);
745 System.out.println("Error writing file " + file + " in "
746 + format + " format!!");
751 while (aparser.getSize() > 0)
753 System.out.println("Unknown arg: " + aparser.nextValue());
757 AlignFrame startUpAlframe = null;
758 // We'll only open the default file if the desktop is visible.
760 // ////////////////////
762 if (!Platform.isJS() && !headless && file == null
763 && Cache.getDefault("SHOW_STARTUP_FILE", true))
770 file = Cache.getDefault("STARTUP_FILE",
771 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
772 + "/examples/exampleFile_2_7.jar");
774 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
776 // hardwire upgrade of the startup file
777 file.replace("_2_3.jar", "_2_7.jar");
778 // and remove the stale setting
779 Cache.removeProperty("STARTUP_FILE");
782 protocol = DataSourceType.FILE;
784 if (file.indexOf("http:") > -1)
786 protocol = DataSourceType.URL;
789 if (file.endsWith(".jar"))
791 format = FileFormat.Jalview;
797 format = new IdentifyFile().identify(file, protocol);
798 } catch (FileFormatException e)
804 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
806 // extract groovy arguments before anything else.
809 // Once all other stuff is done, execute any groovy scripts (in order)
810 if (groovyscript != null)
812 if (Cache.groovyJarsPresent())
814 System.out.println("Executing script " + groovyscript);
815 executeGroovyScript(groovyscript, startUpAlframe);
820 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
824 // and finally, turn off batch mode indicator - if the desktop still exists
829 desktop.setProgressBar(null, progress);
831 desktop.setInBatchMode(false);
835 private static void setLookAndFeel()
837 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
839 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
841 String lafProp = System.getProperty("laf");
842 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
848 else if (lafSetting != null)
852 boolean lafSet = false;
855 case "crossplatform":
856 lafSet = setCrossPlatformLookAndFeel();
859 Cache.log.error("Could not set requested laf=" + laf);
863 lafSet = setSystemLookAndFeel();
866 Cache.log.error("Could not set requested laf=" + laf);
870 lafSet = setGtkLookAndFeel();
873 Cache.log.error("Could not set requested laf=" + laf);
877 lafSet = setMetalLookAndFeel();
880 Cache.log.error("Could not set requested laf=" + laf);
884 lafSet = setNimbusLookAndFeel();
887 Cache.log.error("Could not set requested laf=" + laf);
891 lafSet = setQuaquaLookAndFeel();
894 Cache.log.error("Could not set requested laf=" + laf);
898 lafSet = setVaquaLookAndFeel();
901 Cache.log.error("Could not set requested laf=" + laf);
905 lafSet = setMacLookAndFeel();
908 Cache.log.error("Could not set requested laf=" + laf);
914 Cache.log.error("Requested laf=" + laf + " not implemented");
918 setSystemLookAndFeel();
919 if (Platform.isLinux())
921 setMetalLookAndFeel();
923 if (Platform.isMac())
930 private static boolean setCrossPlatformLookAndFeel()
935 UIManager.setLookAndFeel(
936 UIManager.getCrossPlatformLookAndFeelClassName());
938 } catch (Exception ex)
940 Cache.log.error("Unexpected Look and Feel Exception");
941 Cache.log.error(ex.getMessage());
942 Cache.log.debug(Cache.getStackTraceString(ex));
947 private static boolean setSystemLookAndFeel()
952 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
954 } catch (Exception ex)
956 Cache.log.error("Unexpected Look and Feel Exception");
957 Cache.log.error(ex.getMessage());
958 Cache.log.debug(Cache.getStackTraceString(ex));
963 private static boolean setSpecificLookAndFeel(String name,
964 String className, boolean nameStartsWith)
969 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
971 if (info.getName() != null && nameStartsWith
972 ? info.getName().toLowerCase()
973 .startsWith(name.toLowerCase())
974 : info.getName().toLowerCase().equals(name.toLowerCase()))
976 className = info.getClassName();
980 UIManager.setLookAndFeel(className);
982 } catch (Exception ex)
984 Cache.log.error("Unexpected Look and Feel Exception");
985 Cache.log.error(ex.getMessage());
986 Cache.log.debug(Cache.getStackTraceString(ex));
991 private static boolean setGtkLookAndFeel()
993 return setSpecificLookAndFeel("gtk",
994 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
997 private static boolean setMetalLookAndFeel()
999 return setSpecificLookAndFeel("metal",
1000 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1003 private static boolean setNimbusLookAndFeel()
1005 return setSpecificLookAndFeel("nimbus",
1006 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1009 private static boolean setQuaquaLookAndFeel()
1011 return setSpecificLookAndFeel("quaqua",
1012 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
1017 private static boolean setVaquaLookAndFeel()
1019 return setSpecificLookAndFeel("vaqua",
1020 "org.violetlib.aqua.AquaLookAndFeel", false);
1023 private static boolean setMacLookAndFeel()
1025 boolean set = false;
1026 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1028 System.setProperty("apple.laf.useScreenMenuBar", "true");
1029 set = setQuaquaLookAndFeel();
1030 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1031 .toLowerCase().contains("quaqua"))
1033 set = setVaquaLookAndFeel();
1038 private static void showUsage()
1041 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1042 + "-nodisplay\tRun Jalview without User Interface.\n"
1043 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1044 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1045 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1046 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1047 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1048 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1049 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1050 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1051 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1052 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1053 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1054 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1055 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1056 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1057 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1058 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1059 + "-html FILE\tCreate HTML file from alignment.\n"
1060 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1061 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1062 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1063 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1064 + "-noquestionnaire\tTurn off questionnaire check.\n"
1065 + "-nonews\tTurn off check for Jalview news.\n"
1066 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1067 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1069 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1070 // after all other properties files have been read\n\t
1071 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1072 // passed in correctly)"
1073 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1074 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1075 + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
1076 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1079 private static void startUsageStats(final Desktop desktop)
1082 * start a User Config prompt asking if we can log usage statistics.
1084 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1085 "USAGESTATS", "Jalview Usage Statistics",
1086 "Do you want to help make Jalview better by enabling "
1087 + "the collection of usage statistics with Google Analytics ?"
1088 + "\n\n(you can enable or disable usage tracking in the preferences)",
1095 "Initialising googletracker for usage stats.");
1096 Cache.initGoogleTracker();
1097 Cache.log.debug("Tracking enabled.");
1104 Cache.log.debug("Not enabling Google Tracking.");
1107 desktop.addDialogThread(prompter);
1111 * Locate the given string as a file and pass it to the groovy interpreter.
1113 * @param groovyscript
1114 * the script to execute
1115 * @param jalviewContext
1116 * the Jalview Desktop object passed in to the groovy binding as the
1119 private void executeGroovyScript(String groovyscript, AlignFrame af)
1122 * for scripts contained in files
1129 if (groovyscript.trim().equals("STDIN"))
1131 // read from stdin into a tempfile and execute it
1134 tfile = File.createTempFile("jalview", "groovy");
1135 PrintWriter outfile = new PrintWriter(
1136 new OutputStreamWriter(new FileOutputStream(tfile)));
1137 BufferedReader br = new BufferedReader(
1138 new InputStreamReader(System.in));
1140 while ((line = br.readLine()) != null)
1142 outfile.write(line + "\n");
1148 } catch (Exception ex)
1150 System.err.println("Failed to read from STDIN into tempfile "
1151 + ((tfile == null) ? "(tempfile wasn't created)"
1152 : tfile.toString()));
1153 ex.printStackTrace();
1158 sfile = tfile.toURI().toURL();
1159 } catch (Exception x)
1162 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1164 x.printStackTrace();
1172 sfile = new URI(groovyscript).toURL();
1173 } catch (Exception x)
1175 tfile = new File(groovyscript);
1176 if (!tfile.exists())
1178 System.err.println("File '" + groovyscript + "' does not exist.");
1181 if (!tfile.canRead())
1183 System.err.println("File '" + groovyscript + "' cannot be read.");
1186 if (tfile.length() < 1)
1188 System.err.println("File '" + groovyscript + "' is empty.");
1193 sfile = tfile.getAbsoluteFile().toURI().toURL();
1194 } catch (Exception ex)
1196 System.err.println("Failed to create a file URL for "
1197 + tfile.getAbsoluteFile());
1204 Map<String, java.lang.Object> vbinding = new HashMap<>();
1205 vbinding.put("Jalview", this);
1208 vbinding.put("currentAlFrame", af);
1210 Binding gbinding = new Binding(vbinding);
1211 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1212 gse.run(sfile.toString(), gbinding);
1213 if ("STDIN".equals(groovyscript))
1215 // delete temp file that we made -
1216 // only if it was successfully executed
1219 } catch (Exception e)
1221 System.err.println("Exception Whilst trying to execute file " + sfile
1222 + " as a groovy script.");
1223 e.printStackTrace(System.err);
1228 public static boolean isHeadlessMode()
1230 String isheadless = System.getProperty("java.awt.headless");
1231 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1238 public AlignFrame[] getAlignFrames()
1240 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1241 : Desktop.getAlignFrames();
1246 * Quit method delegates to Desktop.quit - unless running in headless mode
1247 * when it just ends the JVM
1251 if (desktop != null)
1261 public static AlignFrame getCurrentAlignFrame()
1263 return Jalview.currentAlignFrame;
1266 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1268 Jalview.currentAlignFrame = currentAlignFrame;