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.AlignFrameI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.JalviewApp;
27 import jalview.api.StructureSelectionManagerProvider;
28 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.HiddenColumns;
31 import jalview.datamodel.PDBEntry;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.ext.so.SequenceOntology;
35 import jalview.gui.AlignFrame;
36 import jalview.gui.AlignViewport;
37 import jalview.gui.AlignmentPanel;
38 import jalview.gui.CalculationChooser;
39 import jalview.gui.Desktop;
40 import jalview.gui.Preferences;
41 import jalview.gui.PromptUserConfig;
42 import jalview.gui.StructureViewer;
43 import jalview.io.AppletFormatAdapter;
44 import jalview.io.BioJsHTMLOutput;
45 import jalview.io.DataSourceType;
46 import jalview.io.FileFormat;
47 import jalview.io.FileFormatException;
48 import jalview.io.FileFormatI;
49 import jalview.io.FileFormats;
50 import jalview.io.FileLoader;
51 import jalview.io.HtmlSvgOutput;
52 import jalview.io.IdentifyFile;
53 import jalview.io.NewickFile;
54 import jalview.io.gff.SequenceOntologyFactory;
55 import jalview.javascript.JSFunctionExec;
56 import jalview.javascript.MouseOverStructureListener;
57 import jalview.renderer.seqfeatures.FeatureRenderer;
58 import jalview.schemes.ColourSchemeI;
59 import jalview.schemes.ColourSchemeProperty;
60 import jalview.structure.SelectionSource;
61 import jalview.structure.VamsasSource;
62 import jalview.util.MessageManager;
63 import jalview.util.Platform;
64 import jalview.ws.jws2.Jws2Discoverer;
66 import java.applet.AppletContext;
67 import java.io.BufferedReader;
69 import java.io.FileOutputStream;
70 import java.io.IOException;
71 import java.io.InputStreamReader;
72 import java.io.OutputStreamWriter;
73 import java.io.PrintWriter;
74 import java.net.MalformedURLException;
76 import java.net.URISyntaxException;
78 import java.security.AllPermission;
79 import java.security.CodeSource;
80 import java.security.PermissionCollection;
81 import java.security.Permissions;
82 import java.security.Policy;
83 import java.util.HashMap;
84 import java.util.Hashtable;
86 import java.util.Vector;
88 import javax.swing.LookAndFeel;
89 import javax.swing.SwingUtilities;
90 import javax.swing.UIManager;
92 import groovy.lang.Binding;
93 import groovy.util.GroovyScriptEngine;
94 import netscape.javascript.JSObject;
97 * Main class for Jalview Application <br>
99 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
100 * jalview.bin.Jalview
102 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
103 * jalview.bin.Jalview jalview.bin.Jalview
105 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
106 * embellish '*' to e.g. '*.jar')
109 * @version $Revision$
111 public class Jalview implements ApplicationSingletonI, JalviewJSApi
114 public static Jalview getInstance()
116 return (Jalview) ApplicationSingletonProvider
117 .getInstance(Jalview.class);
126 Platform.getURLCommandArguments();
129 private boolean headless;
131 public static boolean isHeadlessMode()
133 return getInstance().headless;
136 private Desktop desktop;
138 private AlignFrame currentAlignFrame;
140 public boolean isJavaAppletTag;
142 public String appletResourcePath;
144 JalviewAppLoader appLoader;
146 protected JSFunctionExec jsFunctionExec;
148 private boolean noCalculation, noMenuBar, noStatus;
150 private boolean noAnnotation;
152 public static final String TERMINATOR_LINE = "Jalview argument parsing complete.";
154 public boolean getStartCalculations()
156 return !noCalculation;
159 public boolean getAllowMenuBar()
164 public boolean getShowStatus()
169 public boolean getShowAnnotation()
171 return !noAnnotation;
174 public static AlignFrame getCurrentAlignFrame()
176 return getInstance().currentAlignFrame;
179 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
181 getInstance().currentAlignFrame = currentAlignFrame;
186 if (!Platform.isJS())
193 // grab all the rights we can for the JVM
194 Policy.setPolicy(new Policy()
197 public PermissionCollection getPermissions(CodeSource codesource)
199 Permissions perms = new Permissions();
200 perms.add(new AllPermission());
205 public void refresh()
213 * keep track of feature fetching tasks.
221 * TODO: generalise to track all jalview events to orchestrate batch
225 private int queued = 0;
227 private int running = 0;
229 public FeatureFetcher()
234 public void addFetcher(final AlignFrame af,
235 final Vector<String> dasSources)
237 final long id = System.currentTimeMillis();
239 final FeatureFetcher us = this;
240 new Thread(new Runnable()
252 af.setProgressBar(MessageManager
253 .getString("status.das_features_being_retrived"), id);
254 af.featureSettings_actionPerformed(null);
255 af.setProgressBar(null, id);
264 public synchronized boolean allFinished()
266 return queued == 0 && running == 0;
272 * main class for Jalview application
275 * open <em>filename</em>
277 public static void main(String[] args)
279 // Platform.startJavaLogging();
280 getInstance().doMain(args);
284 @SuppressWarnings("unused")
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(System.getProperty("os.arch") + " "
304 + System.getProperty("os.name") + " "
305 + System.getProperty("os.version"));
307 ArgsParser aparser = new ArgsParser(args);
309 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
310 Cache.loadProperties(usrPropsFile);
312 if (aparser.contains(ArgsParser.NODISPLAY)
313 || aparser.contains(ArgsParser.NOGUI)
314 || aparser.contains(ArgsParser.HEADLESS)
315 || "true".equals(System.getProperty("java.awt.headless")))
318 setSynchronous(true);
323 isJavaAppletTag = aparser.isApplet();
326 Preferences.setAppletDefaults();
327 Cache.loadProperties(usrPropsFile); // again, because we
328 // might be changing defaults here?
331 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
332 appletResourcePath = aparser.getValue("Info.resourcePath");
341 if (usrPropsFile != null)
344 "CMD [-props " + usrPropsFile + "] executed successfully!");
347 if (aparser.contains("help") || aparser.contains("h"))
355 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
356 if (jabawsUrl != null)
360 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
362 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
363 } catch (MalformedURLException e)
366 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
371 // check for property setting
372 String defs = aparser.getValue(ArgsParser.SETPROP);
375 int p = defs.indexOf('=');
378 System.err.println("Ignoring invalid setprop argument : " + defs);
382 System.out.println("Executing setprop argument: " + defs);
385 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
388 defs = aparser.getValue(ArgsParser.SETPROP);
390 System.setProperty("http.agent",
391 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
395 } catch (NoClassDefFoundError error)
397 error.printStackTrace();
398 System.out.println("\nEssential logging libraries not found."
399 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
407 if (!isJS && Platform.isWin())
409 UIManager.setLookAndFeel(
410 headless ? "javax.swing.plaf.metal.MetalLookAndFeel"
411 : UIManager.getSystemLookAndFeelClassName());
412 // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
414 } catch (Exception ex)
416 System.err.println("Unexpected Look and Feel Exception");
417 ex.printStackTrace();
419 if (Platform.isAMacAndNotJS())
422 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
424 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
426 System.setProperty("apple.laf.useScreenMenuBar", "true");
427 if (lookAndFeel != null)
431 UIManager.setLookAndFeel(lookAndFeel);
432 } catch (Throwable e)
435 "Failed to set QuaQua look and feel: " + e.toString());
438 if (lookAndFeel == null
439 || !(lookAndFeel.getClass().isAssignableFrom(
440 UIManager.getLookAndFeel().getClass()))
441 || !UIManager.getLookAndFeel().getClass().toString()
442 .toLowerCase().contains("quaqua"))
447 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
448 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
449 } catch (Throwable e)
452 "Failed to reset look and feel: " + e.toString());
458 * configure 'full' SO model if preferences say to,
459 * else use the default (SO Lite)
461 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
463 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
468 // If this is not tested, then
470 if (aparser.contains(ArgsParser.NOUSAGESTATS))
472 System.err.println("CMD [-nousagestats] executed successfully!");
474 if (aparser.contains(ArgsParser.NOQUESTIONNAIRE))
476 System.err.println("CMD [-noquestionnaire] executed successfully!");
482 desktop = Desktop.getInstance();
483 desktop.setInBatchMode(true); // indicate we are starting up
484 desktop.setVisible(true);
493 desktop.startServiceDiscovery();
494 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
496 startUsageStats(desktop);
500 System.err.println("CMD [-nousagestats] executed successfully!");
503 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
505 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
508 // Start the desktop questionnaire prompter with the specified
510 Cache.log.debug("Starting questionnaire url at " + url);
511 desktop.checkForQuestionnaire(url);
512 System.out.println("CMD questionnaire[-" + url
513 + "] executed successfully!");
517 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
519 // Start the desktop questionnaire prompter with the specified
522 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
524 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
526 "Starting questionnaire with default url: " + defurl);
527 desktop.checkForQuestionnaire(defurl);
534 .println("CMD [-noquestionnaire] executed successfully!");
537 if (!aparser.contains(ArgsParser.NONEWS))
539 desktop.checkForNews();
542 BioJsHTMLOutput.updateBioJS();
546 parseArguments(aparser, true);
547 System.err.println(TERMINATOR_LINE);
551 * Allow an outside entity to initiate the second half of argument parsing
555 * @return null is good
558 public Object parseArguments(String[] args)
563 ArgsParser aparser = new ArgsParser(args);
564 return parseArguments(aparser, false);
565 } catch (Throwable t)
577 private Object parseArguments(ArgsParser aparser, boolean isStartup)
579 boolean isJS = Platform.isJS();
581 Desktop desktop = (headless ? null : Desktop.getInstance());
582 // script to execute after all loading is
583 // completed one way or another
584 // extract groovy argument and execute if necessary
585 String groovyscript = (isJS ? null
586 : aparser.getValue(ArgsParser.GROOVY, true));
587 String file = aparser.getValue(ArgsParser.OPEN, true);
588 // BH this here to allow split frame; not working as of 5/17/2019
589 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
590 String fileFormat = (isJavaAppletTag
591 ? aparser.getAppletValue("format", null)
593 FileFormatI format = null;
594 DataSourceType protocol = null;
596 if (file == null && desktop == null)
598 System.out.println("No files to open!");
601 boolean haveImport = false;// checkStartVamas(aparser);
602 // Finally, deal with the remaining input data.
604 if (file == null && isJavaAppletTag)
606 // Maybe the sequences are added as parameters
607 StringBuffer data = new StringBuffer("PASTE");
609 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
611 data.append(file.toString() + "\n");
614 if (data.length() > 5)
616 file = data.toString();
627 desktop.setProgressBar(
629 .getString("status.processing_commandline_args"),
630 progress = System.currentTimeMillis());
635 * ignore in JavaScript -- can't just check file existence - could load
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);
655 protocol = AppletFormatAdapter.checkProtocol(file);
659 format = (isJavaAppletTag && fileFormat != null
660 ? FileFormats.getInstance().forName(fileFormat)
664 format = new IdentifyFile().identify(file, protocol);
666 } catch (FileFormatException e1)
671 if (aparser.contains(ArgsParser.NOMENUBAR))
674 System.out.println("CMD [nomenu] executed successfully!");
677 if (aparser.contains(ArgsParser.NOSTATUS))
680 System.out.println("CMD [nostatus] executed successfully!");
683 if (aparser.contains(ArgsParser.NOANNOTATION)
684 || aparser.contains(ArgsParser.NOANNOTATION2))
687 System.out.println("CMD no-annotation executed successfully!");
689 if (aparser.contains(ArgsParser.NOCALCULATION))
691 noCalculation = true;
692 System.out.println("CMD [nocalculation] executed successfully!");
695 AlignFrame af = new FileLoader(!headless).LoadFileWaitTillLoaded(file,
699 System.out.println("error");
704 .println("CMD [-open " + file + "] executed successfully!");
707 protocol = AppletFormatAdapter.checkProtocol(file2);
710 format = new IdentifyFile().identify(file2, protocol);
711 } catch (FileFormatException e1)
715 AlignFrame af2 = new FileLoader(!headless)
716 .LoadFileWaitTillLoaded(file2, protocol, format);
719 System.out.println("error");
723 AlignViewport.openLinkedAlignmentAs(af,
724 af.getViewport().getAlignment(),
725 af2.getViewport().getAlignment(), "",
726 AlignViewport.SPLIT_FRAME);
728 "CMD [-open2 " + file2 + "] executed successfully!");
732 setCurrentAlignFrame(af);
734 // TODO: file2 How to implement file2 for the applet spit screen?
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.
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!");
822 if (aparser.contains(ArgsParser.NOSORTBYTREE))
824 af.getViewport().setSortByTree(false);
825 if (!af.getViewport().getSortByTree())
827 doUpdateAnnotation = true;
829 .println("CMD [-nosortbytree] executed successfully!");
832 if (doUpdateAnnotation)
834 af.setMenusForViewport();
835 af.alignPanel.updateLayout();
837 data = aparser.getValue(ArgsParser.TREE, true);
843 "CMD [-tree " + data + "] executed successfully!");
844 NewickFile nf = new NewickFile(data,
845 AppletFormatAdapter.checkProtocol(data));
847 .setCurrentTree(af.showNewickTree(nf, data).getTree());
848 } catch (IOException ex)
850 System.err.println("Couldn't add tree " + data);
851 ex.printStackTrace(System.err);
854 // TODO - load PDB structure(s) to alignment JAL-629
855 // (associate with identical sequence in alignment, or a specified
859 loadAppletParams(aparser, af);
868 if (groovyscript != null)
870 // Execute the groovy script after we've done all the rendering
872 // and before any images or figures are generated.
873 System.out.println("Executing script " + groovyscript);
874 executeGroovyScript(groovyscript, af);
875 System.out.println("CMD groovy[" + groovyscript
876 + "] executed successfully!");
880 createOutputFiles(aparser, af, format);
881 while (aparser.getSize() > 0)
883 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 && !haveImport
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);
969 * Writes an output file for each format (if any) specified in the
970 * command-line arguments. Supported formats are currently
979 * A format parameter should be followed by a parameter specifying the output
980 * file name. {@code imgMap} parameters should follow those for the
981 * corresponding alignment image output.
987 private void createOutputFiles(ArgsParser aparser, AlignFrame af,
990 String imageName = "unnamed.png";
991 while (aparser.getSize() > 1)
993 String outputFormat = aparser.nextValue();
994 String file = aparser.nextValue();
995 // System.out.println("format " + outputFormat);
997 if (outputFormat.equalsIgnoreCase("png"))
999 af.createPNG(new File(file));
1000 imageName = (new File(file)).getName();
1001 System.out.println("Creating PNG image: " + file);
1004 else if (outputFormat.equalsIgnoreCase("svg"))
1006 File imageFile = new File(file);
1007 imageName = imageFile.getName();
1008 af.createSVG(imageFile);
1009 System.out.println("Creating SVG image: " + file);
1012 else if (outputFormat.equalsIgnoreCase("html"))
1014 File imageFile = new File(file);
1015 imageName = imageFile.getName();
1016 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1017 htmlSVG.exportHTML(file);
1019 System.out.println("Creating HTML image: " + file);
1022 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1026 System.err.println("The output html file must not be null");
1031 BioJsHTMLOutput.refreshVersionInfo(
1032 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1033 } catch (URISyntaxException e)
1035 e.printStackTrace();
1037 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1038 bjs.exportHTML(file);
1039 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1042 else if (outputFormat.equalsIgnoreCase("imgMap"))
1044 af.createImageMap(new File(file), imageName);
1045 System.out.println("Creating image map: " + file);
1048 else if (outputFormat.equalsIgnoreCase("eps"))
1050 File outputFile = new File(file);
1052 "Creating EPS file: " + outputFile.getAbsolutePath());
1053 af.createEPS(outputFile);
1057 af.saveAlignment(file, format);
1058 if (af.isSaveAlignmentSuccessful())
1061 "Written alignment in " + format + " format to " + file);
1065 System.out.println("Error writing file " + file + " in " + format
1072 private static void showUsage()
1075 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1076 + "-nodisplay\tRun Jalview without User Interface.\n"
1077 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1078 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1079 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1080 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1081 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1082 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1083 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1084 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1085 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1086 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1087 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1088 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1089 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1090 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1091 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1092 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1093 + "-html FILE\tCreate HTML file from alignment.\n"
1094 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1095 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1096 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1097 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1098 + "-noquestionnaire\tTurn off questionnaire check.\n"
1099 + "-nonews\tTurn off check for Jalview news.\n"
1100 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1101 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1103 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1104 // after all other properties files have been read\n\t
1105 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1106 // passed in correctly)"
1107 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1108 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1110 // "-vdoc vamsas-document\tImport vamsas document into new
1111 // session or join existing session with same URN\n"
1112 // + "-vses vamsas-session\tJoin session with given URN\n"
1113 + "-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"
1114 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1117 private static void startUsageStats(final Desktop desktop)
1120 * start a User Config prompt asking if we can log usage statistics.
1122 PromptUserConfig prompter = new PromptUserConfig(
1123 Desktop.getDesktopPane(), "USAGESTATS",
1124 "Jalview Usage Statistics",
1125 "Do you want to help make Jalview better by enabling "
1126 + "the collection of usage statistics with Google Analytics ?"
1127 + "\n\n(you can enable or disable usage tracking in the preferences)",
1134 "Initialising googletracker for usage stats.");
1135 Cache.initGoogleTracker();
1136 Cache.log.debug("Tracking enabled.");
1143 Cache.log.debug("Not enabling Google Tracking.");
1146 desktop.addDialogThread(prompter);
1150 * Locate the given string as a file and pass it to the groovy interpreter.
1152 * @param groovyscript
1153 * the script to execute
1154 * @param jalviewContext
1155 * the Jalview Desktop object passed in to the groovy binding as the
1158 private void executeGroovyScript(String groovyscript, AlignFrame af)
1161 * for scripts contained in files
1168 if (groovyscript.trim().equals("STDIN"))
1170 // read from stdin into a tempfile and execute it
1173 tfile = File.createTempFile("jalview", "groovy");
1174 PrintWriter outfile = new PrintWriter(
1175 new OutputStreamWriter(new FileOutputStream(tfile)));
1176 BufferedReader br = new BufferedReader(
1177 new InputStreamReader(System.in));
1179 while ((line = br.readLine()) != null)
1181 outfile.write(line + "\n");
1187 } catch (Exception ex)
1189 System.err.println("Failed to read from STDIN into tempfile "
1190 + ((tfile == null) ? "(tempfile wasn't created)"
1191 : tfile.toString()));
1192 ex.printStackTrace();
1197 sfile = tfile.toURI().toURL();
1198 } catch (Exception x)
1201 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1203 x.printStackTrace();
1211 sfile = new URI(groovyscript).toURL();
1212 } catch (Exception x)
1214 tfile = new File(groovyscript);
1215 if (!tfile.exists())
1217 System.err.println("File '" + groovyscript + "' does not exist.");
1220 if (!tfile.canRead())
1222 System.err.println("File '" + groovyscript + "' cannot be read.");
1225 if (tfile.length() < 1)
1227 System.err.println("File '" + groovyscript + "' is empty.");
1232 sfile = tfile.getAbsoluteFile().toURI().toURL();
1233 } catch (Exception ex)
1235 System.err.println("Failed to create a file URL for "
1236 + tfile.getAbsoluteFile());
1243 Map<String, Object> vbinding = new HashMap<>();
1244 vbinding.put("Jalview", this);
1247 vbinding.put("currentAlFrame", af);
1249 Binding gbinding = new Binding(vbinding);
1250 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1251 gse.run(sfile.toString(), gbinding);
1252 if ("STDIN".equals(groovyscript))
1254 // delete temp file that we made -
1255 // only if it was successfully executed
1258 } catch (Exception e)
1260 System.err.println("Exception Whilst trying to execute file " + sfile
1261 + " as a groovy script.");
1262 e.printStackTrace(System.err);
1267 public AlignFrame[] getAlignFrames()
1269 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1270 : Desktop.getAlignFrames();
1275 * Quit method delegates to Desktop.quit - unless running in headless mode
1276 * when it just ends the JVM
1280 if (jsFunctionExec != null)
1282 jsFunctionExec.tidyUp();
1283 jsFunctionExec = null;
1286 if (desktop != null)
1297 * Handle all JalviewLite applet parameters
1302 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1304 JalviewApp app = new JalviewApp()
1309 // These are methods that are in JalviewLite that various classes call
1310 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1312 // them to JalviewLite directly. Some may not be necessary, but they have
1314 // be at least mentioned here, or the classes calling them should
1316 // JalviewLite itself.
1318 private boolean alignPDBStructures; // From JalviewLite; not implemented
1320 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1322 private Hashtable<String, int[]> jshashes;
1325 public String getParameter(String name)
1327 return aparser.getAppletValue(name, null);
1331 public boolean getDefaultParameter(String name, boolean def)
1334 return ((stn = getParameter(name)) == null ? def
1335 : "true".equalsIgnoreCase(stn));
1339 * Get the applet-like document base even though this is an application.
1342 public URL getDocumentBase()
1344 return Platform.getDocumentBase();
1348 * Get the applet-like code base even though this is an application.
1351 public URL getCodeBase()
1353 return Platform.getCodeBase();
1357 public AlignViewportI getViewport()
1359 return af.getViewport();
1367 public boolean parseFeaturesFile(String filename,
1368 DataSourceType protocol)
1370 return af.parseFeaturesFile(filename, protocol);
1378 public boolean loadScoreFile(String sScoreFile) throws IOException
1380 af.loadJalviewDataFile(sScoreFile, null, null, null);
1385 * annotations, jpredfile, jnetfile
1389 public void updateForAnnotations()
1391 af.updateForAnnotations();
1395 public void loadTree(NewickFile fin, String treeFile)
1398 // n/a -- already done by standard Jalview command line processing
1402 public void setAlignPdbStructures(boolean defaultParameter)
1404 alignPDBStructures = true;
1408 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1409 String[] chains, DataSourceType protocol)
1411 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1415 public void setFeatureGroupState(String[] groups, boolean state)
1417 af.setFeatureGroupState(groups, state);
1421 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1422 String[][] chains, String[] protocols)
1425 "Jalview applet interface alignedStructureView not implemented");
1429 public void newFeatureSettings()
1432 "Jalview applet interface newFeatureSettings not implemented");
1435 private Vector<Runnable> jsExecQueue;
1438 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1440 jsFunctionExec = exec;
1441 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1446 public AppletContext getAppletContext()
1448 // TODO Auto-generated method stub
1453 public boolean isJsfallbackEnabled()
1455 // TODO Auto-generated method stub
1460 public JSObject getJSObject()
1462 // TODO Auto-generated method stub
1467 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1469 // TODO Q: what exactly is this? BH
1474 public void updateColoursFromMouseOver(Object source,
1475 MouseOverStructureListener mouseOverStructureListener)
1477 // TODO Auto-generated method stub
1482 public Object[] getSelectionForListener(SequenceGroup seqsel,
1483 ColumnSelection colsel, HiddenColumns hidden,
1484 SelectionSource source, Object alignFrame)
1486 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1487 seqsel, colsel, hidden, source, alignFrame);
1491 public String arrayToSeparatorList(String[] array)
1493 return appLoader.arrayToSeparatorList(array);
1497 public Hashtable<String, int[]> getJSHashes()
1499 return (jshashes == null ? (jshashes = new Hashtable<>())
1504 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1506 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1511 public Object getFrameForSource(VamsasSource source)
1516 if (source instanceof jalview.gui.AlignViewport
1517 && source == (af = getCurrentAlignFrame()).getViewport())
1519 // should be valid if it just generated an event!
1522 // TODO: ensure that if '_af' is specified along with a handler
1523 // function, then only events from that alignFrame are sent to that
1530 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1532 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1537 appLoader = new JalviewAppLoader(true);
1538 appLoader.load(app);
1543 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1546 public String getSelectedSequences()
1548 return getSelectedSequencesFrom(getCurrentAlignFrame());
1553 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1556 public String getSelectedSequences(String sep)
1558 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1563 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1567 public String getSelectedSequencesFrom(AlignFrameI alf)
1571 alf = getCurrentAlignFrame();
1573 return getSelectedSequencesFrom(alf, null);
1578 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1579 * .AlignFrame, java.lang.String)
1582 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
1586 alf = getCurrentAlignFrame();
1588 return appLoader.getSelectedSequencesFrom(alf, sep);
1593 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1594 * .AlignFrame, java.lang.String)
1597 public void highlight(String sequenceId, String position,
1598 String alignedPosition)
1600 highlightIn(null, sequenceId, position,
1605 public void highlightIn(AlignFrameI alf, String sequenceId,
1606 String position, String alignedPosition)
1610 alf = getCurrentAlignFrame();
1612 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1616 public void select(String sequenceIds, String columns)
1618 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1622 public void select(String sequenceIds, String columns, String sep)
1624 selectIn(null, sequenceIds, columns, sep);
1628 public void selectIn(AlignFrameI alf, String sequenceIds, String columns)
1630 selectIn(alf, sequenceIds, columns, null);
1634 public void selectIn(AlignFrameI alf, String sequenceIds, String columns,
1639 alf = getCurrentAlignFrame();
1641 appLoader.selectIn(alf, sequenceIds, columns, sep);
1645 public String getSelectedSequencesAsAlignment(String format,
1648 return getSelectedSequencesAsAlignmentFrom(null,
1653 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1654 String format, String sep)
1658 alf = getCurrentAlignFrame();
1660 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1664 public String getAlignmentOrder()
1666 return getAlignmentFrom(getCurrentAlignFrame(), null);
1670 public String getAlignmentOrderFrom(AlignFrameI alf)
1672 return getAlignmentFrom(alf, null);
1676 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
1680 alf = getCurrentAlignFrame();
1682 return appLoader.getAlignmentOrderFrom(alf, sep);
1686 public String orderBy(String order, String undoName)
1688 return orderBy(order, undoName, null);
1692 public String orderBy(String order, String undoName, String sep)
1694 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1698 public String orderAlignmentBy(AlignFrameI alf, String order,
1699 String undoName, String sep)
1703 alf = getCurrentAlignFrame();
1705 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1709 public String getAlignment(String format)
1711 return getAlignmentFrom(null, format, null);
1715 public String getAlignmentFrom(AlignFrameI alf, String format)
1717 return getAlignmentFrom(alf, format, null);
1721 public String getAlignment(String format, String suffix)
1723 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1727 public String getAlignmentFrom(AlignFrameI alf, String format,
1730 return appLoader.getAlignmentFrom(alf, format, suffix);
1734 public void loadAnnotation(String annotation)
1736 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1740 public void loadAnnotationFrom(AlignFrameI alf, String annotation)
1744 alf = getCurrentAlignFrame();
1746 appLoader.loadAnnotationFrom(alf, annotation);
1750 public void loadFeatures(String features, boolean autoenabledisplay)
1752 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1756 public boolean loadFeaturesFrom(AlignFrameI alf, String features,
1757 boolean autoenabledisplay)
1761 alf = getCurrentAlignFrame();
1763 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1767 public String getFeatures(String format)
1769 return getFeaturesFrom(null, format);
1773 public String getFeaturesFrom(AlignFrameI alf, String format)
1777 alf = getCurrentAlignFrame();
1779 return appLoader.getFeaturesFrom(alf, format, true, false);
1783 public String getAnnotation()
1785 return getAnnotationFrom(null);
1789 public String getAnnotationFrom(AlignFrameI alf)
1793 alf = getCurrentAlignFrame();
1795 return appLoader.getAnnotationFrom(alf);
1799 public AlignFrameI newView()
1801 return newViewFrom(null, null);
1805 public AlignFrameI newView(String name)
1807 return newViewFrom(null, name);
1811 public AlignFrameI newViewFrom(AlignFrameI alf)
1813 return newViewFrom(alf, null);
1817 public AlignFrameI newViewFrom(AlignFrameI alf, String name)
1821 alf = getCurrentAlignFrame();
1823 return appLoader.newViewFrom(alf, name);
1827 public AlignFrameI loadAlignment(String text, String title)
1829 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1830 AlignFrame.DEFAULT_HEIGHT, title);
1834 public boolean addPdbFile(AlignFrameI alFrame, String sequenceId,
1835 String pdbEntryString, String pdbFile)
1837 if (alFrame == null)
1839 alFrame = getCurrentAlignFrame();
1841 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1846 public void scrollViewToIn(AlignFrameI alf, String topRow,
1847 String leftHandColumn)
1851 alf = getCurrentAlignFrame();
1853 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1857 public void scrollViewToRowIn(AlignFrameI alf, String topRow)
1861 alf = getCurrentAlignFrame();
1863 appLoader.scrollViewToRowIn(alf, topRow);
1867 public void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn)
1871 alf = getCurrentAlignFrame();
1873 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1877 public String getFeatureGroups()
1879 return getFeatureGroupsOn(null);
1883 public String getFeatureGroupsOn(AlignFrameI alf)
1887 alf = getCurrentAlignFrame();
1889 return appLoader.getFeatureGroupsOn(alf);
1893 public String getFeatureGroupsOfState(boolean visible)
1895 return getFeatureGroupsOfStateOn(null, visible);
1899 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
1903 alf = getCurrentAlignFrame();
1905 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1909 public void setFeatureGroupState(String groups, boolean state)
1910 { // JalviewLite API
1911 setFeatureGroupStateOn(null, groups, state);
1915 public void setFeatureGroupStateOn(AlignFrameI alf, String groups,
1920 alf = getCurrentAlignFrame();
1922 appLoader.setFeatureGroupStateOn(alf, groups, state);
1926 public String getSeparator()
1928 return appLoader.getSeparator();
1932 public void setSeparator(String separator)
1934 appLoader.setSeparator(separator);
1938 public String getJsMessage(String messageclass, String viewId)
1940 // see http://www.jalview.org/examples/jalviewLiteJs.html
1945 * Open a new Tree panel on the desktop statically. Params are standard (not
1946 * set by Groovy). No dialog is opened.
1951 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1952 * of sequences selected is inappropriate
1955 public Object openTreePanel(AlignFrame af, String treeType,
1960 af = getCurrentAlignFrame();
1962 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
1966 * public static method for JalviewJS API to open a PCAPanel without
1967 * necessarily using a dialog.
1971 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
1972 * if number of sequences selected is inappropriate
1975 public Object openPcaPanel(AlignFrame af, String modelName)
1979 af = getCurrentAlignFrame();
1981 return CalculationChooser.openPcaPanel(af, modelName, null);
1985 public String getSelectedSequencesAsAlignment(String format,
1988 return getSelectedSequencesAsAlignmentFrom(null,
1993 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1994 String format, boolean suffix)
1998 alf = getCurrentAlignFrame();
2000 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
2005 public String arrayToSeparatorList(String[] array)
2007 return appLoader.arrayToSeparatorList(array);
2011 public String[] separatorListToArray(String list)
2013 return appLoader.separatorListToArray(list);
2016 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
2017 //// have a direct connection?
2020 public void setMouseoverListener(String listener)
2022 // TODO Auto-generated method stub
2027 public void setMouseoverListener(AlignFrameI af, String listener)
2029 // TODO Auto-generated method stub
2034 public void setSelectionListener(String listener)
2036 // TODO Auto-generated method stub
2041 public void setSelectionListener(AlignFrameI af, String listener)
2043 // TODO Auto-generated method stub
2048 public void setStructureListener(String listener, String modelSet)
2050 // TODO Auto-generated method stub
2055 public void removeJavascriptListener(AlignFrameI af, String listener)
2057 // TODO Auto-generated method stub
2062 public void mouseOverStructure(String pdbResNum, String chain,
2065 // TODO Auto-generated method stub
2070 public void showOverview()
2072 currentAlignFrame.overviewMenuItem_actionPerformed(null);
2075 public void notifyWorker(AlignCalcWorkerI worker, String status)
2077 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
2082 * flag to allow selected Runnable and Thread processes to run synchronously
2087 private static boolean isSynchronous = false;
2090 * Set Jalview to run selected processes synchronously in test and headless
2096 * @author Bob Hanson
2098 public static void setSynchronous(boolean b)
2104 * Allows optional synchronous running of a Runnable that would otherwise use
2105 * SwingUtilities.invokeLater.
2110 * @author Bob Hanson
2112 public static boolean isSynchronous()
2114 return isSynchronous;
2118 * Allows optional synchronous running of a Runnable that would otherwise use
2119 * SwingUtilities.invokeLater.
2124 * @author Bob Hanson
2126 public static void execRunnable(Runnable r)
2128 if (isSynchronous())
2134 SwingUtilities.invokeLater(r);
2139 * Allows optional synchronous running of a thread that would otherwise be run
2145 * @author Bob Hanson
2147 public static void execThread(Thread t)
2149 if (isSynchronous())
2160 * Get the SwingJS applet ID and combine that with the frameType
2163 * "alignment", "desktop", etc., or null
2166 public static String getAppID(String frameType)
2168 String id = Cache.getProperty("Info.j2sAppletID");
2173 return id + (frameType == null ? "" : "-" + frameType);