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 jalview.ext.so.SequenceOntology;
24 import jalview.gui.AlignFrame;
25 import jalview.gui.Desktop;
26 import jalview.gui.PromptUserConfig;
27 import jalview.io.AppletFormatAdapter;
28 import jalview.io.BioJsHTMLOutput;
29 import jalview.io.DataSourceType;
30 import jalview.io.FileFormat;
31 import jalview.io.FileFormatException;
32 import jalview.io.FileFormatI;
33 import jalview.io.FileFormats;
34 import jalview.io.FileLoader;
35 import jalview.io.HtmlSvgOutput;
36 import jalview.io.IdentifyFile;
37 import jalview.io.NewickFile;
38 import jalview.io.gff.SequenceOntologyFactory;
39 import jalview.schemes.ColourSchemeI;
40 import jalview.schemes.ColourSchemeProperty;
41 import jalview.util.MessageManager;
42 import jalview.util.Platform;
43 import jalview.ws.jws2.Jws2Discoverer;
45 import java.io.BufferedReader;
47 import java.io.FileOutputStream;
48 import java.io.IOException;
49 import java.io.InputStreamReader;
50 import java.io.OutputStreamWriter;
51 import java.io.PrintWriter;
52 import java.net.MalformedURLException;
54 import java.net.URISyntaxException;
56 import java.security.AllPermission;
57 import java.security.CodeSource;
58 import java.security.PermissionCollection;
59 import java.security.Permissions;
60 import java.security.Policy;
61 import java.util.HashMap;
63 import java.util.Vector;
65 import javax.swing.UIManager;
66 import javax.swing.UIManager.LookAndFeelInfo;
68 import com.threerings.getdown.util.LaunchUtil;
70 import groovy.lang.Binding;
71 import groovy.util.GroovyScriptEngine;
72 import jalview.ext.so.SequenceOntology;
73 import jalview.gui.AlignFrame;
74 import jalview.gui.Desktop;
75 import jalview.gui.PromptUserConfig;
76 import jalview.io.AppletFormatAdapter;
77 import jalview.io.BioJsHTMLOutput;
78 import jalview.io.DataSourceType;
79 import jalview.io.FileFormat;
80 import jalview.io.FileFormatException;
81 import jalview.io.FileFormatI;
82 import jalview.io.FileLoader;
83 import jalview.io.HtmlSvgOutput;
84 import jalview.io.IdentifyFile;
85 import jalview.io.NewickFile;
86 import jalview.io.gff.SequenceOntologyFactory;
87 import jalview.schemes.ColourSchemeI;
88 import jalview.schemes.ColourSchemeProperty;
89 import jalview.util.MessageManager;
90 import jalview.util.Platform;
91 import jalview.ws.jws2.Jws2Discoverer;
94 * Main class for Jalview Application <br>
96 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
99 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
100 * jalview.bin.Jalview jalview.bin.Jalview
102 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
103 * embellish '*' to e.g. '*.jar')
106 * @version $Revision$
111 * singleton instance of this class
113 private static Jalview instance;
115 private Desktop desktop;
117 public static AlignFrame currentAlignFrame;
121 // grab all the rights we can the JVM
122 Policy.setPolicy(new Policy()
125 public PermissionCollection getPermissions(CodeSource codesource)
127 Permissions perms = new Permissions();
128 perms.add(new AllPermission());
133 public void refresh()
140 * keep track of feature fetching tasks.
148 * TODO: generalise to track all jalview events to orchestrate batch processing
152 private int queued = 0;
154 private int running = 0;
156 public FeatureFetcher()
161 public void addFetcher(final AlignFrame af,
162 final Vector<String> dasSources)
164 final long id = System.currentTimeMillis();
166 final FeatureFetcher us = this;
167 new Thread(new Runnable()
179 af.setProgressBar(MessageManager
180 .getString("status.das_features_being_retrived"), id);
181 af.featureSettings_actionPerformed(null);
182 af.setProgressBar(null, id);
191 public synchronized boolean allFinished()
193 return queued == 0 && running == 0;
198 public static Jalview getInstance()
204 * main class for Jalview application
207 * open <em>filename</em>
209 public static void main(String[] args)
211 instance = new Jalview();
212 instance.doMain(args);
218 void doMain(String[] args)
220 System.setSecurityManager(null);
222 .println("Java version: " + System.getProperty("java.version"));
223 System.out.println("Java Home: " + System.getProperty("java.home"));
224 System.out.println(System.getProperty("os.arch") + " "
225 + System.getProperty("os.name") + " "
226 + System.getProperty("os.version"));
227 String val = System.getProperty("sys.install4jVersion");
230 System.out.println("Install4j version: " + val);
232 val = System.getProperty("installer_template_version");
235 System.out.println("Install4j template version: " + val);
237 val = System.getProperty("launcher_version");
240 System.out.println("Launcher version: " + val);
243 // report Jalview version
244 Cache.loadBuildProperties(true);
246 ArgsParser aparser = new ArgsParser(args);
247 boolean headless = false;
249 if (aparser.contains("help") || aparser.contains("h"))
254 if (aparser.contains("nodisplay") || aparser.contains("nogui")
255 || aparser.contains("headless"))
257 System.setProperty("java.awt.headless", "true");
260 String usrPropsFile = aparser.getValue("props");
261 Cache.loadProperties(usrPropsFile); // must do this before
262 if (usrPropsFile != null)
265 "CMD [-props " + usrPropsFile + "] executed successfully!");
270 final String jabawsUrl = aparser.getValue("jabaws");
271 if (jabawsUrl != null)
275 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
277 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
278 } catch (MalformedURLException e)
281 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
285 String defs = aparser.getValue("setprop");
288 int p = defs.indexOf('=');
291 System.err.println("Ignoring invalid setprop argument : " + defs);
295 System.out.println("Executing setprop argument: " + defs);
296 // DISABLED FOR SECURITY REASONS
297 // TODO: add a property to allow properties to be overriden by cli args
298 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
300 defs = aparser.getValue("setprop");
302 if (System.getProperty("java.awt.headless") != null
303 && System.getProperty("java.awt.headless").equals("true"))
307 System.setProperty("http.agent",
308 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
312 } catch (NoClassDefFoundError error)
314 error.printStackTrace();
315 System.out.println("\nEssential logging libraries not found."
316 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
325 * configure 'full' SO model if preferences say to, else use the default (SO
328 if (Cache.getDefault("USE_FULL_SO", true))
330 SequenceOntologyFactory.setInstance(new SequenceOntology());
336 desktop = new Desktop();
337 desktop.setInBatchMode(true); // indicate we are starting up
341 JalviewTaskbar.setTaskbar(this);
342 } catch (Exception e)
344 Cache.log.info("Cannot set Taskbar");
345 Cache.log.error(e.getMessage());
346 // e.printStackTrace();
347 } catch (Throwable t)
349 Cache.log.info("Cannot set Taskbar");
350 Cache.log.error(t.getMessage());
351 // t.printStackTrace();
354 desktop.setVisible(true);
355 desktop.startServiceDiscovery();
356 if (!aparser.contains("nousagestats"))
358 startUsageStats(desktop);
362 System.err.println("CMD [-nousagestats] executed successfully!");
365 if (!aparser.contains("noquestionnaire"))
367 String url = aparser.getValue("questionnaire");
370 // Start the desktop questionnaire prompter with the specified
372 Cache.log.debug("Starting questionnaire url at " + url);
373 desktop.checkForQuestionnaire(url);
375 "CMD questionnaire[-" + url + "] executed successfully!");
379 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
381 // Start the desktop questionnaire prompter with the specified
384 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
386 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
388 "Starting questionnaire with default url: " + defurl);
389 desktop.checkForQuestionnaire(defurl);
395 System.err.println("CMD [-noquestionnaire] executed successfully!");
398 if (!aparser.contains("nonews"))
400 desktop.checkForNews();
403 BioJsHTMLOutput.updateBioJS();
406 // Move any new getdown-launcher-new.jar into place over old
407 // getdown-launcher.jar
408 String appdirString = System.getProperty("getdownappdir");
409 if (appdirString != null && appdirString.length() > 0)
411 final File appdir = new File(appdirString);
417 LaunchUtil.upgradeGetdown(
418 new File(appdir, "getdown-launcher-old.jar"),
419 new File(appdir, "getdown-launcher.jar"),
420 new File(appdir, "getdown-launcher-new.jar"));
425 String file = null, data = null;
426 FileFormatI format = null;
427 DataSourceType protocol = null;
428 FileLoader fileLoader = new FileLoader(!headless);
430 String groovyscript = null; // script to execute after all loading is
431 // completed one way or another
432 // extract groovy argument and execute if necessary
433 groovyscript = aparser.getValue("groovy", true);
434 file = aparser.getValue("open", true);
436 if (file == null && desktop == null)
438 System.out.println("No files to open!");
442 // Finally, deal with the remaining input data.
447 desktop.setProgressBar(
449 .getString("status.processing_commandline_args"),
450 progress = System.currentTimeMillis());
452 System.out.println("CMD [-open " + file + "] executed successfully!");
456 protocol = AppletFormatAdapter.checkProtocol(file);
458 if (protocol == DataSourceType.FILE)
460 if (!(new File(file)).exists())
462 System.out.println("Can't find " + file);
472 format = new IdentifyFile().identify(file, protocol);
473 } catch (FileFormatException e1)
478 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
482 System.out.println("error");
486 setCurrentAlignFrame(af);
487 data = aparser.getValue("colour", true);
490 data.replaceAll("%20", " ");
492 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
493 af.getViewport(), af.getViewport().getAlignment(), data);
498 "CMD [-color " + data + "] executed successfully!");
503 // Must maintain ability to use the groups flag
504 data = aparser.getValue("groups", true);
507 af.parseFeaturesFile(data,
508 AppletFormatAdapter.checkProtocol(data));
509 // System.out.println("Added " + data);
511 "CMD groups[-" + data + "] executed successfully!");
513 data = aparser.getValue("features", true);
516 af.parseFeaturesFile(data,
517 AppletFormatAdapter.checkProtocol(data));
518 // System.out.println("Added " + data);
520 "CMD [-features " + data + "] executed successfully!");
523 data = aparser.getValue("annotations", true);
526 af.loadJalviewDataFile(data, null, null, null);
527 // System.out.println("Added " + data);
529 "CMD [-annotations " + data + "] executed successfully!");
531 // set or clear the sortbytree flag.
532 if (aparser.contains("sortbytree"))
534 af.getViewport().setSortByTree(true);
535 if (af.getViewport().getSortByTree())
537 System.out.println("CMD [-sortbytree] executed successfully!");
540 if (aparser.contains("no-annotation"))
542 af.getViewport().setShowAnnotation(false);
543 if (!af.getViewport().isShowAnnotation())
545 System.out.println("CMD no-annotation executed successfully!");
548 if (aparser.contains("nosortbytree"))
550 af.getViewport().setSortByTree(false);
551 if (!af.getViewport().getSortByTree())
554 .println("CMD [-nosortbytree] executed successfully!");
557 data = aparser.getValue("tree", true);
563 "CMD [-tree " + data + "] executed successfully!");
564 NewickFile nf = new NewickFile(data,
565 AppletFormatAdapter.checkProtocol(data));
567 .setCurrentTree(af.showNewickTree(nf, data).getTree());
568 } catch (IOException ex)
570 System.err.println("Couldn't add tree " + data);
571 ex.printStackTrace(System.err);
574 // TODO - load PDB structure(s) to alignment JAL-629
575 // (associate with identical sequence in alignment, or a specified
577 if (groovyscript != null)
579 // Execute the groovy script after we've done all the rendering stuff
580 // and before any images or figures are generated.
581 System.out.println("Executing script " + groovyscript);
582 executeGroovyScript(groovyscript, af);
583 System.out.println("CMD groovy[" + groovyscript
584 + "] executed successfully!");
587 String imageName = "unnamed.png";
588 while (aparser.getSize() > 1)
590 String outputFormat = aparser.nextValue();
591 file = aparser.nextValue();
593 if (outputFormat.equalsIgnoreCase("png"))
595 af.createPNG(new File(file));
596 imageName = (new File(file)).getName();
597 System.out.println("Creating PNG image: " + file);
600 else if (outputFormat.equalsIgnoreCase("svg"))
602 File imageFile = new File(file);
603 imageName = imageFile.getName();
604 af.createSVG(imageFile);
605 System.out.println("Creating SVG image: " + file);
608 else if (outputFormat.equalsIgnoreCase("html"))
610 File imageFile = new File(file);
611 imageName = imageFile.getName();
612 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
613 htmlSVG.exportHTML(file);
615 System.out.println("Creating HTML image: " + file);
618 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
622 System.err.println("The output html file must not be null");
627 BioJsHTMLOutput.refreshVersionInfo(
628 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
629 } catch (URISyntaxException e)
633 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
634 bjs.exportHTML(file);
636 .println("Creating BioJS MSA Viwer HTML file: " + file);
639 else if (outputFormat.equalsIgnoreCase("imgMap"))
641 af.createImageMap(new File(file), imageName);
642 System.out.println("Creating image map: " + file);
645 else if (outputFormat.equalsIgnoreCase("eps"))
647 File outputFile = new File(file);
649 "Creating EPS file: " + outputFile.getAbsolutePath());
650 af.createEPS(outputFile);
653 FileFormatI outFormat=null;
655 outFormat = FileFormats.getInstance().forName(outputFormat);
656 } catch (Exception formatP) {
657 System.out.println("Couldn't parse "+outFormat+" as a valid Jalview format string.");
659 if (outFormat != null)
661 if (!outFormat.isWritable())
664 "This version of Jalview does not support alignment export as "
669 if (af.saveAlignment(file, outFormat))
671 System.out.println("Written alignment in " + format
672 + " format to " + file);
676 System.out.println("Error writing file " + file + " in "
677 + format + " format!!");
683 while (aparser.getSize() > 0)
685 System.out.println("Unknown arg: " + aparser.nextValue());
689 AlignFrame startUpAlframe = null;
690 // We'll only open the default file if the desktop is visible.
692 // ////////////////////
694 if (!headless && file == null
695 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
697 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
698 jalview.bin.Cache.getDefault("www.jalview.org",
699 "https://www.jalview.org")
700 + "/examples/exampleFile_2_7.jvp");
702 "http://www.jalview.org/examples/exampleFile_2_3.jar") || file.equals(
703 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
705 file.replace("http:", "https:");
706 // hardwire upgrade of the startup file
707 file.replace("_2_3", "_2_7");
708 file.replace("2_7.jar", "2_7.jvp");
709 // and remove the stale setting
710 jalview.bin.Cache.removeProperty("STARTUP_FILE");
713 protocol = DataSourceType.FILE;
715 if (file.indexOf("http:") > -1)
717 protocol = DataSourceType.URL;
720 if (file.endsWith(".jar"))
722 format = FileFormat.Jalview;
728 format = new IdentifyFile().identify(file, protocol);
729 } catch (FileFormatException e)
735 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
737 // extract groovy arguments before anything else.
740 // Once all other stuff is done, execute any groovy scripts (in order)
741 if (groovyscript != null)
743 if (Cache.groovyJarsPresent())
745 System.out.println("Executing script " + groovyscript);
746 executeGroovyScript(groovyscript, startUpAlframe);
751 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
755 // and finally, turn off batch mode indicator - if the desktop still exists
760 desktop.setProgressBar(null, progress);
762 desktop.setInBatchMode(false);
766 private static void setLookAndFeel()
768 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
770 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
772 String lafProp = System.getProperty("laf");
773 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
779 else if (lafSetting != null)
783 boolean lafSet = false;
786 case "crossplatform":
787 lafSet = setCrossPlatformLookAndFeel();
790 Cache.log.error("Could not set requested laf=" + laf);
794 lafSet = setSystemLookAndFeel();
797 Cache.log.error("Could not set requested laf=" + laf);
801 lafSet = setGtkLookAndFeel();
804 Cache.log.error("Could not set requested laf=" + laf);
808 lafSet = setMetalLookAndFeel();
811 Cache.log.error("Could not set requested laf=" + laf);
815 lafSet = setNimbusLookAndFeel();
818 Cache.log.error("Could not set requested laf=" + laf);
822 lafSet = setQuaquaLookAndFeel();
825 Cache.log.error("Could not set requested laf=" + laf);
829 lafSet = setVaquaLookAndFeel();
832 Cache.log.error("Could not set requested laf=" + laf);
836 lafSet = setMacLookAndFeel();
839 Cache.log.error("Could not set requested laf=" + laf);
845 Cache.log.error("Requested laf=" + laf + " not implemented");
849 setSystemLookAndFeel();
850 if (Platform.isLinux())
852 setMetalLookAndFeel();
854 if (Platform.isAMac())
861 private static boolean setCrossPlatformLookAndFeel()
863 return setGenericLookAndFeel(false);
866 private static boolean setSystemLookAndFeel()
868 return setGenericLookAndFeel(true);
871 private static boolean setGenericLookAndFeel(boolean system)
876 UIManager.setLookAndFeel(
877 system ? UIManager.getSystemLookAndFeelClassName()
878 : UIManager.getCrossPlatformLookAndFeelClassName());
880 } catch (Exception ex)
882 Cache.log.error("Unexpected Look and Feel Exception");
883 Cache.log.error(ex.getMessage());
884 Cache.log.debug(Cache.getStackTraceString(ex));
889 private static boolean setSpecificLookAndFeel(String name,
890 String className, boolean nameStartsWith)
895 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
897 if (info.getName() != null && nameStartsWith
898 ? info.getName().toLowerCase()
899 .startsWith(name.toLowerCase())
900 : info.getName().toLowerCase().equals(name.toLowerCase()))
902 className = info.getClassName();
906 UIManager.setLookAndFeel(className);
908 } catch (Exception ex)
910 Cache.log.error("Unexpected Look and Feel Exception");
911 Cache.log.error(ex.getMessage());
912 Cache.log.debug(Cache.getStackTraceString(ex));
917 private static boolean setGtkLookAndFeel()
919 return setSpecificLookAndFeel("gtk",
920 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
923 private static boolean setMetalLookAndFeel()
925 return setSpecificLookAndFeel("metal",
926 "javax.swing.plaf.metal.MetalLookAndFeel", false);
929 private static boolean setNimbusLookAndFeel()
931 return setSpecificLookAndFeel("nimbus",
932 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
935 private static boolean setQuaquaLookAndFeel()
937 return setSpecificLookAndFeel("quaqua",
938 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
943 private static boolean setVaquaLookAndFeel()
945 return setSpecificLookAndFeel("vaqua",
946 "org.violetlib.aqua.AquaLookAndFeel", false);
949 private static boolean setMacLookAndFeel()
952 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
954 System.setProperty("apple.laf.useScreenMenuBar", "true");
955 set = setQuaquaLookAndFeel();
956 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
957 .toLowerCase().contains("quaqua"))
959 set = setVaquaLookAndFeel();
964 private static void showUsage()
967 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
968 + "-nodisplay\tRun Jalview without User Interface.\n"
969 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
970 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
971 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
972 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
973 + "-features FILE\tUse the given file to mark features on the alignment.\n"
974 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
975 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
976 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
977 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
978 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
979 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
980 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
981 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
982 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
983 + "-png FILE\tCreate PNG image FILE from alignment.\n"
984 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
985 + "-html FILE\tCreate HTML file from alignment.\n"
986 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
987 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
988 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
989 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
990 + "-noquestionnaire\tTurn off questionnaire check.\n"
991 + "-nonews\tTurn off check for Jalview news.\n"
992 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
993 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
995 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
996 // after all other properties files have been read\n\t
997 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
998 // passed in correctly)"
999 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1000 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1001 + "-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"
1002 + "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
1003 + "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
1004 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1007 private static void startUsageStats(final Desktop desktop)
1010 * start a User Config prompt asking if we can log usage statistics.
1012 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1013 "USAGESTATS", "Jalview Usage Statistics",
1014 "Do you want to help make Jalview better by enabling "
1015 + "the collection of usage statistics with Google Analytics ?"
1016 + "\n\n(you can enable or disable usage tracking in the preferences)",
1023 "Initialising googletracker for usage stats.");
1024 Cache.initGoogleTracker();
1025 Cache.log.debug("Tracking enabled.");
1032 Cache.log.debug("Not enabling Google Tracking.");
1035 desktop.addDialogThread(prompter);
1039 * Locate the given string as a file and pass it to the groovy interpreter.
1041 * @param groovyscript
1042 * the script to execute
1043 * @param jalviewContext
1044 * the Jalview Desktop object passed in to the groovy binding as the
1047 private void executeGroovyScript(String groovyscript, AlignFrame af)
1050 * for scripts contained in files
1057 if (groovyscript.trim().equals("STDIN"))
1059 // read from stdin into a tempfile and execute it
1062 tfile = File.createTempFile("jalview", "groovy");
1063 PrintWriter outfile = new PrintWriter(
1064 new OutputStreamWriter(new FileOutputStream(tfile)));
1065 BufferedReader br = new BufferedReader(
1066 new InputStreamReader(System.in));
1068 while ((line = br.readLine()) != null)
1070 outfile.write(line + "\n");
1076 } catch (Exception ex)
1078 System.err.println("Failed to read from STDIN into tempfile "
1079 + ((tfile == null) ? "(tempfile wasn't created)"
1080 : tfile.toString()));
1081 ex.printStackTrace();
1086 sfile = tfile.toURI().toURL();
1087 } catch (Exception x)
1090 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1092 x.printStackTrace();
1100 sfile = new URI(groovyscript).toURL();
1101 } catch (Exception x)
1103 tfile = new File(groovyscript);
1104 if (!tfile.exists())
1106 System.err.println("File '" + groovyscript + "' does not exist.");
1109 if (!tfile.canRead())
1111 System.err.println("File '" + groovyscript + "' cannot be read.");
1114 if (tfile.length() < 1)
1116 System.err.println("File '" + groovyscript + "' is empty.");
1121 sfile = tfile.getAbsoluteFile().toURI().toURL();
1122 } catch (Exception ex)
1124 System.err.println("Failed to create a file URL for "
1125 + tfile.getAbsoluteFile());
1132 Map<String, java.lang.Object> vbinding = new HashMap<>();
1133 vbinding.put("Jalview", this);
1136 vbinding.put("currentAlFrame", af);
1138 Binding gbinding = new Binding(vbinding);
1139 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1140 gse.run(sfile.toString(), gbinding);
1141 if ("STDIN".equals(groovyscript))
1143 // delete temp file that we made -
1144 // only if it was successfully executed
1147 } catch (Exception e)
1149 System.err.println("Exception Whilst trying to execute file " + sfile
1150 + " as a groovy script.");
1151 e.printStackTrace(System.err);
1156 public static boolean isHeadlessMode()
1158 String isheadless = System.getProperty("java.awt.headless");
1159 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1166 public AlignFrame[] getAlignFrames()
1168 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1169 : Desktop.getAlignFrames();
1174 * Quit method delegates to Desktop.quit - unless running in headless mode
1175 * when it just ends the JVM
1179 if (desktop != null)
1189 public static AlignFrame getCurrentAlignFrame()
1191 return Jalview.currentAlignFrame;
1194 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1196 Jalview.currentAlignFrame = currentAlignFrame;