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.bin.ApplicationSingletonProvider.ApplicationSingletonI;
56 import jalview.datamodel.ColumnSelection;
57 import jalview.datamodel.HiddenColumns;
58 import jalview.datamodel.PDBEntry;
59 import jalview.datamodel.SequenceGroup;
60 import jalview.datamodel.SequenceI;
61 import jalview.ext.so.SequenceOntology;
62 import jalview.gui.AlignFrame;
63 import jalview.gui.AlignViewport;
64 import jalview.gui.AlignmentPanel;
65 import jalview.gui.CalculationChooser;
66 import jalview.gui.Desktop;
67 import jalview.gui.Preferences;
68 import jalview.gui.PromptUserConfig;
69 import jalview.gui.StructureViewer;
70 import jalview.io.AppletFormatAdapter;
71 import jalview.io.BioJsHTMLOutput;
72 import jalview.io.DataSourceType;
73 import jalview.io.FileFormat;
74 import jalview.io.FileFormatException;
75 import jalview.io.FileFormatI;
76 import jalview.io.FileFormats;
77 import jalview.io.FileLoader;
78 import jalview.io.HtmlSvgOutput;
79 import jalview.io.IdentifyFile;
80 import jalview.io.NewickFile;
81 import jalview.io.gff.SequenceOntologyFactory;
82 import jalview.javascript.JSFunctionExec;
83 import jalview.javascript.MouseOverStructureListener;
84 import jalview.renderer.seqfeatures.FeatureRenderer;
85 import jalview.schemes.ColourSchemeI;
86 import jalview.schemes.ColourSchemeProperty;
87 import jalview.structure.SelectionSource;
88 import jalview.structure.VamsasSource;
89 import jalview.util.MessageManager;
90 import jalview.util.Platform;
91 import jalview.ws.jws2.Jws2Discoverer;
92 import netscape.javascript.JSObject;
95 * Main class for Jalview Application <br>
97 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
100 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
101 * jalview.bin.Jalview jalview.bin.Jalview
103 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
104 * embellish '*' to e.g. '*.jar')
107 * @version $Revision$
109 public class Jalview implements ApplicationSingletonI, JalviewJSApi
112 // for testing those nasty messages you cannot ever find.
115 // System.setOut(new PrintStream(new ByteArrayOutputStream())
118 // public void println(Object o)
122 // System.err.println(o);
128 public static Jalview getInstance()
130 return (Jalview) ApplicationSingletonProvider
131 .getInstance(Jalview.class);
140 Platform.getURLCommandArguments();
143 private boolean headless;
145 private Desktop desktop;
147 public static AlignFrame currentAlignFrame;
149 public boolean isJavaAppletTag;
151 public String appletResourcePath;
153 JalviewAppLoader appLoader;
155 protected JSFunctionExec jsFunctionExec;
157 private boolean noCalculation, noMenuBar, noStatus;
159 private boolean noAnnotation;
161 public boolean getStartCalculations()
163 return !noCalculation;
166 public boolean getAllowMenuBar()
171 public boolean getShowStatus()
176 public boolean getShowAnnotation()
178 return !noAnnotation;
183 if (!Platform.isJS())
190 // grab all the rights we can for the JVM
191 Policy.setPolicy(new Policy()
194 public PermissionCollection getPermissions(CodeSource codesource)
196 Permissions perms = new Permissions();
197 perms.add(new AllPermission());
202 public void refresh()
210 * keep track of feature fetching tasks.
218 * TODO: generalise to track all jalview events to orchestrate batch processing
222 private int queued = 0;
224 private int running = 0;
226 public FeatureFetcher()
231 public void addFetcher(final AlignFrame af,
232 final Vector<String> dasSources)
234 final long id = System.currentTimeMillis();
236 final FeatureFetcher us = this;
237 new Thread(new Runnable()
249 af.setProgressBar(MessageManager
250 .getString("status.das_features_being_retrived"), id);
251 af.featureSettings_actionPerformed(null);
252 af.setProgressBar(null, id);
261 public synchronized boolean allFinished()
263 return queued == 0 && running == 0;
268 private final static boolean doPlatformLogging = false;
271 * main class for Jalview application
274 * open <em>filename</em>
276 public static void main(String[] args)
278 if (doPlatformLogging)
280 Platform.startJavaLogging();
282 getInstance().doMain(args);
288 void doMain(String[] args)
291 boolean isJS = Platform.isJS();
294 Platform.setAppClass(this);
298 System.setSecurityManager(null);
302 .println("Java version: " + System.getProperty("java.version"));
303 System.out.println("Java Home: " + System.getProperty("java.home"));
304 System.out.println(System.getProperty("os.arch") + " "
305 + System.getProperty("os.name") + " "
306 + System.getProperty("os.version"));
307 String val = System.getProperty("sys.install4jVersion");
310 System.out.println("Install4j version: " + val);
312 val = System.getProperty("installer_template_version");
315 System.out.println("Install4j template version: " + val);
317 val = System.getProperty("launcher_version");
320 System.out.println("Launcher version: " + val);
323 // report Jalview version
324 Cache.getInstance().loadBuildProperties(true);
326 ArgsParser aparser = new ArgsParser(args);
329 String usrPropsFile = aparser.getValue("props");
331 Cache.loadProperties(usrPropsFile); // must do this before
335 isJavaAppletTag = aparser.isApplet();
338 Preferences.setAppletDefaults();
339 Cache.loadProperties(usrPropsFile); // again, because we
340 // might be changing defaults here?
343 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
344 appletResourcePath = aparser.getValue("Info.resourcePath");
354 if (usrPropsFile != null)
357 "CMD [-props " + usrPropsFile + "] executed successfully!");
359 if (aparser.contains("help") || aparser.contains("h"))
365 if (aparser.contains("nodisplay") || aparser.contains("nogui")
366 || aparser.contains("headless"))
368 System.setProperty("java.awt.headless", "true");
375 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
376 if (jabawsUrl != null)
380 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
382 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
383 } catch (MalformedURLException e)
386 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
391 String defs = aparser.getValue(ArgsParser.SETPROP);
394 int p = defs.indexOf('=');
397 System.err.println("Ignoring invalid setprop argument : " + defs);
401 System.out.println("Executing setprop argument: " + defs);
404 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
407 defs = aparser.getValue("setprop");
409 if (System.getProperty("java.awt.headless") != null
410 && System.getProperty("java.awt.headless").equals("true"))
414 System.setProperty("http.agent",
415 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
419 } catch (NoClassDefFoundError error)
421 error.printStackTrace();
422 System.out.println("\nEssential logging libraries not found."
423 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
434 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
435 } catch (Exception ex)
437 System.err.println("Unexpected Look and Feel Exception");
438 ex.printStackTrace();
440 if (Platform.isMac())
443 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
446 "com.apple.mrj.application.apple.menu.about.name",
448 System.setProperty("apple.laf.useScreenMenuBar", "true");
449 if (lookAndFeel != null)
453 UIManager.setLookAndFeel(lookAndFeel);
454 } catch (Throwable e)
457 "Failed to set QuaQua look and feel: " + e.toString());
460 if (lookAndFeel == null
461 || !(lookAndFeel.getClass().isAssignableFrom(
462 UIManager.getLookAndFeel().getClass()))
463 || !UIManager.getLookAndFeel().getClass().toString()
464 .toLowerCase().contains("quaqua"))
469 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
470 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
471 } catch (Throwable e)
474 "Failed to reset look and feel: " + e.toString());
480 * configure 'full' SO model if preferences say to, else use the default (full SO)
481 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
483 boolean soDefault = !Platform.isJS();
484 if (Cache.getDefault("USE_FULL_SO", soDefault))
486 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
491 desktop = Desktop.getInstance();
492 desktop.setInBatchMode(true); // indicate we are starting up
495 JalviewTaskbar.setTaskbar(this);
496 } catch (Throwable t)
498 System.out.println("Error setting Taskbar: " + t.getMessage());
500 desktop.setVisible(true);
502 if (!Platform.isJS())
509 desktop.startServiceDiscovery();
510 if (!aparser.contains("nousagestats"))
512 startUsageStats(desktop);
516 System.err.println("CMD [-nousagestats] executed successfully!");
519 if (!aparser.contains("noquestionnaire"))
521 String url = aparser.getValue("questionnaire");
524 // Start the desktop questionnaire prompter with the specified
526 Cache.log.debug("Starting questionnaire url at " + url);
527 desktop.checkForQuestionnaire(url);
528 System.out.println("CMD questionnaire[-" + url
529 + "] executed successfully!");
533 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
535 // Start the desktop questionnaire prompter with the specified
538 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
540 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
542 "Starting questionnaire with default url: " + defurl);
543 desktop.checkForQuestionnaire(defurl);
550 .println("CMD [-noquestionnaire] executed successfully!");
553 if (!aparser.contains("nonews"))
555 desktop.checkForNews();
558 BioJsHTMLOutput.updateBioJS();
562 parseArguments(aparser, true);
566 * Allow an outside entity to initiate the second half of argument parsing
570 * @return null is good
573 public Object parseArguments(String[] args)
578 parseArguments(new ArgsParser(args), false);
580 } catch (Throwable t)
591 private void parseArguments(ArgsParser aparser, boolean isStartup)
594 String groovyscript = null; // script to execute after all loading is
595 boolean isJS = Platform.isJS();
599 // Move any new getdown-launcher-new.jar into place over old
600 // getdown-launcher.jar
601 String appdirString = System.getProperty("getdownappdir");
602 if (appdirString != null && appdirString.length() > 0)
604 final File appdir = new File(appdirString);
610 LaunchUtil.upgradeGetdown(
611 new File(appdir, "getdown-launcher-old.jar"),
612 new File(appdir, "getdown-launcher.jar"),
613 new File(appdir, "getdown-launcher-new.jar"));
618 // completed one way or another
619 // extract groovy argument and execute if necessary
620 groovyscript = aparser.getValue("groovy", true);
624 String file = aparser.getValue("open", true);
626 if (file == null && desktop == null)
628 System.out.println("No files to open!");
633 DataSourceType protocol = null;
634 FileLoader fileLoader = new FileLoader(!headless);
635 FileFormatI format = null;
636 // Finally, deal with the remaining input data.
641 desktop.setProgressBar(
643 .getString("status.processing_commandline_args"),
644 progress = System.currentTimeMillis());
646 System.out.println("CMD [-open " + file + "] executed successfully!");
648 if (!Platform.isJS())
650 * ignore in JavaScript -- can't just file existence - could load it?
655 if (!file.startsWith("http://") && !file.startsWith("https://"))
656 // BH 2019 added https check for Java
658 if (!(new File(file)).exists())
660 System.out.println("Can't find " + file);
668 String fileFormat = (isJavaAppletTag
669 ? aparser.getAppletValue("format", null)
671 protocol = AppletFormatAdapter.checkProtocol(file);
674 format = (isJavaAppletTag && fileFormat != null
675 ? FileFormats.getInstance().forName(fileFormat)
679 format = new IdentifyFile().identify(file, protocol);
681 format = new IdentifyFile().identify(file, protocol);
682 } catch (FileFormatException e1)
687 if (aparser.contains(ArgsParser.NOMENUBAR))
690 System.out.println("CMD [nomenu] executed successfully!");
693 if (aparser.contains(ArgsParser.NOSTATUS))
696 System.out.println("CMD [nostatus] executed successfully!");
699 if (aparser.contains(ArgsParser.NOANNOTATION)
700 || aparser.contains(ArgsParser.NOANNOTATION2))
703 System.out.println("CMD no-annotation executed successfully!");
705 if (aparser.contains(ArgsParser.NOCALCULATION))
707 noCalculation = true;
708 System.out.println("CMD [nocalculation] executed successfully!");
711 AlignFrame af = new FileLoader(!headless).LoadFileWaitTillLoaded(file,
715 System.out.println("error");
720 // JalviewLite interface for JavaScript allows second file open
721 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
724 protocol = AppletFormatAdapter.checkProtocol(file2);
727 format = new IdentifyFile().identify(file2, protocol);
728 } catch (FileFormatException e1)
732 AlignFrame af2 = new FileLoader(!headless)
733 .LoadFileWaitTillLoaded(file2, protocol, format);
736 System.out.println("error");
740 AlignViewport.openLinkedAlignmentAs(af,
741 af.getViewport().getAlignment(),
742 af2.getViewport().getAlignment(), "",
743 AlignViewport.SPLIT_FRAME);
745 "CMD [-open2 " + file2 + "] executed successfully!");
748 setCurrentAlignFrame(af);
750 String data = aparser.getValue(ArgsParser.COLOUR, true);
753 data.replaceAll("%20", " ");
755 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
756 af.getViewport(), af.getViewport().getAlignment(), data);
761 "CMD [-color " + data + "] executed successfully!");
766 // Must maintain ability to use the groups flag
767 data = aparser.getValue(ArgsParser.GROUPS, true);
770 af.parseFeaturesFile(data,
771 AppletFormatAdapter.checkProtocol(data));
772 // System.out.println("Added " + data);
774 "CMD groups[-" + data + "] executed successfully!");
776 data = aparser.getValue(ArgsParser.FEATURES, true);
779 af.parseFeaturesFile(data,
780 AppletFormatAdapter.checkProtocol(data));
781 // System.out.println("Added " + data);
783 "CMD [-features " + data + "] executed successfully!");
785 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
788 af.loadJalviewDataFile(data, null, null, null);
789 // System.out.println("Added " + data);
791 "CMD [-annotations " + data + "] executed successfully!");
794 // JavaScript feature
796 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
798 af.overviewMenuItem_actionPerformed(null);
799 System.out.println("CMD [showoverview] executed successfully!");
802 // set or clear the sortbytree flag.
803 if (aparser.contains(ArgsParser.SORTBYTREE))
805 af.getViewport().setSortByTree(true);
806 if (af.getViewport().getSortByTree())
808 System.out.println("CMD [-sortbytree] executed successfully!");
812 boolean doUpdateAnnotation = false;
814 * we do this earlier in JalviewJS because of a complication with
817 * For now, just fixing this in JalviewJS.
824 if (aparser.contains(ArgsParser.NOANNOTATION)
825 || aparser.contains(ArgsParser.NOANNOTATION2))
827 af.getViewport().setShowAnnotation(false);
828 if (!af.getViewport().isShowAnnotation())
830 doUpdateAnnotation = true;
832 .println("CMD no-annotation executed successfully!");
837 if (aparser.contains(ArgsParser.NOSORTBYTREE))
839 af.getViewport().setSortByTree(false);
840 if (!af.getViewport().getSortByTree())
842 doUpdateAnnotation = true;
844 .println("CMD [-nosortbytree] executed successfully!");
847 if (doUpdateAnnotation)
849 af.setMenusForViewport();
850 af.alignPanel.updateLayout();
853 data = aparser.getValue(ArgsParser.TREE, true);
859 "CMD [-tree " + data + "] executed successfully!");
860 NewickFile nf = new NewickFile(data,
861 AppletFormatAdapter.checkProtocol(data));
863 .setCurrentTree(af.showNewickTree(nf, data).getTree());
864 } catch (IOException ex)
866 System.err.println("Couldn't add tree " + data);
867 ex.printStackTrace(System.err);
870 // TODO - load PDB structure(s) to alignment JAL-629
871 // (associate with identical sequence in alignment, or a specified
875 loadAppletParams(aparser, af);
884 if (groovyscript != null)
886 // Execute the groovy script after we've done all the rendering
888 // and before any images or figures are generated.
889 System.out.println("Executing script " + groovyscript);
890 executeGroovyScript(groovyscript, af);
891 System.out.println("CMD groovy[" + groovyscript
892 + "] executed successfully!");
896 createOutputFiles(aparser, af, format);
897 while (aparser.getSize() > 0)
899 System.out.println("Unknown arg: " + aparser.nextValue());
904 AlignFrame startUpAlframe = null;
905 // We'll only open the default file if the desktop is visible.
907 // ////////////////////
909 if (!isJS && !headless && file == null
910 && Cache.getDefault("SHOW_STARTUP_FILE", true))
917 file = Cache.getDefault("STARTUP_FILE",
918 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
919 + "/examples/exampleFile_2_7.jar");
921 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
923 // hardwire upgrade of the startup file
924 file.replace("_2_3.jar", "_2_7.jar");
925 // and remove the stale setting
926 Cache.removeProperty("STARTUP_FILE");
929 protocol = DataSourceType.FILE;
931 if (file.indexOf("http:") > -1)
933 protocol = DataSourceType.URL;
936 if (file.endsWith(".jar"))
938 format = FileFormat.Jalview;
944 format = new IdentifyFile().identify(file, protocol);
945 } catch (FileFormatException e)
951 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
956 // extract groovy arguments before anything else.
957 // Once all other stuff is done, execute any groovy scripts (in order)
958 if (groovyscript != null)
960 if (Cache.groovyJarsPresent())
962 System.out.println("Executing script " + groovyscript);
963 executeGroovyScript(groovyscript, startUpAlframe);
968 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
973 // and finally, turn off batch mode indicator - if the desktop still exists
978 desktop.setProgressBar(null, progress);
980 desktop.setInBatchMode(false);
985 * Writes an output file for each format (if any) specified in the
986 * command-line arguments. Supported formats are currently
995 * A format parameter should be followed by a parameter specifying the output
996 * file name. {@code imgMap} parameters should follow those for the
997 * corresponding alignment image output.
1003 private void createOutputFiles(ArgsParser aparser, AlignFrame af,
1006 String imageName = "unnamed.png";
1007 while (aparser.getSize() > 1)
1009 String outputFormat = aparser.nextValue();
1010 String file = aparser.nextValue();
1012 if (outputFormat.equalsIgnoreCase("png"))
1014 af.createPNG(new File(file));
1015 imageName = (new File(file)).getName();
1016 System.out.println("Creating PNG image: " + file);
1019 else if (outputFormat.equalsIgnoreCase("svg"))
1021 File imageFile = new File(file);
1022 imageName = imageFile.getName();
1023 af.createSVG(imageFile);
1024 System.out.println("Creating SVG image: " + file);
1027 else if (outputFormat.equalsIgnoreCase("html"))
1029 File imageFile = new File(file);
1030 imageName = imageFile.getName();
1031 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1032 htmlSVG.exportHTML(file);
1033 System.out.println("Creating HTML image: " + file);
1036 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1040 System.err.println("The output html file must not be null");
1045 BioJsHTMLOutput.refreshVersionInfo(
1046 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1047 } catch (URISyntaxException e)
1049 e.printStackTrace();
1051 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1052 bjs.exportHTML(file);
1053 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1056 else if (outputFormat.equalsIgnoreCase("imgMap"))
1058 af.createImageMap(new File(file), imageName);
1059 System.out.println("Creating image map: " + file);
1062 else if (outputFormat.equalsIgnoreCase("eps"))
1064 File outputFile = new File(file);
1066 "Creating EPS file: " + outputFile.getAbsolutePath());
1067 af.createEPS(outputFile);
1071 af.saveAlignment(file, format);
1072 if (af.isSaveAlignmentSuccessful())
1075 "Written alignment in " + format + " format to " + file);
1079 System.out.println("Error writing file " + file + " in " + format
1087 private static void showUsage()
1090 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1091 + "-nodisplay\tRun Jalview without User Interface.\n"
1092 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1093 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1094 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1095 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1096 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1097 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1098 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1099 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1100 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1101 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1102 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1103 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1104 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1105 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1106 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1107 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1108 + "-html FILE\tCreate HTML file from alignment.\n"
1109 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1110 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1111 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1112 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1113 + "-noquestionnaire\tTurn off questionnaire check.\n"
1114 + "-nonews\tTurn off check for Jalview news.\n"
1115 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1116 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1118 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1119 // after all other properties files have been read\n\t
1120 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1121 // passed in correctly)"
1122 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1123 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1124 + "-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"
1125 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1128 private static void startUsageStats(final Desktop desktop)
1131 * start a User Config prompt asking if we can log usage statistics.
1133 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1134 "USAGESTATS", "Jalview Usage Statistics",
1135 "Do you want to help make Jalview better by enabling "
1136 + "the collection of usage statistics with Google Analytics ?"
1137 + "\n\n(you can enable or disable usage tracking in the preferences)",
1144 "Initialising googletracker for usage stats.");
1145 Cache.initGoogleTracker();
1146 Cache.log.debug("Tracking enabled.");
1153 Cache.log.debug("Not enabling Google Tracking.");
1156 desktop.addDialogThread(prompter);
1160 * Locate the given string as a file and pass it to the groovy interpreter.
1162 * @param groovyscript
1163 * the script to execute
1164 * @param jalviewContext
1165 * the Jalview Desktop object passed in to the groovy binding as the
1168 private void executeGroovyScript(String groovyscript, AlignFrame af)
1171 * for scripts contained in files
1178 if (groovyscript.trim().equals("STDIN"))
1180 // read from stdin into a tempfile and execute it
1183 tfile = File.createTempFile("jalview", "groovy");
1184 PrintWriter outfile = new PrintWriter(
1185 new OutputStreamWriter(new FileOutputStream(tfile)));
1186 BufferedReader br = new BufferedReader(
1187 new InputStreamReader(System.in));
1189 while ((line = br.readLine()) != null)
1191 outfile.write(line + "\n");
1197 } catch (Exception ex)
1199 System.err.println("Failed to read from STDIN into tempfile "
1200 + ((tfile == null) ? "(tempfile wasn't created)"
1201 : tfile.toString()));
1202 ex.printStackTrace();
1207 sfile = tfile.toURI().toURL();
1208 } catch (Exception x)
1211 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1213 x.printStackTrace();
1221 sfile = new URI(groovyscript).toURL();
1222 } catch (Exception x)
1224 tfile = new File(groovyscript);
1225 if (!tfile.exists())
1227 System.err.println("File '" + groovyscript + "' does not exist.");
1230 if (!tfile.canRead())
1232 System.err.println("File '" + groovyscript + "' cannot be read.");
1235 if (tfile.length() < 1)
1237 System.err.println("File '" + groovyscript + "' is empty.");
1242 sfile = tfile.getAbsoluteFile().toURI().toURL();
1243 } catch (Exception ex)
1245 System.err.println("Failed to create a file URL for "
1246 + tfile.getAbsoluteFile());
1253 Map<String, java.lang.Object> vbinding = new HashMap<>();
1254 vbinding.put("Jalview", this);
1257 vbinding.put("currentAlFrame", af);
1259 Binding gbinding = new Binding(vbinding);
1260 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1261 gse.run(sfile.toString(), gbinding);
1262 if ("STDIN".equals(groovyscript))
1264 // delete temp file that we made -
1265 // only if it was successfully executed
1268 } catch (Exception e)
1270 System.err.println("Exception Whilst trying to execute file " + sfile
1271 + " as a groovy script.");
1272 e.printStackTrace(System.err);
1277 public static boolean isHeadlessMode()
1279 String isheadless = System.getProperty("java.awt.headless");
1280 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1287 public AlignFrame[] getAlignFrames()
1289 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1290 : Desktop.getAlignFrames();
1295 * Quit method delegates to Desktop.quit - unless running in headless mode
1296 * when it just ends the JVM
1300 if (desktop != null)
1310 public static AlignFrame getCurrentAlignFrame()
1312 return Jalview.currentAlignFrame;
1315 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1317 Jalview.currentAlignFrame = currentAlignFrame;
1321 * Get the SwingJS applet ID and combine that with the frameType
1324 * "alignment", "desktop", etc., or null
1327 public static String getAppID(String frameType)
1329 String id = Cache.getProperty("Info.j2sAppletID");
1334 return id + (frameType == null ? "" : "-" + frameType);
1338 * Handle all JalviewLite applet parameters
1343 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1345 JalviewApp app = new JalviewApp()
1350 // These are methods that are in JalviewLite that various classes call
1351 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1353 // them to JalviewLite directly. Some may not be necessary, but they have
1355 // be at least mentioned here, or the classes calling them should
1357 // JalviewLite itself.
1359 private boolean alignPDBStructures; // From JalviewLite; not implemented
1361 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1363 private Hashtable<String, int[]> jshashes;
1366 public String getParameter(String name)
1368 return aparser.getAppletValue(name, null);
1372 public boolean getDefaultParameter(String name, boolean def)
1375 return ((stn = getParameter(name)) == null ? def
1376 : "true".equalsIgnoreCase(stn));
1380 * Get the applet-like document base even though this is an application.
1383 public URL getDocumentBase()
1385 return Platform.getDocumentBase();
1389 * Get the applet-like code base even though this is an application.
1392 public URL getCodeBase()
1394 return Platform.getCodeBase();
1398 public AlignViewportI getViewport()
1400 return af.getViewport();
1408 public boolean parseFeaturesFile(String filename,
1409 DataSourceType protocol)
1411 return af.parseFeaturesFile(filename, protocol);
1419 public boolean loadScoreFile(String sScoreFile) throws IOException
1421 af.loadJalviewDataFile(sScoreFile, null, null, null);
1426 * annotations, jpredfile, jnetfile
1430 public void updateForAnnotations()
1432 af.updateForAnnotations();
1436 public void loadTree(NewickFile fin, String treeFile)
1439 // n/a -- already done by standard Jalview command line processing
1443 public void setAlignPdbStructures(boolean defaultParameter)
1445 alignPDBStructures = true;
1449 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1450 String[] chains, DataSourceType protocol)
1452 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1456 public void setFeatureGroupState(String[] groups, boolean state)
1458 af.setFeatureGroupState(groups, state);
1462 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1463 String[][] chains, String[] protocols)
1466 "Jalview applet interface alignedStructureView not implemented");
1470 public void newFeatureSettings()
1473 "Jalview applet interface newFeatureSettings not implemented");
1476 private Vector<Runnable> jsExecQueue;
1479 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1481 jsFunctionExec = exec;
1482 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1486 // AppletContext deprecated
1489 // public AppletContext getAppletContext()
1491 // // TODO Auto-generated method stub
1496 public boolean isJsfallbackEnabled()
1498 // TODO Auto-generated method stub
1503 public JSObject getJSObject()
1505 // TODO Auto-generated method stub
1510 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1512 // TODO Q: what exactly is this? BH
1517 public void updateColoursFromMouseOver(Object source,
1518 MouseOverStructureListener mouseOverStructureListener)
1520 // TODO Auto-generated method stub
1525 public Object[] getSelectionForListener(SequenceGroup seqsel,
1526 ColumnSelection colsel, HiddenColumns hidden,
1527 SelectionSource source, Object alignFrame)
1529 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1530 seqsel, colsel, hidden, source, alignFrame);
1534 public String arrayToSeparatorList(String[] array)
1536 return appLoader.arrayToSeparatorList(array);
1540 public Hashtable<String, int[]> getJSHashes()
1542 return (jshashes == null ? (jshashes = new Hashtable<>())
1547 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1549 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1554 public Object getFrameForSource(VamsasSource source)
1559 if (source instanceof jalview.gui.AlignViewport
1560 && source == (af = getCurrentAlignFrame()).getViewport())
1562 // should be valid if it just generated an event!
1565 // TODO: ensure that if '_af' is specified along with a handler
1566 // function, then only events from that alignFrame are sent to that
1573 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1575 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1580 appLoader = new JalviewAppLoader(true);
1581 appLoader.load(app);
1586 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1589 public String getSelectedSequences()
1591 return getSelectedSequencesFrom(getCurrentAlignFrame());
1596 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1599 public String getSelectedSequences(String sep)
1601 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1606 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1610 public String getSelectedSequencesFrom(AlignFrame alf)
1614 alf = getCurrentAlignFrame();
1616 return getSelectedSequencesFrom(alf, null);
1621 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1622 * .AlignFrame, java.lang.String)
1625 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
1629 alf = getCurrentAlignFrame();
1631 return appLoader.getSelectedSequencesFrom(alf, sep);
1636 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1637 * .AlignFrame, java.lang.String)
1640 public void highlight(String sequenceId, String position,
1641 String alignedPosition)
1643 highlightIn(null, sequenceId, position, alignedPosition);
1647 public void highlightIn(AlignFrame alf, String sequenceId,
1648 String position, String alignedPosition)
1652 alf = getCurrentAlignFrame();
1654 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1658 public void select(String sequenceIds, String columns)
1660 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1664 public void select(String sequenceIds, String columns, String sep)
1666 selectIn(null, sequenceIds, columns, sep);
1670 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
1672 selectIn(alf, sequenceIds, columns, null);
1676 public void selectIn(AlignFrame alf, String sequenceIds, String columns,
1681 alf = getCurrentAlignFrame();
1683 appLoader.selectIn(alf, sequenceIds, columns, sep);
1687 public String getSelectedSequencesAsAlignment(String format,
1690 return getSelectedSequencesAsAlignmentFrom(null, format, suffix);
1694 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
1695 String format, String sep)
1699 alf = getCurrentAlignFrame();
1701 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1705 public String getAlignmentOrder()
1707 return getAlignmentFrom(getCurrentAlignFrame(), null);
1711 public String getAlignmentOrderFrom(AlignFrame alf)
1713 return getAlignmentFrom(alf, null);
1717 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
1721 alf = getCurrentAlignFrame();
1723 return appLoader.getAlignmentOrderFrom(alf, sep);
1727 public String orderBy(String order, String undoName)
1729 return orderBy(order, undoName, null);
1733 public String orderBy(String order, String undoName, String sep)
1735 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1739 public String orderAlignmentBy(AlignFrame alf, String order,
1740 String undoName, String sep)
1744 alf = getCurrentAlignFrame();
1746 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1750 public String getAlignment(String format)
1752 return getAlignmentFrom(null, format, null);
1756 public String getAlignmentFrom(AlignFrame alf, String format)
1758 return getAlignmentFrom(alf, format, null);
1762 public String getAlignment(String format, String suffix)
1764 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1768 public String getAlignmentFrom(AlignFrame alf, String format,
1771 return appLoader.getAlignmentFrom(alf, format, suffix);
1775 public void loadAnnotation(String annotation)
1777 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1781 public void loadAnnotationFrom(AlignFrame alf, String annotation)
1785 alf = getCurrentAlignFrame();
1787 appLoader.loadAnnotationFrom(alf, annotation);
1791 public void loadFeatures(String features, boolean autoenabledisplay)
1793 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1797 public boolean loadFeaturesFrom(AlignFrame alf, String features,
1798 boolean autoenabledisplay)
1802 alf = getCurrentAlignFrame();
1804 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1808 public String getFeatures(String format)
1810 return getFeaturesFrom(null, format);
1814 public String getFeaturesFrom(AlignFrame alf, String format)
1818 alf = getCurrentAlignFrame();
1820 return appLoader.getFeaturesFrom(alf, format);
1824 public String getAnnotation()
1826 return getAnnotationFrom(null);
1830 public String getAnnotationFrom(AlignFrame alf)
1834 alf = getCurrentAlignFrame();
1836 return appLoader.getAnnotationFrom(alf);
1840 // public AlignFrame newView()
1842 // return newViewFrom(null, null);
1846 // public AlignFrame newView(String name)
1848 // return newViewFrom(null, name);
1852 // public AlignFrame newViewFrom(AlignFrame alf)
1854 // return newViewFrom(alf, null);
1858 // public AlignFrame newViewFrom(AlignFrame alf, String name)
1862 // alf = getCurrentAlignFrame();
1864 // return appLoader.newViewFrom(alf, name);
1868 public AlignFrame loadAlignment(String text, String title)
1870 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1871 AlignFrame.DEFAULT_HEIGHT, title);
1875 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
1876 String pdbEntryString, String pdbFile)
1878 if (alFrame == null)
1880 alFrame = getCurrentAlignFrame();
1882 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1887 public void scrollViewToIn(AlignFrame alf, String topRow,
1888 String leftHandColumn)
1892 alf = getCurrentAlignFrame();
1894 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1898 public void scrollViewToRowIn(AlignFrame alf, String topRow)
1902 alf = getCurrentAlignFrame();
1904 appLoader.scrollViewToRowIn(alf, topRow);
1908 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
1912 alf = getCurrentAlignFrame();
1914 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1918 public String getFeatureGroups()
1920 return getFeatureGroupsOn(null);
1924 public String getFeatureGroupsOn(AlignFrame alf)
1928 alf = getCurrentAlignFrame();
1930 return appLoader.getFeatureGroupsOn(alf);
1934 public String getFeatureGroupsOfState(boolean visible)
1936 return getFeatureGroupsOfStateOn(null, visible);
1940 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
1944 alf = getCurrentAlignFrame();
1946 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1950 public void setFeatureGroupState(String groups, boolean state)
1951 { // JalviewLite API
1952 setFeatureGroupStateOn(null, groups, state);
1956 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
1961 alf = getCurrentAlignFrame();
1963 appLoader.setFeatureGroupStateOn(alf, groups, state);
1967 public String getSeparator()
1969 return appLoader.getSeparator();
1973 public void setSeparator(String separator)
1975 appLoader.setSeparator(separator);
1979 public String getJsMessage(String messageclass, String viewId)
1981 // see http://www.jalview.org/examples/jalviewLiteJs.html
1986 * Open a new Tree panel on the desktop statically. Params are standard (not
1987 * set by Groovy). No dialog is opened.
1992 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1993 * of sequences selected is inappropriate
1996 public Object openTreePanel(AlignFrame af, String treeType,
2001 af = getCurrentAlignFrame();
2003 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
2007 * public static method for JalviewJS API to open a PCAPanel without
2008 * necessarily using a dialog.
2012 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
2013 * if number of sequences selected is inappropriate
2016 public Object openPcaPanel(AlignFrame af, String modelName)
2020 af = getCurrentAlignFrame();
2022 return CalculationChooser.openPcaPanel(af, modelName, null);
2026 public String getSelectedSequencesAsAlignment(String format,
2029 return getSelectedSequencesAsAlignmentFrom(null, format, suffix);
2033 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
2034 String format, boolean suffix)
2038 alf = getCurrentAlignFrame();
2040 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
2045 public String arrayToSeparatorList(String[] array)
2047 return appLoader.arrayToSeparatorList(array);
2051 public String[] separatorListToArray(String list)
2053 return appLoader.separatorListToArray(list);
2056 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
2057 //// have a direct connection?
2060 public void setMouseoverListener(String listener)
2062 // TODO Auto-generated method stub
2067 public void setMouseoverListener(AlignFrame af, String listener)
2069 // TODO Auto-generated method stub
2074 public void setSelectionListener(String listener)
2076 // TODO Auto-generated method stub
2081 public void setSelectionListener(AlignFrame af, String listener)
2083 // TODO Auto-generated method stub
2088 public void setStructureListener(String listener, String modelSet)
2090 // TODO Auto-generated method stub
2095 public void removeJavascriptListener(AlignFrame af, String listener)
2097 // TODO Auto-generated method stub
2102 public void mouseOverStructure(String pdbResNum, String chain,
2105 // TODO Auto-generated method stub
2110 public void showOverview()
2112 currentAlignFrame.overviewMenuItem_actionPerformed(null);
2115 public void notifyWorker(AlignCalcWorkerI worker, String status)
2117 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()