2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.io.BufferedReader;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28 import java.io.OutputStreamWriter;
29 import java.io.PrintWriter;
30 import java.net.MalformedURLException;
32 import java.net.URISyntaxException;
34 import java.security.AllPermission;
35 import java.security.CodeSource;
36 import java.security.PermissionCollection;
37 import java.security.Permissions;
38 import java.security.Policy;
39 import java.util.HashMap;
40 import java.util.Hashtable;
42 import java.util.Vector;
44 import javax.swing.LookAndFeel;
45 import javax.swing.UIManager;
47 import com.threerings.getdown.util.LaunchUtil;
49 import groovy.lang.Binding;
50 import groovy.util.GroovyScriptEngine;
51 import jalview.api.AlignCalcWorkerI;
52 import jalview.api.AlignViewportI;
53 import jalview.api.JalviewApp;
54 import jalview.api.StructureSelectionManagerProvider;
55 import jalview.datamodel.ColumnSelection;
56 import jalview.datamodel.HiddenColumns;
57 import jalview.datamodel.PDBEntry;
58 import jalview.datamodel.SequenceGroup;
59 import jalview.datamodel.SequenceI;
60 import jalview.ext.so.SequenceOntology;
61 import jalview.gui.AlignFrame;
62 import jalview.gui.AlignViewport;
63 import jalview.gui.AlignmentPanel;
64 import jalview.gui.CalculationChooser;
65 import jalview.gui.Desktop;
66 import jalview.gui.Preferences;
67 import jalview.gui.PromptUserConfig;
68 import jalview.gui.StructureViewer;
69 import jalview.io.AppletFormatAdapter;
70 import jalview.io.BioJsHTMLOutput;
71 import jalview.io.DataSourceType;
72 import jalview.io.FileFormat;
73 import jalview.io.FileFormatException;
74 import jalview.io.FileFormatI;
75 import jalview.io.FileFormats;
76 import jalview.io.FileLoader;
77 import jalview.io.HtmlSvgOutput;
78 import jalview.io.IdentifyFile;
79 import jalview.io.NewickFile;
80 import jalview.io.gff.SequenceOntologyFactory;
81 import jalview.javascript.JSFunctionExec;
82 import jalview.javascript.MouseOverStructureListener;
83 import jalview.renderer.seqfeatures.FeatureRenderer;
84 import jalview.schemes.ColourSchemeI;
85 import jalview.schemes.ColourSchemeProperty;
86 import jalview.structure.SelectionSource;
87 import jalview.structure.VamsasSource;
88 import jalview.util.MessageManager;
89 import jalview.util.Platform;
90 import jalview.ws.jws2.Jws2Discoverer;
91 import netscape.javascript.JSObject;
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$
108 public class Jalview implements JalviewJSApi
112 Platform.getURLCommandArguments();
115 private boolean headless;
117 // singleton instance of this class
119 private static Jalview instance;
121 private Desktop desktop;
123 public static AlignFrame currentAlignFrame;
125 public boolean isJavaAppletTag;
127 public String appletResourcePath;
129 JalviewAppLoader appLoader;
131 protected JSFunctionExec jsFunctionExec;
133 private boolean noCalculation, noMenuBar, noStatus;
135 private boolean noAnnotation;
137 public boolean getStartCalculations()
139 return !noCalculation;
142 public boolean getAllowMenuBar()
147 public boolean getShowStatus()
152 public boolean getShowAnnotation()
154 return !noAnnotation;
159 if (!Platform.isJS())
166 // grab all the rights we can for the JVM
167 Policy.setPolicy(new Policy()
170 public PermissionCollection getPermissions(CodeSource codesource)
172 Permissions perms = new Permissions();
173 perms.add(new AllPermission());
178 public void refresh()
186 * keep track of feature fetching tasks.
194 * TODO: generalise to track all jalview events to orchestrate batch processing
198 private int queued = 0;
200 private int running = 0;
202 public FeatureFetcher()
207 public void addFetcher(final AlignFrame af,
208 final Vector<String> dasSources)
210 final long id = System.currentTimeMillis();
212 final FeatureFetcher us = this;
213 new Thread(new Runnable()
225 af.setProgressBar(MessageManager
226 .getString("status.das_features_being_retrived"), id);
227 af.featureSettings_actionPerformed(null);
228 af.setProgressBar(null, id);
237 public synchronized boolean allFinished()
239 return queued == 0 && running == 0;
244 public static Jalview getInstance()
250 private final static boolean doPlatformLogging = false;
253 * main class for Jalview application
256 * open <em>filename</em>
258 public static void main(String[] args)
260 if (doPlatformLogging)
262 Platform.startJavaLogging();
265 instance = new Jalview();
266 instance.doMain(args);
272 void doMain(String[] args)
275 boolean isJS = Platform.isJS();
278 Platform.setAppClass(this);
282 System.setSecurityManager(null);
286 .println("Java version: " + System.getProperty("java.version"));
287 System.out.println("Java Home: " + System.getProperty("java.home"));
288 System.out.println(System.getProperty("os.arch") + " "
289 + System.getProperty("os.name") + " "
290 + System.getProperty("os.version"));
291 String val = System.getProperty("sys.install4jVersion");
294 System.out.println("Install4j version: " + val);
296 val = System.getProperty("installer_template_version");
299 System.out.println("Install4j template version: " + val);
301 val = System.getProperty("launcher_version");
304 System.out.println("Launcher version: " + val);
307 // report Jalview version
308 Cache.loadBuildProperties(true);
310 ArgsParser aparser = new ArgsParser(args);
313 String usrPropsFile = aparser.getValue("props");
315 Cache.loadProperties(usrPropsFile); // must do this before
319 isJavaAppletTag = aparser.isApplet();
322 Preferences.setAppletDefaults();
323 Cache.loadProperties(usrPropsFile); // again, because we
324 // might be changing defaults here?
327 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
328 appletResourcePath = aparser.getValue("Info.resourcePath");
338 if (usrPropsFile != null)
341 "CMD [-props " + usrPropsFile + "] executed successfully!");
343 if (aparser.contains("help") || aparser.contains("h"))
349 if (aparser.contains("nodisplay") || aparser.contains("nogui")
350 || aparser.contains("headless"))
352 System.setProperty("java.awt.headless", "true");
359 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
360 if (jabawsUrl != null)
364 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
366 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
367 } catch (MalformedURLException e)
370 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
375 String defs = aparser.getValue(ArgsParser.SETPROP);
378 int p = defs.indexOf('=');
381 System.err.println("Ignoring invalid setprop argument : " + defs);
385 System.out.println("Executing setprop argument: " + defs);
388 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
391 defs = aparser.getValue("setprop");
393 if (System.getProperty("java.awt.headless") != null
394 && System.getProperty("java.awt.headless").equals("true"))
398 System.setProperty("http.agent",
399 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
403 } catch (NoClassDefFoundError error)
405 error.printStackTrace();
406 System.out.println("\nEssential logging libraries not found."
407 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
418 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
419 } catch (Exception ex)
421 System.err.println("Unexpected Look and Feel Exception");
422 ex.printStackTrace();
424 if (Platform.isMac())
427 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
430 "com.apple.mrj.application.apple.menu.about.name",
432 System.setProperty("apple.laf.useScreenMenuBar", "true");
433 if (lookAndFeel != null)
437 UIManager.setLookAndFeel(lookAndFeel);
438 } catch (Throwable e)
441 "Failed to set QuaQua look and feel: " + e.toString());
444 if (lookAndFeel == null
445 || !(lookAndFeel.getClass().isAssignableFrom(
446 UIManager.getLookAndFeel().getClass()))
447 || !UIManager.getLookAndFeel().getClass().toString()
448 .toLowerCase().contains("quaqua"))
453 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
454 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
455 } catch (Throwable e)
458 "Failed to reset look and feel: " + e.toString());
464 * configure 'full' SO model if preferences say to, else use the default (full SO)
465 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
467 boolean soDefault = !Platform.isJS();
468 if (Cache.getDefault("USE_FULL_SO", soDefault))
470 SequenceOntologyFactory.setInstance(new SequenceOntology());
475 desktop = new Desktop();
476 desktop.setInBatchMode(true); // indicate we are starting up
480 JalviewTaskbar.setTaskbar(this);
481 } catch (Throwable t)
483 System.out.println("Error setting Taskbar: " + t.getMessage());
486 desktop.setVisible(true);
488 if (!Platform.isJS())
495 desktop.startServiceDiscovery();
496 if (!aparser.contains("nousagestats"))
498 startUsageStats(desktop);
502 System.err.println("CMD [-nousagestats] executed successfully!");
505 if (!aparser.contains("noquestionnaire"))
507 String url = aparser.getValue("questionnaire");
510 // Start the desktop questionnaire prompter with the specified
512 Cache.log.debug("Starting questionnaire url at " + url);
513 desktop.checkForQuestionnaire(url);
514 System.out.println("CMD questionnaire[-" + url
515 + "] executed successfully!");
519 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
521 // Start the desktop questionnaire prompter with the specified
524 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
526 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
528 "Starting questionnaire with default url: " + defurl);
529 desktop.checkForQuestionnaire(defurl);
536 .println("CMD [-noquestionnaire] executed successfully!");
539 if (!aparser.contains("nonews"))
541 desktop.checkForNews();
544 BioJsHTMLOutput.updateBioJS();
548 parseArguments(aparser, true);
552 * Allow an outside entity to initiate the second half of argument parsing
556 * @return null is good
559 public Object parseArguments(String[] args)
564 parseArguments(new ArgsParser(args), false);
566 } catch (Throwable t)
577 private void parseArguments(ArgsParser aparser, boolean isStartup)
580 String groovyscript = null; // script to execute after all loading is
581 boolean isJS = Platform.isJS();
585 // Move any new getdown-launcher-new.jar into place over old
586 // getdown-launcher.jar
587 String appdirString = System.getProperty("getdownappdir");
588 if (appdirString != null && appdirString.length() > 0)
590 final File appdir = new File(appdirString);
596 LaunchUtil.upgradeGetdown(
597 new File(appdir, "getdown-launcher-old.jar"),
598 new File(appdir, "getdown-launcher.jar"),
599 new File(appdir, "getdown-launcher-new.jar"));
604 // completed one way or another
605 // extract groovy argument and execute if necessary
606 groovyscript = aparser.getValue("groovy", true);
610 String file = aparser.getValue("open", true);
612 if (file == null && desktop == null)
614 System.out.println("No files to open!");
619 DataSourceType protocol = null;
620 FileLoader fileLoader = new FileLoader(!headless);
621 FileFormatI format = null;
622 // Finally, deal with the remaining input data.
627 desktop.setProgressBar(
629 .getString("status.processing_commandline_args"),
630 progress = System.currentTimeMillis());
632 System.out.println("CMD [-open " + file + "] executed successfully!");
634 if (!Platform.isJS())
636 * ignore in JavaScript -- can't just file existence - could load it?
641 if (!file.startsWith("http://") && !file.startsWith("https://"))
642 // BH 2019 added https check for Java
644 if (!(new File(file)).exists())
646 System.out.println("Can't find " + file);
654 String fileFormat = (isJavaAppletTag
655 ? aparser.getAppletValue("format", null)
657 protocol = AppletFormatAdapter.checkProtocol(file);
660 format = (isJavaAppletTag && fileFormat != null
661 ? FileFormats.getInstance().forName(fileFormat)
665 format = new IdentifyFile().identify(file, protocol);
667 format = new IdentifyFile().identify(file, protocol);
668 } catch (FileFormatException e1)
673 if (aparser.contains(ArgsParser.NOMENUBAR))
676 System.out.println("CMD [nomenu] executed successfully!");
679 if (aparser.contains(ArgsParser.NOSTATUS))
682 System.out.println("CMD [nostatus] executed successfully!");
685 if (aparser.contains(ArgsParser.NOANNOTATION)
686 || aparser.contains(ArgsParser.NOANNOTATION2))
689 System.out.println("CMD no-annotation executed successfully!");
691 if (aparser.contains(ArgsParser.NOCALCULATION))
693 noCalculation = true;
694 System.out.println("CMD [nocalculation] executed successfully!");
697 AlignFrame af = new FileLoader(!headless).LoadFileWaitTillLoaded(file,
701 System.out.println("error");
706 // JalviewLite interface for JavaScript allows second file open
707 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
710 protocol = AppletFormatAdapter.checkProtocol(file2);
713 format = new IdentifyFile().identify(file2, protocol);
714 } catch (FileFormatException e1)
718 AlignFrame af2 = new FileLoader(!headless)
719 .LoadFileWaitTillLoaded(file2, protocol, format);
722 System.out.println("error");
726 AlignViewport.openLinkedAlignmentAs(af,
727 af.getViewport().getAlignment(),
728 af2.getViewport().getAlignment(), "",
729 AlignViewport.SPLIT_FRAME);
731 "CMD [-open2 " + file2 + "] executed successfully!");
734 setCurrentAlignFrame(af);
736 String data = aparser.getValue(ArgsParser.COLOUR, true);
739 data.replaceAll("%20", " ");
741 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
742 af.getViewport(), af.getViewport().getAlignment(), data);
747 "CMD [-color " + data + "] executed successfully!");
752 // Must maintain ability to use the groups flag
753 data = aparser.getValue(ArgsParser.GROUPS, true);
756 af.parseFeaturesFile(data,
757 AppletFormatAdapter.checkProtocol(data));
758 // System.out.println("Added " + data);
760 "CMD groups[-" + data + "] executed successfully!");
762 data = aparser.getValue(ArgsParser.FEATURES, true);
765 af.parseFeaturesFile(data,
766 AppletFormatAdapter.checkProtocol(data));
767 // System.out.println("Added " + data);
769 "CMD [-features " + data + "] executed successfully!");
771 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
774 af.loadJalviewDataFile(data, null, null, null);
775 // System.out.println("Added " + data);
777 "CMD [-annotations " + data + "] executed successfully!");
780 // JavaScript feature
782 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
784 af.overviewMenuItem_actionPerformed(null);
785 System.out.println("CMD [showoverview] executed successfully!");
788 // set or clear the sortbytree flag.
789 if (aparser.contains(ArgsParser.SORTBYTREE))
791 af.getViewport().setSortByTree(true);
792 if (af.getViewport().getSortByTree())
794 System.out.println("CMD [-sortbytree] executed successfully!");
798 boolean doUpdateAnnotation = false;
800 * we do this earlier in JalviewJS because of a complication with
803 * For now, just fixing this in JalviewJS.
810 if (aparser.contains(ArgsParser.NOANNOTATION)
811 || aparser.contains(ArgsParser.NOANNOTATION2))
813 af.getViewport().setShowAnnotation(false);
814 if (!af.getViewport().isShowAnnotation())
816 doUpdateAnnotation = true;
818 .println("CMD no-annotation executed successfully!");
824 if (aparser.contains(ArgsParser.NOSORTBYTREE))
826 af.getViewport().setSortByTree(false);
827 if (!af.getViewport().getSortByTree())
829 doUpdateAnnotation = true;
831 .println("CMD [-nosortbytree] executed successfully!");
834 if (doUpdateAnnotation)
836 af.setMenusForViewport();
837 af.alignPanel.updateLayout();
840 data = aparser.getValue(ArgsParser.TREE, true);
846 "CMD [-tree " + data + "] executed successfully!");
847 NewickFile nf = new NewickFile(data,
848 AppletFormatAdapter.checkProtocol(data));
850 .setCurrentTree(af.showNewickTree(nf, data).getTree());
851 } catch (IOException ex)
853 System.err.println("Couldn't add tree " + data);
854 ex.printStackTrace(System.err);
857 // TODO - load PDB structure(s) to alignment JAL-629
858 // (associate with identical sequence in alignment, or a specified
862 loadAppletParams(aparser, af);
871 if (groovyscript != null)
873 // Execute the groovy script after we've done all the rendering
875 // and before any images or figures are generated.
876 System.out.println("Executing script " + groovyscript);
877 executeGroovyScript(groovyscript, af);
878 System.out.println("CMD groovy[" + groovyscript
879 + "] executed successfully!");
883 createOutputFiles(aparser, af, format);
884 while (aparser.getSize() > 0)
886 System.out.println("Unknown arg: " + aparser.nextValue());
892 AlignFrame startUpAlframe = null;
893 // We'll only open the default file if the desktop is visible.
895 // ////////////////////
897 if (!isJS && !headless && file == null
898 && Cache.getDefault("SHOW_STARTUP_FILE", true))
905 file = Cache.getDefault("STARTUP_FILE",
906 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
907 + "/examples/exampleFile_2_7.jar");
909 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
911 // hardwire upgrade of the startup file
912 file.replace("_2_3.jar", "_2_7.jar");
913 // and remove the stale setting
914 Cache.removeProperty("STARTUP_FILE");
917 protocol = DataSourceType.FILE;
919 if (file.indexOf("http:") > -1)
921 protocol = DataSourceType.URL;
924 if (file.endsWith(".jar"))
926 format = FileFormat.Jalview;
932 format = new IdentifyFile().identify(file, protocol);
933 } catch (FileFormatException e)
939 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
944 // extract groovy arguments before anything else.
945 // Once all other stuff is done, execute any groovy scripts (in order)
946 if (groovyscript != null)
948 if (Cache.groovyJarsPresent())
950 System.out.println("Executing script " + groovyscript);
951 executeGroovyScript(groovyscript, startUpAlframe);
956 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
961 // and finally, turn off batch mode indicator - if the desktop still exists
966 desktop.setProgressBar(null, progress);
968 desktop.setInBatchMode(false);
973 * Writes an output file for each format (if any) specified in the
974 * command-line arguments. Supported formats are currently
983 * A format parameter should be followed by a parameter specifying the output
984 * file name. {@code imgMap} parameters should follow those for the
985 * corresponding alignment image output.
991 private void createOutputFiles(ArgsParser aparser, AlignFrame af,
994 String imageName = "unnamed.png";
995 while (aparser.getSize() > 1)
997 String outputFormat = aparser.nextValue();
998 String file = aparser.nextValue();
1000 if (outputFormat.equalsIgnoreCase("png"))
1002 af.createPNG(new File(file));
1003 imageName = (new File(file)).getName();
1004 System.out.println("Creating PNG image: " + file);
1007 else if (outputFormat.equalsIgnoreCase("svg"))
1009 File imageFile = new File(file);
1010 imageName = imageFile.getName();
1011 af.createSVG(imageFile);
1012 System.out.println("Creating SVG image: " + file);
1015 else if (outputFormat.equalsIgnoreCase("html"))
1017 File imageFile = new File(file);
1018 imageName = imageFile.getName();
1019 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1020 htmlSVG.exportHTML(file);
1021 System.out.println("Creating HTML image: " + file);
1024 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1028 System.err.println("The output html file must not be null");
1033 BioJsHTMLOutput.refreshVersionInfo(
1034 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1035 } catch (URISyntaxException e)
1037 e.printStackTrace();
1039 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1040 bjs.exportHTML(file);
1041 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1044 else if (outputFormat.equalsIgnoreCase("imgMap"))
1046 af.createImageMap(new File(file), imageName);
1047 System.out.println("Creating image map: " + file);
1050 else if (outputFormat.equalsIgnoreCase("eps"))
1052 File outputFile = new File(file);
1054 "Creating EPS file: " + outputFile.getAbsolutePath());
1055 af.createEPS(outputFile);
1059 af.saveAlignment(file, format);
1060 if (af.isSaveAlignmentSuccessful())
1063 "Written alignment in " + format + " format to " + file);
1067 System.out.println("Error writing file " + file + " in " + format
1075 private static void showUsage()
1078 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1079 + "-nodisplay\tRun Jalview without User Interface.\n"
1080 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1081 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1082 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1083 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1084 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1085 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1086 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1087 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1088 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1089 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1090 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1091 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1092 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1093 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1094 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1095 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1096 + "-html FILE\tCreate HTML file from alignment.\n"
1097 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1098 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1099 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1100 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1101 + "-noquestionnaire\tTurn off questionnaire check.\n"
1102 + "-nonews\tTurn off check for Jalview news.\n"
1103 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1104 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1106 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1107 // after all other properties files have been read\n\t
1108 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1109 // passed in correctly)"
1110 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1111 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1112 + "-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"
1113 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1116 private static void startUsageStats(final Desktop desktop)
1119 * start a User Config prompt asking if we can log usage statistics.
1121 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1122 "USAGESTATS", "Jalview Usage Statistics",
1123 "Do you want to help make Jalview better by enabling "
1124 + "the collection of usage statistics with Google Analytics ?"
1125 + "\n\n(you can enable or disable usage tracking in the preferences)",
1132 "Initialising googletracker for usage stats.");
1133 Cache.initGoogleTracker();
1134 Cache.log.debug("Tracking enabled.");
1141 Cache.log.debug("Not enabling Google Tracking.");
1144 desktop.addDialogThread(prompter);
1148 * Locate the given string as a file and pass it to the groovy interpreter.
1150 * @param groovyscript
1151 * the script to execute
1152 * @param jalviewContext
1153 * the Jalview Desktop object passed in to the groovy binding as the
1156 private void executeGroovyScript(String groovyscript, AlignFrame af)
1159 * for scripts contained in files
1166 if (groovyscript.trim().equals("STDIN"))
1168 // read from stdin into a tempfile and execute it
1171 tfile = File.createTempFile("jalview", "groovy");
1172 PrintWriter outfile = new PrintWriter(
1173 new OutputStreamWriter(new FileOutputStream(tfile)));
1174 BufferedReader br = new BufferedReader(
1175 new InputStreamReader(System.in));
1177 while ((line = br.readLine()) != null)
1179 outfile.write(line + "\n");
1185 } catch (Exception ex)
1187 System.err.println("Failed to read from STDIN into tempfile "
1188 + ((tfile == null) ? "(tempfile wasn't created)"
1189 : tfile.toString()));
1190 ex.printStackTrace();
1195 sfile = tfile.toURI().toURL();
1196 } catch (Exception x)
1199 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1201 x.printStackTrace();
1209 sfile = new URI(groovyscript).toURL();
1210 } catch (Exception x)
1212 tfile = new File(groovyscript);
1213 if (!tfile.exists())
1215 System.err.println("File '" + groovyscript + "' does not exist.");
1218 if (!tfile.canRead())
1220 System.err.println("File '" + groovyscript + "' cannot be read.");
1223 if (tfile.length() < 1)
1225 System.err.println("File '" + groovyscript + "' is empty.");
1230 sfile = tfile.getAbsoluteFile().toURI().toURL();
1231 } catch (Exception ex)
1233 System.err.println("Failed to create a file URL for "
1234 + tfile.getAbsoluteFile());
1241 Map<String, java.lang.Object> vbinding = new HashMap<>();
1242 vbinding.put("Jalview", this);
1245 vbinding.put("currentAlFrame", af);
1247 Binding gbinding = new Binding(vbinding);
1248 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1249 gse.run(sfile.toString(), gbinding);
1250 if ("STDIN".equals(groovyscript))
1252 // delete temp file that we made -
1253 // only if it was successfully executed
1256 } catch (Exception e)
1258 System.err.println("Exception Whilst trying to execute file " + sfile
1259 + " as a groovy script.");
1260 e.printStackTrace(System.err);
1265 public static boolean isHeadlessMode()
1267 String isheadless = System.getProperty("java.awt.headless");
1268 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1275 public AlignFrame[] getAlignFrames()
1277 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1278 : Desktop.getAlignFrames();
1283 * Quit method delegates to Desktop.quit - unless running in headless mode
1284 * when it just ends the JVM
1288 if (desktop != null)
1298 public static AlignFrame getCurrentAlignFrame()
1300 return Jalview.currentAlignFrame;
1303 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1305 Jalview.currentAlignFrame = currentAlignFrame;
1309 * Get the SwingJS applet ID and combine that with the frameType
1312 * "alignment", "desktop", etc., or null
1315 public static String getAppID(String frameType)
1317 String id = Cache.getProperty("Info.j2sAppletID");
1322 return id + (frameType == null ? "" : "-" + frameType);
1326 * Handle all JalviewLite applet parameters
1331 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1333 JalviewApp app = new JalviewApp()
1338 // These are methods that are in JalviewLite that various classes call
1339 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1341 // them to JalviewLite directly. Some may not be necessary, but they have
1343 // be at least mentioned here, or the classes calling them should
1345 // JalviewLite itself.
1347 private boolean alignPDBStructures; // From JalviewLite; not implemented
1349 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1351 private Hashtable<String, int[]> jshashes;
1354 public String getParameter(String name)
1356 return aparser.getAppletValue(name, null);
1360 public boolean getDefaultParameter(String name, boolean def)
1363 return ((stn = getParameter(name)) == null ? def
1364 : "true".equalsIgnoreCase(stn));
1368 * Get the applet-like document base even though this is an application.
1371 public URL getDocumentBase()
1373 return Platform.getDocumentBase();
1377 * Get the applet-like code base even though this is an application.
1380 public URL getCodeBase()
1382 return Platform.getCodeBase();
1386 public AlignViewportI getViewport()
1388 return af.getViewport();
1396 public boolean parseFeaturesFile(String filename,
1397 DataSourceType protocol)
1399 return af.parseFeaturesFile(filename, protocol);
1407 public boolean loadScoreFile(String sScoreFile) throws IOException
1409 af.loadJalviewDataFile(sScoreFile, null, null, null);
1414 * annotations, jpredfile, jnetfile
1418 public void updateForAnnotations()
1420 af.updateForAnnotations();
1424 public void loadTree(NewickFile fin, String treeFile)
1427 // n/a -- already done by standard Jalview command line processing
1431 public void setAlignPdbStructures(boolean defaultParameter)
1433 alignPDBStructures = true;
1437 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1438 String[] chains, DataSourceType protocol)
1440 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1444 public void setFeatureGroupState(String[] groups, boolean state)
1446 af.setFeatureGroupState(groups, state);
1450 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1451 String[][] chains, String[] protocols)
1454 "Jalview applet interface alignedStructureView not implemented");
1458 public void newFeatureSettings()
1461 "Jalview applet interface newFeatureSettings not implemented");
1464 private Vector<Runnable> jsExecQueue;
1467 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1469 jsFunctionExec = exec;
1470 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1474 // AppletContext deprecated
1477 // public AppletContext getAppletContext()
1479 // // TODO Auto-generated method stub
1484 public boolean isJsfallbackEnabled()
1486 // TODO Auto-generated method stub
1491 public JSObject getJSObject()
1493 // TODO Auto-generated method stub
1498 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1500 // TODO Q: what exactly is this? BH
1505 public void updateColoursFromMouseOver(Object source,
1506 MouseOverStructureListener mouseOverStructureListener)
1508 // TODO Auto-generated method stub
1513 public Object[] getSelectionForListener(SequenceGroup seqsel,
1514 ColumnSelection colsel, HiddenColumns hidden,
1515 SelectionSource source, Object alignFrame)
1517 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1518 seqsel, colsel, hidden, source, alignFrame);
1522 public String arrayToSeparatorList(String[] array)
1524 return appLoader.arrayToSeparatorList(array);
1528 public Hashtable<String, int[]> getJSHashes()
1530 return (jshashes == null ? (jshashes = new Hashtable<>())
1535 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1537 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1542 public Object getFrameForSource(VamsasSource source)
1547 if (source instanceof jalview.gui.AlignViewport
1548 && source == (af = getCurrentAlignFrame()).getViewport())
1550 // should be valid if it just generated an event!
1553 // TODO: ensure that if '_af' is specified along with a handler
1554 // function, then only events from that alignFrame are sent to that
1561 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1563 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1568 appLoader = new JalviewAppLoader(true);
1569 appLoader.load(app);
1574 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1577 public String getSelectedSequences()
1579 return getSelectedSequencesFrom(getCurrentAlignFrame());
1584 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1587 public String getSelectedSequences(String sep)
1589 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1594 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1598 public String getSelectedSequencesFrom(AlignFrame alf)
1602 alf = getCurrentAlignFrame();
1604 return getSelectedSequencesFrom(alf, null);
1609 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1610 * .AlignFrame, java.lang.String)
1613 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
1617 alf = getCurrentAlignFrame();
1619 return appLoader.getSelectedSequencesFrom(alf, sep);
1624 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1625 * .AlignFrame, java.lang.String)
1628 public void highlight(String sequenceId, String position,
1629 String alignedPosition)
1631 highlightIn(null, sequenceId, position, alignedPosition);
1635 public void highlightIn(AlignFrame alf, String sequenceId,
1636 String position, String alignedPosition)
1640 alf = getCurrentAlignFrame();
1642 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1646 public void select(String sequenceIds, String columns)
1648 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1652 public void select(String sequenceIds, String columns, String sep)
1654 selectIn(null, sequenceIds, columns, sep);
1658 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
1660 selectIn(alf, sequenceIds, columns, null);
1664 public void selectIn(AlignFrame alf, String sequenceIds, String columns,
1669 alf = getCurrentAlignFrame();
1671 appLoader.selectIn(alf, sequenceIds, columns, sep);
1675 public String getSelectedSequencesAsAlignment(String format,
1678 return getSelectedSequencesAsAlignmentFrom(null, format, suffix);
1682 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
1683 String format, String sep)
1687 alf = getCurrentAlignFrame();
1689 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1693 public String getAlignmentOrder()
1695 return getAlignmentFrom(getCurrentAlignFrame(), null);
1699 public String getAlignmentOrderFrom(AlignFrame alf)
1701 return getAlignmentFrom(alf, null);
1705 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
1709 alf = getCurrentAlignFrame();
1711 return appLoader.getAlignmentOrderFrom(alf, sep);
1715 public String orderBy(String order, String undoName)
1717 return orderBy(order, undoName, null);
1721 public String orderBy(String order, String undoName, String sep)
1723 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1727 public String orderAlignmentBy(AlignFrame alf, String order,
1728 String undoName, String sep)
1732 alf = getCurrentAlignFrame();
1734 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1738 public String getAlignment(String format)
1740 return getAlignmentFrom(null, format, null);
1744 public String getAlignmentFrom(AlignFrame alf, String format)
1746 return getAlignmentFrom(alf, format, null);
1750 public String getAlignment(String format, String suffix)
1752 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1756 public String getAlignmentFrom(AlignFrame alf, String format,
1759 return appLoader.getAlignmentFrom(alf, format, suffix);
1763 public void loadAnnotation(String annotation)
1765 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1769 public void loadAnnotationFrom(AlignFrame alf, String annotation)
1773 alf = getCurrentAlignFrame();
1775 appLoader.loadAnnotationFrom(alf, annotation);
1779 public void loadFeatures(String features, boolean autoenabledisplay)
1781 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1785 public boolean loadFeaturesFrom(AlignFrame alf, String features,
1786 boolean autoenabledisplay)
1790 alf = getCurrentAlignFrame();
1792 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1796 public String getFeatures(String format)
1798 return getFeaturesFrom(null, format);
1802 public String getFeaturesFrom(AlignFrame alf, String format)
1806 alf = getCurrentAlignFrame();
1808 return appLoader.getFeaturesFrom(alf, format);
1812 public String getAnnotation()
1814 return getAnnotationFrom(null);
1818 public String getAnnotationFrom(AlignFrame alf)
1822 alf = getCurrentAlignFrame();
1824 return appLoader.getAnnotationFrom(alf);
1828 // public AlignFrame newView()
1830 // return newViewFrom(null, null);
1834 // public AlignFrame newView(String name)
1836 // return newViewFrom(null, name);
1840 // public AlignFrame newViewFrom(AlignFrame alf)
1842 // return newViewFrom(alf, null);
1846 // public AlignFrame newViewFrom(AlignFrame alf, String name)
1850 // alf = getCurrentAlignFrame();
1852 // return appLoader.newViewFrom(alf, name);
1856 public AlignFrame loadAlignment(String text, String title)
1858 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1859 AlignFrame.DEFAULT_HEIGHT, title);
1863 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
1864 String pdbEntryString, String pdbFile)
1866 if (alFrame == null)
1868 alFrame = getCurrentAlignFrame();
1870 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1875 public void scrollViewToIn(AlignFrame alf, String topRow,
1876 String leftHandColumn)
1880 alf = getCurrentAlignFrame();
1882 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1886 public void scrollViewToRowIn(AlignFrame alf, String topRow)
1890 alf = getCurrentAlignFrame();
1892 appLoader.scrollViewToRowIn(alf, topRow);
1896 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
1900 alf = getCurrentAlignFrame();
1902 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1906 public String getFeatureGroups()
1908 return getFeatureGroupsOn(null);
1912 public String getFeatureGroupsOn(AlignFrame alf)
1916 alf = getCurrentAlignFrame();
1918 return appLoader.getFeatureGroupsOn(alf);
1922 public String getFeatureGroupsOfState(boolean visible)
1924 return getFeatureGroupsOfStateOn(null, visible);
1928 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
1932 alf = getCurrentAlignFrame();
1934 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1938 public void setFeatureGroupState(String groups, boolean state)
1939 { // JalviewLite API
1940 setFeatureGroupStateOn(null, groups, state);
1944 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
1949 alf = getCurrentAlignFrame();
1951 appLoader.setFeatureGroupStateOn(alf, groups, state);
1955 public String getSeparator()
1957 return appLoader.getSeparator();
1961 public void setSeparator(String separator)
1963 appLoader.setSeparator(separator);
1967 public String getJsMessage(String messageclass, String viewId)
1969 // see http://www.jalview.org/examples/jalviewLiteJs.html
1974 * Open a new Tree panel on the desktop statically. Params are standard (not
1975 * set by Groovy). No dialog is opened.
1980 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1981 * of sequences selected is inappropriate
1984 public Object openTreePanel(AlignFrame af, String treeType,
1989 af = getCurrentAlignFrame();
1991 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
1995 * public static method for JalviewJS API to open a PCAPanel without
1996 * necessarily using a dialog.
2000 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
2001 * if number of sequences selected is inappropriate
2004 public Object openPcaPanel(AlignFrame af, String modelName)
2008 af = getCurrentAlignFrame();
2010 return CalculationChooser.openPcaPanel(af, modelName, null);
2014 public String getSelectedSequencesAsAlignment(String format,
2017 return getSelectedSequencesAsAlignmentFrom(null, format, suffix);
2021 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
2022 String format, boolean suffix)
2026 alf = getCurrentAlignFrame();
2028 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
2033 public String arrayToSeparatorList(String[] array)
2035 return appLoader.arrayToSeparatorList(array);
2039 public String[] separatorListToArray(String list)
2041 return appLoader.separatorListToArray(list);
2044 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
2045 //// have a direct connection?
2048 public void setMouseoverListener(String listener)
2050 // TODO Auto-generated method stub
2055 public void setMouseoverListener(AlignFrame af, String listener)
2057 // TODO Auto-generated method stub
2062 public void setSelectionListener(String listener)
2064 // TODO Auto-generated method stub
2069 public void setSelectionListener(AlignFrame af, String listener)
2071 // TODO Auto-generated method stub
2076 public void setStructureListener(String listener, String modelSet)
2078 // TODO Auto-generated method stub
2083 public void removeJavascriptListener(AlignFrame af, String listener)
2085 // TODO Auto-generated method stub
2090 public void mouseOverStructure(String pdbResNum, String chain,
2093 // TODO Auto-generated method stub
2098 public void showOverview()
2100 currentAlignFrame.overviewMenuItem_actionPerformed(null);
2103 public void notifyWorker(AlignCalcWorkerI worker, String status)
2105 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()