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.awt.GraphicsEnvironment;
24 import java.io.BufferedReader;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.io.OutputStreamWriter;
30 import java.io.PrintWriter;
31 import java.net.MalformedURLException;
33 import java.net.URISyntaxException;
35 import java.security.AllPermission;
36 import java.security.CodeSource;
37 import java.security.PermissionCollection;
38 import java.security.Permissions;
39 import java.security.Policy;
40 import java.util.HashMap;
42 import java.util.Vector;
44 import javax.swing.LookAndFeel;
45 import javax.swing.UIManager;
47 import com.threerings.getdown.util.LaunchUtil;
49 import groovy.lang.Binding;
50 import groovy.util.GroovyScriptEngine;
51 import jalview.api.AlignCalcWorkerI;
52 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
53 import jalview.ext.so.SequenceOntology;
54 import jalview.gui.AlignFrame;
55 import jalview.gui.AlignViewport;
56 import jalview.gui.Desktop;
57 import jalview.gui.Preferences;
58 import jalview.gui.PromptUserConfig;
59 import jalview.io.AppletFormatAdapter;
60 import jalview.io.BioJsHTMLOutput;
61 import jalview.io.DataSourceType;
62 import jalview.io.FileFormat;
63 import jalview.io.FileFormatException;
64 import jalview.io.FileFormatI;
65 import jalview.io.FileFormats;
66 import jalview.io.FileLoader;
67 import jalview.io.HtmlSvgOutput;
68 import jalview.io.IdentifyFile;
69 import jalview.io.NewickFile;
70 import jalview.io.gff.SequenceOntologyFactory;
71 import jalview.schemes.ColourSchemeI;
72 import jalview.schemes.ColourSchemeProperty;
73 import jalview.util.MessageManager;
74 import jalview.util.Platform;
75 import jalview.ws.jws2.Jws2Discoverer;
76 //import netscape.javascript.JSObject;
79 * Main class for Jalview Application <br>
81 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
84 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
85 * jalview.bin.Jalview jalview.bin.Jalview
87 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
88 * embellish '*' to e.g. '*.jar')
93 public class Jalview implements ApplicationSingletonI
96 // for testing those nasty messages you cannot ever find.
99 // System.setOut(new PrintStream(new ByteArrayOutputStream())
102 // public void println(Object o)
106 // System.err.println(o);
112 public static Jalview getInstance()
114 System.out.println("Hello, MW!!!!!!!!!!!!");
115 return (Jalview) ApplicationSingletonProvider
116 .getInstance(Jalview.class);
123 private boolean headless;
125 private Desktop desktop;
127 public AlignFrame currentAlignFrame;
129 public String appletResourcePath;
131 public String j2sAppletID;
133 private boolean noCalculation, noMenuBar, noStatus;
135 private boolean noAnnotation;
137 public boolean getStartCalculations()
139 return !noCalculation;
142 public boolean getAllowMenuBar()
147 public boolean getShowStatus()
152 public boolean getShowAnnotation()
154 return !noAnnotation;
159 if (Platform.isJS()) {
160 Platform.getURLCommandArguments();
161 } else /** @j2sIgnore */
163 // grab all the rights we can for the JVM
164 Policy.setPolicy(new Policy()
167 public PermissionCollection getPermissions(CodeSource codesource)
169 Permissions perms = new Permissions();
170 perms.add(new AllPermission());
175 public void refresh()
183 * keep track of feature fetching tasks.
191 * TODO: generalise to track all jalview events to orchestrate batch processing
195 private int queued = 0;
197 private int running = 0;
199 public FeatureFetcher()
204 public void addFetcher(final AlignFrame af,
205 final Vector<String> dasSources)
207 final long id = System.currentTimeMillis();
209 final FeatureFetcher us = this;
210 new Thread(new Runnable()
222 af.setProgressBar(MessageManager
223 .getString("status.das_features_being_retrived"), id);
224 af.featureSettings_actionPerformed(null);
225 af.setProgressBar(null, id);
234 public synchronized boolean allFinished()
236 return queued == 0 && running == 0;
241 private final static boolean doPlatformLogging = false;
244 * main class for Jalview application
247 * open <em>filename</em>
249 public static void main(String[] args)
251 if (doPlatformLogging)
253 Platform.startJavaLogging();
255 getInstance().doMain(args);
261 void doMain(String[] args)
264 boolean isJS = Platform.isJS();
267 System.setSecurityManager(null);
271 .println("Java version: " + System.getProperty("java.version"));
272 System.out.println("Java Home: " + System.getProperty("java.home"));
273 System.out.println(System.getProperty("os.arch") + " "
274 + System.getProperty("os.name") + " "
275 + System.getProperty("os.version"));
276 String val = System.getProperty("sys.install4jVersion");
279 System.out.println("Install4j version: " + val);
281 val = System.getProperty("installer_template_version");
284 System.out.println("Install4j template version: " + val);
286 val = System.getProperty("launcher_version");
289 System.out.println("Launcher version: " + val);
292 // report Jalview version
293 Cache.getInstance().loadBuildProperties(true);
295 ArgsParser aparser = new ArgsParser(args);
298 String usrPropsFile = aparser.getValue("props");
300 Cache.loadProperties(usrPropsFile); // must do this before
302 boolean allowServices = true;
306 j2sAppletID = Platform.getAppID(null);
307 Preferences.setAppletDefaults();
308 Cache.loadProperties(usrPropsFile); // again, because we
309 // might be changing defaults here?
310 appletResourcePath = (String) aparser.getAppletValue("resourcepath",
321 if (usrPropsFile != null)
324 "CMD [-props " + usrPropsFile + "] executed successfully!");
326 if (aparser.contains("help") || aparser.contains("h"))
331 // BH note: Only -nodisplay is official; others are deprecated?
332 if (aparser.contains("nodisplay") || aparser.contains("nogui")
333 || aparser.contains("headless")
334 || GraphicsEnvironment.isHeadless())
337 // BH Definitely not a good idea in JavaScript;
338 // probably should not be here for Java, either.
339 System.setProperty("java.awt.headless", "true");
343 if (GraphicsEnvironment.isHeadless())
351 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
352 allowServices = !("none".equals(jabawsUrl));
353 if (allowServices && jabawsUrl != null)
357 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
359 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
360 } catch (MalformedURLException e)
363 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
368 String defs = aparser.getValue(ArgsParser.SETPROP);
371 int p = defs.indexOf('=');
374 System.err.println("Ignoring invalid setprop argument : " + defs);
378 System.out.println("Executing setprop argument: " + defs);
381 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
384 defs = aparser.getValue("setprop");
386 System.setProperty("http.agent",
387 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
391 } catch (NoClassDefFoundError error)
393 error.printStackTrace();
394 System.out.println("\nEssential logging libraries not found."
395 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
404 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
405 } catch (Exception ex)
407 System.err.println("Unexpected Look and Feel Exception");
408 ex.printStackTrace();
410 if (Platform.isMac())
413 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
416 "com.apple.mrj.application.apple.menu.about.name",
418 System.setProperty("apple.laf.useScreenMenuBar", "true");
419 if (lookAndFeel != null)
423 UIManager.setLookAndFeel(lookAndFeel);
424 } catch (Throwable e)
427 "Failed to set QuaQua look and feel: " + e.toString());
430 if (lookAndFeel == null
431 || !(lookAndFeel.getClass().isAssignableFrom(
432 UIManager.getLookAndFeel().getClass()))
433 || !UIManager.getLookAndFeel().getClass().toString()
434 .toLowerCase().contains("quaqua"))
439 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
440 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
441 } catch (Throwable e)
444 "Failed to reset look and feel: " + e.toString());
450 * configure 'full' SO model if preferences say to, else use the default (full SO)
451 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
453 boolean soDefault = !isJS;
454 if (Cache.getDefault("USE_FULL_SO", soDefault))
456 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
463 desktop = Desktop.getInstance();
464 desktop.setInBatchMode(true); // indicate we are starting up
467 JalviewTaskbar.setTaskbar(this);
468 } catch (Throwable t)
470 System.out.println("Error setting Taskbar: " + t.getMessage());
472 desktop.setVisible(true);
482 desktop.startServiceDiscovery();
483 if (!aparser.contains("nousagestats"))
485 startUsageStats(desktop);
489 System.err.println("CMD [-nousagestats] executed successfully!");
492 if (!aparser.contains("noquestionnaire"))
494 String url = aparser.getValue("questionnaire");
497 // Start the desktop questionnaire prompter with the specified
499 Cache.log.debug("Starting questionnaire url at " + url);
500 desktop.checkForQuestionnaire(url);
501 System.out.println("CMD questionnaire[-" + url
502 + "] executed successfully!");
506 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
508 // Start the desktop questionnaire prompter with the specified
511 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
513 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
515 "Starting questionnaire with default url: " + defurl);
516 desktop.checkForQuestionnaire(defurl);
523 .println("CMD [-noquestionnaire] executed successfully!");
526 if (!aparser.contains("nonews"))
528 desktop.checkForNews();
531 BioJsHTMLOutput.updateBioJS();
534 parseArguments(aparser, true);
538 * Parse all command-line String[] arguments as well as all JavaScript-derived
539 * parameters from Info.
541 * We allow for this method to be run from JavaScript. Basically allowing
547 public void parseArguments(ArgsParser aparser, boolean isStartup)
550 String groovyscript = null; // script to execute after all loading is
551 boolean isJS = Platform.isJS();
555 // Move any new getdown-launcher-new.jar into place over old
556 // getdown-launcher.jar
557 String appdirString = System.getProperty("getdownappdir");
558 if (appdirString != null && appdirString.length() > 0)
560 final File appdir = new File(appdirString);
566 LaunchUtil.upgradeGetdown(
567 new File(appdir, "getdown-launcher-old.jar"),
568 new File(appdir, "getdown-launcher.jar"),
569 new File(appdir, "getdown-launcher-new.jar"));
574 // completed one way or another
575 // extract groovy argument and execute if necessary
576 groovyscript = aparser.getValue("groovy", true);
580 String file = aparser.getValue("open", true);
582 if (!isJS && file == null && desktop == null)
584 System.out.println("No files to open!");
588 setDisplayParameters(aparser);
590 // time to open a file.
593 DataSourceType protocol = null;
594 FileLoader fileLoader = new FileLoader(!headless);
595 FileFormatI format = null;
596 // Finally, deal with the remaining input data.
597 AlignFrame af = null;
599 JalviewJSApp jsApp = (isJS ? new JalviewJSApp(this, aparser) : null);
605 // JalviewJS allows sequence1 sequence2 ....
608 else if (!headless && Cache.getDefault("SHOW_STARTUP_FILE", true))
616 // We'll only open the default file if the desktop is visible.
618 // ////////////////////
620 file = Cache.getDefault("STARTUP_FILE",
621 Cache.getDefault("www.jalview.org",
622 "http://www.jalview.org")
623 + "/examples/exampleFile_2_7.jar");
625 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
627 // hardwire upgrade of the startup file
628 file.replace("_2_3.jar", "_2_7.jar");
629 // and remove the stale setting
630 Cache.removeProperty("STARTUP_FILE");
633 protocol = DataSourceType.FILE;
635 if (file.indexOf("http:") > -1)
637 protocol = DataSourceType.URL;
640 if (file.endsWith(".jar"))
642 format = FileFormat.Jalview;
648 format = new IdentifyFile().identify(file, protocol);
649 } catch (FileFormatException e)
654 af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
661 desktop.setProgressBar(
663 .getString("status.processing_commandline_args"),
664 progress = System.currentTimeMillis());
666 System.out.println("CMD [-open " + file + "] executed successfully!");
668 if (!Platform.isJS())
670 * ignore in JavaScript -- can't just file existence - could load it?
675 if (!file.startsWith("http://") && !file.startsWith("https://"))
676 // BH 2019 added https check for Java
678 if (!(new File(file)).exists())
680 System.out.println("Can't find " + file);
689 String fileFormat = (isJS
690 ? (String) aparser.getAppletValue("format", null, true)
692 protocol = AppletFormatAdapter.checkProtocol(file);
695 format = (fileFormat != null
696 ? FileFormats.getInstance().forName(fileFormat)
700 format = new IdentifyFile().identify(file, protocol);
702 } catch (FileFormatException e1)
707 af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol,
711 System.out.println("jalview error - AlignFrame was not created");
716 // JalviewLite interface for JavaScript allows second file open
717 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
720 protocol = AppletFormatAdapter.checkProtocol(file2);
723 format = new IdentifyFile().identify(file2, protocol);
724 } catch (FileFormatException e1)
728 AlignFrame af2 = new FileLoader(!headless)
729 .LoadFileWaitTillLoaded(file2, protocol, format);
732 System.out.println("error");
736 AlignViewport.openLinkedAlignmentAs(af,
737 af.getViewport().getAlignment(),
738 af2.getViewport().getAlignment(), "",
739 AlignViewport.SPLIT_FRAME);
741 "CMD [-open2 " + file2 + "] executed successfully!");
744 setCurrentAlignFrame(af);
746 setFrameDependentProperties(aparser, af);
750 jsApp.initFromParams(af);
759 if (groovyscript != null)
761 // Execute the groovy script after we've done all the rendering
763 // and before any images or figures are generated.
764 System.out.println("Executing script " + groovyscript);
765 executeGroovyScript(groovyscript, af);
766 System.out.println("CMD groovy[" + groovyscript
767 + "] executed successfully!");
771 if (!isJS || !isStartup) {
772 createOutputFiles(aparser, format);
776 // extract groovy arguments before anything else.
777 // Once all other stuff is done, execute any groovy scripts (in order)
778 if (!isJS && groovyscript != null)
780 if (Cache.groovyJarsPresent())
782 System.out.println("Executing script " + groovyscript);
783 executeGroovyScript(groovyscript, af);
788 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
793 // and finally, turn off batch mode indicator - if the desktop still exists
798 desktop.setProgressBar(null, progress);
800 desktop.setInBatchMode(false);
804 jsApp.callInitCallback();
809 * Set general display parameters irrespective of file loading or headlessness.
813 private void setDisplayParameters(ArgsParser aparser)
815 if (aparser.contains(ArgsParser.NOMENUBAR))
818 System.out.println("CMD [nomenu] executed successfully!");
821 if (aparser.contains(ArgsParser.NOSTATUS))
824 System.out.println("CMD [nostatus] executed successfully!");
827 if (aparser.contains(ArgsParser.NOANNOTATION)
828 || aparser.contains(ArgsParser.NOANNOTATION2))
831 System.out.println("CMD no-annotation executed successfully!");
833 if (aparser.contains(ArgsParser.NOCALCULATION))
835 noCalculation = true;
836 System.out.println("CMD [nocalculation] executed successfully!");
841 private void setFrameDependentProperties(ArgsParser aparser,
844 String data = aparser.getValue(ArgsParser.COLOUR, true);
847 data.replaceAll("%20", " ");
849 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
850 af.getViewport(), af.getViewport().getAlignment(), data);
855 "CMD [-color " + data + "] executed successfully!");
860 // Must maintain ability to use the groups flag
861 data = aparser.getValue(ArgsParser.GROUPS, true);
864 af.parseFeaturesFile(data,
865 AppletFormatAdapter.checkProtocol(data));
866 // System.out.println("Added " + data);
868 "CMD groups[-" + data + "] executed successfully!");
870 data = aparser.getValue(ArgsParser.FEATURES, true);
873 af.parseFeaturesFile(data,
874 AppletFormatAdapter.checkProtocol(data));
875 // System.out.println("Added " + data);
877 "CMD [-features " + data + "] executed successfully!");
879 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
882 af.loadJalviewDataFile(data, null, null, null);
883 // System.out.println("Added " + data);
885 "CMD [-annotations " + data + "] executed successfully!");
888 // JavaScript feature
890 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
892 af.overviewMenuItem_actionPerformed(null);
893 System.out.println("CMD [showoverview] executed successfully!");
896 // set or clear the sortbytree flag.
897 if (aparser.contains(ArgsParser.SORTBYTREE))
899 af.getViewport().setSortByTree(true);
900 if (af.getViewport().getSortByTree())
902 System.out.println("CMD [-sortbytree] executed successfully!");
906 boolean doUpdateAnnotation = false;
908 * we do this earlier in JalviewJS because of a complication with
911 * For now, just fixing this in JalviewJS.
920 af.getViewport().setShowAnnotation(false);
921 if (!af.getViewport().isShowAnnotation())
923 doUpdateAnnotation = true;
928 if (aparser.contains(ArgsParser.NOSORTBYTREE))
930 af.getViewport().setSortByTree(false);
931 if (!af.getViewport().getSortByTree())
933 doUpdateAnnotation = true;
935 .println("CMD [-nosortbytree] executed successfully!");
938 if (doUpdateAnnotation)
940 af.setMenusForViewport();
941 af.alignPanel.updateLayout();
944 data = aparser.getValue(ArgsParser.TREE, true);
949 NewickFile nf = new NewickFile(data,
950 AppletFormatAdapter.checkProtocol(data));
952 .setCurrentTree(af.showNewickTree(nf, data).getTree());
954 "CMD [-tree " + data + "] executed successfully!");
955 } catch (IOException ex)
957 System.err.println("Couldn't add tree " + data);
958 ex.printStackTrace(System.err);
961 // TODO - load PDB structure(s) to alignment JAL-629
962 // (associate with identical sequence in alignment, or a specified
968 * Writes an output file for each format (if any) specified in the
969 * command-line arguments. Supported formats are currently
978 * A format parameter should be followed by a parameter specifying the output
979 * file name. {@code imgMap} parameters should follow those for the
980 * corresponding alignment image output.
985 private void createOutputFiles(ArgsParser aparser,
988 AlignFrame af = currentAlignFrame;
989 while (aparser.getSize() >= 2)
991 String outputFormat = aparser.nextValue();
994 switch (outputFormat.toLowerCase())
997 imageFile = new File(aparser.nextValue());
998 af.createPNG(imageFile);
1000 "Creating PNG image: " + imageFile.getAbsolutePath());
1003 imageFile = new File(aparser.nextValue());
1004 af.createSVG(imageFile);
1006 "Creating SVG image: " + imageFile.getAbsolutePath());
1009 imageFile = new File(aparser.nextValue());
1011 "Creating EPS file: " + imageFile.getAbsolutePath());
1012 af.createEPS(imageFile);
1015 fname = new File(aparser.nextValue()).getAbsolutePath();
1018 BioJsHTMLOutput.refreshVersionInfo(
1019 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1020 } catch (URISyntaxException e)
1022 e.printStackTrace();
1024 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1025 bjs.exportHTML(fname);
1026 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
1029 fname = new File(aparser.nextValue()).getAbsolutePath();
1030 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1031 htmlSVG.exportHTML(fname);
1032 System.out.println("Creating HTML image: " + fname);
1035 imageFile = new File(aparser.nextValue());
1036 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1038 "Creating image map: " + imageFile.getAbsolutePath());
1041 format = FileFormats.getInstance().forName(outputFormat);
1044 System.out.println("Invalid file format: " + outputFormat);
1047 fname = new File(aparser.nextValue()).getAbsolutePath();
1048 af.saveAlignment(fname, format);
1049 if (!af.isSaveAlignmentSuccessful())
1051 System.out.println("Error writing file " + fname + " in " + format
1057 System.out.println("Unknown arg: " + outputFormat);
1060 while (aparser.getSize() > 0)
1062 System.out.println("Unknown arg: " + aparser.nextValue());
1066 private static void showUsage()
1069 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1070 + "-nodisplay\tRun Jalview without User Interface.\n"
1071 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1072 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1073 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1074 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1075 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1076 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1077 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1078 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1079 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1080 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1081 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1082 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1083 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1084 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1085 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1086 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1087 + "-html FILE\tCreate HTML file from alignment.\n"
1088 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1089 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1090 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1091 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1092 + "-noquestionnaire\tTurn off questionnaire check.\n"
1093 + "-nonews\tTurn off check for Jalview news.\n"
1094 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1095 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1097 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1098 // after all other properties files have been read\n\t
1099 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1100 // passed in correctly)"
1101 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1102 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1103 + "-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"
1104 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1107 private static void startUsageStats(final Desktop desktop)
1110 * start a User Config prompt asking if we can log usage statistics.
1112 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1113 "USAGESTATS", "Jalview Usage Statistics",
1114 "Do you want to help make Jalview better by enabling "
1115 + "the collection of usage statistics with Google Analytics ?"
1116 + "\n\n(you can enable or disable usage tracking in the preferences)",
1123 "Initialising googletracker for usage stats.");
1124 Cache.initGoogleTracker();
1125 Cache.log.debug("Tracking enabled.");
1132 Cache.log.debug("Not enabling Google Tracking.");
1135 desktop.addDialogThread(prompter);
1139 * Locate the given string as a file and pass it to the groovy interpreter.
1141 * @param groovyscript
1142 * the script to execute
1143 * @param jalviewContext
1144 * the Jalview Desktop object passed in to the groovy binding as the
1147 private void executeGroovyScript(String groovyscript, AlignFrame af)
1150 * for scripts contained in files
1157 if (groovyscript.trim().equals("STDIN"))
1159 // read from stdin into a tempfile and execute it
1162 tfile = File.createTempFile("jalview", "groovy");
1163 PrintWriter outfile = new PrintWriter(
1164 new OutputStreamWriter(new FileOutputStream(tfile)));
1165 BufferedReader br = new BufferedReader(
1166 new InputStreamReader(System.in));
1168 while ((line = br.readLine()) != null)
1170 outfile.write(line + "\n");
1176 } catch (Exception ex)
1178 System.err.println("Failed to read from STDIN into tempfile "
1179 + ((tfile == null) ? "(tempfile wasn't created)"
1180 : tfile.toString()));
1181 ex.printStackTrace();
1186 sfile = tfile.toURI().toURL();
1187 } catch (Exception x)
1190 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1192 x.printStackTrace();
1200 sfile = new URI(groovyscript).toURL();
1201 } catch (Exception x)
1203 tfile = new File(groovyscript);
1204 if (!tfile.exists())
1206 System.err.println("File '" + groovyscript + "' does not exist.");
1209 if (!tfile.canRead())
1211 System.err.println("File '" + groovyscript + "' cannot be read.");
1214 if (tfile.length() < 1)
1216 System.err.println("File '" + groovyscript + "' is empty.");
1221 sfile = tfile.getAbsoluteFile().toURI().toURL();
1222 } catch (Exception ex)
1224 System.err.println("Failed to create a file URL for "
1225 + tfile.getAbsoluteFile());
1232 Map<String, java.lang.Object> vbinding = new HashMap<>();
1233 vbinding.put("Jalview", this);
1236 vbinding.put("currentAlFrame", af);
1238 Binding gbinding = new Binding(vbinding);
1239 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1240 gse.run(sfile.toString(), gbinding);
1241 if ("STDIN".equals(groovyscript))
1243 // delete temp file that we made -
1244 // only if it was successfully executed
1247 } catch (Exception e)
1249 System.err.println("Exception Whilst trying to execute file " + sfile
1250 + " as a groovy script.");
1251 e.printStackTrace(System.err);
1256 public static boolean isHeadlessMode()
1258 String isheadless = System.getProperty("java.awt.headless");
1259 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1266 public AlignFrame[] getAlignFrames()
1268 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1269 : Desktop.getAlignFrames();
1274 * Quit method delegates to Desktop.quit - unless running in headless mode
1275 * when it just ends the JVM
1279 if (desktop != null)
1289 public static AlignFrame getCurrentAlignFrame()
1291 return Jalview.getInstance().currentAlignFrame;
1294 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1296 Jalview.getInstance().currentAlignFrame = currentAlignFrame;
1300 public void notifyWorker(AlignCalcWorkerI worker, String status)
1302 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
1307 private static boolean isInteractive = true;
1309 public static boolean isInteractive()
1311 return isInteractive;
1314 public static void setInteractive(boolean tf)