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;
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 public static Jalview getInstance()
114 return (Jalview) ApplicationSingletonProvider
115 .getInstance(Jalview.class);
124 Platform.getURLCommandArguments();
127 private boolean headless;
129 public static boolean isHeadlessMode()
131 return getInstance().headless;
134 private Desktop desktop;
136 private AlignFrame currentAlignFrame;
138 public boolean isJavaAppletTag;
140 public String appletResourcePath;
142 JalviewAppLoader appLoader;
144 protected JSFunctionExec jsFunctionExec;
146 private boolean noCalculation, noMenuBar, noStatus;
148 public boolean getStartCalculations()
150 return !noCalculation;
153 public boolean getAllowMenuBar()
158 public boolean getShowStatus()
164 public static AlignFrame getCurrentAlignFrame()
166 return getInstance().currentAlignFrame;
169 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
171 getInstance().currentAlignFrame = currentAlignFrame;
176 if (!Platform.isJS())
183 // grab all the rights we can for the JVM
184 Policy.setPolicy(new Policy()
187 public PermissionCollection getPermissions(CodeSource codesource)
189 Permissions perms = new Permissions();
190 perms.add(new AllPermission());
195 public void refresh()
203 * keep track of feature fetching tasks.
211 * TODO: generalise to track all jalview events to orchestrate batch
215 private int queued = 0;
217 private int running = 0;
219 public FeatureFetcher()
224 public void addFetcher(final AlignFrame af,
225 final Vector<String> dasSources)
227 final long id = System.currentTimeMillis();
229 final FeatureFetcher us = this;
230 new Thread(new Runnable()
242 af.setProgressBar(MessageManager
243 .getString("status.das_features_being_retrived"), id);
244 af.featureSettings_actionPerformed(null);
245 af.setProgressBar(null, id);
254 public synchronized boolean allFinished()
256 return queued == 0 && running == 0;
262 * main class for Jalview application
265 * open <em>filename</em>
267 public static void main(String[] args)
269 // Platform.startJavaLogging();
270 getInstance().doMain(args);
274 @SuppressWarnings("unused")
278 void doMain(String[] args)
281 boolean isJS = Platform.isJS();
284 System.setSecurityManager(null);
288 .println("Java version: " + System.getProperty("java.version"));
289 System.out.println(System.getProperty("os.arch") + " "
290 + System.getProperty("os.name") + " "
291 + System.getProperty("os.version"));
293 ArgsParser aparser = new ArgsParser(args);
295 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
296 Cache.loadProperties(usrPropsFile);
299 isJavaAppletTag = aparser.isApplet();
302 Preferences.setAppletDefaults();
303 Cache.loadProperties(usrPropsFile); // again, because we
304 // might be changing defaults here?
307 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
308 appletResourcePath = aparser.getValue("Info.resourcePath");
317 if (usrPropsFile != null)
320 "CMD [-props " + usrPropsFile + "] executed successfully!");
323 if (aparser.contains("help") || aparser.contains("h"))
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 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
339 if (jabawsUrl != null)
343 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
345 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
346 } catch (MalformedURLException e)
349 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
354 // check for property setting
355 String defs = aparser.getValue(ArgsParser.SETPROP);
358 int p = defs.indexOf('=');
361 System.err.println("Ignoring invalid setprop argument : " + defs);
365 System.out.println("Executing setprop argument: " + defs);
368 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
371 defs = aparser.getValue(ArgsParser.SETPROP);
373 System.setProperty("http.agent",
374 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
378 } catch (NoClassDefFoundError error)
380 error.printStackTrace();
381 System.out.println("\nEssential logging libraries not found."
382 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
390 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
391 } catch (Exception ex)
393 System.err.println("Unexpected Look and Feel Exception");
394 ex.printStackTrace();
396 if (Platform.isAMacAndNotJS())
399 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
401 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
403 System.setProperty("apple.laf.useScreenMenuBar", "true");
404 if (lookAndFeel != null)
408 UIManager.setLookAndFeel(lookAndFeel);
409 } catch (Throwable e)
412 "Failed to set QuaQua look and feel: " + e.toString());
415 if (lookAndFeel == null
416 || !(lookAndFeel.getClass().isAssignableFrom(
417 UIManager.getLookAndFeel().getClass()))
418 || !UIManager.getLookAndFeel().getClass().toString()
419 .toLowerCase().contains("quaqua"))
424 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
425 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
426 } catch (Throwable e)
429 "Failed to reset look and feel: " + e.toString());
435 * configure 'full' SO model if preferences say to,
436 * else use the default (SO Lite)
438 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
440 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
445 desktop = Desktop.getInstance();
446 desktop.setInBatchMode(true); // indicate we are starting up
447 desktop.setVisible(true);
456 desktop.startServiceDiscovery();
457 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
459 startUsageStats(desktop);
463 System.err.println("CMD [-nousagestats] executed successfully!");
466 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
468 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
471 // Start the desktop questionnaire prompter with the specified
473 Cache.log.debug("Starting questionnaire url at " + url);
474 desktop.checkForQuestionnaire(url);
475 System.out.println("CMD questionnaire[-" + url
476 + "] executed successfully!");
480 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
482 // Start the desktop questionnaire prompter with the specified
485 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
487 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
489 "Starting questionnaire with default url: " + defurl);
490 desktop.checkForQuestionnaire(defurl);
497 .println("CMD [-noquestionnaire] executed successfully!");
500 if (!aparser.contains(ArgsParser.NONEWS))
502 desktop.checkForNews();
505 BioJsHTMLOutput.updateBioJS();
509 parseArguments(aparser, true);
513 * Allow an outside entity to initiate the second half of argument parsing
517 * @return null is good
520 public Object parseArguments(String[] args)
525 ArgsParser aparser = new ArgsParser(args);
526 return parseArguments(aparser, false);
527 } catch (Throwable t)
539 private Object parseArguments(ArgsParser aparser, boolean isStartup)
541 boolean isJS = Platform.isJS();
543 Desktop desktop = (headless ? null : Desktop.getInstance());
544 // script to execute after all loading is
545 // completed one way or another
546 // extract groovy argument and execute if necessary
547 String groovyscript = (isJS ? null
548 : aparser.getValue(ArgsParser.GROOVY, true));
549 String file = aparser.getValue(ArgsParser.OPEN, true);
550 // BH this here to allow split frame; not working as of 5/17/2019
551 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
552 String fileFormat = (isJavaAppletTag
553 ? aparser.getAppletValue("format", null)
555 FileFormatI format = null;
556 DataSourceType protocol = null;
558 if (file == null && desktop == null)
560 System.out.println("No files to open!");
563 boolean haveImport = checkStartVamas(aparser);
564 // Finally, deal with the remaining input data.
566 if (file == null && isJavaAppletTag)
568 // Maybe the sequences are added as parameters
569 StringBuffer data = new StringBuffer("PASTE");
571 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
573 data.append(file.toString() + "\n");
576 if (data.length() > 5)
578 file = data.toString();
589 desktop.setProgressBar(
591 .getString("status.processing_commandline_args"),
592 progress = System.currentTimeMillis());
597 * ignore in JavaScript -- can't just check file existence - could load
603 if (!file.startsWith("http://") && !file.startsWith("https://"))
604 // BH 2019 added https check for Java
606 if (!(new File(file)).exists())
608 System.out.println("Can't find " + file);
617 protocol = AppletFormatAdapter.checkProtocol(file);
621 format = (isJavaAppletTag && fileFormat != null
622 ? FileFormats.getInstance().forName(fileFormat)
626 format = new IdentifyFile().identify(file, protocol);
628 } catch (FileFormatException e1)
633 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
635 jalview.bin.Cache.setPropertyNoSave(Preferences.SHOW_OVERVIEW,
638 System.out.println("CMD [showoverview] executed successfully!");
641 if (aparser.contains(ArgsParser.NOMENUBAR))
644 System.out.println("CMD [nomenu] executed successfully!");
647 if (aparser.contains(ArgsParser.NOSTATUS))
650 System.out.println("CMD [nostatus] executed successfully!");
653 if (aparser.contains(ArgsParser.NOCALCULATION))
655 noCalculation = true;
656 System.out.println("CMD [nocalculation] executed successfully!");
659 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
663 System.out.println("error");
668 .println("CMD [-open " + file + "] executed successfully!");
671 protocol = AppletFormatAdapter.checkProtocol(file2);
674 format = new IdentifyFile().identify(file2, protocol);
675 } catch (FileFormatException e1)
679 AlignFrame af2 = new FileLoader(!headless)
680 .loadFileWaitTillLoaded(file2, protocol, format);
683 System.out.println("error");
687 AlignViewport.openLinkedAlignmentAs(af,
688 af.getViewport().getAlignment(),
689 af2.getViewport().getAlignment(), "",
690 AlignViewport.SPLIT_FRAME);
692 "CMD [-open2 " + file2 + "] executed successfully!");
696 setCurrentAlignFrame(af);
698 // TODO: file2 How to implement file2 for the applet spit screen?
700 data = aparser.getValue(ArgsParser.COLOUR, true);
703 data.replaceAll("%20", " ");
705 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
706 af.getViewport(), af.getViewport().getAlignment(), data);
711 "CMD [-color " + data + "] executed successfully!");
716 // Must maintain ability to use the groups flag
717 data = aparser.getValue(ArgsParser.GROUPS, true);
720 af.parseFeaturesFile(data,
721 AppletFormatAdapter.checkProtocol(data));
722 // System.out.println("Added " + data);
724 "CMD groups[-" + data + "] executed successfully!");
726 data = aparser.getValue(ArgsParser.FEATURES, true);
729 af.parseFeaturesFile(data,
730 AppletFormatAdapter.checkProtocol(data));
731 // System.out.println("Added " + data);
733 "CMD [-features " + data + "] executed successfully!");
736 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
739 af.loadJalviewDataFile(data, null, null, null);
740 // System.out.println("Added " + data);
742 "CMD [-annotations " + data + "] executed successfully!");
744 // set or clear the sortbytree flag.
745 if (aparser.contains(ArgsParser.SORTBYTREE))
747 af.getViewport().setSortByTree(true);
748 if (af.getViewport().getSortByTree())
750 System.out.println("CMD [-sortbytree] executed successfully!");
754 boolean doUpdateAnnotation = false;
757 if (aparser.contains(ArgsParser.NOANNOTATION)
758 || aparser.contains(ArgsParser.NOANNOTATION2))
760 af.getViewport().setShowAnnotation(false);
761 if (!af.getViewport().isShowAnnotation())
763 doUpdateAnnotation = true;
764 System.out.println("CMD no-annotation executed successfully!");
767 if (aparser.contains(ArgsParser.NOSORTBYTREE))
769 af.getViewport().setSortByTree(false);
770 if (!af.getViewport().getSortByTree())
772 doUpdateAnnotation = true;
774 .println("CMD [-nosortbytree] executed successfully!");
777 if (doUpdateAnnotation)
779 af.setMenusForViewport();
780 af.alignPanel.updateLayout();
782 data = aparser.getValue(ArgsParser.TREE, true);
788 "CMD [-tree " + data + "] executed successfully!");
789 NewickFile nf = new NewickFile(data,
790 AppletFormatAdapter.checkProtocol(data));
792 .setCurrentTree(af.showNewickTree(nf, data).getTree());
793 } catch (IOException ex)
795 System.err.println("Couldn't add tree " + data);
796 ex.printStackTrace(System.err);
799 // TODO - load PDB structure(s) to alignment JAL-629
800 // (associate with identical sequence in alignment, or a specified
804 loadAppletParams(aparser, af);
813 if (groovyscript != null)
815 // Execute the groovy script after we've done all the rendering
817 // and before any images or figures are generated.
818 System.out.println("Executing script " + groovyscript);
819 executeGroovyScript(groovyscript, af);
820 System.out.println("CMD groovy[" + groovyscript
821 + "] executed successfully!");
824 checkOutputFile(aparser, af, format);
825 while (aparser.getSize() > 0)
827 System.out.println("Unknown arg: " + aparser.nextValue());
832 AlignFrame startUpAlframe = null;
833 // We'll only open the default file if the desktop is visible.
835 // ////////////////////
837 if (!isJS && !headless && file == null && !haveImport
838 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
845 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
846 jalview.bin.Cache.getDefault("www.jalview.org",
847 "http://www.jalview.org")
848 + "/examples/exampleFile_2_7.jar");
850 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
852 // hardwire upgrade of the startup file
853 file.replace("_2_3.jar", "_2_7.jar");
854 // and remove the stale setting
855 jalview.bin.Cache.removeProperty("STARTUP_FILE");
858 protocol = DataSourceType.FILE;
860 if (file.indexOf("http:") > -1)
862 protocol = DataSourceType.URL;
865 if (file.endsWith(".jar"))
867 format = FileFormat.Jalview;
873 format = new IdentifyFile().identify(file, protocol);
874 } catch (FileFormatException e)
880 startUpAlframe = new FileLoader(!headless)
881 .loadFileWaitTillLoaded(file, protocol, format);
882 // extract groovy arguments before anything else.
885 // Once all other stuff is done, execute any groovy scripts (in order)
886 if (groovyscript != null)
888 if (Cache.groovyJarsPresent())
890 System.out.println("Executing script " + groovyscript);
891 executeGroovyScript(groovyscript, startUpAlframe);
896 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
900 // and finally, turn off batch mode indicator - if the desktop still exists
905 desktop.setProgressBar(null, progress);
907 desktop.setInBatchMode(false);
913 private boolean checkStartVamas(ArgsParser aparser)
915 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
916 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
917 if (vamsasImport == null && vamsasSession == null)
921 if (desktop == null || headless)
924 "Headless vamsas sessions not yet supported. Sorry.");
927 boolean haveImport = (vamsasImport != null);
930 // if we have a file, start a new session and import it.
931 boolean inSession = false;
934 DataSourceType viprotocol = AppletFormatAdapter
935 .checkProtocol(vamsasImport);
936 if (viprotocol == DataSourceType.FILE)
938 inSession = desktop.vamsasImport(new File(vamsasImport));
940 else if (viprotocol == DataSourceType.URL)
942 inSession = desktop.vamsasImport(new URL(vamsasImport));
945 } catch (Exception e)
947 System.err.println("Exeption when importing " + vamsasImport
948 + " as a vamsas document.");
953 System.err.println("Failed to import " + vamsasImport
954 + " as a vamsas document.");
958 System.out.println("Imported Successfully into new session "
959 + desktop.getVamsasApplication().getCurrentSession());
962 if (vamsasSession != null)
964 if (vamsasImport != null)
966 // close the newly imported session and import the Jalview specific
967 // remnants into the new session later on.
968 desktop.vamsasStop_actionPerformed(null);
970 // now join the new session
973 if (desktop.joinVamsasSession(vamsasSession))
976 "Successfully joined vamsas session " + vamsasSession);
980 System.err.println("WARNING: Failed to join vamsas session "
983 } catch (Exception e)
986 "ERROR: Failed to join vamsas session " + vamsasSession);
989 if (vamsasImport != null)
991 // the Jalview specific remnants can now be imported into the new
992 // session at the user's leisure.
994 "Skipping Push for import of data into existing vamsas session.");
1000 // desktop.getVamsasApplication().push_update();
1006 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
1009 String imageName = "unnamed.png";
1010 while (aparser.getSize() > 1)
1015 // biojsmsa filename
1016 String outputFormat = aparser.nextValue();
1017 String file = aparser.nextValue();
1018 if (outputFormat.equalsIgnoreCase("png"))
1020 af.createPNG(new File(file));
1021 imageName = (new File(file)).getName();
1022 System.out.println("Creating PNG image: " + file);
1025 else if (outputFormat.equalsIgnoreCase("svg"))
1027 File imageFile = new File(file);
1028 imageName = imageFile.getName();
1029 af.createSVG(imageFile);
1030 System.out.println("Creating SVG image: " + file);
1033 else if (outputFormat.equalsIgnoreCase("html"))
1035 File imageFile = new File(file);
1036 imageName = imageFile.getName();
1037 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1038 htmlSVG.exportHTML(file);
1040 System.out.println("Creating HTML image: " + file);
1043 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1047 System.err.println("The output html file must not be null");
1052 BioJsHTMLOutput.refreshVersionInfo(
1053 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1054 } catch (URISyntaxException e)
1056 e.printStackTrace();
1058 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1059 bjs.exportHTML(file);
1060 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1063 else if (outputFormat.equalsIgnoreCase("imgMap"))
1065 af.createImageMap(new File(file), imageName);
1066 System.out.println("Creating image map: " + file);
1069 else if (outputFormat.equalsIgnoreCase("eps"))
1071 File outputFile = new File(file);
1073 "Creating EPS file: " + outputFile.getAbsolutePath());
1074 af.createEPS(outputFile);
1078 af.saveAlignment(file, format);
1079 if (af.isSaveAlignmentSuccessful())
1082 "Written alignment in " + format + " format to " + file);
1086 System.out.println("Error writing file " + file + " in " + format
1093 private static void showUsage()
1096 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1097 + "-nodisplay\tRun Jalview without User Interface.\n"
1098 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1099 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1100 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1101 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1102 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1103 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1104 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1105 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1106 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1107 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1108 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1109 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1110 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1111 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1112 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1113 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1114 + "-html FILE\tCreate HTML file from alignment.\n"
1115 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1116 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1117 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1118 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1119 + "-noquestionnaire\tTurn off questionnaire check.\n"
1120 + "-nonews\tTurn off check for Jalview news.\n"
1121 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1122 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1124 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1125 // after all other properties files have been read\n\t
1126 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1127 // passed in correctly)"
1128 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1129 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1131 // "-vdoc vamsas-document\tImport vamsas document into new
1132 // session or join existing session with same URN\n"
1133 // + "-vses vamsas-session\tJoin session with given URN\n"
1134 + "-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"
1135 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1138 private static void startUsageStats(final Desktop desktop)
1141 * start a User Config prompt asking if we can log usage statistics.
1143 PromptUserConfig prompter = new PromptUserConfig(
1144 Desktop.getDesktopPane(), "USAGESTATS",
1145 "Jalview Usage Statistics",
1146 "Do you want to help make Jalview better by enabling "
1147 + "the collection of usage statistics with Google Analytics ?"
1148 + "\n\n(you can enable or disable usage tracking in the preferences)",
1155 "Initialising googletracker for usage stats.");
1156 Cache.initGoogleTracker();
1157 Cache.log.debug("Tracking enabled.");
1164 Cache.log.debug("Not enabling Google Tracking.");
1167 desktop.addDialogThread(prompter);
1171 * Locate the given string as a file and pass it to the groovy interpreter.
1173 * @param groovyscript
1174 * the script to execute
1175 * @param jalviewContext
1176 * the Jalview Desktop object passed in to the groovy binding as the
1179 private void executeGroovyScript(String groovyscript, AlignFrame af)
1182 * for scripts contained in files
1189 if (groovyscript.trim().equals("STDIN"))
1191 // read from stdin into a tempfile and execute it
1194 tfile = File.createTempFile("jalview", "groovy");
1195 PrintWriter outfile = new PrintWriter(
1196 new OutputStreamWriter(new FileOutputStream(tfile)));
1197 BufferedReader br = new BufferedReader(
1198 new InputStreamReader(System.in));
1200 while ((line = br.readLine()) != null)
1202 outfile.write(line + "\n");
1208 } catch (Exception ex)
1210 System.err.println("Failed to read from STDIN into tempfile "
1211 + ((tfile == null) ? "(tempfile wasn't created)"
1212 : tfile.toString()));
1213 ex.printStackTrace();
1218 sfile = tfile.toURI().toURL();
1219 } catch (Exception x)
1222 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1224 x.printStackTrace();
1232 sfile = new URI(groovyscript).toURL();
1233 } catch (Exception x)
1235 tfile = new File(groovyscript);
1236 if (!tfile.exists())
1238 System.err.println("File '" + groovyscript + "' does not exist.");
1241 if (!tfile.canRead())
1243 System.err.println("File '" + groovyscript + "' cannot be read.");
1246 if (tfile.length() < 1)
1248 System.err.println("File '" + groovyscript + "' is empty.");
1253 sfile = tfile.getAbsoluteFile().toURI().toURL();
1254 } catch (Exception ex)
1256 System.err.println("Failed to create a file URL for "
1257 + tfile.getAbsoluteFile());
1264 Map<String, Object> vbinding = new HashMap<>();
1265 vbinding.put("Jalview", this);
1268 vbinding.put("currentAlFrame", af);
1270 Binding gbinding = new Binding(vbinding);
1271 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1272 gse.run(sfile.toString(), gbinding);
1273 if ("STDIN".equals(groovyscript))
1275 // delete temp file that we made -
1276 // only if it was successfully executed
1279 } catch (Exception e)
1281 System.err.println("Exception Whilst trying to execute file " + sfile
1282 + " as a groovy script.");
1283 e.printStackTrace(System.err);
1288 public AlignFrame[] getAlignFrames()
1290 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1291 : Desktop.getAlignFrames();
1296 * Quit method delegates to Desktop.quit - unless running in headless mode
1297 * when it just ends the JVM
1301 if (jsFunctionExec != null)
1303 jsFunctionExec.tidyUp();
1304 jsFunctionExec = null;
1307 if (desktop != null)
1318 * Get the SwingJS applet ID and combine that with the frameType
1321 * "alignment", "desktop", etc., or null
1324 public static String getAppID(String frameType)
1326 String id = Cache.getProperty("Info.j2sAppletID");
1331 return id + (frameType == null ? "" : "-" + frameType);
1335 * Handle all JalviewLite applet parameters
1340 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1342 JalviewApp app = new JalviewApp()
1347 // These are methods that are in JalviewLite that various classes call
1348 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1350 // them to JalviewLite directly. Some may not be necessary, but they have
1352 // be at least mentioned here, or the classes calling them should
1354 // JalviewLite itself.
1356 private boolean alignPDBStructures; // From JalviewLite; not implemented
1358 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1360 private Hashtable<String, int[]> jshashes;
1363 public String getParameter(String name)
1365 return aparser.getAppletValue(name, null);
1369 public boolean getDefaultParameter(String name, boolean def)
1372 return ((stn = getParameter(name)) == null ? def
1373 : "true".equalsIgnoreCase(stn));
1377 * Get the applet-like document base even though this is an application.
1380 public URL getDocumentBase()
1382 return Platform.getDocumentBase();
1386 * Get the applet-like code base even though this is an application.
1389 public URL getCodeBase()
1391 return Platform.getCodeBase();
1395 public AlignViewportI getViewport()
1397 return af.getViewport();
1405 public boolean parseFeaturesFile(String filename,
1406 DataSourceType protocol)
1408 return af.parseFeaturesFile(filename, protocol);
1416 public boolean loadScoreFile(String sScoreFile) throws IOException
1418 af.loadJalviewDataFile(sScoreFile, null, null, null);
1423 * annotations, jpredfile, jnetfile
1427 public void updateForAnnotations()
1429 af.updateForAnnotations();
1433 public void loadTree(NewickFile fin, String treeFile)
1436 // n/a -- already done by standard Jalview command line processing
1440 public void setAlignPdbStructures(boolean defaultParameter)
1442 alignPDBStructures = true;
1446 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1447 String[] chains, DataSourceType protocol)
1449 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1453 public void setFeatureGroupState(String[] groups, boolean state)
1455 af.setFeatureGroupState(groups, state);
1459 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1460 String[][] chains, String[] protocols)
1463 "Jalview applet interface alignedStructureView not implemented");
1467 public void newFeatureSettings()
1470 "Jalview applet interface newFeatureSettings not implemented");
1473 private Vector<Runnable> jsExecQueue;
1476 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1478 jsFunctionExec = exec;
1479 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1484 public AppletContext getAppletContext()
1486 // TODO Auto-generated method stub
1491 public boolean isJsfallbackEnabled()
1493 // TODO Auto-generated method stub
1498 public JSObject getJSObject()
1500 // TODO Auto-generated method stub
1505 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1507 // TODO Q: what exactly is this? BH
1512 public void updateColoursFromMouseOver(Object source,
1513 MouseOverStructureListener mouseOverStructureListener)
1515 // TODO Auto-generated method stub
1520 public Object[] getSelectionForListener(SequenceGroup seqsel,
1521 ColumnSelection colsel, HiddenColumns hidden,
1522 SelectionSource source, Object alignFrame)
1524 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1525 seqsel, colsel, hidden, source, alignFrame);
1529 public String arrayToSeparatorList(String[] array)
1531 return appLoader.arrayToSeparatorList(array);
1535 public Hashtable<String, int[]> getJSHashes()
1537 return (jshashes == null ? (jshashes = new Hashtable<>())
1542 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1544 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1549 public Object getFrameForSource(VamsasSource source)
1554 if (source instanceof jalview.gui.AlignViewport
1555 && source == (af = getCurrentAlignFrame()).getViewport())
1557 // should be valid if it just generated an event!
1560 // TODO: ensure that if '_af' is specified along with a handler
1561 // function, then only events from that alignFrame are sent to that
1568 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1570 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1575 appLoader = new JalviewAppLoader(true);
1576 appLoader.load(app);
1581 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1584 public String getSelectedSequences()
1586 return getSelectedSequencesFrom(getCurrentAlignFrame());
1591 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1594 public String getSelectedSequences(String sep)
1596 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1601 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1605 public String getSelectedSequencesFrom(AlignFrameI alf)
1607 return getSelectedSequencesFrom(alf, null);
1612 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1613 * .AlignFrame, java.lang.String)
1616 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
1618 return appLoader.getSelectedSequencesFrom(alf, sep);
1623 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1624 * .AlignFrame, java.lang.String)
1627 public void highlight(String sequenceId, String position,
1628 String alignedPosition)
1630 highlightIn(getCurrentAlignFrame(), sequenceId, position,
1635 public void highlightIn(AlignFrameI alf, String sequenceId,
1636 String position, String alignedPosition)
1638 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1642 public void select(String sequenceIds, String columns)
1644 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1648 public void select(String sequenceIds, String columns, String sep)
1650 selectIn(getCurrentAlignFrame(), sequenceIds, columns, sep);
1654 public void selectIn(AlignFrameI alf, String sequenceIds, String columns)
1656 selectIn(alf, sequenceIds, columns, null);
1660 public void selectIn(AlignFrameI alf, String sequenceIds, String columns,
1663 appLoader.selectIn(alf, sequenceIds, columns, sep);
1667 public String getSelectedSequencesAsAlignment(String format,
1670 return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
1675 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1676 String format, String sep)
1678 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1682 public String getAlignmentOrder()
1684 return getAlignmentFrom(getCurrentAlignFrame(), null);
1688 public String getAlignmentOrderFrom(AlignFrameI alf)
1690 return getAlignmentFrom(alf, null);
1694 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
1696 return appLoader.getAlignmentOrderFrom(alf, sep);
1700 public String orderBy(String order, String undoName)
1702 return orderBy(order, undoName, null);
1706 public String orderBy(String order, String undoName, String sep)
1708 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1712 public String orderAlignmentBy(AlignFrameI alf, String order,
1713 String undoName, String sep)
1715 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1719 public String getAlignment(String format)
1721 return getAlignmentFrom(null, format, null);
1725 public String getAlignmentFrom(AlignFrameI alf, String format)
1727 return getAlignmentFrom(alf, format, null);
1731 public String getAlignment(String format, String suffix)
1733 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1737 public String getAlignmentFrom(AlignFrameI alf, String format,
1740 return appLoader.getAlignmentFrom(alf, format, suffix);
1744 public void loadAnnotation(String annotation)
1746 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1750 public void loadAnnotationFrom(AlignFrameI alf, String annotation)
1752 appLoader.loadAnnotationFrom(alf, annotation);
1756 public void loadFeatures(String features, boolean autoenabledisplay)
1758 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1762 public boolean loadFeaturesFrom(AlignFrameI alf, String features,
1763 boolean autoenabledisplay)
1765 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1769 public String getFeatures(String format)
1771 return getFeaturesFrom(getCurrentAlignFrame(), format);
1775 public String getFeaturesFrom(AlignFrameI alf, String format)
1777 return appLoader.getFeaturesFrom(alf, format);
1781 public String getAnnotation()
1783 return getAnnotationFrom(getCurrentAlignFrame());
1787 public String getAnnotationFrom(AlignFrameI alf)
1789 return appLoader.getAnnotationFrom(alf);
1793 public AlignFrameI newView()
1795 return newViewFrom(getCurrentAlignFrame(), null);
1799 public AlignFrameI newView(String name)
1801 return newViewFrom(getCurrentAlignFrame(), name);
1805 public AlignFrameI newViewFrom(AlignFrameI alf)
1807 return newViewFrom(alf, null);
1811 public AlignFrameI newViewFrom(AlignFrameI alf, String name)
1813 return appLoader.newViewFrom(alf, name);
1817 public AlignFrameI loadAlignment(String text, String title)
1819 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1820 AlignFrame.DEFAULT_HEIGHT, title);
1824 public boolean addPdbFile(AlignFrameI alFrame, String sequenceId,
1825 String pdbEntryString, String pdbFile)
1827 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1832 public void scrollViewToIn(AlignFrameI alf, String topRow,
1833 String leftHandColumn)
1835 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1839 public void scrollViewToRowIn(AlignFrameI alf, String topRow)
1841 appLoader.scrollViewToRowIn(alf, topRow);
1845 public void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn)
1847 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1851 public String getFeatureGroups()
1853 return getFeatureGroupsOn(getCurrentAlignFrame());
1857 public String getFeatureGroupsOn(AlignFrameI alf)
1859 return appLoader.getFeatureGroupsOn(alf);
1863 public String getFeatureGroupsOfState(boolean visible)
1865 return getFeatureGroupsOfStateOn(getCurrentAlignFrame(), visible);
1869 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
1871 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1875 public void setFeatureGroupStateOn(AlignFrameI alf, String groups,
1878 setFeatureGroupStateOn(alf, groups, state);
1882 public void setFeatureGroupState(String groups, boolean state)
1884 appLoader.setFeatureGroupStateOn(getCurrentAlignFrame(), groups, state);
1888 public String getSeparator()
1890 return appLoader.getSeparator();
1894 public void setSeparator(String separator)
1896 appLoader.setSeparator(separator);
1900 public String getJsMessage(String messageclass, String viewId)
1902 // see http://www.jalview.org/examples/jalviewLiteJs.html
1907 * Open a new Tree panel on the desktop statically. Params are standard (not
1908 * set by Groovy). No dialog is opened.
1913 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1914 * of sequences selected is inappropriate
1917 public Object openTreePanel(AlignFrame af, String treeType,
1920 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
1924 * public static method for JalviewJS API to open a PCAPanel without
1925 * necessarily using a dialog.
1929 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
1930 * if number of sequences selected is inappropriate
1933 public Object openPcaPanel(AlignFrame af, String modelName)
1935 return CalculationChooser.openPcaPanel(af, modelName, null);
1939 public String getSelectedSequencesAsAlignment(String format,
1942 return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
1947 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1948 String format, boolean suffix)
1950 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
1955 public String arrayToSeparatorList(String[] array)
1957 return appLoader.arrayToSeparatorList(array);
1961 public String[] separatorListToArray(String list)
1963 return appLoader.separatorListToArray(list);
1966 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
1967 //// have a direct connection?
1970 public void setMouseoverListener(String listener)
1972 // TODO Auto-generated method stub
1977 public void setMouseoverListener(AlignFrameI af, String listener)
1979 // TODO Auto-generated method stub
1984 public void setSelectionListener(String listener)
1986 // TODO Auto-generated method stub
1991 public void setSelectionListener(AlignFrameI af, String listener)
1993 // TODO Auto-generated method stub
1998 public void setStructureListener(String listener, String modelSet)
2000 // TODO Auto-generated method stub
2005 public void removeJavascriptListener(AlignFrameI af, String listener)
2007 // TODO Auto-generated method stub
2012 public void mouseOverStructure(String pdbResNum, String chain,
2015 // TODO Auto-generated method stub