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.api.AlignViewportI;
24 import jalview.api.JalviewApp;
25 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
26 import jalview.datamodel.PDBEntry;
27 import jalview.datamodel.SequenceI;
28 import jalview.ext.so.SequenceOntology;
29 import jalview.gui.AlignFrame;
30 import jalview.gui.AlignViewport;
31 import jalview.gui.Desktop;
32 import jalview.gui.Preferences;
33 import jalview.gui.PromptUserConfig;
34 import jalview.gui.StructureViewer;
35 import jalview.io.AppletFormatAdapter;
36 import jalview.io.BioJsHTMLOutput;
37 import jalview.io.DataSourceType;
38 import jalview.io.FileFormat;
39 import jalview.io.FileFormatException;
40 import jalview.io.FileFormatI;
41 import jalview.io.FileFormats;
42 import jalview.io.FileLoader;
43 import jalview.io.HtmlSvgOutput;
44 import jalview.io.IdentifyFile;
45 import jalview.io.NewickFile;
46 import jalview.io.gff.SequenceOntologyFactory;
47 import jalview.schemes.ColourSchemeI;
48 import jalview.schemes.ColourSchemeProperty;
49 import jalview.util.MessageManager;
50 import jalview.util.Platform;
51 import jalview.ws.jws2.Jws2Discoverer;
53 import java.io.BufferedReader;
55 import java.io.FileOutputStream;
56 import java.io.IOException;
57 import java.io.InputStreamReader;
58 import java.io.OutputStreamWriter;
59 import java.io.PrintWriter;
60 import java.net.MalformedURLException;
62 import java.net.URISyntaxException;
64 import java.security.AllPermission;
65 import java.security.CodeSource;
66 import java.security.PermissionCollection;
67 import java.security.Permissions;
68 import java.security.Policy;
69 import java.util.HashMap;
71 import java.util.Vector;
72 import java.util.logging.ConsoleHandler;
73 import java.util.logging.Level;
74 import java.util.logging.Logger;
76 import javax.swing.LookAndFeel;
77 import javax.swing.UIManager;
79 import groovy.lang.Binding;
80 import groovy.util.GroovyScriptEngine;
83 * Main class for Jalview Application <br>
85 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
88 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
89 * jalview.bin.Jalview jalview.bin.Jalview
91 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
92 * embellish '*' to e.g. '*.jar')
97 public class Jalview implements ApplicationSingletonI
100 public static Jalview getInstance()
102 return (Jalview) ApplicationSingletonProvider
103 .getInstance(Jalview.class);
112 Platform.getURLCommandArguments();
115 private boolean headless;
117 public static boolean isHeadlessMode()
119 return getInstance().headless;
122 private Desktop desktop;
124 private AlignFrame currentAlignFrame;
126 public boolean isJavaAppletTag;
128 public String appletResourcePath;
130 public static AlignFrame getCurrentAlignFrame()
132 return getInstance().currentAlignFrame;
135 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
137 getInstance().currentAlignFrame = currentAlignFrame;
142 if (!Platform.isJS())
149 // grab all the rights we can for the JVM
150 Policy.setPolicy(new Policy()
153 public PermissionCollection getPermissions(CodeSource codesource)
155 Permissions perms = new Permissions();
156 perms.add(new AllPermission());
161 public void refresh()
169 * keep track of feature fetching tasks.
177 * TODO: generalise to track all jalview events to orchestrate batch
181 private int queued = 0;
183 private int running = 0;
185 public FeatureFetcher()
190 public void addFetcher(final AlignFrame af,
191 final Vector<String> dasSources)
193 final long id = System.currentTimeMillis();
195 final FeatureFetcher us = this;
196 new Thread(new Runnable()
208 af.setProgressBar(MessageManager
209 .getString("status.das_features_being_retrived"), id);
210 af.featureSettings_actionPerformed(null);
211 af.setProgressBar(null, id);
220 public synchronized boolean allFinished()
222 return queued == 0 && running == 0;
228 * main class for Jalview application
231 * open <em>filename</em>
233 public static void main(String[] args)
235 // setLogging(); // BH - for event debugging in JavaScript
236 getInstance().doMain(args);
239 private static void logClass(String name)
241 // BH - for event debugging in JavaScript
242 ConsoleHandler consoleHandler = new ConsoleHandler();
243 consoleHandler.setLevel(Level.ALL);
244 Logger logger = Logger.getLogger(name);
245 logger.setLevel(Level.ALL);
246 logger.addHandler(consoleHandler);
249 @SuppressWarnings("unused")
250 private static void setLogging()
258 System.out.println("not in js");
261 // BH - for event debugging in JavaScript (Java mode only)
262 if (!Platform.isJS())
269 Logger.getLogger("").setLevel(Level.ALL);
270 logClass("java.awt.EventDispatchThread");
271 logClass("java.awt.EventQueue");
272 logClass("java.awt.Component");
273 logClass("java.awt.focus.Component");
274 logClass("java.awt.focus.DefaultKeyboardFocusManager");
282 void doMain(String[] args)
285 boolean isJS = Platform.isJS();
288 System.setSecurityManager(null);
292 .println("Java version: " + System.getProperty("java.version"));
293 System.out.println(System.getProperty("os.arch") + " "
294 + System.getProperty("os.name") + " "
295 + System.getProperty("os.version"));
297 ArgsParser aparser = new ArgsParser(args);
299 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
300 Cache.loadProperties(usrPropsFile);
303 isJavaAppletTag = aparser.isApplet();
306 Preferences.setAppletDefaults();
307 Cache.loadProperties(usrPropsFile); // again, because we
308 // might be changing defaults here?
311 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
312 appletResourcePath = aparser.getValue("Info.resourcePath");
321 if (usrPropsFile != null)
324 "CMD [-props " + usrPropsFile + "] executed successfully!");
327 if (aparser.contains("help") || aparser.contains("h"))
332 if (aparser.contains(ArgsParser.NODISPLAY)
333 || aparser.contains(ArgsParser.NOGUI)
334 || aparser.contains(ArgsParser.HEADLESS)
335 || "true".equals(System.getProperty("java.awt.headless")))
342 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
343 if (jabawsUrl != null)
347 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
349 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
350 } catch (MalformedURLException e)
353 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
358 // check for property setting
359 String defs = aparser.getValue(ArgsParser.SETPROP);
362 int p = defs.indexOf('=');
365 System.err.println("Ignoring invalid setprop argument : " + defs);
369 System.out.println("Executing setprop argument: " + defs);
372 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
375 defs = aparser.getValue(ArgsParser.SETPROP);
377 System.setProperty("http.agent",
378 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
382 } catch (NoClassDefFoundError error)
384 error.printStackTrace();
385 System.out.println("\nEssential logging libraries not found."
386 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
394 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
395 } catch (Exception ex)
397 System.err.println("Unexpected Look and Feel Exception");
398 ex.printStackTrace();
400 if (Platform.isAMacAndNotJS())
403 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
405 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
407 System.setProperty("apple.laf.useScreenMenuBar", "true");
408 if (lookAndFeel != null)
412 UIManager.setLookAndFeel(lookAndFeel);
413 } catch (Throwable e)
416 "Failed to set QuaQua look and feel: " + e.toString());
419 if (lookAndFeel == null
420 || !(lookAndFeel.getClass().isAssignableFrom(
421 UIManager.getLookAndFeel().getClass()))
422 || !UIManager.getLookAndFeel().getClass().toString()
423 .toLowerCase().contains("quaqua"))
428 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
429 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
430 } catch (Throwable e)
433 "Failed to reset look and feel: " + e.toString());
439 * configure 'full' SO model if preferences say to,
440 * else use the default (SO Lite)
442 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
444 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
449 desktop = Desktop.getInstance();
450 desktop.setInBatchMode(true); // indicate we are starting up
451 desktop.setVisible(true);
460 desktop.startServiceDiscovery();
461 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
463 startUsageStats(desktop);
467 System.err.println("CMD [-nousagestats] executed successfully!");
470 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
472 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
475 // Start the desktop questionnaire prompter with the specified
477 Cache.log.debug("Starting questionnaire url at " + url);
478 desktop.checkForQuestionnaire(url);
479 System.out.println("CMD questionnaire[-" + url
480 + "] executed successfully!");
484 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
486 // Start the desktop questionnaire prompter with the specified
489 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
491 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
493 "Starting questionnaire with default url: " + defurl);
494 desktop.checkForQuestionnaire(defurl);
501 .println("CMD [-noquestionnaire] executed successfully!");
504 if (!aparser.contains(ArgsParser.NONEWS))
506 desktop.checkForNews();
509 BioJsHTMLOutput.updateBioJS();
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 = (isJS ? null
517 : aparser.getValue(ArgsParser.GROOVY, true));
518 String file = aparser.getValue(ArgsParser.OPEN, true);
519 // BH this here to allow split frame; not working as of 5/17/2019
520 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
521 String fileFormat = (isJavaAppletTag
522 ? aparser.getAppletValue("format", null)
525 FileFormatI format = null;
526 DataSourceType protocol = null;
528 if (file == null && desktop == null)
530 System.out.println("No files to open!");
533 boolean haveImport = checkStartVamas(aparser);
534 // Finally, deal with the remaining input data.
536 if (file == null && isJavaAppletTag)
538 // Maybe the sequences are added as parameters
539 StringBuffer data = new StringBuffer("PASTE");
541 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
543 data.append(file.toString() + "\n");
546 if (data.length() > 5)
548 file = data.toString();
556 desktop.setProgressBar(
558 .getString("status.processing_commandline_args"),
559 progress = System.currentTimeMillis());
564 * ignore in JavaScript -- can't just check file existence - could load
570 if (!file.startsWith("http://") && !file.startsWith("https://"))
571 // BH 2019 added https check for Java
573 if (!(new File(file)).exists())
575 System.out.println("Can't find " + file);
584 protocol = AppletFormatAdapter.checkProtocol(file);
588 format = (isJavaAppletTag && fileFormat != null
589 ? FileFormats.getInstance().forName(fileFormat)
593 format = new IdentifyFile().identify(file, protocol);
595 } catch (FileFormatException e1)
600 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
604 System.out.println("error");
609 .println("CMD [-open " + file + "] executed successfully!");
612 protocol = AppletFormatAdapter.checkProtocol(file2);
615 format = new IdentifyFile().identify(file2, protocol);
616 } catch (FileFormatException e1)
620 AlignFrame af2 = new FileLoader(!headless)
621 .loadFileWaitTillLoaded(file2, protocol, format);
624 System.out.println("error");
628 AlignViewport.openLinkedAlignmentAs(af,
629 af.getViewport().getAlignment(),
630 af2.getViewport().getAlignment(), "",
631 AlignViewport.SPLIT_FRAME);
633 "CMD [-open2 " + file2 + "] executed successfully!");
637 setCurrentAlignFrame(af);
639 // TODO: file2 How to implement file2 for the applet spit screen?
641 String data = aparser.getValue(ArgsParser.COLOUR, true);
644 data.replaceAll("%20", " ");
646 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
647 af.getViewport(), af.getViewport().getAlignment(), data);
652 "CMD [-color " + data + "] executed successfully!");
657 // Must maintain ability to use the groups flag
658 data = aparser.getValue(ArgsParser.GROUPS, true);
661 af.parseFeaturesFile(data,
662 AppletFormatAdapter.checkProtocol(data));
663 // System.out.println("Added " + data);
665 "CMD groups[-" + data + "] executed successfully!");
667 data = aparser.getValue(ArgsParser.FEATURES, true);
670 af.parseFeaturesFile(data,
671 AppletFormatAdapter.checkProtocol(data));
672 // System.out.println("Added " + data);
674 "CMD [-features " + data + "] executed successfully!");
677 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
680 af.loadJalviewDataFile(data, null, null, null);
681 // System.out.println("Added " + data);
683 "CMD [-annotations " + data + "] executed successfully!");
685 // set or clear the sortbytree flag.
686 if (aparser.contains(ArgsParser.SORTBYTREE))
688 af.getViewport().setSortByTree(true);
689 if (af.getViewport().getSortByTree())
691 System.out.println("CMD [-sortbytree] executed successfully!");
694 if (aparser.contains(ArgsParser.NOANNOTATION)
695 || aparser.contains(ArgsParser.NOANNOTATION2))
697 af.getViewport().setShowAnnotation(false);
698 if (!af.getViewport().isShowAnnotation())
700 System.out.println("CMD no-annotation executed successfully!");
703 if (aparser.contains(ArgsParser.NOSORTBYTREE))
705 af.getViewport().setSortByTree(false);
706 if (!af.getViewport().getSortByTree())
709 .println("CMD [-nosortbytree] executed successfully!");
712 data = aparser.getValue(ArgsParser.TREE, true);
718 "CMD [-tree " + data + "] executed successfully!");
719 NewickFile nf = new NewickFile(data,
720 AppletFormatAdapter.checkProtocol(data));
722 .setCurrentTree(af.showNewickTree(nf, data).getTree());
723 } catch (IOException ex)
725 System.err.println("Couldn't add tree " + data);
726 ex.printStackTrace(System.err);
729 // TODO - load PDB structure(s) to alignment JAL-629
730 // (associate with identical sequence in alignment, or a specified
734 loadAppletParams(aparser, af);
743 if (groovyscript != null)
745 // Execute the groovy script after we've done all the rendering
747 // and before any images or figures are generated.
748 System.out.println("Executing script " + groovyscript);
749 executeGroovyScript(groovyscript, af);
750 System.out.println("CMD groovy[" + groovyscript
751 + "] executed successfully!");
754 checkOutputFile(aparser, af, format);
755 while (aparser.getSize() > 0)
757 System.out.println("Unknown arg: " + aparser.nextValue());
762 AlignFrame startUpAlframe = null;
763 // We'll only open the default file if the desktop is visible.
765 // ////////////////////
767 if (!isJS && !headless && file == null && !haveImport
768 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
775 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
776 jalview.bin.Cache.getDefault("www.jalview.org",
777 "http://www.jalview.org")
778 + "/examples/exampleFile_2_7.jar");
780 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
782 // hardwire upgrade of the startup file
783 file.replace("_2_3.jar", "_2_7.jar");
784 // and remove the stale setting
785 jalview.bin.Cache.removeProperty("STARTUP_FILE");
788 protocol = DataSourceType.FILE;
790 if (file.indexOf("http:") > -1)
792 protocol = DataSourceType.URL;
795 if (file.endsWith(".jar"))
797 format = FileFormat.Jalview;
803 format = new IdentifyFile().identify(file, protocol);
804 } catch (FileFormatException e)
810 startUpAlframe = new FileLoader(!headless)
811 .loadFileWaitTillLoaded(file, protocol, format);
812 // extract groovy arguments before anything else.
815 // Once all other stuff is done, execute any groovy scripts (in order)
816 if (groovyscript != null)
818 if (Cache.groovyJarsPresent())
820 System.out.println("Executing script " + groovyscript);
821 executeGroovyScript(groovyscript, startUpAlframe);
826 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
830 // and finally, turn off batch mode indicator - if the desktop still exists
835 desktop.setProgressBar(null, progress);
837 desktop.setInBatchMode(false);
841 private boolean checkStartVamas(ArgsParser aparser)
843 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
844 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
845 if (vamsasImport == null && vamsasSession == null)
849 if (desktop == null || headless)
852 "Headless vamsas sessions not yet supported. Sorry.");
855 boolean haveImport = (vamsasImport != null);
858 // if we have a file, start a new session and import it.
859 boolean inSession = false;
862 DataSourceType viprotocol = AppletFormatAdapter
863 .checkProtocol(vamsasImport);
864 if (viprotocol == DataSourceType.FILE)
866 inSession = desktop.vamsasImport(new File(vamsasImport));
868 else if (viprotocol == DataSourceType.URL)
870 inSession = desktop.vamsasImport(new URL(vamsasImport));
873 } catch (Exception e)
875 System.err.println("Exeption when importing " + vamsasImport
876 + " as a vamsas document.");
881 System.err.println("Failed to import " + vamsasImport
882 + " as a vamsas document.");
886 System.out.println("Imported Successfully into new session "
887 + desktop.getVamsasApplication().getCurrentSession());
890 if (vamsasSession != null)
892 if (vamsasImport != null)
894 // close the newly imported session and import the Jalview specific
895 // remnants into the new session later on.
896 desktop.vamsasStop_actionPerformed(null);
898 // now join the new session
901 if (desktop.joinVamsasSession(vamsasSession))
904 "Successfully joined vamsas session " + vamsasSession);
908 System.err.println("WARNING: Failed to join vamsas session "
911 } catch (Exception e)
914 "ERROR: Failed to join vamsas session " + vamsasSession);
917 if (vamsasImport != null)
919 // the Jalview specific remnants can now be imported into the new
920 // session at the user's leisure.
922 "Skipping Push for import of data into existing vamsas session."); // TODO:
927 // desktop.getVamsasApplication().push_update();
933 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
936 String imageName = "unnamed.png";
937 while (aparser.getSize() > 1)
943 String outputFormat = aparser.nextValue();
944 String file = aparser.nextValue();
945 if (outputFormat.equalsIgnoreCase("png"))
947 af.createPNG(new File(file));
948 imageName = (new File(file)).getName();
949 System.out.println("Creating PNG image: " + file);
952 else if (outputFormat.equalsIgnoreCase("svg"))
954 File imageFile = new File(file);
955 imageName = imageFile.getName();
956 af.createSVG(imageFile);
957 System.out.println("Creating SVG image: " + file);
960 else if (outputFormat.equalsIgnoreCase("html"))
962 File imageFile = new File(file);
963 imageName = imageFile.getName();
964 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
965 htmlSVG.exportHTML(file);
967 System.out.println("Creating HTML image: " + file);
970 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
974 System.err.println("The output html file must not be null");
979 BioJsHTMLOutput.refreshVersionInfo(
980 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
981 } catch (URISyntaxException e)
985 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
986 bjs.exportHTML(file);
987 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
990 else if (outputFormat.equalsIgnoreCase("imgMap"))
992 af.createImageMap(new File(file), imageName);
993 System.out.println("Creating image map: " + file);
996 else if (outputFormat.equalsIgnoreCase("eps"))
998 File outputFile = new File(file);
1000 "Creating EPS file: " + outputFile.getAbsolutePath());
1001 af.createEPS(outputFile);
1005 af.saveAlignment(file, format);
1006 if (af.isSaveAlignmentSuccessful())
1009 "Written alignment in " + format + " format to " + file);
1013 System.out.println("Error writing file " + file + " in " + format
1020 private static void showUsage()
1023 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1024 + "-nodisplay\tRun Jalview without User Interface.\n"
1025 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1026 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1027 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1028 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1029 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1030 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1031 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1032 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1033 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1034 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1035 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1036 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1037 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1038 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1039 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1040 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1041 + "-html FILE\tCreate HTML file from alignment.\n"
1042 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1043 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1044 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1045 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1046 + "-noquestionnaire\tTurn off questionnaire check.\n"
1047 + "-nonews\tTurn off check for Jalview news.\n"
1048 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1049 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1051 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1052 // after all other properties files have been read\n\t
1053 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1054 // passed in correctly)"
1055 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1056 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1058 // "-vdoc vamsas-document\tImport vamsas document into new
1059 // session or join existing session with same URN\n"
1060 // + "-vses vamsas-session\tJoin session with given URN\n"
1061 + "-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"
1062 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1065 private static void startUsageStats(final Desktop desktop)
1068 * start a User Config prompt asking if we can log usage statistics.
1070 PromptUserConfig prompter = new PromptUserConfig(
1071 Desktop.getDesktopPane(), "USAGESTATS",
1072 "Jalview Usage Statistics",
1073 "Do you want to help make Jalview better by enabling "
1074 + "the collection of usage statistics with Google Analytics ?"
1075 + "\n\n(you can enable or disable usage tracking in the preferences)",
1082 "Initialising googletracker for usage stats.");
1083 Cache.initGoogleTracker();
1084 Cache.log.debug("Tracking enabled.");
1091 Cache.log.debug("Not enabling Google Tracking.");
1094 desktop.addDialogThread(prompter);
1098 * Locate the given string as a file and pass it to the groovy interpreter.
1100 * @param groovyscript
1101 * the script to execute
1102 * @param jalviewContext
1103 * the Jalview Desktop object passed in to the groovy binding as the
1106 private void executeGroovyScript(String groovyscript, AlignFrame af)
1109 * for scripts contained in files
1116 if (groovyscript.trim().equals("STDIN"))
1118 // read from stdin into a tempfile and execute it
1121 tfile = File.createTempFile("jalview", "groovy");
1122 PrintWriter outfile = new PrintWriter(
1123 new OutputStreamWriter(new FileOutputStream(tfile)));
1124 BufferedReader br = new BufferedReader(
1125 new InputStreamReader(System.in));
1127 while ((line = br.readLine()) != null)
1129 outfile.write(line + "\n");
1135 } catch (Exception ex)
1137 System.err.println("Failed to read from STDIN into tempfile "
1138 + ((tfile == null) ? "(tempfile wasn't created)"
1139 : tfile.toString()));
1140 ex.printStackTrace();
1145 sfile = tfile.toURI().toURL();
1146 } catch (Exception x)
1149 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1151 x.printStackTrace();
1159 sfile = new URI(groovyscript).toURL();
1160 } catch (Exception x)
1162 tfile = new File(groovyscript);
1163 if (!tfile.exists())
1165 System.err.println("File '" + groovyscript + "' does not exist.");
1168 if (!tfile.canRead())
1170 System.err.println("File '" + groovyscript + "' cannot be read.");
1173 if (tfile.length() < 1)
1175 System.err.println("File '" + groovyscript + "' is empty.");
1180 sfile = tfile.getAbsoluteFile().toURI().toURL();
1181 } catch (Exception ex)
1183 System.err.println("Failed to create a file URL for "
1184 + tfile.getAbsoluteFile());
1191 Map<String, Object> vbinding = new HashMap<>();
1192 vbinding.put("Jalview", this);
1195 vbinding.put("currentAlFrame", af);
1197 Binding gbinding = new Binding(vbinding);
1198 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1199 gse.run(sfile.toString(), gbinding);
1200 if ("STDIN".equals(groovyscript))
1202 // delete temp file that we made -
1203 // only if it was successfully executed
1206 } catch (Exception e)
1208 System.err.println("Exception Whilst trying to execute file " + sfile
1209 + " as a groovy script.");
1210 e.printStackTrace(System.err);
1215 public AlignFrame[] getAlignFrames()
1217 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1218 : Desktop.getAlignFrames();
1223 * Quit method delegates to Desktop.quit - unless running in headless mode
1224 * when it just ends the JVM
1228 if (desktop != null)
1239 * Get the SwingJS applet ID and combine that with the frameType
1242 * "alignment", "desktop", etc., or null
1245 public static String getAppID(String frameType)
1247 String id = Cache.getProperty("Info.j2sAppletID");
1252 return id + (frameType == null ? "" : "-" + frameType);
1256 * Handle all JalviewLite applet parameters
1261 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1263 JalviewApp app = new JalviewApp()
1266 private boolean alignPDBStructures; // From JalviewLite; not implemented
1269 public String getParameter(String name)
1271 return aparser.getAppletValue(name, null);
1275 public boolean getDefaultParameter(String name, boolean def)
1278 return ((stn = getParameter(name)) == null ? def
1279 : "true".equalsIgnoreCase(stn));
1283 * Get the applet-like document base even though this is an application.
1286 public URL getDocumentBase()
1288 return Platform.getDocumentBase();
1292 * Get the applet-like code base even though this is an application.
1295 public URL getCodeBase()
1297 return Platform.getCodeBase();
1301 public AlignViewportI getViewport()
1303 return af.getViewport();
1311 public boolean parseFeaturesFile(String filename,
1312 DataSourceType protocol)
1314 return af.parseFeaturesFile(filename, protocol);
1322 public boolean loadScoreFile(String sScoreFile) throws IOException
1324 af.loadJalviewDataFile(sScoreFile, null, null, null);
1329 * annotations, jpredfile, jnetfile
1333 public void updateForAnnotations()
1335 af.updateForAnnotations();
1339 public void loadTree(NewickFile fin, String treeFile)
1342 // n/a -- already done by standard Jalview command line processing
1346 public void setAlignPdbStructures(boolean defaultParameter)
1348 alignPDBStructures = true;
1352 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1353 String[] chains, DataSourceType protocol)
1355 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1359 public void setFeatureGroupState(String[] groups, boolean state)
1361 af.setFeatureGroupState(groups, state);
1365 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1366 String[][] chains, String[] protocols)
1369 "Jalview applet interface alignedStructureView not implemented");
1373 public void newFeatureSettings()
1376 "Jalview applet interface newFeatureSettings not implemented");
1381 new JalviewAppLoader(true).load(app);