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.AlignCalcWorkerI;
24 import jalview.api.AlignViewportI;
25 import jalview.api.JalviewApp;
26 import jalview.api.StructureSelectionManagerProvider;
27 import jalview.datamodel.ColumnSelection;
28 import jalview.datamodel.HiddenColumns;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.SequenceGroup;
31 import jalview.datamodel.SequenceI;
32 import jalview.ext.so.SequenceOntology;
33 import jalview.gui.AlignFrame;
34 import jalview.gui.AlignmentPanel;
35 import jalview.gui.CalculationChooser;
36 import jalview.gui.Desktop;
37 import jalview.gui.PromptUserConfig;
38 import jalview.gui.StructureViewer;
39 import jalview.io.AppletFormatAdapter;
40 import jalview.io.BioJsHTMLOutput;
41 import jalview.io.DataSourceType;
42 import jalview.io.FileFormat;
43 import jalview.io.FileFormatException;
44 import jalview.io.FileFormatI;
45 import jalview.io.FileLoader;
46 import jalview.io.HtmlSvgOutput;
47 import jalview.io.IdentifyFile;
48 import jalview.io.NewickFile;
49 import jalview.io.gff.SequenceOntologyFactory;
50 import jalview.javascript.JSFunctionExec;
51 import jalview.javascript.MouseOverStructureListener;
52 import jalview.renderer.seqfeatures.FeatureRenderer;
53 import jalview.schemes.ColourSchemeI;
54 import jalview.schemes.ColourSchemeProperty;
55 import jalview.structure.SelectionSource;
56 import jalview.structure.VamsasSource;
57 import jalview.util.MessageManager;
58 import jalview.util.Platform;
59 import jalview.ws.jws2.Jws2Discoverer;
60 import netscape.javascript.JSObject;
62 import java.applet.AppletContext;
63 import java.io.BufferedReader;
65 import java.io.FileOutputStream;
66 import java.io.IOException;
67 import java.io.InputStreamReader;
68 import java.io.OutputStreamWriter;
69 import java.io.PrintWriter;
70 import java.net.MalformedURLException;
72 import java.net.URISyntaxException;
74 import java.security.AllPermission;
75 import java.security.CodeSource;
76 import java.security.PermissionCollection;
77 import java.security.Permissions;
78 import java.security.Policy;
79 import java.util.HashMap;
80 import java.util.Hashtable;
82 import java.util.Vector;
83 import java.util.logging.ConsoleHandler;
84 import java.util.logging.Level;
85 import java.util.logging.Logger;
87 import javax.swing.LookAndFeel;
88 import javax.swing.UIManager;
90 import com.threerings.getdown.util.LaunchUtil;
92 import groovy.lang.Binding;
93 import groovy.util.GroovyScriptEngine;
96 * Main class for Jalview Application <br>
98 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
101 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
102 * jalview.bin.Jalview jalview.bin.Jalview
104 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
105 * embellish '*' to e.g. '*.jar')
108 * @version $Revision$
110 public class Jalview implements JalviewJSApi
114 Platform.getURLCommandArguments();
117 // singleton instance of this class
119 private static Jalview instance;
121 private Desktop desktop;
123 public static AlignFrame currentAlignFrame;
125 public boolean isJavaAppletTag;
127 public String appletResourcePath;
129 JalviewAppLoader appLoader;
131 protected JSFunctionExec jsFunctionExec;
133 private boolean noCalculation, noMenuBar, noStatus;
135 private boolean noAnnotation;
137 public boolean getStartCalculations()
139 return !noCalculation;
142 public boolean getAllowMenuBar()
147 public boolean getShowStatus()
152 public boolean getShowAnnotation()
154 return !noAnnotation;
160 if (!Platform.isJS())
167 // grab all the rights we can for the JVM
168 Policy.setPolicy(new Policy()
171 public PermissionCollection getPermissions(CodeSource codesource)
173 Permissions perms = new Permissions();
174 perms.add(new AllPermission());
179 public void refresh()
187 * keep track of feature fetching tasks.
195 * TODO: generalise to track all jalview events to orchestrate batch processing
199 private int queued = 0;
201 private int running = 0;
203 public FeatureFetcher()
208 public void addFetcher(final AlignFrame af,
209 final Vector<String> dasSources)
211 final long id = System.currentTimeMillis();
213 final FeatureFetcher us = this;
214 new Thread(new Runnable()
226 af.setProgressBar(MessageManager
227 .getString("status.das_features_being_retrived"), id);
228 af.featureSettings_actionPerformed(null);
229 af.setProgressBar(null, id);
238 public synchronized boolean allFinished()
240 return queued == 0 && running == 0;
245 public static Jalview getInstance()
251 * main class for Jalview application
254 * open <em>filename</em>
256 public static void main(String[] args)
260 Platform.startJavaLogging();
263 instance = new Jalview();
264 instance.doMain(args);
270 void doMain(String[] args)
273 if (!Platform.isJS())
275 System.setSecurityManager(null);
279 .println("Java version: "
280 + System.getProperty("java.version"));
281 System.out.println("Java Home: " + System.getProperty("java.home"));
282 System.out.println(System.getProperty("os.arch") + " "
283 + System.getProperty("os.name") + " "
284 + System.getProperty("os.version"));
285 String val = System.getProperty("sys.install4jVersion");
287 System.out.println("Install4j version: " + val);
289 val = System.getProperty("installer_template_version");
291 System.out.println("Install4j template version: " + val);
293 val = System.getProperty("launcher_version");
295 System.out.println("Launcher version: " + val);
298 // report Jalview version
299 Cache.loadBuildProperties(true);
301 ArgsParser aparser = new ArgsParser(args);
302 boolean headless = false;
304 String usrPropsFile = aparser.getValue("props");
305 Cache.loadProperties(usrPropsFile); // must do this before
306 if (usrPropsFile != null)
309 "CMD [-props " + usrPropsFile + "] executed successfully!");
312 if (!Platform.isJS())
319 if (aparser.contains("help") || aparser.contains("h"))
324 if (aparser.contains("nodisplay") || aparser.contains("nogui")
325 || aparser.contains("headless"))
327 System.setProperty("java.awt.headless", "true");
332 final String jabawsUrl = aparser.getValue("jabaws");
333 if (jabawsUrl != null)
337 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
339 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
340 } catch (MalformedURLException e)
343 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
348 String defs = aparser.getValue("setprop");
351 int p = defs.indexOf('=');
354 System.err.println("Ignoring invalid setprop argument : " + defs);
358 System.out.println("Executing setprop argument: " + defs);
361 Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
364 defs = aparser.getValue("setprop");
366 if (System.getProperty("java.awt.headless") != null
367 && System.getProperty("java.awt.headless").equals("true"))
371 System.setProperty("http.agent",
372 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
376 } catch (NoClassDefFoundError error)
378 error.printStackTrace();
379 System.out.println("\nEssential logging libraries not found."
380 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
388 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
389 } catch (Exception ex)
391 System.err.println("Unexpected Look and Feel Exception");
392 ex.printStackTrace();
394 if (Platform.isAMacAndNotJS())
397 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
399 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
401 System.setProperty("apple.laf.useScreenMenuBar", "true");
402 if (lookAndFeel != null)
406 UIManager.setLookAndFeel(lookAndFeel);
407 } catch (Throwable e)
410 "Failed to set QuaQua look and feel: " + e.toString());
413 if (lookAndFeel == null
414 || !(lookAndFeel.getClass().isAssignableFrom(
415 UIManager.getLookAndFeel().getClass()))
416 || !UIManager.getLookAndFeel().getClass().toString()
417 .toLowerCase().contains("quaqua"))
422 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
423 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
424 } catch (Throwable e)
427 "Failed to reset look and feel: " + e.toString());
433 * configure 'full' SO model if preferences say to, else use the default (full SO)
434 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
436 boolean soDefault = !Platform.isJS();
437 if (Cache.getDefault("USE_FULL_SO", soDefault))
439 SequenceOntologyFactory.setInstance(new SequenceOntology());
444 desktop = new Desktop();
445 desktop.setInBatchMode(true); // indicate we are starting up
449 JalviewTaskbar.setTaskbar(this);
450 } catch (Throwable t)
452 System.out.println("Error setting Taskbar: " + t.getMessage());
455 desktop.setVisible(true);
457 if (!Platform.isJS())
464 desktop.startServiceDiscovery();
465 if (!aparser.contains("nousagestats"))
467 startUsageStats(desktop);
471 System.err.println("CMD [-nousagestats] executed successfully!");
474 if (!aparser.contains("noquestionnaire"))
476 String url = aparser.getValue("questionnaire");
479 // Start the desktop questionnaire prompter with the specified
481 Cache.log.debug("Starting questionnaire url at " + url);
482 desktop.checkForQuestionnaire(url);
483 System.out.println("CMD questionnaire[-" + url
484 + "] executed successfully!");
488 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
490 // Start the desktop questionnaire prompter with the specified
493 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
495 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
497 "Starting questionnaire with default url: " + defurl);
498 desktop.checkForQuestionnaire(defurl);
505 .println("CMD [-noquestionnaire] executed successfully!");
508 if (!aparser.contains("nonews"))
510 desktop.checkForNews();
513 BioJsHTMLOutput.updateBioJS();
517 // Move any new getdown-launcher-new.jar into place over old
518 // getdown-launcher.jar
519 String appdirString = System.getProperty("getdownappdir");
520 if (appdirString != null && appdirString.length() > 0)
522 final File appdir = new File(appdirString);
528 LaunchUtil.upgradeGetdown(
529 new File(appdir, "getdown-launcher-old.jar"),
530 new File(appdir, "getdown-launcher.jar"),
531 new File(appdir, "getdown-launcher-new.jar"));
536 String file = null, data = null;
537 FileFormatI format = null;
538 DataSourceType protocol = null;
539 FileLoader fileLoader = new FileLoader(!headless);
541 String groovyscript = null; // script to execute after all loading is
542 // completed one way or another
543 // extract groovy argument and execute if necessary
544 groovyscript = aparser.getValue("groovy", true);
545 file = aparser.getValue("open", true);
547 if (file == null && desktop == null)
549 System.out.println("No files to open!");
553 // Finally, deal with the remaining input data.
558 desktop.setProgressBar(
560 .getString("status.processing_commandline_args"),
561 progress = System.currentTimeMillis());
563 System.out.println("CMD [-open " + file + "] executed successfully!");
565 if (!Platform.isJS())
567 * ignore in JavaScript -- can't just file existence - could load it?
572 if (!file.startsWith("http://") && !file.startsWith("https://"))
573 // BH 2019 added https check for Java
575 if (!(new File(file)).exists())
577 System.out.println("Can't find " + file);
586 protocol = AppletFormatAdapter.checkProtocol(file);
590 format = new IdentifyFile().identify(file, protocol);
591 } catch (FileFormatException e1)
596 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
600 System.out.println("error");
604 setCurrentAlignFrame(af);
605 data = aparser.getValue("colour", true);
608 data.replaceAll("%20", " ");
610 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
611 af.getViewport(), af.getViewport().getAlignment(), data);
616 "CMD [-color " + data + "] executed successfully!");
621 // Must maintain ability to use the groups flag
622 data = aparser.getValue("groups", true);
625 af.parseFeaturesFile(data,
626 AppletFormatAdapter.checkProtocol(data));
627 // System.out.println("Added " + data);
629 "CMD groups[-" + data + "] executed successfully!");
631 data = aparser.getValue("features", true);
634 af.parseFeaturesFile(data,
635 AppletFormatAdapter.checkProtocol(data));
636 // System.out.println("Added " + data);
638 "CMD [-features " + data + "] executed successfully!");
641 data = aparser.getValue("annotations", true);
644 af.loadJalviewDataFile(data, null, null, null);
645 // System.out.println("Added " + data);
647 "CMD [-annotations " + data + "] executed successfully!");
649 // set or clear the sortbytree flag.
650 if (aparser.contains("sortbytree"))
652 af.getViewport().setSortByTree(true);
653 if (af.getViewport().getSortByTree())
655 System.out.println("CMD [-sortbytree] executed successfully!");
658 if (aparser.contains("no-annotation"))
660 af.getViewport().setShowAnnotation(false);
661 if (!af.getViewport().isShowAnnotation())
663 System.out.println("CMD no-annotation executed successfully!");
666 if (aparser.contains("nosortbytree"))
668 af.getViewport().setSortByTree(false);
669 if (!af.getViewport().getSortByTree())
672 .println("CMD [-nosortbytree] executed successfully!");
675 data = aparser.getValue("tree", true);
681 "CMD [-tree " + data + "] executed successfully!");
682 NewickFile nf = new NewickFile(data,
683 AppletFormatAdapter.checkProtocol(data));
685 .setCurrentTree(af.showNewickTree(nf, data).getTree());
686 } catch (IOException ex)
688 System.err.println("Couldn't add tree " + data);
689 ex.printStackTrace(System.err);
692 // TODO - load PDB structure(s) to alignment JAL-629
693 // (associate with identical sequence in alignment, or a specified
695 if (groovyscript != null)
697 // Execute the groovy script after we've done all the rendering stuff
698 // and before any images or figures are generated.
699 System.out.println("Executing script " + groovyscript);
700 executeGroovyScript(groovyscript, af);
701 System.out.println("CMD groovy[" + groovyscript
702 + "] executed successfully!");
705 String imageName = "unnamed.png";
706 while (aparser.getSize() > 1)
708 String outputFormat = aparser.nextValue();
709 file = aparser.nextValue();
711 if (outputFormat.equalsIgnoreCase("png"))
713 af.createPNG(new File(file));
714 imageName = (new File(file)).getName();
715 System.out.println("Creating PNG image: " + file);
718 else if (outputFormat.equalsIgnoreCase("svg"))
720 File imageFile = new File(file);
721 imageName = imageFile.getName();
722 af.createSVG(imageFile);
723 System.out.println("Creating SVG image: " + file);
726 else if (outputFormat.equalsIgnoreCase("html"))
728 File imageFile = new File(file);
729 imageName = imageFile.getName();
730 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
731 htmlSVG.exportHTML(file);
733 System.out.println("Creating HTML image: " + file);
736 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
740 System.err.println("The output html file must not be null");
745 BioJsHTMLOutput.refreshVersionInfo(
746 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
747 } catch (URISyntaxException e)
751 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
752 bjs.exportHTML(file);
754 .println("Creating BioJS MSA Viwer HTML file: " + file);
757 else if (outputFormat.equalsIgnoreCase("imgMap"))
759 af.createImageMap(new File(file), imageName);
760 System.out.println("Creating image map: " + file);
763 else if (outputFormat.equalsIgnoreCase("eps"))
765 File outputFile = new File(file);
767 "Creating EPS file: " + outputFile.getAbsolutePath());
768 af.createEPS(outputFile);
772 af.saveAlignment(file, format);
773 if (af.isSaveAlignmentSuccessful())
775 System.out.println("Written alignment in " + format
776 + " format to " + file);
780 System.out.println("Error writing file " + file + " in "
781 + format + " format!!");
786 while (aparser.getSize() > 0)
788 System.out.println("Unknown arg: " + aparser.nextValue());
792 AlignFrame startUpAlframe = null;
793 // We'll only open the default file if the desktop is visible.
795 // ////////////////////
797 if (!Platform.isJS() && !headless && file == null
798 && Cache.getDefault("SHOW_STARTUP_FILE", true))
805 file = Cache.getDefault("STARTUP_FILE",
806 Cache.getDefault("www.jalview.org",
807 "http://www.jalview.org")
808 + "/examples/exampleFile_2_7.jar");
810 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
812 // hardwire upgrade of the startup file
813 file.replace("_2_3.jar", "_2_7.jar");
814 // and remove the stale setting
815 Cache.removeProperty("STARTUP_FILE");
818 protocol = DataSourceType.FILE;
820 if (file.indexOf("http:") > -1)
822 protocol = DataSourceType.URL;
825 if (file.endsWith(".jar"))
827 format = FileFormat.Jalview;
833 format = new IdentifyFile().identify(file, protocol);
834 } catch (FileFormatException e)
840 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
842 // extract groovy arguments before anything else.
845 // Once all other stuff is done, execute any groovy scripts (in order)
846 if (groovyscript != null)
848 if (Cache.groovyJarsPresent())
850 System.out.println("Executing script " + groovyscript);
851 executeGroovyScript(groovyscript, startUpAlframe);
856 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
860 // and finally, turn off batch mode indicator - if the desktop still exists
865 desktop.setProgressBar(null, progress);
867 desktop.setInBatchMode(false);
871 private static void showUsage()
874 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
875 + "-nodisplay\tRun Jalview without User Interface.\n"
876 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
877 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
878 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
879 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
880 + "-features FILE\tUse the given file to mark features on the alignment.\n"
881 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
882 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
883 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
884 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
885 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
886 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
887 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
888 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
889 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
890 + "-png FILE\tCreate PNG image FILE from alignment.\n"
891 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
892 + "-html FILE\tCreate HTML file from alignment.\n"
893 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
894 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
895 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
896 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
897 + "-noquestionnaire\tTurn off questionnaire check.\n"
898 + "-nonews\tTurn off check for Jalview news.\n"
899 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
900 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
902 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
903 // after all other properties files have been read\n\t
904 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
905 // passed in correctly)"
906 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
907 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
908 + "-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"
909 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
912 private static void startUsageStats(final Desktop desktop)
915 * start a User Config prompt asking if we can log usage statistics.
917 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
918 "USAGESTATS", "Jalview Usage Statistics",
919 "Do you want to help make Jalview better by enabling "
920 + "the collection of usage statistics with Google Analytics ?"
921 + "\n\n(you can enable or disable usage tracking in the preferences)",
928 "Initialising googletracker for usage stats.");
929 Cache.initGoogleTracker();
930 Cache.log.debug("Tracking enabled.");
937 Cache.log.debug("Not enabling Google Tracking.");
940 desktop.addDialogThread(prompter);
944 * Locate the given string as a file and pass it to the groovy interpreter.
946 * @param groovyscript
947 * the script to execute
948 * @param jalviewContext
949 * the Jalview Desktop object passed in to the groovy
950 * binding as the 'Jalview' object.
952 private void executeGroovyScript(String groovyscript, AlignFrame af)
955 * for scripts contained in files
962 if (groovyscript.trim().equals("STDIN"))
964 // read from stdin into a tempfile and execute it
967 tfile = File.createTempFile("jalview", "groovy");
968 PrintWriter outfile = new PrintWriter(
969 new OutputStreamWriter(new FileOutputStream(tfile)));
970 BufferedReader br = new BufferedReader(
971 new InputStreamReader(System.in));
973 while ((line = br.readLine()) != null)
975 outfile.write(line + "\n");
981 } catch (Exception ex)
983 System.err.println("Failed to read from STDIN into tempfile "
984 + ((tfile == null) ? "(tempfile wasn't created)"
985 : tfile.toString()));
986 ex.printStackTrace();
991 sfile = tfile.toURI().toURL();
992 } catch (Exception x)
995 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1005 sfile = new URI(groovyscript).toURL();
1006 } catch (Exception x)
1008 tfile = new File(groovyscript);
1009 if (!tfile.exists())
1011 System.err.println("File '" + groovyscript + "' does not exist.");
1014 if (!tfile.canRead())
1016 System.err.println("File '" + groovyscript + "' cannot be read.");
1019 if (tfile.length() < 1)
1021 System.err.println("File '" + groovyscript + "' is empty.");
1026 sfile = tfile.getAbsoluteFile().toURI().toURL();
1027 } catch (Exception ex)
1029 System.err.println("Failed to create a file URL for "
1030 + tfile.getAbsoluteFile());
1037 Map<String, java.lang.Object> vbinding = new HashMap<>();
1038 vbinding.put("Jalview", this);
1041 vbinding.put("currentAlFrame", af);
1043 Binding gbinding = new Binding(vbinding);
1044 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1045 gse.run(sfile.toString(), gbinding);
1046 if ("STDIN".equals(groovyscript))
1048 // delete temp file that we made -
1049 // only if it was successfully executed
1052 } catch (Exception e)
1054 System.err.println("Exception Whilst trying to execute file " + sfile
1055 + " as a groovy script.");
1056 e.printStackTrace(System.err);
1061 public static boolean isHeadlessMode()
1063 String isheadless = System.getProperty("java.awt.headless");
1064 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1071 public AlignFrame[] getAlignFrames()
1073 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1074 : Desktop.getAlignFrames();
1079 * Quit method delegates to Desktop.quit - unless running in headless mode when
1080 * it just ends the JVM
1084 if (desktop != null)
1094 public static AlignFrame getCurrentAlignFrame()
1096 return Jalview.currentAlignFrame;
1099 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1101 Jalview.currentAlignFrame = currentAlignFrame;
1105 * Get the SwingJS applet ID and combine that with the frameType
1108 * "alignment", "desktop", etc., or null
1111 public static String getAppID(String frameType)
1113 String id = Cache.getProperty("Info.j2sAppletID");
1118 return id + (frameType == null ? "" : "-" + frameType);
1122 * Handle all JalviewLite applet parameters
1127 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1129 JalviewApp app = new JalviewApp()
1134 // These are methods that are in JalviewLite that various classes call
1135 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1137 // them to JalviewLite directly. Some may not be necessary, but they have
1139 // be at least mentioned here, or the classes calling them should
1141 // JalviewLite itself.
1143 private boolean alignPDBStructures; // From JalviewLite; not implemented
1145 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1147 private Hashtable<String, int[]> jshashes;
1150 public String getParameter(String name)
1152 return aparser.getAppletValue(name, null);
1156 public boolean getDefaultParameter(String name, boolean def)
1159 return ((stn = getParameter(name)) == null ? def
1160 : "true".equalsIgnoreCase(stn));
1164 * Get the applet-like document base even though this is an application.
1167 public URL getDocumentBase()
1169 return Platform.getDocumentBase();
1173 * Get the applet-like code base even though this is an application.
1176 public URL getCodeBase()
1178 return Platform.getCodeBase();
1182 public AlignViewportI getViewport()
1184 return af.getViewport();
1192 public boolean parseFeaturesFile(String filename,
1193 DataSourceType protocol)
1195 return af.parseFeaturesFile(filename, protocol);
1203 public boolean loadScoreFile(String sScoreFile) throws IOException
1205 af.loadJalviewDataFile(sScoreFile, null, null, null);
1210 * annotations, jpredfile, jnetfile
1214 public void updateForAnnotations()
1216 af.updateForAnnotations();
1220 public void loadTree(NewickFile fin, String treeFile)
1223 // n/a -- already done by standard Jalview command line processing
1227 public void setAlignPdbStructures(boolean defaultParameter)
1229 alignPDBStructures = true;
1233 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1234 String[] chains, DataSourceType protocol)
1236 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1240 public void setFeatureGroupState(String[] groups, boolean state)
1242 af.setFeatureGroupState(groups, state);
1246 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1247 String[][] chains, String[] protocols)
1250 "Jalview applet interface alignedStructureView not implemented");
1254 public void newFeatureSettings()
1257 "Jalview applet interface newFeatureSettings not implemented");
1260 private Vector<Runnable> jsExecQueue;
1263 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1265 jsFunctionExec = exec;
1266 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1271 public AppletContext getAppletContext()
1273 // TODO Auto-generated method stub
1278 public boolean isJsfallbackEnabled()
1280 // TODO Auto-generated method stub
1285 public JSObject getJSObject()
1287 // TODO Auto-generated method stub
1292 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1294 // TODO Q: what exactly is this? BH
1299 public void updateColoursFromMouseOver(Object source,
1300 MouseOverStructureListener mouseOverStructureListener)
1302 // TODO Auto-generated method stub
1307 public Object[] getSelectionForListener(SequenceGroup seqsel,
1308 ColumnSelection colsel, HiddenColumns hidden,
1309 SelectionSource source, Object alignFrame)
1311 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1312 seqsel, colsel, hidden, source, alignFrame);
1316 public String arrayToSeparatorList(String[] array)
1318 return appLoader.arrayToSeparatorList(array);
1322 public Hashtable<String, int[]> getJSHashes()
1324 return (jshashes == null ? (jshashes = new Hashtable<>())
1329 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1331 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1336 public Object getFrameForSource(VamsasSource source)
1341 if (source instanceof jalview.gui.AlignViewport
1342 && source == (af = getCurrentAlignFrame()).getViewport())
1344 // should be valid if it just generated an event!
1347 // TODO: ensure that if '_af' is specified along with a handler
1348 // function, then only events from that alignFrame are sent to that
1355 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1357 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1362 appLoader = new JalviewAppLoader(true);
1363 appLoader.load(app);
1368 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1371 public String getSelectedSequences()
1373 return getSelectedSequencesFrom(getCurrentAlignFrame());
1378 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1381 public String getSelectedSequences(String sep)
1383 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1388 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1392 public String getSelectedSequencesFrom(AlignFrame alf)
1396 alf = getCurrentAlignFrame();
1398 return getSelectedSequencesFrom(alf, null);
1403 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1404 * .AlignFrame, java.lang.String)
1407 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
1411 alf = getCurrentAlignFrame();
1413 return appLoader.getSelectedSequencesFrom(alf, sep);
1418 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1419 * .AlignFrame, java.lang.String)
1422 public void highlight(String sequenceId, String position,
1423 String alignedPosition)
1425 highlightIn(null, sequenceId, position,
1430 public void highlightIn(AlignFrame alf, String sequenceId,
1431 String position, String alignedPosition)
1435 alf = getCurrentAlignFrame();
1437 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1441 public void select(String sequenceIds, String columns)
1443 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1447 public void select(String sequenceIds, String columns, String sep)
1449 selectIn(null, sequenceIds, columns, sep);
1453 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
1455 selectIn(alf, sequenceIds, columns, null);
1459 public void selectIn(AlignFrame alf, String sequenceIds, String columns,
1464 alf = getCurrentAlignFrame();
1466 appLoader.selectIn(alf, sequenceIds, columns, sep);
1470 public String getSelectedSequencesAsAlignment(String format,
1473 return getSelectedSequencesAsAlignmentFrom(null,
1478 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
1479 String format, String sep)
1483 alf = getCurrentAlignFrame();
1485 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1489 public String getAlignmentOrder()
1491 return getAlignmentFrom(getCurrentAlignFrame(), null);
1495 public String getAlignmentOrderFrom(AlignFrame alf)
1497 return getAlignmentFrom(alf, null);
1501 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
1505 alf = getCurrentAlignFrame();
1507 return appLoader.getAlignmentOrderFrom(alf, sep);
1511 public String orderBy(String order, String undoName)
1513 return orderBy(order, undoName, null);
1517 public String orderBy(String order, String undoName, String sep)
1519 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1523 public String orderAlignmentBy(AlignFrame alf, String order,
1524 String undoName, String sep)
1528 alf = getCurrentAlignFrame();
1530 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1534 public String getAlignment(String format)
1536 return getAlignmentFrom(null, format, null);
1540 public String getAlignmentFrom(AlignFrame alf, String format)
1542 return getAlignmentFrom(alf, format, null);
1546 public String getAlignment(String format, String suffix)
1548 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1552 public String getAlignmentFrom(AlignFrame alf, String format,
1555 return appLoader.getAlignmentFrom(alf, format, suffix);
1559 public void loadAnnotation(String annotation)
1561 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1565 public void loadAnnotationFrom(AlignFrame alf, String annotation)
1569 alf = getCurrentAlignFrame();
1571 appLoader.loadAnnotationFrom(alf, annotation);
1575 public void loadFeatures(String features, boolean autoenabledisplay)
1577 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1581 public boolean loadFeaturesFrom(AlignFrame alf, String features,
1582 boolean autoenabledisplay)
1586 alf = getCurrentAlignFrame();
1588 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1592 public String getFeatures(String format)
1594 return getFeaturesFrom(null, format);
1598 public String getFeaturesFrom(AlignFrame alf, String format)
1602 alf = getCurrentAlignFrame();
1604 return appLoader.getFeaturesFrom(alf, format);
1608 public String getAnnotation()
1610 return getAnnotationFrom(null);
1614 public String getAnnotationFrom(AlignFrame alf)
1618 alf = getCurrentAlignFrame();
1620 return appLoader.getAnnotationFrom(alf);
1624 // public AlignFrame newView()
1626 // return newViewFrom(null, null);
1630 // public AlignFrame newView(String name)
1632 // return newViewFrom(null, name);
1636 // public AlignFrame newViewFrom(AlignFrame alf)
1638 // return newViewFrom(alf, null);
1642 // public AlignFrame newViewFrom(AlignFrame alf, String name)
1646 // alf = getCurrentAlignFrame();
1648 // return appLoader.newViewFrom(alf, name);
1652 public AlignFrame loadAlignment(String text, String title)
1654 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1655 AlignFrame.DEFAULT_HEIGHT, title);
1659 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
1660 String pdbEntryString, String pdbFile)
1662 if (alFrame == null)
1664 alFrame = getCurrentAlignFrame();
1666 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1671 public void scrollViewToIn(AlignFrame alf, String topRow,
1672 String leftHandColumn)
1676 alf = getCurrentAlignFrame();
1678 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1682 public void scrollViewToRowIn(AlignFrame alf, String topRow)
1686 alf = getCurrentAlignFrame();
1688 appLoader.scrollViewToRowIn(alf, topRow);
1692 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
1696 alf = getCurrentAlignFrame();
1698 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1702 public String getFeatureGroups()
1704 return getFeatureGroupsOn(null);
1708 public String getFeatureGroupsOn(AlignFrame alf)
1712 alf = getCurrentAlignFrame();
1714 return appLoader.getFeatureGroupsOn(alf);
1718 public String getFeatureGroupsOfState(boolean visible)
1720 return getFeatureGroupsOfStateOn(null, visible);
1724 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
1728 alf = getCurrentAlignFrame();
1730 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
1734 public void setFeatureGroupState(String groups, boolean state)
1735 { // JalviewLite API
1736 setFeatureGroupStateOn(null, groups, state);
1740 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
1745 alf = getCurrentAlignFrame();
1747 appLoader.setFeatureGroupStateOn(alf, groups, state);
1751 public String getSeparator()
1753 return appLoader.getSeparator();
1757 public void setSeparator(String separator)
1759 appLoader.setSeparator(separator);
1763 public String getJsMessage(String messageclass, String viewId)
1765 // see http://www.jalview.org/examples/jalviewLiteJs.html
1770 * Open a new Tree panel on the desktop statically. Params are standard (not
1771 * set by Groovy). No dialog is opened.
1776 * @return null, or the string "label.you_need_at_least_n_sequences" if number
1777 * of sequences selected is inappropriate
1780 public Object openTreePanel(AlignFrame af, String treeType,
1785 af = getCurrentAlignFrame();
1787 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
1791 * public static method for JalviewJS API to open a PCAPanel without
1792 * necessarily using a dialog.
1796 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
1797 * if number of sequences selected is inappropriate
1800 public Object openPcaPanel(AlignFrame af, String modelName)
1804 af = getCurrentAlignFrame();
1806 return CalculationChooser.openPcaPanel(af, modelName, null);
1810 public String getSelectedSequencesAsAlignment(String format,
1813 return getSelectedSequencesAsAlignmentFrom(null,
1818 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
1819 String format, boolean suffix)
1823 alf = getCurrentAlignFrame();
1825 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
1830 public String arrayToSeparatorList(String[] array)
1832 return appLoader.arrayToSeparatorList(array);
1836 public String[] separatorListToArray(String list)
1838 return appLoader.separatorListToArray(list);
1841 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
1842 //// have a direct connection?
1845 public void setMouseoverListener(String listener)
1847 // TODO Auto-generated method stub
1852 public void setMouseoverListener(AlignFrame af, String listener)
1854 // TODO Auto-generated method stub
1859 public void setSelectionListener(String listener)
1861 // TODO Auto-generated method stub
1866 public void setSelectionListener(AlignFrame af, String listener)
1868 // TODO Auto-generated method stub
1873 public void setStructureListener(String listener, String modelSet)
1875 // TODO Auto-generated method stub
1880 public void removeJavascriptListener(AlignFrame af, String listener)
1882 // TODO Auto-generated method stub
1887 public void mouseOverStructure(String pdbResNum, String chain,
1890 // TODO Auto-generated method stub
1895 public void showOverview()
1897 currentAlignFrame.overviewMenuItem_actionPerformed(null);
1900 public void notifyWorker(AlignCalcWorkerI worker, String status)
1902 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
1907 public Object parseArguments(String[] args)
1909 // TODO Auto-generated method stub