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;
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
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"))
329 // BH note: Only -nodisplay is official; others are deprecated?
330 if (aparser.contains("nodisplay") || aparser.contains("nogui")
331 || aparser.contains("headless")
332 || GraphicsEnvironment.isHeadless())
335 // BH Definitely not a good idea in JavaScript;
336 // probably should not be here for Java, either.
337 System.setProperty("java.awt.headless", "true");
342 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
343 allowServices = !("none".equals(jabawsUrl));
344 if (allowServices && jabawsUrl != null)
348 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
350 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
351 } catch (MalformedURLException e)
354 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
359 String defs = aparser.getValue(ArgsParser.SETPROP);
362 int p = defs.indexOf('=');
365 System.err.println("Ignoring invalid setprop argument : " + defs);
369 System.out.println("Executing setprop argument: " + defs);
372 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
375 defs = aparser.getValue("setprop");
377 System.setProperty("http.agent",
378 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
382 } catch (NoClassDefFoundError error)
384 error.printStackTrace();
385 System.out.println("\nEssential logging libraries not found."
386 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
395 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
396 } catch (Exception ex)
398 System.err.println("Unexpected Look and Feel Exception");
399 ex.printStackTrace();
401 if (Platform.isMac())
404 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
407 "com.apple.mrj.application.apple.menu.about.name",
409 System.setProperty("apple.laf.useScreenMenuBar", "true");
410 if (lookAndFeel != null)
414 UIManager.setLookAndFeel(lookAndFeel);
415 } catch (Throwable e)
418 "Failed to set QuaQua look and feel: " + e.toString());
421 if (lookAndFeel == null
422 || !(lookAndFeel.getClass().isAssignableFrom(
423 UIManager.getLookAndFeel().getClass()))
424 || !UIManager.getLookAndFeel().getClass().toString()
425 .toLowerCase().contains("quaqua"))
430 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
431 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
432 } catch (Throwable e)
435 "Failed to reset look and feel: " + e.toString());
441 * configure 'full' SO model if preferences say to, else use the default (full SO)
442 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
444 boolean soDefault = !isJS;
445 if (Cache.getDefault("USE_FULL_SO", soDefault))
447 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
454 desktop = Desktop.getInstance();
455 desktop.setInBatchMode(true); // indicate we are starting up
458 JalviewTaskbar.setTaskbar(this);
459 } catch (Throwable t)
461 System.out.println("Error setting Taskbar: " + t.getMessage());
463 desktop.setVisible(true);
465 Cache.setProperty("SHOW_JWS2_SERVICES", "false");
468 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);
771 af.getViewport().getCalcManager().shutdown();
774 // extract groovy arguments before anything else.
775 // Once all other stuff is done, execute any groovy scripts (in order)
776 if (!isJS && groovyscript != null)
778 if (Cache.groovyJarsPresent())
780 System.out.println("Executing script " + groovyscript);
781 executeGroovyScript(groovyscript, af);
786 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
791 // and finally, turn off batch mode indicator - if the desktop still exists
796 desktop.setProgressBar(null, progress);
798 desktop.setInBatchMode(false);
802 jsApp.callInitCallback();
807 * Set general display parameters irrespective of file loading or headlessness.
811 private void setDisplayParameters(ArgsParser aparser)
813 if (aparser.contains(ArgsParser.NOMENUBAR))
816 System.out.println("CMD [nomenu] executed successfully!");
819 if (aparser.contains(ArgsParser.NOSTATUS))
822 System.out.println("CMD [nostatus] executed successfully!");
825 if (aparser.contains(ArgsParser.NOANNOTATION)
826 || aparser.contains(ArgsParser.NOANNOTATION2))
829 System.out.println("CMD no-annotation executed successfully!");
831 if (aparser.contains(ArgsParser.NOCALCULATION))
833 noCalculation = true;
834 System.out.println("CMD [nocalculation] executed successfully!");
839 private void setFrameDependentProperties(ArgsParser aparser,
842 String data = aparser.getValue(ArgsParser.COLOUR, true);
845 data.replaceAll("%20", " ");
847 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
848 af.getViewport(), af.getViewport().getAlignment(), data);
853 "CMD [-color " + data + "] executed successfully!");
858 // Must maintain ability to use the groups flag
859 data = aparser.getValue(ArgsParser.GROUPS, true);
862 af.parseFeaturesFile(data,
863 AppletFormatAdapter.checkProtocol(data));
864 // System.out.println("Added " + data);
866 "CMD groups[-" + data + "] executed successfully!");
868 data = aparser.getValue(ArgsParser.FEATURES, true);
871 af.parseFeaturesFile(data,
872 AppletFormatAdapter.checkProtocol(data));
873 // System.out.println("Added " + data);
875 "CMD [-features " + data + "] executed successfully!");
877 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
880 af.loadJalviewDataFile(data, null, null, null);
881 // System.out.println("Added " + data);
883 "CMD [-annotations " + data + "] executed successfully!");
886 // JavaScript feature
888 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
890 af.overviewMenuItem_actionPerformed(null);
891 System.out.println("CMD [showoverview] executed successfully!");
894 // set or clear the sortbytree flag.
895 if (aparser.contains(ArgsParser.SORTBYTREE))
897 af.getViewport().setSortByTree(true);
898 if (af.getViewport().getSortByTree())
900 System.out.println("CMD [-sortbytree] executed successfully!");
904 boolean doUpdateAnnotation = false;
906 * we do this earlier in JalviewJS because of a complication with
909 * For now, just fixing this in JalviewJS.
918 af.getViewport().setShowAnnotation(false);
919 if (!af.getViewport().isShowAnnotation())
921 doUpdateAnnotation = true;
926 if (aparser.contains(ArgsParser.NOSORTBYTREE))
928 af.getViewport().setSortByTree(false);
929 if (!af.getViewport().getSortByTree())
931 doUpdateAnnotation = true;
933 .println("CMD [-nosortbytree] executed successfully!");
936 if (doUpdateAnnotation)
938 af.setMenusForViewport();
939 af.alignPanel.updateLayout();
942 data = aparser.getValue(ArgsParser.TREE, true);
947 NewickFile nf = new NewickFile(data,
948 AppletFormatAdapter.checkProtocol(data));
950 .setCurrentTree(af.showNewickTree(nf, data).getTree());
952 "CMD [-tree " + data + "] executed successfully!");
953 } catch (IOException ex)
955 System.err.println("Couldn't add tree " + data);
956 ex.printStackTrace(System.err);
959 // TODO - load PDB structure(s) to alignment JAL-629
960 // (associate with identical sequence in alignment, or a specified
966 * Writes an output file for each format (if any) specified in the
967 * command-line arguments. Supported formats are currently
976 * A format parameter should be followed by a parameter specifying the output
977 * file name. {@code imgMap} parameters should follow those for the
978 * corresponding alignment image output.
983 private void createOutputFiles(ArgsParser aparser, FileFormatI format)
985 AlignFrame af = currentAlignFrame;
986 while (aparser.getSize() >= 2)
988 String outputFormat = aparser.nextValue();
991 switch (outputFormat.toLowerCase())
994 imageFile = new File(aparser.nextValue());
995 af.createPNG(imageFile);
997 "Creating PNG image: " + imageFile.getAbsolutePath());
1000 imageFile = new File(aparser.nextValue());
1001 af.createSVG(imageFile);
1003 "Creating SVG image: " + imageFile.getAbsolutePath());
1006 imageFile = new File(aparser.nextValue());
1008 "Creating EPS file: " + imageFile.getAbsolutePath());
1009 af.createEPS(imageFile);
1012 fname = new File(aparser.nextValue()).getAbsolutePath();
1015 BioJsHTMLOutput.refreshVersionInfo(
1016 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1017 } catch (URISyntaxException e)
1019 e.printStackTrace();
1021 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1022 bjs.exportHTML(fname);
1023 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
1026 fname = new File(aparser.nextValue()).getAbsolutePath();
1027 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1028 htmlSVG.exportHTML(fname);
1029 System.out.println("Creating HTML image: " + fname);
1032 imageFile = new File(aparser.nextValue());
1033 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1035 "Creating image map: " + imageFile.getAbsolutePath());
1038 // fall through - try to parse as an alignment data export format
1039 FileFormatI outFormat = null;
1042 outFormat = FileFormats.getInstance().forName(outputFormat);
1043 } catch (Exception formatP)
1046 if (outFormat == null)
1048 System.out.println("Couldn't parse " + outputFormat
1049 + " as a valid Jalview format string.");
1052 if (!outFormat.isWritable())
1055 "This version of Jalview does not support alignment export as "
1059 // record file as it was passed to Jalview so it is recognisable to the CLI
1062 fname = new File(file = aparser.nextValue()).getAbsolutePath();
1063 // JBPNote - yuck - really wish we did have a bean returned from this which gave
1064 // success/fail like before !
1065 af.saveAlignment(fname, outFormat);
1066 if (!af.isSaveAlignmentSuccessful())
1068 System.out.println("Written alignment in " + outputFormat
1069 + " format to " + file);
1074 System.out.println("Error writing file " + file + " in "
1075 + outputFormat + " format!!");
1079 // ??? Should report - 'ignoring' extra args here...
1080 while (aparser.getSize() > 0)
1082 System.out.println("Ignoring extra argument: " + aparser.nextValue());
1086 private static void showUsage()
1089 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1090 + "-nodisplay\tRun Jalview without User Interface.\n"
1091 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1092 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1093 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1094 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1095 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1096 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1097 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1098 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1099 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1100 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1101 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1102 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1103 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1104 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1105 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1106 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1107 + "-html FILE\tCreate HTML file from alignment.\n"
1108 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1109 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1110 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1111 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1112 + "-noquestionnaire\tTurn off questionnaire check.\n"
1113 + "-nonews\tTurn off check for Jalview news.\n"
1114 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1115 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1117 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1118 // after all other properties files have been read\n\t
1119 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1120 // passed in correctly)"
1121 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1122 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1123 + "-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"
1124 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1127 private static void startUsageStats(final Desktop desktop)
1130 * start a User Config prompt asking if we can log usage statistics.
1132 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1133 "USAGESTATS", "Jalview Usage Statistics",
1134 "Do you want to help make Jalview better by enabling "
1135 + "the collection of usage statistics with Google Analytics ?"
1136 + "\n\n(you can enable or disable usage tracking in the preferences)",
1143 "Initialising googletracker for usage stats.");
1144 Cache.initGoogleTracker();
1145 Cache.log.debug("Tracking enabled.");
1152 Cache.log.debug("Not enabling Google Tracking.");
1155 desktop.addDialogThread(prompter);
1159 * Locate the given string as a file and pass it to the groovy interpreter.
1161 * @param groovyscript
1162 * the script to execute
1163 * @param jalviewContext
1164 * the Jalview Desktop object passed in to the groovy binding as the
1167 private void executeGroovyScript(String groovyscript, AlignFrame af)
1170 * for scripts contained in files
1177 if (groovyscript.trim().equals("STDIN"))
1179 // read from stdin into a tempfile and execute it
1182 tfile = File.createTempFile("jalview", "groovy");
1183 PrintWriter outfile = new PrintWriter(
1184 new OutputStreamWriter(new FileOutputStream(tfile)));
1185 BufferedReader br = new BufferedReader(
1186 new InputStreamReader(System.in));
1188 while ((line = br.readLine()) != null)
1190 outfile.write(line + "\n");
1196 } catch (Exception ex)
1198 System.err.println("Failed to read from STDIN into tempfile "
1199 + ((tfile == null) ? "(tempfile wasn't created)"
1200 : tfile.toString()));
1201 ex.printStackTrace();
1206 sfile = tfile.toURI().toURL();
1207 } catch (Exception x)
1210 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1212 x.printStackTrace();
1220 sfile = new URI(groovyscript).toURL();
1221 } catch (Exception x)
1223 tfile = new File(groovyscript);
1224 if (!tfile.exists())
1226 System.err.println("File '" + groovyscript + "' does not exist.");
1229 if (!tfile.canRead())
1231 System.err.println("File '" + groovyscript + "' cannot be read.");
1234 if (tfile.length() < 1)
1236 System.err.println("File '" + groovyscript + "' is empty.");
1241 sfile = tfile.getAbsoluteFile().toURI().toURL();
1242 } catch (Exception ex)
1244 System.err.println("Failed to create a file URL for "
1245 + tfile.getAbsoluteFile());
1252 Map<String, java.lang.Object> vbinding = new HashMap<>();
1253 vbinding.put("Jalview", this);
1256 vbinding.put("currentAlFrame", af);
1258 Binding gbinding = new Binding(vbinding);
1259 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1260 gse.run(sfile.toString(), gbinding);
1261 if ("STDIN".equals(groovyscript))
1263 // delete temp file that we made -
1264 // only if it was successfully executed
1267 } catch (Exception e)
1269 System.err.println("Exception Whilst trying to execute file " + sfile
1270 + " as a groovy script.");
1271 e.printStackTrace(System.err);
1276 public static boolean isHeadlessMode()
1278 String isheadless = System.getProperty("java.awt.headless");
1279 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1286 public AlignFrame[] getAlignFrames()
1288 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1289 : Desktop.getAlignFrames();
1294 * Quit method delegates to Desktop.quit - unless running in headless mode
1295 * when it just ends the JVM
1299 if (desktop != null)
1309 public static AlignFrame getCurrentAlignFrame()
1311 return Jalview.getInstance().currentAlignFrame;
1314 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1316 Jalview.getInstance().currentAlignFrame = currentAlignFrame;
1320 public void notifyWorker(AlignCalcWorkerI worker, String status)
1322 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
1327 private static boolean isInteractive = true;
1329 public static boolean isInteractive()
1331 return isInteractive;
1334 public static void setInteractive(boolean tf)