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;
43 import javax.swing.LookAndFeel;
44 import javax.swing.UIManager;
46 import com.threerings.getdown.util.LaunchUtil;
48 import groovy.lang.Binding;
49 import groovy.util.GroovyScriptEngine;
50 import jalview.api.AlignCalcWorkerI;
51 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
52 import jalview.ext.so.SequenceOntology;
53 import jalview.gui.AlignFrame;
54 import jalview.gui.AlignViewport;
55 import jalview.gui.Desktop;
56 import jalview.gui.Preferences;
57 import jalview.gui.PromptUserConfig;
58 import jalview.io.AppletFormatAdapter;
59 import jalview.io.BioJsHTMLOutput;
60 import jalview.io.DataSourceType;
61 import jalview.io.FileFormat;
62 import jalview.io.FileFormatException;
63 import jalview.io.FileFormatI;
64 import jalview.io.FileFormats;
65 import jalview.io.FileLoader;
66 import jalview.io.HtmlSvgOutput;
67 import jalview.io.IdentifyFile;
68 import jalview.io.NewickFile;
69 import jalview.io.gff.SequenceOntologyFactory;
70 import jalview.schemes.ColourSchemeI;
71 import jalview.schemes.ColourSchemeProperty;
72 import jalview.util.MessageManager;
73 import jalview.util.Platform;
74 import jalview.ws.jws2.Jws2Discoverer;
75 //import netscape.javascript.JSObject;
78 * Main class for Jalview Application <br>
80 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
83 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
84 * jalview.bin.Jalview jalview.bin.Jalview
86 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
87 * embellish '*' to e.g. '*.jar')
92 public class Jalview implements ApplicationSingletonI
95 // for testing those nasty messages you cannot ever find.
98 // System.setOut(new PrintStream(new ByteArrayOutputStream())
101 // public void println(Object o)
105 // System.err.println(o);
111 public static Jalview getInstance()
113 return (Jalview) ApplicationSingletonProvider
114 .getInstance(Jalview.class);
121 private boolean headless;
123 private Desktop desktop;
125 public AlignFrame currentAlignFrame;
127 public String appletResourcePath;
129 public String j2sAppletID;
131 private boolean noCalculation, noMenuBar, noStatus;
133 private boolean noAnnotation;
135 public boolean getStartCalculations()
137 return !noCalculation;
140 public boolean getAllowMenuBar()
145 public boolean getShowStatus()
150 public boolean getShowAnnotation()
152 return !noAnnotation;
157 if (Platform.isJS()) {
158 Platform.getURLCommandArguments();
159 } else /** @j2sIgnore */
161 // grab all the rights we can for the JVM
162 Policy.setPolicy(new Policy()
165 public PermissionCollection getPermissions(CodeSource codesource)
167 Permissions perms = new Permissions();
168 perms.add(new AllPermission());
173 public void refresh()
181 * keep track of feature fetching tasks.
189 * TODO: generalise to track all jalview events to orchestrate batch processing
193 private int queued = 0;
195 private int running = 0;
197 public FeatureFetcher()
202 public void addFetcher(final AlignFrame af,
203 final Vector<String> dasSources)
205 final long id = System.currentTimeMillis();
207 final FeatureFetcher us = this;
208 new Thread(new Runnable()
220 af.setProgressBar(MessageManager
221 .getString("status.das_features_being_retrived"), id);
222 af.featureSettings_actionPerformed(null);
223 af.setProgressBar(null, id);
232 public synchronized boolean allFinished()
234 return queued == 0 && running == 0;
239 private final static boolean doPlatformLogging = false;
242 * main class for Jalview application
245 * open <em>filename</em>
247 public static void main(String[] args)
249 if (doPlatformLogging)
251 Platform.startJavaLogging();
253 getInstance().doMain(args);
259 void doMain(String[] args)
262 boolean isJS = Platform.isJS();
265 System.setSecurityManager(null);
269 .println("Java version: " + System.getProperty("java.version"));
270 System.out.println("Java Home: " + System.getProperty("java.home"));
271 System.out.println(System.getProperty("os.arch") + " "
272 + System.getProperty("os.name") + " "
273 + System.getProperty("os.version"));
274 String val = System.getProperty("sys.install4jVersion");
277 System.out.println("Install4j version: " + val);
279 val = System.getProperty("installer_template_version");
282 System.out.println("Install4j template version: " + val);
284 val = System.getProperty("launcher_version");
287 System.out.println("Launcher version: " + val);
290 // report Jalview version
291 Cache.getInstance().loadBuildProperties(true);
293 ArgsParser aparser = new ArgsParser(args);
296 String usrPropsFile = aparser.getValue("props");
298 Cache.loadProperties(usrPropsFile); // must do this before
300 boolean allowServices = true;
304 j2sAppletID = Platform.getAppID(null);
305 Preferences.setAppletDefaults();
306 Cache.loadProperties(usrPropsFile); // again, because we
307 // might be changing defaults here?
308 appletResourcePath = (String) aparser.getAppletValue("resourcepath",
319 if (usrPropsFile != null)
322 "CMD [-props " + usrPropsFile + "] executed successfully!");
324 if (aparser.contains("help") || aparser.contains("h"))
330 if (aparser.contains("nodisplay") || aparser.contains("nogui")
331 || aparser.contains("headless"))
333 System.setProperty("java.awt.headless", "true");
340 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
341 allowServices = !("none".equals(jabawsUrl));
342 if (allowServices && jabawsUrl != null)
346 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
348 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
349 } catch (MalformedURLException e)
352 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
357 String defs = aparser.getValue(ArgsParser.SETPROP);
360 int p = defs.indexOf('=');
363 System.err.println("Ignoring invalid setprop argument : " + defs);
367 System.out.println("Executing setprop argument: " + defs);
370 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
373 defs = aparser.getValue("setprop");
375 if (System.getProperty("java.awt.headless") != null
376 && System.getProperty("java.awt.headless").equals("true"))
380 System.setProperty("http.agent",
381 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
385 } catch (NoClassDefFoundError error)
387 error.printStackTrace();
388 System.out.println("\nEssential logging libraries not found."
389 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
398 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
399 } catch (Exception ex)
401 System.err.println("Unexpected Look and Feel Exception");
402 ex.printStackTrace();
404 if (Platform.isMac())
407 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
410 "com.apple.mrj.application.apple.menu.about.name",
412 System.setProperty("apple.laf.useScreenMenuBar", "true");
413 if (lookAndFeel != null)
417 UIManager.setLookAndFeel(lookAndFeel);
418 } catch (Throwable e)
421 "Failed to set QuaQua look and feel: " + e.toString());
424 if (lookAndFeel == null
425 || !(lookAndFeel.getClass().isAssignableFrom(
426 UIManager.getLookAndFeel().getClass()))
427 || !UIManager.getLookAndFeel().getClass().toString()
428 .toLowerCase().contains("quaqua"))
433 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
434 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
435 } catch (Throwable e)
438 "Failed to reset look and feel: " + e.toString());
444 * configure 'full' SO model if preferences say to, else use the default (full SO)
445 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
447 boolean soDefault = !isJS;
448 if (Cache.getDefault("USE_FULL_SO", soDefault))
450 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
457 desktop = Desktop.getInstance();
458 desktop.setInBatchMode(true); // indicate we are starting up
461 JalviewTaskbar.setTaskbar(this);
462 } catch (Throwable t)
464 System.out.println("Error setting Taskbar: " + t.getMessage());
466 desktop.setVisible(true);
476 desktop.startServiceDiscovery();
477 if (!aparser.contains("nousagestats"))
479 startUsageStats(desktop);
483 System.err.println("CMD [-nousagestats] executed successfully!");
486 if (!aparser.contains("noquestionnaire"))
488 String url = aparser.getValue("questionnaire");
491 // Start the desktop questionnaire prompter with the specified
493 Cache.log.debug("Starting questionnaire url at " + url);
494 desktop.checkForQuestionnaire(url);
495 System.out.println("CMD questionnaire[-" + url
496 + "] executed successfully!");
500 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
502 // Start the desktop questionnaire prompter with the specified
505 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
507 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
509 "Starting questionnaire with default url: " + defurl);
510 desktop.checkForQuestionnaire(defurl);
517 .println("CMD [-noquestionnaire] executed successfully!");
520 if (!aparser.contains("nonews"))
522 desktop.checkForNews();
525 BioJsHTMLOutput.updateBioJS();
528 parseArguments(aparser, true);
532 * Parse all command-line String[] arguments as well as all JavaScript-derived
533 * parameters from Info.
535 * We allow for this method to be run from JavaScript. Basically allowing
541 public void parseArguments(ArgsParser aparser, boolean isStartup)
544 String groovyscript = null; // script to execute after all loading is
545 boolean isJS = Platform.isJS();
549 // Move any new getdown-launcher-new.jar into place over old
550 // getdown-launcher.jar
551 String appdirString = System.getProperty("getdownappdir");
552 if (appdirString != null && appdirString.length() > 0)
554 final File appdir = new File(appdirString);
560 LaunchUtil.upgradeGetdown(
561 new File(appdir, "getdown-launcher-old.jar"),
562 new File(appdir, "getdown-launcher.jar"),
563 new File(appdir, "getdown-launcher-new.jar"));
568 // completed one way or another
569 // extract groovy argument and execute if necessary
570 groovyscript = aparser.getValue("groovy", true);
574 String file = aparser.getValue("open", true);
576 if (!isJS && file == null && desktop == null)
578 System.out.println("No files to open!");
582 setDisplayParameters(aparser);
584 // time to open a file.
587 DataSourceType protocol = null;
588 FileLoader fileLoader = new FileLoader(!headless);
589 FileFormatI format = null;
590 // Finally, deal with the remaining input data.
591 AlignFrame af = null;
593 JalviewJSApp jsApp = (isJS ? new JalviewJSApp(this, aparser) : null);
599 // JalviewJS allows sequence1 sequence2 ....
602 else if (!headless && Cache.getDefault("SHOW_STARTUP_FILE", true))
610 // We'll only open the default file if the desktop is visible.
612 // ////////////////////
614 file = Cache.getDefault("STARTUP_FILE",
615 Cache.getDefault("www.jalview.org",
616 "http://www.jalview.org")
617 + "/examples/exampleFile_2_7.jar");
619 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
621 // hardwire upgrade of the startup file
622 file.replace("_2_3.jar", "_2_7.jar");
623 // and remove the stale setting
624 Cache.removeProperty("STARTUP_FILE");
627 protocol = DataSourceType.FILE;
629 if (file.indexOf("http:") > -1)
631 protocol = DataSourceType.URL;
634 if (file.endsWith(".jar"))
636 format = FileFormat.Jalview;
642 format = new IdentifyFile().identify(file, protocol);
643 } catch (FileFormatException e)
648 af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
655 desktop.setProgressBar(
657 .getString("status.processing_commandline_args"),
658 progress = System.currentTimeMillis());
660 System.out.println("CMD [-open " + file + "] executed successfully!");
662 if (!Platform.isJS())
664 * ignore in JavaScript -- can't just file existence - could load it?
669 if (!file.startsWith("http://") && !file.startsWith("https://"))
670 // BH 2019 added https check for Java
672 if (!(new File(file)).exists())
674 System.out.println("Can't find " + file);
683 String fileFormat = (isJS
684 ? (String) aparser.getAppletValue("format", null, true)
686 protocol = AppletFormatAdapter.checkProtocol(file);
689 format = (fileFormat != null
690 ? FileFormats.getInstance().forName(fileFormat)
694 format = new IdentifyFile().identify(file, protocol);
696 } catch (FileFormatException e1)
701 af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol,
705 System.out.println("jalview error - AlignFrame was not created");
710 // JalviewLite interface for JavaScript allows second file open
711 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
714 protocol = AppletFormatAdapter.checkProtocol(file2);
717 format = new IdentifyFile().identify(file2, protocol);
718 } catch (FileFormatException e1)
722 AlignFrame af2 = new FileLoader(!headless)
723 .LoadFileWaitTillLoaded(file2, protocol, format);
726 System.out.println("error");
730 AlignViewport.openLinkedAlignmentAs(af,
731 af.getViewport().getAlignment(),
732 af2.getViewport().getAlignment(), "",
733 AlignViewport.SPLIT_FRAME);
735 "CMD [-open2 " + file2 + "] executed successfully!");
738 setCurrentAlignFrame(af);
740 setFrameDependentProperties(aparser, af);
744 jsApp.initFromParams(af);
753 if (groovyscript != null)
755 // Execute the groovy script after we've done all the rendering
757 // and before any images or figures are generated.
758 System.out.println("Executing script " + groovyscript);
759 executeGroovyScript(groovyscript, af);
760 System.out.println("CMD groovy[" + groovyscript
761 + "] executed successfully!");
765 if (!isJS || !isStartup) {
766 createOutputFiles(aparser, format);
770 // extract groovy arguments before anything else.
771 // Once all other stuff is done, execute any groovy scripts (in order)
772 if (!isJS && groovyscript != null)
774 if (Cache.groovyJarsPresent())
776 System.out.println("Executing script " + groovyscript);
777 executeGroovyScript(groovyscript, af);
782 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
787 // and finally, turn off batch mode indicator - if the desktop still exists
792 desktop.setProgressBar(null, progress);
794 desktop.setInBatchMode(false);
798 jsApp.callInitCallback();
803 * Set general display parameters irrespective of file loading or headlessness.
807 private void setDisplayParameters(ArgsParser aparser)
809 if (aparser.contains(ArgsParser.NOMENUBAR))
812 System.out.println("CMD [nomenu] executed successfully!");
815 if (aparser.contains(ArgsParser.NOSTATUS))
818 System.out.println("CMD [nostatus] executed successfully!");
821 if (aparser.contains(ArgsParser.NOANNOTATION)
822 || aparser.contains(ArgsParser.NOANNOTATION2))
825 System.out.println("CMD no-annotation executed successfully!");
827 if (aparser.contains(ArgsParser.NOCALCULATION))
829 noCalculation = true;
830 System.out.println("CMD [nocalculation] executed successfully!");
835 private void setFrameDependentProperties(ArgsParser aparser,
838 String data = aparser.getValue(ArgsParser.COLOUR, true);
841 data.replaceAll("%20", " ");
843 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
844 af.getViewport(), af.getViewport().getAlignment(), data);
849 "CMD [-color " + data + "] executed successfully!");
854 // Must maintain ability to use the groups flag
855 data = aparser.getValue(ArgsParser.GROUPS, true);
858 af.parseFeaturesFile(data,
859 AppletFormatAdapter.checkProtocol(data));
860 // System.out.println("Added " + data);
862 "CMD groups[-" + data + "] executed successfully!");
864 data = aparser.getValue(ArgsParser.FEATURES, true);
867 af.parseFeaturesFile(data,
868 AppletFormatAdapter.checkProtocol(data));
869 // System.out.println("Added " + data);
871 "CMD [-features " + data + "] executed successfully!");
873 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
876 af.loadJalviewDataFile(data, null, null, null);
877 // System.out.println("Added " + data);
879 "CMD [-annotations " + data + "] executed successfully!");
882 // JavaScript feature
884 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
886 af.overviewMenuItem_actionPerformed(null);
887 System.out.println("CMD [showoverview] executed successfully!");
890 // set or clear the sortbytree flag.
891 if (aparser.contains(ArgsParser.SORTBYTREE))
893 af.getViewport().setSortByTree(true);
894 if (af.getViewport().getSortByTree())
896 System.out.println("CMD [-sortbytree] executed successfully!");
900 boolean doUpdateAnnotation = false;
902 * we do this earlier in JalviewJS because of a complication with
905 * For now, just fixing this in JalviewJS.
914 af.getViewport().setShowAnnotation(false);
915 if (!af.getViewport().isShowAnnotation())
917 doUpdateAnnotation = true;
922 if (aparser.contains(ArgsParser.NOSORTBYTREE))
924 af.getViewport().setSortByTree(false);
925 if (!af.getViewport().getSortByTree())
927 doUpdateAnnotation = true;
929 .println("CMD [-nosortbytree] executed successfully!");
932 if (doUpdateAnnotation)
934 af.setMenusForViewport();
935 af.alignPanel.updateLayout();
938 data = aparser.getValue(ArgsParser.TREE, true);
943 NewickFile nf = new NewickFile(data,
944 AppletFormatAdapter.checkProtocol(data));
946 .setCurrentTree(af.showNewickTree(nf, data).getTree());
948 "CMD [-tree " + data + "] executed successfully!");
949 } catch (IOException ex)
951 System.err.println("Couldn't add tree " + data);
952 ex.printStackTrace(System.err);
955 // TODO - load PDB structure(s) to alignment JAL-629
956 // (associate with identical sequence in alignment, or a specified
962 * Writes an output file for each format (if any) specified in the
963 * command-line arguments. Supported formats are currently
972 * A format parameter should be followed by a parameter specifying the output
973 * file name. {@code imgMap} parameters should follow those for the
974 * corresponding alignment image output.
979 private void createOutputFiles(ArgsParser aparser,
982 AlignFrame af = currentAlignFrame;
983 while (aparser.getSize() >= 2)
985 String outputFormat = aparser.nextValue();
988 switch (outputFormat.toLowerCase())
991 imageFile = new File(aparser.nextValue());
992 af.createPNG(imageFile);
994 "Creating PNG image: " + imageFile.getAbsolutePath());
997 imageFile = new File(aparser.nextValue());
998 af.createSVG(imageFile);
1000 "Creating SVG image: " + imageFile.getAbsolutePath());
1003 imageFile = new File(aparser.nextValue());
1005 "Creating EPS file: " + imageFile.getAbsolutePath());
1006 af.createEPS(imageFile);
1009 fname = new File(aparser.nextValue()).getAbsolutePath();
1012 BioJsHTMLOutput.refreshVersionInfo(
1013 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1014 } catch (URISyntaxException e)
1016 e.printStackTrace();
1018 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1019 bjs.exportHTML(fname);
1020 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
1023 fname = new File(aparser.nextValue()).getAbsolutePath();
1024 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1025 htmlSVG.exportHTML(fname);
1026 System.out.println("Creating HTML image: " + fname);
1029 imageFile = new File(aparser.nextValue());
1030 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1032 "Creating image map: " + imageFile.getAbsolutePath());
1035 if (!Platform.isJS()) /** @j2sIgnore */
1037 // skipping outputFormat?
1038 System.out.println("Unknown arg: " + outputFormat);
1039 fname = new File(aparser.nextValue()).getAbsolutePath();
1040 af.saveAlignment(fname, format);
1041 if (af.isSaveAlignmentSuccessful())
1044 "Written alignment in " + format + " format to " + fname);
1048 System.out.println("Error writing file " + fname + " in " + format
1054 while (aparser.getSize() > 0)
1056 System.out.println("Unknown arg: " + aparser.nextValue());
1060 private static void showUsage()
1063 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1064 + "-nodisplay\tRun Jalview without User Interface.\n"
1065 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1066 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1067 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1068 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1069 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1070 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1071 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1072 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1073 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1074 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1075 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1076 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1077 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1078 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1079 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1080 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1081 + "-html FILE\tCreate HTML file from alignment.\n"
1082 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1083 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1084 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1085 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1086 + "-noquestionnaire\tTurn off questionnaire check.\n"
1087 + "-nonews\tTurn off check for Jalview news.\n"
1088 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1089 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1091 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1092 // after all other properties files have been read\n\t
1093 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1094 // passed in correctly)"
1095 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1096 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1097 + "-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"
1098 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1101 private static void startUsageStats(final Desktop desktop)
1104 * start a User Config prompt asking if we can log usage statistics.
1106 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1107 "USAGESTATS", "Jalview Usage Statistics",
1108 "Do you want to help make Jalview better by enabling "
1109 + "the collection of usage statistics with Google Analytics ?"
1110 + "\n\n(you can enable or disable usage tracking in the preferences)",
1117 "Initialising googletracker for usage stats.");
1118 Cache.initGoogleTracker();
1119 Cache.log.debug("Tracking enabled.");
1126 Cache.log.debug("Not enabling Google Tracking.");
1129 desktop.addDialogThread(prompter);
1133 * Locate the given string as a file and pass it to the groovy interpreter.
1135 * @param groovyscript
1136 * the script to execute
1137 * @param jalviewContext
1138 * the Jalview Desktop object passed in to the groovy binding as the
1141 private void executeGroovyScript(String groovyscript, AlignFrame af)
1144 * for scripts contained in files
1151 if (groovyscript.trim().equals("STDIN"))
1153 // read from stdin into a tempfile and execute it
1156 tfile = File.createTempFile("jalview", "groovy");
1157 PrintWriter outfile = new PrintWriter(
1158 new OutputStreamWriter(new FileOutputStream(tfile)));
1159 BufferedReader br = new BufferedReader(
1160 new InputStreamReader(System.in));
1162 while ((line = br.readLine()) != null)
1164 outfile.write(line + "\n");
1170 } catch (Exception ex)
1172 System.err.println("Failed to read from STDIN into tempfile "
1173 + ((tfile == null) ? "(tempfile wasn't created)"
1174 : tfile.toString()));
1175 ex.printStackTrace();
1180 sfile = tfile.toURI().toURL();
1181 } catch (Exception x)
1184 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1186 x.printStackTrace();
1194 sfile = new URI(groovyscript).toURL();
1195 } catch (Exception x)
1197 tfile = new File(groovyscript);
1198 if (!tfile.exists())
1200 System.err.println("File '" + groovyscript + "' does not exist.");
1203 if (!tfile.canRead())
1205 System.err.println("File '" + groovyscript + "' cannot be read.");
1208 if (tfile.length() < 1)
1210 System.err.println("File '" + groovyscript + "' is empty.");
1215 sfile = tfile.getAbsoluteFile().toURI().toURL();
1216 } catch (Exception ex)
1218 System.err.println("Failed to create a file URL for "
1219 + tfile.getAbsoluteFile());
1226 Map<String, java.lang.Object> vbinding = new HashMap<>();
1227 vbinding.put("Jalview", this);
1230 vbinding.put("currentAlFrame", af);
1232 Binding gbinding = new Binding(vbinding);
1233 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1234 gse.run(sfile.toString(), gbinding);
1235 if ("STDIN".equals(groovyscript))
1237 // delete temp file that we made -
1238 // only if it was successfully executed
1241 } catch (Exception e)
1243 System.err.println("Exception Whilst trying to execute file " + sfile
1244 + " as a groovy script.");
1245 e.printStackTrace(System.err);
1250 public static boolean isHeadlessMode()
1252 String isheadless = System.getProperty("java.awt.headless");
1253 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1260 public AlignFrame[] getAlignFrames()
1262 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1263 : Desktop.getAlignFrames();
1268 * Quit method delegates to Desktop.quit - unless running in headless mode
1269 * when it just ends the JVM
1273 if (desktop != null)
1283 public static AlignFrame getCurrentAlignFrame()
1285 return Jalview.getInstance().currentAlignFrame;
1288 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1290 Jalview.getInstance().currentAlignFrame = currentAlignFrame;
1294 public void notifyWorker(AlignCalcWorkerI worker, String status)
1296 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
1301 private static boolean isInteractive = true;
1303 public static boolean isInteractive()
1305 return isInteractive;
1308 public static void setInteractive(boolean tf)