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.api.JalviewJSApp;
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 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
303 j2sAppletID = Platform.getAppID(null);
304 Preferences.setAppletDefaults();
305 Cache.loadProperties(usrPropsFile); // again, because we
306 // might be changing defaults here?
307 appletResourcePath = (String) aparser.getAppletValue("resourcepath",
318 if (usrPropsFile != null)
321 "CMD [-props " + usrPropsFile + "] executed successfully!");
323 if (aparser.contains("help") || aparser.contains("h"))
329 if (aparser.contains("nodisplay") || aparser.contains("nogui")
330 || aparser.contains("headless"))
332 System.setProperty("java.awt.headless", "true");
339 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
340 if (jabawsUrl != null)
344 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
346 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
347 } catch (MalformedURLException e)
350 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
355 String defs = aparser.getValue(ArgsParser.SETPROP);
358 int p = defs.indexOf('=');
361 System.err.println("Ignoring invalid setprop argument : " + defs);
365 System.out.println("Executing setprop argument: " + defs);
368 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
371 defs = aparser.getValue("setprop");
373 if (System.getProperty("java.awt.headless") != null
374 && System.getProperty("java.awt.headless").equals("true"))
378 System.setProperty("http.agent",
379 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
383 } catch (NoClassDefFoundError error)
385 error.printStackTrace();
386 System.out.println("\nEssential logging libraries not found."
387 + "\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());
455 desktop = Desktop.getInstance();
456 desktop.setInBatchMode(true); // indicate we are starting up
459 JalviewTaskbar.setTaskbar(this);
460 } catch (Throwable t)
462 System.out.println("Error setting Taskbar: " + t.getMessage());
464 desktop.setVisible(true);
473 desktop.startServiceDiscovery();
474 if (!aparser.contains("nousagestats"))
476 startUsageStats(desktop);
480 System.err.println("CMD [-nousagestats] executed successfully!");
483 if (!aparser.contains("noquestionnaire"))
485 String url = aparser.getValue("questionnaire");
488 // Start the desktop questionnaire prompter with the specified
490 Cache.log.debug("Starting questionnaire url at " + url);
491 desktop.checkForQuestionnaire(url);
492 System.out.println("CMD questionnaire[-" + url
493 + "] executed successfully!");
497 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
499 // Start the desktop questionnaire prompter with the specified
502 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
504 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
506 "Starting questionnaire with default url: " + defurl);
507 desktop.checkForQuestionnaire(defurl);
514 .println("CMD [-noquestionnaire] executed successfully!");
517 if (!aparser.contains("nonews"))
519 desktop.checkForNews();
522 BioJsHTMLOutput.updateBioJS();
525 parseArguments(aparser, true);
529 * Parse all command-line String[] arguments as well as all JavaScript-derived parameters from Info.
531 * We allow for this method to be run from JavaScript. Basically allowing simple scripting.
536 public void parseArguments(ArgsParser aparser, boolean isStartup)
539 String groovyscript = null; // script to execute after all loading is
540 boolean isJS = Platform.isJS();
544 // Move any new getdown-launcher-new.jar into place over old
545 // getdown-launcher.jar
546 String appdirString = System.getProperty("getdownappdir");
547 if (appdirString != null && appdirString.length() > 0)
549 final File appdir = new File(appdirString);
555 LaunchUtil.upgradeGetdown(
556 new File(appdir, "getdown-launcher-old.jar"),
557 new File(appdir, "getdown-launcher.jar"),
558 new File(appdir, "getdown-launcher-new.jar"));
563 // completed one way or another
564 // extract groovy argument and execute if necessary
565 groovyscript = aparser.getValue("groovy", true);
569 String file = aparser.getValue("open", true);
571 if (!isJS && file == null && desktop == null)
573 System.out.println("No files to open!");
577 // time to open a file.
580 DataSourceType protocol = null;
581 FileLoader fileLoader = new FileLoader(!headless);
582 FileFormatI format = null;
583 // Finally, deal with the remaining input data.
584 JalviewJSApp jsApp = null;
585 AlignFrame af = null;
591 desktop.setProgressBar(
593 .getString("status.processing_commandline_args"),
594 progress = System.currentTimeMillis());
596 System.out.println("CMD [-open " + file + "] executed successfully!");
598 if (!Platform.isJS())
600 * ignore in JavaScript -- can't just file existence - could load it?
605 if (!file.startsWith("http://") && !file.startsWith("https://"))
606 // BH 2019 added https check for Java
608 if (!(new File(file)).exists())
610 System.out.println("Can't find " + file);
618 String fileFormat = (isJS
619 ? (String) aparser.getAppletValue("format", null, true)
621 protocol = AppletFormatAdapter.checkProtocol(file);
624 format = (fileFormat != null
625 ? FileFormats.getInstance().forName(fileFormat)
629 format = new IdentifyFile().identify(file, protocol);
631 } catch (FileFormatException e1)
636 if (aparser.contains(ArgsParser.NOMENUBAR))
639 System.out.println("CMD [nomenu] executed successfully!");
642 if (aparser.contains(ArgsParser.NOSTATUS))
645 System.out.println("CMD [nostatus] executed successfully!");
648 if (aparser.contains(ArgsParser.NOANNOTATION)
649 || aparser.contains(ArgsParser.NOANNOTATION2))
652 System.out.println("CMD no-annotation executed successfully!");
654 if (aparser.contains(ArgsParser.NOCALCULATION))
656 noCalculation = true;
657 System.out.println("CMD [nocalculation] executed successfully!");
660 af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol,
664 System.out.println("error");
669 // JalviewLite interface for JavaScript allows second file open
670 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
673 protocol = AppletFormatAdapter.checkProtocol(file2);
676 format = new IdentifyFile().identify(file2, protocol);
677 } catch (FileFormatException e1)
681 AlignFrame af2 = new FileLoader(!headless)
682 .LoadFileWaitTillLoaded(file2, protocol, format);
685 System.out.println("error");
689 AlignViewport.openLinkedAlignmentAs(af,
690 af.getViewport().getAlignment(),
691 af2.getViewport().getAlignment(), "",
692 AlignViewport.SPLIT_FRAME);
694 "CMD [-open2 " + file2 + "] executed successfully!");
697 setCurrentAlignFrame(af);
699 String data = aparser.getValue(ArgsParser.COLOUR, true);
702 data.replaceAll("%20", " ");
704 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
705 af.getViewport(), af.getViewport().getAlignment(), data);
710 "CMD [-color " + data + "] executed successfully!");
715 // Must maintain ability to use the groups flag
716 data = aparser.getValue(ArgsParser.GROUPS, true);
719 af.parseFeaturesFile(data,
720 AppletFormatAdapter.checkProtocol(data));
721 // System.out.println("Added " + data);
723 "CMD groups[-" + data + "] executed successfully!");
725 data = aparser.getValue(ArgsParser.FEATURES, true);
728 af.parseFeaturesFile(data,
729 AppletFormatAdapter.checkProtocol(data));
730 // System.out.println("Added " + data);
732 "CMD [-features " + data + "] executed successfully!");
734 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
737 af.loadJalviewDataFile(data, null, null, null);
738 // System.out.println("Added " + data);
740 "CMD [-annotations " + data + "] executed successfully!");
743 // JavaScript feature
745 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
747 af.overviewMenuItem_actionPerformed(null);
748 System.out.println("CMD [showoverview] executed successfully!");
751 // set or clear the sortbytree flag.
752 if (aparser.contains(ArgsParser.SORTBYTREE))
754 af.getViewport().setSortByTree(true);
755 if (af.getViewport().getSortByTree())
757 System.out.println("CMD [-sortbytree] executed successfully!");
761 boolean doUpdateAnnotation = false;
763 * we do this earlier in JalviewJS because of a complication with
766 * For now, just fixing this in JalviewJS.
773 if (aparser.contains(ArgsParser.NOANNOTATION)
774 || aparser.contains(ArgsParser.NOANNOTATION2))
776 af.getViewport().setShowAnnotation(false);
777 if (!af.getViewport().isShowAnnotation())
779 doUpdateAnnotation = true;
781 .println("CMD no-annotation executed successfully!");
786 if (aparser.contains(ArgsParser.NOSORTBYTREE))
788 af.getViewport().setSortByTree(false);
789 if (!af.getViewport().getSortByTree())
791 doUpdateAnnotation = true;
793 .println("CMD [-nosortbytree] executed successfully!");
796 if (doUpdateAnnotation)
798 af.setMenusForViewport();
799 af.alignPanel.updateLayout();
802 data = aparser.getValue(ArgsParser.TREE, true);
807 NewickFile nf = new NewickFile(data,
808 AppletFormatAdapter.checkProtocol(data));
810 .setCurrentTree(af.showNewickTree(nf, data).getTree());
812 "CMD [-tree " + data + "] executed successfully!");
813 } catch (IOException ex)
815 System.err.println("Couldn't add tree " + data);
816 ex.printStackTrace(System.err);
819 // TODO - load PDB structure(s) to alignment JAL-629
820 // (associate with identical sequence in alignment, or a specified
825 jsApp = new JalviewJSApp(aparser);
835 if (groovyscript != null)
837 // Execute the groovy script after we've done all the rendering
839 // and before any images or figures are generated.
840 System.out.println("Executing script " + groovyscript);
841 executeGroovyScript(groovyscript, af);
842 System.out.println("CMD groovy[" + groovyscript
843 + "] executed successfully!");
846 createOutputFiles(aparser, af, format);
852 if (!isJS && !headless && Cache.getDefault("SHOW_STARTUP_FILE", true))
860 // We'll only open the default file if the desktop is visible.
862 // ////////////////////
864 file = Cache.getDefault("STARTUP_FILE",
865 Cache.getDefault("www.jalview.org",
866 "http://www.jalview.org")
867 + "/examples/exampleFile_2_7.jar");
869 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
871 // hardwire upgrade of the startup file
872 file.replace("_2_3.jar", "_2_7.jar");
873 // and remove the stale setting
874 Cache.removeProperty("STARTUP_FILE");
877 protocol = DataSourceType.FILE;
879 if (file.indexOf("http:") > -1)
881 protocol = DataSourceType.URL;
884 if (file.endsWith(".jar"))
886 format = FileFormat.Jalview;
892 format = new IdentifyFile().identify(file, protocol);
893 } catch (FileFormatException e)
899 af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
903 // extract groovy arguments before anything else.
904 // Once all other stuff is done, execute any groovy scripts (in order)
905 if (!isJS && groovyscript != null)
907 if (Cache.groovyJarsPresent())
909 System.out.println("Executing script " + groovyscript);
910 executeGroovyScript(groovyscript, af);
915 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
920 // and finally, turn off batch mode indicator - if the desktop still exists
925 desktop.setProgressBar(null, progress);
927 desktop.setInBatchMode(false);
930 if (isJS && isStartup)
932 jsApp.callInitCallback();
938 * Writes an output file for each format (if any) specified in the
939 * command-line arguments. Supported formats are currently
948 * A format parameter should be followed by a parameter specifying the output
949 * file name. {@code imgMap} parameters should follow those for the
950 * corresponding alignment image output.
956 private void createOutputFiles(ArgsParser aparser, AlignFrame af,
959 while (aparser.getSize() >= 2)
961 String outputFormat = aparser.nextValue();
964 switch (outputFormat.toLowerCase())
967 imageFile = new File(aparser.nextValue());
968 af.createPNG(imageFile);
970 "Creating PNG image: " + imageFile.getAbsolutePath());
973 imageFile = new File(aparser.nextValue());
974 af.createSVG(imageFile);
976 "Creating SVG image: " + imageFile.getAbsolutePath());
979 imageFile = new File(aparser.nextValue());
981 "Creating EPS file: " + imageFile.getAbsolutePath());
982 af.createEPS(imageFile);
985 fname = new File(aparser.nextValue()).getAbsolutePath();
988 BioJsHTMLOutput.refreshVersionInfo(
989 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
990 } catch (URISyntaxException e)
994 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
995 bjs.exportHTML(fname);
996 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
999 fname = new File(aparser.nextValue()).getAbsolutePath();
1000 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1001 htmlSVG.exportHTML(fname);
1002 System.out.println("Creating HTML image: " + fname);
1005 imageFile = new File(aparser.nextValue());
1006 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1008 "Creating image map: " + imageFile.getAbsolutePath());
1011 if (!Platform.isJS()) /** @j2sIgnore */
1013 // skipping outputFormat?
1014 System.out.println("Unknown arg: " + outputFormat);
1015 fname = new File(aparser.nextValue()).getAbsolutePath();
1016 af.saveAlignment(fname, format);
1017 if (af.isSaveAlignmentSuccessful())
1020 "Written alignment in " + format + " format to " + fname);
1024 System.out.println("Error writing file " + fname + " in " + format
1030 while (aparser.getSize() > 0)
1032 System.out.println("Unknown arg: " + aparser.nextValue());
1036 private static void showUsage()
1039 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1040 + "-nodisplay\tRun Jalview without User Interface.\n"
1041 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1042 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1043 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1044 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1045 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1046 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1047 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1048 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1049 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1050 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1051 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1052 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1053 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1054 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1055 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1056 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1057 + "-html FILE\tCreate HTML file from alignment.\n"
1058 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1059 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1060 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1061 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1062 + "-noquestionnaire\tTurn off questionnaire check.\n"
1063 + "-nonews\tTurn off check for Jalview news.\n"
1064 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1065 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1067 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1068 // after all other properties files have been read\n\t
1069 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1070 // passed in correctly)"
1071 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1072 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1073 + "-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"
1074 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1077 private static void startUsageStats(final Desktop desktop)
1080 * start a User Config prompt asking if we can log usage statistics.
1082 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1083 "USAGESTATS", "Jalview Usage Statistics",
1084 "Do you want to help make Jalview better by enabling "
1085 + "the collection of usage statistics with Google Analytics ?"
1086 + "\n\n(you can enable or disable usage tracking in the preferences)",
1093 "Initialising googletracker for usage stats.");
1094 Cache.initGoogleTracker();
1095 Cache.log.debug("Tracking enabled.");
1102 Cache.log.debug("Not enabling Google Tracking.");
1105 desktop.addDialogThread(prompter);
1109 * Locate the given string as a file and pass it to the groovy interpreter.
1111 * @param groovyscript
1112 * the script to execute
1113 * @param jalviewContext
1114 * the Jalview Desktop object passed in to the groovy binding as the
1117 private void executeGroovyScript(String groovyscript, AlignFrame af)
1120 * for scripts contained in files
1127 if (groovyscript.trim().equals("STDIN"))
1129 // read from stdin into a tempfile and execute it
1132 tfile = File.createTempFile("jalview", "groovy");
1133 PrintWriter outfile = new PrintWriter(
1134 new OutputStreamWriter(new FileOutputStream(tfile)));
1135 BufferedReader br = new BufferedReader(
1136 new InputStreamReader(System.in));
1138 while ((line = br.readLine()) != null)
1140 outfile.write(line + "\n");
1146 } catch (Exception ex)
1148 System.err.println("Failed to read from STDIN into tempfile "
1149 + ((tfile == null) ? "(tempfile wasn't created)"
1150 : tfile.toString()));
1151 ex.printStackTrace();
1156 sfile = tfile.toURI().toURL();
1157 } catch (Exception x)
1160 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1162 x.printStackTrace();
1170 sfile = new URI(groovyscript).toURL();
1171 } catch (Exception x)
1173 tfile = new File(groovyscript);
1174 if (!tfile.exists())
1176 System.err.println("File '" + groovyscript + "' does not exist.");
1179 if (!tfile.canRead())
1181 System.err.println("File '" + groovyscript + "' cannot be read.");
1184 if (tfile.length() < 1)
1186 System.err.println("File '" + groovyscript + "' is empty.");
1191 sfile = tfile.getAbsoluteFile().toURI().toURL();
1192 } catch (Exception ex)
1194 System.err.println("Failed to create a file URL for "
1195 + tfile.getAbsoluteFile());
1202 Map<String, java.lang.Object> vbinding = new HashMap<>();
1203 vbinding.put("Jalview", this);
1206 vbinding.put("currentAlFrame", af);
1208 Binding gbinding = new Binding(vbinding);
1209 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1210 gse.run(sfile.toString(), gbinding);
1211 if ("STDIN".equals(groovyscript))
1213 // delete temp file that we made -
1214 // only if it was successfully executed
1217 } catch (Exception e)
1219 System.err.println("Exception Whilst trying to execute file " + sfile
1220 + " as a groovy script.");
1221 e.printStackTrace(System.err);
1226 public static boolean isHeadlessMode()
1228 String isheadless = System.getProperty("java.awt.headless");
1229 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1236 public AlignFrame[] getAlignFrames()
1238 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1239 : Desktop.getAlignFrames();
1244 * Quit method delegates to Desktop.quit - unless running in headless mode
1245 * when it just ends the JVM
1249 if (desktop != null)
1259 public static AlignFrame getCurrentAlignFrame()
1261 return Jalview.getInstance().currentAlignFrame;
1264 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1266 Jalview.getInstance().currentAlignFrame = currentAlignFrame;
1270 public void notifyWorker(AlignCalcWorkerI worker, String status)
1272 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()