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 private boolean noAnnotation;
150 public boolean getStartCalculations()
152 return !noCalculation;
155 public boolean getAllowMenuBar()
160 public boolean getShowStatus()
165 public boolean getShowAnnotation()
167 return !noAnnotation;
170 public static AlignFrame getCurrentAlignFrame()
172 return getInstance().currentAlignFrame;
175 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
177 getInstance().currentAlignFrame = currentAlignFrame;
182 if (!Platform.isJS())
189 // grab all the rights we can for the JVM
190 Policy.setPolicy(new Policy()
193 public PermissionCollection getPermissions(CodeSource codesource)
195 Permissions perms = new Permissions();
196 perms.add(new AllPermission());
201 public void refresh()
209 * keep track of feature fetching tasks.
217 * TODO: generalise to track all jalview events to orchestrate batch
221 private int queued = 0;
223 private int running = 0;
225 public FeatureFetcher()
230 public void addFetcher(final AlignFrame af,
231 final Vector<String> dasSources)
233 final long id = System.currentTimeMillis();
235 final FeatureFetcher us = this;
236 new Thread(new Runnable()
248 af.setProgressBar(MessageManager
249 .getString("status.das_features_being_retrived"), id);
250 af.featureSettings_actionPerformed(null);
251 af.setProgressBar(null, id);
260 public synchronized boolean allFinished()
262 return queued == 0 && running == 0;
268 * main class for Jalview application
271 * open <em>filename</em>
273 public static void main(String[] args)
275 // Platform.startJavaLogging();
276 getInstance().doMain(args);
280 @SuppressWarnings("unused")
284 void doMain(String[] args)
287 boolean isJS = Platform.isJS();
290 Platform.setAppClass(this);
294 System.setSecurityManager(null);
298 .println("Java version: " + System.getProperty("java.version"));
299 System.out.println(System.getProperty("os.arch") + " "
300 + System.getProperty("os.name") + " "
301 + System.getProperty("os.version"));
303 ArgsParser aparser = new ArgsParser(args);
305 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
306 Cache.loadProperties(usrPropsFile);
309 isJavaAppletTag = aparser.isApplet();
312 Preferences.setAppletDefaults();
313 Cache.loadProperties(usrPropsFile); // again, because we
314 // might be changing defaults here?
317 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
318 appletResourcePath = aparser.getValue("Info.resourcePath");
327 if (usrPropsFile != null)
330 "CMD [-props " + usrPropsFile + "] executed successfully!");
333 if (aparser.contains("help") || aparser.contains("h"))
338 if (aparser.contains(ArgsParser.NODISPLAY)
339 || aparser.contains(ArgsParser.NOGUI)
340 || aparser.contains(ArgsParser.HEADLESS)
341 || "true".equals(System.getProperty("java.awt.headless")))
348 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
349 if (jabawsUrl != null)
353 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
355 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
356 } catch (MalformedURLException e)
359 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
364 // check for property setting
365 String defs = aparser.getValue(ArgsParser.SETPROP);
368 int p = defs.indexOf('=');
371 System.err.println("Ignoring invalid setprop argument : " + defs);
375 System.out.println("Executing setprop argument: " + defs);
378 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
381 defs = aparser.getValue(ArgsParser.SETPROP);
383 System.setProperty("http.agent",
384 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
388 } catch (NoClassDefFoundError error)
390 error.printStackTrace();
391 System.out.println("\nEssential logging libraries not found."
392 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
400 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
401 } catch (Exception ex)
403 System.err.println("Unexpected Look and Feel Exception");
404 ex.printStackTrace();
406 if (Platform.isAMacAndNotJS())
409 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
411 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
413 System.setProperty("apple.laf.useScreenMenuBar", "true");
414 if (lookAndFeel != null)
418 UIManager.setLookAndFeel(lookAndFeel);
419 } catch (Throwable e)
422 "Failed to set QuaQua look and feel: " + e.toString());
425 if (lookAndFeel == null
426 || !(lookAndFeel.getClass().isAssignableFrom(
427 UIManager.getLookAndFeel().getClass()))
428 || !UIManager.getLookAndFeel().getClass().toString()
429 .toLowerCase().contains("quaqua"))
434 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
435 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
436 } catch (Throwable e)
439 "Failed to reset look and feel: " + e.toString());
445 * configure 'full' SO model if preferences say to,
446 * else use the default (SO Lite)
448 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
450 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
455 desktop = Desktop.getInstance();
456 desktop.setInBatchMode(true); // indicate we are starting up
457 desktop.setVisible(true);
466 desktop.startServiceDiscovery();
467 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
469 startUsageStats(desktop);
473 System.err.println("CMD [-nousagestats] executed successfully!");
476 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
478 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
481 // Start the desktop questionnaire prompter with the specified
483 Cache.log.debug("Starting questionnaire url at " + url);
484 desktop.checkForQuestionnaire(url);
485 System.out.println("CMD questionnaire[-" + url
486 + "] executed successfully!");
490 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
492 // Start the desktop questionnaire prompter with the specified
495 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
497 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
499 "Starting questionnaire with default url: " + defurl);
500 desktop.checkForQuestionnaire(defurl);
507 .println("CMD [-noquestionnaire] executed successfully!");
510 if (!aparser.contains(ArgsParser.NONEWS))
512 desktop.checkForNews();
515 BioJsHTMLOutput.updateBioJS();
519 parseArguments(aparser, true);
523 * Allow an outside entity to initiate the second half of argument parsing
527 * @return null is good
530 public Object parseArguments(String[] args)
535 ArgsParser aparser = new ArgsParser(args);
536 return parseArguments(aparser, false);
537 } catch (Throwable t)
549 private Object parseArguments(ArgsParser aparser, boolean isStartup)
551 boolean isJS = Platform.isJS();
553 Desktop desktop = (headless ? null : Desktop.getInstance());
554 // script to execute after all loading is
555 // completed one way or another
556 // extract groovy argument and execute if necessary
557 String groovyscript = (isJS ? null
558 : aparser.getValue(ArgsParser.GROOVY, true));
559 String file = aparser.getValue(ArgsParser.OPEN, true);
560 // BH this here to allow split frame; not working as of 5/17/2019
561 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
562 String fileFormat = (isJavaAppletTag
563 ? aparser.getAppletValue("format", null)
565 FileFormatI format = null;
566 DataSourceType protocol = null;
568 if (file == null && desktop == null)
570 System.out.println("No files to open!");
573 boolean haveImport = checkStartVamas(aparser);
574 // Finally, deal with the remaining input data.
576 if (file == null && isJavaAppletTag)
578 // Maybe the sequences are added as parameters
579 StringBuffer data = new StringBuffer("PASTE");
581 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
583 data.append(file.toString() + "\n");
586 if (data.length() > 5)
588 file = data.toString();
599 desktop.setProgressBar(
601 .getString("status.processing_commandline_args"),
602 progress = System.currentTimeMillis());
607 * ignore in JavaScript -- can't just check file existence - could load
613 if (!file.startsWith("http://") && !file.startsWith("https://"))
614 // BH 2019 added https check for Java
616 if (!(new File(file)).exists())
618 System.out.println("Can't find " + file);
627 protocol = AppletFormatAdapter.checkProtocol(file);
631 format = (isJavaAppletTag && fileFormat != null
632 ? FileFormats.getInstance().forName(fileFormat)
636 format = new IdentifyFile().identify(file, protocol);
638 } catch (FileFormatException e1)
643 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
645 jalview.bin.Cache.setPropertyNoSave(Preferences.SHOW_OVERVIEW,
648 System.out.println("CMD [showoverview] executed successfully!");
651 if (aparser.contains(ArgsParser.NOMENUBAR))
654 System.out.println("CMD [nomenu] executed successfully!");
657 if (aparser.contains(ArgsParser.NOSTATUS))
660 System.out.println("CMD [nostatus] executed successfully!");
663 if (aparser.contains(ArgsParser.NOANNOTATION)
664 || aparser.contains(ArgsParser.NOANNOTATION2))
667 System.out.println("CMD no-annotation executed successfully!");
669 if (aparser.contains(ArgsParser.NOCALCULATION))
671 noCalculation = true;
672 System.out.println("CMD [nocalculation] executed successfully!");
675 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
679 System.out.println("error");
684 .println("CMD [-open " + file + "] executed successfully!");
687 protocol = AppletFormatAdapter.checkProtocol(file2);
690 format = new IdentifyFile().identify(file2, protocol);
691 } catch (FileFormatException e1)
695 AlignFrame af2 = new FileLoader(!headless)
696 .loadFileWaitTillLoaded(file2, protocol, format);
699 System.out.println("error");
703 AlignViewport.openLinkedAlignmentAs(af,
704 af.getViewport().getAlignment(),
705 af2.getViewport().getAlignment(), "",
706 AlignViewport.SPLIT_FRAME);
708 "CMD [-open2 " + file2 + "] executed successfully!");
712 setCurrentAlignFrame(af);
714 // TODO: file2 How to implement file2 for the applet spit screen?
716 data = aparser.getValue(ArgsParser.COLOUR, true);
719 data.replaceAll("%20", " ");
721 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
722 af.getViewport(), af.getViewport().getAlignment(), data);
727 "CMD [-color " + data + "] executed successfully!");
732 // Must maintain ability to use the groups flag
733 data = aparser.getValue(ArgsParser.GROUPS, true);
736 af.parseFeaturesFile(data,
737 AppletFormatAdapter.checkProtocol(data));
738 // System.out.println("Added " + data);
740 "CMD groups[-" + data + "] executed successfully!");
742 data = aparser.getValue(ArgsParser.FEATURES, true);
745 af.parseFeaturesFile(data,
746 AppletFormatAdapter.checkProtocol(data));
747 // System.out.println("Added " + data);
749 "CMD [-features " + data + "] executed successfully!");
752 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
755 af.loadJalviewDataFile(data, null, null, null);
756 // System.out.println("Added " + data);
758 "CMD [-annotations " + data + "] executed successfully!");
760 // set or clear the sortbytree flag.
761 if (aparser.contains(ArgsParser.SORTBYTREE))
763 af.getViewport().setSortByTree(true);
764 if (af.getViewport().getSortByTree())
766 System.out.println("CMD [-sortbytree] executed successfully!");
770 boolean doUpdateAnnotation = false;
773 * we do this earlier in JalviewJS because of a complication with
776 * For now, just fixing this in JalviewJS.
783 if (aparser.contains(ArgsParser.NOANNOTATION)
784 || aparser.contains(ArgsParser.NOANNOTATION2))
786 af.getViewport().setShowAnnotation(false);
787 if (!af.getViewport().isShowAnnotation())
789 doUpdateAnnotation = true;
791 .println("CMD no-annotation executed successfully!");
795 if (aparser.contains(ArgsParser.NOSORTBYTREE))
797 af.getViewport().setSortByTree(false);
798 if (!af.getViewport().getSortByTree())
800 doUpdateAnnotation = true;
802 .println("CMD [-nosortbytree] executed successfully!");
805 if (doUpdateAnnotation)
807 af.setMenusForViewport();
808 af.alignPanel.updateLayout();
810 data = aparser.getValue(ArgsParser.TREE, true);
816 "CMD [-tree " + data + "] executed successfully!");
817 NewickFile nf = new NewickFile(data,
818 AppletFormatAdapter.checkProtocol(data));
820 .setCurrentTree(af.showNewickTree(nf, data).getTree());
821 } catch (IOException ex)
823 System.err.println("Couldn't add tree " + data);
824 ex.printStackTrace(System.err);
827 // TODO - load PDB structure(s) to alignment JAL-629
828 // (associate with identical sequence in alignment, or a specified
832 loadAppletParams(aparser, af);
841 if (groovyscript != null)
843 // Execute the groovy script after we've done all the rendering
845 // and before any images or figures are generated.
846 System.out.println("Executing script " + groovyscript);
847 executeGroovyScript(groovyscript, af);
848 System.out.println("CMD groovy[" + groovyscript
849 + "] executed successfully!");
852 checkOutputFile(aparser, af, format);
853 while (aparser.getSize() > 0)
855 System.out.println("Unknown arg: " + aparser.nextValue());
860 AlignFrame startUpAlframe = null;
861 // We'll only open the default file if the desktop is visible.
863 // ////////////////////
865 if (!isJS && !headless && file == null && !haveImport
866 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
873 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
874 jalview.bin.Cache.getDefault("www.jalview.org",
875 "http://www.jalview.org")
876 + "/examples/exampleFile_2_7.jar");
878 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
880 // hardwire upgrade of the startup file
881 file.replace("_2_3.jar", "_2_7.jar");
882 // and remove the stale setting
883 jalview.bin.Cache.removeProperty("STARTUP_FILE");
886 protocol = DataSourceType.FILE;
888 if (file.indexOf("http:") > -1)
890 protocol = DataSourceType.URL;
893 if (file.endsWith(".jar"))
895 format = FileFormat.Jalview;
901 format = new IdentifyFile().identify(file, protocol);
902 } catch (FileFormatException e)
908 startUpAlframe = new FileLoader(!headless)
909 .loadFileWaitTillLoaded(file, protocol, format);
910 // extract groovy arguments before anything else.
913 // Once all other stuff is done, execute any groovy scripts (in order)
914 if (groovyscript != null)
916 if (Cache.groovyJarsPresent())
918 System.out.println("Executing script " + groovyscript);
919 executeGroovyScript(groovyscript, startUpAlframe);
924 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
928 // and finally, turn off batch mode indicator - if the desktop still exists
933 desktop.setProgressBar(null, progress);
935 desktop.setInBatchMode(false);
941 private boolean checkStartVamas(ArgsParser aparser)
943 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
944 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
945 if (vamsasImport == null && vamsasSession == null)
949 if (desktop == null || headless)
952 "Headless vamsas sessions not yet supported. Sorry.");
955 boolean haveImport = (vamsasImport != null);
958 // if we have a file, start a new session and import it.
959 boolean inSession = false;
962 DataSourceType viprotocol = AppletFormatAdapter
963 .checkProtocol(vamsasImport);
964 if (viprotocol == DataSourceType.FILE)
966 inSession = desktop.vamsasImport(new File(vamsasImport));
968 else if (viprotocol == DataSourceType.URL)
970 inSession = desktop.vamsasImport(new URL(vamsasImport));
973 } catch (Exception e)
975 System.err.println("Exeption when importing " + vamsasImport
976 + " as a vamsas document.");
981 System.err.println("Failed to import " + vamsasImport
982 + " as a vamsas document.");
986 System.out.println("Imported Successfully into new session "
987 + desktop.getVamsasApplication().getCurrentSession());
990 if (vamsasSession != null)
992 if (vamsasImport != null)
994 // close the newly imported session and import the Jalview specific
995 // remnants into the new session later on.
996 desktop.vamsasStop_actionPerformed(null);
998 // now join the new session
1001 if (desktop.joinVamsasSession(vamsasSession))
1004 "Successfully joined vamsas session " + vamsasSession);
1008 System.err.println("WARNING: Failed to join vamsas session "
1011 } catch (Exception e)
1014 "ERROR: Failed to join vamsas session " + vamsasSession);
1015 e.printStackTrace();
1017 if (vamsasImport != null)
1019 // the Jalview specific remnants can now be imported into the new
1020 // session at the user's leisure.
1022 "Skipping Push for import of data into existing vamsas session.");
1028 // desktop.getVamsasApplication().push_update();
1034 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
1037 String imageName = "unnamed.png";
1038 while (aparser.getSize() > 1)
1043 // biojsmsa filename
1044 String outputFormat = aparser.nextValue();
1045 String file = aparser.nextValue();
1046 if (outputFormat.equalsIgnoreCase("png"))
1048 af.createPNG(new File(file));
1049 imageName = (new File(file)).getName();
1050 System.out.println("Creating PNG image: " + file);
1053 else if (outputFormat.equalsIgnoreCase("svg"))
1055 File imageFile = new File(file);
1056 imageName = imageFile.getName();
1057 af.createSVG(imageFile);
1058 System.out.println("Creating SVG image: " + file);
1061 else if (outputFormat.equalsIgnoreCase("html"))
1063 File imageFile = new File(file);
1064 imageName = imageFile.getName();
1065 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1066 htmlSVG.exportHTML(file);
1068 System.out.println("Creating HTML image: " + file);
1071 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1075 System.err.println("The output html file must not be null");
1080 BioJsHTMLOutput.refreshVersionInfo(
1081 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1082 } catch (URISyntaxException e)
1084 e.printStackTrace();
1086 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1087 bjs.exportHTML(file);
1088 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1091 else if (outputFormat.equalsIgnoreCase("imgMap"))
1093 af.createImageMap(new File(file), imageName);
1094 System.out.println("Creating image map: " + file);
1097 else if (outputFormat.equalsIgnoreCase("eps"))
1099 File outputFile = new File(file);
1101 "Creating EPS file: " + outputFile.getAbsolutePath());
1102 af.createEPS(outputFile);
1106 af.saveAlignment(file, format);
1107 if (af.isSaveAlignmentSuccessful())
1110 "Written alignment in " + format + " format to " + file);
1114 System.out.println("Error writing file " + file + " in " + format
1121 private static void showUsage()
1124 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1125 + "-nodisplay\tRun Jalview without User Interface.\n"
1126 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1127 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1128 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1129 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1130 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1131 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1132 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1133 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1134 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1135 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1136 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1137 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1138 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1139 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1140 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1141 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1142 + "-html FILE\tCreate HTML file from alignment.\n"
1143 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1144 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1145 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1146 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1147 + "-noquestionnaire\tTurn off questionnaire check.\n"
1148 + "-nonews\tTurn off check for Jalview news.\n"
1149 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1150 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1152 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1153 // after all other properties files have been read\n\t
1154 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1155 // passed in correctly)"
1156 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1157 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1159 // "-vdoc vamsas-document\tImport vamsas document into new
1160 // session or join existing session with same URN\n"
1161 // + "-vses vamsas-session\tJoin session with given URN\n"
1162 + "-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"
1163 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1166 private static void startUsageStats(final Desktop desktop)
1169 * start a User Config prompt asking if we can log usage statistics.
1171 PromptUserConfig prompter = new PromptUserConfig(
1172 Desktop.getDesktopPane(), "USAGESTATS",
1173 "Jalview Usage Statistics",
1174 "Do you want to help make Jalview better by enabling "
1175 + "the collection of usage statistics with Google Analytics ?"
1176 + "\n\n(you can enable or disable usage tracking in the preferences)",
1183 "Initialising googletracker for usage stats.");
1184 Cache.initGoogleTracker();
1185 Cache.log.debug("Tracking enabled.");
1192 Cache.log.debug("Not enabling Google Tracking.");
1195 desktop.addDialogThread(prompter);
1199 * Locate the given string as a file and pass it to the groovy interpreter.
1201 * @param groovyscript
1202 * the script to execute
1203 * @param jalviewContext
1204 * the Jalview Desktop object passed in to the groovy binding as the
1207 private void executeGroovyScript(String groovyscript, AlignFrame af)
1210 * for scripts contained in files
1217 if (groovyscript.trim().equals("STDIN"))
1219 // read from stdin into a tempfile and execute it
1222 tfile = File.createTempFile("jalview", "groovy");
1223 PrintWriter outfile = new PrintWriter(
1224 new OutputStreamWriter(new FileOutputStream(tfile)));
1225 BufferedReader br = new BufferedReader(
1226 new InputStreamReader(System.in));
1228 while ((line = br.readLine()) != null)
1230 outfile.write(line + "\n");
1236 } catch (Exception ex)
1238 System.err.println("Failed to read from STDIN into tempfile "
1239 + ((tfile == null) ? "(tempfile wasn't created)"
1240 : tfile.toString()));
1241 ex.printStackTrace();
1246 sfile = tfile.toURI().toURL();
1247 } catch (Exception x)
1250 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1252 x.printStackTrace();
1260 sfile = new URI(groovyscript).toURL();
1261 } catch (Exception x)
1263 tfile = new File(groovyscript);
1264 if (!tfile.exists())
1266 System.err.println("File '" + groovyscript + "' does not exist.");
1269 if (!tfile.canRead())
1271 System.err.println("File '" + groovyscript + "' cannot be read.");
1274 if (tfile.length() < 1)
1276 System.err.println("File '" + groovyscript + "' is empty.");
1281 sfile = tfile.getAbsoluteFile().toURI().toURL();
1282 } catch (Exception ex)
1284 System.err.println("Failed to create a file URL for "
1285 + tfile.getAbsoluteFile());
1292 Map<String, Object> vbinding = new HashMap<>();
1293 vbinding.put("Jalview", this);
1296 vbinding.put("currentAlFrame", af);
1298 Binding gbinding = new Binding(vbinding);
1299 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1300 gse.run(sfile.toString(), gbinding);
1301 if ("STDIN".equals(groovyscript))
1303 // delete temp file that we made -
1304 // only if it was successfully executed
1307 } catch (Exception e)
1309 System.err.println("Exception Whilst trying to execute file " + sfile
1310 + " as a groovy script.");
1311 e.printStackTrace(System.err);
1316 public AlignFrame[] getAlignFrames()
1318 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1319 : Desktop.getAlignFrames();
1324 * Quit method delegates to Desktop.quit - unless running in headless mode
1325 * when it just ends the JVM
1329 if (jsFunctionExec != null)
1331 jsFunctionExec.tidyUp();
1332 jsFunctionExec = null;
1335 if (desktop != null)
1346 * Get the SwingJS applet ID and combine that with the frameType
1349 * "alignment", "desktop", etc., or null
1352 public static String getAppID(String frameType)
1354 String id = Cache.getProperty("Info.j2sAppletID");
1359 return id + (frameType == null ? "" : "-" + frameType);
1363 * Handle all JalviewLite applet parameters
1368 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1370 JalviewApp app = new JalviewApp()
1375 // These are methods that are in JalviewLite that various classes call
1376 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1378 // them to JalviewLite directly. Some may not be necessary, but they have
1380 // be at least mentioned here, or the classes calling them should
1382 // JalviewLite itself.
1384 private boolean alignPDBStructures; // From JalviewLite; not implemented
1386 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1388 private Hashtable<String, int[]> jshashes;
1391 public String getParameter(String name)
1393 return aparser.getAppletValue(name, null);
1397 public boolean getDefaultParameter(String name, boolean def)
1400 return ((stn = getParameter(name)) == null ? def
1401 : "true".equalsIgnoreCase(stn));
1405 * Get the applet-like document base even though this is an application.
1408 public URL getDocumentBase()
1410 return Platform.getDocumentBase();
1414 * Get the applet-like code base even though this is an application.
1417 public URL getCodeBase()
1419 return Platform.getCodeBase();
1423 public AlignViewportI getViewport()
1425 return af.getViewport();
1433 public boolean parseFeaturesFile(String filename,
1434 DataSourceType protocol)
1436 return af.parseFeaturesFile(filename, protocol);
1444 public boolean loadScoreFile(String sScoreFile) throws IOException
1446 af.loadJalviewDataFile(sScoreFile, null, null, null);
1451 * annotations, jpredfile, jnetfile
1455 public void updateForAnnotations()
1457 af.updateForAnnotations();
1461 public void loadTree(NewickFile fin, String treeFile)
1464 // n/a -- already done by standard Jalview command line processing
1468 public void setAlignPdbStructures(boolean defaultParameter)
1470 alignPDBStructures = true;
1474 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1475 String[] chains, DataSourceType protocol)
1477 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1481 public void setFeatureGroupState(String[] groups, boolean state)
1483 af.setFeatureGroupState(groups, state);
1487 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1488 String[][] chains, String[] protocols)
1491 "Jalview applet interface alignedStructureView not implemented");
1495 public void newFeatureSettings()
1498 "Jalview applet interface newFeatureSettings not implemented");
1501 private Vector<Runnable> jsExecQueue;
1504 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1506 jsFunctionExec = exec;
1507 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1512 public AppletContext getAppletContext()
1514 // TODO Auto-generated method stub
1519 public boolean isJsfallbackEnabled()
1521 // TODO Auto-generated method stub
1526 public JSObject getJSObject()
1528 // TODO Auto-generated method stub
1533 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1535 // TODO Q: what exactly is this? BH
1540 public void updateColoursFromMouseOver(Object source,
1541 MouseOverStructureListener mouseOverStructureListener)
1543 // TODO Auto-generated method stub
1548 public Object[] getSelectionForListener(SequenceGroup seqsel,
1549 ColumnSelection colsel, HiddenColumns hidden,
1550 SelectionSource source, Object alignFrame)
1552 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1553 seqsel, colsel, hidden, source, alignFrame);
1557 public String arrayToSeparatorList(String[] array)
1559 return appLoader.arrayToSeparatorList(array);
1563 public Hashtable<String, int[]> getJSHashes()
1565 return (jshashes == null ? (jshashes = new Hashtable<>())
1570 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1572 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1577 public Object getFrameForSource(VamsasSource source)
1582 if (source instanceof jalview.gui.AlignViewport
1583 && source == (af = getCurrentAlignFrame()).getViewport())
1585 // should be valid if it just generated an event!
1588 // TODO: ensure that if '_af' is specified along with a handler
1589 // function, then only events from that alignFrame are sent to that
1596 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1598 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1603 appLoader = new JalviewAppLoader(true);
1604 appLoader.load(app);
1609 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1612 public String getSelectedSequences()
1614 return getSelectedSequencesFrom(getCurrentAlignFrame());
1619 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1622 public String getSelectedSequences(String sep)
1624 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1629 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1633 public String getSelectedSequencesFrom(AlignFrameI alf)
1635 return getSelectedSequencesFrom(alf, null);
1640 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1641 * .AlignFrame, java.lang.String)
1644 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
1646 return appLoader.getSelectedSequencesFrom(alf, sep);
1651 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1652 * .AlignFrame, java.lang.String)
1655 public void highlight(String sequenceId, String position,
1656 String alignedPosition)
1658 highlightIn(getCurrentAlignFrame(), sequenceId, position,
1663 public void highlightIn(AlignFrameI alf, String sequenceId,
1664 String position, String alignedPosition)
1666 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1670 public void select(String sequenceIds, String columns)
1672 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1676 public void select(String sequenceIds, String columns, String sep)
1678 selectIn(getCurrentAlignFrame(), sequenceIds, columns, sep);
1682 public void selectIn(AlignFrameI alf, String sequenceIds, String columns)
1684 selectIn(alf, sequenceIds, columns, null);
1688 public void selectIn(AlignFrameI alf, String sequenceIds, String columns,
1691 appLoader.selectIn(alf, sequenceIds, columns, sep);
1695 public String getSelectedSequencesAsAlignment(String format,
1698 return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
1703 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1704 String format, String sep)
1706 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1710 public String getAlignmentOrder()
1712 return getAlignmentFrom(getCurrentAlignFrame(), null);
1716 public String getAlignmentOrderFrom(AlignFrameI alf)
1718 return getAlignmentFrom(alf, null);
1722 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
1724 return appLoader.getAlignmentOrderFrom(alf, sep);
1728 public String orderBy(String order, String undoName)
1730 return orderBy(order, undoName, null);
1734 public String orderBy(String order, String undoName, String sep)
1736 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1740 public String orderAlignmentBy(AlignFrameI alf, String order,
1741 String undoName, String sep)
1743 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1747 public String getAlignment(String format)
1749 return getAlignmentFrom(null, format, null);
1753 public String getAlignmentFrom(AlignFrameI alf, String format)
1755 return getAlignmentFrom(alf, format, null);
1759 public String getAlignment(String format, String suffix)
1761 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1765 public String getAlignmentFrom(AlignFrameI alf, String format,
1768 return appLoader.getAlignmentFrom(alf, format, suffix);
1772 public void loadAnnotation(String annotation)
1774 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1778 public void loadAnnotationFrom(AlignFrameI alf, String annotation)
1780 appLoader.loadAnnotationFrom(alf, annotation);
1784 public void loadFeatures(String features, boolean autoenabledisplay)
1786 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1790 public boolean loadFeaturesFrom(AlignFrameI alf, String features,
1791 boolean autoenabledisplay)
1793 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1797 public String getFeatures(String format)
1799 return getFeaturesFrom(getCurrentAlignFrame(), format);
1803 public String getFeaturesFrom(AlignFrameI alf, String format)
1805 return appLoader.getFeaturesFrom(alf, format);
1809 public String getAnnotation()
1811 return getAnnotationFrom(getCurrentAlignFrame());
1815 public String getAnnotationFrom(AlignFrameI alf)
1817 return appLoader.getAnnotationFrom(alf);
1821 public AlignFrameI newView()
1823 return newViewFrom(getCurrentAlignFrame(), null);
1827 public AlignFrameI newView(String name)
1829 return newViewFrom(getCurrentAlignFrame(), name);
1833 public AlignFrameI newViewFrom(AlignFrameI alf)
1835 return newViewFrom(alf, null);
1839 public AlignFrameI newViewFrom(AlignFrameI alf, String name)
1841 return appLoader.newViewFrom(alf, name);
1845 public AlignFrameI loadAlignment(String text, String title)
1847 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1848 AlignFrame.DEFAULT_HEIGHT, title);
1852 public boolean addPdbFile(AlignFrameI alFrame, String sequenceId,
1853 String pdbEntryString, String pdbFile)
1855 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1860 public void scrollViewToIn(AlignFrameI alf, String topRow,
1861 String leftHandColumn)
1863 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1867 public void scrollViewToRowIn(AlignFrameI alf, String topRow)
1869 appLoader.scrollViewToRowIn(alf, topRow);
1873 public void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn)
1875 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1879 public String getFeatureGroups()
1881 return getFeatureGroupsOn(getCurrentAlignFrame());
1885 public String getFeatureGroupsOn(AlignFrameI alf)
1887 return appLoader.getFeatureGroupsOn(alf);
1891 public String getFeatureGroupsOfState(boolean visible)
1893 return getFeatureGroupsOfStateOn(getCurrentAlignFrame(), visible);
1897 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
1899 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1903 public void setFeatureGroupStateOn(AlignFrameI alf, String groups,
1906 setFeatureGroupStateOn(alf, groups, state);
1910 public void setFeatureGroupState(String groups, boolean state)
1912 appLoader.setFeatureGroupStateOn(getCurrentAlignFrame(), groups, state);
1916 public String getSeparator()
1918 return appLoader.getSeparator();
1922 public void setSeparator(String separator)
1924 appLoader.setSeparator(separator);
1928 public String getJsMessage(String messageclass, String viewId)
1930 // see http://www.jalview.org/examples/jalviewLiteJs.html
1935 * Open a new Tree panel on the desktop statically. Params are standard (not
1936 * set by Groovy). No dialog is opened.
1941 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1942 * of sequences selected is inappropriate
1945 public Object openTreePanel(AlignFrame af, String treeType,
1948 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
1952 * public static method for JalviewJS API to open a PCAPanel without
1953 * necessarily using a dialog.
1957 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
1958 * if number of sequences selected is inappropriate
1961 public Object openPcaPanel(AlignFrame af, String modelName)
1963 return CalculationChooser.openPcaPanel(af, modelName, null);
1967 public String getSelectedSequencesAsAlignment(String format,
1970 return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
1975 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1976 String format, boolean suffix)
1978 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
1983 public String arrayToSeparatorList(String[] array)
1985 return appLoader.arrayToSeparatorList(array);
1989 public String[] separatorListToArray(String list)
1991 return appLoader.separatorListToArray(list);
1994 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
1995 //// have a direct connection?
1998 public void setMouseoverListener(String listener)
2000 // TODO Auto-generated method stub
2005 public void setMouseoverListener(AlignFrameI af, String listener)
2007 // TODO Auto-generated method stub
2012 public void setSelectionListener(String listener)
2014 // TODO Auto-generated method stub
2019 public void setSelectionListener(AlignFrameI af, String listener)
2021 // TODO Auto-generated method stub
2026 public void setStructureListener(String listener, String modelSet)
2028 // TODO Auto-generated method stub
2033 public void removeJavascriptListener(AlignFrameI af, String listener)
2035 // TODO Auto-generated method stub
2040 public void mouseOverStructure(String pdbResNum, String chain,
2043 // TODO Auto-generated method stub