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.schemes.ColourSchemeI;
48 import jalview.schemes.ColourSchemeProperty;
49 import jalview.util.MessageManager;
50 import jalview.util.Platform;
51 import jalview.ws.jws2.Jws2Discoverer;
53 import java.io.BufferedReader;
55 import java.io.FileOutputStream;
56 import java.io.IOException;
57 import java.io.InputStreamReader;
58 import java.io.OutputStreamWriter;
59 import java.io.PrintWriter;
60 import java.net.MalformedURLException;
62 import java.net.URISyntaxException;
64 import java.security.AllPermission;
65 import java.security.CodeSource;
66 import java.security.PermissionCollection;
67 import java.security.Permissions;
68 import java.security.Policy;
69 import java.util.HashMap;
71 import java.util.Vector;
72 import java.util.logging.ConsoleHandler;
73 import java.util.logging.Level;
74 import java.util.logging.Logger;
76 import javax.swing.LookAndFeel;
77 import javax.swing.UIManager;
79 import groovy.lang.Binding;
80 import groovy.util.GroovyScriptEngine;
83 * Main class for Jalview Application <br>
85 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
88 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
89 * jalview.bin.Jalview jalview.bin.Jalview
91 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
92 * embellish '*' to e.g. '*.jar')
97 public class Jalview implements ApplicationSingletonI
100 public static Jalview getInstance()
102 return (Jalview) ApplicationSingletonProvider
103 .getInstance(Jalview.class);
112 Platform.getURLCommandArguments();
115 private boolean headless;
117 public static boolean isHeadlessMode()
119 return getInstance().headless;
122 private Desktop desktop;
124 private AlignFrame currentAlignFrame;
126 public boolean isJavaAppletTag;
128 public String appletResourcePath;
130 public static AlignFrame getCurrentAlignFrame()
132 return getInstance().currentAlignFrame;
135 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
137 getInstance().currentAlignFrame = currentAlignFrame;
142 if (!Platform.isJS())
149 // grab all the rights we can for the JVM
150 Policy.setPolicy(new Policy()
153 public PermissionCollection getPermissions(CodeSource codesource)
155 Permissions perms = new Permissions();
156 perms.add(new AllPermission());
161 public void refresh()
169 * keep track of feature fetching tasks.
177 * TODO: generalise to track all jalview events to orchestrate batch
181 private int queued = 0;
183 private int running = 0;
185 public FeatureFetcher()
190 public void addFetcher(final AlignFrame af,
191 final Vector<String> dasSources)
193 final long id = System.currentTimeMillis();
195 final FeatureFetcher us = this;
196 new Thread(new Runnable()
208 af.setProgressBar(MessageManager
209 .getString("status.das_features_being_retrived"), id);
210 af.featureSettings_actionPerformed(null);
211 af.setProgressBar(null, id);
220 public synchronized boolean allFinished()
222 return queued == 0 && running == 0;
228 * main class for Jalview application
231 * open <em>filename</em>
233 public static void main(String[] args)
235 // setLogging(); // BH - for event debugging in JavaScript
236 getInstance().doMain(args);
239 private static void logClass(String name)
241 // BH - for event debugging in JavaScript
242 ConsoleHandler consoleHandler = new ConsoleHandler();
243 consoleHandler.setLevel(Level.ALL);
244 Logger logger = Logger.getLogger(name);
245 logger.setLevel(Level.ALL);
246 logger.addHandler(consoleHandler);
249 @SuppressWarnings("unused")
250 private static void setLogging()
258 System.out.println("not in js");
261 // BH - for event debugging in JavaScript (Java mode only)
262 if (!Platform.isJS())
269 Logger.getLogger("").setLevel(Level.ALL);
270 logClass("java.awt.EventDispatchThread");
271 logClass("java.awt.EventQueue");
272 logClass("java.awt.Component");
273 logClass("java.awt.focus.Component");
274 logClass("java.awt.focus.DefaultKeyboardFocusManager");
282 void doMain(String[] args)
285 boolean isJS = Platform.isJS();
288 System.setSecurityManager(null);
292 .println("Java version: " + System.getProperty("java.version"));
293 System.out.println(System.getProperty("os.arch") + " "
294 + System.getProperty("os.name") + " "
295 + System.getProperty("os.version"));
297 ArgsParser aparser = new ArgsParser(args);
299 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
300 Cache.loadProperties(usrPropsFile);
303 isJavaAppletTag = aparser.isApplet();
306 Preferences.setAppletDefaults();
307 Cache.loadProperties(usrPropsFile); // again, because we
308 // might be changing defaults here?
311 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
312 appletResourcePath = aparser.getValue("Info.resourcePath");
321 if (usrPropsFile != null)
324 "CMD [-props " + usrPropsFile + "] executed successfully!");
327 if (aparser.contains("help") || aparser.contains("h"))
332 if (aparser.contains(ArgsParser.NODISPLAY)
333 || aparser.contains(ArgsParser.NOGUI)
334 || aparser.contains(ArgsParser.HEADLESS)
335 || "true".equals(System.getProperty("java.awt.headless")))
342 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
343 if (jabawsUrl != null)
347 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
349 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
350 } catch (MalformedURLException e)
353 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
358 // check for property setting
359 String defs = aparser.getValue(ArgsParser.SETPROP);
362 int p = defs.indexOf('=');
365 System.err.println("Ignoring invalid setprop argument : " + defs);
369 System.out.println("Executing setprop argument: " + defs);
372 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
375 defs = aparser.getValue(ArgsParser.SETPROP);
377 System.setProperty("http.agent",
378 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
382 } catch (NoClassDefFoundError error)
384 error.printStackTrace();
385 System.out.println("\nEssential logging libraries not found."
386 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
394 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
395 } catch (Exception ex)
397 System.err.println("Unexpected Look and Feel Exception");
398 ex.printStackTrace();
400 if (Platform.isAMacAndNotJS())
403 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
405 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
407 System.setProperty("apple.laf.useScreenMenuBar", "true");
408 if (lookAndFeel != null)
412 UIManager.setLookAndFeel(lookAndFeel);
413 } catch (Throwable e)
416 "Failed to set QuaQua look and feel: " + e.toString());
419 if (lookAndFeel == null
420 || !(lookAndFeel.getClass().isAssignableFrom(
421 UIManager.getLookAndFeel().getClass()))
422 || !UIManager.getLookAndFeel().getClass().toString()
423 .toLowerCase().contains("quaqua"))
428 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
429 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
430 } catch (Throwable e)
433 "Failed to reset look and feel: " + e.toString());
439 * configure 'full' SO model if preferences say to,
440 * else use the default (SO Lite)
442 if (Cache.getDefault("USE_FULL_SO", false))
444 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
449 desktop = Desktop.getInstance();
450 desktop.setInBatchMode(true); // indicate we are starting up
451 desktop.setVisible(true);
460 desktop.startServiceDiscovery();
461 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
463 startUsageStats(desktop);
467 System.err.println("CMD [-nousagestats] executed successfully!");
470 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
472 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
475 // Start the desktop questionnaire prompter with the specified
477 Cache.log.debug("Starting questionnaire url at " + url);
478 desktop.checkForQuestionnaire(url);
479 System.out.println("CMD questionnaire[-" + url
480 + "] executed successfully!");
484 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
486 // Start the desktop questionnaire prompter with the specified
489 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
491 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
493 "Starting questionnaire with default url: " + defurl);
494 desktop.checkForQuestionnaire(defurl);
501 .println("CMD [-noquestionnaire] executed successfully!");
504 if (!aparser.contains(ArgsParser.NONEWS))
506 desktop.checkForNews();
509 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 String file2 = (isJavaAppletTag ? aparser.getAppletValue("file2", null)
522 String fileFormat = (isJavaAppletTag
523 ? aparser.getAppletValue("format", null)
525 FileFormatI format = null;
526 DataSourceType protocol = null;
528 if (file == null && desktop == null)
530 System.out.println("No files to open!");
533 boolean haveImport = checkStartVamas(aparser);
534 // Finally, deal with the remaining input data.
540 desktop.setProgressBar(
542 .getString("status.processing_commandline_args"),
543 progress = System.currentTimeMillis());
548 * ignore in JavaScript -- can't just check file existence - could load
554 if (!file.startsWith("http://") && !file.startsWith("https://"))
555 // BH 2019 added https check for Java
557 if (!(new File(file)).exists())
559 System.out.println("Can't find " + file);
568 protocol = AppletFormatAdapter.checkProtocol(file);
572 format = (isJavaAppletTag && fileFormat != null
573 ? FileFormats.getInstance().forName(fileFormat)
577 format = new IdentifyFile().identify(file, protocol);
579 } catch (FileFormatException e1)
584 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
589 System.out.println("error");
594 .println("CMD [-open " + file + "] executed successfully!");
597 protocol = AppletFormatAdapter.checkProtocol(file2);
600 format = new IdentifyFile().identify(file2, protocol);
601 } catch (FileFormatException e1)
605 AlignFrame af2 = new FileLoader(!headless).loadFileWaitTillLoaded(
610 System.out.println("error");
614 AlignViewport.openLinkedAlignmentAs(af,
615 af.getViewport().getAlignment(),
616 af2.getViewport().getAlignment(), "",
617 AlignViewport.SPLIT_FRAME);
621 setCurrentAlignFrame(af);
623 // TODO: file2 How to implement file2 for the applet spit screen?
625 String data = aparser.getValue(ArgsParser.COLOUR, true);
628 data.replaceAll("%20", " ");
630 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
631 af.getViewport(), af.getViewport().getAlignment(), data);
636 "CMD [-color " + data + "] executed successfully!");
641 // Must maintain ability to use the groups flag
642 data = aparser.getValue(ArgsParser.GROUPS, true);
645 af.parseFeaturesFile(data,
646 AppletFormatAdapter.checkProtocol(data));
647 // System.out.println("Added " + data);
649 "CMD groups[-" + data + "] executed successfully!");
651 data = aparser.getValue(ArgsParser.FEATURES, true);
654 af.parseFeaturesFile(data,
655 AppletFormatAdapter.checkProtocol(data));
656 // System.out.println("Added " + data);
658 "CMD [-features " + data + "] executed successfully!");
661 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
664 af.loadJalviewDataFile(data, null, null, null);
665 // System.out.println("Added " + data);
667 "CMD [-annotations " + data + "] executed successfully!");
669 // set or clear the sortbytree flag.
670 if (aparser.contains(ArgsParser.SORTBYTREE))
672 af.getViewport().setSortByTree(true);
673 if (af.getViewport().getSortByTree())
675 System.out.println("CMD [-sortbytree] executed successfully!");
678 if (aparser.contains(ArgsParser.NOANNOTATION)
679 || aparser.contains(ArgsParser.NOANNOTATION2))
681 af.getViewport().setShowAnnotation(false);
682 if (!af.getViewport().isShowAnnotation())
684 System.out.println("CMD no-annotation executed successfully!");
687 if (aparser.contains(ArgsParser.NOSORTBYTREE))
689 af.getViewport().setSortByTree(false);
690 if (!af.getViewport().getSortByTree())
693 .println("CMD [-nosortbytree] executed successfully!");
696 data = aparser.getValue(ArgsParser.TREE, true);
702 "CMD [-tree " + data + "] executed successfully!");
703 NewickFile nf = new NewickFile(data,
704 AppletFormatAdapter.checkProtocol(data));
706 .setCurrentTree(af.showNewickTree(nf, data).getTree());
707 } catch (IOException ex)
709 System.err.println("Couldn't add tree " + data);
710 ex.printStackTrace(System.err);
713 // TODO - load PDB structure(s) to alignment JAL-629
714 // (associate with identical sequence in alignment, or a specified
718 loadAppletParams(aparser, af);
727 if (groovyscript != null)
729 // Execute the groovy script after we've done all the rendering
731 // and before any images or figures are generated.
732 System.out.println("Executing script " + groovyscript);
733 executeGroovyScript(groovyscript, af);
734 System.out.println("CMD groovy[" + groovyscript
735 + "] executed successfully!");
738 checkOutputFile(aparser, af, format);
739 while (aparser.getSize() > 0)
741 System.out.println("Unknown arg: " + aparser.nextValue());
746 AlignFrame startUpAlframe = null;
747 // We'll only open the default file if the desktop is visible.
749 // ////////////////////
751 if (!isJS && !headless && file == null && !haveImport
752 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
759 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
760 jalview.bin.Cache.getDefault("www.jalview.org",
761 "http://www.jalview.org")
762 + "/examples/exampleFile_2_7.jar");
764 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
766 // hardwire upgrade of the startup file
767 file.replace("_2_3.jar", "_2_7.jar");
768 // and remove the stale setting
769 jalview.bin.Cache.removeProperty("STARTUP_FILE");
772 protocol = DataSourceType.FILE;
774 if (file.indexOf("http:") > -1)
776 protocol = DataSourceType.URL;
779 if (file.endsWith(".jar"))
781 format = FileFormat.Jalview;
787 format = new IdentifyFile().identify(file, protocol);
788 } catch (FileFormatException e)
794 startUpAlframe = new FileLoader(!headless)
795 .loadFileWaitTillLoaded(file, protocol,
797 // extract groovy arguments before anything else.
800 // Once all other stuff is done, execute any groovy scripts (in order)
801 if (groovyscript != null)
803 if (Cache.groovyJarsPresent())
805 System.out.println("Executing script " + groovyscript);
806 executeGroovyScript(groovyscript, startUpAlframe);
811 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
815 // and finally, turn off batch mode indicator - if the desktop still exists
820 desktop.setProgressBar(null, progress);
822 desktop.setInBatchMode(false);
826 private boolean checkStartVamas(ArgsParser aparser)
828 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
829 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
830 if (vamsasImport == null && vamsasSession == null)
834 if (desktop == null || headless)
837 "Headless vamsas sessions not yet supported. Sorry.");
840 boolean haveImport = (vamsasImport != null);
843 // if we have a file, start a new session and import it.
844 boolean inSession = false;
847 DataSourceType viprotocol = AppletFormatAdapter
848 .checkProtocol(vamsasImport);
849 if (viprotocol == DataSourceType.FILE)
851 inSession = desktop.vamsasImport(new File(vamsasImport));
853 else if (viprotocol == DataSourceType.URL)
855 inSession = desktop.vamsasImport(new URL(vamsasImport));
858 } catch (Exception e)
860 System.err.println("Exeption when importing " + vamsasImport
861 + " as a vamsas document.");
866 System.err.println("Failed to import " + vamsasImport
867 + " as a vamsas document.");
871 System.out.println("Imported Successfully into new session "
872 + desktop.getVamsasApplication().getCurrentSession());
875 if (vamsasSession != null)
877 if (vamsasImport != null)
879 // close the newly imported session and import the Jalview specific
880 // remnants into the new session later on.
881 desktop.vamsasStop_actionPerformed(null);
883 // now join the new session
886 if (desktop.joinVamsasSession(vamsasSession))
889 "Successfully joined vamsas session " + vamsasSession);
893 System.err.println("WARNING: Failed to join vamsas session "
896 } catch (Exception e)
899 "ERROR: Failed to join vamsas session " + vamsasSession);
902 if (vamsasImport != null)
904 // the Jalview specific remnants can now be imported into the new
905 // session at the user's leisure.
907 "Skipping Push for import of data into existing vamsas session."); // TODO:
912 // desktop.getVamsasApplication().push_update();
918 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
921 String imageName = "unnamed.png";
922 while (aparser.getSize() > 1)
928 String outputFormat = aparser.nextValue();
929 String file = aparser.nextValue();
930 if (outputFormat.equalsIgnoreCase("png"))
932 af.createPNG(new File(file));
933 imageName = (new File(file)).getName();
934 System.out.println("Creating PNG image: " + file);
937 else if (outputFormat.equalsIgnoreCase("svg"))
939 File imageFile = new File(file);
940 imageName = imageFile.getName();
941 af.createSVG(imageFile);
942 System.out.println("Creating SVG image: " + file);
945 else if (outputFormat.equalsIgnoreCase("html"))
947 File imageFile = new File(file);
948 imageName = imageFile.getName();
949 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
950 htmlSVG.exportHTML(file);
952 System.out.println("Creating HTML image: " + file);
955 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
959 System.err.println("The output html file must not be null");
964 BioJsHTMLOutput.refreshVersionInfo(
965 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
966 } catch (URISyntaxException e)
970 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
971 bjs.exportHTML(file);
972 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
975 else if (outputFormat.equalsIgnoreCase("imgMap"))
977 af.createImageMap(new File(file), imageName);
978 System.out.println("Creating image map: " + file);
981 else if (outputFormat.equalsIgnoreCase("eps"))
983 File outputFile = new File(file);
985 "Creating EPS file: " + outputFile.getAbsolutePath());
986 af.createEPS(outputFile);
990 af.saveAlignment(file, format);
991 if (af.isSaveAlignmentSuccessful())
994 "Written alignment in " + format + " format to " + file);
998 System.out.println("Error writing file " + file + " in " + format
1005 private static void showUsage()
1008 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1009 + "-nodisplay\tRun Jalview without User Interface.\n"
1010 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1011 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1012 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1013 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1014 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1015 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1016 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1017 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1018 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1019 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1020 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1021 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1022 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1023 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1024 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1025 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1026 + "-html FILE\tCreate HTML file from alignment.\n"
1027 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1028 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1029 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1030 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1031 + "-noquestionnaire\tTurn off questionnaire check.\n"
1032 + "-nonews\tTurn off check for Jalview news.\n"
1033 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1034 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1036 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1037 // after all other properties files have been read\n\t
1038 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1039 // passed in correctly)"
1040 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1041 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1043 // "-vdoc vamsas-document\tImport vamsas document into new
1044 // session or join existing session with same URN\n"
1045 // + "-vses vamsas-session\tJoin session with given URN\n"
1046 + "-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"
1047 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1050 private static void startUsageStats(final Desktop desktop)
1053 * start a User Config prompt asking if we can log usage statistics.
1055 PromptUserConfig prompter = new PromptUserConfig(
1056 Desktop.getDesktopPane(), "USAGESTATS",
1057 "Jalview Usage Statistics",
1058 "Do you want to help make Jalview better by enabling "
1059 + "the collection of usage statistics with Google Analytics ?"
1060 + "\n\n(you can enable or disable usage tracking in the preferences)",
1067 "Initialising googletracker for usage stats.");
1068 Cache.initGoogleTracker();
1069 Cache.log.debug("Tracking enabled.");
1076 Cache.log.debug("Not enabling Google Tracking.");
1079 desktop.addDialogThread(prompter);
1083 * Locate the given string as a file and pass it to the groovy interpreter.
1085 * @param groovyscript
1086 * the script to execute
1087 * @param jalviewContext
1088 * the Jalview Desktop object passed in to the groovy binding as the
1091 private void executeGroovyScript(String groovyscript, AlignFrame af)
1094 * for scripts contained in files
1101 if (groovyscript.trim().equals("STDIN"))
1103 // read from stdin into a tempfile and execute it
1106 tfile = File.createTempFile("jalview", "groovy");
1107 PrintWriter outfile = new PrintWriter(
1108 new OutputStreamWriter(new FileOutputStream(tfile)));
1109 BufferedReader br = new BufferedReader(
1110 new InputStreamReader(System.in));
1112 while ((line = br.readLine()) != null)
1114 outfile.write(line + "\n");
1120 } catch (Exception ex)
1122 System.err.println("Failed to read from STDIN into tempfile "
1123 + ((tfile == null) ? "(tempfile wasn't created)"
1124 : tfile.toString()));
1125 ex.printStackTrace();
1130 sfile = tfile.toURI().toURL();
1131 } catch (Exception x)
1134 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1136 x.printStackTrace();
1144 sfile = new URI(groovyscript).toURL();
1145 } catch (Exception x)
1147 tfile = new File(groovyscript);
1148 if (!tfile.exists())
1150 System.err.println("File '" + groovyscript + "' does not exist.");
1153 if (!tfile.canRead())
1155 System.err.println("File '" + groovyscript + "' cannot be read.");
1158 if (tfile.length() < 1)
1160 System.err.println("File '" + groovyscript + "' is empty.");
1165 sfile = tfile.getAbsoluteFile().toURI().toURL();
1166 } catch (Exception ex)
1168 System.err.println("Failed to create a file URL for "
1169 + tfile.getAbsoluteFile());
1176 Map<String, Object> vbinding = new HashMap<>();
1177 vbinding.put("Jalview", this);
1180 vbinding.put("currentAlFrame", af);
1182 Binding gbinding = new Binding(vbinding);
1183 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1184 gse.run(sfile.toString(), gbinding);
1185 if ("STDIN".equals(groovyscript))
1187 // delete temp file that we made -
1188 // only if it was successfully executed
1191 } catch (Exception e)
1193 System.err.println("Exception Whilst trying to execute file " + sfile
1194 + " as a groovy script.");
1195 e.printStackTrace(System.err);
1200 public AlignFrame[] getAlignFrames()
1202 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1203 : Desktop.getAlignFrames();
1208 * Quit method delegates to Desktop.quit - unless running in headless mode
1209 * when it just ends the JVM
1213 if (desktop != null)
1224 * Get the SwingJS applet ID and combine that with the frameType
1227 * "alignment", "desktop", etc., or null
1230 public static String getAppID(String frameType)
1232 String id = Cache.getProperty("Info.j2sAppletID");
1237 return id + (frameType == null ? "" : "-" + frameType);
1241 * Handle all JalviewLite applet parameters
1246 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1248 JalviewApp app = new JalviewApp()
1251 private boolean alignPDBStructures; // From JalviewLite; not implemented
1254 public String getParameter(String name)
1256 return aparser.getAppletValue(name, null);
1260 public boolean getDefaultParameter(String name, boolean def)
1263 return ((stn = getParameter(name)) == null ? def
1264 : "true".equalsIgnoreCase(stn));
1268 * Get the applet-like document base even though this is an application.
1271 public URL getDocumentBase()
1273 return Platform.getDocumentBase();
1277 * Get the applet-like code base even though this is an application.
1280 public URL getCodeBase()
1282 return Platform.getCodeBase();
1286 public AlignViewportI getViewport()
1288 return af.getViewport();
1296 public boolean parseFeaturesFile(String filename,
1297 DataSourceType protocol)
1299 return af.parseFeaturesFile(filename, protocol);
1307 public boolean loadScoreFile(String sScoreFile) throws IOException
1309 af.loadJalviewDataFile(sScoreFile, null, null, null);
1314 * annotations, jpredfile, jnetfile
1318 public void updateForAnnotations()
1320 af.updateForAnnotations();
1324 public void loadTree(NewickFile fin, String treeFile)
1327 // n/a -- already done by standard Jalview command line processing
1331 public void setAlignPdbStructures(boolean defaultParameter)
1333 alignPDBStructures = true;
1337 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1338 String[] chains, DataSourceType protocol)
1340 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1344 public void setFeatureGroupState(String[] groups, boolean state)
1346 af.setFeatureGroupState(groups, state);
1350 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1351 String[][] chains, String[] protocols)
1354 "Jalview applet interface alignedStructureView not implemented");
1358 public void newFeatureSettings()
1361 "Jalview applet interface newFeatureSettings not implemented");
1366 new JalviewAppLoader(true).load(app);