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 System.out.println("Hello, MW!!!!!!!!!!!!");
114 return (Jalview) ApplicationSingletonProvider
115 .getInstance(Jalview.class);
122 private boolean headless;
124 private Desktop desktop;
126 public AlignFrame currentAlignFrame;
128 public String appletResourcePath;
130 public String j2sAppletID;
132 private boolean noCalculation, noMenuBar, noStatus;
134 private boolean noAnnotation;
136 public boolean getStartCalculations()
138 return !noCalculation;
141 public boolean getAllowMenuBar()
146 public boolean getShowStatus()
151 public boolean getShowAnnotation()
153 return !noAnnotation;
158 if (Platform.isJS()) {
159 Platform.getURLCommandArguments();
160 } else /** @j2sIgnore */
162 // grab all the rights we can for the JVM
163 Policy.setPolicy(new Policy()
166 public PermissionCollection getPermissions(CodeSource codesource)
168 Permissions perms = new Permissions();
169 perms.add(new AllPermission());
174 public void refresh()
182 * keep track of feature fetching tasks.
190 * TODO: generalise to track all jalview events to orchestrate batch processing
194 private int queued = 0;
196 private int running = 0;
198 public FeatureFetcher()
203 public void addFetcher(final AlignFrame af,
204 final Vector<String> dasSources)
206 final long id = System.currentTimeMillis();
208 final FeatureFetcher us = this;
209 new Thread(new Runnable()
221 af.setProgressBar(MessageManager
222 .getString("status.das_features_being_retrived"), id);
223 af.featureSettings_actionPerformed(null);
224 af.setProgressBar(null, id);
233 public synchronized boolean allFinished()
235 return queued == 0 && running == 0;
240 private final static boolean doPlatformLogging = false;
243 * main class for Jalview application
246 * open <em>filename</em>
248 public static void main(String[] args)
250 if (doPlatformLogging)
252 Platform.startJavaLogging();
254 getInstance().doMain(args);
260 void doMain(String[] args)
263 boolean isJS = Platform.isJS();
266 System.setSecurityManager(null);
270 .println("Java version: " + System.getProperty("java.version"));
271 System.out.println("Java Home: " + System.getProperty("java.home"));
272 System.out.println(System.getProperty("os.arch") + " "
273 + System.getProperty("os.name") + " "
274 + System.getProperty("os.version"));
275 String val = System.getProperty("sys.install4jVersion");
278 System.out.println("Install4j version: " + val);
280 val = System.getProperty("installer_template_version");
283 System.out.println("Install4j template version: " + val);
285 val = System.getProperty("launcher_version");
288 System.out.println("Launcher version: " + val);
291 // report Jalview version
292 Cache.getInstance().loadBuildProperties(true);
294 ArgsParser aparser = new ArgsParser(args);
297 String usrPropsFile = aparser.getValue("props");
299 Cache.loadProperties(usrPropsFile); // must do this before
301 boolean allowServices = true;
305 j2sAppletID = Platform.getAppID(null);
306 Preferences.setAppletDefaults();
307 Cache.loadProperties(usrPropsFile); // again, because we
308 // might be changing defaults here?
309 appletResourcePath = (String) aparser.getAppletValue("resourcepath",
320 if (usrPropsFile != null)
323 "CMD [-props " + usrPropsFile + "] executed successfully!");
325 if (aparser.contains("help") || aparser.contains("h"))
331 if (aparser.contains("nodisplay") || aparser.contains("nogui")
332 || aparser.contains("headless"))
334 // BH Is this necessary? Seems like a hack; was removed for applet branch
335 System.setProperty("java.awt.headless", "true");
338 if ("true".equals(System.getProperty("java.awt.headless")))
346 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
347 allowServices = !("none".equals(jabawsUrl));
348 if (allowServices && jabawsUrl != null)
352 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
354 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
355 } catch (MalformedURLException e)
358 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
363 String defs = aparser.getValue(ArgsParser.SETPROP);
366 int p = defs.indexOf('=');
369 System.err.println("Ignoring invalid setprop argument : " + defs);
373 System.out.println("Executing setprop argument: " + defs);
376 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
379 defs = aparser.getValue("setprop");
381 System.setProperty("http.agent",
382 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
386 } catch (NoClassDefFoundError error)
388 error.printStackTrace();
389 System.out.println("\nEssential logging libraries not found."
390 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
399 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
400 } catch (Exception ex)
402 System.err.println("Unexpected Look and Feel Exception");
403 ex.printStackTrace();
405 if (Platform.isMac())
408 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
411 "com.apple.mrj.application.apple.menu.about.name",
413 System.setProperty("apple.laf.useScreenMenuBar", "true");
414 if (lookAndFeel != null)
418 UIManager.setLookAndFeel(lookAndFeel);
419 } catch (Throwable e)
422 "Failed to set QuaQua look and feel: " + e.toString());
425 if (lookAndFeel == null
426 || !(lookAndFeel.getClass().isAssignableFrom(
427 UIManager.getLookAndFeel().getClass()))
428 || !UIManager.getLookAndFeel().getClass().toString()
429 .toLowerCase().contains("quaqua"))
434 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
435 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
436 } catch (Throwable e)
439 "Failed to reset look and feel: " + e.toString());
445 * configure 'full' SO model if preferences say to, else use the default (full SO)
446 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
448 boolean soDefault = !isJS;
449 if (Cache.getDefault("USE_FULL_SO", soDefault))
451 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
458 desktop = Desktop.getInstance();
459 desktop.setInBatchMode(true); // indicate we are starting up
462 JalviewTaskbar.setTaskbar(this);
463 } catch (Throwable t)
465 System.out.println("Error setting Taskbar: " + t.getMessage());
467 desktop.setVisible(true);
477 desktop.startServiceDiscovery();
478 if (!aparser.contains("nousagestats"))
480 startUsageStats(desktop);
484 System.err.println("CMD [-nousagestats] executed successfully!");
487 if (!aparser.contains("noquestionnaire"))
489 String url = aparser.getValue("questionnaire");
492 // Start the desktop questionnaire prompter with the specified
494 Cache.log.debug("Starting questionnaire url at " + url);
495 desktop.checkForQuestionnaire(url);
496 System.out.println("CMD questionnaire[-" + url
497 + "] executed successfully!");
501 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
503 // Start the desktop questionnaire prompter with the specified
506 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
508 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
510 "Starting questionnaire with default url: " + defurl);
511 desktop.checkForQuestionnaire(defurl);
518 .println("CMD [-noquestionnaire] executed successfully!");
521 if (!aparser.contains("nonews"))
523 desktop.checkForNews();
526 BioJsHTMLOutput.updateBioJS();
529 parseArguments(aparser, true);
533 * Parse all command-line String[] arguments as well as all JavaScript-derived
534 * parameters from Info.
536 * We allow for this method to be run from JavaScript. Basically allowing
542 public void parseArguments(ArgsParser aparser, boolean isStartup)
545 String groovyscript = null; // script to execute after all loading is
546 boolean isJS = Platform.isJS();
550 // Move any new getdown-launcher-new.jar into place over old
551 // getdown-launcher.jar
552 String appdirString = System.getProperty("getdownappdir");
553 if (appdirString != null && appdirString.length() > 0)
555 final File appdir = new File(appdirString);
561 LaunchUtil.upgradeGetdown(
562 new File(appdir, "getdown-launcher-old.jar"),
563 new File(appdir, "getdown-launcher.jar"),
564 new File(appdir, "getdown-launcher-new.jar"));
569 // completed one way or another
570 // extract groovy argument and execute if necessary
571 groovyscript = aparser.getValue("groovy", true);
575 String file = aparser.getValue("open", true);
577 if (!isJS && file == null && desktop == null)
579 System.out.println("No files to open!");
583 setDisplayParameters(aparser);
585 // time to open a file.
588 DataSourceType protocol = null;
589 FileLoader fileLoader = new FileLoader(!headless);
590 FileFormatI format = null;
591 // Finally, deal with the remaining input data.
592 AlignFrame af = null;
594 JalviewJSApp jsApp = (isJS ? new JalviewJSApp(this, aparser) : null);
600 // JalviewJS allows sequence1 sequence2 ....
603 else if (!headless && Cache.getDefault("SHOW_STARTUP_FILE", true))
611 // We'll only open the default file if the desktop is visible.
613 // ////////////////////
615 file = Cache.getDefault("STARTUP_FILE",
616 Cache.getDefault("www.jalview.org",
617 "http://www.jalview.org")
618 + "/examples/exampleFile_2_7.jar");
620 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
622 // hardwire upgrade of the startup file
623 file.replace("_2_3.jar", "_2_7.jar");
624 // and remove the stale setting
625 Cache.removeProperty("STARTUP_FILE");
628 protocol = DataSourceType.FILE;
630 if (file.indexOf("http:") > -1)
632 protocol = DataSourceType.URL;
635 if (file.endsWith(".jar"))
637 format = FileFormat.Jalview;
643 format = new IdentifyFile().identify(file, protocol);
644 } catch (FileFormatException e)
649 af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
656 desktop.setProgressBar(
658 .getString("status.processing_commandline_args"),
659 progress = System.currentTimeMillis());
661 System.out.println("CMD [-open " + file + "] executed successfully!");
663 if (!Platform.isJS())
665 * ignore in JavaScript -- can't just file existence - could load it?
670 if (!file.startsWith("http://") && !file.startsWith("https://"))
671 // BH 2019 added https check for Java
673 if (!(new File(file)).exists())
675 System.out.println("Can't find " + file);
684 String fileFormat = (isJS
685 ? (String) aparser.getAppletValue("format", null, true)
687 protocol = AppletFormatAdapter.checkProtocol(file);
690 format = (fileFormat != null
691 ? FileFormats.getInstance().forName(fileFormat)
695 format = new IdentifyFile().identify(file, protocol);
697 } catch (FileFormatException e1)
702 af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol,
706 System.out.println("jalview error - AlignFrame was not created");
711 // JalviewLite interface for JavaScript allows second file open
712 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
715 protocol = AppletFormatAdapter.checkProtocol(file2);
718 format = new IdentifyFile().identify(file2, protocol);
719 } catch (FileFormatException e1)
723 AlignFrame af2 = new FileLoader(!headless)
724 .LoadFileWaitTillLoaded(file2, protocol, format);
727 System.out.println("error");
731 AlignViewport.openLinkedAlignmentAs(af,
732 af.getViewport().getAlignment(),
733 af2.getViewport().getAlignment(), "",
734 AlignViewport.SPLIT_FRAME);
736 "CMD [-open2 " + file2 + "] executed successfully!");
739 setCurrentAlignFrame(af);
741 setFrameDependentProperties(aparser, af);
745 jsApp.initFromParams(af);
754 if (groovyscript != null)
756 // Execute the groovy script after we've done all the rendering
758 // and before any images or figures are generated.
759 System.out.println("Executing script " + groovyscript);
760 executeGroovyScript(groovyscript, af);
761 System.out.println("CMD groovy[" + groovyscript
762 + "] executed successfully!");
766 if (!isJS || !isStartup) {
767 createOutputFiles(aparser, format);
771 // extract groovy arguments before anything else.
772 // Once all other stuff is done, execute any groovy scripts (in order)
773 if (!isJS && groovyscript != null)
775 if (Cache.groovyJarsPresent())
777 System.out.println("Executing script " + groovyscript);
778 executeGroovyScript(groovyscript, af);
783 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
788 // and finally, turn off batch mode indicator - if the desktop still exists
793 desktop.setProgressBar(null, progress);
795 desktop.setInBatchMode(false);
799 jsApp.callInitCallback();
804 * Set general display parameters irrespective of file loading or headlessness.
808 private void setDisplayParameters(ArgsParser aparser)
810 if (aparser.contains(ArgsParser.NOMENUBAR))
813 System.out.println("CMD [nomenu] executed successfully!");
816 if (aparser.contains(ArgsParser.NOSTATUS))
819 System.out.println("CMD [nostatus] executed successfully!");
822 if (aparser.contains(ArgsParser.NOANNOTATION)
823 || aparser.contains(ArgsParser.NOANNOTATION2))
826 System.out.println("CMD no-annotation executed successfully!");
828 if (aparser.contains(ArgsParser.NOCALCULATION))
830 noCalculation = true;
831 System.out.println("CMD [nocalculation] executed successfully!");
836 private void setFrameDependentProperties(ArgsParser aparser,
839 String data = aparser.getValue(ArgsParser.COLOUR, true);
842 data.replaceAll("%20", " ");
844 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
845 af.getViewport(), af.getViewport().getAlignment(), data);
850 "CMD [-color " + data + "] executed successfully!");
855 // Must maintain ability to use the groups flag
856 data = aparser.getValue(ArgsParser.GROUPS, true);
859 af.parseFeaturesFile(data,
860 AppletFormatAdapter.checkProtocol(data));
861 // System.out.println("Added " + data);
863 "CMD groups[-" + data + "] executed successfully!");
865 data = aparser.getValue(ArgsParser.FEATURES, true);
868 af.parseFeaturesFile(data,
869 AppletFormatAdapter.checkProtocol(data));
870 // System.out.println("Added " + data);
872 "CMD [-features " + data + "] executed successfully!");
874 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
877 af.loadJalviewDataFile(data, null, null, null);
878 // System.out.println("Added " + data);
880 "CMD [-annotations " + data + "] executed successfully!");
883 // JavaScript feature
885 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
887 af.overviewMenuItem_actionPerformed(null);
888 System.out.println("CMD [showoverview] executed successfully!");
891 // set or clear the sortbytree flag.
892 if (aparser.contains(ArgsParser.SORTBYTREE))
894 af.getViewport().setSortByTree(true);
895 if (af.getViewport().getSortByTree())
897 System.out.println("CMD [-sortbytree] executed successfully!");
901 boolean doUpdateAnnotation = false;
903 * we do this earlier in JalviewJS because of a complication with
906 * For now, just fixing this in JalviewJS.
915 af.getViewport().setShowAnnotation(false);
916 if (!af.getViewport().isShowAnnotation())
918 doUpdateAnnotation = true;
923 if (aparser.contains(ArgsParser.NOSORTBYTREE))
925 af.getViewport().setSortByTree(false);
926 if (!af.getViewport().getSortByTree())
928 doUpdateAnnotation = true;
930 .println("CMD [-nosortbytree] executed successfully!");
933 if (doUpdateAnnotation)
935 af.setMenusForViewport();
936 af.alignPanel.updateLayout();
939 data = aparser.getValue(ArgsParser.TREE, true);
944 NewickFile nf = new NewickFile(data,
945 AppletFormatAdapter.checkProtocol(data));
947 .setCurrentTree(af.showNewickTree(nf, data).getTree());
949 "CMD [-tree " + data + "] executed successfully!");
950 } catch (IOException ex)
952 System.err.println("Couldn't add tree " + data);
953 ex.printStackTrace(System.err);
956 // TODO - load PDB structure(s) to alignment JAL-629
957 // (associate with identical sequence in alignment, or a specified
963 * Writes an output file for each format (if any) specified in the
964 * command-line arguments. Supported formats are currently
973 * A format parameter should be followed by a parameter specifying the output
974 * file name. {@code imgMap} parameters should follow those for the
975 * corresponding alignment image output.
980 private void createOutputFiles(ArgsParser aparser,
983 AlignFrame af = currentAlignFrame;
984 while (aparser.getSize() >= 2)
986 String outputFormat = aparser.nextValue();
989 switch (outputFormat.toLowerCase())
992 imageFile = new File(aparser.nextValue());
993 af.createPNG(imageFile);
995 "Creating PNG image: " + imageFile.getAbsolutePath());
998 imageFile = new File(aparser.nextValue());
999 af.createSVG(imageFile);
1001 "Creating SVG image: " + imageFile.getAbsolutePath());
1004 imageFile = new File(aparser.nextValue());
1006 "Creating EPS file: " + imageFile.getAbsolutePath());
1007 af.createEPS(imageFile);
1010 fname = new File(aparser.nextValue()).getAbsolutePath();
1013 BioJsHTMLOutput.refreshVersionInfo(
1014 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1015 } catch (URISyntaxException e)
1017 e.printStackTrace();
1019 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1020 bjs.exportHTML(fname);
1021 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
1024 fname = new File(aparser.nextValue()).getAbsolutePath();
1025 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1026 htmlSVG.exportHTML(fname);
1027 System.out.println("Creating HTML image: " + fname);
1030 imageFile = new File(aparser.nextValue());
1031 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1033 "Creating image map: " + imageFile.getAbsolutePath());
1036 format = FileFormats.getInstance().forName(outputFormat);
1039 System.out.println("Invalid file format: " + outputFormat);
1042 fname = new File(aparser.nextValue()).getAbsolutePath();
1043 af.saveAlignment(fname, format);
1044 if (!af.isSaveAlignmentSuccessful())
1046 System.out.println("Error writing file " + fname + " in " + format
1052 System.out.println("Unknown arg: " + outputFormat);
1055 while (aparser.getSize() > 0)
1057 System.out.println("Unknown arg: " + aparser.nextValue());
1061 private static void showUsage()
1064 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1065 + "-nodisplay\tRun Jalview without User Interface.\n"
1066 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1067 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1068 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1069 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1070 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1071 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1072 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1073 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1074 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1075 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1076 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1077 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1078 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1079 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1080 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1081 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1082 + "-html FILE\tCreate HTML file from alignment.\n"
1083 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1084 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1085 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1086 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1087 + "-noquestionnaire\tTurn off questionnaire check.\n"
1088 + "-nonews\tTurn off check for Jalview news.\n"
1089 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1090 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1092 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1093 // after all other properties files have been read\n\t
1094 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1095 // passed in correctly)"
1096 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1097 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1098 + "-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"
1099 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1102 private static void startUsageStats(final Desktop desktop)
1105 * start a User Config prompt asking if we can log usage statistics.
1107 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1108 "USAGESTATS", "Jalview Usage Statistics",
1109 "Do you want to help make Jalview better by enabling "
1110 + "the collection of usage statistics with Google Analytics ?"
1111 + "\n\n(you can enable or disable usage tracking in the preferences)",
1118 "Initialising googletracker for usage stats.");
1119 Cache.initGoogleTracker();
1120 Cache.log.debug("Tracking enabled.");
1127 Cache.log.debug("Not enabling Google Tracking.");
1130 desktop.addDialogThread(prompter);
1134 * Locate the given string as a file and pass it to the groovy interpreter.
1136 * @param groovyscript
1137 * the script to execute
1138 * @param jalviewContext
1139 * the Jalview Desktop object passed in to the groovy binding as the
1142 private void executeGroovyScript(String groovyscript, AlignFrame af)
1145 * for scripts contained in files
1152 if (groovyscript.trim().equals("STDIN"))
1154 // read from stdin into a tempfile and execute it
1157 tfile = File.createTempFile("jalview", "groovy");
1158 PrintWriter outfile = new PrintWriter(
1159 new OutputStreamWriter(new FileOutputStream(tfile)));
1160 BufferedReader br = new BufferedReader(
1161 new InputStreamReader(System.in));
1163 while ((line = br.readLine()) != null)
1165 outfile.write(line + "\n");
1171 } catch (Exception ex)
1173 System.err.println("Failed to read from STDIN into tempfile "
1174 + ((tfile == null) ? "(tempfile wasn't created)"
1175 : tfile.toString()));
1176 ex.printStackTrace();
1181 sfile = tfile.toURI().toURL();
1182 } catch (Exception x)
1185 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1187 x.printStackTrace();
1195 sfile = new URI(groovyscript).toURL();
1196 } catch (Exception x)
1198 tfile = new File(groovyscript);
1199 if (!tfile.exists())
1201 System.err.println("File '" + groovyscript + "' does not exist.");
1204 if (!tfile.canRead())
1206 System.err.println("File '" + groovyscript + "' cannot be read.");
1209 if (tfile.length() < 1)
1211 System.err.println("File '" + groovyscript + "' is empty.");
1216 sfile = tfile.getAbsoluteFile().toURI().toURL();
1217 } catch (Exception ex)
1219 System.err.println("Failed to create a file URL for "
1220 + tfile.getAbsoluteFile());
1227 Map<String, java.lang.Object> vbinding = new HashMap<>();
1228 vbinding.put("Jalview", this);
1231 vbinding.put("currentAlFrame", af);
1233 Binding gbinding = new Binding(vbinding);
1234 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1235 gse.run(sfile.toString(), gbinding);
1236 if ("STDIN".equals(groovyscript))
1238 // delete temp file that we made -
1239 // only if it was successfully executed
1242 } catch (Exception e)
1244 System.err.println("Exception Whilst trying to execute file " + sfile
1245 + " as a groovy script.");
1246 e.printStackTrace(System.err);
1251 public static boolean isHeadlessMode()
1253 String isheadless = System.getProperty("java.awt.headless");
1254 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1261 public AlignFrame[] getAlignFrames()
1263 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1264 : Desktop.getAlignFrames();
1269 * Quit method delegates to Desktop.quit - unless running in headless mode
1270 * when it just ends the JVM
1274 if (desktop != null)
1284 public static AlignFrame getCurrentAlignFrame()
1286 return Jalview.getInstance().currentAlignFrame;
1289 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1291 Jalview.getInstance().currentAlignFrame = currentAlignFrame;
1295 public void notifyWorker(AlignCalcWorkerI worker, String status)
1297 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
1302 private static boolean isInteractive = true;
1304 public static boolean isInteractive()
1306 return isInteractive;
1309 public static void setInteractive(boolean tf)