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.AlignCalcWorkerI;
24 import jalview.api.AlignViewportI;
25 import jalview.api.JalviewApp;
26 import jalview.api.StructureSelectionManagerProvider;
27 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.HiddenColumns;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
33 import jalview.ext.so.SequenceOntology;
34 import jalview.gui.AlignFrame;
35 import jalview.gui.AlignViewport;
36 import jalview.gui.AlignmentPanel;
37 import jalview.gui.CalculationChooser;
38 import jalview.gui.Desktop;
39 import jalview.gui.Preferences;
40 import jalview.gui.PromptUserConfig;
41 import jalview.gui.StructureViewer;
42 import jalview.io.AppletFormatAdapter;
43 import jalview.io.BioJsHTMLOutput;
44 import jalview.io.DataSourceType;
45 import jalview.io.FileFormat;
46 import jalview.io.FileFormatException;
47 import jalview.io.FileFormatI;
48 import jalview.io.FileFormats;
49 import jalview.io.FileLoader;
50 import jalview.io.HtmlSvgOutput;
51 import jalview.io.IdentifyFile;
52 import jalview.io.NewickFile;
53 import jalview.io.gff.SequenceOntologyFactory;
54 import jalview.javascript.JSFunctionExec;
55 import jalview.javascript.MouseOverStructureListener;
56 import jalview.renderer.seqfeatures.FeatureRenderer;
57 import jalview.schemes.ColourSchemeI;
58 import jalview.schemes.ColourSchemeProperty;
59 import jalview.structure.SelectionSource;
60 import jalview.structure.VamsasSource;
61 import jalview.util.MessageManager;
62 import jalview.util.Platform;
63 import jalview.ws.jws2.Jws2Discoverer;
65 import java.applet.AppletContext;
66 import java.io.BufferedReader;
68 import java.io.FileOutputStream;
69 import java.io.IOException;
70 import java.io.InputStreamReader;
71 import java.io.OutputStreamWriter;
72 import java.io.PrintWriter;
73 import java.net.MalformedURLException;
75 import java.net.URISyntaxException;
77 import java.security.AllPermission;
78 import java.security.CodeSource;
79 import java.security.PermissionCollection;
80 import java.security.Permissions;
81 import java.security.Policy;
82 import java.util.HashMap;
83 import java.util.Hashtable;
85 import java.util.Vector;
87 import javax.swing.LookAndFeel;
88 import javax.swing.UIManager;
90 import groovy.lang.Binding;
91 import groovy.util.GroovyScriptEngine;
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 public static boolean isHeadlessMode()
147 return getInstance().headless;
150 private Desktop desktop;
152 private AlignFrame currentAlignFrame;
154 public boolean isJavaAppletTag;
156 public String appletResourcePath;
158 JalviewAppLoader appLoader;
160 protected JSFunctionExec jsFunctionExec;
162 private boolean noCalculation, noMenuBar, noStatus;
164 private boolean noAnnotation;
166 public boolean getStartCalculations()
168 return !noCalculation;
171 public boolean getAllowMenuBar()
176 public boolean getShowStatus()
181 public boolean getShowAnnotation()
183 return !noAnnotation;
186 public static AlignFrame getCurrentAlignFrame()
188 return getInstance().currentAlignFrame;
191 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
193 getInstance().currentAlignFrame = currentAlignFrame;
198 if (!Platform.isJS())
205 // grab all the rights we can for the JVM
206 Policy.setPolicy(new Policy()
209 public PermissionCollection getPermissions(CodeSource codesource)
211 Permissions perms = new Permissions();
212 perms.add(new AllPermission());
217 public void refresh()
225 * keep track of feature fetching tasks.
233 * TODO: generalise to track all jalview events to orchestrate batch
237 private int queued = 0;
239 private int running = 0;
241 public FeatureFetcher()
246 public void addFetcher(final AlignFrame af,
247 final Vector<String> dasSources)
249 final long id = System.currentTimeMillis();
251 final FeatureFetcher us = this;
252 new Thread(new Runnable()
264 af.setProgressBar(MessageManager
265 .getString("status.das_features_being_retrived"), id);
266 af.featureSettings_actionPerformed(null);
267 af.setProgressBar(null, id);
276 public synchronized boolean allFinished()
278 return queued == 0 && running == 0;
284 * main class for Jalview application
287 * open <em>filename</em>
289 @SuppressWarnings("unused")
290 public static void main(String[] args)
294 Platform.startJavaLogging();
296 getInstance().doMain(args);
300 @SuppressWarnings("unused")
304 void doMain(String[] args)
307 boolean isJS = Platform.isJS();
310 Platform.setAppClass(this);
314 System.setSecurityManager(null);
318 .println("Java version: " + System.getProperty("java.version"));
319 System.out.println(System.getProperty("os.arch") + " "
320 + System.getProperty("os.name") + " "
321 + System.getProperty("os.version"));
323 ArgsParser aparser = new ArgsParser(args);
325 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
326 Cache.loadProperties(usrPropsFile);
328 if (aparser.contains(ArgsParser.NODISPLAY)
329 || aparser.contains(ArgsParser.NOGUI)
330 || aparser.contains(ArgsParser.HEADLESS)
331 || "true".equals(System.getProperty("java.awt.headless")))
338 isJavaAppletTag = aparser.isApplet();
341 Preferences.setAppletDefaults();
342 Cache.loadProperties(usrPropsFile); // again, because we
343 // might be changing defaults here?
346 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
347 appletResourcePath = aparser.getValue("Info.resourcePath");
356 if (usrPropsFile != null)
359 "CMD [-props " + usrPropsFile + "] executed successfully!");
362 if (aparser.contains("help") || aparser.contains("h"))
371 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
372 if (jabawsUrl != null)
376 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
378 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
379 } catch (MalformedURLException e)
382 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
387 // check for property setting
388 String defs = aparser.getValue(ArgsParser.SETPROP);
391 int p = defs.indexOf('=');
394 System.err.println("Ignoring invalid setprop argument : " + defs);
398 System.out.println("Executing setprop argument: " + defs);
401 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
404 defs = aparser.getValue(ArgsParser.SETPROP);
406 System.setProperty("http.agent",
407 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
411 } catch (NoClassDefFoundError error)
413 error.printStackTrace();
414 System.out.println("\nEssential logging libraries not found."
415 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
423 if (!isJS && Platform.isWin())
425 UIManager.setLookAndFeel(
426 headless ? "javax.swing.plaf.metal.MetalLookAndFeel"
427 : UIManager.getSystemLookAndFeelClassName());
428 // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
430 } catch (Exception ex)
432 System.err.println("Unexpected Look and Feel Exception");
433 ex.printStackTrace();
435 if (Platform.isAMacAndNotJS())
438 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
440 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
442 System.setProperty("apple.laf.useScreenMenuBar", "true");
443 if (lookAndFeel != null)
447 UIManager.setLookAndFeel(lookAndFeel);
448 } catch (Throwable e)
451 "Failed to set QuaQua look and feel: " + e.toString());
454 if (lookAndFeel == null
455 || !(lookAndFeel.getClass().isAssignableFrom(
456 UIManager.getLookAndFeel().getClass()))
457 || !UIManager.getLookAndFeel().getClass().toString()
458 .toLowerCase().contains("quaqua"))
463 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
464 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
465 } catch (Throwable e)
468 "Failed to reset look and feel: " + e.toString());
474 * configure 'full' SO model if preferences say to,
475 * else use the default (SO Lite)
477 // BH NOTE 2020.06.01 Jalview-JS/develop has this true for Java, false for
479 if (Cache.getDefault(Preferences.USE_FULL_SO, !isJS))
481 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
486 desktop = Desktop.getInstance();
487 desktop.setInBatchMode(true); // indicate we are starting up
488 desktop.setVisible(true);
497 desktop.startServiceDiscovery();
498 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
500 startUsageStats(desktop);
504 System.err.println("CMD [-nousagestats] executed successfully!");
507 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
509 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
512 // Start the desktop questionnaire prompter with the specified
514 Cache.log.debug("Starting questionnaire url at " + url);
515 desktop.checkForQuestionnaire(url);
516 System.out.println("CMD questionnaire[-" + url
517 + "] executed successfully!");
521 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
523 // Start the desktop questionnaire prompter with the specified
526 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
528 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
530 "Starting questionnaire with default url: " + defurl);
531 desktop.checkForQuestionnaire(defurl);
538 .println("CMD [-noquestionnaire] executed successfully!");
541 if (!aparser.contains(ArgsParser.NONEWS))
543 desktop.checkForNews();
546 BioJsHTMLOutput.updateBioJS();
550 parseArguments(aparser, true);
554 * Allow an outside entity to initiate the second half of argument parsing
558 * @return null is good
561 public Object parseArguments(String[] args)
566 ArgsParser aparser = new ArgsParser(args);
567 parseArguments(aparser, false);
569 } catch (Throwable t)
579 * @return null, indicating no error
581 private void parseArguments(ArgsParser aparser, boolean isStartup)
583 boolean isJS = Platform.isJS();
585 Desktop desktop = (headless ? null : Desktop.getInstance());
586 // script to execute after all loading is
587 // completed one way or another
588 // extract groovy argument and execute if necessary
589 String groovyscript = (isJS ? null
590 : aparser.getValue(ArgsParser.GROOVY, true));
591 String file = aparser.getValue(ArgsParser.OPEN, true);
592 // BH this here to allow split frame; not working as of 5/17/2019
593 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
594 String fileFormat = (isJavaAppletTag
595 ? aparser.getAppletValue("format", null)
597 FileFormatI format = null;
598 DataSourceType protocol = null;
600 if (file == null && desktop == null)
602 System.out.println("No files to open!");
605 // Finally, deal with the remaining input data.
607 if (file == null && isJavaAppletTag)
609 // Maybe the sequences are added as parameters
610 StringBuffer data = new StringBuffer("PASTE");
612 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
614 data.append(file.toString() + "\n");
617 if (data.length() > 5)
619 file = data.toString();
630 desktop.setProgressBar(
632 .getString("status.processing_commandline_args"),
633 progress = System.currentTimeMillis());
638 * ignore in JavaScript -- can't just check file existence - could load
644 if (!file.startsWith("http://") && !file.startsWith("https://"))
645 // BH 2019 added https check for Java
647 if (!(new File(file)).exists())
649 System.out.println("Can't find " + file);
658 protocol = AppletFormatAdapter.checkProtocol(file);
662 format = (isJavaAppletTag && fileFormat != null
663 ? FileFormats.getInstance().forName(fileFormat)
667 format = new IdentifyFile().identify(file, protocol);
669 } catch (FileFormatException e1)
674 if (aparser.contains(ArgsParser.NOMENUBAR))
677 System.out.println("CMD [nomenu] executed successfully!");
680 if (aparser.contains(ArgsParser.NOSTATUS))
683 System.out.println("CMD [nostatus] executed successfully!");
686 if (aparser.contains(ArgsParser.NOANNOTATION)
687 || aparser.contains(ArgsParser.NOANNOTATION2))
690 System.out.println("CMD no-annotation executed successfully!");
692 if (aparser.contains(ArgsParser.NOCALCULATION))
694 noCalculation = true;
695 System.out.println("CMD [nocalculation] executed successfully!");
698 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
702 System.out.println("error");
707 .println("CMD [-open " + file + "] executed successfully!");
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 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!");
772 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
775 af.loadJalviewDataFile(data, null, null, null);
776 // System.out.println("Added " + data);
778 "CMD [-annotations " + data + "] executed successfully!");
781 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
783 af.overviewMenuItem_actionPerformed(null);
784 System.out.println("CMD [showoverview] executed successfully!");
787 // set or clear the sortbytree flag.
788 if (aparser.contains(ArgsParser.SORTBYTREE))
790 af.getViewport().setSortByTree(true);
791 if (af.getViewport().getSortByTree())
793 System.out.println("CMD [-sortbytree] executed successfully!");
797 boolean doUpdateAnnotation = false;
800 * we do this earlier in JalviewJS because of a complication with
803 * For now, just fixing this in JalviewJS.
812 af.getViewport().setShowAnnotation(false);
813 if (!af.getViewport().isShowAnnotation())
815 doUpdateAnnotation = true;
817 .println("CMD no-annotation executed successfully!");
821 if (aparser.contains(ArgsParser.NOSORTBYTREE))
823 af.getViewport().setSortByTree(false);
824 if (!af.getViewport().getSortByTree())
826 doUpdateAnnotation = true;
828 .println("CMD [-nosortbytree] executed successfully!");
831 if (doUpdateAnnotation)
833 af.setMenusForViewport();
834 af.alignPanel.updateLayout();
836 data = aparser.getValue(ArgsParser.TREE, true);
842 "CMD [-tree " + data + "] executed successfully!");
843 NewickFile nf = new NewickFile(data,
844 AppletFormatAdapter.checkProtocol(data));
846 .setCurrentTree(af.showNewickTree(nf, data).getTree());
847 } catch (IOException ex)
849 System.err.println("Couldn't add tree " + data);
850 ex.printStackTrace(System.err);
853 // TODO - load PDB structure(s) to alignment JAL-629
854 // (associate with identical sequence in alignment, or a specified
858 loadAppletParams(aparser, af);
867 if (groovyscript != null)
869 // Execute the groovy script after we've done all the rendering
871 // and before any images or figures are generated.
872 System.out.println("Executing script " + groovyscript);
873 executeGroovyScript(groovyscript, af);
874 System.out.println("CMD groovy[" + groovyscript
875 + "] executed successfully!");
879 createOutputFiles(aparser, af, format);
880 while (aparser.getSize() > 0)
882 System.out.println("Unknown arg: " + aparser.nextValue());
887 AlignFrame startUpAlframe = null;
888 // We'll only open the default file if the desktop is visible.
890 // ////////////////////
892 if (!isJS && !headless && file == null
893 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
900 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
901 jalview.bin.Cache.getDefault("www.jalview.org",
902 "http://www.jalview.org")
903 + "/examples/exampleFile_2_7.jar");
905 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
907 // hardwire upgrade of the startup file
908 file.replace("_2_3.jar", "_2_7.jar");
909 // and remove the stale setting
910 jalview.bin.Cache.removeProperty("STARTUP_FILE");
913 protocol = DataSourceType.FILE;
915 if (file.indexOf("http:") > -1)
917 protocol = DataSourceType.URL;
920 if (file.endsWith(".jar"))
922 format = FileFormat.Jalview;
928 format = new IdentifyFile().identify(file, protocol);
929 } catch (FileFormatException e)
935 startUpAlframe = new FileLoader(!headless)
936 .loadFileWaitTillLoaded(file, protocol, format);
937 // extract groovy arguments before anything else.
940 // Once all other stuff is done, execute any groovy scripts (in order)
941 if (groovyscript != null)
943 if (Cache.groovyJarsPresent())
945 System.out.println("Executing script " + groovyscript);
946 executeGroovyScript(groovyscript, startUpAlframe);
951 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
955 // and finally, turn off batch mode indicator - if the desktop still exists
960 desktop.setProgressBar(null, progress);
962 desktop.setInBatchMode(false);
968 * Writes an output file for each format (if any) specified in the
969 * command-line arguments. Supported formats are currently
978 * A format parameter should be followed by a parameter specifying the output
979 * file name. {@code imgMap} parameters should follow those for the
980 * corresponding alignment image output.
986 private void createOutputFiles(ArgsParser aparser, AlignFrame af,
989 String imageName = "unnamed.png";
990 while (aparser.getSize() > 1)
992 String outputFormat = aparser.nextValue();
993 String file = aparser.nextValue();
994 // System.out.println("format " + outputFormat);
996 if (outputFormat.equalsIgnoreCase("png"))
998 af.createPNG(new File(file));
999 imageName = (new File(file)).getName();
1000 System.out.println("Creating PNG image: " + file);
1003 else if (outputFormat.equalsIgnoreCase("svg"))
1005 File imageFile = new File(file);
1006 imageName = imageFile.getName();
1007 af.createSVG(imageFile);
1008 System.out.println("Creating SVG image: " + file);
1011 else if (outputFormat.equalsIgnoreCase("html"))
1013 File imageFile = new File(file);
1014 imageName = imageFile.getName();
1015 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1016 htmlSVG.exportHTML(file);
1017 System.out.println("Creating HTML image: " + file);
1020 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1024 System.err.println("The output html file must not be null");
1029 BioJsHTMLOutput.refreshVersionInfo(
1030 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1031 } catch (URISyntaxException e)
1033 e.printStackTrace();
1035 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1036 bjs.exportHTML(file);
1037 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1040 else if (outputFormat.equalsIgnoreCase("imgMap"))
1042 af.createImageMap(new File(file), imageName);
1043 System.out.println("Creating image map: " + file);
1046 else if (outputFormat.equalsIgnoreCase("eps"))
1048 File outputFile = new File(file);
1050 "Creating EPS file: " + outputFile.getAbsolutePath());
1051 af.createEPS(outputFile);
1055 af.saveAlignment(file, format);
1056 if (af.isSaveAlignmentSuccessful())
1059 "Written alignment in " + format + " format to " + file);
1063 System.out.println("Error writing file " + file + " in " + format
1070 private static void showUsage()
1073 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1074 + "-nodisplay\tRun Jalview without User Interface.\n"
1075 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1076 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1077 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1078 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1079 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1080 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1081 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1082 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1083 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1084 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1085 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1086 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1087 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1088 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1089 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1090 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1091 + "-html FILE\tCreate HTML file from alignment.\n"
1092 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1093 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1094 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1095 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1096 + "-noquestionnaire\tTurn off questionnaire check.\n"
1097 + "-nonews\tTurn off check for Jalview news.\n"
1098 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1099 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1101 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1102 // after all other properties files have been read\n\t
1103 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1104 // passed in correctly)"
1105 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1106 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1108 // "-vdoc vamsas-document\tImport vamsas document into new
1109 // session or join existing session with same URN\n"
1110 // + "-vses vamsas-session\tJoin session with given URN\n"
1111 + "-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"
1112 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1115 private static void startUsageStats(final Desktop desktop)
1118 * start a User Config prompt asking if we can log usage statistics.
1120 PromptUserConfig prompter = new PromptUserConfig(
1121 Desktop.getDesktopPane(), "USAGESTATS",
1122 "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, 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 AlignFrame[] getAlignFrames()
1267 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1268 : Desktop.getAlignFrames();
1273 * Quit method delegates to Desktop.quit - unless running in headless mode
1274 * when it just ends the JVM
1278 if (jsFunctionExec != null)
1280 jsFunctionExec.tidyUp();
1281 jsFunctionExec = null;
1284 if (desktop != null)
1295 * Get the SwingJS applet ID and combine that with the frameType
1298 * "alignment", "desktop", etc., or null
1301 public static String getAppID(String frameType)
1303 String id = Cache.getProperty("Info.j2sAppletID");
1308 return id + (frameType == null ? "" : "-" + frameType);
1312 * Handle all JalviewLite applet parameters
1317 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1319 JalviewApp app = new JalviewApp()
1324 // These are methods that are in JalviewLite that various classes call
1325 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1327 // them to JalviewLite directly. Some may not be necessary, but they have
1329 // be at least mentioned here, or the classes calling them should
1331 // JalviewLite itself.
1333 private boolean alignPDBStructures; // From JalviewLite; not implemented
1335 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1337 private Hashtable<String, int[]> jshashes;
1340 public String getParameter(String name)
1342 return aparser.getAppletValue(name, null);
1346 public boolean getDefaultParameter(String name, boolean def)
1349 return ((stn = getParameter(name)) == null ? def
1350 : "true".equalsIgnoreCase(stn));
1354 * Get the applet-like document base even though this is an application.
1357 public URL getDocumentBase()
1359 return Platform.getDocumentBase();
1363 * Get the applet-like code base even though this is an application.
1366 public URL getCodeBase()
1368 return Platform.getCodeBase();
1372 public AlignViewportI getViewport()
1374 return af.getViewport();
1382 public boolean parseFeaturesFile(String filename,
1383 DataSourceType protocol)
1385 return af.parseFeaturesFile(filename, protocol);
1393 public boolean loadScoreFile(String sScoreFile) throws IOException
1395 af.loadJalviewDataFile(sScoreFile, null, null, null);
1400 * annotations, jpredfile, jnetfile
1404 public void updateForAnnotations()
1406 af.updateForAnnotations();
1410 public void loadTree(NewickFile fin, String treeFile)
1413 // n/a -- already done by standard Jalview command line processing
1417 public void setAlignPdbStructures(boolean defaultParameter)
1419 alignPDBStructures = true;
1423 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1424 String[] chains, DataSourceType protocol)
1426 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1430 public void setFeatureGroupState(String[] groups, boolean state)
1432 af.setFeatureGroupState(groups, state);
1436 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1437 String[][] chains, String[] protocols)
1440 "Jalview applet interface alignedStructureView not implemented");
1444 public void newFeatureSettings()
1447 "Jalview applet interface newFeatureSettings not implemented");
1450 private Vector<Runnable> jsExecQueue;
1453 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1455 jsFunctionExec = exec;
1456 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1461 public AppletContext getAppletContext()
1463 // TODO Auto-generated method stub
1468 public boolean isJsfallbackEnabled()
1470 // TODO Auto-generated method stub
1475 public JSObject getJSObject()
1477 // TODO Auto-generated method stub
1482 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1484 // TODO Q: what exactly is this? BH
1489 public void updateColoursFromMouseOver(Object source,
1490 MouseOverStructureListener mouseOverStructureListener)
1492 // TODO Auto-generated method stub
1497 public Object[] getSelectionForListener(SequenceGroup seqsel,
1498 ColumnSelection colsel, HiddenColumns hidden,
1499 SelectionSource source, Object alignFrame)
1501 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1502 seqsel, colsel, hidden, source, alignFrame);
1506 public String arrayToSeparatorList(String[] array)
1508 return appLoader.arrayToSeparatorList(array);
1512 public Hashtable<String, int[]> getJSHashes()
1514 return (jshashes == null ? (jshashes = new Hashtable<>())
1519 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1521 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1526 public Object getFrameForSource(VamsasSource source)
1531 if (source instanceof jalview.gui.AlignViewport
1532 && source == (af = getCurrentAlignFrame()).getViewport())
1534 // should be valid if it just generated an event!
1537 // TODO: ensure that if '_af' is specified along with a handler
1538 // function, then only events from that alignFrame are sent to that
1545 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1547 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1552 appLoader = new JalviewAppLoader(true);
1553 appLoader.load(app);
1558 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1561 public String getSelectedSequences()
1563 return getSelectedSequencesFrom(getCurrentAlignFrame());
1568 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1571 public String getSelectedSequences(String sep)
1573 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1578 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1582 public String getSelectedSequencesFrom(AlignFrame alf)
1586 alf = getCurrentAlignFrame();
1588 return getSelectedSequencesFrom(alf, null);
1593 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1594 * .AlignFrame, java.lang.String)
1597 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
1601 alf = getCurrentAlignFrame();
1603 return appLoader.getSelectedSequencesFrom(alf, sep);
1608 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1609 * .AlignFrame, java.lang.String)
1612 public void highlight(String sequenceId, String position,
1613 String alignedPosition)
1615 highlightIn(null, sequenceId, position,
1620 public void highlightIn(AlignFrame alf, String sequenceId,
1621 String position, String alignedPosition)
1625 alf = getCurrentAlignFrame();
1627 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1631 public void select(String sequenceIds, String columns)
1633 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1637 public void select(String sequenceIds, String columns, String sep)
1639 selectIn(null, sequenceIds, columns, sep);
1643 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
1645 selectIn(alf, sequenceIds, columns, null);
1649 public void selectIn(AlignFrame alf, String sequenceIds, String columns,
1654 alf = getCurrentAlignFrame();
1656 appLoader.selectIn(alf, sequenceIds, columns, sep);
1660 public String getSelectedSequencesAsAlignment(String format,
1663 return getSelectedSequencesAsAlignmentFrom(null,
1668 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
1669 String format, String sep)
1673 alf = getCurrentAlignFrame();
1675 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1679 public String getAlignmentOrder()
1681 return getAlignmentFrom(getCurrentAlignFrame(), null);
1685 public String getAlignmentOrderFrom(AlignFrame alf)
1687 return getAlignmentFrom(alf, null);
1691 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
1695 alf = getCurrentAlignFrame();
1697 return appLoader.getAlignmentOrderFrom(alf, sep);
1701 public String orderBy(String order, String undoName)
1703 return orderBy(order, undoName, null);
1707 public String orderBy(String order, String undoName, String sep)
1709 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1713 public String orderAlignmentBy(AlignFrame alf, String order,
1714 String undoName, String sep)
1718 alf = getCurrentAlignFrame();
1720 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1724 public String getAlignment(String format)
1726 return getAlignmentFrom(null, format, null);
1730 public String getAlignmentFrom(AlignFrame alf, String format)
1732 return getAlignmentFrom(alf, format, null);
1736 public String getAlignment(String format, String suffix)
1738 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1742 public String getAlignmentFrom(AlignFrame alf, String format,
1745 return appLoader.getAlignmentFrom(alf, format, suffix);
1749 public void loadAnnotation(String annotation)
1751 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1755 public void loadAnnotationFrom(AlignFrame alf, String annotation)
1759 alf = getCurrentAlignFrame();
1761 appLoader.loadAnnotationFrom(alf, annotation);
1765 public void loadFeatures(String features, boolean autoenabledisplay)
1767 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1771 public boolean loadFeaturesFrom(AlignFrame alf, String features,
1772 boolean autoenabledisplay)
1776 alf = getCurrentAlignFrame();
1778 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1782 public String getFeatures(String format)
1784 return getFeaturesFrom(null, format);
1788 public String getFeaturesFrom(AlignFrame alf, String format)
1792 alf = getCurrentAlignFrame();
1794 return appLoader.getFeaturesFrom(alf, format);
1798 public String getAnnotation()
1800 return getAnnotationFrom(null);
1804 public String getAnnotationFrom(AlignFrame alf)
1808 alf = getCurrentAlignFrame();
1810 return appLoader.getAnnotationFrom(alf);
1814 // public AlignFrame newView()
1816 // return newViewFrom(null, null);
1820 // public AlignFrame newView(String name)
1822 // return newViewFrom(null, name);
1826 // public AlignFrame newViewFrom(AlignFrame alf)
1828 // return newViewFrom(alf, null);
1832 // public AlignFrame newViewFrom(AlignFrame alf, String name)
1836 // alf = getCurrentAlignFrame();
1838 // return appLoader.newViewFrom(alf, name);
1842 public AlignFrame loadAlignment(String text, String title)
1844 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1845 AlignFrame.DEFAULT_HEIGHT, title);
1849 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
1850 String pdbEntryString, String pdbFile)
1852 if (alFrame == null)
1854 alFrame = getCurrentAlignFrame();
1856 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1861 public void scrollViewToIn(AlignFrame alf, String topRow,
1862 String leftHandColumn)
1866 alf = getCurrentAlignFrame();
1868 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1872 public void scrollViewToRowIn(AlignFrame alf, String topRow)
1876 alf = getCurrentAlignFrame();
1878 appLoader.scrollViewToRowIn(alf, topRow);
1882 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
1886 alf = getCurrentAlignFrame();
1888 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1892 public String getFeatureGroups()
1894 return getFeatureGroupsOn(null);
1898 public String getFeatureGroupsOn(AlignFrame alf)
1902 alf = getCurrentAlignFrame();
1904 return appLoader.getFeatureGroupsOn(alf);
1908 public String getFeatureGroupsOfState(boolean visible)
1910 return getFeatureGroupsOfStateOn(null, visible);
1914 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
1918 alf = getCurrentAlignFrame();
1920 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1924 public void setFeatureGroupState(String groups, boolean state)
1925 { // JalviewLite API
1926 setFeatureGroupStateOn(null, groups, state);
1930 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
1935 alf = getCurrentAlignFrame();
1937 appLoader.setFeatureGroupStateOn(alf, groups, state);
1941 public String getSeparator()
1943 return appLoader.getSeparator();
1947 public void setSeparator(String separator)
1949 appLoader.setSeparator(separator);
1953 public String getJsMessage(String messageclass, String viewId)
1955 // see http://www.jalview.org/examples/jalviewLiteJs.html
1960 * Open a new Tree panel on the desktop statically. Params are standard (not
1961 * set by Groovy). No dialog is opened.
1966 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1967 * of sequences selected is inappropriate
1970 public Object openTreePanel(AlignFrame af, String treeType,
1975 af = getCurrentAlignFrame();
1977 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
1981 * public static method for JalviewJS API to open a PCAPanel without
1982 * necessarily using a dialog.
1986 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
1987 * if number of sequences selected is inappropriate
1990 public Object openPcaPanel(AlignFrame af, String modelName)
1994 af = getCurrentAlignFrame();
1996 return CalculationChooser.openPcaPanel(af, modelName, null);
2000 public String getSelectedSequencesAsAlignment(String format,
2003 return getSelectedSequencesAsAlignmentFrom(null,
2008 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
2009 String format, boolean suffix)
2013 alf = getCurrentAlignFrame();
2015 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
2020 public String arrayToSeparatorList(String[] array)
2022 return appLoader.arrayToSeparatorList(array);
2026 public String[] separatorListToArray(String list)
2028 return appLoader.separatorListToArray(list);
2031 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
2032 //// have a direct connection?
2035 public void setMouseoverListener(String listener)
2037 // TODO Auto-generated method stub
2042 public void setMouseoverListener(AlignFrame af, String listener)
2044 // TODO Auto-generated method stub
2049 public void setSelectionListener(String listener)
2051 // TODO Auto-generated method stub
2056 public void setSelectionListener(AlignFrame af, String listener)
2058 // TODO Auto-generated method stub
2063 public void setStructureListener(String listener, String modelSet)
2065 // TODO Auto-generated method stub
2070 public void removeJavascriptListener(AlignFrame af, String listener)
2072 // TODO Auto-generated method stub
2077 public void mouseOverStructure(String pdbResNum, String chain,
2080 // TODO Auto-generated method stub
2085 public void showOverview()
2087 currentAlignFrame.overviewMenuItem_actionPerformed(null);
2090 public void notifyWorker(AlignCalcWorkerI worker, String status)
2092 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
2096 private static boolean isInteractive = true;
2098 public static boolean isInteractive()
2100 return isInteractive;
2103 public static void setInteractive(boolean tf)