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.AlignViewportI;
24 import jalview.api.JalviewApp;
25 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
26 import jalview.datamodel.PDBEntry;
27 import jalview.datamodel.SequenceI;
28 import jalview.ext.so.SequenceOntology;
29 import jalview.gui.AlignFrame;
30 import jalview.gui.AlignViewport;
31 import jalview.gui.Desktop;
32 import jalview.gui.Preferences;
33 import jalview.gui.PromptUserConfig;
34 import jalview.gui.StructureViewer;
35 import jalview.io.AppletFormatAdapter;
36 import jalview.io.BioJsHTMLOutput;
37 import jalview.io.DataSourceType;
38 import jalview.io.FileFormat;
39 import jalview.io.FileFormatException;
40 import jalview.io.FileFormatI;
41 import jalview.io.FileFormats;
42 import jalview.io.FileLoader;
43 import jalview.io.HtmlSvgOutput;
44 import jalview.io.IdentifyFile;
45 import jalview.io.NewickFile;
46 import jalview.io.gff.SequenceOntologyFactory;
47 import jalview.javascript.JalviewLiteJsApi;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.schemes.ColourSchemeProperty;
50 import jalview.util.MessageManager;
51 import jalview.util.Platform;
52 import jalview.ws.jws2.Jws2Discoverer;
54 import java.io.BufferedReader;
56 import java.io.FileOutputStream;
57 import java.io.IOException;
58 import java.io.InputStreamReader;
59 import java.io.OutputStreamWriter;
60 import java.io.PrintWriter;
61 import java.net.MalformedURLException;
63 import java.net.URISyntaxException;
65 import java.security.AllPermission;
66 import java.security.CodeSource;
67 import java.security.PermissionCollection;
68 import java.security.Permissions;
69 import java.security.Policy;
70 import java.util.HashMap;
72 import java.util.Vector;
73 import java.util.logging.ConsoleHandler;
74 import java.util.logging.Level;
75 import java.util.logging.Logger;
77 import javax.swing.LookAndFeel;
78 import javax.swing.UIManager;
80 import groovy.lang.Binding;
81 import groovy.util.GroovyScriptEngine;
84 * Main class for Jalview Application <br>
86 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
89 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
90 * jalview.bin.Jalview jalview.bin.Jalview
92 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
93 * embellish '*' to e.g. '*.jar')
98 public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi
101 public static Jalview getInstance()
103 return (Jalview) ApplicationSingletonProvider
104 .getInstance(Jalview.class);
113 Platform.getURLCommandArguments();
116 private boolean headless;
118 public static boolean isHeadlessMode()
120 return getInstance().headless;
123 private Desktop desktop;
125 private AlignFrame currentAlignFrame;
127 public boolean isJavaAppletTag;
129 public String appletResourcePath;
131 public static AlignFrame getCurrentAlignFrame()
133 return getInstance().currentAlignFrame;
136 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
138 getInstance().currentAlignFrame = currentAlignFrame;
143 if (!Platform.isJS())
150 // grab all the rights we can for the JVM
151 Policy.setPolicy(new Policy()
154 public PermissionCollection getPermissions(CodeSource codesource)
156 Permissions perms = new Permissions();
157 perms.add(new AllPermission());
162 public void refresh()
170 * keep track of feature fetching tasks.
178 * TODO: generalise to track all jalview events to orchestrate batch
182 private int queued = 0;
184 private int running = 0;
186 public FeatureFetcher()
191 public void addFetcher(final AlignFrame af,
192 final Vector<String> dasSources)
194 final long id = System.currentTimeMillis();
196 final FeatureFetcher us = this;
197 new Thread(new Runnable()
209 af.setProgressBar(MessageManager
210 .getString("status.das_features_being_retrived"), id);
211 af.featureSettings_actionPerformed(null);
212 af.setProgressBar(null, id);
221 public synchronized boolean allFinished()
223 return queued == 0 && running == 0;
229 * main class for Jalview application
232 * open <em>filename</em>
234 public static void main(String[] args)
236 // setLogging(); // BH - for event debugging in JavaScript
237 getInstance().doMain(args);
240 private static void logClass(String name)
242 // BH - for event debugging in JavaScript
243 ConsoleHandler consoleHandler = new ConsoleHandler();
244 consoleHandler.setLevel(Level.ALL);
245 Logger logger = Logger.getLogger(name);
246 logger.setLevel(Level.ALL);
247 logger.addHandler(consoleHandler);
250 @SuppressWarnings("unused")
251 private static void setLogging()
259 System.out.println("not in js");
262 // BH - for event debugging in JavaScript (Java mode only)
263 if (!Platform.isJS())
270 Logger.getLogger("").setLevel(Level.ALL);
271 logClass("java.awt.EventDispatchThread");
272 logClass("java.awt.EventQueue");
273 logClass("java.awt.Component");
274 logClass("java.awt.focus.Component");
275 logClass("java.awt.focus.DefaultKeyboardFocusManager");
283 void doMain(String[] args)
286 boolean isJS = Platform.isJS();
289 System.setSecurityManager(null);
293 .println("Java version: " + System.getProperty("java.version"));
294 System.out.println(System.getProperty("os.arch") + " "
295 + System.getProperty("os.name") + " "
296 + System.getProperty("os.version"));
298 ArgsParser aparser = new ArgsParser(args);
300 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
301 Cache.loadProperties(usrPropsFile);
304 isJavaAppletTag = aparser.isApplet();
307 Preferences.setAppletDefaults();
308 Cache.loadProperties(usrPropsFile); // again, because we
309 // might be changing defaults here?
312 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
313 appletResourcePath = aparser.getValue("Info.resourcePath");
322 if (usrPropsFile != null)
325 "CMD [-props " + usrPropsFile + "] executed successfully!");
328 if (aparser.contains("help") || aparser.contains("h"))
333 if (aparser.contains(ArgsParser.NODISPLAY)
334 || aparser.contains(ArgsParser.NOGUI)
335 || aparser.contains(ArgsParser.HEADLESS)
336 || "true".equals(System.getProperty("java.awt.headless")))
343 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
344 if (jabawsUrl != null)
348 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
350 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
351 } catch (MalformedURLException e)
354 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
359 // check for property setting
360 String defs = aparser.getValue(ArgsParser.SETPROP);
363 int p = defs.indexOf('=');
366 System.err.println("Ignoring invalid setprop argument : " + defs);
370 System.out.println("Executing setprop argument: " + defs);
373 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
376 defs = aparser.getValue(ArgsParser.SETPROP);
378 System.setProperty("http.agent",
379 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
383 } catch (NoClassDefFoundError error)
385 error.printStackTrace();
386 System.out.println("\nEssential logging libraries not found."
387 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
395 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
396 } catch (Exception ex)
398 System.err.println("Unexpected Look and Feel Exception");
399 ex.printStackTrace();
401 if (Platform.isAMacAndNotJS())
404 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
406 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
408 System.setProperty("apple.laf.useScreenMenuBar", "true");
409 if (lookAndFeel != null)
413 UIManager.setLookAndFeel(lookAndFeel);
414 } catch (Throwable e)
417 "Failed to set QuaQua look and feel: " + e.toString());
420 if (lookAndFeel == null
421 || !(lookAndFeel.getClass().isAssignableFrom(
422 UIManager.getLookAndFeel().getClass()))
423 || !UIManager.getLookAndFeel().getClass().toString()
424 .toLowerCase().contains("quaqua"))
429 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
430 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
431 } catch (Throwable e)
434 "Failed to reset look and feel: " + e.toString());
440 * configure 'full' SO model if preferences say to,
441 * else use the default (SO Lite)
443 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
445 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
450 desktop = Desktop.getInstance();
451 desktop.setInBatchMode(true); // indicate we are starting up
452 desktop.setVisible(true);
461 desktop.startServiceDiscovery();
462 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
464 startUsageStats(desktop);
468 System.err.println("CMD [-nousagestats] executed successfully!");
471 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
473 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
476 // Start the desktop questionnaire prompter with the specified
478 Cache.log.debug("Starting questionnaire url at " + url);
479 desktop.checkForQuestionnaire(url);
480 System.out.println("CMD questionnaire[-" + url
481 + "] executed successfully!");
485 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
487 // Start the desktop questionnaire prompter with the specified
490 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
492 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
494 "Starting questionnaire with default url: " + defurl);
495 desktop.checkForQuestionnaire(defurl);
502 .println("CMD [-noquestionnaire] executed successfully!");
505 if (!aparser.contains(ArgsParser.NONEWS))
507 desktop.checkForNews();
510 BioJsHTMLOutput.updateBioJS();
514 // script to execute after all loading is
515 // completed one way or another
516 // extract groovy argument and execute if necessary
517 String groovyscript = (isJS ? null
518 : aparser.getValue(ArgsParser.GROOVY, true));
519 String file = aparser.getValue(ArgsParser.OPEN, true);
520 // BH this here to allow split frame; not working as of 5/17/2019
521 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
522 String fileFormat = (isJavaAppletTag
523 ? aparser.getAppletValue("format", null)
526 FileFormatI format = null;
527 DataSourceType protocol = null;
529 if (file == null && desktop == null)
531 System.out.println("No files to open!");
534 boolean haveImport = checkStartVamas(aparser);
535 // Finally, deal with the remaining input data.
537 if (file == null && isJavaAppletTag)
539 // Maybe the sequences are added as parameters
540 StringBuffer data = new StringBuffer("PASTE");
542 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
544 data.append(file.toString() + "\n");
547 if (data.length() > 5)
549 file = data.toString();
557 desktop.setProgressBar(
559 .getString("status.processing_commandline_args"),
560 progress = System.currentTimeMillis());
565 * ignore in JavaScript -- can't just check file existence - could load
571 if (!file.startsWith("http://") && !file.startsWith("https://"))
572 // BH 2019 added https check for Java
574 if (!(new File(file)).exists())
576 System.out.println("Can't find " + file);
585 protocol = AppletFormatAdapter.checkProtocol(file);
589 format = (isJavaAppletTag && fileFormat != null
590 ? FileFormats.getInstance().forName(fileFormat)
594 format = new IdentifyFile().identify(file, protocol);
596 } catch (FileFormatException e1)
601 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
605 System.out.println("error");
610 .println("CMD [-open " + file + "] executed successfully!");
613 protocol = AppletFormatAdapter.checkProtocol(file2);
616 format = new IdentifyFile().identify(file2, protocol);
617 } catch (FileFormatException e1)
621 AlignFrame af2 = new FileLoader(!headless)
622 .loadFileWaitTillLoaded(file2, protocol, format);
625 System.out.println("error");
629 AlignViewport.openLinkedAlignmentAs(af,
630 af.getViewport().getAlignment(),
631 af2.getViewport().getAlignment(), "",
632 AlignViewport.SPLIT_FRAME);
634 "CMD [-open2 " + file2 + "] executed successfully!");
638 setCurrentAlignFrame(af);
640 // TODO: file2 How to implement file2 for the applet spit screen?
642 String data = aparser.getValue(ArgsParser.COLOUR, true);
645 data.replaceAll("%20", " ");
647 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
648 af.getViewport(), af.getViewport().getAlignment(), data);
653 "CMD [-color " + data + "] executed successfully!");
658 // Must maintain ability to use the groups flag
659 data = aparser.getValue(ArgsParser.GROUPS, true);
662 af.parseFeaturesFile(data,
663 AppletFormatAdapter.checkProtocol(data));
664 // System.out.println("Added " + data);
666 "CMD groups[-" + data + "] executed successfully!");
668 data = aparser.getValue(ArgsParser.FEATURES, true);
671 af.parseFeaturesFile(data,
672 AppletFormatAdapter.checkProtocol(data));
673 // System.out.println("Added " + data);
675 "CMD [-features " + data + "] executed successfully!");
678 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
681 af.loadJalviewDataFile(data, null, null, null);
682 // System.out.println("Added " + data);
684 "CMD [-annotations " + data + "] executed successfully!");
686 // set or clear the sortbytree flag.
687 if (aparser.contains(ArgsParser.SORTBYTREE))
689 af.getViewport().setSortByTree(true);
690 if (af.getViewport().getSortByTree())
692 System.out.println("CMD [-sortbytree] executed successfully!");
695 if (aparser.contains(ArgsParser.NOANNOTATION)
696 || aparser.contains(ArgsParser.NOANNOTATION2))
698 af.getViewport().setShowAnnotation(false);
699 if (!af.getViewport().isShowAnnotation())
701 System.out.println("CMD no-annotation executed successfully!");
704 if (aparser.contains(ArgsParser.NOSORTBYTREE))
706 af.getViewport().setSortByTree(false);
707 if (!af.getViewport().getSortByTree())
710 .println("CMD [-nosortbytree] executed successfully!");
713 data = aparser.getValue(ArgsParser.TREE, true);
719 "CMD [-tree " + data + "] executed successfully!");
720 NewickFile nf = new NewickFile(data,
721 AppletFormatAdapter.checkProtocol(data));
723 .setCurrentTree(af.showNewickTree(nf, data).getTree());
724 } catch (IOException ex)
726 System.err.println("Couldn't add tree " + data);
727 ex.printStackTrace(System.err);
730 // TODO - load PDB structure(s) to alignment JAL-629
731 // (associate with identical sequence in alignment, or a specified
735 loadAppletParams(aparser, af);
744 if (groovyscript != null)
746 // Execute the groovy script after we've done all the rendering
748 // and before any images or figures are generated.
749 System.out.println("Executing script " + groovyscript);
750 executeGroovyScript(groovyscript, af);
751 System.out.println("CMD groovy[" + groovyscript
752 + "] executed successfully!");
755 checkOutputFile(aparser, af, format);
756 while (aparser.getSize() > 0)
758 System.out.println("Unknown arg: " + aparser.nextValue());
763 AlignFrame startUpAlframe = null;
764 // We'll only open the default file if the desktop is visible.
766 // ////////////////////
768 if (!isJS && !headless && file == null && !haveImport
769 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
776 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
777 jalview.bin.Cache.getDefault("www.jalview.org",
778 "http://www.jalview.org")
779 + "/examples/exampleFile_2_7.jar");
781 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
783 // hardwire upgrade of the startup file
784 file.replace("_2_3.jar", "_2_7.jar");
785 // and remove the stale setting
786 jalview.bin.Cache.removeProperty("STARTUP_FILE");
789 protocol = DataSourceType.FILE;
791 if (file.indexOf("http:") > -1)
793 protocol = DataSourceType.URL;
796 if (file.endsWith(".jar"))
798 format = FileFormat.Jalview;
804 format = new IdentifyFile().identify(file, protocol);
805 } catch (FileFormatException e)
811 startUpAlframe = new FileLoader(!headless)
812 .loadFileWaitTillLoaded(file, protocol, format);
813 // extract groovy arguments before anything else.
816 // Once all other stuff is done, execute any groovy scripts (in order)
817 if (groovyscript != null)
819 if (Cache.groovyJarsPresent())
821 System.out.println("Executing script " + groovyscript);
822 executeGroovyScript(groovyscript, startUpAlframe);
827 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
831 // and finally, turn off batch mode indicator - if the desktop still exists
836 desktop.setProgressBar(null, progress);
838 desktop.setInBatchMode(false);
842 private boolean checkStartVamas(ArgsParser aparser)
844 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
845 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
846 if (vamsasImport == null && vamsasSession == null)
850 if (desktop == null || headless)
853 "Headless vamsas sessions not yet supported. Sorry.");
856 boolean haveImport = (vamsasImport != null);
859 // if we have a file, start a new session and import it.
860 boolean inSession = false;
863 DataSourceType viprotocol = AppletFormatAdapter
864 .checkProtocol(vamsasImport);
865 if (viprotocol == DataSourceType.FILE)
867 inSession = desktop.vamsasImport(new File(vamsasImport));
869 else if (viprotocol == DataSourceType.URL)
871 inSession = desktop.vamsasImport(new URL(vamsasImport));
874 } catch (Exception e)
876 System.err.println("Exeption when importing " + vamsasImport
877 + " as a vamsas document.");
882 System.err.println("Failed to import " + vamsasImport
883 + " as a vamsas document.");
887 System.out.println("Imported Successfully into new session "
888 + desktop.getVamsasApplication().getCurrentSession());
891 if (vamsasSession != null)
893 if (vamsasImport != null)
895 // close the newly imported session and import the Jalview specific
896 // remnants into the new session later on.
897 desktop.vamsasStop_actionPerformed(null);
899 // now join the new session
902 if (desktop.joinVamsasSession(vamsasSession))
905 "Successfully joined vamsas session " + vamsasSession);
909 System.err.println("WARNING: Failed to join vamsas session "
912 } catch (Exception e)
915 "ERROR: Failed to join vamsas session " + vamsasSession);
918 if (vamsasImport != null)
920 // the Jalview specific remnants can now be imported into the new
921 // session at the user's leisure.
923 "Skipping Push for import of data into existing vamsas session."); // TODO:
928 // desktop.getVamsasApplication().push_update();
934 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
937 String imageName = "unnamed.png";
938 while (aparser.getSize() > 1)
944 String outputFormat = aparser.nextValue();
945 String file = aparser.nextValue();
946 if (outputFormat.equalsIgnoreCase("png"))
948 af.createPNG(new File(file));
949 imageName = (new File(file)).getName();
950 System.out.println("Creating PNG image: " + file);
953 else if (outputFormat.equalsIgnoreCase("svg"))
955 File imageFile = new File(file);
956 imageName = imageFile.getName();
957 af.createSVG(imageFile);
958 System.out.println("Creating SVG image: " + file);
961 else if (outputFormat.equalsIgnoreCase("html"))
963 File imageFile = new File(file);
964 imageName = imageFile.getName();
965 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
966 htmlSVG.exportHTML(file);
968 System.out.println("Creating HTML image: " + file);
971 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
975 System.err.println("The output html file must not be null");
980 BioJsHTMLOutput.refreshVersionInfo(
981 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
982 } catch (URISyntaxException e)
986 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
987 bjs.exportHTML(file);
988 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
991 else if (outputFormat.equalsIgnoreCase("imgMap"))
993 af.createImageMap(new File(file), imageName);
994 System.out.println("Creating image map: " + file);
997 else if (outputFormat.equalsIgnoreCase("eps"))
999 File outputFile = new File(file);
1001 "Creating EPS file: " + outputFile.getAbsolutePath());
1002 af.createEPS(outputFile);
1006 af.saveAlignment(file, format);
1007 if (af.isSaveAlignmentSuccessful())
1010 "Written alignment in " + format + " format to " + file);
1014 System.out.println("Error writing file " + file + " in " + format
1021 private static void showUsage()
1024 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1025 + "-nodisplay\tRun Jalview without User Interface.\n"
1026 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1027 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1028 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1029 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1030 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1031 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1032 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1033 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1034 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1035 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1036 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1037 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1038 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1039 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1040 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1041 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1042 + "-html FILE\tCreate HTML file from alignment.\n"
1043 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1044 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1045 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1046 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1047 + "-noquestionnaire\tTurn off questionnaire check.\n"
1048 + "-nonews\tTurn off check for Jalview news.\n"
1049 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1050 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1052 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1053 // after all other properties files have been read\n\t
1054 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1055 // passed in correctly)"
1056 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1057 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1059 // "-vdoc vamsas-document\tImport vamsas document into new
1060 // session or join existing session with same URN\n"
1061 // + "-vses vamsas-session\tJoin session with given URN\n"
1062 + "-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"
1063 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1066 private static void startUsageStats(final Desktop desktop)
1069 * start a User Config prompt asking if we can log usage statistics.
1071 PromptUserConfig prompter = new PromptUserConfig(
1072 Desktop.getDesktopPane(), "USAGESTATS",
1073 "Jalview Usage Statistics",
1074 "Do you want to help make Jalview better by enabling "
1075 + "the collection of usage statistics with Google Analytics ?"
1076 + "\n\n(you can enable or disable usage tracking in the preferences)",
1083 "Initialising googletracker for usage stats.");
1084 Cache.initGoogleTracker();
1085 Cache.log.debug("Tracking enabled.");
1092 Cache.log.debug("Not enabling Google Tracking.");
1095 desktop.addDialogThread(prompter);
1099 * Locate the given string as a file and pass it to the groovy interpreter.
1101 * @param groovyscript
1102 * the script to execute
1103 * @param jalviewContext
1104 * the Jalview Desktop object passed in to the groovy binding as the
1107 private void executeGroovyScript(String groovyscript, AlignFrame af)
1110 * for scripts contained in files
1117 if (groovyscript.trim().equals("STDIN"))
1119 // read from stdin into a tempfile and execute it
1122 tfile = File.createTempFile("jalview", "groovy");
1123 PrintWriter outfile = new PrintWriter(
1124 new OutputStreamWriter(new FileOutputStream(tfile)));
1125 BufferedReader br = new BufferedReader(
1126 new InputStreamReader(System.in));
1128 while ((line = br.readLine()) != null)
1130 outfile.write(line + "\n");
1136 } catch (Exception ex)
1138 System.err.println("Failed to read from STDIN into tempfile "
1139 + ((tfile == null) ? "(tempfile wasn't created)"
1140 : tfile.toString()));
1141 ex.printStackTrace();
1146 sfile = tfile.toURI().toURL();
1147 } catch (Exception x)
1150 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1152 x.printStackTrace();
1160 sfile = new URI(groovyscript).toURL();
1161 } catch (Exception x)
1163 tfile = new File(groovyscript);
1164 if (!tfile.exists())
1166 System.err.println("File '" + groovyscript + "' does not exist.");
1169 if (!tfile.canRead())
1171 System.err.println("File '" + groovyscript + "' cannot be read.");
1174 if (tfile.length() < 1)
1176 System.err.println("File '" + groovyscript + "' is empty.");
1181 sfile = tfile.getAbsoluteFile().toURI().toURL();
1182 } catch (Exception ex)
1184 System.err.println("Failed to create a file URL for "
1185 + tfile.getAbsoluteFile());
1192 Map<String, Object> vbinding = new HashMap<>();
1193 vbinding.put("Jalview", this);
1196 vbinding.put("currentAlFrame", af);
1198 Binding gbinding = new Binding(vbinding);
1199 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1200 gse.run(sfile.toString(), gbinding);
1201 if ("STDIN".equals(groovyscript))
1203 // delete temp file that we made -
1204 // only if it was successfully executed
1207 } catch (Exception e)
1209 System.err.println("Exception Whilst trying to execute file " + sfile
1210 + " as a groovy script.");
1211 e.printStackTrace(System.err);
1216 public AlignFrame[] getAlignFrames()
1218 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1219 : Desktop.getAlignFrames();
1224 * Quit method delegates to Desktop.quit - unless running in headless mode
1225 * when it just ends the JVM
1229 if (desktop != null)
1240 * Get the SwingJS applet ID and combine that with the frameType
1243 * "alignment", "desktop", etc., or null
1246 public static String getAppID(String frameType)
1248 String id = Cache.getProperty("Info.j2sAppletID");
1253 return id + (frameType == null ? "" : "-" + frameType);
1257 * Handle all JalviewLite applet parameters
1262 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1264 JalviewApp app = new JalviewApp()
1267 private boolean alignPDBStructures; // From JalviewLite; not implemented
1270 public String getParameter(String name)
1272 return aparser.getAppletValue(name, null);
1276 public boolean getDefaultParameter(String name, boolean def)
1279 return ((stn = getParameter(name)) == null ? def
1280 : "true".equalsIgnoreCase(stn));
1284 * Get the applet-like document base even though this is an application.
1287 public URL getDocumentBase()
1289 return Platform.getDocumentBase();
1293 * Get the applet-like code base even though this is an application.
1296 public URL getCodeBase()
1298 return Platform.getCodeBase();
1302 public AlignViewportI getViewport()
1304 return af.getViewport();
1312 public boolean parseFeaturesFile(String filename,
1313 DataSourceType protocol)
1315 return af.parseFeaturesFile(filename, protocol);
1323 public boolean loadScoreFile(String sScoreFile) throws IOException
1325 af.loadJalviewDataFile(sScoreFile, null, null, null);
1330 * annotations, jpredfile, jnetfile
1334 public void updateForAnnotations()
1336 af.updateForAnnotations();
1340 public void loadTree(NewickFile fin, String treeFile)
1343 // n/a -- already done by standard Jalview command line processing
1347 public void setAlignPdbStructures(boolean defaultParameter)
1349 alignPDBStructures = true;
1353 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1354 String[] chains, DataSourceType protocol)
1356 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1360 public void setFeatureGroupState(String[] groups, boolean state)
1362 af.setFeatureGroupState(groups, state);
1366 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1367 String[][] chains, String[] protocols)
1370 "Jalview applet interface alignedStructureView not implemented");
1374 public void newFeatureSettings()
1377 "Jalview applet interface newFeatureSettings not implemented");
1382 new JalviewAppLoader(true).load(app);
1386 public String getSelectedSequences()
1388 // TODO Auto-generated method stub
1393 public String getSelectedSequences(String sep)
1395 // TODO Auto-generated method stub
1400 public String getSelectedSequencesFrom(jalview.appletgui.AlignFrame alf)
1402 // TODO Auto-generated method stub
1407 public String getSelectedSequencesFrom(jalview.appletgui.AlignFrame alf,
1410 // TODO Auto-generated method stub
1415 public void highlight(String sequenceId, String position,
1416 String alignedPosition)
1418 // TODO Auto-generated method stub
1423 public void highlightIn(jalview.appletgui.AlignFrame alf,
1424 String sequenceId, String position, String alignedPosition)
1426 // TODO Auto-generated method stub
1431 public void select(String sequenceIds, String columns)
1433 // TODO Auto-generated method stub
1438 public void select(String sequenceIds, String columns, String sep)
1440 // TODO Auto-generated method stub
1445 public void selectIn(jalview.appletgui.AlignFrame alf, String sequenceIds,
1448 // TODO Auto-generated method stub
1453 public void selectIn(jalview.appletgui.AlignFrame alf, String sequenceIds,
1454 String columns, String sep)
1456 // TODO Auto-generated method stub
1461 public String getSelectedSequencesAsAlignment(String format,
1464 // TODO Auto-generated method stub
1469 public String getSelectedSequencesAsAlignmentFrom(
1470 jalview.appletgui.AlignFrame alf, String format, String suffix)
1472 // TODO Auto-generated method stub
1477 public String getAlignmentOrder()
1479 // TODO Auto-generated method stub
1484 public String getAlignmentOrderFrom(jalview.appletgui.AlignFrame alf)
1486 // TODO Auto-generated method stub
1491 public String getAlignmentOrderFrom(jalview.appletgui.AlignFrame alf,
1494 // TODO Auto-generated method stub
1499 public String orderBy(String order, String undoName)
1501 // TODO Auto-generated method stub
1506 public String orderBy(String order, String undoName, String sep)
1508 // TODO Auto-generated method stub
1513 public String orderAlignmentBy(jalview.appletgui.AlignFrame alf,
1514 String order, String undoName, String sep)
1516 // TODO Auto-generated method stub
1521 public String getAlignment(String format)
1523 // TODO Auto-generated method stub
1528 public String getAlignmentFrom(jalview.appletgui.AlignFrame alf,
1531 // TODO Auto-generated method stub
1536 public String getAlignment(String format, String suffix)
1538 // TODO Auto-generated method stub
1543 public String getAlignmentFrom(jalview.appletgui.AlignFrame alf,
1544 String format, String suffix)
1546 // TODO Auto-generated method stub
1551 public void loadAnnotation(String annotation)
1553 // TODO Auto-generated method stub
1558 public void loadAnnotationFrom(jalview.appletgui.AlignFrame alf,
1561 // TODO Auto-generated method stub
1566 public void loadFeatures(String features, boolean autoenabledisplay)
1568 // TODO Auto-generated method stub
1573 public boolean loadFeaturesFrom(jalview.appletgui.AlignFrame alf,
1574 String features, boolean autoenabledisplay)
1576 // TODO Auto-generated method stub
1581 public String getFeatures(String format)
1583 // TODO Auto-generated method stub
1588 public String getFeaturesFrom(jalview.appletgui.AlignFrame alf,
1591 // TODO Auto-generated method stub
1596 public String getAnnotation()
1598 // TODO Auto-generated method stub
1603 public String getAnnotationFrom(jalview.appletgui.AlignFrame alf)
1605 // TODO Auto-generated method stub
1610 public jalview.appletgui.AlignFrame newView()
1612 // TODO Auto-generated method stub
1617 public jalview.appletgui.AlignFrame newView(String name)
1619 // TODO Auto-generated method stub
1624 public jalview.appletgui.AlignFrame newViewFrom(
1625 jalview.appletgui.AlignFrame alf)
1627 // TODO Auto-generated method stub
1632 public jalview.appletgui.AlignFrame newViewFrom(
1633 jalview.appletgui.AlignFrame alf, String name)
1635 // TODO Auto-generated method stub
1640 public jalview.appletgui.AlignFrame loadAlignment(String text,
1643 // TODO Auto-generated method stub
1648 public void setMouseoverListener(String listener)
1650 // TODO Auto-generated method stub
1655 public void setMouseoverListener(jalview.appletgui.AlignFrame af,
1658 // TODO Auto-generated method stub
1663 public void setSelectionListener(String listener)
1665 // TODO Auto-generated method stub
1670 public void setSelectionListener(jalview.appletgui.AlignFrame af,
1673 // TODO Auto-generated method stub
1678 public void setStructureListener(String listener, String modelSet)
1680 // TODO Auto-generated method stub
1685 public void removeJavascriptListener(jalview.appletgui.AlignFrame af,
1688 // TODO Auto-generated method stub
1693 public void mouseOverStructure(String pdbResNum, String chain,
1696 // TODO Auto-generated method stub
1701 public boolean addPdbFile(jalview.appletgui.AlignFrame alFrame,
1702 String sequenceId, String pdbEntryString, String pdbFile)
1704 // TODO Auto-generated method stub
1709 public void scrollViewToIn(jalview.appletgui.AlignFrame alf,
1710 String topRow, String leftHandColumn)
1712 // TODO Auto-generated method stub
1717 public void scrollViewToRowIn(jalview.appletgui.AlignFrame alf,
1720 // TODO Auto-generated method stub
1725 public void scrollViewToColumnIn(jalview.appletgui.AlignFrame alf,
1726 String leftHandColumn)
1728 // TODO Auto-generated method stub
1733 public String getFeatureGroups()
1735 // TODO Auto-generated method stub
1740 public String getFeatureGroupsOn(jalview.appletgui.AlignFrame alf)
1742 // TODO Auto-generated method stub
1747 public String getFeatureGroupsOfState(boolean visible)
1749 // TODO Auto-generated method stub
1754 public String getFeatureGroupsOfStateOn(jalview.appletgui.AlignFrame alf,
1757 // TODO Auto-generated method stub
1762 public void setFeatureGroupStateOn(jalview.appletgui.AlignFrame alf,
1763 String groups, boolean state)
1765 // TODO Auto-generated method stub
1770 public void setFeatureGroupState(String groups, boolean state)
1772 // TODO Auto-generated method stub
1777 public String getSeparator()
1779 // TODO Auto-generated method stub
1784 public void setSeparator(String separator)
1786 // TODO Auto-generated method stub
1791 public String getJsMessage(String messageclass, String viewId)
1793 // TODO Auto-generated method stub