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);
124 Platform.getURLCommandArguments();
127 private boolean headless;
129 private Desktop desktop;
131 public AlignFrame currentAlignFrame;
133 public String appletResourcePath;
135 JalviewJSApp app; // JalviewJS-specific JavaScript interface
137 private boolean noCalculation, noMenuBar, noStatus;
139 private boolean noAnnotation;
141 public boolean getStartCalculations()
143 return !noCalculation;
146 public boolean getAllowMenuBar()
151 public boolean getShowStatus()
156 public boolean getShowAnnotation()
158 return !noAnnotation;
163 if (!Platform.isJS())
170 // grab all the rights we can for the JVM
171 Policy.setPolicy(new Policy()
174 public PermissionCollection getPermissions(CodeSource codesource)
176 Permissions perms = new Permissions();
177 perms.add(new AllPermission());
182 public void refresh()
190 * keep track of feature fetching tasks.
198 * TODO: generalise to track all jalview events to orchestrate batch processing
202 private int queued = 0;
204 private int running = 0;
206 public FeatureFetcher()
211 public void addFetcher(final AlignFrame af,
212 final Vector<String> dasSources)
214 final long id = System.currentTimeMillis();
216 final FeatureFetcher us = this;
217 new Thread(new Runnable()
229 af.setProgressBar(MessageManager
230 .getString("status.das_features_being_retrived"), id);
231 af.featureSettings_actionPerformed(null);
232 af.setProgressBar(null, id);
241 public synchronized boolean allFinished()
243 return queued == 0 && running == 0;
248 private final static boolean doPlatformLogging = false;
251 * main class for Jalview application
254 * open <em>filename</em>
256 public static void main(String[] args)
258 if (doPlatformLogging)
260 Platform.startJavaLogging();
262 getInstance().doMain(args);
268 void doMain(String[] args)
271 boolean isJS = Platform.isJS();
274 System.setSecurityManager(null);
278 .println("Java version: " + System.getProperty("java.version"));
279 System.out.println("Java Home: " + System.getProperty("java.home"));
280 System.out.println(System.getProperty("os.arch") + " "
281 + System.getProperty("os.name") + " "
282 + System.getProperty("os.version"));
283 String val = System.getProperty("sys.install4jVersion");
286 System.out.println("Install4j version: " + val);
288 val = System.getProperty("installer_template_version");
291 System.out.println("Install4j template version: " + val);
293 val = System.getProperty("launcher_version");
296 System.out.println("Launcher version: " + val);
299 // report Jalview version
300 Cache.getInstance().loadBuildProperties(true);
302 ArgsParser aparser = new ArgsParser(args);
305 String usrPropsFile = aparser.getValue("props");
307 Cache.loadProperties(usrPropsFile); // must do this before
311 app = new JalviewJSApp(aparser);
312 Preferences.setAppletDefaults();
313 Cache.loadProperties(usrPropsFile); // again, because we
314 // might be changing defaults here?
315 appletResourcePath = (String) aparser.getAppletValue("resourcepath", null, true);
325 if (usrPropsFile != null)
328 "CMD [-props " + usrPropsFile + "] executed successfully!");
330 if (aparser.contains("help") || aparser.contains("h"))
336 if (aparser.contains("nodisplay") || aparser.contains("nogui")
337 || aparser.contains("headless"))
339 System.setProperty("java.awt.headless", "true");
346 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
347 if (jabawsUrl != null)
351 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
353 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
354 } catch (MalformedURLException e)
357 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
362 String defs = aparser.getValue(ArgsParser.SETPROP);
365 int p = defs.indexOf('=');
368 System.err.println("Ignoring invalid setprop argument : " + defs);
372 System.out.println("Executing setprop argument: " + defs);
375 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
378 defs = aparser.getValue("setprop");
380 if (System.getProperty("java.awt.headless") != null
381 && System.getProperty("java.awt.headless").equals("true"))
385 System.setProperty("http.agent",
386 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
390 } catch (NoClassDefFoundError error)
392 error.printStackTrace();
393 System.out.println("\nEssential logging libraries not found."
394 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
405 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
406 } catch (Exception ex)
408 System.err.println("Unexpected Look and Feel Exception");
409 ex.printStackTrace();
411 if (Platform.isMac())
414 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
417 "com.apple.mrj.application.apple.menu.about.name",
419 System.setProperty("apple.laf.useScreenMenuBar", "true");
420 if (lookAndFeel != null)
424 UIManager.setLookAndFeel(lookAndFeel);
425 } catch (Throwable e)
428 "Failed to set QuaQua look and feel: " + e.toString());
431 if (lookAndFeel == null
432 || !(lookAndFeel.getClass().isAssignableFrom(
433 UIManager.getLookAndFeel().getClass()))
434 || !UIManager.getLookAndFeel().getClass().toString()
435 .toLowerCase().contains("quaqua"))
440 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
441 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
442 } catch (Throwable e)
445 "Failed to reset look and feel: " + e.toString());
451 * configure 'full' SO model if preferences say to, else use the default (full SO)
452 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
454 boolean soDefault = !Platform.isJS();
455 if (Cache.getDefault("USE_FULL_SO", soDefault))
457 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
462 desktop = Desktop.getInstance();
463 desktop.setInBatchMode(true); // indicate we are starting up
466 JalviewTaskbar.setTaskbar(this);
467 } catch (Throwable t)
469 System.out.println("Error setting Taskbar: " + t.getMessage());
471 desktop.setVisible(true);
473 if (!Platform.isJS())
480 desktop.startServiceDiscovery();
481 if (!aparser.contains("nousagestats"))
483 startUsageStats(desktop);
487 System.err.println("CMD [-nousagestats] executed successfully!");
490 if (!aparser.contains("noquestionnaire"))
492 String url = aparser.getValue("questionnaire");
495 // Start the desktop questionnaire prompter with the specified
497 Cache.log.debug("Starting questionnaire url at " + url);
498 desktop.checkForQuestionnaire(url);
499 System.out.println("CMD questionnaire[-" + url
500 + "] executed successfully!");
504 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
506 // Start the desktop questionnaire prompter with the specified
509 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
511 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
513 "Starting questionnaire with default url: " + defurl);
514 desktop.checkForQuestionnaire(defurl);
521 .println("CMD [-noquestionnaire] executed successfully!");
524 if (!aparser.contains("nonews"))
526 desktop.checkForNews();
529 BioJsHTMLOutput.updateBioJS();
533 parseArguments(aparser, true);
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 (file == null && desktop == null)
579 System.out.println("No files to open!");
584 DataSourceType protocol = null;
585 FileLoader fileLoader = new FileLoader(!headless);
586 FileFormatI format = null;
587 // Finally, deal with the remaining input data.
592 desktop.setProgressBar(
594 .getString("status.processing_commandline_args"),
595 progress = System.currentTimeMillis());
597 System.out.println("CMD [-open " + file + "] executed successfully!");
599 if (!Platform.isJS())
601 * ignore in JavaScript -- can't just file existence - could load it?
606 if (!file.startsWith("http://") && !file.startsWith("https://"))
607 // BH 2019 added https check for Java
609 if (!(new File(file)).exists())
611 System.out.println("Can't find " + file);
619 String fileFormat = (isJS ? (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 AlignFrame af = new FileLoader(!headless).LoadFileWaitTillLoaded(file,
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
834 if (groovyscript != null)
836 // Execute the groovy script after we've done all the rendering
838 // and before any images or figures are generated.
839 System.out.println("Executing script " + groovyscript);
840 executeGroovyScript(groovyscript, af);
841 System.out.println("CMD groovy[" + groovyscript
842 + "] executed successfully!");
845 createOutputFiles(aparser, af, format);
850 AlignFrame startUpAlframe = null;
851 // We'll only open the default file if the desktop is visible.
853 // ////////////////////
855 if (!isJS && !headless && file == null
856 && Cache.getDefault("SHOW_STARTUP_FILE", true))
863 file = Cache.getDefault("STARTUP_FILE",
864 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
865 + "/examples/exampleFile_2_7.jar");
867 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
869 // hardwire upgrade of the startup file
870 file.replace("_2_3.jar", "_2_7.jar");
871 // and remove the stale setting
872 Cache.removeProperty("STARTUP_FILE");
875 protocol = DataSourceType.FILE;
877 if (file.indexOf("http:") > -1)
879 protocol = DataSourceType.URL;
882 if (file.endsWith(".jar"))
884 format = FileFormat.Jalview;
890 format = new IdentifyFile().identify(file, protocol);
891 } catch (FileFormatException e)
897 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
902 // extract groovy arguments before anything else.
903 // Once all other stuff is done, execute any groovy scripts (in order)
904 if (groovyscript != null)
906 if (Cache.groovyJarsPresent())
908 System.out.println("Executing script " + groovyscript);
909 executeGroovyScript(groovyscript, startUpAlframe);
914 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
919 // and finally, turn off batch mode indicator - if the desktop still exists
924 desktop.setProgressBar(null, progress);
926 desktop.setInBatchMode(false);
929 if (isJS && isStartup)
931 app.callInitCallback();
937 * Writes an output file for each format (if any) specified in the
938 * command-line arguments. Supported formats are currently
947 * A format parameter should be followed by a parameter specifying the output
948 * file name. {@code imgMap} parameters should follow those for the
949 * corresponding alignment image output.
955 private void createOutputFiles(ArgsParser aparser, AlignFrame af,
958 while (aparser.getSize() >= 2)
960 String outputFormat = aparser.nextValue();
963 switch (outputFormat.toLowerCase())
966 imageFile = new File(aparser.nextValue());
967 af.createPNG(imageFile);
969 "Creating PNG image: " + imageFile.getAbsolutePath());
972 imageFile = new File(aparser.nextValue());
973 af.createSVG(imageFile);
975 "Creating SVG image: " + imageFile.getAbsolutePath());
978 imageFile = new File(aparser.nextValue());
980 "Creating EPS file: " + imageFile.getAbsolutePath());
981 af.createEPS(imageFile);
984 fname = new File(aparser.nextValue()).getAbsolutePath();
987 BioJsHTMLOutput.refreshVersionInfo(
988 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
989 } catch (URISyntaxException e)
993 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
994 bjs.exportHTML(fname);
995 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
998 fname = new File(aparser.nextValue()).getAbsolutePath();
999 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1000 htmlSVG.exportHTML(fname);
1001 System.out.println("Creating HTML image: " + fname);
1004 imageFile = new File(aparser.nextValue());
1005 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1007 "Creating image map: " + imageFile.getAbsolutePath());
1010 if (!Platform.isJS())
1012 // skipping outputFormat?
1013 System.out.println("Unknown arg: " + outputFormat);
1014 fname = new File(aparser.nextValue()).getAbsolutePath();
1015 af.saveAlignment(fname, format);
1016 if (af.isSaveAlignmentSuccessful())
1019 "Written alignment in " + format + " format to " + fname);
1023 System.out.println("Error writing file " + fname + " in " + format
1027 while (aparser.getSize() > 0)
1029 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;
1271 * Get the SwingJS applet ID and combine that with the frameType
1274 * "alignment", "desktop", etc., or null
1277 public static String getAppID(String frameType)
1279 return (Platform.isJS() ? getInstance().app.getAppID(frameType) : null);
1282 public String doSendCallback(Object callback, Object[] data) {
1283 return (Platform.isJS() ? app.doSendCallback(callback, data) : null);
1286 public void notifyWorker(AlignCalcWorkerI worker, String status)
1288 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
1292 public Object arrayToSeparatorList(String[] seqs)
1294 return (Platform.isJS() ? app.arrayToSeparatorList(seqs) : null);