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.io.AppletFormatAdapter;
34 import jalview.io.BioJsHTMLOutput;
35 import jalview.io.DataSourceType;
36 import jalview.io.FileFormat;
37 import jalview.io.FileFormatException;
38 import jalview.io.FileFormatI;
39 import jalview.io.FileLoader;
40 import jalview.io.HtmlSvgOutput;
41 import jalview.io.IdentifyFile;
42 import jalview.io.NewickFile;
43 import jalview.io.gff.SequenceOntologyFactory;
44 import jalview.schemes.ColourSchemeI;
45 import jalview.schemes.ColourSchemeProperty;
46 import jalview.util.MessageManager;
47 import jalview.util.Platform;
48 import jalview.ws.jws2.Jws2Discoverer;
50 import java.io.BufferedReader;
52 import java.io.FileOutputStream;
53 import java.io.IOException;
54 import java.io.InputStreamReader;
55 import java.io.OutputStreamWriter;
56 import java.io.PrintWriter;
57 import java.net.MalformedURLException;
59 import java.net.URISyntaxException;
61 import java.security.AllPermission;
62 import java.security.CodeSource;
63 import java.security.PermissionCollection;
64 import java.security.Permissions;
65 import java.security.Policy;
66 import java.util.HashMap;
68 import java.util.Vector;
69 import java.util.logging.ConsoleHandler;
70 import java.util.logging.Level;
71 import java.util.logging.Logger;
73 import javax.swing.LookAndFeel;
74 import javax.swing.UIManager;
76 import groovy.lang.Binding;
77 import groovy.util.GroovyScriptEngine;
80 * Main class for Jalview Application <br>
82 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
85 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
86 * jalview.bin.Jalview jalview.bin.Jalview
88 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
89 * embellish '*' to e.g. '*.jar')
94 public class Jalview implements ApplicationSingletonI
97 public static Jalview getInstance()
99 return (Jalview) ApplicationSingletonProvider
100 .getInstance(Jalview.class);
109 Platform.getURLCommandArguments();
112 private boolean headless;
114 public static boolean isHeadlessMode()
116 return getInstance().headless;
119 private Desktop desktop;
121 private AlignFrame currentAlignFrame;
123 public boolean isJavaAppletTag;
125 public String appletResourcePath;
127 public static AlignFrame getCurrentAlignFrame()
129 return getInstance().currentAlignFrame;
132 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
134 getInstance().currentAlignFrame = currentAlignFrame;
139 if (!Platform.isJS())
146 // grab all the rights we can for the JVM
147 Policy.setPolicy(new Policy()
150 public PermissionCollection getPermissions(CodeSource codesource)
152 Permissions perms = new Permissions();
153 perms.add(new AllPermission());
158 public void refresh()
166 * keep track of feature fetching tasks.
174 * TODO: generalise to track all jalview events to orchestrate batch
178 private int queued = 0;
180 private int running = 0;
182 public FeatureFetcher()
187 public void addFetcher(final AlignFrame af,
188 final Vector<String> dasSources)
190 final long id = System.currentTimeMillis();
192 final FeatureFetcher us = this;
193 new Thread(new Runnable()
205 af.setProgressBar(MessageManager
206 .getString("status.das_features_being_retrived"), id);
207 af.featureSettings_actionPerformed(null);
208 af.setProgressBar(null, id);
217 public synchronized boolean allFinished()
219 return queued == 0 && running == 0;
225 * main class for Jalview application
228 * open <em>filename</em>
230 public static void main(String[] args)
232 // setLogging(); // BH - for event debugging in JavaScript
233 getInstance().doMain(args);
236 private static void logClass(String name)
238 // BH - for event debugging in JavaScript
239 ConsoleHandler consoleHandler = new ConsoleHandler();
240 consoleHandler.setLevel(Level.ALL);
241 Logger logger = Logger.getLogger(name);
242 logger.setLevel(Level.ALL);
243 logger.addHandler(consoleHandler);
246 @SuppressWarnings("unused")
247 private static void setLogging()
255 System.out.println("not in js");
258 // BH - for event debugging in JavaScript (Java mode only)
259 if (!Platform.isJS())
266 Logger.getLogger("").setLevel(Level.ALL);
267 logClass("java.awt.EventDispatchThread");
268 logClass("java.awt.EventQueue");
269 logClass("java.awt.Component");
270 logClass("java.awt.focus.Component");
271 logClass("java.awt.focus.DefaultKeyboardFocusManager");
279 void doMain(String[] args)
282 if (!Platform.isJS())
284 System.setSecurityManager(null);
288 .println("Java version: " + System.getProperty("java.version"));
289 System.out.println(System.getProperty("os.arch") + " "
290 + System.getProperty("os.name") + " "
291 + System.getProperty("os.version"));
293 ArgsParser aparser = new ArgsParser(args);
295 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
296 Cache.loadProperties(usrPropsFile);
299 isJavaAppletTag = aparser.isApplet();
302 Preferences.setAppletDefaults();
303 Cache.loadProperties(usrPropsFile); // again, because we
304 // might be changing defaults here?
307 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
308 appletResourcePath = aparser.getValue("Info.resourcePath");
317 if (usrPropsFile != null)
320 "CMD [-props " + usrPropsFile + "] executed successfully!");
323 if (aparser.contains("help") || aparser.contains("h"))
328 if (aparser.contains(ArgsParser.NODISPLAY)
329 || aparser.contains(ArgsParser.NOGUI)
330 || aparser.contains(ArgsParser.HEADLESS)
331 || "true".equals(System.getProperty("java.awt.headless")))
338 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
339 if (jabawsUrl != null)
343 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
345 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
346 } catch (MalformedURLException e)
349 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
354 // check for property setting
355 String defs = aparser.getValue(ArgsParser.SETPROP);
358 int p = defs.indexOf('=');
361 System.err.println("Ignoring invalid setprop argument : " + defs);
365 System.out.println("Executing setprop argument: " + defs);
368 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
371 defs = aparser.getValue(ArgsParser.SETPROP);
373 System.setProperty("http.agent",
374 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
378 } catch (NoClassDefFoundError error)
380 error.printStackTrace();
381 System.out.println("\nEssential logging libraries not found."
382 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
390 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
391 } catch (Exception ex)
393 System.err.println("Unexpected Look and Feel Exception");
394 ex.printStackTrace();
396 if (Platform.isAMacAndNotJS())
399 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
401 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
403 System.setProperty("apple.laf.useScreenMenuBar", "true");
404 if (lookAndFeel != null)
408 UIManager.setLookAndFeel(lookAndFeel);
409 } catch (Throwable e)
412 "Failed to set QuaQua look and feel: " + e.toString());
415 if (lookAndFeel == null
416 || !(lookAndFeel.getClass().isAssignableFrom(
417 UIManager.getLookAndFeel().getClass()))
418 || !UIManager.getLookAndFeel().getClass().toString()
419 .toLowerCase().contains("quaqua"))
424 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
425 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
426 } catch (Throwable e)
429 "Failed to reset look and feel: " + e.toString());
435 * configure 'full' SO model if preferences say to,
436 * else use the default (SO Lite)
438 if (Cache.getDefault("USE_FULL_SO", false))
440 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
445 desktop = Desktop.getInstance();
446 desktop.setInBatchMode(true); // indicate we are starting up
447 desktop.setVisible(true);
449 if (!Platform.isJS())
456 desktop.startServiceDiscovery();
457 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
459 startUsageStats(desktop);
463 System.err.println("CMD [-nousagestats] executed successfully!");
466 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
468 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
471 // Start the desktop questionnaire prompter with the specified
473 Cache.log.debug("Starting questionnaire url at " + url);
474 desktop.checkForQuestionnaire(url);
475 System.out.println("CMD questionnaire[-" + url
476 + "] executed successfully!");
480 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
482 // Start the desktop questionnaire prompter with the specified
485 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
487 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
489 "Starting questionnaire with default url: " + defurl);
490 desktop.checkForQuestionnaire(defurl);
497 .println("CMD [-noquestionnaire] executed successfully!");
500 if (!aparser.contains(ArgsParser.NONEWS))
502 desktop.checkForNews();
505 BioJsHTMLOutput.updateBioJS();
510 FileFormatI format = null;
511 DataSourceType protocol = null;
512 FileLoader fileLoader = new FileLoader(!headless);
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 = aparser.getValue(ArgsParser.GROOVY, true);
518 String file = aparser.getValue(ArgsParser.OPEN, true);
520 if (file == null && desktop == null)
522 System.out.println("No files to open!");
525 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
526 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
527 if (vamsasImport != null || vamsasSession != null)
529 if (desktop == null || headless)
532 "Headless vamsas sessions not yet supported. Sorry.");
535 // if we have a file, start a new session and import it.
536 boolean inSession = false;
537 if (vamsasImport != null)
541 DataSourceType viprotocol = AppletFormatAdapter
542 .checkProtocol(vamsasImport);
543 if (viprotocol == DataSourceType.FILE)
545 inSession = desktop.vamsasImport(new File(vamsasImport));
547 else if (viprotocol == DataSourceType.URL)
549 inSession = desktop.vamsasImport(new URL(vamsasImport));
552 } catch (Exception e)
554 System.err.println("Exeption when importing " + vamsasImport
555 + " as a vamsas document.");
560 System.err.println("Failed to import " + vamsasImport
561 + " as a vamsas document.");
565 System.out.println("Imported Successfully into new session "
566 + desktop.getVamsasApplication().getCurrentSession());
569 if (vamsasSession != null)
571 if (vamsasImport != null)
573 // close the newly imported session and import the Jalview specific
574 // remnants into the new session later on.
575 desktop.vamsasStop_actionPerformed(null);
577 // now join the new session
580 if (desktop.joinVamsasSession(vamsasSession))
583 "Successfully joined vamsas session " + vamsasSession);
587 System.err.println("WARNING: Failed to join vamsas session "
590 } catch (Exception e)
593 "ERROR: Failed to join vamsas session " + vamsasSession);
596 if (vamsasImport != null)
598 // the Jalview specific remnants can now be imported into the new
599 // session at the user's leisure.
601 "Skipping Push for import of data into existing vamsas session."); // TODO:
606 // desktop.getVamsasApplication().push_update();
611 // Finally, deal with the remaining input data.
616 desktop.setProgressBar(
618 .getString("status.processing_commandline_args"),
619 progress = System.currentTimeMillis());
621 System.out.println("CMD [-open " + file + "] executed successfully!");
623 if (!Platform.isJS())
625 * ignore in JavaScript -- can't just check file existence - could load
631 if (!file.startsWith("http://") && !file.startsWith("https://"))
632 // BH 2019 added https check for Java
634 if (!(new File(file)).exists())
636 System.out.println("Can't find " + file);
645 protocol = AppletFormatAdapter.checkProtocol(file);
649 format = new IdentifyFile().identify(file, protocol);
650 } catch (FileFormatException e1)
655 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
659 System.out.println("error");
663 setCurrentAlignFrame(af);
664 data = aparser.getValue(ArgsParser.COLOUR, true);
667 data.replaceAll("%20", " ");
669 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
670 af.getViewport(), af.getViewport().getAlignment(), data);
675 "CMD [-color " + data + "] executed successfully!");
680 // Must maintain ability to use the groups flag
681 data = aparser.getValue(ArgsParser.GROUPS, true);
684 af.parseFeaturesFile(data,
685 AppletFormatAdapter.checkProtocol(data));
686 // System.out.println("Added " + data);
688 "CMD groups[-" + data + "] executed successfully!");
690 data = aparser.getValue(ArgsParser.FEATURES, true);
693 af.parseFeaturesFile(data,
694 AppletFormatAdapter.checkProtocol(data));
695 // System.out.println("Added " + data);
697 "CMD [-features " + data + "] executed successfully!");
700 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
703 af.loadJalviewDataFile(data, null, null, null);
704 // System.out.println("Added " + data);
706 "CMD [-annotations " + data + "] executed successfully!");
708 // set or clear the sortbytree flag.
709 if (aparser.contains(ArgsParser.SORTBYTREE))
711 af.getViewport().setSortByTree(true);
712 if (af.getViewport().getSortByTree())
714 System.out.println("CMD [-sortbytree] executed successfully!");
717 if (aparser.contains(ArgsParser.NOANNOTATION)
718 || aparser.contains(ArgsParser.NOANNOTATION2))
720 af.getViewport().setShowAnnotation(false);
721 if (!af.getViewport().isShowAnnotation())
723 System.out.println("CMD no-annotation executed successfully!");
726 if (aparser.contains(ArgsParser.NOSORTBYTREE))
728 af.getViewport().setSortByTree(false);
729 if (!af.getViewport().getSortByTree())
732 .println("CMD [-nosortbytree] executed successfully!");
735 data = aparser.getValue(ArgsParser.TREE, true);
741 "CMD [-tree " + data + "] executed successfully!");
742 NewickFile nf = new NewickFile(data,
743 AppletFormatAdapter.checkProtocol(data));
745 .setCurrentTree(af.showNewickTree(nf, data).getTree());
746 } catch (IOException ex)
748 System.err.println("Couldn't add tree " + data);
749 ex.printStackTrace(System.err);
752 // TODO - load PDB structure(s) to alignment JAL-629
753 // (associate with identical sequence in alignment, or a specified
755 if (groovyscript != null)
757 // Execute the groovy script after we've done all the rendering stuff
758 // and before any images or figures are generated.
759 System.out.println("Executing script " + groovyscript);
760 executeGroovyScript(groovyscript, af);
761 System.out.println("CMD groovy[" + groovyscript
762 + "] executed successfully!");
768 loadAppletParams(aparser, af);
773 String imageName = "unnamed.png";
774 while (aparser.getSize() > 1)
780 String outputFormat = aparser.nextValue();
781 file = aparser.nextValue();
783 if (outputFormat.equalsIgnoreCase("png"))
785 af.createPNG(new File(file));
786 imageName = (new File(file)).getName();
787 System.out.println("Creating PNG image: " + file);
790 else if (outputFormat.equalsIgnoreCase("svg"))
792 File imageFile = new File(file);
793 imageName = imageFile.getName();
794 af.createSVG(imageFile);
795 System.out.println("Creating SVG image: " + file);
798 else if (outputFormat.equalsIgnoreCase("html"))
800 File imageFile = new File(file);
801 imageName = imageFile.getName();
802 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
803 htmlSVG.exportHTML(file);
805 System.out.println("Creating HTML image: " + file);
808 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
812 System.err.println("The output html file must not be null");
817 BioJsHTMLOutput.refreshVersionInfo(
818 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
819 } catch (URISyntaxException e)
823 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
824 bjs.exportHTML(file);
826 "Creating BioJS MSA Viwer HTML file: " + file);
829 else if (outputFormat.equalsIgnoreCase("imgMap"))
831 af.createImageMap(new File(file), imageName);
832 System.out.println("Creating image map: " + file);
835 else if (outputFormat.equalsIgnoreCase("eps"))
837 File outputFile = new File(file);
839 "Creating EPS file: " + outputFile.getAbsolutePath());
840 af.createEPS(outputFile);
844 af.saveAlignment(file, format);
845 if (af.isSaveAlignmentSuccessful())
847 System.out.println("Written alignment in " + format
848 + " format to " + file);
852 System.out.println("Error writing file " + file + " in "
853 + format + " format!!");
858 while (aparser.getSize() > 0)
860 System.out.println("Unknown arg: " + aparser.nextValue());
865 AlignFrame startUpAlframe = null;
866 // We'll only open the default file if the desktop is visible.
868 // ////////////////////
870 if (!Platform.isJS() && !headless && file == null
871 && vamsasImport == null
872 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
879 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
880 jalview.bin.Cache.getDefault("www.jalview.org",
881 "http://www.jalview.org")
882 + "/examples/exampleFile_2_7.jar");
884 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
886 // hardwire upgrade of the startup file
887 file.replace("_2_3.jar", "_2_7.jar");
888 // and remove the stale setting
889 jalview.bin.Cache.removeProperty("STARTUP_FILE");
892 protocol = DataSourceType.FILE;
894 if (file.indexOf("http:") > -1)
896 protocol = DataSourceType.URL;
899 if (file.endsWith(".jar"))
901 format = FileFormat.Jalview;
907 format = new IdentifyFile().identify(file, protocol);
908 } catch (FileFormatException e)
914 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
916 // extract groovy arguments before anything else.
919 // Once all other stuff is done, execute any groovy scripts (in order)
920 if (groovyscript != null)
922 if (Cache.groovyJarsPresent())
924 System.out.println("Executing script " + groovyscript);
925 executeGroovyScript(groovyscript, startUpAlframe);
930 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
934 // and finally, turn off batch mode indicator - if the desktop still exists
939 desktop.setProgressBar(null, progress);
941 desktop.setInBatchMode(false);
945 private static void showUsage()
948 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
949 + "-nodisplay\tRun Jalview without User Interface.\n"
950 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
951 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
952 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
953 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
954 + "-features FILE\tUse the given file to mark features on the alignment.\n"
955 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
956 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
957 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
958 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
959 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
960 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
961 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
962 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
963 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
964 + "-png FILE\tCreate PNG image FILE from alignment.\n"
965 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
966 + "-html FILE\tCreate HTML file from alignment.\n"
967 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
968 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
969 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
970 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
971 + "-noquestionnaire\tTurn off questionnaire check.\n"
972 + "-nonews\tTurn off check for Jalview news.\n"
973 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
974 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
976 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
977 // after all other properties files have been read\n\t
978 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
979 // passed in correctly)"
980 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
981 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
983 // "-vdoc vamsas-document\tImport vamsas document into new
984 // session or join existing session with same URN\n"
985 // + "-vses vamsas-session\tJoin session with given URN\n"
986 + "-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"
987 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
990 private static void startUsageStats(final Desktop desktop)
993 * start a User Config prompt asking if we can log usage statistics.
995 PromptUserConfig prompter = new PromptUserConfig(
996 Desktop.getDesktopPane(), "USAGESTATS",
997 "Jalview Usage Statistics",
998 "Do you want to help make Jalview better by enabling "
999 + "the collection of usage statistics with Google Analytics ?"
1000 + "\n\n(you can enable or disable usage tracking in the preferences)",
1007 "Initialising googletracker for usage stats.");
1008 Cache.initGoogleTracker();
1009 Cache.log.debug("Tracking enabled.");
1016 Cache.log.debug("Not enabling Google Tracking.");
1019 desktop.addDialogThread(prompter);
1023 * Locate the given string as a file and pass it to the groovy interpreter.
1025 * @param groovyscript
1026 * the script to execute
1027 * @param jalviewContext
1028 * the Jalview Desktop object passed in to the groovy binding as the
1031 private void executeGroovyScript(String groovyscript, AlignFrame af)
1034 * for scripts contained in files
1041 if (groovyscript.trim().equals("STDIN"))
1043 // read from stdin into a tempfile and execute it
1046 tfile = File.createTempFile("jalview", "groovy");
1047 PrintWriter outfile = new PrintWriter(
1048 new OutputStreamWriter(new FileOutputStream(tfile)));
1049 BufferedReader br = new BufferedReader(
1050 new InputStreamReader(System.in));
1052 while ((line = br.readLine()) != null)
1054 outfile.write(line + "\n");
1060 } catch (Exception ex)
1062 System.err.println("Failed to read from STDIN into tempfile "
1063 + ((tfile == null) ? "(tempfile wasn't created)"
1064 : tfile.toString()));
1065 ex.printStackTrace();
1070 sfile = tfile.toURI().toURL();
1071 } catch (Exception x)
1074 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1076 x.printStackTrace();
1084 sfile = new URI(groovyscript).toURL();
1085 } catch (Exception x)
1087 tfile = new File(groovyscript);
1088 if (!tfile.exists())
1090 System.err.println("File '" + groovyscript + "' does not exist.");
1093 if (!tfile.canRead())
1095 System.err.println("File '" + groovyscript + "' cannot be read.");
1098 if (tfile.length() < 1)
1100 System.err.println("File '" + groovyscript + "' is empty.");
1105 sfile = tfile.getAbsoluteFile().toURI().toURL();
1106 } catch (Exception ex)
1108 System.err.println("Failed to create a file URL for "
1109 + tfile.getAbsoluteFile());
1116 Map<String, Object> vbinding = new HashMap<>();
1117 vbinding.put("Jalview", this);
1120 vbinding.put("currentAlFrame", af);
1122 Binding gbinding = new Binding(vbinding);
1123 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1124 gse.run(sfile.toString(), gbinding);
1125 if ("STDIN".equals(groovyscript))
1127 // delete temp file that we made -
1128 // only if it was successfully executed
1131 } catch (Exception e)
1133 System.err.println("Exception Whilst trying to execute file " + sfile
1134 + " as a groovy script.");
1135 e.printStackTrace(System.err);
1140 public AlignFrame[] getAlignFrames()
1142 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1143 : Desktop.getAlignFrames();
1148 * Quit method delegates to Desktop.quit - unless running in headless mode
1149 * when it just ends the JVM
1153 if (desktop != null)
1164 * Get the SwingJS applet ID and combine that with the frameType
1167 * "alignment", "desktop", etc., or null
1170 public static String getAppID(String frameType)
1172 String id = Cache.getProperty("Info.j2sAppletID");
1177 return id + (frameType == null ? "" : "-" + frameType);
1180 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1183 JalviewApp app = new JalviewApp()
1188 public String getParameter(String name)
1190 return aparser.getAppletValue(name, null);
1194 public boolean getDefaultParameter(String name, boolean def)
1197 return ((stn = getParameter(name)) == null ? def
1198 : "true".equalsIgnoreCase(stn));
1202 public URL getDocumentBase()
1204 return Platform.getDocumentBase();
1208 public URL getCodeBase()
1210 return Platform.getCodeBase();
1214 public AlignViewportI getViewport()
1216 return Jalview.getCurrentAlignFrame().getViewport();
1220 public boolean loadScoreFile(String sScoreFile) throws IOException
1222 Jalview.getCurrentAlignFrame().loadJalviewDataFile(sScoreFile, null,
1228 public boolean parseFeaturesFile(String filename,
1229 DataSourceType protocol)
1231 return af.parseFeaturesFile(filename, protocol);
1235 public void loadTree(NewickFile fin, String treeFile)
1238 // n/a -- already done
1242 public void setAlignPdbStructures(boolean defaultParameter)
1244 // TODO Auto-generated method stub
1249 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1250 String[] chains, DataSourceType protocol)
1252 // TODO Auto-generated method stub
1257 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1258 String[][] chains, String[] protocols)
1260 // TODO Auto-generated method stub
1265 public void updateForLoader()
1267 // TODO Auto-generated method stub
1272 public void setFeatureGroupState(String[] groups, boolean state)
1274 // TODO Auto-generated method stub
1279 public void newFeatureSettings()
1281 // TODO Auto-generated method stub
1287 new JalviewAppLoader(true).load(app);