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.ext.so.SequenceOntology;
24 import jalview.gui.AlignFrame;
25 import jalview.gui.Desktop;
26 import jalview.gui.PromptUserConfig;
27 import jalview.io.AppletFormatAdapter;
28 import jalview.io.BioJsHTMLOutput;
29 import jalview.io.DataSourceType;
30 import jalview.io.FileFormat;
31 import jalview.io.FileFormatException;
32 import jalview.io.FileFormatI;
33 import jalview.io.FileLoader;
34 import jalview.io.HtmlSvgOutput;
35 import jalview.io.IdentifyFile;
36 import jalview.io.NewickFile;
37 import jalview.io.gff.SequenceOntologyFactory;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.ColourSchemeProperty;
40 import jalview.util.MessageManager;
41 import jalview.util.Platform;
42 import jalview.ws.jws2.Jws2Discoverer;
44 import java.io.BufferedReader;
46 import java.io.FileOutputStream;
47 import java.io.IOException;
48 import java.io.InputStreamReader;
49 import java.io.OutputStreamWriter;
50 import java.io.PrintWriter;
51 import java.net.MalformedURLException;
53 import java.net.URISyntaxException;
55 import java.security.AllPermission;
56 import java.security.CodeSource;
57 import java.security.PermissionCollection;
58 import java.security.Permissions;
59 import java.security.Policy;
60 import java.util.HashMap;
62 import java.util.Vector;
64 import javax.swing.LookAndFeel;
65 import javax.swing.UIManager;
67 import groovy.lang.Binding;
68 import groovy.util.GroovyScriptEngine;
71 * Main class for Jalview Application <br>
73 * start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
81 // BH 6/19/2018 starting to work on JS version - just discovering issues
84 * singleton instance of this class
86 private static Jalview instance;
88 private Desktop desktop;
90 public static AlignFrame currentAlignFrame;
93 * Answers true if Jalview is running as Javascript, else false. The value is
94 * set at compile time.
98 public static boolean isJS()
100 return /** @j2sNative true || */
108 // grab all the rights we can the JVM
109 Policy.setPolicy(new Policy()
112 public PermissionCollection getPermissions(CodeSource codesource)
114 Permissions perms = new Permissions();
115 perms.add(new AllPermission());
120 public void refresh()
129 * keep track of feature fetching tasks.
137 * TODO: generalise to track all jalview events to orchestrate batch
141 private int queued = 0;
143 private int running = 0;
145 public FeatureFetcher()
150 public void addFetcher(final AlignFrame af,
151 final Vector<String> dasSources)
153 final long id = System.currentTimeMillis();
155 final FeatureFetcher us = this;
156 new Thread(new Runnable()
168 af.setProgressBar(MessageManager
169 .getString("status.das_features_being_retrived"), id);
170 af.featureSettings_actionPerformed(null);
171 af.setProgressBar(null, id);
180 public synchronized boolean allFinished()
182 return queued == 0 && running == 0;
187 public static Jalview getInstance()
193 * main class for Jalview application
196 * open <em>filename</em>
198 public static void main(String[] args)
200 instance = new Jalview();
201 instance.doMain(args);
207 void doMain(String[] args)
212 System.setSecurityManager(null);
216 .println("Java version: " + System.getProperty("java.version"));
217 System.out.println(System.getProperty("os.arch") + " "
218 + System.getProperty("os.name") + " "
219 + System.getProperty("os.version"));
221 ArgsParser aparser = new ArgsParser(args);
222 boolean headless = false;
224 String usrPropsFile = aparser.getValue("props");
225 Cache.loadProperties(usrPropsFile); // must do this before
226 if (usrPropsFile != null)
229 "CMD [-props " + usrPropsFile + "] executed successfully!");
233 * BH 2018 ignoring this section for JS
238 if (aparser.contains("help") || aparser.contains("h"))
243 if (aparser.contains("nodisplay") || aparser.contains("nogui")
244 || aparser.contains("headless"))
246 System.setProperty("java.awt.headless", "true");
251 final String jabawsUrl = aparser.getValue("jabaws");
252 if (jabawsUrl != null)
256 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
258 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
259 } catch (MalformedURLException e)
262 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
267 String defs = aparser.getValue("setprop");
270 int p = defs.indexOf('=');
273 System.err.println("Ignoring invalid setprop argument : " + defs);
277 System.out.println("Executing setprop argument: " + defs);
278 // DISABLED FOR SECURITY REASONS
279 // TODO: add a property to allow properties to be overriden by cli args
280 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
282 defs = aparser.getValue("setprop");
284 if (System.getProperty("java.awt.headless") != null
285 && System.getProperty("java.awt.headless").equals("true"))
289 System.setProperty("http.agent",
290 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
294 } catch (NoClassDefFoundError error)
296 error.printStackTrace();
297 System.out.println("\nEssential logging libraries not found."
298 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
306 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
307 } catch (Exception ex)
309 System.err.println("Unexpected Look and Feel Exception");
310 ex.printStackTrace();
312 if (Platform.isAMac())
315 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
317 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
319 System.setProperty("apple.laf.useScreenMenuBar", "true");
320 if (lookAndFeel != null)
324 UIManager.setLookAndFeel(lookAndFeel);
325 } catch (Throwable e)
328 "Failed to set QuaQua look and feel: " + e.toString());
331 if (lookAndFeel == null || !(lookAndFeel.getClass()
332 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
333 || !UIManager.getLookAndFeel().getClass().toString()
334 .toLowerCase().contains("quaqua"))
339 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
340 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
341 } catch (Throwable e)
344 "Failed to reset look and feel: " + e.toString());
350 * configure 'full' SO model if preferences say to,
351 * else use the default (SO Lite)
353 if (Cache.getDefault("USE_FULL_SO", false))
355 SequenceOntologyFactory.setInstance(new SequenceOntology());
360 desktop = new Desktop();
361 desktop.setInBatchMode(true); // indicate we are starting up
362 desktop.setVisible(true);
365 * BH 2018 JS bypass this section
371 desktop.startServiceDiscovery();
372 if (!aparser.contains("nousagestats"))
374 startUsageStats(desktop);
378 System.err.println("CMD [-nousagestats] executed successfully!");
381 if (!aparser.contains("noquestionnaire"))
383 String url = aparser.getValue("questionnaire");
386 // Start the desktop questionnaire prompter with the specified
388 Cache.log.debug("Starting questionnaire url at " + url);
389 desktop.checkForQuestionnaire(url);
390 System.out.println("CMD questionnaire[-" + url
391 + "] executed successfully!");
395 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
397 // Start the desktop questionnaire prompter with the specified
400 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
402 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
404 "Starting questionnaire with default url: " + defurl);
405 desktop.checkForQuestionnaire(defurl);
412 .println("CMD [-noquestionnaire] executed successfully!");
415 if (!aparser.contains("nonews"))
417 desktop.checkForNews();
420 BioJsHTMLOutput.updateBioJS();
424 String file = null, data = null;
425 FileFormatI format = null;
426 DataSourceType protocol = null;
427 FileLoader fileLoader = new FileLoader(!headless);
428 Vector<String> getFeatures = null; // vector of das source nicknames to
432 String groovyscript = null; // script to execute after all loading is
433 // completed one way or another
434 // extract groovy argument and execute if necessary
435 groovyscript = aparser.getValue("groovy", true);
436 file = aparser.getValue("open", true);
438 if (file == null && desktop == null)
440 System.out.println("No files to open!");
443 String vamsasImport = aparser.getValue("vdoc");
444 String vamsasSession = aparser.getValue("vsess");
445 if (vamsasImport != null || vamsasSession != null)
447 if (desktop == null || headless)
450 "Headless vamsas sessions not yet supported. Sorry.");
453 // if we have a file, start a new session and import it.
454 boolean inSession = false;
455 if (vamsasImport != null)
459 DataSourceType viprotocol = AppletFormatAdapter
460 .checkProtocol(vamsasImport);
461 if (viprotocol == DataSourceType.FILE)
463 inSession = desktop.vamsasImport(new File(vamsasImport));
465 else if (viprotocol == DataSourceType.URL)
467 inSession = desktop.vamsasImport(new URL(vamsasImport));
470 } catch (Exception e)
472 System.err.println("Exeption when importing " + vamsasImport
473 + " as a vamsas document.");
478 System.err.println("Failed to import " + vamsasImport
479 + " as a vamsas document.");
483 System.out.println("Imported Successfully into new session "
484 + desktop.getVamsasApplication().getCurrentSession());
487 if (vamsasSession != null)
489 if (vamsasImport != null)
491 // close the newly imported session and import the Jalview specific
492 // remnants into the new session later on.
493 desktop.vamsasStop_actionPerformed(null);
495 // now join the new session
498 if (desktop.joinVamsasSession(vamsasSession))
501 "Successfully joined vamsas session " + vamsasSession);
505 System.err.println("WARNING: Failed to join vamsas session "
508 } catch (Exception e)
511 "ERROR: Failed to join vamsas session " + vamsasSession);
514 if (vamsasImport != null)
516 // the Jalview specific remnants can now be imported into the new
517 // session at the user's leisure.
519 "Skipping Push for import of data into existing vamsas session."); // TODO:
524 // desktop.getVamsasApplication().push_update();
529 // Finally, deal with the remaining input data.
534 desktop.setProgressBar(
536 .getString("status.processing_commandline_args"),
537 progress = System.currentTimeMillis());
539 System.out.println("CMD [-open " + file + "] executed successfully!");
541 if (!isJS() && !file.startsWith("http://"))
543 if (!(new File(file)).exists())
545 System.out.println("Can't find " + file);
553 protocol = AppletFormatAdapter.checkProtocol(file);
557 format = new IdentifyFile().identify(file, protocol);
558 } catch (FileFormatException e1)
563 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
567 System.out.println("error");
571 setCurrentAlignFrame(af);
572 data = aparser.getValue("colour", true);
575 data.replaceAll("%20", " ");
577 ColourSchemeI cs = ColourSchemeProperty
578 .getColourScheme(af.getViewport().getAlignment(), data);
583 "CMD [-color " + data + "] executed successfully!");
588 // Must maintain ability to use the groups flag
589 data = aparser.getValue("groups", true);
592 af.parseFeaturesFile(data,
593 AppletFormatAdapter.checkProtocol(data));
594 // System.out.println("Added " + data);
596 "CMD groups[-" + data + "] executed successfully!");
598 data = aparser.getValue("features", true);
601 af.parseFeaturesFile(data,
602 AppletFormatAdapter.checkProtocol(data));
603 // System.out.println("Added " + data);
605 "CMD [-features " + data + "] executed successfully!");
608 data = aparser.getValue("annotations", true);
611 af.loadJalviewDataFile(data, null, null, null);
612 // System.out.println("Added " + data);
614 "CMD [-annotations " + data + "] executed successfully!");
616 // set or clear the sortbytree flag.
617 if (aparser.contains("sortbytree"))
619 af.getViewport().setSortByTree(true);
620 if (af.getViewport().getSortByTree())
622 System.out.println("CMD [-sortbytree] executed successfully!");
625 if (aparser.contains("no-annotation"))
627 af.getViewport().setShowAnnotation(false);
628 if (!af.getViewport().isShowAnnotation())
630 System.out.println("CMD no-annotation executed successfully!");
633 if (aparser.contains("nosortbytree"))
635 af.getViewport().setSortByTree(false);
636 if (!af.getViewport().getSortByTree())
639 .println("CMD [-nosortbytree] executed successfully!");
642 data = aparser.getValue("tree", true);
648 "CMD [-tree " + data + "] executed successfully!");
649 NewickFile nf = new NewickFile(data,
650 AppletFormatAdapter.checkProtocol(data));
652 .setCurrentTree(af.showNewickTree(nf, data).getTree());
653 } catch (IOException ex)
655 System.err.println("Couldn't add tree " + data);
656 ex.printStackTrace(System.err);
659 // TODO - load PDB structure(s) to alignment JAL-629
660 // (associate with identical sequence in alignment, or a specified
663 getFeatures = checkDasArguments(aparser);
664 if (af != null && getFeatures != null)
666 FeatureFetcher ff = startFeatureFetching(getFeatures);
669 while (!ff.allFinished() || af.operationInProgress())
671 // wait around until fetching is finished.
675 } catch (Exception e)
681 getFeatures = null; // have retrieved features - forget them now.
683 if (groovyscript != null)
685 // Execute the groovy script after we've done all the rendering stuff
686 // and before any images or figures are generated.
687 System.out.println("Executing script " + groovyscript);
688 executeGroovyScript(groovyscript, af);
689 System.out.println("CMD groovy[" + groovyscript
690 + "] executed successfully!");
693 String imageName = "unnamed.png";
694 while (aparser.getSize() > 1)
696 String outputFormat = aparser.nextValue();
697 file = aparser.nextValue();
699 if (outputFormat.equalsIgnoreCase("png"))
701 af.createPNG(new File(file));
702 imageName = (new File(file)).getName();
703 System.out.println("Creating PNG image: " + file);
706 else if (outputFormat.equalsIgnoreCase("svg"))
708 File imageFile = new File(file);
709 imageName = imageFile.getName();
710 af.createSVG(imageFile);
711 System.out.println("Creating SVG image: " + file);
714 else if (outputFormat.equalsIgnoreCase("html"))
716 File imageFile = new File(file);
717 imageName = imageFile.getName();
718 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
719 htmlSVG.exportHTML(file);
721 System.out.println("Creating HTML image: " + file);
724 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
728 System.err.println("The output html file must not be null");
733 BioJsHTMLOutput.refreshVersionInfo(
734 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
735 } catch (URISyntaxException e)
739 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
740 bjs.exportHTML(file);
742 .println("Creating BioJS MSA Viwer HTML file: " + file);
745 else if (outputFormat.equalsIgnoreCase("imgMap"))
747 af.createImageMap(new File(file), imageName);
748 System.out.println("Creating image map: " + file);
751 else if (outputFormat.equalsIgnoreCase("eps"))
753 File outputFile = new File(file);
755 "Creating EPS file: " + outputFile.getAbsolutePath());
756 af.createEPS(outputFile);
760 af.saveAlignment(file, format);
761 if (af.isSaveAlignmentSuccessful())
763 System.out.println("Written alignment in " + format
764 + " format to " + file);
768 System.out.println("Error writing file " + file + " in "
769 + format + " format!!");
774 while (aparser.getSize() > 0)
776 System.out.println("Unknown arg: " + aparser.nextValue());
780 AlignFrame startUpAlframe = null;
781 // We'll only open the default file if the desktop is visible.
783 // ////////////////////
785 if (/** @j2sNative false && */ // BH 2018
786 !headless && file == null && vamsasImport == null
787 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
789 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
790 jalview.bin.Cache.getDefault("www.jalview.org",
791 "http://www.jalview.org")
792 + "/examples/exampleFile_2_7.jar");
794 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
796 // hardwire upgrade of the startup file
797 file.replace("_2_3.jar", "_2_7.jar");
798 // and remove the stale setting
799 jalview.bin.Cache.removeProperty("STARTUP_FILE");
802 protocol = DataSourceType.FILE;
804 if (file.indexOf("http:") > -1)
806 protocol = DataSourceType.URL;
809 if (file.endsWith(".jar"))
811 format = FileFormat.Jalview;
817 format = new IdentifyFile().identify(file, protocol);
818 } catch (FileFormatException e)
824 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
826 getFeatures = checkDasArguments(aparser);
827 // extract groovy arguments before anything else.
829 // If the user has specified features to be retrieved,
830 // or a groovy script to be executed, do them if they
831 // haven't been done already
832 // fetch features for the default alignment
833 if (getFeatures != null)
835 if (startUpAlframe != null)
837 startFeatureFetching(getFeatures);
840 // Once all other stuff is done, execute any groovy scripts (in order)
841 if (groovyscript != null)
843 if (Cache.groovyJarsPresent())
845 System.out.println("Executing script " + groovyscript);
846 executeGroovyScript(groovyscript, startUpAlframe);
851 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
855 // and finally, turn off batch mode indicator - if the desktop still exists
860 desktop.setProgressBar(null, progress);
862 desktop.setInBatchMode(false);
866 private static void showUsage()
869 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
870 + "-nodisplay\tRun Jalview without User Interface.\n"
871 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
872 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
873 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
874 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
875 + "-features FILE\tUse the given file to mark features on the alignment.\n"
876 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
877 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
878 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
879 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
880 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
881 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
882 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
883 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
884 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
885 + "-png FILE\tCreate PNG image FILE from alignment.\n"
886 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
887 + "-html FILE\tCreate HTML file from alignment.\n"
888 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
889 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
890 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
891 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
892 + "-noquestionnaire\tTurn off questionnaire check.\n"
893 + "-nonews\tTurn off check for Jalview news.\n"
894 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
895 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
897 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
898 // after all other properties files have been read\n\t
899 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
900 // passed in correctly)"
901 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
902 + "-dasserver nickname=URL\tAdd and enable a das server with given nickname\n\t\t\t(alphanumeric or underscores only) for retrieval of features for all alignments.\n"
903 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
904 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
905 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
907 // "-vdoc vamsas-document\tImport vamsas document into new
908 // session or join existing session with same URN\n"
909 // + "-vses vamsas-session\tJoin session with given URN\n"
910 + "-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"
911 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
914 private static void startUsageStats(final Desktop desktop)
917 * start a User Config prompt asking if we can log usage statistics.
919 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
920 "USAGESTATS", "Jalview Usage Statistics",
921 "Do you want to help make Jalview better by enabling "
922 + "the collection of usage statistics with Google Analytics ?"
923 + "\n\n(you can enable or disable usage tracking in the preferences)",
930 "Initialising googletracker for usage stats.");
931 Cache.initGoogleTracker();
932 Cache.log.debug("Tracking enabled.");
939 Cache.log.debug("Not enabling Google Tracking.");
942 desktop.addDialogThread(prompter);
946 * Locate the given string as a file and pass it to the groovy interpreter.
948 * @param groovyscript
949 * the script to execute
950 * @param jalviewContext
951 * the Jalview Desktop object passed in to the groovy binding as the
954 private void executeGroovyScript(String groovyscript, AlignFrame af)
957 * for scripts contained in files
964 if (groovyscript.trim().equals("STDIN"))
966 // read from stdin into a tempfile and execute it
969 tfile = File.createTempFile("jalview", "groovy");
970 PrintWriter outfile = new PrintWriter(
971 new OutputStreamWriter(new FileOutputStream(tfile)));
972 BufferedReader br = new BufferedReader(
973 new InputStreamReader(System.in));
975 while ((line = br.readLine()) != null)
977 outfile.write(line + "\n");
983 } catch (Exception ex)
985 System.err.println("Failed to read from STDIN into tempfile "
986 + ((tfile == null) ? "(tempfile wasn't created)"
987 : tfile.toString()));
988 ex.printStackTrace();
993 sfile = tfile.toURI().toURL();
994 } catch (Exception x)
997 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1007 sfile = new URI(groovyscript).toURL();
1008 } catch (Exception x)
1010 tfile = new File(groovyscript);
1011 if (!tfile.exists())
1013 System.err.println("File '" + groovyscript + "' does not exist.");
1016 if (!tfile.canRead())
1018 System.err.println("File '" + groovyscript + "' cannot be read.");
1021 if (tfile.length() < 1)
1023 System.err.println("File '" + groovyscript + "' is empty.");
1028 sfile = tfile.getAbsoluteFile().toURI().toURL();
1029 } catch (Exception ex)
1031 System.err.println("Failed to create a file URL for "
1032 + tfile.getAbsoluteFile());
1039 Map<String, Object> vbinding = new HashMap<>();
1040 vbinding.put("Jalview", this);
1043 vbinding.put("currentAlFrame", af);
1045 Binding gbinding = new Binding(vbinding);
1046 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1047 gse.run(sfile.toString(), gbinding);
1048 if ("STDIN".equals(groovyscript))
1050 // delete temp file that we made -
1051 // only if it was successfully executed
1054 } catch (Exception e)
1056 System.err.println("Exception Whilst trying to execute file " + sfile
1057 + " as a groovy script.");
1058 e.printStackTrace(System.err);
1064 * Check commandline for any das server definitions or any fetchfrom switches
1066 * @return vector of DAS source nicknames to retrieve from
1068 private static Vector<String> checkDasArguments(ArgsParser aparser)
1070 Vector<String> source = null;
1072 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
1073 while ((data = aparser.getValue("dasserver", true)) != null)
1075 String nickname = null;
1077 int pos = data.indexOf('=');
1078 // determine capabilities
1081 nickname = data.substring(0, pos);
1083 url = data.substring(pos + 1);
1084 if (url != null && (url.startsWith("http:")
1085 || url.startsWith("sequence:http:")))
1087 if (nickname == null)
1091 if (locsources == null)
1099 locsources = locsources + nickname + "|" + url;
1101 "NOTE! dasserver parameter not yet really supported (got args of "
1102 + nickname + "|" + url);
1105 source = new Vector<>();
1107 source.addElement(nickname);
1110 "CMD [-dasserver " + data + "] executed successfully!");
1111 } // loop until no more server entries are found.
1112 if (locsources != null && locsources.indexOf('|') > -1)
1114 Cache.log.debug("Setting local source list in properties file to:\n"
1116 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
1118 while ((data = aparser.getValue("fetchfrom", true)) != null)
1120 System.out.println("adding source '" + data + "'");
1123 source = new Vector<>();
1125 source.addElement(data);
1131 * start a feature fetcher for every alignment frame
1135 private FeatureFetcher startFeatureFetching(
1136 final Vector<String> dasSources)
1138 FeatureFetcher ff = new FeatureFetcher();
1139 AlignFrame afs[] = Desktop.getAlignFrames();
1140 if (afs == null || afs.length == 0)
1144 for (int i = 0; i < afs.length; i++)
1146 ff.addFetcher(afs[i], dasSources);
1151 public static boolean isHeadlessMode()
1153 String isheadless = System.getProperty("java.awt.headless");
1154 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1161 public AlignFrame[] getAlignFrames()
1163 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1164 : Desktop.getAlignFrames();
1169 * Quit method delegates to Desktop.quit - unless running in headless mode
1170 * when it just ends the JVM
1174 if (desktop != null)
1184 public static AlignFrame getCurrentAlignFrame()
1186 return Jalview.currentAlignFrame;
1189 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1191 Jalview.currentAlignFrame = currentAlignFrame;