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.AlignFrameI;
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;
86 import java.util.logging.ConsoleHandler;
87 import java.util.logging.Level;
88 import java.util.logging.Logger;
90 import javax.swing.LookAndFeel;
91 import javax.swing.UIManager;
93 import groovy.lang.Binding;
94 import groovy.util.GroovyScriptEngine;
95 import netscape.javascript.JSObject;
98 * Main class for Jalview Application <br>
100 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
101 * jalview.bin.Jalview
103 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
104 * jalview.bin.Jalview jalview.bin.Jalview
106 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
107 * embellish '*' to e.g. '*.jar')
110 * @version $Revision$
112 public class Jalview implements ApplicationSingletonI, JalviewJSApi
115 public static Jalview getInstance()
117 return (Jalview) ApplicationSingletonProvider
118 .getInstance(Jalview.class);
127 Platform.getURLCommandArguments();
130 private boolean headless;
132 public static boolean isHeadlessMode()
134 return getInstance().headless;
137 private Desktop desktop;
139 private AlignFrame currentAlignFrame;
141 public boolean isJavaAppletTag;
143 public String appletResourcePath;
145 JalviewAppLoader appLoader;
147 protected JSFunctionExec jsFunctionExec;
149 public static AlignFrame getCurrentAlignFrame()
151 return getInstance().currentAlignFrame;
154 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
156 getInstance().currentAlignFrame = currentAlignFrame;
161 if (!Platform.isJS())
168 // grab all the rights we can for the JVM
169 Policy.setPolicy(new Policy()
172 public PermissionCollection getPermissions(CodeSource codesource)
174 Permissions perms = new Permissions();
175 perms.add(new AllPermission());
180 public void refresh()
188 * keep track of feature fetching tasks.
196 * TODO: generalise to track all jalview events to orchestrate batch
200 private int queued = 0;
202 private int running = 0;
204 public FeatureFetcher()
209 public void addFetcher(final AlignFrame af,
210 final Vector<String> dasSources)
212 final long id = System.currentTimeMillis();
214 final FeatureFetcher us = this;
215 new Thread(new Runnable()
227 af.setProgressBar(MessageManager
228 .getString("status.das_features_being_retrived"), id);
229 af.featureSettings_actionPerformed(null);
230 af.setProgressBar(null, id);
239 public synchronized boolean allFinished()
241 return queued == 0 && running == 0;
247 * main class for Jalview application
250 * open <em>filename</em>
252 public static void main(String[] args)
254 // setLogging(); // BH - for event debugging in JavaScript
255 getInstance().doMain(args);
259 * Allow an outside entity to initiate the second half of argument parsing
263 * @return null is good
266 public Object parseArguments(String[] args)
271 ArgsParser aparser = new ArgsParser(args);
272 return parseArguments(aparser, false);
273 } catch (Throwable t)
279 private static void logClass(String name)
281 // BH - for event debugging in JavaScript
282 ConsoleHandler consoleHandler = new ConsoleHandler();
283 consoleHandler.setLevel(Level.ALL);
284 Logger logger = Logger.getLogger(name);
285 logger.setLevel(Level.ALL);
286 logger.addHandler(consoleHandler);
289 @SuppressWarnings("unused")
290 private static void setLogging()
298 System.out.println("not in js");
301 // BH - for event debugging in JavaScript (Java mode only)
302 if (!Platform.isJS())
309 Logger.getLogger("").setLevel(Level.ALL);
310 logClass("java.awt.EventDispatchThread");
311 logClass("java.awt.EventQueue");
312 logClass("java.awt.Component");
313 logClass("java.awt.focus.Component");
314 logClass("java.awt.focus.DefaultKeyboardFocusManager");
322 void doMain(String[] args)
325 boolean isJS = Platform.isJS();
328 System.setSecurityManager(null);
332 .println("Java version: " + System.getProperty("java.version"));
333 System.out.println(System.getProperty("os.arch") + " "
334 + System.getProperty("os.name") + " "
335 + System.getProperty("os.version"));
337 ArgsParser aparser = new ArgsParser(args);
339 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
340 Cache.loadProperties(usrPropsFile);
343 isJavaAppletTag = aparser.isApplet();
346 Preferences.setAppletDefaults();
347 Cache.loadProperties(usrPropsFile); // again, because we
348 // might be changing defaults here?
351 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
352 appletResourcePath = aparser.getValue("Info.resourcePath");
361 if (usrPropsFile != null)
364 "CMD [-props " + usrPropsFile + "] executed successfully!");
367 if (aparser.contains("help") || aparser.contains("h"))
372 if (aparser.contains(ArgsParser.NODISPLAY)
373 || aparser.contains(ArgsParser.NOGUI)
374 || aparser.contains(ArgsParser.HEADLESS)
375 || "true".equals(System.getProperty("java.awt.headless")))
382 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
383 if (jabawsUrl != null)
387 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
389 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
390 } catch (MalformedURLException e)
393 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
398 // check for property setting
399 String defs = aparser.getValue(ArgsParser.SETPROP);
402 int p = defs.indexOf('=');
405 System.err.println("Ignoring invalid setprop argument : " + defs);
409 System.out.println("Executing setprop argument: " + defs);
412 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
415 defs = aparser.getValue(ArgsParser.SETPROP);
417 System.setProperty("http.agent",
418 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
422 } catch (NoClassDefFoundError error)
424 error.printStackTrace();
425 System.out.println("\nEssential logging libraries not found."
426 + "\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.isAMacAndNotJS())
443 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
445 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
447 System.setProperty("apple.laf.useScreenMenuBar", "true");
448 if (lookAndFeel != null)
452 UIManager.setLookAndFeel(lookAndFeel);
453 } catch (Throwable e)
456 "Failed to set QuaQua look and feel: " + e.toString());
459 if (lookAndFeel == null
460 || !(lookAndFeel.getClass().isAssignableFrom(
461 UIManager.getLookAndFeel().getClass()))
462 || !UIManager.getLookAndFeel().getClass().toString()
463 .toLowerCase().contains("quaqua"))
468 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
469 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
470 } catch (Throwable e)
473 "Failed to reset look and feel: " + e.toString());
479 * configure 'full' SO model if preferences say to,
480 * else use the default (SO Lite)
482 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
484 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
489 desktop = Desktop.getInstance();
490 desktop.setInBatchMode(true); // indicate we are starting up
491 desktop.setVisible(true);
500 desktop.startServiceDiscovery();
501 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
503 startUsageStats(desktop);
507 System.err.println("CMD [-nousagestats] executed successfully!");
510 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
512 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
515 // Start the desktop questionnaire prompter with the specified
517 Cache.log.debug("Starting questionnaire url at " + url);
518 desktop.checkForQuestionnaire(url);
519 System.out.println("CMD questionnaire[-" + url
520 + "] executed successfully!");
524 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
526 // Start the desktop questionnaire prompter with the specified
529 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
531 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
533 "Starting questionnaire with default url: " + defurl);
534 desktop.checkForQuestionnaire(defurl);
541 .println("CMD [-noquestionnaire] executed successfully!");
544 if (!aparser.contains(ArgsParser.NONEWS))
546 desktop.checkForNews();
549 BioJsHTMLOutput.updateBioJS();
553 parseArguments(aparser, true);
556 private Object parseArguments(ArgsParser aparser, boolean isStartup)
558 boolean isJS = Platform.isJS();
560 Desktop desktop = (headless ? null : Desktop.getInstance());
561 // script to execute after all loading is
562 // completed one way or another
563 // extract groovy argument and execute if necessary
564 String groovyscript = (isJS ? null
565 : aparser.getValue(ArgsParser.GROOVY, true));
566 String file = aparser.getValue(ArgsParser.OPEN, true);
567 // BH this here to allow split frame; not working as of 5/17/2019
568 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
569 String fileFormat = (isJavaAppletTag
570 ? aparser.getAppletValue("format", null)
573 FileFormatI format = null;
574 DataSourceType protocol = null;
576 if (file == null && desktop == null)
578 System.out.println("No files to open!");
581 boolean haveImport = checkStartVamas(aparser);
582 // Finally, deal with the remaining input data.
584 if (file == null && isJavaAppletTag)
586 // Maybe the sequences are added as parameters
587 StringBuffer data = new StringBuffer("PASTE");
589 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
591 data.append(file.toString() + "\n");
594 if (data.length() > 5)
596 file = data.toString();
604 desktop.setProgressBar(
606 .getString("status.processing_commandline_args"),
607 progress = System.currentTimeMillis());
612 * ignore in JavaScript -- can't just check file existence - could load
618 if (!file.startsWith("http://") && !file.startsWith("https://"))
619 // BH 2019 added https check for Java
621 if (!(new File(file)).exists())
623 System.out.println("Can't find " + file);
632 protocol = AppletFormatAdapter.checkProtocol(file);
636 format = (isJavaAppletTag && fileFormat != null
637 ? FileFormats.getInstance().forName(fileFormat)
641 format = new IdentifyFile().identify(file, protocol);
643 } catch (FileFormatException e1)
648 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
652 System.out.println("error");
657 .println("CMD [-open " + file + "] executed successfully!");
660 protocol = AppletFormatAdapter.checkProtocol(file2);
663 format = new IdentifyFile().identify(file2, protocol);
664 } catch (FileFormatException e1)
668 AlignFrame af2 = new FileLoader(!headless)
669 .loadFileWaitTillLoaded(file2, protocol, format);
672 System.out.println("error");
676 AlignViewport.openLinkedAlignmentAs(af,
677 af.getViewport().getAlignment(),
678 af2.getViewport().getAlignment(), "",
679 AlignViewport.SPLIT_FRAME);
681 "CMD [-open2 " + file2 + "] executed successfully!");
685 setCurrentAlignFrame(af);
687 // TODO: file2 How to implement file2 for the applet spit screen?
689 String data = aparser.getValue(ArgsParser.COLOUR, true);
692 data.replaceAll("%20", " ");
694 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
695 af.getViewport(), af.getViewport().getAlignment(), data);
700 "CMD [-color " + data + "] executed successfully!");
705 // Must maintain ability to use the groups flag
706 data = aparser.getValue(ArgsParser.GROUPS, true);
709 af.parseFeaturesFile(data,
710 AppletFormatAdapter.checkProtocol(data));
711 // System.out.println("Added " + data);
713 "CMD groups[-" + data + "] executed successfully!");
715 data = aparser.getValue(ArgsParser.FEATURES, true);
718 af.parseFeaturesFile(data,
719 AppletFormatAdapter.checkProtocol(data));
720 // System.out.println("Added " + data);
722 "CMD [-features " + data + "] executed successfully!");
725 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
728 af.loadJalviewDataFile(data, null, null, null);
729 // System.out.println("Added " + data);
731 "CMD [-annotations " + data + "] executed successfully!");
733 // set or clear the sortbytree flag.
734 if (aparser.contains(ArgsParser.SORTBYTREE))
736 af.getViewport().setSortByTree(true);
737 if (af.getViewport().getSortByTree())
739 System.out.println("CMD [-sortbytree] executed successfully!");
742 if (aparser.contains(ArgsParser.NOANNOTATION)
743 || aparser.contains(ArgsParser.NOANNOTATION2))
745 af.getViewport().setShowAnnotation(false);
746 if (!af.getViewport().isShowAnnotation())
748 System.out.println("CMD no-annotation executed successfully!");
751 if (aparser.contains(ArgsParser.NOSORTBYTREE))
753 af.getViewport().setSortByTree(false);
754 if (!af.getViewport().getSortByTree())
757 .println("CMD [-nosortbytree] executed successfully!");
760 data = aparser.getValue(ArgsParser.TREE, true);
766 "CMD [-tree " + data + "] executed successfully!");
767 NewickFile nf = new NewickFile(data,
768 AppletFormatAdapter.checkProtocol(data));
770 .setCurrentTree(af.showNewickTree(nf, data).getTree());
771 } catch (IOException ex)
773 System.err.println("Couldn't add tree " + data);
774 ex.printStackTrace(System.err);
777 // TODO - load PDB structure(s) to alignment JAL-629
778 // (associate with identical sequence in alignment, or a specified
782 loadAppletParams(aparser, af);
791 if (groovyscript != null)
793 // Execute the groovy script after we've done all the rendering
795 // and before any images or figures are generated.
796 System.out.println("Executing script " + groovyscript);
797 executeGroovyScript(groovyscript, af);
798 System.out.println("CMD groovy[" + groovyscript
799 + "] executed successfully!");
802 checkOutputFile(aparser, af, format);
803 while (aparser.getSize() > 0)
805 System.out.println("Unknown arg: " + aparser.nextValue());
810 AlignFrame startUpAlframe = null;
811 // We'll only open the default file if the desktop is visible.
813 // ////////////////////
815 if (!isJS && !headless && file == null && !haveImport
816 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
823 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
824 jalview.bin.Cache.getDefault("www.jalview.org",
825 "http://www.jalview.org")
826 + "/examples/exampleFile_2_7.jar");
828 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
830 // hardwire upgrade of the startup file
831 file.replace("_2_3.jar", "_2_7.jar");
832 // and remove the stale setting
833 jalview.bin.Cache.removeProperty("STARTUP_FILE");
836 protocol = DataSourceType.FILE;
838 if (file.indexOf("http:") > -1)
840 protocol = DataSourceType.URL;
843 if (file.endsWith(".jar"))
845 format = FileFormat.Jalview;
851 format = new IdentifyFile().identify(file, protocol);
852 } catch (FileFormatException e)
858 startUpAlframe = new FileLoader(!headless)
859 .loadFileWaitTillLoaded(file, protocol, format);
860 // extract groovy arguments before anything else.
863 // Once all other stuff is done, execute any groovy scripts (in order)
864 if (groovyscript != null)
866 if (Cache.groovyJarsPresent())
868 System.out.println("Executing script " + groovyscript);
869 executeGroovyScript(groovyscript, startUpAlframe);
874 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
878 // and finally, turn off batch mode indicator - if the desktop still exists
883 desktop.setProgressBar(null, progress);
885 desktop.setInBatchMode(false);
891 private boolean checkStartVamas(ArgsParser aparser)
893 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
894 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
895 if (vamsasImport == null && vamsasSession == null)
899 if (desktop == null || headless)
902 "Headless vamsas sessions not yet supported. Sorry.");
905 boolean haveImport = (vamsasImport != null);
908 // if we have a file, start a new session and import it.
909 boolean inSession = false;
912 DataSourceType viprotocol = AppletFormatAdapter
913 .checkProtocol(vamsasImport);
914 if (viprotocol == DataSourceType.FILE)
916 inSession = desktop.vamsasImport(new File(vamsasImport));
918 else if (viprotocol == DataSourceType.URL)
920 inSession = desktop.vamsasImport(new URL(vamsasImport));
923 } catch (Exception e)
925 System.err.println("Exeption when importing " + vamsasImport
926 + " as a vamsas document.");
931 System.err.println("Failed to import " + vamsasImport
932 + " as a vamsas document.");
936 System.out.println("Imported Successfully into new session "
937 + desktop.getVamsasApplication().getCurrentSession());
940 if (vamsasSession != null)
942 if (vamsasImport != null)
944 // close the newly imported session and import the Jalview specific
945 // remnants into the new session later on.
946 desktop.vamsasStop_actionPerformed(null);
948 // now join the new session
951 if (desktop.joinVamsasSession(vamsasSession))
954 "Successfully joined vamsas session " + vamsasSession);
958 System.err.println("WARNING: Failed to join vamsas session "
961 } catch (Exception e)
964 "ERROR: Failed to join vamsas session " + vamsasSession);
967 if (vamsasImport != null)
969 // the Jalview specific remnants can now be imported into the new
970 // session at the user's leisure.
972 "Skipping Push for import of data into existing vamsas session.");
978 // desktop.getVamsasApplication().push_update();
984 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
987 String imageName = "unnamed.png";
988 while (aparser.getSize() > 1)
994 String outputFormat = aparser.nextValue();
995 String file = aparser.nextValue();
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);
1018 System.out.println("Creating HTML image: " + file);
1021 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1025 System.err.println("The output html file must not be null");
1030 BioJsHTMLOutput.refreshVersionInfo(
1031 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1032 } catch (URISyntaxException e)
1034 e.printStackTrace();
1036 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1037 bjs.exportHTML(file);
1038 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1041 else if (outputFormat.equalsIgnoreCase("imgMap"))
1043 af.createImageMap(new File(file), imageName);
1044 System.out.println("Creating image map: " + file);
1047 else if (outputFormat.equalsIgnoreCase("eps"))
1049 File outputFile = new File(file);
1051 "Creating EPS file: " + outputFile.getAbsolutePath());
1052 af.createEPS(outputFile);
1056 af.saveAlignment(file, format);
1057 if (af.isSaveAlignmentSuccessful())
1060 "Written alignment in " + format + " format to " + file);
1064 System.out.println("Error writing file " + file + " in " + format
1071 private static void showUsage()
1074 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1075 + "-nodisplay\tRun Jalview without User Interface.\n"
1076 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1077 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1078 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1079 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1080 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1081 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1082 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1083 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1084 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1085 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1086 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1087 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1088 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1089 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1090 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1091 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1092 + "-html FILE\tCreate HTML file from alignment.\n"
1093 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1094 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1095 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1096 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1097 + "-noquestionnaire\tTurn off questionnaire check.\n"
1098 + "-nonews\tTurn off check for Jalview news.\n"
1099 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1100 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1102 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1103 // after all other properties files have been read\n\t
1104 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1105 // passed in correctly)"
1106 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1107 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1109 // "-vdoc vamsas-document\tImport vamsas document into new
1110 // session or join existing session with same URN\n"
1111 // + "-vses vamsas-session\tJoin session with given URN\n"
1112 + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
1113 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1116 private static void startUsageStats(final Desktop desktop)
1119 * start a User Config prompt asking if we can log usage statistics.
1121 PromptUserConfig prompter = new PromptUserConfig(
1122 Desktop.getDesktopPane(), "USAGESTATS",
1123 "Jalview Usage Statistics",
1124 "Do you want to help make Jalview better by enabling "
1125 + "the collection of usage statistics with Google Analytics ?"
1126 + "\n\n(you can enable or disable usage tracking in the preferences)",
1133 "Initialising googletracker for usage stats.");
1134 Cache.initGoogleTracker();
1135 Cache.log.debug("Tracking enabled.");
1142 Cache.log.debug("Not enabling Google Tracking.");
1145 desktop.addDialogThread(prompter);
1149 * Locate the given string as a file and pass it to the groovy interpreter.
1151 * @param groovyscript
1152 * the script to execute
1153 * @param jalviewContext
1154 * the Jalview Desktop object passed in to the groovy binding as the
1157 private void executeGroovyScript(String groovyscript, AlignFrame af)
1160 * for scripts contained in files
1167 if (groovyscript.trim().equals("STDIN"))
1169 // read from stdin into a tempfile and execute it
1172 tfile = File.createTempFile("jalview", "groovy");
1173 PrintWriter outfile = new PrintWriter(
1174 new OutputStreamWriter(new FileOutputStream(tfile)));
1175 BufferedReader br = new BufferedReader(
1176 new InputStreamReader(System.in));
1178 while ((line = br.readLine()) != null)
1180 outfile.write(line + "\n");
1186 } catch (Exception ex)
1188 System.err.println("Failed to read from STDIN into tempfile "
1189 + ((tfile == null) ? "(tempfile wasn't created)"
1190 : tfile.toString()));
1191 ex.printStackTrace();
1196 sfile = tfile.toURI().toURL();
1197 } catch (Exception x)
1200 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1202 x.printStackTrace();
1210 sfile = new URI(groovyscript).toURL();
1211 } catch (Exception x)
1213 tfile = new File(groovyscript);
1214 if (!tfile.exists())
1216 System.err.println("File '" + groovyscript + "' does not exist.");
1219 if (!tfile.canRead())
1221 System.err.println("File '" + groovyscript + "' cannot be read.");
1224 if (tfile.length() < 1)
1226 System.err.println("File '" + groovyscript + "' is empty.");
1231 sfile = tfile.getAbsoluteFile().toURI().toURL();
1232 } catch (Exception ex)
1234 System.err.println("Failed to create a file URL for "
1235 + tfile.getAbsoluteFile());
1242 Map<String, Object> vbinding = new HashMap<>();
1243 vbinding.put("Jalview", this);
1246 vbinding.put("currentAlFrame", af);
1248 Binding gbinding = new Binding(vbinding);
1249 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1250 gse.run(sfile.toString(), gbinding);
1251 if ("STDIN".equals(groovyscript))
1253 // delete temp file that we made -
1254 // only if it was successfully executed
1257 } catch (Exception e)
1259 System.err.println("Exception Whilst trying to execute file " + sfile
1260 + " as a groovy script.");
1261 e.printStackTrace(System.err);
1266 public AlignFrame[] getAlignFrames()
1268 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1269 : Desktop.getAlignFrames();
1274 * Quit method delegates to Desktop.quit - unless running in headless mode
1275 * when it just ends the JVM
1279 if (jsFunctionExec != null)
1281 jsFunctionExec.tidyUp();
1282 jsFunctionExec = null;
1285 if (desktop != null)
1296 * Get the SwingJS applet ID and combine that with the frameType
1299 * "alignment", "desktop", etc., or null
1302 public static String getAppID(String frameType)
1304 String id = Cache.getProperty("Info.j2sAppletID");
1309 return id + (frameType == null ? "" : "-" + frameType);
1313 * Handle all JalviewLite applet parameters
1318 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1320 JalviewApp app = new JalviewApp()
1325 // These are methods that are in JalviewLite that various classes call
1326 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1328 // them to JalviewLite directly. Some may not be necessary, but they have
1330 // be at least mentioned here, or the classes calling them should
1332 // JalviewLite itself.
1334 private boolean alignPDBStructures; // From JalviewLite; not implemented
1336 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1338 private Hashtable<String, int[]> jshashes;
1341 public String getParameter(String name)
1343 return aparser.getAppletValue(name, null);
1347 public boolean getDefaultParameter(String name, boolean def)
1350 return ((stn = getParameter(name)) == null ? def
1351 : "true".equalsIgnoreCase(stn));
1355 * Get the applet-like document base even though this is an application.
1358 public URL getDocumentBase()
1360 return Platform.getDocumentBase();
1364 * Get the applet-like code base even though this is an application.
1367 public URL getCodeBase()
1369 return Platform.getCodeBase();
1373 public AlignViewportI getViewport()
1375 return af.getViewport();
1383 public boolean parseFeaturesFile(String filename,
1384 DataSourceType protocol)
1386 return af.parseFeaturesFile(filename, protocol);
1394 public boolean loadScoreFile(String sScoreFile) throws IOException
1396 af.loadJalviewDataFile(sScoreFile, null, null, null);
1401 * annotations, jpredfile, jnetfile
1405 public void updateForAnnotations()
1407 af.updateForAnnotations();
1411 public void loadTree(NewickFile fin, String treeFile)
1414 // n/a -- already done by standard Jalview command line processing
1418 public void setAlignPdbStructures(boolean defaultParameter)
1420 alignPDBStructures = true;
1424 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1425 String[] chains, DataSourceType protocol)
1427 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1431 public void setFeatureGroupState(String[] groups, boolean state)
1433 af.setFeatureGroupState(groups, state);
1437 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1438 String[][] chains, String[] protocols)
1441 "Jalview applet interface alignedStructureView not implemented");
1445 public void newFeatureSettings()
1448 "Jalview applet interface newFeatureSettings not implemented");
1451 private Vector<Runnable> jsExecQueue;
1454 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1456 jsFunctionExec = exec;
1457 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1462 public AppletContext getAppletContext()
1464 // TODO Auto-generated method stub
1469 public boolean isJsfallbackEnabled()
1471 // TODO Auto-generated method stub
1476 public JSObject getJSObject()
1478 // TODO Auto-generated method stub
1483 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1485 // TODO Q: what exactly is this? BH
1490 public void updateColoursFromMouseOver(Object source,
1491 MouseOverStructureListener mouseOverStructureListener)
1493 // TODO Auto-generated method stub
1498 public Object[] getSelectionForListener(SequenceGroup seqsel,
1499 ColumnSelection colsel, HiddenColumns hidden,
1500 SelectionSource source, Object alignFrame)
1502 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1503 seqsel, colsel, hidden, source, alignFrame);
1507 public String arrayToSeparatorList(String[] array)
1509 return appLoader.arrayToSeparatorList(array);
1513 public Hashtable<String, int[]> getJSHashes()
1515 return (jshashes == null ? (jshashes = new Hashtable<>())
1520 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1522 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1527 public Object getFrameForSource(VamsasSource source)
1532 if (source instanceof jalview.gui.AlignViewport
1533 && source == (af = getCurrentAlignFrame()).getViewport())
1535 // should be valid if it just generated an event!
1538 // TODO: ensure that if '_af' is specified along with a handler
1539 // function, then only events from that alignFrame are sent to that
1546 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1548 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1553 appLoader = new JalviewAppLoader(true);
1554 appLoader.load(app);
1559 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1562 public String getSelectedSequences()
1564 return getSelectedSequencesFrom(getCurrentAlignFrame());
1569 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1572 public String getSelectedSequences(String sep)
1574 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1579 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1583 public String getSelectedSequencesFrom(AlignFrameI alf)
1585 return getSelectedSequencesFrom(alf, null);
1590 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1591 * .AlignFrame, java.lang.String)
1594 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
1596 return appLoader.getSelectedSequencesFrom(alf, sep);
1601 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1602 * .AlignFrame, java.lang.String)
1605 public void highlight(String sequenceId, String position,
1606 String alignedPosition)
1608 highlightIn(getCurrentAlignFrame(), sequenceId, position,
1613 public void highlightIn(AlignFrameI alf, String sequenceId,
1614 String position, String alignedPosition)
1616 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1620 public void select(String sequenceIds, String columns)
1622 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1626 public void select(String sequenceIds, String columns, String sep)
1628 selectIn(getCurrentAlignFrame(), sequenceIds, columns, sep);
1632 public void selectIn(AlignFrameI alf, String sequenceIds, String columns)
1634 selectIn(alf, sequenceIds, columns, null);
1638 public void selectIn(AlignFrameI alf, String sequenceIds, String columns,
1641 appLoader.selectIn(alf, sequenceIds, columns, sep);
1645 public String getSelectedSequencesAsAlignment(String format,
1648 return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
1653 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1654 String format, String sep)
1656 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1660 public String getAlignmentOrder()
1662 return getAlignmentFrom(getCurrentAlignFrame(), null);
1666 public String getAlignmentOrderFrom(AlignFrameI alf)
1668 return getAlignmentFrom(alf, null);
1672 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
1674 return appLoader.getAlignmentOrderFrom(alf, sep);
1678 public String orderBy(String order, String undoName)
1680 return orderBy(order, undoName, null);
1684 public String orderBy(String order, String undoName, String sep)
1686 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1690 public String orderAlignmentBy(AlignFrameI alf, String order,
1691 String undoName, String sep)
1693 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1697 public String getAlignment(String format)
1699 return getAlignmentFrom(null, format, null);
1703 public String getAlignmentFrom(AlignFrameI alf, String format)
1705 return getAlignmentFrom(alf, format, null);
1709 public String getAlignment(String format, String suffix)
1711 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1715 public String getAlignmentFrom(AlignFrameI alf, String format,
1718 return appLoader.getAlignmentFrom(alf, format, suffix);
1722 public void loadAnnotation(String annotation)
1724 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1728 public void loadAnnotationFrom(AlignFrameI alf, String annotation)
1730 appLoader.loadAnnotationFrom(alf, annotation);
1734 public void loadFeatures(String features, boolean autoenabledisplay)
1736 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1740 public boolean loadFeaturesFrom(AlignFrameI alf, String features,
1741 boolean autoenabledisplay)
1743 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1747 public String getFeatures(String format)
1749 return getFeaturesFrom(getCurrentAlignFrame(), format);
1753 public String getFeaturesFrom(AlignFrameI alf, String format)
1755 return appLoader.getFeaturesFrom(alf, format);
1759 public String getAnnotation()
1761 return getAnnotationFrom(getCurrentAlignFrame());
1765 public String getAnnotationFrom(AlignFrameI alf)
1767 return appLoader.getAnnotationFrom(alf);
1771 public AlignFrameI newView()
1773 return newViewFrom(getCurrentAlignFrame(), null);
1777 public AlignFrameI newView(String name)
1779 return newViewFrom(getCurrentAlignFrame(), name);
1783 public AlignFrameI newViewFrom(AlignFrameI alf)
1785 return newViewFrom(alf, null);
1789 public AlignFrameI newViewFrom(AlignFrameI alf, String name)
1791 return appLoader.newViewFrom(alf, name);
1795 public AlignFrameI loadAlignment(String text, String title)
1797 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1798 AlignFrame.DEFAULT_HEIGHT, title);
1802 public boolean addPdbFile(AlignFrameI alFrame, String sequenceId,
1803 String pdbEntryString, String pdbFile)
1805 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1810 public void scrollViewToIn(AlignFrameI alf, String topRow,
1811 String leftHandColumn)
1813 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1817 public void scrollViewToRowIn(AlignFrameI alf, String topRow)
1819 appLoader.scrollViewToRowIn(alf, topRow);
1823 public void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn)
1825 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1829 public String getFeatureGroups()
1831 return getFeatureGroupsOn(getCurrentAlignFrame());
1835 public String getFeatureGroupsOn(AlignFrameI alf)
1837 return appLoader.getFeatureGroupsOn(alf);
1841 public String getFeatureGroupsOfState(boolean visible)
1843 return getFeatureGroupsOfStateOn(getCurrentAlignFrame(), visible);
1847 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
1849 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1853 public void setFeatureGroupStateOn(AlignFrameI alf, String groups,
1856 setFeatureGroupStateOn(alf, groups, state);
1860 public void setFeatureGroupState(String groups, boolean state)
1862 appLoader.setFeatureGroupStateOn(getCurrentAlignFrame(), groups, state);
1866 public String getSeparator()
1868 return appLoader.getSeparator();
1872 public void setSeparator(String separator)
1874 appLoader.setSeparator(separator);
1878 public String getJsMessage(String messageclass, String viewId)
1880 // see http://www.jalview.org/examples/jalviewLiteJs.html
1885 * Open a new Tree panel on the desktop statically. Params are standard (not
1886 * set by Groovy). No dialog is opened.
1891 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1892 * of sequences selected is inappropriate
1895 public Object openTreePanel(AlignFrame af, String treeType,
1898 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
1902 * public static method for JalviewJS API to open a PCAPanel without
1903 * necessarily using a dialog.
1907 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
1908 * if number of sequences selected is inappropriate
1911 public Object openPcaPanel(AlignFrame af, String modelName)
1913 return CalculationChooser.openPcaPanel(af, modelName, null);
1917 public String getSelectedSequencesAsAlignment(String format,
1920 return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
1925 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1926 String format, boolean suffix)
1928 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
1933 public String arrayToSeparatorList(String[] array)
1935 return appLoader.arrayToSeparatorList(array);
1939 public String[] separatorListToArray(String list)
1941 return appLoader.separatorListToArray(list);
1944 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
1945 //// have a direct connection?
1948 public void setMouseoverListener(String listener)
1950 // TODO Auto-generated method stub
1955 public void setMouseoverListener(AlignFrameI af, String listener)
1957 // TODO Auto-generated method stub
1962 public void setSelectionListener(String listener)
1964 // TODO Auto-generated method stub
1969 public void setSelectionListener(AlignFrameI af, String listener)
1971 // TODO Auto-generated method stub
1976 public void setStructureListener(String listener, String modelSet)
1978 // TODO Auto-generated method stub
1983 public void removeJavascriptListener(AlignFrameI af, String listener)
1985 // TODO Auto-generated method stub
1990 public void mouseOverStructure(String pdbResNum, String chain,
1993 // TODO Auto-generated method stub