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.awt.event.ActionEvent;
45 import java.awt.event.ActionListener;
46 import java.io.BufferedReader;
48 import java.io.FileOutputStream;
49 import java.io.IOException;
50 import java.io.InputStreamReader;
51 import java.io.OutputStreamWriter;
52 import java.io.PrintWriter;
53 import java.net.MalformedURLException;
55 import java.net.URISyntaxException;
57 import java.security.AllPermission;
58 import java.security.CodeSource;
59 import java.security.PermissionCollection;
60 import java.security.Permissions;
61 import java.security.Policy;
62 import java.util.HashMap;
64 import java.util.Vector;
65 import java.util.logging.ConsoleHandler;
66 import java.util.logging.Level;
67 import java.util.logging.Logger;
69 import javax.swing.LookAndFeel;
70 import javax.swing.Timer;
71 import javax.swing.UIManager;
73 import groovy.lang.Binding;
74 import groovy.util.GroovyScriptEngine;
77 * Main class for Jalview Application <br>
79 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
82 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
83 * jalview.bin.Jalview jalview.bin.Jalview
85 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
86 * embellish '*' to e.g. '*.jar')
96 * // set space-delimited query parameters as arguments to Jalview main
97 * hr = decodeURI(document.location.href);
98 * pos = hr.indexOf("?");
101 * thisApplet.__Info.args = hr.substring(pos+1).split(" ");
106 * singleton instance of this class
108 private static Jalview instance;
110 private Desktop desktop;
112 public static AlignFrame currentAlignFrame;
114 //BH 2019.01.25 moved to Platform
116 // * Answers true if Jalview is running as Javascript, else false. The value is
117 // * set at compile time.
121 //public static boolean isJS()
123 // return /** @j2sNative true || */
129 if (!Platform.isJS())
131 // grab all the rights we can the JVM
132 Policy.setPolicy(new Policy()
135 public PermissionCollection getPermissions(CodeSource codesource)
137 Permissions perms = new Permissions();
138 perms.add(new AllPermission());
143 public void refresh()
152 * keep track of feature fetching tasks.
160 * TODO: generalise to track all jalview events to orchestrate batch
164 private int queued = 0;
166 private int running = 0;
168 public FeatureFetcher()
173 public void addFetcher(final AlignFrame af,
174 final Vector<String> dasSources)
176 final long id = System.currentTimeMillis();
178 final FeatureFetcher us = this;
179 new Thread(new Runnable()
191 af.setProgressBar(MessageManager
192 .getString("status.das_features_being_retrived"), id);
193 af.featureSettings_actionPerformed(null);
194 af.setProgressBar(null, id);
203 public synchronized boolean allFinished()
205 return queued == 0 && running == 0;
210 public static Jalview getInstance()
216 * main class for Jalview application
219 * open <em>filename</em>
221 public static void main(String[] args)
223 // setLogging(); // BH - for event debugging in JavaScript
224 instance = new Jalview();
225 instance.doMain(args);
228 private static void logClass(String name)
230 // BH - for event debugging in JavaScript
231 ConsoleHandler consoleHandler = new ConsoleHandler();
232 consoleHandler.setLevel(Level.ALL);
233 Logger logger = Logger.getLogger(name);
234 logger.setLevel(Level.ALL);
235 logger.addHandler(consoleHandler);
238 @SuppressWarnings("unused")
239 private static void setLogging()
241 // BH - for event debugging in JavaScript (Java mode only)
242 if (!(/** @j2sNative true ||*/false))
244 Logger.getLogger("").setLevel(Level.ALL);
245 logClass("java.awt.EventDispatchThread");
246 logClass("java.awt.EventQueue");
247 logClass("java.awt.Component");
248 logClass("java.awt.focus.Component");
249 logClass("java.awt.focus.DefaultKeyboardFocusManager");
260 void doMain(String[] args)
263 if (!Platform.isJS())
265 System.setSecurityManager(null);
269 .println("Java version: " + System.getProperty("java.version"));
270 System.out.println(System.getProperty("os.arch") + " "
271 + System.getProperty("os.name") + " "
272 + System.getProperty("os.version"));
274 ArgsParser aparser = new ArgsParser(args);
275 boolean headless = false;
277 String usrPropsFile = aparser.getValue("props");
278 Cache.loadProperties(usrPropsFile); // must do this before
279 if (usrPropsFile != null)
282 "CMD [-props " + usrPropsFile + "] executed successfully!");
286 * BH 2018 ignoring this section for JS
291 if (aparser.contains("help") || aparser.contains("h"))
296 if (aparser.contains("nodisplay") || aparser.contains("nogui")
297 || aparser.contains("headless"))
299 System.setProperty("java.awt.headless", "true");
304 final String jabawsUrl = aparser.getValue("jabaws");
305 if (jabawsUrl != null)
309 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
311 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
312 } catch (MalformedURLException e)
315 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
320 String defs = aparser.getValue("setprop");
323 int p = defs.indexOf('=');
326 System.err.println("Ignoring invalid setprop argument : " + defs);
330 System.out.println("Executing setprop argument: " + defs);
331 // DISABLED FOR SECURITY REASONS
332 // TODO: add a property to allow properties to be overriden by cli args
333 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
335 defs = aparser.getValue("setprop");
337 if (System.getProperty("java.awt.headless") != null
338 && System.getProperty("java.awt.headless").equals("true"))
342 System.setProperty("http.agent",
343 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
347 } catch (NoClassDefFoundError error)
349 error.printStackTrace();
350 System.out.println("\nEssential logging libraries not found."
351 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
359 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
360 } catch (Exception ex)
362 System.err.println("Unexpected Look and Feel Exception");
363 ex.printStackTrace();
365 if (Platform.isAMacAndNotJS())
368 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
370 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
372 System.setProperty("apple.laf.useScreenMenuBar", "true");
373 if (lookAndFeel != null)
377 UIManager.setLookAndFeel(lookAndFeel);
378 } catch (Throwable e)
381 "Failed to set QuaQua look and feel: " + e.toString());
384 if (lookAndFeel == null || !(lookAndFeel.getClass()
385 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
386 || !UIManager.getLookAndFeel().getClass().toString()
387 .toLowerCase().contains("quaqua"))
392 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
393 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
394 } catch (Throwable e)
397 "Failed to reset look and feel: " + e.toString());
403 * configure 'full' SO model if preferences say to,
404 * else use the default (SO Lite)
406 if (Cache.getDefault("USE_FULL_SO", false))
408 SequenceOntologyFactory.setInstance(new SequenceOntology());
413 desktop = new Desktop()
417 // protected void processEvent(AWTEvent e) {
418 // System.out.println("Jalview.java " + e);
419 // super.processEvent(e);
423 desktop.setInBatchMode(true); // indicate we are starting up
424 desktop.setVisible(true);
427 * BH 2018 JS bypass this section
433 desktop.startServiceDiscovery();
434 if (!aparser.contains("nousagestats"))
436 startUsageStats(desktop);
440 System.err.println("CMD [-nousagestats] executed successfully!");
443 if (!aparser.contains("noquestionnaire"))
445 String url = aparser.getValue("questionnaire");
448 // Start the desktop questionnaire prompter with the specified
450 Cache.log.debug("Starting questionnaire url at " + url);
451 desktop.checkForQuestionnaire(url);
452 System.out.println("CMD questionnaire[-" + url
453 + "] executed successfully!");
457 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
459 // Start the desktop questionnaire prompter with the specified
462 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
464 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
466 "Starting questionnaire with default url: " + defurl);
467 desktop.checkForQuestionnaire(defurl);
474 .println("CMD [-noquestionnaire] executed successfully!");
477 if (!aparser.contains("nonews"))
479 desktop.checkForNews();
482 BioJsHTMLOutput.updateBioJS();
486 String file = null, data = null;
487 FileFormatI format = null;
488 DataSourceType protocol = null;
489 FileLoader fileLoader = new FileLoader(!headless);
490 Vector<String> getFeatures = null; // vector of das source nicknames to
494 String groovyscript = null; // script to execute after all loading is
495 // completed one way or another
496 // extract groovy argument and execute if necessary
497 groovyscript = aparser.getValue("groovy", true);
498 file = aparser.getValue("open", true);
500 if (file == null && desktop == null)
502 System.out.println("No files to open!");
505 String vamsasImport = aparser.getValue("vdoc");
506 String vamsasSession = aparser.getValue("vsess");
507 if (vamsasImport != null || vamsasSession != null)
509 if (desktop == null || headless)
512 "Headless vamsas sessions not yet supported. Sorry.");
515 // if we have a file, start a new session and import it.
516 boolean inSession = false;
517 if (vamsasImport != null)
521 DataSourceType viprotocol = AppletFormatAdapter
522 .checkProtocol(vamsasImport);
523 if (viprotocol == DataSourceType.FILE)
525 inSession = desktop.vamsasImport(new File(vamsasImport));
527 else if (viprotocol == DataSourceType.URL)
529 inSession = desktop.vamsasImport(new URL(vamsasImport));
532 } catch (Exception e)
534 System.err.println("Exeption when importing " + vamsasImport
535 + " as a vamsas document.");
540 System.err.println("Failed to import " + vamsasImport
541 + " as a vamsas document.");
545 System.out.println("Imported Successfully into new session "
546 + desktop.getVamsasApplication().getCurrentSession());
549 if (vamsasSession != null)
551 if (vamsasImport != null)
553 // close the newly imported session and import the Jalview specific
554 // remnants into the new session later on.
555 desktop.vamsasStop_actionPerformed(null);
557 // now join the new session
560 if (desktop.joinVamsasSession(vamsasSession))
563 "Successfully joined vamsas session " + vamsasSession);
567 System.err.println("WARNING: Failed to join vamsas session "
570 } catch (Exception e)
573 "ERROR: Failed to join vamsas session " + vamsasSession);
576 if (vamsasImport != null)
578 // the Jalview specific remnants can now be imported into the new
579 // session at the user's leisure.
581 "Skipping Push for import of data into existing vamsas session."); // TODO:
586 // desktop.getVamsasApplication().push_update();
591 // Finally, deal with the remaining input data.
596 desktop.setProgressBar(
598 .getString("status.processing_commandline_args"),
599 progress = System.currentTimeMillis());
601 System.out.println("CMD [-open " + file + "] executed successfully!");
603 if (!Platform.isJS() && !file.startsWith("http://"))
605 if (!(new File(file)).exists())
607 System.out.println("Can't find " + file);
615 protocol = AppletFormatAdapter.checkProtocol(file);
619 format = new IdentifyFile().identify(file, protocol);
620 } catch (FileFormatException e1)
625 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
629 System.out.println("error");
633 setCurrentAlignFrame(af);
634 data = aparser.getValue("colour", true);
637 data.replaceAll("%20", " ");
639 ColourSchemeI cs = ColourSchemeProperty
640 .getColourScheme(af.getViewport().getAlignment(), data);
645 "CMD [-color " + data + "] executed successfully!");
650 // Must maintain ability to use the groups flag
651 data = aparser.getValue("groups", true);
654 af.parseFeaturesFile(data,
655 AppletFormatAdapter.checkProtocol(data));
656 // System.out.println("Added " + data);
658 "CMD groups[-" + data + "] executed successfully!");
660 data = aparser.getValue("features", true);
663 af.parseFeaturesFile(data,
664 AppletFormatAdapter.checkProtocol(data));
665 // System.out.println("Added " + data);
667 "CMD [-features " + data + "] executed successfully!");
670 data = aparser.getValue("annotations", true);
673 af.loadJalviewDataFile(data, null, null, null);
674 // System.out.println("Added " + data);
676 "CMD [-annotations " + data + "] executed successfully!");
678 // set or clear the sortbytree flag.
679 if (aparser.contains("sortbytree"))
681 af.getViewport().setSortByTree(true);
682 if (af.getViewport().getSortByTree())
684 System.out.println("CMD [-sortbytree] executed successfully!");
687 if (aparser.contains("no-annotation"))
689 af.getViewport().setShowAnnotation(false);
690 if (!af.getViewport().isShowAnnotation())
692 System.out.println("CMD no-annotation executed successfully!");
695 if (aparser.contains("nosortbytree"))
697 af.getViewport().setSortByTree(false);
698 if (!af.getViewport().getSortByTree())
701 .println("CMD [-nosortbytree] executed successfully!");
704 data = aparser.getValue("tree", true);
710 "CMD [-tree " + data + "] executed successfully!");
711 NewickFile nf = new NewickFile(data,
712 AppletFormatAdapter.checkProtocol(data));
714 .setCurrentTree(af.showNewickTree(nf, data).getTree());
715 } catch (IOException ex)
717 System.err.println("Couldn't add tree " + data);
718 ex.printStackTrace(System.err);
721 // TODO - load PDB structure(s) to alignment JAL-629
722 // (associate with identical sequence in alignment, or a specified
725 getFeatures = checkDasArguments(aparser);
726 if (af != null && getFeatures != null)
728 FeatureFetcher ff = startFeatureFetching(getFeatures);
731 while (!ff.allFinished() || af.operationInProgress())
733 // wait around until fetching is finished.
737 } catch (Exception e)
743 getFeatures = null; // have retrieved features - forget them now.
745 if (groovyscript != null)
747 // Execute the groovy script after we've done all the rendering stuff
748 // and before any images or figures are generated.
749 System.out.println("Executing script " + groovyscript);
750 executeGroovyScript(groovyscript, af);
751 System.out.println("CMD groovy[" + groovyscript
752 + "] executed successfully!");
755 String imageName = "unnamed.png";
756 while (aparser.getSize() > 1)
758 String outputFormat = aparser.nextValue();
759 file = aparser.nextValue();
761 if (outputFormat.equalsIgnoreCase("png"))
763 af.createPNG(new File(file));
764 imageName = (new File(file)).getName();
765 System.out.println("Creating PNG image: " + file);
768 else if (outputFormat.equalsIgnoreCase("svg"))
770 File imageFile = new File(file);
771 imageName = imageFile.getName();
772 af.createSVG(imageFile);
773 System.out.println("Creating SVG image: " + file);
776 else if (outputFormat.equalsIgnoreCase("html"))
778 File imageFile = new File(file);
779 imageName = imageFile.getName();
780 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
781 htmlSVG.exportHTML(file);
783 System.out.println("Creating HTML image: " + file);
786 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
790 System.err.println("The output html file must not be null");
795 BioJsHTMLOutput.refreshVersionInfo(
796 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
797 } catch (URISyntaxException e)
801 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
802 bjs.exportHTML(file);
804 .println("Creating BioJS MSA Viwer HTML file: " + file);
807 else if (outputFormat.equalsIgnoreCase("imgMap"))
809 af.createImageMap(new File(file), imageName);
810 System.out.println("Creating image map: " + file);
813 else if (outputFormat.equalsIgnoreCase("eps"))
815 File outputFile = new File(file);
817 "Creating EPS file: " + outputFile.getAbsolutePath());
818 af.createEPS(outputFile);
822 af.saveAlignment(file, format);
823 if (af.isSaveAlignmentSuccessful())
825 System.out.println("Written alignment in " + format
826 + " format to " + file);
830 System.out.println("Error writing file " + file + " in "
831 + format + " format!!");
836 while (aparser.getSize() > 0)
838 System.out.println("Unknown arg: " + aparser.nextValue());
842 AlignFrame startUpAlframe = null;
843 // We'll only open the default file if the desktop is visible.
845 // ////////////////////
847 if (/** @j2sNative false && */ // BH 2018
848 !headless && file == null && vamsasImport == null
849 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
851 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
852 jalview.bin.Cache.getDefault("www.jalview.org",
853 "http://www.jalview.org")
854 + "/examples/exampleFile_2_7.jar");
856 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
858 // hardwire upgrade of the startup file
859 file.replace("_2_3.jar", "_2_7.jar");
860 // and remove the stale setting
861 jalview.bin.Cache.removeProperty("STARTUP_FILE");
864 protocol = DataSourceType.FILE;
866 if (file.indexOf("http:") > -1)
868 protocol = DataSourceType.URL;
871 if (file.endsWith(".jar"))
873 format = FileFormat.Jalview;
879 format = new IdentifyFile().identify(file, protocol);
880 } catch (FileFormatException e)
886 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
888 getFeatures = checkDasArguments(aparser);
889 // extract groovy arguments before anything else.
891 // If the user has specified features to be retrieved,
892 // or a groovy script to be executed, do them if they
893 // haven't been done already
894 // fetch features for the default alignment
895 if (getFeatures != null)
897 if (startUpAlframe != null)
899 startFeatureFetching(getFeatures);
902 // Once all other stuff is done, execute any groovy scripts (in order)
903 if (groovyscript != null)
905 if (Cache.groovyJarsPresent())
907 System.out.println("Executing script " + groovyscript);
908 executeGroovyScript(groovyscript, startUpAlframe);
913 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
917 // and finally, turn off batch mode indicator - if the desktop still exists
922 desktop.setProgressBar(null, progress);
924 desktop.setInBatchMode(false);
928 private static void showUsage()
931 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
932 + "-nodisplay\tRun Jalview without User Interface.\n"
933 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
934 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
935 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
936 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
937 + "-features FILE\tUse the given file to mark features on the alignment.\n"
938 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
939 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
940 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
941 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
942 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
943 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
944 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
945 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
946 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
947 + "-png FILE\tCreate PNG image FILE from alignment.\n"
948 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
949 + "-html FILE\tCreate HTML file from alignment.\n"
950 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
951 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
952 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
953 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
954 + "-noquestionnaire\tTurn off questionnaire check.\n"
955 + "-nonews\tTurn off check for Jalview news.\n"
956 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
957 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
959 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
960 // after all other properties files have been read\n\t
961 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
962 // passed in correctly)"
963 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
964 + "-dasserver nickname=URL\tAdd and enable a das server with given nickname\n\t\t\t(alphanumeric or underscores only) for retrieval of features for all alignments.\n"
965 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
966 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
967 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
969 // "-vdoc vamsas-document\tImport vamsas document into new
970 // session or join existing session with same URN\n"
971 // + "-vses vamsas-session\tJoin session with given URN\n"
972 + "-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"
973 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
976 private static void startUsageStats(final Desktop desktop)
979 * start a User Config prompt asking if we can log usage statistics.
981 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
982 "USAGESTATS", "Jalview Usage Statistics",
983 "Do you want to help make Jalview better by enabling "
984 + "the collection of usage statistics with Google Analytics ?"
985 + "\n\n(you can enable or disable usage tracking in the preferences)",
992 "Initialising googletracker for usage stats.");
993 Cache.initGoogleTracker();
994 Cache.log.debug("Tracking enabled.");
1001 Cache.log.debug("Not enabling Google Tracking.");
1004 desktop.addDialogThread(prompter);
1008 * Locate the given string as a file and pass it to the groovy interpreter.
1010 * @param groovyscript
1011 * the script to execute
1012 * @param jalviewContext
1013 * the Jalview Desktop object passed in to the groovy binding as the
1016 private void executeGroovyScript(String groovyscript, AlignFrame af)
1019 * for scripts contained in files
1026 if (groovyscript.trim().equals("STDIN"))
1028 // read from stdin into a tempfile and execute it
1031 tfile = File.createTempFile("jalview", "groovy");
1032 PrintWriter outfile = new PrintWriter(
1033 new OutputStreamWriter(new FileOutputStream(tfile)));
1034 BufferedReader br = new BufferedReader(
1035 new InputStreamReader(System.in));
1037 while ((line = br.readLine()) != null)
1039 outfile.write(line + "\n");
1045 } catch (Exception ex)
1047 System.err.println("Failed to read from STDIN into tempfile "
1048 + ((tfile == null) ? "(tempfile wasn't created)"
1049 : tfile.toString()));
1050 ex.printStackTrace();
1055 sfile = tfile.toURI().toURL();
1056 } catch (Exception x)
1059 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1061 x.printStackTrace();
1069 sfile = new URI(groovyscript).toURL();
1070 } catch (Exception x)
1072 tfile = new File(groovyscript);
1073 if (!tfile.exists())
1075 System.err.println("File '" + groovyscript + "' does not exist.");
1078 if (!tfile.canRead())
1080 System.err.println("File '" + groovyscript + "' cannot be read.");
1083 if (tfile.length() < 1)
1085 System.err.println("File '" + groovyscript + "' is empty.");
1090 sfile = tfile.getAbsoluteFile().toURI().toURL();
1091 } catch (Exception ex)
1093 System.err.println("Failed to create a file URL for "
1094 + tfile.getAbsoluteFile());
1101 Map<String, Object> vbinding = new HashMap<>();
1102 vbinding.put("Jalview", this);
1105 vbinding.put("currentAlFrame", af);
1107 Binding gbinding = new Binding(vbinding);
1108 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1109 gse.run(sfile.toString(), gbinding);
1110 if ("STDIN".equals(groovyscript))
1112 // delete temp file that we made -
1113 // only if it was successfully executed
1116 } catch (Exception e)
1118 System.err.println("Exception Whilst trying to execute file " + sfile
1119 + " as a groovy script.");
1120 e.printStackTrace(System.err);
1126 * Check commandline for any das server definitions or any fetchfrom switches
1128 * @return vector of DAS source nicknames to retrieve from
1130 private static Vector<String> checkDasArguments(ArgsParser aparser)
1132 Vector<String> source = null;
1134 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
1135 while ((data = aparser.getValue("dasserver", true)) != null)
1137 String nickname = null;
1139 int pos = data.indexOf('=');
1140 // determine capabilities
1143 nickname = data.substring(0, pos);
1145 url = data.substring(pos + 1);
1146 if (url != null && (url.startsWith("http:")
1147 || url.startsWith("sequence:http:")))
1149 if (nickname == null)
1153 if (locsources == null)
1161 locsources = locsources + nickname + "|" + url;
1163 "NOTE! dasserver parameter not yet really supported (got args of "
1164 + nickname + "|" + url);
1167 source = new Vector<>();
1169 source.addElement(nickname);
1172 "CMD [-dasserver " + data + "] executed successfully!");
1173 } // loop until no more server entries are found.
1174 if (locsources != null && locsources.indexOf('|') > -1)
1176 Cache.log.debug("Setting local source list in properties file to:\n"
1178 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
1180 while ((data = aparser.getValue("fetchfrom", true)) != null)
1182 System.out.println("adding source '" + data + "'");
1185 source = new Vector<>();
1187 source.addElement(data);
1193 * start a feature fetcher for every alignment frame
1197 private FeatureFetcher startFeatureFetching(
1198 final Vector<String> dasSources)
1200 FeatureFetcher ff = new FeatureFetcher();
1201 AlignFrame afs[] = Desktop.getAlignFrames();
1202 if (afs == null || afs.length == 0)
1206 for (int i = 0; i < afs.length; i++)
1208 ff.addFetcher(afs[i], dasSources);
1213 public static boolean isHeadlessMode()
1215 String isheadless = System.getProperty("java.awt.headless");
1216 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1223 public AlignFrame[] getAlignFrames()
1225 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1226 : Desktop.getAlignFrames();
1231 * Quit method delegates to Desktop.quit - unless running in headless mode
1232 * when it just ends the JVM
1236 if (desktop != null)
1246 public static AlignFrame getCurrentAlignFrame()
1248 return Jalview.currentAlignFrame;
1251 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1253 Jalview.currentAlignFrame = currentAlignFrame;