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.Desktop;
38 import jalview.gui.Preferences;
39 import jalview.gui.PromptUserConfig;
40 import jalview.gui.StructureViewer;
41 import jalview.io.AppletFormatAdapter;
42 import jalview.io.BioJsHTMLOutput;
43 import jalview.io.DataSourceType;
44 import jalview.io.FileFormat;
45 import jalview.io.FileFormatException;
46 import jalview.io.FileFormatI;
47 import jalview.io.FileFormats;
48 import jalview.io.FileLoader;
49 import jalview.io.HtmlSvgOutput;
50 import jalview.io.IdentifyFile;
51 import jalview.io.NewickFile;
52 import jalview.io.gff.SequenceOntologyFactory;
53 import jalview.javascript.JSFunctionExec;
54 import jalview.javascript.JalviewLiteJsApi;
55 import jalview.javascript.MouseOverStructureListener;
56 import jalview.renderer.seqfeatures.FeatureRenderer;
57 import jalview.schemes.ColourSchemeI;
58 import jalview.schemes.ColourSchemeProperty;
59 import jalview.structure.SelectionSource;
60 import jalview.structure.VamsasSource;
61 import jalview.util.MessageManager;
62 import jalview.util.Platform;
63 import jalview.ws.jws2.Jws2Discoverer;
65 import java.applet.AppletContext;
66 import java.io.BufferedReader;
68 import java.io.FileOutputStream;
69 import java.io.IOException;
70 import java.io.InputStreamReader;
71 import java.io.OutputStreamWriter;
72 import java.io.PrintWriter;
73 import java.net.MalformedURLException;
75 import java.net.URISyntaxException;
77 import java.security.AllPermission;
78 import java.security.CodeSource;
79 import java.security.PermissionCollection;
80 import java.security.Permissions;
81 import java.security.Policy;
82 import java.util.HashMap;
83 import java.util.Hashtable;
85 import java.util.Vector;
86 import java.util.logging.ConsoleHandler;
87 import java.util.logging.Level;
88 import java.util.logging.Logger;
90 import javax.swing.LookAndFeel;
91 import javax.swing.UIManager;
93 import groovy.lang.Binding;
94 import groovy.util.GroovyScriptEngine;
95 import netscape.javascript.JSObject;
98 * Main class for Jalview Application <br>
100 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
101 * jalview.bin.Jalview
103 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
104 * jalview.bin.Jalview jalview.bin.Jalview
106 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
107 * embellish '*' to e.g. '*.jar')
110 * @version $Revision$
112 public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi
115 public static Jalview getInstance()
117 return (Jalview) ApplicationSingletonProvider
118 .getInstance(Jalview.class);
127 Platform.getURLCommandArguments();
130 private boolean headless;
132 public static boolean isHeadlessMode()
134 return getInstance().headless;
137 private Desktop desktop;
139 private AlignFrame currentAlignFrame;
141 public boolean isJavaAppletTag;
143 public String appletResourcePath;
145 private JalviewAppLoader appLoader;
147 protected JSFunctionExec jsFunctionExec;
149 public static AlignFrame getCurrentAlignFrame()
151 return getInstance().currentAlignFrame;
154 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
156 getInstance().currentAlignFrame = currentAlignFrame;
161 if (!Platform.isJS())
168 // grab all the rights we can for the JVM
169 Policy.setPolicy(new Policy()
172 public PermissionCollection getPermissions(CodeSource codesource)
174 Permissions perms = new Permissions();
175 perms.add(new AllPermission());
180 public void refresh()
188 * keep track of feature fetching tasks.
196 * TODO: generalise to track all jalview events to orchestrate batch
200 private int queued = 0;
202 private int running = 0;
204 public FeatureFetcher()
209 public void addFetcher(final AlignFrame af,
210 final Vector<String> dasSources)
212 final long id = System.currentTimeMillis();
214 final FeatureFetcher us = this;
215 new Thread(new Runnable()
227 af.setProgressBar(MessageManager
228 .getString("status.das_features_being_retrived"), id);
229 af.featureSettings_actionPerformed(null);
230 af.setProgressBar(null, id);
239 public synchronized boolean allFinished()
241 return queued == 0 && running == 0;
247 * main class for Jalview application
250 * open <em>filename</em>
252 public static void main(String[] args)
254 // setLogging(); // BH - for event debugging in JavaScript
255 getInstance().doMain(args);
258 private static void logClass(String name)
260 // BH - for event debugging in JavaScript
261 ConsoleHandler consoleHandler = new ConsoleHandler();
262 consoleHandler.setLevel(Level.ALL);
263 Logger logger = Logger.getLogger(name);
264 logger.setLevel(Level.ALL);
265 logger.addHandler(consoleHandler);
268 @SuppressWarnings("unused")
269 private static void setLogging()
277 System.out.println("not in js");
280 // BH - for event debugging in JavaScript (Java mode only)
281 if (!Platform.isJS())
288 Logger.getLogger("").setLevel(Level.ALL);
289 logClass("java.awt.EventDispatchThread");
290 logClass("java.awt.EventQueue");
291 logClass("java.awt.Component");
292 logClass("java.awt.focus.Component");
293 logClass("java.awt.focus.DefaultKeyboardFocusManager");
301 void doMain(String[] args)
304 boolean isJS = Platform.isJS();
307 System.setSecurityManager(null);
311 .println("Java version: " + System.getProperty("java.version"));
312 System.out.println(System.getProperty("os.arch") + " "
313 + System.getProperty("os.name") + " "
314 + System.getProperty("os.version"));
316 ArgsParser aparser = new ArgsParser(args);
318 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
319 Cache.loadProperties(usrPropsFile);
322 isJavaAppletTag = aparser.isApplet();
325 Preferences.setAppletDefaults();
326 Cache.loadProperties(usrPropsFile); // again, because we
327 // might be changing defaults here?
330 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
331 appletResourcePath = aparser.getValue("Info.resourcePath");
340 if (usrPropsFile != null)
343 "CMD [-props " + usrPropsFile + "] executed successfully!");
346 if (aparser.contains("help") || aparser.contains("h"))
351 if (aparser.contains(ArgsParser.NODISPLAY)
352 || aparser.contains(ArgsParser.NOGUI)
353 || aparser.contains(ArgsParser.HEADLESS)
354 || "true".equals(System.getProperty("java.awt.headless")))
361 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
362 if (jabawsUrl != null)
366 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
368 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
369 } catch (MalformedURLException e)
372 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
377 // check for property setting
378 String defs = aparser.getValue(ArgsParser.SETPROP);
381 int p = defs.indexOf('=');
384 System.err.println("Ignoring invalid setprop argument : " + defs);
388 System.out.println("Executing setprop argument: " + defs);
391 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
394 defs = aparser.getValue(ArgsParser.SETPROP);
396 System.setProperty("http.agent",
397 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
401 } catch (NoClassDefFoundError error)
403 error.printStackTrace();
404 System.out.println("\nEssential logging libraries not found."
405 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
413 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
414 } catch (Exception ex)
416 System.err.println("Unexpected Look and Feel Exception");
417 ex.printStackTrace();
419 if (Platform.isAMacAndNotJS())
422 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
424 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
426 System.setProperty("apple.laf.useScreenMenuBar", "true");
427 if (lookAndFeel != null)
431 UIManager.setLookAndFeel(lookAndFeel);
432 } catch (Throwable e)
435 "Failed to set QuaQua look and feel: " + e.toString());
438 if (lookAndFeel == null
439 || !(lookAndFeel.getClass().isAssignableFrom(
440 UIManager.getLookAndFeel().getClass()))
441 || !UIManager.getLookAndFeel().getClass().toString()
442 .toLowerCase().contains("quaqua"))
447 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
448 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
449 } catch (Throwable e)
452 "Failed to reset look and feel: " + e.toString());
458 * configure 'full' SO model if preferences say to,
459 * else use the default (SO Lite)
461 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
463 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
468 desktop = Desktop.getInstance();
469 desktop.setInBatchMode(true); // indicate we are starting up
470 desktop.setVisible(true);
479 desktop.startServiceDiscovery();
480 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
482 startUsageStats(desktop);
486 System.err.println("CMD [-nousagestats] executed successfully!");
489 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
491 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
494 // Start the desktop questionnaire prompter with the specified
496 Cache.log.debug("Starting questionnaire url at " + url);
497 desktop.checkForQuestionnaire(url);
498 System.out.println("CMD questionnaire[-" + url
499 + "] executed successfully!");
503 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
505 // Start the desktop questionnaire prompter with the specified
508 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
510 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
512 "Starting questionnaire with default url: " + defurl);
513 desktop.checkForQuestionnaire(defurl);
520 .println("CMD [-noquestionnaire] executed successfully!");
523 if (!aparser.contains(ArgsParser.NONEWS))
525 desktop.checkForNews();
528 BioJsHTMLOutput.updateBioJS();
532 // script to execute after all loading is
533 // completed one way or another
534 // extract groovy argument and execute if necessary
535 String groovyscript = (isJS ? null
536 : aparser.getValue(ArgsParser.GROOVY, true));
537 String file = aparser.getValue(ArgsParser.OPEN, true);
538 // BH this here to allow split frame; not working as of 5/17/2019
539 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
540 String fileFormat = (isJavaAppletTag
541 ? aparser.getAppletValue("format", null)
544 FileFormatI format = null;
545 DataSourceType protocol = null;
547 if (file == null && desktop == null)
549 System.out.println("No files to open!");
552 boolean haveImport = checkStartVamas(aparser);
553 // Finally, deal with the remaining input data.
555 if (file == null && isJavaAppletTag)
557 // Maybe the sequences are added as parameters
558 StringBuffer data = new StringBuffer("PASTE");
560 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
562 data.append(file.toString() + "\n");
565 if (data.length() > 5)
567 file = data.toString();
575 desktop.setProgressBar(
577 .getString("status.processing_commandline_args"),
578 progress = System.currentTimeMillis());
583 * ignore in JavaScript -- can't just check file existence - could load
589 if (!file.startsWith("http://") && !file.startsWith("https://"))
590 // BH 2019 added https check for Java
592 if (!(new File(file)).exists())
594 System.out.println("Can't find " + file);
603 protocol = AppletFormatAdapter.checkProtocol(file);
607 format = (isJavaAppletTag && fileFormat != null
608 ? FileFormats.getInstance().forName(fileFormat)
612 format = new IdentifyFile().identify(file, protocol);
614 } catch (FileFormatException e1)
619 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
623 System.out.println("error");
628 .println("CMD [-open " + file + "] executed successfully!");
631 protocol = AppletFormatAdapter.checkProtocol(file2);
634 format = new IdentifyFile().identify(file2, protocol);
635 } catch (FileFormatException e1)
639 AlignFrame af2 = new FileLoader(!headless)
640 .loadFileWaitTillLoaded(file2, protocol, format);
643 System.out.println("error");
647 AlignViewport.openLinkedAlignmentAs(af,
648 af.getViewport().getAlignment(),
649 af2.getViewport().getAlignment(), "",
650 AlignViewport.SPLIT_FRAME);
652 "CMD [-open2 " + file2 + "] executed successfully!");
656 setCurrentAlignFrame(af);
658 // TODO: file2 How to implement file2 for the applet spit screen?
660 String data = aparser.getValue(ArgsParser.COLOUR, true);
663 data.replaceAll("%20", " ");
665 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
666 af.getViewport(), af.getViewport().getAlignment(), data);
671 "CMD [-color " + data + "] executed successfully!");
676 // Must maintain ability to use the groups flag
677 data = aparser.getValue(ArgsParser.GROUPS, true);
680 af.parseFeaturesFile(data,
681 AppletFormatAdapter.checkProtocol(data));
682 // System.out.println("Added " + data);
684 "CMD groups[-" + data + "] executed successfully!");
686 data = aparser.getValue(ArgsParser.FEATURES, true);
689 af.parseFeaturesFile(data,
690 AppletFormatAdapter.checkProtocol(data));
691 // System.out.println("Added " + data);
693 "CMD [-features " + data + "] executed successfully!");
696 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
699 af.loadJalviewDataFile(data, null, null, null);
700 // System.out.println("Added " + data);
702 "CMD [-annotations " + data + "] executed successfully!");
704 // set or clear the sortbytree flag.
705 if (aparser.contains(ArgsParser.SORTBYTREE))
707 af.getViewport().setSortByTree(true);
708 if (af.getViewport().getSortByTree())
710 System.out.println("CMD [-sortbytree] executed successfully!");
713 if (aparser.contains(ArgsParser.NOANNOTATION)
714 || aparser.contains(ArgsParser.NOANNOTATION2))
716 af.getViewport().setShowAnnotation(false);
717 if (!af.getViewport().isShowAnnotation())
719 System.out.println("CMD no-annotation executed successfully!");
722 if (aparser.contains(ArgsParser.NOSORTBYTREE))
724 af.getViewport().setSortByTree(false);
725 if (!af.getViewport().getSortByTree())
728 .println("CMD [-nosortbytree] executed successfully!");
731 data = aparser.getValue(ArgsParser.TREE, true);
737 "CMD [-tree " + data + "] executed successfully!");
738 NewickFile nf = new NewickFile(data,
739 AppletFormatAdapter.checkProtocol(data));
741 .setCurrentTree(af.showNewickTree(nf, data).getTree());
742 } catch (IOException ex)
744 System.err.println("Couldn't add tree " + data);
745 ex.printStackTrace(System.err);
748 // TODO - load PDB structure(s) to alignment JAL-629
749 // (associate with identical sequence in alignment, or a specified
753 loadAppletParams(aparser, af);
762 if (groovyscript != null)
764 // Execute the groovy script after we've done all the rendering
766 // and before any images or figures are generated.
767 System.out.println("Executing script " + groovyscript);
768 executeGroovyScript(groovyscript, af);
769 System.out.println("CMD groovy[" + groovyscript
770 + "] executed successfully!");
773 checkOutputFile(aparser, af, format);
774 while (aparser.getSize() > 0)
776 System.out.println("Unknown arg: " + aparser.nextValue());
781 AlignFrame startUpAlframe = null;
782 // We'll only open the default file if the desktop is visible.
784 // ////////////////////
786 if (!isJS && !headless && file == null && !haveImport
787 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
794 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
795 jalview.bin.Cache.getDefault("www.jalview.org",
796 "http://www.jalview.org")
797 + "/examples/exampleFile_2_7.jar");
799 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
801 // hardwire upgrade of the startup file
802 file.replace("_2_3.jar", "_2_7.jar");
803 // and remove the stale setting
804 jalview.bin.Cache.removeProperty("STARTUP_FILE");
807 protocol = DataSourceType.FILE;
809 if (file.indexOf("http:") > -1)
811 protocol = DataSourceType.URL;
814 if (file.endsWith(".jar"))
816 format = FileFormat.Jalview;
822 format = new IdentifyFile().identify(file, protocol);
823 } catch (FileFormatException e)
829 startUpAlframe = new FileLoader(!headless)
830 .loadFileWaitTillLoaded(file, protocol, format);
831 // extract groovy arguments before anything else.
834 // Once all other stuff is done, execute any groovy scripts (in order)
835 if (groovyscript != null)
837 if (Cache.groovyJarsPresent())
839 System.out.println("Executing script " + groovyscript);
840 executeGroovyScript(groovyscript, startUpAlframe);
845 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
849 // and finally, turn off batch mode indicator - if the desktop still exists
854 desktop.setProgressBar(null, progress);
856 desktop.setInBatchMode(false);
860 private boolean checkStartVamas(ArgsParser aparser)
862 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
863 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
864 if (vamsasImport == null && vamsasSession == null)
868 if (desktop == null || headless)
871 "Headless vamsas sessions not yet supported. Sorry.");
874 boolean haveImport = (vamsasImport != null);
877 // if we have a file, start a new session and import it.
878 boolean inSession = false;
881 DataSourceType viprotocol = AppletFormatAdapter
882 .checkProtocol(vamsasImport);
883 if (viprotocol == DataSourceType.FILE)
885 inSession = desktop.vamsasImport(new File(vamsasImport));
887 else if (viprotocol == DataSourceType.URL)
889 inSession = desktop.vamsasImport(new URL(vamsasImport));
892 } catch (Exception e)
894 System.err.println("Exeption when importing " + vamsasImport
895 + " as a vamsas document.");
900 System.err.println("Failed to import " + vamsasImport
901 + " as a vamsas document.");
905 System.out.println("Imported Successfully into new session "
906 + desktop.getVamsasApplication().getCurrentSession());
909 if (vamsasSession != null)
911 if (vamsasImport != null)
913 // close the newly imported session and import the Jalview specific
914 // remnants into the new session later on.
915 desktop.vamsasStop_actionPerformed(null);
917 // now join the new session
920 if (desktop.joinVamsasSession(vamsasSession))
923 "Successfully joined vamsas session " + vamsasSession);
927 System.err.println("WARNING: Failed to join vamsas session "
930 } catch (Exception e)
933 "ERROR: Failed to join vamsas session " + vamsasSession);
936 if (vamsasImport != null)
938 // the Jalview specific remnants can now be imported into the new
939 // session at the user's leisure.
941 "Skipping Push for import of data into existing vamsas session."); // TODO:
946 // desktop.getVamsasApplication().push_update();
952 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
955 String imageName = "unnamed.png";
956 while (aparser.getSize() > 1)
962 String outputFormat = aparser.nextValue();
963 String file = aparser.nextValue();
964 if (outputFormat.equalsIgnoreCase("png"))
966 af.createPNG(new File(file));
967 imageName = (new File(file)).getName();
968 System.out.println("Creating PNG image: " + file);
971 else if (outputFormat.equalsIgnoreCase("svg"))
973 File imageFile = new File(file);
974 imageName = imageFile.getName();
975 af.createSVG(imageFile);
976 System.out.println("Creating SVG image: " + file);
979 else if (outputFormat.equalsIgnoreCase("html"))
981 File imageFile = new File(file);
982 imageName = imageFile.getName();
983 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
984 htmlSVG.exportHTML(file);
986 System.out.println("Creating HTML image: " + file);
989 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
993 System.err.println("The output html file must not be null");
998 BioJsHTMLOutput.refreshVersionInfo(
999 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1000 } catch (URISyntaxException e)
1002 e.printStackTrace();
1004 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1005 bjs.exportHTML(file);
1006 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1009 else if (outputFormat.equalsIgnoreCase("imgMap"))
1011 af.createImageMap(new File(file), imageName);
1012 System.out.println("Creating image map: " + file);
1015 else if (outputFormat.equalsIgnoreCase("eps"))
1017 File outputFile = new File(file);
1019 "Creating EPS file: " + outputFile.getAbsolutePath());
1020 af.createEPS(outputFile);
1024 af.saveAlignment(file, format);
1025 if (af.isSaveAlignmentSuccessful())
1028 "Written alignment in " + format + " format to " + file);
1032 System.out.println("Error writing file " + file + " in " + format
1039 private static void showUsage()
1042 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1043 + "-nodisplay\tRun Jalview without User Interface.\n"
1044 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1045 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1046 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1047 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1048 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1049 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1050 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1051 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1052 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1053 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1054 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1055 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1056 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1057 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1058 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1059 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1060 + "-html FILE\tCreate HTML file from alignment.\n"
1061 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1062 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1063 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1064 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1065 + "-noquestionnaire\tTurn off questionnaire check.\n"
1066 + "-nonews\tTurn off check for Jalview news.\n"
1067 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1068 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1070 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1071 // after all other properties files have been read\n\t
1072 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1073 // passed in correctly)"
1074 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1075 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1077 // "-vdoc vamsas-document\tImport vamsas document into new
1078 // session or join existing session with same URN\n"
1079 // + "-vses vamsas-session\tJoin session with given URN\n"
1080 + "-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"
1081 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1084 private static void startUsageStats(final Desktop desktop)
1087 * start a User Config prompt asking if we can log usage statistics.
1089 PromptUserConfig prompter = new PromptUserConfig(
1090 Desktop.getDesktopPane(), "USAGESTATS",
1091 "Jalview Usage Statistics",
1092 "Do you want to help make Jalview better by enabling "
1093 + "the collection of usage statistics with Google Analytics ?"
1094 + "\n\n(you can enable or disable usage tracking in the preferences)",
1101 "Initialising googletracker for usage stats.");
1102 Cache.initGoogleTracker();
1103 Cache.log.debug("Tracking enabled.");
1110 Cache.log.debug("Not enabling Google Tracking.");
1113 desktop.addDialogThread(prompter);
1117 * Locate the given string as a file and pass it to the groovy interpreter.
1119 * @param groovyscript
1120 * the script to execute
1121 * @param jalviewContext
1122 * the Jalview Desktop object passed in to the groovy binding as the
1125 private void executeGroovyScript(String groovyscript, AlignFrame af)
1128 * for scripts contained in files
1135 if (groovyscript.trim().equals("STDIN"))
1137 // read from stdin into a tempfile and execute it
1140 tfile = File.createTempFile("jalview", "groovy");
1141 PrintWriter outfile = new PrintWriter(
1142 new OutputStreamWriter(new FileOutputStream(tfile)));
1143 BufferedReader br = new BufferedReader(
1144 new InputStreamReader(System.in));
1146 while ((line = br.readLine()) != null)
1148 outfile.write(line + "\n");
1154 } catch (Exception ex)
1156 System.err.println("Failed to read from STDIN into tempfile "
1157 + ((tfile == null) ? "(tempfile wasn't created)"
1158 : tfile.toString()));
1159 ex.printStackTrace();
1164 sfile = tfile.toURI().toURL();
1165 } catch (Exception x)
1168 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1170 x.printStackTrace();
1178 sfile = new URI(groovyscript).toURL();
1179 } catch (Exception x)
1181 tfile = new File(groovyscript);
1182 if (!tfile.exists())
1184 System.err.println("File '" + groovyscript + "' does not exist.");
1187 if (!tfile.canRead())
1189 System.err.println("File '" + groovyscript + "' cannot be read.");
1192 if (tfile.length() < 1)
1194 System.err.println("File '" + groovyscript + "' is empty.");
1199 sfile = tfile.getAbsoluteFile().toURI().toURL();
1200 } catch (Exception ex)
1202 System.err.println("Failed to create a file URL for "
1203 + tfile.getAbsoluteFile());
1210 Map<String, Object> vbinding = new HashMap<>();
1211 vbinding.put("Jalview", this);
1214 vbinding.put("currentAlFrame", af);
1216 Binding gbinding = new Binding(vbinding);
1217 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1218 gse.run(sfile.toString(), gbinding);
1219 if ("STDIN".equals(groovyscript))
1221 // delete temp file that we made -
1222 // only if it was successfully executed
1225 } catch (Exception e)
1227 System.err.println("Exception Whilst trying to execute file " + sfile
1228 + " as a groovy script.");
1229 e.printStackTrace(System.err);
1234 public AlignFrame[] getAlignFrames()
1236 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1237 : Desktop.getAlignFrames();
1242 * Quit method delegates to Desktop.quit - unless running in headless mode
1243 * when it just ends the JVM
1247 if (jsFunctionExec != null)
1249 jsFunctionExec.tidyUp();
1250 jsFunctionExec = null;
1253 if (desktop != null)
1264 * Get the SwingJS applet ID and combine that with the frameType
1267 * "alignment", "desktop", etc., or null
1270 public static String getAppID(String frameType)
1272 String id = Cache.getProperty("Info.j2sAppletID");
1277 return id + (frameType == null ? "" : "-" + frameType);
1281 * Handle all JalviewLite applet parameters
1286 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1288 JalviewApp app = new JalviewApp()
1291 private boolean alignPDBStructures; // From JalviewLite; not implemented
1293 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1295 private Hashtable<String, int[]> jshashes;
1298 public String getParameter(String name)
1300 return aparser.getAppletValue(name, null);
1304 public boolean getDefaultParameter(String name, boolean def)
1307 return ((stn = getParameter(name)) == null ? def
1308 : "true".equalsIgnoreCase(stn));
1312 * Get the applet-like document base even though this is an application.
1315 public URL getDocumentBase()
1317 return Platform.getDocumentBase();
1321 * Get the applet-like code base even though this is an application.
1324 public URL getCodeBase()
1326 return Platform.getCodeBase();
1330 public AlignViewportI getViewport()
1332 return af.getViewport();
1340 public boolean parseFeaturesFile(String filename,
1341 DataSourceType protocol)
1343 return af.parseFeaturesFile(filename, protocol);
1351 public boolean loadScoreFile(String sScoreFile) throws IOException
1353 af.loadJalviewDataFile(sScoreFile, null, null, null);
1358 * annotations, jpredfile, jnetfile
1362 public void updateForAnnotations()
1364 af.updateForAnnotations();
1368 public void loadTree(NewickFile fin, String treeFile)
1371 // n/a -- already done by standard Jalview command line processing
1375 public void setAlignPdbStructures(boolean defaultParameter)
1377 alignPDBStructures = true;
1381 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1382 String[] chains, DataSourceType protocol)
1384 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1388 public void setFeatureGroupState(String[] groups, boolean state)
1390 af.setFeatureGroupState(groups, state);
1394 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1395 String[][] chains, String[] protocols)
1398 "Jalview applet interface alignedStructureView not implemented");
1402 public void newFeatureSettings()
1405 "Jalview applet interface newFeatureSettings not implemented");
1408 private Vector<Runnable> jsExecQueue;
1411 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1413 jsFunctionExec = exec;
1414 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1419 public AppletContext getAppletContext()
1421 // TODO Auto-generated method stub
1426 public boolean isJsfallbackEnabled()
1428 // TODO Auto-generated method stub
1433 public JSObject getJSObject()
1435 // TODO Auto-generated method stub
1440 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1442 // TODO Auto-generated method stub
1447 public void updateColoursFromMouseOver(Object source,
1448 MouseOverStructureListener mouseOverStructureListener)
1450 // TODO Auto-generated method stub
1455 public Object[] getSelectionForListener(SequenceGroup seqsel,
1456 ColumnSelection colsel, HiddenColumns hidden,
1457 SelectionSource source, Object alignFrame)
1459 // TODO Auto-generated method stub
1464 public String arrayToSeparatorList(String[] array)
1466 return appLoader.arrayToSeparatorList(array);
1470 public Hashtable<String, int[]> getJSHashes()
1472 return (jshashes == null
1473 ? (jshashes = new Hashtable<>())
1478 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1480 return (jsmessages == null
1481 ? (jsmessages = new Hashtable<>())
1486 public Object getFrameForSource(VamsasSource source)
1491 if (source instanceof jalview.gui.AlignViewport
1492 && source == (af = getCurrentAlignFrame()).getViewport())
1494 // should be valid if it just generated an event!
1497 // TODO: ensure that if '_af' is specified along with a handler
1498 // function, then only events from that alignFrame are sent to that
1505 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1507 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1512 appLoader = new JalviewAppLoader(true);
1513 appLoader.load(app);
1517 public String getSelectedSequences()
1519 // TODO Auto-generated method stub
1524 public String getSelectedSequences(String sep)
1526 // TODO Auto-generated method stub
1531 public String getSelectedSequencesFrom(AlignFrameI alf)
1533 // TODO Auto-generated method stub
1538 public String getSelectedSequencesFrom(AlignFrameI alf,
1541 // TODO Auto-generated method stub
1546 public void highlight(String sequenceId, String position,
1547 String alignedPosition)
1549 // TODO Auto-generated method stub
1554 public void highlightIn(AlignFrameI alf,
1555 String sequenceId, String position, String alignedPosition)
1557 // TODO Auto-generated method stub
1562 public void select(String sequenceIds, String columns)
1564 // TODO Auto-generated method stub
1569 public void select(String sequenceIds, String columns, String sep)
1571 // TODO Auto-generated method stub
1576 public void selectIn(AlignFrameI alf, String sequenceIds,
1579 // TODO Auto-generated method stub
1584 public void selectIn(AlignFrameI alf, String sequenceIds,
1585 String columns, String sep)
1587 // TODO Auto-generated method stub
1592 public String getSelectedSequencesAsAlignment(String format,
1595 // TODO Auto-generated method stub
1600 public String getSelectedSequencesAsAlignmentFrom(
1601 AlignFrameI alf, String format, String suffix)
1603 // TODO Auto-generated method stub
1608 public String getAlignmentOrder()
1610 // TODO Auto-generated method stub
1615 public String getAlignmentOrderFrom(AlignFrameI alf)
1617 // TODO Auto-generated method stub
1622 public String getAlignmentOrderFrom(AlignFrameI alf,
1625 // TODO Auto-generated method stub
1630 public String orderBy(String order, String undoName)
1632 // TODO Auto-generated method stub
1637 public String orderBy(String order, String undoName, String sep)
1639 // TODO Auto-generated method stub
1644 public String orderAlignmentBy(AlignFrameI alf,
1645 String order, String undoName, String sep)
1647 // TODO Auto-generated method stub
1652 public String getAlignment(String format)
1654 // TODO Auto-generated method stub
1659 public String getAlignmentFrom(AlignFrameI alf,
1662 // TODO Auto-generated method stub
1667 public String getAlignment(String format, String suffix)
1669 // TODO Auto-generated method stub
1674 public String getAlignmentFrom(AlignFrameI alf,
1675 String format, String suffix)
1677 // TODO Auto-generated method stub
1682 public void loadAnnotation(String annotation)
1684 // TODO Auto-generated method stub
1689 public void loadAnnotationFrom(AlignFrameI alf,
1692 // TODO Auto-generated method stub
1697 public void loadFeatures(String features, boolean autoenabledisplay)
1699 // TODO Auto-generated method stub
1704 public boolean loadFeaturesFrom(AlignFrameI alf,
1705 String features, boolean autoenabledisplay)
1707 // TODO Auto-generated method stub
1712 public String getFeatures(String format)
1714 // TODO Auto-generated method stub
1719 public String getFeaturesFrom(AlignFrameI alf,
1722 // TODO Auto-generated method stub
1727 public String getAnnotation()
1729 // TODO Auto-generated method stub
1734 public String getAnnotationFrom(AlignFrameI alf)
1736 // TODO Auto-generated method stub
1741 public AlignFrameI newView()
1743 // TODO Auto-generated method stub
1748 public AlignFrameI newView(String name)
1750 // TODO Auto-generated method stub
1755 public AlignFrameI newViewFrom(AlignFrameI alf)
1757 // TODO Auto-generated method stub
1762 public AlignFrameI newViewFrom(AlignFrameI alf, String name)
1764 // TODO Auto-generated method stub
1769 public AlignFrameI loadAlignment(String text,
1772 // TODO Auto-generated method stub
1777 public void setMouseoverListener(String listener)
1779 // TODO Auto-generated method stub
1784 public void setMouseoverListener(AlignFrameI af,
1787 // TODO Auto-generated method stub
1792 public void setSelectionListener(String listener)
1794 // TODO Auto-generated method stub
1799 public void setSelectionListener(AlignFrameI af,
1802 // TODO Auto-generated method stub
1807 public void setStructureListener(String listener, String modelSet)
1809 // TODO Auto-generated method stub
1814 public void removeJavascriptListener(AlignFrameI af,
1817 // TODO Auto-generated method stub
1822 public void mouseOverStructure(String pdbResNum, String chain,
1825 // TODO Auto-generated method stub
1830 public boolean addPdbFile(AlignFrameI alFrame,
1831 String sequenceId, String pdbEntryString, String pdbFile)
1833 // TODO Auto-generated method stub
1838 public void scrollViewToIn(AlignFrameI alf,
1839 String topRow, String leftHandColumn)
1841 // TODO Auto-generated method stub
1846 public void scrollViewToRowIn(AlignFrameI alf,
1849 // TODO Auto-generated method stub
1854 public void scrollViewToColumnIn(AlignFrameI alf,
1855 String leftHandColumn)
1857 // TODO Auto-generated method stub
1862 public String getFeatureGroups()
1864 // TODO Auto-generated method stub
1869 public String getFeatureGroupsOn(AlignFrameI alf)
1871 // TODO Auto-generated method stub
1876 public String getFeatureGroupsOfState(boolean visible)
1878 // TODO Auto-generated method stub
1883 public String getFeatureGroupsOfStateOn(AlignFrameI alf,
1886 // TODO Auto-generated method stub
1891 public void setFeatureGroupStateOn(AlignFrameI alf,
1892 String groups, boolean state)
1894 // TODO Auto-generated method stub
1899 public void setFeatureGroupState(String groups, boolean state)
1901 // TODO Auto-generated method stub
1906 public String getSeparator()
1908 // TODO Auto-generated method stub
1913 public void setSeparator(String separator)
1915 // TODO Auto-generated method stub
1920 public String getJsMessage(String messageclass, String viewId)
1922 // TODO Auto-generated method stub