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.FileLoader;
34 import jalview.io.HtmlSvgOutput;
35 import jalview.io.IdentifyFile;
36 import jalview.io.NewickFile;
37 import jalview.io.gff.SequenceOntologyFactory;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.ColourSchemeProperty;
40 import jalview.util.MessageManager;
41 import jalview.util.Platform;
42 import jalview.ws.jws2.Jws2Discoverer;
44 import java.io.BufferedReader;
46 import java.io.FileOutputStream;
47 import java.io.IOException;
48 import java.io.InputStreamReader;
49 import java.io.OutputStreamWriter;
50 import java.io.PrintWriter;
51 import java.net.MalformedURLException;
53 import java.net.URISyntaxException;
55 import java.security.AllPermission;
56 import java.security.CodeSource;
57 import java.security.PermissionCollection;
58 import java.security.Permissions;
59 import java.security.Policy;
60 import java.util.HashMap;
62 import java.util.Vector;
63 import java.util.logging.ConsoleHandler;
64 import java.util.logging.Level;
65 import java.util.logging.Logger;
67 import javax.swing.LookAndFeel;
68 import javax.swing.UIManager;
70 import groovy.lang.Binding;
71 import groovy.util.GroovyScriptEngine;
74 * Main class for Jalview Application <br>
76 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
79 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
80 * jalview.bin.Jalview jalview.bin.Jalview
82 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
83 * embellish '*' to e.g. '*.jar')
92 Platform.getURLCommandArguments();
95 private boolean headless;
97 public static boolean isHeadlessMode()
99 return getInstance().headless;
103 * singleton instance of this class in Java only
106 private static Jalview instance;
108 public static Jalview getInstance()
111 @SuppressWarnings("unused")
112 ThreadGroup g = Thread.currentThread().getThreadGroup();
114 * @j2sNative j = g._jalviewInstance;
122 private static void setInstance(Jalview j)
124 @SuppressWarnings("unused")
125 ThreadGroup g = Thread.currentThread().getThreadGroup();
127 * @j2s g._jalviewInstance = j;
134 private Desktop desktop;
136 private AlignFrame currentAlignFrame;
138 public static AlignFrame getCurrentAlignFrame()
140 return getInstance().currentAlignFrame;
143 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
145 getInstance().currentAlignFrame = currentAlignFrame;
150 if (!Platform.isJS())
157 // grab all the rights we can for the JVM
158 Policy.setPolicy(new Policy()
161 public PermissionCollection getPermissions(CodeSource codesource)
163 Permissions perms = new Permissions();
164 perms.add(new AllPermission());
169 public void refresh()
177 * keep track of feature fetching tasks.
185 * TODO: generalise to track all jalview events to orchestrate batch
189 private int queued = 0;
191 private int running = 0;
193 public FeatureFetcher()
198 public void addFetcher(final AlignFrame af,
199 final Vector<String> dasSources)
201 final long id = System.currentTimeMillis();
203 final FeatureFetcher us = this;
204 new Thread(new Runnable()
216 af.setProgressBar(MessageManager
217 .getString("status.das_features_being_retrived"), id);
218 af.featureSettings_actionPerformed(null);
219 af.setProgressBar(null, id);
228 public synchronized boolean allFinished()
230 return queued == 0 && running == 0;
236 * main class for Jalview application
239 * open <em>filename</em>
241 public static void main(String[] args)
243 // setLogging(); // BH - for event debugging in JavaScript
244 setInstance(new Jalview());
245 getInstance().doMain(args);
248 private static void logClass(String name)
250 // BH - for event debugging in JavaScript
251 ConsoleHandler consoleHandler = new ConsoleHandler();
252 consoleHandler.setLevel(Level.ALL);
253 Logger logger = Logger.getLogger(name);
254 logger.setLevel(Level.ALL);
255 logger.addHandler(consoleHandler);
258 @SuppressWarnings("unused")
259 private static void setLogging()
267 System.out.println("not in js");
270 // BH - for event debugging in JavaScript (Java mode only)
271 if (!Platform.isJS())
278 Logger.getLogger("").setLevel(Level.ALL);
279 logClass("java.awt.EventDispatchThread");
280 logClass("java.awt.EventQueue");
281 logClass("java.awt.Component");
282 logClass("java.awt.focus.Component");
283 logClass("java.awt.focus.DefaultKeyboardFocusManager");
291 void doMain(String[] args)
294 if (!Platform.isJS())
296 System.setSecurityManager(null);
300 .println("Java version: " + System.getProperty("java.version"));
301 System.out.println(System.getProperty("os.arch") + " "
302 + System.getProperty("os.name") + " "
303 + System.getProperty("os.version"));
305 ArgsParser aparser = new ArgsParser(args);
307 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
308 Cache.loadProperties(usrPropsFile);
309 if (usrPropsFile != null)
312 "CMD [-props " + usrPropsFile + "] executed successfully!");
315 if (!Platform.isJS())
322 if (aparser.contains("help") || aparser.contains("h"))
327 if (aparser.contains(ArgsParser.NODISPLAY)
328 || aparser.contains(ArgsParser.NOGUI)
329 || aparser.contains(ArgsParser.HEADLESS)
330 || "true".equals(System.getProperty("java.awt.headless")))
337 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
338 if (jabawsUrl != null)
342 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
344 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
345 } catch (MalformedURLException e)
348 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
353 // check for property setting
354 String defs = aparser.getValue(ArgsParser.SETPROP);
357 int p = defs.indexOf('=');
360 System.err.println("Ignoring invalid setprop argument : " + defs);
364 System.out.println("Executing setprop argument: " + defs);
367 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
370 defs = aparser.getValue(ArgsParser.SETPROP);
372 System.setProperty("http.agent",
373 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
377 } catch (NoClassDefFoundError error)
379 error.printStackTrace();
380 System.out.println("\nEssential logging libraries not found."
381 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
389 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
390 } catch (Exception ex)
392 System.err.println("Unexpected Look and Feel Exception");
393 ex.printStackTrace();
395 if (Platform.isAMacAndNotJS())
398 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
400 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
402 System.setProperty("apple.laf.useScreenMenuBar", "true");
403 if (lookAndFeel != null)
407 UIManager.setLookAndFeel(lookAndFeel);
408 } catch (Throwable e)
411 "Failed to set QuaQua look and feel: " + e.toString());
414 if (lookAndFeel == null
415 || !(lookAndFeel.getClass().isAssignableFrom(
416 UIManager.getLookAndFeel().getClass()))
417 || !UIManager.getLookAndFeel().getClass().toString()
418 .toLowerCase().contains("quaqua"))
423 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
424 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
425 } catch (Throwable e)
428 "Failed to reset look and feel: " + e.toString());
434 * configure 'full' SO model if preferences say to,
435 * else use the default (SO Lite)
437 if (Cache.getDefault("USE_FULL_SO", false))
439 SequenceOntologyFactory.setInstance(new SequenceOntology());
444 desktop = new Desktop();
445 desktop.setInBatchMode(true); // indicate we are starting up
446 desktop.setVisible(true);
448 if (!Platform.isJS())
455 desktop.startServiceDiscovery();
456 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
458 startUsageStats(desktop);
462 System.err.println("CMD [-nousagestats] executed successfully!");
465 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
467 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
470 // Start the desktop questionnaire prompter with the specified
472 Cache.log.debug("Starting questionnaire url at " + url);
473 desktop.checkForQuestionnaire(url);
474 System.out.println("CMD questionnaire[-" + url
475 + "] executed successfully!");
479 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
481 // Start the desktop questionnaire prompter with the specified
484 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
486 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
488 "Starting questionnaire with default url: " + defurl);
489 desktop.checkForQuestionnaire(defurl);
496 .println("CMD [-noquestionnaire] executed successfully!");
499 if (!aparser.contains(ArgsParser.NONEWS))
501 desktop.checkForNews();
504 BioJsHTMLOutput.updateBioJS();
509 FileFormatI format = null;
510 DataSourceType protocol = null;
511 FileLoader fileLoader = new FileLoader(!headless);
513 // script to execute after all loading is
514 // completed one way or another
515 // extract groovy argument and execute if necessary
516 String groovyscript = aparser.getValue(ArgsParser.GROOVY, true);
517 String file = aparser.getValue(ArgsParser.OPEN, true);
519 if (file == null && desktop == null)
521 System.out.println("No files to open!");
524 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
525 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
526 if (vamsasImport != null || vamsasSession != null)
528 if (desktop == null || headless)
531 "Headless vamsas sessions not yet supported. Sorry.");
534 // if we have a file, start a new session and import it.
535 boolean inSession = false;
536 if (vamsasImport != null)
540 DataSourceType viprotocol = AppletFormatAdapter
541 .checkProtocol(vamsasImport);
542 if (viprotocol == DataSourceType.FILE)
544 inSession = desktop.vamsasImport(new File(vamsasImport));
546 else if (viprotocol == DataSourceType.URL)
548 inSession = desktop.vamsasImport(new URL(vamsasImport));
551 } catch (Exception e)
553 System.err.println("Exeption when importing " + vamsasImport
554 + " as a vamsas document.");
559 System.err.println("Failed to import " + vamsasImport
560 + " as a vamsas document.");
564 System.out.println("Imported Successfully into new session "
565 + desktop.getVamsasApplication().getCurrentSession());
568 if (vamsasSession != null)
570 if (vamsasImport != null)
572 // close the newly imported session and import the Jalview specific
573 // remnants into the new session later on.
574 desktop.vamsasStop_actionPerformed(null);
576 // now join the new session
579 if (desktop.joinVamsasSession(vamsasSession))
582 "Successfully joined vamsas session " + vamsasSession);
586 System.err.println("WARNING: Failed to join vamsas session "
589 } catch (Exception e)
592 "ERROR: Failed to join vamsas session " + vamsasSession);
595 if (vamsasImport != null)
597 // the Jalview specific remnants can now be imported into the new
598 // session at the user's leisure.
600 "Skipping Push for import of data into existing vamsas session."); // TODO:
605 // desktop.getVamsasApplication().push_update();
610 // Finally, deal with the remaining input data.
615 desktop.setProgressBar(
617 .getString("status.processing_commandline_args"),
618 progress = System.currentTimeMillis());
620 System.out.println("CMD [-open " + file + "] executed successfully!");
622 if (!Platform.isJS())
624 * ignore in JavaScript -- can't just check file existence - could load
630 if (!file.startsWith("http://") && !file.startsWith("https://"))
631 // BH 2019 added https check for Java
633 if (!(new File(file)).exists())
635 System.out.println("Can't find " + file);
644 protocol = AppletFormatAdapter.checkProtocol(file);
648 format = new IdentifyFile().identify(file, protocol);
649 } catch (FileFormatException e1)
654 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
658 System.out.println("error");
662 setCurrentAlignFrame(af);
663 data = aparser.getValue(ArgsParser.COLOUR, true);
666 data.replaceAll("%20", " ");
668 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
669 af.getViewport(), af.getViewport().getAlignment(), data);
674 "CMD [-color " + data + "] executed successfully!");
679 // Must maintain ability to use the groups flag
680 data = aparser.getValue(ArgsParser.GROUPS, true);
683 af.parseFeaturesFile(data,
684 AppletFormatAdapter.checkProtocol(data));
685 // System.out.println("Added " + data);
687 "CMD groups[-" + data + "] executed successfully!");
689 data = aparser.getValue(ArgsParser.FEATURES, true);
692 af.parseFeaturesFile(data,
693 AppletFormatAdapter.checkProtocol(data));
694 // System.out.println("Added " + data);
696 "CMD [-features " + data + "] executed successfully!");
699 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
702 af.loadJalviewDataFile(data, null, null, null);
703 // System.out.println("Added " + data);
705 "CMD [-annotations " + data + "] executed successfully!");
707 // set or clear the sortbytree flag.
708 if (aparser.contains(ArgsParser.SORTBYTREE))
710 af.getViewport().setSortByTree(true);
711 if (af.getViewport().getSortByTree())
713 System.out.println("CMD [-sortbytree] executed successfully!");
716 if (aparser.contains(ArgsParser.NOANNOTATION)
717 || aparser.contains(ArgsParser.NOANNOTATION2))
719 af.getViewport().setShowAnnotation(false);
720 if (!af.getViewport().isShowAnnotation())
722 System.out.println("CMD no-annotation executed successfully!");
725 if (aparser.contains(ArgsParser.NOSORTBYTREE))
727 af.getViewport().setSortByTree(false);
728 if (!af.getViewport().getSortByTree())
731 .println("CMD [-nosortbytree] executed successfully!");
734 data = aparser.getValue(ArgsParser.TREE, true);
740 "CMD [-tree " + data + "] executed successfully!");
741 NewickFile nf = new NewickFile(data,
742 AppletFormatAdapter.checkProtocol(data));
744 .setCurrentTree(af.showNewickTree(nf, data).getTree());
745 } catch (IOException ex)
747 System.err.println("Couldn't add tree " + data);
748 ex.printStackTrace(System.err);
751 // TODO - load PDB structure(s) to alignment JAL-629
752 // (associate with identical sequence in alignment, or a specified
754 if (groovyscript != null)
756 // Execute the groovy script after we've done all the rendering stuff
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!");
764 String imageName = "unnamed.png";
765 while (aparser.getSize() > 1)
771 String outputFormat = aparser.nextValue();
772 file = aparser.nextValue();
774 if (outputFormat.equalsIgnoreCase("png"))
776 af.createPNG(new File(file));
777 imageName = (new File(file)).getName();
778 System.out.println("Creating PNG image: " + file);
781 else if (outputFormat.equalsIgnoreCase("svg"))
783 File imageFile = new File(file);
784 imageName = imageFile.getName();
785 af.createSVG(imageFile);
786 System.out.println("Creating SVG image: " + file);
789 else if (outputFormat.equalsIgnoreCase("html"))
791 File imageFile = new File(file);
792 imageName = imageFile.getName();
793 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
794 htmlSVG.exportHTML(file);
796 System.out.println("Creating HTML image: " + file);
799 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
803 System.err.println("The output html file must not be null");
808 BioJsHTMLOutput.refreshVersionInfo(
809 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
810 } catch (URISyntaxException e)
814 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
815 bjs.exportHTML(file);
817 .println("Creating BioJS MSA Viwer HTML file: " + file);
820 else if (outputFormat.equalsIgnoreCase("imgMap"))
822 af.createImageMap(new File(file), imageName);
823 System.out.println("Creating image map: " + file);
826 else if (outputFormat.equalsIgnoreCase("eps"))
828 File outputFile = new File(file);
830 "Creating EPS file: " + outputFile.getAbsolutePath());
831 af.createEPS(outputFile);
835 af.saveAlignment(file, format);
836 if (af.isSaveAlignmentSuccessful())
838 System.out.println("Written alignment in " + format
839 + " format to " + file);
843 System.out.println("Error writing file " + file + " in "
844 + format + " format!!");
849 while (aparser.getSize() > 0)
851 System.out.println("Unknown arg: " + aparser.nextValue());
855 AlignFrame startUpAlframe = null;
856 // We'll only open the default file if the desktop is visible.
858 // ////////////////////
860 if (!Platform.isJS() && !headless && file == null
861 && vamsasImport == null
862 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
869 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
870 jalview.bin.Cache.getDefault("www.jalview.org",
871 "http://www.jalview.org")
872 + "/examples/exampleFile_2_7.jar");
874 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
876 // hardwire upgrade of the startup file
877 file.replace("_2_3.jar", "_2_7.jar");
878 // and remove the stale setting
879 jalview.bin.Cache.removeProperty("STARTUP_FILE");
882 protocol = DataSourceType.FILE;
884 if (file.indexOf("http:") > -1)
886 protocol = DataSourceType.URL;
889 if (file.endsWith(".jar"))
891 format = FileFormat.Jalview;
897 format = new IdentifyFile().identify(file, protocol);
898 } catch (FileFormatException e)
904 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
906 // extract groovy arguments before anything else.
909 // Once all other stuff is done, execute any groovy scripts (in order)
910 if (groovyscript != null)
912 if (Cache.groovyJarsPresent())
914 System.out.println("Executing script " + groovyscript);
915 executeGroovyScript(groovyscript, startUpAlframe);
920 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
924 // and finally, turn off batch mode indicator - if the desktop still exists
929 desktop.setProgressBar(null, progress);
931 desktop.setInBatchMode(false);
935 private static void showUsage()
938 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
939 + "-nodisplay\tRun Jalview without User Interface.\n"
940 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
941 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
942 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
943 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
944 + "-features FILE\tUse the given file to mark features on the alignment.\n"
945 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
946 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
947 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
948 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
949 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
950 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
951 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
952 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
953 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
954 + "-png FILE\tCreate PNG image FILE from alignment.\n"
955 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
956 + "-html FILE\tCreate HTML file from alignment.\n"
957 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
958 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
959 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
960 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
961 + "-noquestionnaire\tTurn off questionnaire check.\n"
962 + "-nonews\tTurn off check for Jalview news.\n"
963 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
964 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
966 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
967 // after all other properties files have been read\n\t
968 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
969 // passed in correctly)"
970 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
971 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
973 // "-vdoc vamsas-document\tImport vamsas document into new
974 // session or join existing session with same URN\n"
975 // + "-vses vamsas-session\tJoin session with given URN\n"
976 + "-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"
977 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
980 private static void startUsageStats(final Desktop desktop)
983 * start a User Config prompt asking if we can log usage statistics.
985 PromptUserConfig prompter = new PromptUserConfig(
986 Desktop.getDesktopPane(), "USAGESTATS",
987 "Jalview Usage Statistics",
988 "Do you want to help make Jalview better by enabling "
989 + "the collection of usage statistics with Google Analytics ?"
990 + "\n\n(you can enable or disable usage tracking in the preferences)",
997 "Initialising googletracker for usage stats.");
998 Cache.initGoogleTracker();
999 Cache.log.debug("Tracking enabled.");
1006 Cache.log.debug("Not enabling Google Tracking.");
1009 desktop.addDialogThread(prompter);
1013 * Locate the given string as a file and pass it to the groovy interpreter.
1015 * @param groovyscript
1016 * the script to execute
1017 * @param jalviewContext
1018 * the Jalview Desktop object passed in to the groovy binding as the
1021 private void executeGroovyScript(String groovyscript, AlignFrame af)
1024 * for scripts contained in files
1031 if (groovyscript.trim().equals("STDIN"))
1033 // read from stdin into a tempfile and execute it
1036 tfile = File.createTempFile("jalview", "groovy");
1037 PrintWriter outfile = new PrintWriter(
1038 new OutputStreamWriter(new FileOutputStream(tfile)));
1039 BufferedReader br = new BufferedReader(
1040 new InputStreamReader(System.in));
1042 while ((line = br.readLine()) != null)
1044 outfile.write(line + "\n");
1050 } catch (Exception ex)
1052 System.err.println("Failed to read from STDIN into tempfile "
1053 + ((tfile == null) ? "(tempfile wasn't created)"
1054 : tfile.toString()));
1055 ex.printStackTrace();
1060 sfile = tfile.toURI().toURL();
1061 } catch (Exception x)
1064 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1066 x.printStackTrace();
1074 sfile = new URI(groovyscript).toURL();
1075 } catch (Exception x)
1077 tfile = new File(groovyscript);
1078 if (!tfile.exists())
1080 System.err.println("File '" + groovyscript + "' does not exist.");
1083 if (!tfile.canRead())
1085 System.err.println("File '" + groovyscript + "' cannot be read.");
1088 if (tfile.length() < 1)
1090 System.err.println("File '" + groovyscript + "' is empty.");
1095 sfile = tfile.getAbsoluteFile().toURI().toURL();
1096 } catch (Exception ex)
1098 System.err.println("Failed to create a file URL for "
1099 + tfile.getAbsoluteFile());
1106 Map<String, Object> vbinding = new HashMap<>();
1107 vbinding.put("Jalview", this);
1110 vbinding.put("currentAlFrame", af);
1112 Binding gbinding = new Binding(vbinding);
1113 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1114 gse.run(sfile.toString(), gbinding);
1115 if ("STDIN".equals(groovyscript))
1117 // delete temp file that we made -
1118 // only if it was successfully executed
1121 } catch (Exception e)
1123 System.err.println("Exception Whilst trying to execute file " + sfile
1124 + " as a groovy script.");
1125 e.printStackTrace(System.err);
1130 public AlignFrame[] getAlignFrames()
1132 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1133 : Desktop.getAlignFrames();
1138 * Quit method delegates to Desktop.quit - unless running in headless mode
1139 * when it just ends the JVM
1143 if (desktop != null)