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.bin.ApplicationSingletonProvider.ApplicationSingletonI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.HiddenColumns;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
33 import jalview.ext.so.SequenceOntology;
34 import jalview.gui.AlignFrame;
35 import jalview.gui.AlignViewport;
36 import jalview.gui.AlignmentPanel;
37 import jalview.gui.CalculationChooser;
38 import jalview.gui.Desktop;
39 import jalview.gui.Preferences;
40 import jalview.gui.PromptUserConfig;
41 import jalview.gui.StructureViewer;
42 import jalview.io.AppletFormatAdapter;
43 import jalview.io.BioJsHTMLOutput;
44 import jalview.io.DataSourceType;
45 import jalview.io.FileFormat;
46 import jalview.io.FileFormatException;
47 import jalview.io.FileFormatI;
48 import jalview.io.FileFormats;
49 import jalview.io.FileLoader;
50 import jalview.io.HtmlSvgOutput;
51 import jalview.io.IdentifyFile;
52 import jalview.io.NewickFile;
53 import jalview.io.gff.SequenceOntologyFactory;
54 import jalview.javascript.JSFunctionExec;
55 import jalview.javascript.MouseOverStructureListener;
56 import jalview.renderer.seqfeatures.FeatureRenderer;
57 import jalview.schemes.ColourSchemeI;
58 import jalview.schemes.ColourSchemeProperty;
59 import jalview.structure.SelectionSource;
60 import jalview.structure.VamsasSource;
61 import jalview.util.MessageManager;
62 import jalview.util.Platform;
63 import jalview.ws.jws2.Jws2Discoverer;
65 import java.applet.AppletContext;
66 import java.io.BufferedReader;
68 import java.io.FileOutputStream;
69 import java.io.IOException;
70 import java.io.InputStreamReader;
71 import java.io.OutputStreamWriter;
72 import java.io.PrintWriter;
73 import java.net.MalformedURLException;
75 import java.net.URISyntaxException;
77 import java.security.AllPermission;
78 import java.security.CodeSource;
79 import java.security.PermissionCollection;
80 import java.security.Permissions;
81 import java.security.Policy;
82 import java.util.HashMap;
83 import java.util.Hashtable;
85 import java.util.Vector;
87 import javax.swing.LookAndFeel;
88 import javax.swing.UIManager;
90 import groovy.lang.Binding;
91 import groovy.util.GroovyScriptEngine;
92 import netscape.javascript.JSObject;
95 * Main class for Jalview Application <br>
97 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
100 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
101 * jalview.bin.Jalview jalview.bin.Jalview
103 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
104 * embellish '*' to e.g. '*.jar')
107 * @version $Revision$
109 public class Jalview implements ApplicationSingletonI, JalviewJSApi
112 // for testing those nasty messages you cannot ever find.
115 // System.setOut(new PrintStream(new ByteArrayOutputStream())
118 // public void println(Object o)
122 // System.err.println(o);
128 public static Jalview getInstance()
130 return (Jalview) ApplicationSingletonProvider
131 .getInstance(Jalview.class);
140 Platform.getURLCommandArguments();
143 private boolean headless;
145 public static boolean isHeadlessMode()
147 return getInstance().headless;
150 private Desktop desktop;
152 private AlignFrame currentAlignFrame;
154 public boolean isJavaAppletTag;
156 public String appletResourcePath;
158 JalviewAppLoader appLoader;
160 protected JSFunctionExec jsFunctionExec;
162 private boolean noCalculation, noMenuBar, noStatus;
164 private boolean noAnnotation;
166 public boolean getStartCalculations()
168 return !noCalculation;
171 public boolean getAllowMenuBar()
176 public boolean getShowStatus()
181 public boolean getShowAnnotation()
183 return !noAnnotation;
186 public static AlignFrame getCurrentAlignFrame()
188 return getInstance().currentAlignFrame;
191 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
193 getInstance().currentAlignFrame = currentAlignFrame;
198 if (!Platform.isJS())
205 // grab all the rights we can for the JVM
206 Policy.setPolicy(new Policy()
209 public PermissionCollection getPermissions(CodeSource codesource)
211 Permissions perms = new Permissions();
212 perms.add(new AllPermission());
217 public void refresh()
225 * keep track of feature fetching tasks.
233 * TODO: generalise to track all jalview events to orchestrate batch
237 private int queued = 0;
239 private int running = 0;
241 public FeatureFetcher()
246 public void addFetcher(final AlignFrame af,
247 final Vector<String> dasSources)
249 final long id = System.currentTimeMillis();
251 final FeatureFetcher us = this;
252 new Thread(new Runnable()
264 af.setProgressBar(MessageManager
265 .getString("status.das_features_being_retrived"), id);
266 af.featureSettings_actionPerformed(null);
267 af.setProgressBar(null, id);
276 public synchronized boolean allFinished()
278 return queued == 0 && running == 0;
284 * main class for Jalview application
287 * open <em>filename</em>
289 @SuppressWarnings("unused")
290 public static void main(String[] args)
294 Platform.startJavaLogging();
296 getInstance().doMain(args);
300 @SuppressWarnings("unused")
304 void doMain(String[] args)
307 boolean isJS = Platform.isJS();
310 Platform.setAppClass(this);
314 System.setSecurityManager(null);
318 .println("Java version: " + System.getProperty("java.version"));
319 System.out.println(System.getProperty("os.arch") + " "
320 + System.getProperty("os.name") + " "
321 + System.getProperty("os.version"));
323 ArgsParser aparser = new ArgsParser(args);
325 String usrPropsFile = aparser.getValue(ArgsParser.PROPS);
326 Cache.loadProperties(usrPropsFile);
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 isJavaAppletTag = aparser.isApplet();
341 Preferences.setAppletDefaults();
342 Cache.loadProperties(usrPropsFile); // again, because we
343 // might be changing defaults here?
346 "<Applet> found: " + aparser.getValue("Info.j2sAppletID"));
347 appletResourcePath = aparser.getValue("Info.resourcePath");
356 if (usrPropsFile != null)
359 "CMD [-props " + usrPropsFile + "] executed successfully!");
362 if (aparser.contains("help") || aparser.contains("h"))
371 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
372 if (jabawsUrl != null)
376 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
378 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
379 } catch (MalformedURLException e)
382 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
387 // check for property setting
388 String defs = aparser.getValue(ArgsParser.SETPROP);
391 int p = defs.indexOf('=');
394 System.err.println("Ignoring invalid setprop argument : " + defs);
398 System.out.println("Executing setprop argument: " + defs);
401 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
404 defs = aparser.getValue(ArgsParser.SETPROP);
406 System.setProperty("http.agent",
407 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
411 } catch (NoClassDefFoundError error)
413 error.printStackTrace();
414 System.out.println("\nEssential logging libraries not found."
415 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
423 if (!isJS && Platform.isWin())
425 UIManager.setLookAndFeel(
426 headless ? "javax.swing.plaf.metal.MetalLookAndFeel"
427 : UIManager.getSystemLookAndFeelClassName());
428 // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
430 } catch (Exception ex)
432 System.err.println("Unexpected Look and Feel Exception");
433 ex.printStackTrace();
435 if (Platform.isAMacAndNotJS())
438 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
440 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
442 System.setProperty("apple.laf.useScreenMenuBar", "true");
443 if (lookAndFeel != null)
447 UIManager.setLookAndFeel(lookAndFeel);
448 } catch (Throwable e)
451 "Failed to set QuaQua look and feel: " + e.toString());
454 if (lookAndFeel == null
455 || !(lookAndFeel.getClass().isAssignableFrom(
456 UIManager.getLookAndFeel().getClass()))
457 || !UIManager.getLookAndFeel().getClass().toString()
458 .toLowerCase().contains("quaqua"))
463 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
464 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
465 } catch (Throwable e)
468 "Failed to reset look and feel: " + e.toString());
474 * configure 'full' SO model if preferences say to,
475 * else use the default (SO Lite)
477 if (Cache.getDefault(Preferences.USE_FULL_SO, false))
479 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
484 desktop = Desktop.getInstance();
485 desktop.setInBatchMode(true); // indicate we are starting up
486 desktop.setVisible(true);
495 desktop.startServiceDiscovery();
496 if (!aparser.contains(ArgsParser.NOUSAGESTATS))
498 startUsageStats(desktop);
502 System.err.println("CMD [-nousagestats] executed successfully!");
505 if (!aparser.contains(ArgsParser.NOQUESTIONNAIRE))
507 String url = aparser.getValue(ArgsParser.QUESTIONNAIRE);
510 // Start the desktop questionnaire prompter with the specified
512 Cache.log.debug("Starting questionnaire url at " + url);
513 desktop.checkForQuestionnaire(url);
514 System.out.println("CMD questionnaire[-" + url
515 + "] executed successfully!");
519 if (Cache.getProperty(Preferences.NOQUESTIONNAIRES) == null)
521 // Start the desktop questionnaire prompter with the specified
524 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
526 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
528 "Starting questionnaire with default url: " + defurl);
529 desktop.checkForQuestionnaire(defurl);
536 .println("CMD [-noquestionnaire] executed successfully!");
539 if (!aparser.contains(ArgsParser.NONEWS))
541 desktop.checkForNews();
544 BioJsHTMLOutput.updateBioJS();
548 parseArguments(aparser, true);
552 * Allow an outside entity to initiate the second half of argument parsing
556 * @return null is good
559 public Object parseArguments(String[] args)
564 ArgsParser aparser = new ArgsParser(args);
565 return parseArguments(aparser, false);
566 } catch (Throwable t)
578 private Object parseArguments(ArgsParser aparser, boolean isStartup)
580 boolean isJS = Platform.isJS();
582 Desktop desktop = (headless ? null : Desktop.getInstance());
583 // script to execute after all loading is
584 // completed one way or another
585 // extract groovy argument and execute if necessary
586 String groovyscript = (isJS ? null
587 : aparser.getValue(ArgsParser.GROOVY, true));
588 String file = aparser.getValue(ArgsParser.OPEN, true);
589 // BH this here to allow split frame; not working as of 5/17/2019
590 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
591 String fileFormat = (isJavaAppletTag
592 ? aparser.getAppletValue("format", null)
594 FileFormatI format = null;
595 DataSourceType protocol = null;
597 if (file == null && desktop == null)
599 System.out.println("No files to open!");
602 boolean haveImport = checkStartVamas(aparser);
603 // Finally, deal with the remaining input data.
605 if (file == null && isJavaAppletTag)
607 // Maybe the sequences are added as parameters
608 StringBuffer data = new StringBuffer("PASTE");
610 while ((file = aparser.getAppletValue("sequence" + i, null)) != null)
612 data.append(file.toString() + "\n");
615 if (data.length() > 5)
617 file = data.toString();
628 desktop.setProgressBar(
630 .getString("status.processing_commandline_args"),
631 progress = System.currentTimeMillis());
636 * ignore in JavaScript -- can't just check file existence - could load
642 if (!file.startsWith("http://") && !file.startsWith("https://"))
643 // BH 2019 added https check for Java
645 if (!(new File(file)).exists())
647 System.out.println("Can't find " + file);
656 protocol = AppletFormatAdapter.checkProtocol(file);
660 format = (isJavaAppletTag && fileFormat != null
661 ? FileFormats.getInstance().forName(fileFormat)
665 format = new IdentifyFile().identify(file, protocol);
667 } catch (FileFormatException e1)
672 if (aparser.contains(ArgsParser.NOMENUBAR))
675 System.out.println("CMD [nomenu] executed successfully!");
678 if (aparser.contains(ArgsParser.NOSTATUS))
681 System.out.println("CMD [nostatus] executed successfully!");
684 if (aparser.contains(ArgsParser.NOANNOTATION)
685 || aparser.contains(ArgsParser.NOANNOTATION2))
688 System.out.println("CMD no-annotation executed successfully!");
690 if (aparser.contains(ArgsParser.NOCALCULATION))
692 noCalculation = true;
693 System.out.println("CMD [nocalculation] executed successfully!");
696 AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
700 System.out.println("error");
705 .println("CMD [-open " + file + "] executed successfully!");
708 protocol = AppletFormatAdapter.checkProtocol(file2);
711 format = new IdentifyFile().identify(file2, protocol);
712 } catch (FileFormatException e1)
716 AlignFrame af2 = new FileLoader(!headless)
717 .loadFileWaitTillLoaded(file2, protocol, format);
720 System.out.println("error");
724 AlignViewport.openLinkedAlignmentAs(af,
725 af.getViewport().getAlignment(),
726 af2.getViewport().getAlignment(), "",
727 AlignViewport.SPLIT_FRAME);
729 "CMD [-open2 " + file2 + "] executed successfully!");
733 setCurrentAlignFrame(af);
735 // TODO: file2 How to implement file2 for the applet spit screen?
737 data = aparser.getValue(ArgsParser.COLOUR, true);
740 data.replaceAll("%20", " ");
742 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
743 af.getViewport(), af.getViewport().getAlignment(), data);
748 "CMD [-color " + data + "] executed successfully!");
753 // Must maintain ability to use the groups flag
754 data = aparser.getValue(ArgsParser.GROUPS, true);
757 af.parseFeaturesFile(data,
758 AppletFormatAdapter.checkProtocol(data));
759 // System.out.println("Added " + data);
761 "CMD groups[-" + data + "] executed successfully!");
763 data = aparser.getValue(ArgsParser.FEATURES, true);
766 af.parseFeaturesFile(data,
767 AppletFormatAdapter.checkProtocol(data));
768 // System.out.println("Added " + data);
770 "CMD [-features " + data + "] executed successfully!");
773 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
776 af.loadJalviewDataFile(data, null, null, null);
777 // System.out.println("Added " + data);
779 "CMD [-annotations " + data + "] executed successfully!");
782 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
784 af.overviewMenuItem_actionPerformed(null);
785 System.out.println("CMD [showoverview] executed successfully!");
788 // set or clear the sortbytree flag.
789 if (aparser.contains(ArgsParser.SORTBYTREE))
791 af.getViewport().setSortByTree(true);
792 if (af.getViewport().getSortByTree())
794 System.out.println("CMD [-sortbytree] executed successfully!");
798 boolean doUpdateAnnotation = false;
801 * we do this earlier in JalviewJS because of a complication with
804 * For now, just fixing this in JalviewJS.
811 if (aparser.contains(ArgsParser.NOANNOTATION)
812 || aparser.contains(ArgsParser.NOANNOTATION2))
814 af.getViewport().setShowAnnotation(false);
815 if (!af.getViewport().isShowAnnotation())
817 doUpdateAnnotation = true;
819 .println("CMD no-annotation executed successfully!");
823 if (aparser.contains(ArgsParser.NOSORTBYTREE))
825 af.getViewport().setSortByTree(false);
826 if (!af.getViewport().getSortByTree())
828 doUpdateAnnotation = true;
830 .println("CMD [-nosortbytree] executed successfully!");
833 if (doUpdateAnnotation)
835 af.setMenusForViewport();
836 af.alignPanel.updateLayout();
838 data = aparser.getValue(ArgsParser.TREE, true);
844 "CMD [-tree " + data + "] executed successfully!");
845 NewickFile nf = new NewickFile(data,
846 AppletFormatAdapter.checkProtocol(data));
848 .setCurrentTree(af.showNewickTree(nf, data).getTree());
849 } catch (IOException ex)
851 System.err.println("Couldn't add tree " + data);
852 ex.printStackTrace(System.err);
855 // TODO - load PDB structure(s) to alignment JAL-629
856 // (associate with identical sequence in alignment, or a specified
860 loadAppletParams(aparser, af);
869 if (groovyscript != null)
871 // Execute the groovy script after we've done all the rendering
873 // and before any images or figures are generated.
874 System.out.println("Executing script " + groovyscript);
875 executeGroovyScript(groovyscript, af);
876 System.out.println("CMD groovy[" + groovyscript
877 + "] executed successfully!");
881 createOutputFiles(aparser, af, format);
882 while (aparser.getSize() > 0)
884 System.out.println("Unknown arg: " + aparser.nextValue());
888 AlignFrame startUpAlframe = null;
889 // We'll only open the default file if the desktop is visible.
891 // ////////////////////
893 if (!isJS && !headless && file == null && !haveImport
894 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
901 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
902 jalview.bin.Cache.getDefault("www.jalview.org",
903 "http://www.jalview.org")
904 + "/examples/exampleFile_2_7.jar");
906 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
908 // hardwire upgrade of the startup file
909 file.replace("_2_3.jar", "_2_7.jar");
910 // and remove the stale setting
911 jalview.bin.Cache.removeProperty("STARTUP_FILE");
914 protocol = DataSourceType.FILE;
916 if (file.indexOf("http:") > -1)
918 protocol = DataSourceType.URL;
921 if (file.endsWith(".jar"))
923 format = FileFormat.Jalview;
929 format = new IdentifyFile().identify(file, protocol);
930 } catch (FileFormatException e)
936 startUpAlframe = new FileLoader(!headless)
937 .loadFileWaitTillLoaded(file, protocol, format);
938 // extract groovy arguments before anything else.
941 // Once all other stuff is done, execute any groovy scripts (in order)
942 if (groovyscript != null)
944 if (Cache.groovyJarsPresent())
946 System.out.println("Executing script " + groovyscript);
947 executeGroovyScript(groovyscript, startUpAlframe);
952 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
956 // and finally, turn off batch mode indicator - if the desktop still exists
961 desktop.setProgressBar(null, progress);
963 desktop.setInBatchMode(false);
969 private boolean checkStartVamas(ArgsParser aparser)
971 String vamsasImport = aparser.getValue(ArgsParser.VDOC);
972 String vamsasSession = aparser.getValue(ArgsParser.VSESS);
973 if (vamsasImport == null && vamsasSession == null)
977 if (desktop == null || headless)
980 "Headless vamsas sessions not yet supported. Sorry.");
983 boolean haveImport = (vamsasImport != null);
986 // if we have a file, start a new session and import it.
987 boolean inSession = false;
990 DataSourceType viprotocol = AppletFormatAdapter
991 .checkProtocol(vamsasImport);
992 if (viprotocol == DataSourceType.FILE)
994 inSession = desktop.vamsasImport(new File(vamsasImport));
996 else if (viprotocol == DataSourceType.URL)
998 inSession = desktop.vamsasImport(new URL(vamsasImport));
1001 } catch (Exception e)
1003 System.err.println("Exeption when importing " + vamsasImport
1004 + " as a vamsas document.");
1005 e.printStackTrace();
1009 System.err.println("Failed to import " + vamsasImport
1010 + " as a vamsas document.");
1014 System.out.println("Imported Successfully into new session "
1015 + desktop.getVamsasApplication().getCurrentSession());
1018 if (vamsasSession != null)
1020 if (vamsasImport != null)
1022 // close the newly imported session and import the Jalview specific
1023 // remnants into the new session later on.
1024 desktop.vamsasStop_actionPerformed(null);
1026 // now join the new session
1029 if (desktop.joinVamsasSession(vamsasSession))
1032 "Successfully joined vamsas session " + vamsasSession);
1036 System.err.println("WARNING: Failed to join vamsas session "
1039 } catch (Exception e)
1042 "ERROR: Failed to join vamsas session " + vamsasSession);
1043 e.printStackTrace();
1045 if (vamsasImport != null)
1047 // the Jalview specific remnants can now be imported into the new
1048 // session at the user's leisure.
1050 "Skipping Push for import of data into existing vamsas session.");
1056 // desktop.getVamsasApplication().push_update();
1063 * Writes an output file for each format (if any) specified in the
1064 * command-line arguments. Supported formats are currently
1073 * A format parameter should be followed by a parameter specifying the output
1074 * file name. {@code imgMap} parameters should follow those for the
1075 * corresponding alignment image output.
1081 private void createOutputFiles(ArgsParser aparser, AlignFrame af,
1084 String imageName = "unnamed.png";
1085 while (aparser.getSize() > 1)
1087 String outputFormat = aparser.nextValue();
1088 String file = aparser.nextValue();
1089 // System.out.println("format " + outputFormat);
1091 if (outputFormat.equalsIgnoreCase("png"))
1093 af.createPNG(new File(file));
1094 imageName = (new File(file)).getName();
1095 System.out.println("Creating PNG image: " + file);
1098 else if (outputFormat.equalsIgnoreCase("svg"))
1100 File imageFile = new File(file);
1101 imageName = imageFile.getName();
1102 af.createSVG(imageFile);
1103 System.out.println("Creating SVG image: " + file);
1106 else if (outputFormat.equalsIgnoreCase("html"))
1108 File imageFile = new File(file);
1109 imageName = imageFile.getName();
1110 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1111 htmlSVG.exportHTML(file);
1113 System.out.println("Creating HTML image: " + file);
1116 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
1120 System.err.println("The output html file must not be null");
1125 BioJsHTMLOutput.refreshVersionInfo(
1126 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1127 } catch (URISyntaxException e)
1129 e.printStackTrace();
1131 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1132 bjs.exportHTML(file);
1133 System.out.println("Creating BioJS MSA Viwer HTML file: " + file);
1136 else if (outputFormat.equalsIgnoreCase("imgMap"))
1138 af.createImageMap(new File(file), imageName);
1139 System.out.println("Creating image map: " + file);
1142 else if (outputFormat.equalsIgnoreCase("eps"))
1144 File outputFile = new File(file);
1146 "Creating EPS file: " + outputFile.getAbsolutePath());
1147 af.createEPS(outputFile);
1151 af.saveAlignment(file, format);
1152 if (af.isSaveAlignmentSuccessful())
1155 "Written alignment in " + format + " format to " + file);
1159 System.out.println("Error writing file " + file + " in " + format
1166 private static void showUsage()
1169 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1170 + "-nodisplay\tRun Jalview without User Interface.\n"
1171 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1172 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1173 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1174 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1175 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1176 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1177 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1178 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1179 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1180 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1181 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1182 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1183 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1184 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1185 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1186 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1187 + "-html FILE\tCreate HTML file from alignment.\n"
1188 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1189 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1190 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1191 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1192 + "-noquestionnaire\tTurn off questionnaire check.\n"
1193 + "-nonews\tTurn off check for Jalview news.\n"
1194 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1195 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1197 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1198 // after all other properties files have been read\n\t
1199 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1200 // passed in correctly)"
1201 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1202 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1204 // "-vdoc vamsas-document\tImport vamsas document into new
1205 // session or join existing session with same URN\n"
1206 // + "-vses vamsas-session\tJoin session with given URN\n"
1207 + "-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"
1208 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
1211 private static void startUsageStats(final Desktop desktop)
1214 * start a User Config prompt asking if we can log usage statistics.
1216 PromptUserConfig prompter = new PromptUserConfig(
1217 Desktop.getDesktopPane(), "USAGESTATS",
1218 "Jalview Usage Statistics",
1219 "Do you want to help make Jalview better by enabling "
1220 + "the collection of usage statistics with Google Analytics ?"
1221 + "\n\n(you can enable or disable usage tracking in the preferences)",
1228 "Initialising googletracker for usage stats.");
1229 Cache.initGoogleTracker();
1230 Cache.log.debug("Tracking enabled.");
1237 Cache.log.debug("Not enabling Google Tracking.");
1240 desktop.addDialogThread(prompter);
1244 * Locate the given string as a file and pass it to the groovy interpreter.
1246 * @param groovyscript
1247 * the script to execute
1248 * @param jalviewContext
1249 * the Jalview Desktop object passed in to the groovy binding as the
1252 private void executeGroovyScript(String groovyscript, AlignFrame af)
1255 * for scripts contained in files
1262 if (groovyscript.trim().equals("STDIN"))
1264 // read from stdin into a tempfile and execute it
1267 tfile = File.createTempFile("jalview", "groovy");
1268 PrintWriter outfile = new PrintWriter(
1269 new OutputStreamWriter(new FileOutputStream(tfile)));
1270 BufferedReader br = new BufferedReader(
1271 new InputStreamReader(System.in));
1273 while ((line = br.readLine()) != null)
1275 outfile.write(line + "\n");
1281 } catch (Exception ex)
1283 System.err.println("Failed to read from STDIN into tempfile "
1284 + ((tfile == null) ? "(tempfile wasn't created)"
1285 : tfile.toString()));
1286 ex.printStackTrace();
1291 sfile = tfile.toURI().toURL();
1292 } catch (Exception x)
1295 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1297 x.printStackTrace();
1305 sfile = new URI(groovyscript).toURL();
1306 } catch (Exception x)
1308 tfile = new File(groovyscript);
1309 if (!tfile.exists())
1311 System.err.println("File '" + groovyscript + "' does not exist.");
1314 if (!tfile.canRead())
1316 System.err.println("File '" + groovyscript + "' cannot be read.");
1319 if (tfile.length() < 1)
1321 System.err.println("File '" + groovyscript + "' is empty.");
1326 sfile = tfile.getAbsoluteFile().toURI().toURL();
1327 } catch (Exception ex)
1329 System.err.println("Failed to create a file URL for "
1330 + tfile.getAbsoluteFile());
1337 Map<String, Object> vbinding = new HashMap<>();
1338 vbinding.put("Jalview", this);
1341 vbinding.put("currentAlFrame", af);
1343 Binding gbinding = new Binding(vbinding);
1344 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1345 gse.run(sfile.toString(), gbinding);
1346 if ("STDIN".equals(groovyscript))
1348 // delete temp file that we made -
1349 // only if it was successfully executed
1352 } catch (Exception e)
1354 System.err.println("Exception Whilst trying to execute file " + sfile
1355 + " as a groovy script.");
1356 e.printStackTrace(System.err);
1361 public AlignFrame[] getAlignFrames()
1363 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1364 : Desktop.getAlignFrames();
1369 * Quit method delegates to Desktop.quit - unless running in headless mode
1370 * when it just ends the JVM
1374 if (jsFunctionExec != null)
1376 jsFunctionExec.tidyUp();
1377 jsFunctionExec = null;
1380 if (desktop != null)
1391 * Get the SwingJS applet ID and combine that with the frameType
1394 * "alignment", "desktop", etc., or null
1397 public static String getAppID(String frameType)
1399 String id = Cache.getProperty("Info.j2sAppletID");
1404 return id + (frameType == null ? "" : "-" + frameType);
1408 * Handle all JalviewLite applet parameters
1413 private void loadAppletParams(ArgsParser aparser, AlignFrame af)
1415 JalviewApp app = new JalviewApp()
1420 // These are methods that are in JalviewLite that various classes call
1421 // but are not in JalviewLiteJsApi. Or, even if they are, other classes
1423 // them to JalviewLite directly. Some may not be necessary, but they have
1425 // be at least mentioned here, or the classes calling them should
1427 // JalviewLite itself.
1429 private boolean alignPDBStructures; // From JalviewLite; not implemented
1431 private Hashtable<String, Hashtable<String, String[]>> jsmessages;
1433 private Hashtable<String, int[]> jshashes;
1436 public String getParameter(String name)
1438 return aparser.getAppletValue(name, null);
1442 public boolean getDefaultParameter(String name, boolean def)
1445 return ((stn = getParameter(name)) == null ? def
1446 : "true".equalsIgnoreCase(stn));
1450 * Get the applet-like document base even though this is an application.
1453 public URL getDocumentBase()
1455 return Platform.getDocumentBase();
1459 * Get the applet-like code base even though this is an application.
1462 public URL getCodeBase()
1464 return Platform.getCodeBase();
1468 public AlignViewportI getViewport()
1470 return af.getViewport();
1478 public boolean parseFeaturesFile(String filename,
1479 DataSourceType protocol)
1481 return af.parseFeaturesFile(filename, protocol);
1489 public boolean loadScoreFile(String sScoreFile) throws IOException
1491 af.loadJalviewDataFile(sScoreFile, null, null, null);
1496 * annotations, jpredfile, jnetfile
1500 public void updateForAnnotations()
1502 af.updateForAnnotations();
1506 public void loadTree(NewickFile fin, String treeFile)
1509 // n/a -- already done by standard Jalview command line processing
1513 public void setAlignPdbStructures(boolean defaultParameter)
1515 alignPDBStructures = true;
1519 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
1520 String[] chains, DataSourceType protocol)
1522 StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
1526 public void setFeatureGroupState(String[] groups, boolean state)
1528 af.setFeatureGroupState(groups, state);
1532 public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
1533 String[][] chains, String[] protocols)
1536 "Jalview applet interface alignedStructureView not implemented");
1540 public void newFeatureSettings()
1543 "Jalview applet interface newFeatureSettings not implemented");
1546 private Vector<Runnable> jsExecQueue;
1549 public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
1551 jsFunctionExec = exec;
1552 return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
1557 public AppletContext getAppletContext()
1559 // TODO Auto-generated method stub
1564 public boolean isJsfallbackEnabled()
1566 // TODO Auto-generated method stub
1571 public JSObject getJSObject()
1573 // TODO Auto-generated method stub
1578 public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
1580 // TODO Q: what exactly is this? BH
1585 public void updateColoursFromMouseOver(Object source,
1586 MouseOverStructureListener mouseOverStructureListener)
1588 // TODO Auto-generated method stub
1593 public Object[] getSelectionForListener(SequenceGroup seqsel,
1594 ColumnSelection colsel, HiddenColumns hidden,
1595 SelectionSource source, Object alignFrame)
1597 return appLoader.getSelectionForListener(getCurrentAlignFrame(),
1598 seqsel, colsel, hidden, source, alignFrame);
1602 public String arrayToSeparatorList(String[] array)
1604 return appLoader.arrayToSeparatorList(array);
1608 public Hashtable<String, int[]> getJSHashes()
1610 return (jshashes == null ? (jshashes = new Hashtable<>())
1615 public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
1617 return (jsmessages == null ? (jsmessages = new Hashtable<>())
1622 public Object getFrameForSource(VamsasSource source)
1627 if (source instanceof jalview.gui.AlignViewport
1628 && source == (af = getCurrentAlignFrame()).getViewport())
1630 // should be valid if it just generated an event!
1633 // TODO: ensure that if '_af' is specified along with a handler
1634 // function, then only events from that alignFrame are sent to that
1641 public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
1643 return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
1648 appLoader = new JalviewAppLoader(true);
1649 appLoader.load(app);
1654 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
1657 public String getSelectedSequences()
1659 return getSelectedSequencesFrom(getCurrentAlignFrame());
1664 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
1667 public String getSelectedSequences(String sep)
1669 return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
1674 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1678 public String getSelectedSequencesFrom(AlignFrame alf)
1682 alf = getCurrentAlignFrame();
1684 return getSelectedSequencesFrom(alf, null);
1689 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1690 * .AlignFrame, java.lang.String)
1693 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
1697 alf = getCurrentAlignFrame();
1699 return appLoader.getSelectedSequencesFrom(alf, sep);
1704 * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
1705 * .AlignFrame, java.lang.String)
1708 public void highlight(String sequenceId, String position,
1709 String alignedPosition)
1711 highlightIn(null, sequenceId, position,
1716 public void highlightIn(AlignFrame alf, String sequenceId,
1717 String position, String alignedPosition)
1721 alf = getCurrentAlignFrame();
1723 appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
1727 public void select(String sequenceIds, String columns)
1729 selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
1733 public void select(String sequenceIds, String columns, String sep)
1735 selectIn(null, sequenceIds, columns, sep);
1739 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
1741 selectIn(alf, sequenceIds, columns, null);
1745 public void selectIn(AlignFrame alf, String sequenceIds, String columns,
1750 alf = getCurrentAlignFrame();
1752 appLoader.selectIn(alf, sequenceIds, columns, sep);
1756 public String getSelectedSequencesAsAlignment(String format,
1759 return getSelectedSequencesAsAlignmentFrom(null,
1764 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
1765 String format, String sep)
1769 alf = getCurrentAlignFrame();
1771 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
1775 public String getAlignmentOrder()
1777 return getAlignmentFrom(getCurrentAlignFrame(), null);
1781 public String getAlignmentOrderFrom(AlignFrame alf)
1783 return getAlignmentFrom(alf, null);
1787 public String getAlignmentOrderFrom(AlignFrame alf, String sep)
1791 alf = getCurrentAlignFrame();
1793 return appLoader.getAlignmentOrderFrom(alf, sep);
1797 public String orderBy(String order, String undoName)
1799 return orderBy(order, undoName, null);
1803 public String orderBy(String order, String undoName, String sep)
1805 return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
1809 public String orderAlignmentBy(AlignFrame alf, String order,
1810 String undoName, String sep)
1814 alf = getCurrentAlignFrame();
1816 return appLoader.orderAlignmentBy(alf, order, undoName, sep);
1820 public String getAlignment(String format)
1822 return getAlignmentFrom(null, format, null);
1826 public String getAlignmentFrom(AlignFrame alf, String format)
1828 return getAlignmentFrom(alf, format, null);
1832 public String getAlignment(String format, String suffix)
1834 return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
1838 public String getAlignmentFrom(AlignFrame alf, String format,
1841 return appLoader.getAlignmentFrom(alf, format, suffix);
1845 public void loadAnnotation(String annotation)
1847 loadAnnotationFrom(getCurrentAlignFrame(), annotation);
1851 public void loadAnnotationFrom(AlignFrame alf, String annotation)
1855 alf = getCurrentAlignFrame();
1857 appLoader.loadAnnotationFrom(alf, annotation);
1861 public void loadFeatures(String features, boolean autoenabledisplay)
1863 loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
1867 public boolean loadFeaturesFrom(AlignFrame alf, String features,
1868 boolean autoenabledisplay)
1872 alf = getCurrentAlignFrame();
1874 return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
1878 public String getFeatures(String format)
1880 return getFeaturesFrom(null, format);
1884 public String getFeaturesFrom(AlignFrame alf, String format)
1888 alf = getCurrentAlignFrame();
1890 return appLoader.getFeaturesFrom(alf, format);
1894 public String getAnnotation()
1896 return getAnnotationFrom(null);
1900 public String getAnnotationFrom(AlignFrame alf)
1904 alf = getCurrentAlignFrame();
1906 return appLoader.getAnnotationFrom(alf);
1910 // public AlignFrame newView()
1912 // return newViewFrom(null, null);
1916 // public AlignFrame newView(String name)
1918 // return newViewFrom(null, name);
1922 // public AlignFrame newViewFrom(AlignFrame alf)
1924 // return newViewFrom(alf, null);
1928 // public AlignFrame newViewFrom(AlignFrame alf, String name)
1932 // alf = getCurrentAlignFrame();
1934 // return appLoader.newViewFrom(alf, name);
1938 public AlignFrame loadAlignment(String text, String title)
1940 return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
1941 AlignFrame.DEFAULT_HEIGHT, title);
1945 public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
1946 String pdbEntryString, String pdbFile)
1948 if (alFrame == null)
1950 alFrame = getCurrentAlignFrame();
1952 return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
1957 public void scrollViewToIn(AlignFrame alf, String topRow,
1958 String leftHandColumn)
1962 alf = getCurrentAlignFrame();
1964 appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
1968 public void scrollViewToRowIn(AlignFrame alf, String topRow)
1972 alf = getCurrentAlignFrame();
1974 appLoader.scrollViewToRowIn(alf, topRow);
1978 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
1982 alf = getCurrentAlignFrame();
1984 appLoader.scrollViewToColumnIn(alf, leftHandColumn);
1988 public String getFeatureGroups()
1990 return getFeatureGroupsOn(null);
1994 public String getFeatureGroupsOn(AlignFrame alf)
1998 alf = getCurrentAlignFrame();
2000 return appLoader.getFeatureGroupsOn(alf);
2004 public String getFeatureGroupsOfState(boolean visible)
2006 return getFeatureGroupsOfStateOn(null, visible);
2010 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
2014 alf = getCurrentAlignFrame();
2016 return appLoader.getFeatureGroupsOfStateOn(alf, visible);
2020 public void setFeatureGroupState(String groups, boolean state)
2021 { // JalviewLite API
2022 setFeatureGroupStateOn(null, groups, state);
2026 public void setFeatureGroupStateOn(AlignFrame alf, String groups,
2031 alf = getCurrentAlignFrame();
2033 appLoader.setFeatureGroupStateOn(alf, groups, state);
2037 public String getSeparator()
2039 return appLoader.getSeparator();
2043 public void setSeparator(String separator)
2045 appLoader.setSeparator(separator);
2049 public String getJsMessage(String messageclass, String viewId)
2051 // see http://www.jalview.org/examples/jalviewLiteJs.html
2056 * Open a new Tree panel on the desktop statically. Params are standard (not
2057 * set by Groovy). No dialog is opened.
2062 * @return null, or the string "label.you_need_at_least_n_sequences" if number
2063 * of sequences selected is inappropriate
2066 public Object openTreePanel(AlignFrame af, String treeType,
2071 af = getCurrentAlignFrame();
2073 return CalculationChooser.openTreePanel(af, treeType, modelName, null);
2077 * public static method for JalviewJS API to open a PCAPanel without
2078 * necessarily using a dialog.
2082 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
2083 * if number of sequences selected is inappropriate
2086 public Object openPcaPanel(AlignFrame af, String modelName)
2090 af = getCurrentAlignFrame();
2092 return CalculationChooser.openPcaPanel(af, modelName, null);
2096 public String getSelectedSequencesAsAlignment(String format,
2099 return getSelectedSequencesAsAlignmentFrom(null,
2104 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
2105 String format, boolean suffix)
2109 alf = getCurrentAlignFrame();
2111 return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
2116 public String arrayToSeparatorList(String[] array)
2118 return appLoader.arrayToSeparatorList(array);
2122 public String[] separatorListToArray(String list)
2124 return appLoader.separatorListToArray(list);
2127 //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
2128 //// have a direct connection?
2131 public void setMouseoverListener(String listener)
2133 // TODO Auto-generated method stub
2138 public void setMouseoverListener(AlignFrame af, String listener)
2140 // TODO Auto-generated method stub
2145 public void setSelectionListener(String listener)
2147 // TODO Auto-generated method stub
2152 public void setSelectionListener(AlignFrame af, String listener)
2154 // TODO Auto-generated method stub
2159 public void setStructureListener(String listener, String modelSet)
2161 // TODO Auto-generated method stub
2166 public void removeJavascriptListener(AlignFrame af, String listener)
2168 // TODO Auto-generated method stub
2173 public void mouseOverStructure(String pdbResNum, String chain,
2176 // TODO Auto-generated method stub
2181 public void showOverview()
2183 currentAlignFrame.overviewMenuItem_actionPerformed(null);
2186 public void notifyWorker(AlignCalcWorkerI worker, String status)
2188 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()