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.Desktop;
31 import jalview.gui.Preferences;
32 import jalview.gui.PromptUserConfig;
33 import jalview.gui.StructureViewer;
34 import jalview.io.AppletFormatAdapter;
35 import jalview.io.BioJsHTMLOutput;
36 import jalview.io.DataSourceType;
37 import jalview.io.FileFormat;
38 import jalview.io.FileFormatException;
39 import jalview.io.FileFormatI;
40 import jalview.io.FileFormats;
41 import jalview.io.FileLoader;
42 import jalview.io.HtmlSvgOutput;
43 import jalview.io.IdentifyFile;
44 import jalview.io.NewickFile;
45 import jalview.io.gff.SequenceOntologyFactory;
46 import jalview.schemes.ColourSchemeI;
47 import jalview.schemes.ColourSchemeProperty;
48 import jalview.util.MessageManager;
49 import jalview.util.Platform;
50 import jalview.ws.jws2.Jws2Discoverer;
52 import java.io.BufferedReader;
54 import java.io.FileOutputStream;
55 import java.io.IOException;
56 import java.io.InputStreamReader;
57 import java.io.OutputStreamWriter;
58 import java.io.PrintWriter;
59 import java.net.MalformedURLException;
61 import java.net.URISyntaxException;
63 import java.security.AllPermission;
64 import java.security.CodeSource;
65 import java.security.PermissionCollection;
66 import java.security.Permissions;
67 import java.security.Policy;
68 import java.util.HashMap;
70 import java.util.Vector;
71 import java.util.logging.ConsoleHandler;
72 import java.util.logging.Level;
73 import java.util.logging.Logger;
75 import javax.swing.LookAndFeel;
76 import javax.swing.UIManager;
78 import groovy.lang.Binding;
79 import groovy.util.GroovyScriptEngine;
82 * Main class for Jalview Application <br>
84 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
87 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
88 * jalview.bin.Jalview jalview.bin.Jalview
90 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
91 * embellish '*' to e.g. '*.jar')
96 public class Jalview implements ApplicationSingletonI
99 public static Jalview getInstance()
101 return (Jalview) ApplicationSingletonProvider
102 .getInstance(Jalview.class);
111 Platform.getURLCommandArguments();
114 private boolean headless;
116 public static boolean isHeadlessMode()
118 return getInstance().headless;
121 private Desktop desktop;
123 private AlignFrame currentAlignFrame;
125 public boolean isJavaAppletTag;
127 public String appletResourcePath;
129 public static AlignFrame getCurrentAlignFrame()
131 return getInstance().currentAlignFrame;
134 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
136 getInstance().currentAlignFrame = currentAlignFrame;
141 if (!Platform.isJS())
148 // grab all the rights we can for the JVM
149 Policy.setPolicy(new Policy()
152 public PermissionCollection getPermissions(CodeSource codesource)
154 Permissions perms = new Permissions();
155 perms.add(new AllPermission());
160 public void refresh()
168 * keep track of feature fetching tasks.
176 * TODO: generalise to track all jalview events to orchestrate batch
180 private int queued = 0;
182 private int running = 0;
184 public FeatureFetcher()
189 public void addFetcher(final AlignFrame af,
190 final Vector<String> dasSources)
192 final long id = System.currentTimeMillis();
194 final FeatureFetcher us = this;
195 new Thread(new Runnable()
207 af.setProgressBar(MessageManager
208 .getString("status.das_features_being_retrived"), id);
209 af.featureSettings_actionPerformed(null);
210 af.setProgressBar(null, id);
219 public synchronized boolean allFinished()
221 return queued == 0 && running == 0;
227 * main class for Jalview application
230 * open <em>filename</em>
232 public static void main(String[] args)
234 // setLogging(); // BH - for event debugging in JavaScript
235 getInstance().doMain(args);
238 private static void logClass(String name)
240 // BH - for event debugging in JavaScript
241 ConsoleHandler consoleHandler = new ConsoleHandler();
242 consoleHandler.setLevel(Level.ALL);
243 Logger logger = Logger.getLogger(name);
244 logger.setLevel(Level.ALL);
245 logger.addHandler(consoleHandler);
248 @SuppressWarnings("unused")
249 private static void setLogging()
257 System.out.println("not in js");
260 // BH - for event debugging in JavaScript (Java mode only)
261 if (!Platform.isJS())
268 Logger.getLogger("").setLevel(Level.ALL);
269 logClass("java.awt.EventDispatchThread");
270 logClass("java.awt.EventQueue");
271 logClass("java.awt.Component");
272 logClass("java.awt.focus.Component");
273 logClass("java.awt.focus.DefaultKeyboardFocusManager");
281 void doMain(String[] args)
284 boolean isJS = Platform.isJS();
287 System.setSecurityManager(null);
291 .println("Java version: " + System.getProperty("java.version"));
292 System.out.println(System.getProperty("os.arch") + " "
293 + System.getProperty("os.name") + " "
294 + System.getProperty("os.version"));
296 ArgsParser aparser = new ArgsParser(args);
298 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
299 Cache.loadProperties(usrPropsFile);
302 isJavaAppletTag = aparser.isApplet();
305 Preferences.setAppletDefaults();
306 Cache.loadProperties(usrPropsFile); // again, because we
307 // might be changing defaults here?
310 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
311 appletResourcePath = aparser.getValue("Info.resourcePath");
320 if (usrPropsFile != null)
323 "CMD [-props " + usrPropsFile + "] executed successfully!");
326 if (aparser.contains("help") || aparser.contains("h"))
331 if (aparser.contains(ArgsParser.NODISPLAY)
332 || aparser.contains(ArgsParser.NOGUI)
333 || aparser.contains(ArgsParser.HEADLESS)
334 || "true".equals(System.getProperty("java.awt.headless")))
341 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
342 if (jabawsUrl != null)
346 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
348 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
349 } catch (MalformedURLException e)
352 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
357 // check for property setting
358 String defs = aparser.getValue(ArgsParser.SETPROP);
361 int p = defs.indexOf('=');
364 System.err.println("Ignoring invalid setprop argument : " + defs);
368 System.out.println("Executing setprop argument: " + defs);
371 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
374 defs = aparser.getValue(ArgsParser.SETPROP);
376 System.setProperty("http.agent",
377 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
381 } catch (NoClassDefFoundError error)
383 error.printStackTrace();
384 System.out.println("\nEssential logging libraries not found."
385 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
393 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
394 } catch (Exception ex)
396 System.err.println("Unexpected Look and Feel Exception");
397 ex.printStackTrace();
399 if (Platform.isAMacAndNotJS())
402 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
404 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
406 System.setProperty("apple.laf.useScreenMenuBar", "true");
407 if (lookAndFeel != null)
411 UIManager.setLookAndFeel(lookAndFeel);
412 } catch (Throwable e)
415 "Failed to set QuaQua look and feel: " + e.toString());
418 if (lookAndFeel == null
419 || !(lookAndFeel.getClass().isAssignableFrom(
420 UIManager.getLookAndFeel().getClass()))
421 || !UIManager.getLookAndFeel().getClass().toString()
422 .toLowerCase().contains("quaqua"))
427 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
428 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
429 } catch (Throwable e)
432 "Failed to reset look and feel: " + e.toString());
438 * configure 'full' SO model if preferences say to,
439 * else use the default (SO Lite)
441 if (Cache.getDefault("USE_FULL_SO", false))
443 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
448 desktop = Desktop.getInstance();
449 desktop.setInBatchMode(true); // indicate we are starting up
450 desktop.setVisible(true);
459 desktop.startServiceDiscovery();
460 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
462 startUsageStats(desktop);
466 System.err.println("CMD [-nousagestats] executed successfully!");
469 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
471 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
474 // Start the desktop questionnaire prompter with the specified
476 Cache.log.debug("Starting questionnaire url at " + url);
477 desktop.checkForQuestionnaire(url);
478 System.out.println("CMD questionnaire[-" + url
479 + "] executed successfully!");
483 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
485 // Start the desktop questionnaire prompter with the specified
488 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
490 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
492 "Starting questionnaire with default url: " + defurl);
493 desktop.checkForQuestionnaire(defurl);
500 .println("CMD [-noquestionnaire] executed successfully!");
503 if (!aparser.contains(ArgsParser.NONEWS))
505 desktop.checkForNews();
508 BioJsHTMLOutput.updateBioJS();
513 FileLoader fileLoader = new FileLoader(!headless);
515 // script to execute after all loading is
516 // completed one way or another
517 // extract groovy argument and execute if necessary
518 String groovyscript = (isJS ? null
519 : aparser.getValue(ArgsParser.GROOVY, true));
520 String file = aparser.getValue(ArgsParser.OPEN, true);
521 String file2 = (isJavaAppletTag ? aparser.getAppletValue("file2", null)
523 String fileFormat = (isJavaAppletTag
524 ? 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.
541 desktop.setProgressBar(
543 .getString("status.processing_commandline_args"),
544 progress = System.currentTimeMillis());
546 System.out.println("CMD [-open " + file + "] executed successfully!");
550 * ignore in JavaScript -- can't just check file existence - could load
556 if (!file.startsWith("http://") && !file.startsWith("https://"))
557 // BH 2019 added https check for Java
559 if (!(new File(file)).exists())
561 System.out.println("Can't find " + file);
570 protocol = AppletFormatAdapter.checkProtocol(file);
574 format = (isJavaAppletTag && fileFormat != null
575 ? FileFormats.getInstance().forName(fileFormat)
579 format = new IdentifyFile().identify(file, protocol);
581 } catch (FileFormatException e1)
586 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
590 System.out.println("error");
594 setCurrentAlignFrame(af);
596 // TODO: file2 How to implement file2 for the applet spit screen?
598 data = aparser.getValue(ArgsParser.COLOUR, true);
601 data.replaceAll("%20", " ");
603 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
604 af.getViewport(), af.getViewport().getAlignment(), data);
609 "CMD [-color " + data + "] executed successfully!");
614 // Must maintain ability to use the groups flag
615 data = aparser.getValue(ArgsParser.GROUPS, true);
618 af.parseFeaturesFile(data,
619 AppletFormatAdapter.checkProtocol(data));
620 // System.out.println("Added " + data);
622 "CMD groups[-" + data + "] executed successfully!");
624 data = aparser.getValue(ArgsParser.FEATURES, true);
627 af.parseFeaturesFile(data,
628 AppletFormatAdapter.checkProtocol(data));
629 // System.out.println("Added " + data);
631 "CMD [-features " + data + "] executed successfully!");
634 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
637 af.loadJalviewDataFile(data, null, null, null);
638 // System.out.println("Added " + data);
640 "CMD [-annotations " + data + "] executed successfully!");
642 // set or clear the sortbytree flag.
643 if (aparser.contains(ArgsParser.SORTBYTREE))
645 af.getViewport().setSortByTree(true);
646 if (af.getViewport().getSortByTree())
648 System.out.println("CMD [-sortbytree] executed successfully!");
651 if (aparser.contains(ArgsParser.NOANNOTATION)
652 || aparser.contains(ArgsParser.NOANNOTATION2))
654 af.getViewport().setShowAnnotation(false);
655 if (!af.getViewport().isShowAnnotation())
657 System.out.println("CMD no-annotation executed successfully!");
660 if (aparser.contains(ArgsParser.NOSORTBYTREE))
662 af.getViewport().setSortByTree(false);
663 if (!af.getViewport().getSortByTree())
666 .println("CMD [-nosortbytree] executed successfully!");
669 data = aparser.getValue(ArgsParser.TREE, true);
675 "CMD [-tree " + data + "] executed successfully!");
676 NewickFile nf = new NewickFile(data,
677 AppletFormatAdapter.checkProtocol(data));
679 .setCurrentTree(af.showNewickTree(nf, data).getTree());
680 } catch (IOException ex)
682 System.err.println("Couldn't add tree " + data);
683 ex.printStackTrace(System.err);
686 // TODO - load PDB structure(s) to alignment JAL-629
687 // (associate with identical sequence in alignment, or a specified
691 loadAppletParams(aparser, af);
700 if (groovyscript != null)
702 // Execute the groovy script after we've done all the rendering stuff
703 // and before any images or figures are generated.
704 System.out.println("Executing script " + groovyscript);
705 executeGroovyScript(groovyscript, af);
706 System.out.println("CMD groovy[" + groovyscript
707 + "] executed successfully!");
710 checkOutputFile(aparser, af, format);
711 while (aparser.getSize() > 0)
713 System.out.println("Unknown arg: " + aparser.nextValue());
718 AlignFrame startUpAlframe = null;
719 // We'll only open the default file if the desktop is visible.
721 // ////////////////////
723 if (!isJS && !headless && file == null && !haveImport
724 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
731 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
732 jalview.bin.Cache.getDefault("www.jalview.org",
733 "http://www.jalview.org")
734 + "/examples/exampleFile_2_7.jar");
736 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
738 // hardwire upgrade of the startup file
739 file.replace("_2_3.jar", "_2_7.jar");
740 // and remove the stale setting
741 jalview.bin.Cache.removeProperty("STARTUP_FILE");
744 protocol = DataSourceType.FILE;
746 if (file.indexOf("http:") > -1)
748 protocol = DataSourceType.URL;
751 if (file.endsWith(".jar"))
753 format = FileFormat.Jalview;
759 format = new IdentifyFile().identify(file, protocol);
760 } catch (FileFormatException e)
766 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
768 // extract groovy arguments before anything else.
771 // Once all other stuff is done, execute any groovy scripts (in order)
772 if (groovyscript != null)
774 if (Cache.groovyJarsPresent())
776 System.out.println("Executing script " + groovyscript);
777 executeGroovyScript(groovyscript, startUpAlframe);
782 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
786 // and finally, turn off batch mode indicator - if the desktop still exists
791 desktop.setProgressBar(null, progress);
793 desktop.setInBatchMode(false);
797 private boolean checkStartVamas(ArgsParser aparser)
799 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
800 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
801 if (vamsasImport == null && vamsasSession == null)
805 if (desktop == null || headless)
808 "Headless vamsas sessions not yet supported. Sorry.");
811 boolean haveImport = (vamsasImport != null);
814 // if we have a file, start a new session and import it.
815 boolean inSession = false;
818 DataSourceType viprotocol = AppletFormatAdapter
819 .checkProtocol(vamsasImport);
820 if (viprotocol == DataSourceType.FILE)
822 inSession = desktop.vamsasImport(new File(vamsasImport));
824 else if (viprotocol == DataSourceType.URL)
826 inSession = desktop.vamsasImport(new URL(vamsasImport));
829 } catch (Exception e)
831 System.err.println("Exeption when importing " + vamsasImport
832 + " as a vamsas document.");
837 System.err.println("Failed to import " + vamsasImport
838 + " as a vamsas document.");
842 System.out.println("Imported Successfully into new session "
843 + desktop.getVamsasApplication().getCurrentSession());
846 if (vamsasSession != null)
848 if (vamsasImport != null)
850 // close the newly imported session and import the Jalview specific
851 // remnants into the new session later on.
852 desktop.vamsasStop_actionPerformed(null);
854 // now join the new session
857 if (desktop.joinVamsasSession(vamsasSession))
860 "Successfully joined vamsas session " + vamsasSession);
864 System.err.println("WARNING: Failed to join vamsas session "
867 } catch (Exception e)
870 "ERROR: Failed to join vamsas session " + vamsasSession);
873 if (vamsasImport != null)
875 // the Jalview specific remnants can now be imported into the new
876 // session at the user's leisure.
878 "Skipping Push for import of data into existing vamsas session."); // TODO:
883 // desktop.getVamsasApplication().push_update();
889 private void checkOutputFile(ArgsParser aparser, AlignFrame af,
892 String imageName = "unnamed.png";
893 while (aparser.getSize() > 1)
899 String outputFormat = aparser.nextValue();
900 String file = aparser.nextValue();
901 if (outputFormat.equalsIgnoreCase("png"))
903 af.createPNG(new File(file));
904 imageName = (new File(file)).getName();
905 System.out.println("Creating PNG image: " + file);
908 else if (outputFormat.equalsIgnoreCase("svg"))
910 File imageFile = new File(file);
911 imageName = imageFile.getName();
912 af.createSVG(imageFile);
913 System.out.println("Creating SVG image: " + file);
916 else if (outputFormat.equalsIgnoreCase("html"))
918 File imageFile = new File(file);
919 imageName = imageFile.getName();
920 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
921 htmlSVG.exportHTML(file);
923 System.out.println("Creating HTML image: " + file);
926 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
930 System.err.println("The output html file must not be null");
935 BioJsHTMLOutput.refreshVersionInfo(
936 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
937 } catch (URISyntaxException e)
941 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
942 bjs.exportHTML(file);
943 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
946 else if (outputFormat.equalsIgnoreCase("imgMap"))
948 af.createImageMap(new File(file), imageName);
949 System.out.println("Creating image map: " + file);
952 else if (outputFormat.equalsIgnoreCase("eps"))
954 File outputFile = new File(file);
956 "Creating EPS file: " + outputFile.getAbsolutePath());
957 af.createEPS(outputFile);
961 af.saveAlignment(file, format);
962 if (af.isSaveAlignmentSuccessful())
965 "Written alignment in " + format + " format to " + file);
969 System.out.println("Error writing file " + file + " in " + format
976 private static void showUsage()
979 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
980 + "-nodisplay\tRun Jalview without User Interface.\n"
981 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
982 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
983 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
984 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
985 + "-features FILE\tUse the given file to mark features on the alignment.\n"
986 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
987 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
988 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
989 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
990 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
991 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
992 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
993 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
994 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
995 + "-png FILE\tCreate PNG image FILE from alignment.\n"
996 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
997 + "-html FILE\tCreate HTML file from alignment.\n"
998 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
999 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1000 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1001 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1002 + "-noquestionnaire\tTurn off questionnaire check.\n"
1003 + "-nonews\tTurn off check for Jalview news.\n"
1004 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1005 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1007 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1008 // after all other properties files have been read\n\t
1009 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1010 // passed in correctly)"
1011 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1012 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1014 // "-vdoc vamsas-document\tImport vamsas document into new
1015 // session or join existing session with same URN\n"
1016 // + "-vses vamsas-session\tJoin session with given URN\n"
1017 + "-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"
1018 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1021 private static void startUsageStats(final Desktop desktop)
1024 * start a User Config prompt asking if we can log usage statistics.
1026 PromptUserConfig prompter = new PromptUserConfig(
1027 Desktop.getDesktopPane(), "USAGESTATS",
1028 "Jalview Usage Statistics",
1029 "Do you want to help make Jalview better by enabling "
1030 + "the collection of usage statistics with Google Analytics ?"
1031 + "\n\n(you can enable or disable usage tracking in the preferences)",
1038 "Initialising googletracker for usage stats.");
1039 Cache.initGoogleTracker();
1040 Cache.log.debug("Tracking enabled.");
1047 Cache.log.debug("Not enabling Google Tracking.");
1050 desktop.addDialogThread(prompter);
1054 * Locate the given string as a file and pass it to the groovy interpreter.
1056 * @param groovyscript
1057 * the script to execute
1058 * @param jalviewContext
1059 * the Jalview Desktop object passed in to the groovy binding as the
1062 private void executeGroovyScript(String groovyscript, AlignFrame af)
1065 * for scripts contained in files
1072 if (groovyscript.trim().equals("STDIN"))
1074 // read from stdin into a tempfile and execute it
1077 tfile = File.createTempFile("jalview", "groovy");
1078 PrintWriter outfile = new PrintWriter(
1079 new OutputStreamWriter(new FileOutputStream(tfile)));
1080 BufferedReader br = new BufferedReader(
1081 new InputStreamReader(System.in));
1083 while ((line = br.readLine()) != null)
1085 outfile.write(line + "\n");
1091 } catch (Exception ex)
1093 System.err.println("Failed to read from STDIN into tempfile "
1094 + ((tfile == null) ? "(tempfile wasn't created)"
1095 : tfile.toString()));
1096 ex.printStackTrace();
1101 sfile = tfile.toURI().toURL();
1102 } catch (Exception x)
1105 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1107 x.printStackTrace();
1115 sfile = new URI(groovyscript).toURL();
1116 } catch (Exception x)
1118 tfile = new File(groovyscript);
1119 if (!tfile.exists())
1121 System.err.println("File '" + groovyscript + "' does not exist.");
1124 if (!tfile.canRead())
1126 System.err.println("File '" + groovyscript + "' cannot be read.");
1129 if (tfile.length() < 1)
1131 System.err.println("File '" + groovyscript + "' is empty.");
1136 sfile = tfile.getAbsoluteFile().toURI().toURL();
1137 } catch (Exception ex)
1139 System.err.println("Failed to create a file URL for "
1140 + tfile.getAbsoluteFile());
1147 Map<String, Object> vbinding = new HashMap<>();
1148 vbinding.put("Jalview", this);
1151 vbinding.put("currentAlFrame", af);
1153 Binding gbinding = new Binding(vbinding);
1154 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1155 gse.run(sfile.toString(), gbinding);
1156 if ("STDIN".equals(groovyscript))
1158 // delete temp file that we made -
1159 // only if it was successfully executed
1162 } catch (Exception e)
1164 System.err.println("Exception Whilst trying to execute file " + sfile
1165 + " as a groovy script.");
1166 e.printStackTrace(System.err);
1171 public AlignFrame[] getAlignFrames()
1173 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1174 : Desktop.getAlignFrames();
1179 * Quit method delegates to Desktop.quit - unless running in headless mode
1180 * when it just ends the JVM
1184 if (desktop != null)
1195 * Get the SwingJS applet ID and combine that with the frameType
1198 * "alignment", "desktop", etc., or null
1201 public static String getAppID(String frameType)
1203 String id = Cache.getProperty("Info.j2sAppletID");
1208 return id + (frameType == null ? "" : "-" + frameType);
1212 * Handle all JalviewLite applet parameters
1217 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1219 JalviewApp app = new JalviewApp()
1222 private boolean alignPDBStructures; // From JalviewLite; not implemented
1225 public String getParameter(String name)
1227 return aparser.getAppletValue(name, null);
1231 public boolean getDefaultParameter(String name, boolean def)
1234 return ((stn = getParameter(name)) == null ? def
1235 : "true".equalsIgnoreCase(stn));
1239 * Get the applet-like document base even though this is an application.
1242 public URL getDocumentBase()
1244 return Platform.getDocumentBase();
1248 * Get the applet-like code base even though this is an application.
1251 public URL getCodeBase()
1253 return Platform.getCodeBase();
1257 public AlignViewportI getViewport()
1259 return af.getViewport();
1267 public boolean parseFeaturesFile(String filename,
1268 DataSourceType protocol)
1270 return af.parseFeaturesFile(filename, protocol);
1278 public boolean loadScoreFile(String sScoreFile) throws IOException
1280 af.loadJalviewDataFile(sScoreFile, null,
1286 * annotations, jpredfile, jnetfile
1290 public void updateForAnnotations()
1292 af.updateForAnnotations();
1296 public void loadTree(NewickFile fin, String treeFile)
1299 // n/a -- already done by standard Jalview command line processing
1303 public void setAlignPdbStructures(boolean defaultParameter)
1305 alignPDBStructures = true;
1309 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1310 String[] chains, DataSourceType protocol)
1312 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1316 public void setFeatureGroupState(String[] groups, boolean state)
1318 af.setFeatureGroupState(groups, state);
1322 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1323 String[][] chains, String[] protocols)
1326 "Jalview applet interface alignedStructureView not implemented");
1330 public void newFeatureSettings()
1333 "Jalview applet interface newFeatureSettings not implemented");
1338 new JalviewAppLoader(true).load(app);