2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.AlignCalcWorkerI;
24 import jalview.api.AlignFrameI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.JalviewApp;
27 import jalview.api.StructureSelectionManagerProvider;
28 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.HiddenColumns;
31 import jalview.datamodel.PDBEntry;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.ext.so.SequenceOntology;
35 import jalview.gui.AlignFrame;
36 import jalview.gui.AlignViewport;
37 import jalview.gui.AlignmentPanel;
38 import jalview.gui.CalculationChooser;
39 import jalview.gui.Desktop;
40 import jalview.gui.Preferences;
41 import jalview.gui.PromptUserConfig;
42 import jalview.gui.StructureViewer;
43 import jalview.io.AppletFormatAdapter;
44 import jalview.io.BioJsHTMLOutput;
45 import jalview.io.DataSourceType;
46 import jalview.io.FileFormat;
47 import jalview.io.FileFormatException;
48 import jalview.io.FileFormatI;
49 import jalview.io.FileFormats;
50 import jalview.io.FileLoader;
51 import jalview.io.HtmlSvgOutput;
52 import jalview.io.IdentifyFile;
53 import jalview.io.NewickFile;
54 import jalview.io.gff.SequenceOntologyFactory;
55 import jalview.javascript.JSFunctionExec;
56 import jalview.javascript.MouseOverStructureListener;
57 import jalview.renderer.seqfeatures.FeatureRenderer;
58 import jalview.schemes.ColourSchemeI;
59 import jalview.schemes.ColourSchemeProperty;
60 import jalview.structure.SelectionSource;
61 import jalview.structure.VamsasSource;
62 import jalview.util.MessageManager;
63 import jalview.util.Platform;
64 import jalview.ws.jws2.Jws2Discoverer;
66 import java.applet.AppletContext;
67 import java.io.BufferedReader;
69 import java.io.FileOutputStream;
70 import java.io.IOException;
71 import java.io.InputStreamReader;
72 import java.io.OutputStreamWriter;
73 import java.io.PrintWriter;
74 import java.net.MalformedURLException;
76 import java.net.URISyntaxException;
78 import java.security.AllPermission;
79 import java.security.CodeSource;
80 import java.security.PermissionCollection;
81 import java.security.Permissions;
82 import java.security.Policy;
83 import java.util.HashMap;
84 import java.util.Hashtable;
86 import java.util.Vector;
88 import javax.swing.LookAndFeel;
89 import javax.swing.UIManager;
91 import groovy.lang.Binding;
92 import groovy.util.GroovyScriptEngine;
93 import netscape.javascript.JSObject;
96 * Main class for Jalview Application <br>
98 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
101 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
102 * jalview.bin.Jalview jalview.bin.Jalview
104 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
105 * embellish '*' to e.g. '*.jar')
108 * @version $Revision$
110 public class Jalview implements ApplicationSingletonI, JalviewJSApi
113 public static Jalview getInstance()
115 return (Jalview) ApplicationSingletonProvider
116 .getInstance(Jalview.class);
125 Platform.getURLCommandArguments();
128 private boolean headless;
130 public static boolean isHeadlessMode()
132 return getInstance().headless;
135 private Desktop desktop;
137 private AlignFrame currentAlignFrame;
139 public boolean isJavaAppletTag;
141 public String appletResourcePath;
143 JalviewAppLoader appLoader;
145 protected JSFunctionExec jsFunctionExec;
147 private boolean noCalculation, noMenuBar, noStatus;
149 private boolean noAnnotation;
151 public boolean getStartCalculations()
153 return !noCalculation;
156 public boolean getAllowMenuBar()
161 public boolean getShowStatus()
166 public boolean getShowAnnotation()
168 return !noAnnotation;
171 public static AlignFrame getCurrentAlignFrame()
173 return getInstance().currentAlignFrame;
176 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
178 getInstance().currentAlignFrame = currentAlignFrame;
183 if (!Platform.isJS())
190 // grab all the rights we can for the JVM
191 Policy.setPolicy(new Policy()
194 public PermissionCollection getPermissions(CodeSource codesource)
196 Permissions perms = new Permissions();
197 perms.add(new AllPermission());
202 public void refresh()
210 * keep track of feature fetching tasks.
218 * TODO: generalise to track all jalview events to orchestrate batch
222 private int queued = 0;
224 private int running = 0;
226 public FeatureFetcher()
231 public void addFetcher(final AlignFrame af,
232 final Vector<String> dasSources)
234 final long id = System.currentTimeMillis();
236 final FeatureFetcher us = this;
237 new Thread(new Runnable()
249 af.setProgressBar(MessageManager
250 .getString("status.das_features_being_retrived"), id);
251 af.featureSettings_actionPerformed(null);
252 af.setProgressBar(null, id);
261 public synchronized boolean allFinished()
263 return queued == 0 && running == 0;
269 * main class for Jalview application
272 * open <em>filename</em>
274 public static void main(String[] args)
276 // Platform.startJavaLogging();
277 getInstance().doMain(args);
281 @SuppressWarnings("unused")
285 void doMain(String[] args)
288 boolean isJS = Platform.isJS();
291 Platform.setAppClass(this);
295 System.setSecurityManager(null);
299 .println("Java version: " + System.getProperty("java.version"));
300 System.out.println(System.getProperty("os.arch") + " "
301 + System.getProperty("os.name") + " "
302 + System.getProperty("os.version"));
304 ArgsParser aparser = new ArgsParser(args);
306 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
307 Cache.loadProperties(usrPropsFile);
309 if (aparser.contains(ArgsParser.NODISPLAY)
310 || aparser.contains(ArgsParser.NOGUI)
311 || aparser.contains(ArgsParser.HEADLESS)
312 || "true".equals(System.getProperty("java.awt.headless")))
319 isJavaAppletTag = aparser.isApplet();
322 Preferences.setAppletDefaults();
323 Cache.loadProperties(usrPropsFile); // again, because we
324 // might be changing defaults here?
327 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
328 appletResourcePath = aparser.getValue("Info.resourcePath");
337 if (usrPropsFile != null)
340 "CMD [-props " + usrPropsFile + "] executed successfully!");
343 if (aparser.contains("help") || aparser.contains("h"))
352 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
353 if (jabawsUrl != null)
357 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
359 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
360 } catch (MalformedURLException e)
363 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
368 // check for property setting
369 String defs = aparser.getValue(ArgsParser.SETPROP);
372 int p = defs.indexOf('=');
375 System.err.println("Ignoring invalid setprop argument : " + defs);
379 System.out.println("Executing setprop argument: " + defs);
382 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
385 defs = aparser.getValue(ArgsParser.SETPROP);
387 System.setProperty("http.agent",
388 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
392 } catch (NoClassDefFoundError error)
394 error.printStackTrace();
395 System.out.println("\nEssential logging libraries not found."
396 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
404 if (!isJS && Platform.isWin())
406 UIManager.setLookAndFeel(
407 headless ? "javax.swing.plaf.metal.MetalLookAndFeel"
408 : UIManager.getSystemLookAndFeelClassName());
409 // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
411 } catch (Exception ex)
413 System.err.println("Unexpected Look and Feel Exception");
414 ex.printStackTrace();
416 if (Platform.isAMacAndNotJS())
419 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
421 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
423 System.setProperty("apple.laf.useScreenMenuBar", "true");
424 if (lookAndFeel != null)
428 UIManager.setLookAndFeel(lookAndFeel);
429 } catch (Throwable e)
432 "Failed to set QuaQua look and feel: " + e.toString());
435 if (lookAndFeel == null
436 || !(lookAndFeel.getClass().isAssignableFrom(
437 UIManager.getLookAndFeel().getClass()))
438 || !UIManager.getLookAndFeel().getClass().toString()
439 .toLowerCase().contains("quaqua"))
444 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
445 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
446 } catch (Throwable e)
449 "Failed to reset look and feel: " + e.toString());
455 * configure 'full' SO model if preferences say to,
456 * else use the default (SO Lite)
458 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
460 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
465 desktop = Desktop.getInstance();
466 desktop.setInBatchMode(true); // indicate we are starting up
467 desktop.setVisible(true);
476 desktop.startServiceDiscovery();
477 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
479 startUsageStats(desktop);
483 System.err.println("CMD [-nousagestats] executed successfully!");
486 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
488 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
491 // Start the desktop questionnaire prompter with the specified
493 Cache.log.debug("Starting questionnaire url at " + url);
494 desktop.checkForQuestionnaire(url);
495 System.out.println("CMD questionnaire[-" + url
496 + "] executed successfully!");
500 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
502 // Start the desktop questionnaire prompter with the specified
505 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
507 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
509 "Starting questionnaire with default url: " + defurl);
510 desktop.checkForQuestionnaire(defurl);
517 .println("CMD [-noquestionnaire] executed successfully!");
520 if (!aparser.contains(ArgsParser.NONEWS))
522 desktop.checkForNews();
525 BioJsHTMLOutput.updateBioJS();
529 parseArguments(aparser, true);
533 * Allow an outside entity to initiate the second half of argument parsing
537 * @return null is good
540 public Object parseArguments(String[] args)
545 ArgsParser aparser = new ArgsParser(args);
546 return parseArguments(aparser, false);
547 } catch (Throwable t)
559 private Object parseArguments(ArgsParser aparser, boolean isStartup)
561 boolean isJS = Platform.isJS();
563 Desktop desktop = (headless ? null : Desktop.getInstance());
564 // script to execute after all loading is
565 // completed one way or another
566 // extract groovy argument and execute if necessary
567 String groovyscript = (isJS ? null
568 : aparser.getValue(ArgsParser.GROOVY, true));
569 String file = aparser.getValue(ArgsParser.OPEN, true);
570 // BH this here to allow split frame; not working as of 5/17/2019
571 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
572 String fileFormat = (isJavaAppletTag
573 ? aparser.getAppletValue("format", null)
575 FileFormatI format = null;
576 DataSourceType protocol = null;
578 if (file == null && desktop == null)
580 System.out.println("No files to open!");
583 boolean haveImport = checkStartVamas(aparser);
584 // Finally, deal with the remaining input data.
586 if (file == null && isJavaAppletTag)
588 // Maybe the sequences are added as parameters
589 StringBuffer data = new StringBuffer("PASTE");
591 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
593 data.append(file.toString() + "\n");
596 if (data.length() > 5)
598 file = data.toString();
609 desktop.setProgressBar(
611 .getString("status.processing_commandline_args"),
612 progress = System.currentTimeMillis());
617 * ignore in JavaScript -- can't just check file existence - could load
623 if (!file.startsWith("http://") && !file.startsWith("https://"))
624 // BH 2019 added https check for Java
626 if (!(new File(file)).exists())
628 System.out.println("Can't find " + file);
637 protocol = AppletFormatAdapter.checkProtocol(file);
641 format = (isJavaAppletTag && fileFormat != null
642 ? FileFormats.getInstance().forName(fileFormat)
646 format = new IdentifyFile().identify(file, protocol);
648 } catch (FileFormatException e1)
653 if (aparser.contains(ArgsParser.NOMENUBAR))
656 System.out.println("CMD [nomenu] executed successfully!");
659 if (aparser.contains(ArgsParser.NOSTATUS))
662 System.out.println("CMD [nostatus] executed successfully!");
665 if (aparser.contains(ArgsParser.NOANNOTATION)
666 || aparser.contains(ArgsParser.NOANNOTATION2))
669 System.out.println("CMD no-annotation executed successfully!");
671 if (aparser.contains(ArgsParser.NOCALCULATION))
673 noCalculation = true;
674 System.out.println("CMD [nocalculation] executed successfully!");
677 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
681 System.out.println("error");
686 .println("CMD [-open " + file + "] executed successfully!");
689 protocol = AppletFormatAdapter.checkProtocol(file2);
692 format = new IdentifyFile().identify(file2, protocol);
693 } catch (FileFormatException e1)
697 AlignFrame af2 = new FileLoader(!headless)
698 .loadFileWaitTillLoaded(file2, protocol, format);
701 System.out.println("error");
705 AlignViewport.openLinkedAlignmentAs(af,
706 af.getViewport().getAlignment(),
707 af2.getViewport().getAlignment(), "",
708 AlignViewport.SPLIT_FRAME);
710 "CMD [-open2 " + file2 + "] executed successfully!");
714 setCurrentAlignFrame(af);
716 // TODO: file2 How to implement file2 for the applet spit screen?
718 data = aparser.getValue(ArgsParser.COLOUR, true);
721 data.replaceAll("%20", " ");
723 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
724 af.getViewport(), af.getViewport().getAlignment(), data);
729 "CMD [-color " + data + "] executed successfully!");
734 // Must maintain ability to use the groups flag
735 data = aparser.getValue(ArgsParser.GROUPS, true);
738 af.parseFeaturesFile(data,
739 AppletFormatAdapter.checkProtocol(data));
740 // System.out.println("Added " + data);
742 "CMD groups[-" + data + "] executed successfully!");
744 data = aparser.getValue(ArgsParser.FEATURES, true);
747 af.parseFeaturesFile(data,
748 AppletFormatAdapter.checkProtocol(data));
749 // System.out.println("Added " + data);
751 "CMD [-features " + data + "] executed successfully!");
754 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
757 af.loadJalviewDataFile(data, null, null, null);
758 // System.out.println("Added " + data);
760 "CMD [-annotations " + data + "] executed successfully!");
763 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
765 af.overviewMenuItem_actionPerformed(null);
766 System.out.println("CMD [showoverview] executed successfully!");
769 // set or clear the sortbytree flag.
770 if (aparser.contains(ArgsParser.SORTBYTREE))
772 af.getViewport().setSortByTree(true);
773 if (af.getViewport().getSortByTree())
775 System.out.println("CMD [-sortbytree] executed successfully!");
779 boolean doUpdateAnnotation = false;
782 * we do this earlier in JalviewJS because of a complication with
785 * For now, just fixing this in JalviewJS.
792 if (aparser.contains(ArgsParser.NOANNOTATION)
793 || aparser.contains(ArgsParser.NOANNOTATION2))
795 af.getViewport().setShowAnnotation(false);
796 if (!af.getViewport().isShowAnnotation())
798 doUpdateAnnotation = true;
800 .println("CMD no-annotation executed successfully!");
804 if (aparser.contains(ArgsParser.NOSORTBYTREE))
806 af.getViewport().setSortByTree(false);
807 if (!af.getViewport().getSortByTree())
809 doUpdateAnnotation = true;
811 .println("CMD [-nosortbytree] executed successfully!");
814 if (doUpdateAnnotation)
816 af.setMenusForViewport();
817 af.alignPanel.updateLayout();
819 data = aparser.getValue(ArgsParser.TREE, true);
825 "CMD [-tree " + data + "] executed successfully!");
826 NewickFile nf = new NewickFile(data,
827 AppletFormatAdapter.checkProtocol(data));
829 .setCurrentTree(af.showNewickTree(nf, data).getTree());
830 } catch (IOException ex)
832 System.err.println("Couldn't add tree " + data);
833 ex.printStackTrace(System.err);
836 // TODO - load PDB structure(s) to alignment JAL-629
837 // (associate with identical sequence in alignment, or a specified
841 loadAppletParams(aparser, af);
850 if (groovyscript != null)
852 // Execute the groovy script after we've done all the rendering
854 // and before any images or figures are generated.
855 System.out.println("Executing script " + groovyscript);
856 executeGroovyScript(groovyscript, af);
857 System.out.println("CMD groovy[" + groovyscript
858 + "] executed successfully!");
861 while (aparser.getSize() > 0)
863 System.out.println("Unknown arg: " + aparser.nextValue());
866 checkOutputFile(aparser, af, format);
869 AlignFrame startUpAlframe = null;
870 // We'll only open the default file if the desktop is visible.
872 // ////////////////////
874 if (!isJS && !headless && file == null && !haveImport
875 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
882 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
883 jalview.bin.Cache.getDefault("www.jalview.org",
884 "http://www.jalview.org")
885 + "/examples/exampleFile_2_7.jar");
887 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
889 // hardwire upgrade of the startup file
890 file.replace("_2_3.jar", "_2_7.jar");
891 // and remove the stale setting
892 jalview.bin.Cache.removeProperty("STARTUP_FILE");
895 protocol = DataSourceType.FILE;
897 if (file.indexOf("http:") > -1)
899 protocol = DataSourceType.URL;
902 if (file.endsWith(".jar"))
904 format = FileFormat.Jalview;
910 format = new IdentifyFile().identify(file, protocol);
911 } catch (FileFormatException e)
917 startUpAlframe = new FileLoader(!headless)
918 .loadFileWaitTillLoaded(file, protocol, format);
919 // extract groovy arguments before anything else.
922 // Once all other stuff is done, execute any groovy scripts (in order)
923 if (groovyscript != null)
925 if (Cache.groovyJarsPresent())
927 System.out.println("Executing script " + groovyscript);
928 executeGroovyScript(groovyscript, startUpAlframe);
933 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
937 // and finally, turn off batch mode indicator - if the desktop still exists
942 desktop.setProgressBar(null, progress);
944 desktop.setInBatchMode(false);
950 private boolean checkStartVamas(ArgsParser aparser)
952 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
953 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
954 if (vamsasImport == null && vamsasSession == null)
958 if (desktop == null || headless)
961 "Headless vamsas sessions not yet supported. Sorry.");
964 boolean haveImport = (vamsasImport != null);
967 // if we have a file, start a new session and import it.
968 boolean inSession = false;
971 DataSourceType viprotocol = AppletFormatAdapter
972 .checkProtocol(vamsasImport);
973 if (viprotocol == DataSourceType.FILE)
975 inSession = desktop.vamsasImport(new File(vamsasImport));
977 else if (viprotocol == DataSourceType.URL)
979 inSession = desktop.vamsasImport(new URL(vamsasImport));
982 } catch (Exception e)
984 System.err.println("Exeption when importing " + vamsasImport
985 + " as a vamsas document.");
990 System.err.println("Failed to import " + vamsasImport
991 + " as a vamsas document.");
995 System.out.println("Imported Successfully into new session "
996 + desktop.getVamsasApplication().getCurrentSession());
999 if (vamsasSession != null)
1001 if (vamsasImport != null)
1003 // close the newly imported session and import the Jalview specific
1004 // remnants into the new session later on.
1005 desktop.vamsasStop_actionPerformed(null);
1007 // now join the new session
1010 if (desktop.joinVamsasSession(vamsasSession))
1013 "Successfully joined vamsas session " + vamsasSession);
1017 System.err.println("WARNING: Failed to join vamsas session "
1020 } catch (Exception e)
1023 "ERROR: Failed to join vamsas session " + vamsasSession);
1024 e.printStackTrace();
1026 if (vamsasImport != null)
1028 // the Jalview specific remnants can now be imported into the new
1029 // session at the user's leisure.
1031 "Skipping Push for import of data into existing vamsas session.");
1037 // desktop.getVamsasApplication().push_update();
1043 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
1046 String imageName = "unnamed.png";
1047 while (aparser.getSize() > 1)
1052 // biojsmsa filename
1053 String outputFormat = aparser.nextValue();
1054 String file = aparser.nextValue();
1055 if (outputFormat.equalsIgnoreCase("png"))
1057 af.createPNG(new File(file));
1058 imageName = (new File(file)).getName();
1059 System.out.println("Creating PNG image: " + file);
1062 else if (outputFormat.equalsIgnoreCase("svg"))
1064 File imageFile = new File(file);
1065 imageName = imageFile.getName();
1066 af.createSVG(imageFile);
1067 System.out.println("Creating SVG image: " + file);
1070 else if (outputFormat.equalsIgnoreCase("html"))
1072 File imageFile = new File(file);
1073 imageName = imageFile.getName();
1074 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1075 htmlSVG.exportHTML(file);
1077 System.out.println("Creating HTML image: " + file);
1080 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1084 System.err.println("The output html file must not be null");
1089 BioJsHTMLOutput.refreshVersionInfo(
1090 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1091 } catch (URISyntaxException e)
1093 e.printStackTrace();
1095 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1096 bjs.exportHTML(file);
1097 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1100 else if (outputFormat.equalsIgnoreCase("imgMap"))
1102 af.createImageMap(new File(file), imageName);
1103 System.out.println("Creating image map: " + file);
1106 else if (outputFormat.equalsIgnoreCase("eps"))
1108 File outputFile = new File(file);
1110 "Creating EPS file: " + outputFile.getAbsolutePath());
1111 af.createEPS(outputFile);
1115 af.saveAlignment(file, format);
1116 if (af.isSaveAlignmentSuccessful())
1119 "Written alignment in " + format + " format to " + file);
1123 System.out.println("Error writing file " + file + " in " + format
1130 private static void showUsage()
1133 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1134 + "-nodisplay\tRun Jalview without User Interface.\n"
1135 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1136 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1137 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1138 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1139 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1140 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1141 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1142 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1143 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1144 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1145 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1146 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1147 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1148 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1149 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1150 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1151 + "-html FILE\tCreate HTML file from alignment.\n"
1152 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1153 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1154 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1155 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1156 + "-noquestionnaire\tTurn off questionnaire check.\n"
1157 + "-nonews\tTurn off check for Jalview news.\n"
1158 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1159 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1161 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1162 // after all other properties files have been read\n\t
1163 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1164 // passed in correctly)"
1165 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1166 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1168 // "-vdoc vamsas-document\tImport vamsas document into new
1169 // session or join existing session with same URN\n"
1170 // + "-vses vamsas-session\tJoin session with given URN\n"
1171 + "-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"
1172 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1175 private static void startUsageStats(final Desktop desktop)
1178 * start a User Config prompt asking if we can log usage statistics.
1180 PromptUserConfig prompter = new PromptUserConfig(
1181 Desktop.getDesktopPane(), "USAGESTATS",
1182 "Jalview Usage Statistics",
1183 "Do you want to help make Jalview better by enabling "
1184 + "the collection of usage statistics with Google Analytics ?"
1185 + "\n\n(you can enable or disable usage tracking in the preferences)",
1192 "Initialising googletracker for usage stats.");
1193 Cache.initGoogleTracker();
1194 Cache.log.debug("Tracking enabled.");
1201 Cache.log.debug("Not enabling Google Tracking.");
1204 desktop.addDialogThread(prompter);
1208 * Locate the given string as a file and pass it to the groovy interpreter.
1210 * @param groovyscript
1211 * the script to execute
1212 * @param jalviewContext
1213 * the Jalview Desktop object passed in to the groovy binding as the
1216 private void executeGroovyScript(String groovyscript, AlignFrame af)
1219 * for scripts contained in files
1226 if (groovyscript.trim().equals("STDIN"))
1228 // read from stdin into a tempfile and execute it
1231 tfile = File.createTempFile("jalview", "groovy");
1232 PrintWriter outfile = new PrintWriter(
1233 new OutputStreamWriter(new FileOutputStream(tfile)));
1234 BufferedReader br = new BufferedReader(
1235 new InputStreamReader(System.in));
1237 while ((line = br.readLine()) != null)
1239 outfile.write(line + "\n");
1245 } catch (Exception ex)
1247 System.err.println("Failed to read from STDIN into tempfile "
1248 + ((tfile == null) ? "(tempfile wasn't created)"
1249 : tfile.toString()));
1250 ex.printStackTrace();
1255 sfile = tfile.toURI().toURL();
1256 } catch (Exception x)
1259 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1261 x.printStackTrace();
1269 sfile = new URI(groovyscript).toURL();
1270 } catch (Exception x)
1272 tfile = new File(groovyscript);
1273 if (!tfile.exists())
1275 System.err.println("File '" + groovyscript + "' does not exist.");
1278 if (!tfile.canRead())
1280 System.err.println("File '" + groovyscript + "' cannot be read.");
1283 if (tfile.length() < 1)
1285 System.err.println("File '" + groovyscript + "' is empty.");
1290 sfile = tfile.getAbsoluteFile().toURI().toURL();
1291 } catch (Exception ex)
1293 System.err.println("Failed to create a file URL for "
1294 + tfile.getAbsoluteFile());
1301 Map<String, Object> vbinding = new HashMap<>();
1302 vbinding.put("Jalview", this);
1305 vbinding.put("currentAlFrame", af);
1307 Binding gbinding = new Binding(vbinding);
1308 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1309 gse.run(sfile.toString(), gbinding);
1310 if ("STDIN".equals(groovyscript))
1312 // delete temp file that we made -
1313 // only if it was successfully executed
1316 } catch (Exception e)
1318 System.err.println("Exception Whilst trying to execute file " + sfile
1319 + " as a groovy script.");
1320 e.printStackTrace(System.err);
1325 public AlignFrame[] getAlignFrames()
1327 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1328 : Desktop.getAlignFrames();
1333 * Quit method delegates to Desktop.quit - unless running in headless mode
1334 * when it just ends the JVM
1338 if (jsFunctionExec != null)
1340 jsFunctionExec.tidyUp();
1341 jsFunctionExec = null;
1344 if (desktop != null)
1355 * Get the SwingJS applet ID and combine that with the frameType
1358 * "alignment", "desktop", etc., or null
1361 public static String getAppID(String frameType)
1363 String id = Cache.getProperty("Info.j2sAppletID");
1368 return id + (frameType == null ? "" : "-" + frameType);
1372 * Handle all JalviewLite applet parameters
1377 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1379 JalviewApp app = new JalviewApp()
1384 // These are methods that are in JalviewLite that various classes call
1385 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1387 // them to JalviewLite directly. Some may not be necessary, but they have
1389 // be at least mentioned here, or the classes calling them should
1391 // JalviewLite itself.
1393 private boolean alignPDBStructures; // From JalviewLite; not implemented
1395 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1397 private Hashtable<String, int[]> jshashes;
1400 public String getParameter(String name)
1402 return aparser.getAppletValue(name, null);
1406 public boolean getDefaultParameter(String name, boolean def)
1409 return ((stn = getParameter(name)) == null ? def
1410 : "true".equalsIgnoreCase(stn));
1414 * Get the applet-like document base even though this is an application.
1417 public URL getDocumentBase()
1419 return Platform.getDocumentBase();
1423 * Get the applet-like code base even though this is an application.
1426 public URL getCodeBase()
1428 return Platform.getCodeBase();
1432 public AlignViewportI getViewport()
1434 return af.getViewport();
1442 public boolean parseFeaturesFile(String filename,
1443 DataSourceType protocol)
1445 return af.parseFeaturesFile(filename, protocol);
1453 public boolean loadScoreFile(String sScoreFile) throws IOException
1455 af.loadJalviewDataFile(sScoreFile, null, null, null);
1460 * annotations, jpredfile, jnetfile
1464 public void updateForAnnotations()
1466 af.updateForAnnotations();
1470 public void loadTree(NewickFile fin, String treeFile)
1473 // n/a -- already done by standard Jalview command line processing
1477 public void setAlignPdbStructures(boolean defaultParameter)
1479 alignPDBStructures = true;
1483 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1484 String[] chains, DataSourceType protocol)
1486 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1490 public void setFeatureGroupState(String[] groups, boolean state)
1492 af.setFeatureGroupState(groups, state);
1496 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1497 String[][] chains, String[] protocols)
1500 "Jalview applet interface alignedStructureView not implemented");
1504 public void newFeatureSettings()
1507 "Jalview applet interface newFeatureSettings not implemented");
1510 private Vector<Runnable> jsExecQueue;
1513 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1515 jsFunctionExec = exec;
1516 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1521 public AppletContext getAppletContext()
1523 // TODO Auto-generated method stub
1528 public boolean isJsfallbackEnabled()
1530 // TODO Auto-generated method stub
1535 public JSObject getJSObject()
1537 // TODO Auto-generated method stub
1542 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1544 // TODO Q: what exactly is this? BH
1549 public void updateColoursFromMouseOver(Object source,
1550 MouseOverStructureListener mouseOverStructureListener)
1552 // TODO Auto-generated method stub
1557 public Object[] getSelectionForListener(SequenceGroup seqsel,
1558 ColumnSelection colsel, HiddenColumns hidden,
1559 SelectionSource source, Object alignFrame)
1561 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1562 seqsel, colsel, hidden, source, alignFrame);
1566 public String arrayToSeparatorList(String[] array)
1568 return appLoader.arrayToSeparatorList(array);
1572 public Hashtable<String, int[]> getJSHashes()
1574 return (jshashes == null ? (jshashes = new Hashtable<>())
1579 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1581 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1586 public Object getFrameForSource(VamsasSource source)
1591 if (source instanceof jalview.gui.AlignViewport
1592 && source == (af = getCurrentAlignFrame()).getViewport())
1594 // should be valid if it just generated an event!
1597 // TODO: ensure that if '_af' is specified along with a handler
1598 // function, then only events from that alignFrame are sent to that
1605 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1607 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1612 appLoader = new JalviewAppLoader(true);
1613 appLoader.load(app);
1618 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1621 public String getSelectedSequences()
1623 return getSelectedSequencesFrom(getCurrentAlignFrame());
1628 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1631 public String getSelectedSequences(String sep)
1633 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1638 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1642 public String getSelectedSequencesFrom(AlignFrameI alf)
1644 return getSelectedSequencesFrom(alf, null);
1649 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1650 * .AlignFrame, java.lang.String)
1653 public String getSelectedSequencesFrom(AlignFrameI alf, String sep)
1655 return appLoader.getSelectedSequencesFrom(alf, sep);
1660 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1661 * .AlignFrame, java.lang.String)
1664 public void highlight(String sequenceId, String position,
1665 String alignedPosition)
1667 highlightIn(getCurrentAlignFrame(), sequenceId, position,
1672 public void highlightIn(AlignFrameI alf, String sequenceId,
1673 String position, String alignedPosition)
1675 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1679 public void select(String sequenceIds, String columns)
1681 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1685 public void select(String sequenceIds, String columns, String sep)
1687 selectIn(getCurrentAlignFrame(), sequenceIds, columns, sep);
1691 public void selectIn(AlignFrameI alf, String sequenceIds, String columns)
1693 selectIn(alf, sequenceIds, columns, null);
1697 public void selectIn(AlignFrameI alf, String sequenceIds, String columns,
1700 appLoader.selectIn(alf, sequenceIds, columns, sep);
1704 public String getSelectedSequencesAsAlignment(String format,
1707 return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
1712 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1713 String format, String sep)
1715 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1719 public String getAlignmentOrder()
1721 return getAlignmentFrom(getCurrentAlignFrame(), null);
1725 public String getAlignmentOrderFrom(AlignFrameI alf)
1727 return getAlignmentFrom(alf, null);
1731 public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
1733 return appLoader.getAlignmentOrderFrom(alf, sep);
1737 public String orderBy(String order, String undoName)
1739 return orderBy(order, undoName, null);
1743 public String orderBy(String order, String undoName, String sep)
1745 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1749 public String orderAlignmentBy(AlignFrameI alf, String order,
1750 String undoName, String sep)
1752 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1756 public String getAlignment(String format)
1758 return getAlignmentFrom(null, format, null);
1762 public String getAlignmentFrom(AlignFrameI alf, String format)
1764 return getAlignmentFrom(alf, format, null);
1768 public String getAlignment(String format, String suffix)
1770 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1774 public String getAlignmentFrom(AlignFrameI alf, String format,
1777 return appLoader.getAlignmentFrom(alf, format, suffix);
1781 public void loadAnnotation(String annotation)
1783 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1787 public void loadAnnotationFrom(AlignFrameI alf, String annotation)
1789 appLoader.loadAnnotationFrom(alf, annotation);
1793 public void loadFeatures(String features, boolean autoenabledisplay)
1795 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1799 public boolean loadFeaturesFrom(AlignFrameI alf, String features,
1800 boolean autoenabledisplay)
1802 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1806 public String getFeatures(String format)
1808 return getFeaturesFrom(getCurrentAlignFrame(), format);
1812 public String getFeaturesFrom(AlignFrameI alf, String format)
1814 return appLoader.getFeaturesFrom(alf, format);
1818 public String getAnnotation()
1820 return getAnnotationFrom(getCurrentAlignFrame());
1824 public String getAnnotationFrom(AlignFrameI alf)
1826 return appLoader.getAnnotationFrom(alf);
1830 public AlignFrameI newView()
1832 return newViewFrom(getCurrentAlignFrame(), null);
1836 public AlignFrameI newView(String name)
1838 return newViewFrom(getCurrentAlignFrame(), name);
1842 public AlignFrameI newViewFrom(AlignFrameI alf)
1844 return newViewFrom(alf, null);
1848 public AlignFrameI newViewFrom(AlignFrameI alf, String name)
1850 return appLoader.newViewFrom(alf, name);
1854 public AlignFrameI loadAlignment(String text, String title)
1856 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1857 AlignFrame.DEFAULT_HEIGHT, title);
1861 public boolean addPdbFile(AlignFrameI alFrame, String sequenceId,
1862 String pdbEntryString, String pdbFile)
1864 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1869 public void scrollViewToIn(AlignFrameI alf, String topRow,
1870 String leftHandColumn)
1872 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1876 public void scrollViewToRowIn(AlignFrameI alf, String topRow)
1878 appLoader.scrollViewToRowIn(alf, topRow);
1882 public void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn)
1884 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1888 public String getFeatureGroups()
1890 return getFeatureGroupsOn(getCurrentAlignFrame());
1894 public String getFeatureGroupsOn(AlignFrameI alf)
1896 return appLoader.getFeatureGroupsOn(alf);
1900 public String getFeatureGroupsOfState(boolean visible)
1902 return getFeatureGroupsOfStateOn(getCurrentAlignFrame(), visible);
1906 public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
1908 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1912 public void setFeatureGroupStateOn(AlignFrameI alf, String groups,
1915 setFeatureGroupStateOn(alf, groups, state);
1919 public void setFeatureGroupState(String groups, boolean state)
1921 appLoader.setFeatureGroupStateOn(getCurrentAlignFrame(), groups, state);
1925 public String getSeparator()
1927 return appLoader.getSeparator();
1931 public void setSeparator(String separator)
1933 appLoader.setSeparator(separator);
1937 public String getJsMessage(String messageclass, String viewId)
1939 // see http://www.jalview.org/examples/jalviewLiteJs.html
1944 * Open a new Tree panel on the desktop statically. Params are standard (not
1945 * set by Groovy). No dialog is opened.
1950 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1951 * of sequences selected is inappropriate
1954 public Object openTreePanel(AlignFrame af, String treeType,
1957 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
1961 * public static method for JalviewJS API to open a PCAPanel without
1962 * necessarily using a dialog.
1966 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
1967 * if number of sequences selected is inappropriate
1970 public Object openPcaPanel(AlignFrame af, String modelName)
1972 return CalculationChooser.openPcaPanel(af, modelName, null);
1976 public String getSelectedSequencesAsAlignment(String format,
1979 return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
1984 public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
1985 String format, boolean suffix)
1987 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
1992 public String arrayToSeparatorList(String[] array)
1994 return appLoader.arrayToSeparatorList(array);
1998 public String[] separatorListToArray(String list)
2000 return appLoader.separatorListToArray(list);
2003 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
2004 //// have a direct connection?
2007 public void setMouseoverListener(String listener)
2009 // TODO Auto-generated method stub
2014 public void setMouseoverListener(AlignFrameI af, String listener)
2016 // TODO Auto-generated method stub
2021 public void setSelectionListener(String listener)
2023 // TODO Auto-generated method stub
2028 public void setSelectionListener(AlignFrameI af, String listener)
2030 // TODO Auto-generated method stub
2035 public void setStructureListener(String listener, String modelSet)
2037 // TODO Auto-generated method stub
2042 public void removeJavascriptListener(AlignFrameI af, String listener)
2044 // TODO Auto-generated method stub
2049 public void mouseOverStructure(String pdbResNum, String chain,
2052 // TODO Auto-generated method stub
2057 public void showOverview()
2059 currentAlignFrame.overviewMenuItem_actionPerformed(null);
2062 public void notifyWorker(AlignCalcWorkerI worker, String status)
2064 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()