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 -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
76 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
77 * jalview.bin.Jalview jalview.bin.Jalview
79 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
80 * embellish '*' to e.g. '*.jar')
88 * singleton instance of this class
90 private static Jalview instance;
92 private Desktop desktop;
94 public static AlignFrame currentAlignFrame;
98 // grab all the rights we can the JVM
99 Policy.setPolicy(new Policy()
102 public PermissionCollection getPermissions(CodeSource codesource)
104 Permissions perms = new Permissions();
105 perms.add(new AllPermission());
110 public void refresh()
117 * keep track of feature fetching tasks.
125 * TODO: generalise to track all jalview events to orchestrate batch
129 private int queued = 0;
131 private int running = 0;
133 public FeatureFetcher()
138 public void addFetcher(final AlignFrame af,
139 final Vector<String> dasSources)
141 final long id = System.currentTimeMillis();
143 final FeatureFetcher us = this;
144 new Thread(new Runnable()
156 af.setProgressBar(MessageManager
157 .getString("status.das_features_being_retrived"), id);
158 af.featureSettings_actionPerformed(null);
159 af.setProgressBar(null, id);
168 public synchronized boolean allFinished()
170 return queued == 0 && running == 0;
175 public static Jalview getInstance()
181 * main class for Jalview application
184 * open <em>filename</em>
186 public static void main(String[] args)
188 instance = new Jalview();
189 instance.doMain(args);
195 void doMain(String[] args)
197 System.setSecurityManager(null);
199 .println("Java version: " + System.getProperty("java.version"));
200 System.out.println(System.getProperty("os.arch") + " "
201 + System.getProperty("os.name") + " "
202 + System.getProperty("os.version"));
204 ArgsParser aparser = new ArgsParser(args);
205 boolean headless = false;
207 if (aparser.contains("help") || aparser.contains("h"))
212 if (aparser.contains("nodisplay") || aparser.contains("nogui")
213 || aparser.contains("headless"))
215 System.setProperty("java.awt.headless", "true");
218 String usrPropsFile = aparser.getValue("props");
219 Cache.loadProperties(usrPropsFile); // must do this before
220 if (usrPropsFile != null)
223 "CMD [-props " + usrPropsFile + "] executed successfully!");
228 final String jabawsUrl = aparser.getValue("jabaws");
229 if (jabawsUrl != null)
233 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
235 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
236 } catch (MalformedURLException e)
239 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
243 String defs = aparser.getValue("setprop");
246 int p = defs.indexOf('=');
249 System.err.println("Ignoring invalid setprop argument : " + defs);
253 System.out.println("Executing setprop argument: " + defs);
254 // DISABLED FOR SECURITY REASONS
255 // TODO: add a property to allow properties to be overriden by cli args
256 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
258 defs = aparser.getValue("setprop");
260 if (System.getProperty("java.awt.headless") != null
261 && System.getProperty("java.awt.headless").equals("true"))
265 System.setProperty("http.agent",
266 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
270 } catch (NoClassDefFoundError error)
272 error.printStackTrace();
273 System.out.println("\nEssential logging libraries not found."
274 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
282 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
283 } catch (Exception ex)
285 System.err.println("Unexpected Look and Feel Exception");
286 ex.printStackTrace();
288 if (Platform.isAMac())
291 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
293 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
295 System.setProperty("apple.laf.useScreenMenuBar", "true");
296 if (lookAndFeel != null)
300 UIManager.setLookAndFeel(lookAndFeel);
301 } catch (Throwable e)
304 "Failed to set QuaQua look and feel: " + e.toString());
307 if (lookAndFeel == null || !(lookAndFeel.getClass()
308 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
309 || !UIManager.getLookAndFeel().getClass().toString()
310 .toLowerCase().contains("quaqua"))
315 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
316 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
317 } catch (Throwable e)
320 "Failed to reset look and feel: " + e.toString());
326 * configure 'full' SO model if preferences say to,
327 * else use the default (SO Lite)
329 if (Cache.getDefault("USE_FULL_SO", true))
331 SequenceOntologyFactory.setInstance(new SequenceOntology());
336 desktop = new Desktop();
337 desktop.setInBatchMode(true); // indicate we are starting up
338 desktop.setVisible(true);
339 desktop.startServiceDiscovery();
340 if (!aparser.contains("nousagestats"))
342 startUsageStats(desktop);
346 System.err.println("CMD [-nousagestats] executed successfully!");
349 if (!aparser.contains("noquestionnaire"))
351 String url = aparser.getValue("questionnaire");
354 // Start the desktop questionnaire prompter with the specified
356 Cache.log.debug("Starting questionnaire url at " + url);
357 desktop.checkForQuestionnaire(url);
359 "CMD questionnaire[-" + url + "] executed successfully!");
363 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
365 // Start the desktop questionnaire prompter with the specified
368 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
370 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
372 "Starting questionnaire with default url: " + defurl);
373 desktop.checkForQuestionnaire(defurl);
379 System.err.println("CMD [-noquestionnaire] executed successfully!");
382 if (!aparser.contains("nonews"))
384 desktop.checkForNews();
387 BioJsHTMLOutput.updateBioJS();
390 String file = null, data = null;
391 FileFormatI format = null;
392 DataSourceType protocol = null;
393 FileLoader fileLoader = new FileLoader(!headless);
394 Vector<String> getFeatures = null; // vector of das source nicknames to
398 String groovyscript = null; // script to execute after all loading is
399 // completed one way or another
400 // extract groovy argument and execute if necessary
401 groovyscript = aparser.getValue("groovy", true);
402 file = aparser.getValue("open", true);
404 if (file == null && desktop == null)
406 System.out.println("No files to open!");
409 String vamsasImport = aparser.getValue("vdoc");
410 String vamsasSession = aparser.getValue("vsess");
411 if (vamsasImport != null || vamsasSession != null)
413 if (desktop == null || headless)
416 "Headless vamsas sessions not yet supported. Sorry.");
419 // if we have a file, start a new session and import it.
420 boolean inSession = false;
421 if (vamsasImport != null)
425 DataSourceType viprotocol = AppletFormatAdapter
426 .checkProtocol(vamsasImport);
427 if (viprotocol == DataSourceType.FILE)
429 inSession = desktop.vamsasImport(new File(vamsasImport));
431 else if (viprotocol == DataSourceType.URL)
433 inSession = desktop.vamsasImport(new URL(vamsasImport));
436 } catch (Exception e)
438 System.err.println("Exeption when importing " + vamsasImport
439 + " as a vamsas document.");
444 System.err.println("Failed to import " + vamsasImport
445 + " as a vamsas document.");
449 System.out.println("Imported Successfully into new session "
450 + desktop.getVamsasApplication().getCurrentSession());
453 if (vamsasSession != null)
455 if (vamsasImport != null)
457 // close the newly imported session and import the Jalview specific
458 // remnants into the new session later on.
459 desktop.vamsasStop_actionPerformed(null);
461 // now join the new session
464 if (desktop.joinVamsasSession(vamsasSession))
467 "Successfully joined vamsas session " + vamsasSession);
471 System.err.println("WARNING: Failed to join vamsas session "
474 } catch (Exception e)
477 "ERROR: Failed to join vamsas session " + vamsasSession);
480 if (vamsasImport != null)
482 // the Jalview specific remnants can now be imported into the new
483 // session at the user's leisure.
485 "Skipping Push for import of data into existing vamsas session."); // TODO:
490 // desktop.getVamsasApplication().push_update();
495 // Finally, deal with the remaining input data.
500 desktop.setProgressBar(
502 .getString("status.processing_commandline_args"),
503 progress = System.currentTimeMillis());
505 System.out.println("CMD [-open " + file + "] executed successfully!");
507 if (!file.startsWith("http://"))
509 if (!(new File(file)).exists())
511 System.out.println("Can't find " + file);
519 protocol = AppletFormatAdapter.checkProtocol(file);
523 format = new IdentifyFile().identify(file, protocol);
524 } catch (FileFormatException e1)
529 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
533 System.out.println("error");
537 setCurrentAlignFrame(af);
538 data = aparser.getValue("colour", true);
541 data.replaceAll("%20", " ");
543 ColourSchemeI cs = ColourSchemeProperty
544 .getColourScheme(af.getViewport().getAlignment(), data);
549 "CMD [-color " + data + "] executed successfully!");
554 // Must maintain ability to use the groups flag
555 data = aparser.getValue("groups", true);
558 af.parseFeaturesFile(data,
559 AppletFormatAdapter.checkProtocol(data));
560 // System.out.println("Added " + data);
562 "CMD groups[-" + data + "] executed successfully!");
564 data = aparser.getValue("features", true);
567 af.parseFeaturesFile(data,
568 AppletFormatAdapter.checkProtocol(data));
569 // System.out.println("Added " + data);
571 "CMD [-features " + data + "] executed successfully!");
574 data = aparser.getValue("annotations", true);
577 af.loadJalviewDataFile(data, null, null, null);
578 // System.out.println("Added " + data);
580 "CMD [-annotations " + data + "] executed successfully!");
582 // set or clear the sortbytree flag.
583 if (aparser.contains("sortbytree"))
585 af.getViewport().setSortByTree(true);
586 if (af.getViewport().getSortByTree())
588 System.out.println("CMD [-sortbytree] executed successfully!");
591 if (aparser.contains("no-annotation"))
593 af.getViewport().setShowAnnotation(false);
594 if (!af.getViewport().isShowAnnotation())
596 System.out.println("CMD no-annotation executed successfully!");
599 if (aparser.contains("nosortbytree"))
601 af.getViewport().setSortByTree(false);
602 if (!af.getViewport().getSortByTree())
605 .println("CMD [-nosortbytree] executed successfully!");
608 data = aparser.getValue("tree", true);
614 "CMD [-tree " + data + "] executed successfully!");
615 NewickFile nf = new NewickFile(data,
616 AppletFormatAdapter.checkProtocol(data));
618 .setCurrentTree(af.showNewickTree(nf, data).getTree());
619 } catch (IOException ex)
621 System.err.println("Couldn't add tree " + data);
622 ex.printStackTrace(System.err);
625 // TODO - load PDB structure(s) to alignment JAL-629
626 // (associate with identical sequence in alignment, or a specified
629 getFeatures = checkDasArguments(aparser);
630 if (af != null && getFeatures != null)
632 FeatureFetcher ff = startFeatureFetching(getFeatures);
635 while (!ff.allFinished() || af.operationInProgress())
637 // wait around until fetching is finished.
641 } catch (Exception e)
647 getFeatures = null; // have retrieved features - forget them now.
649 if (groovyscript != null)
651 // Execute the groovy script after we've done all the rendering stuff
652 // and before any images or figures are generated.
653 System.out.println("Executing script " + groovyscript);
654 executeGroovyScript(groovyscript, af);
655 System.out.println("CMD groovy[" + groovyscript
656 + "] executed successfully!");
659 String imageName = "unnamed.png";
660 while (aparser.getSize() > 1)
662 String outputFormat = aparser.nextValue();
663 file = aparser.nextValue();
665 if (outputFormat.equalsIgnoreCase("png"))
667 af.createPNG(new File(file));
668 imageName = (new File(file)).getName();
669 System.out.println("Creating PNG image: " + file);
672 else if (outputFormat.equalsIgnoreCase("svg"))
674 File imageFile = new File(file);
675 imageName = imageFile.getName();
676 af.createSVG(imageFile);
677 System.out.println("Creating SVG image: " + file);
680 else if (outputFormat.equalsIgnoreCase("html"))
682 File imageFile = new File(file);
683 imageName = imageFile.getName();
684 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
685 htmlSVG.exportHTML(file);
687 System.out.println("Creating HTML image: " + file);
690 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
694 System.err.println("The output html file must not be null");
699 BioJsHTMLOutput.refreshVersionInfo(
700 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
701 } catch (URISyntaxException e)
705 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
706 bjs.exportHTML(file);
708 .println("Creating BioJS MSA Viwer HTML file: " + file);
711 else if (outputFormat.equalsIgnoreCase("imgMap"))
713 af.createImageMap(new File(file), imageName);
714 System.out.println("Creating image map: " + file);
717 else if (outputFormat.equalsIgnoreCase("eps"))
719 File outputFile = new File(file);
721 "Creating EPS file: " + outputFile.getAbsolutePath());
722 af.createEPS(outputFile);
726 if (af.saveAlignment(file, format))
728 System.out.println("Written alignment in " + format
729 + " format to " + file);
733 System.out.println("Error writing file " + file + " in "
734 + format + " format!!");
739 while (aparser.getSize() > 0)
741 System.out.println("Unknown arg: " + aparser.nextValue());
745 AlignFrame startUpAlframe = null;
746 // We'll only open the default file if the desktop is visible.
748 // ////////////////////
750 if (!headless && file == null && vamsasImport == null
751 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
753 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
754 jalview.bin.Cache.getDefault("www.jalview.org",
755 "http://www.jalview.org")
756 + "/examples/exampleFile_2_7.jar");
758 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
760 // hardwire upgrade of the startup file
761 file.replace("_2_3.jar", "_2_7.jar");
762 // and remove the stale setting
763 jalview.bin.Cache.removeProperty("STARTUP_FILE");
766 protocol = DataSourceType.FILE;
768 if (file.indexOf("http:") > -1)
770 protocol = DataSourceType.URL;
773 if (file.endsWith(".jar"))
775 format = FileFormat.Jalview;
781 format = new IdentifyFile().identify(file, protocol);
782 } catch (FileFormatException e)
788 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
790 getFeatures = checkDasArguments(aparser);
791 // extract groovy arguments before anything else.
793 // If the user has specified features to be retrieved,
794 // or a groovy script to be executed, do them if they
795 // haven't been done already
796 // fetch features for the default alignment
797 if (getFeatures != null)
799 if (startUpAlframe != null)
801 startFeatureFetching(getFeatures);
804 // Once all other stuff is done, execute any groovy scripts (in order)
805 if (groovyscript != null)
807 if (Cache.groovyJarsPresent())
809 System.out.println("Executing script " + groovyscript);
810 executeGroovyScript(groovyscript, startUpAlframe);
815 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
819 // and finally, turn off batch mode indicator - if the desktop still exists
824 desktop.setProgressBar(null, progress);
826 desktop.setInBatchMode(false);
830 private static void showUsage()
833 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
834 + "-nodisplay\tRun Jalview without User Interface.\n"
835 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
836 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
837 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
838 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
839 + "-features FILE\tUse the given file to mark features on the alignment.\n"
840 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
841 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
842 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
843 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
844 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
845 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
846 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
847 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
848 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
849 + "-png FILE\tCreate PNG image FILE from alignment.\n"
850 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
851 + "-html FILE\tCreate HTML file from alignment.\n"
852 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
853 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
854 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
855 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
856 + "-noquestionnaire\tTurn off questionnaire check.\n"
857 + "-nonews\tTurn off check for Jalview news.\n"
858 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
859 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
861 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
862 // after all other properties files have been read\n\t
863 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
864 // passed in correctly)"
865 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
866 + "-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"
867 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
868 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
869 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
871 // "-vdoc vamsas-document\tImport vamsas document into new
872 // session or join existing session with same URN\n"
873 // + "-vses vamsas-session\tJoin session with given URN\n"
874 + "-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"
875 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
878 private static void startUsageStats(final Desktop desktop)
881 * start a User Config prompt asking if we can log usage statistics.
883 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
884 "USAGESTATS", "Jalview Usage Statistics",
885 "Do you want to help make Jalview better by enabling "
886 + "the collection of usage statistics with Google Analytics ?"
887 + "\n\n(you can enable or disable usage tracking in the preferences)",
894 "Initialising googletracker for usage stats.");
895 Cache.initGoogleTracker();
896 Cache.log.debug("Tracking enabled.");
903 Cache.log.debug("Not enabling Google Tracking.");
906 desktop.addDialogThread(prompter);
910 * Locate the given string as a file and pass it to the groovy interpreter.
912 * @param groovyscript
913 * the script to execute
914 * @param jalviewContext
915 * the Jalview Desktop object passed in to the groovy binding as the
918 private void executeGroovyScript(String groovyscript, AlignFrame af)
921 * for scripts contained in files
928 if (groovyscript.trim().equals("STDIN"))
930 // read from stdin into a tempfile and execute it
933 tfile = File.createTempFile("jalview", "groovy");
934 PrintWriter outfile = new PrintWriter(
935 new OutputStreamWriter(new FileOutputStream(tfile)));
936 BufferedReader br = new BufferedReader(
937 new InputStreamReader(System.in));
939 while ((line = br.readLine()) != null)
941 outfile.write(line + "\n");
947 } catch (Exception ex)
949 System.err.println("Failed to read from STDIN into tempfile "
950 + ((tfile == null) ? "(tempfile wasn't created)"
951 : tfile.toString()));
952 ex.printStackTrace();
957 sfile = tfile.toURI().toURL();
958 } catch (Exception x)
961 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
971 sfile = new URI(groovyscript).toURL();
972 } catch (Exception x)
974 tfile = new File(groovyscript);
977 System.err.println("File '" + groovyscript + "' does not exist.");
980 if (!tfile.canRead())
982 System.err.println("File '" + groovyscript + "' cannot be read.");
985 if (tfile.length() < 1)
987 System.err.println("File '" + groovyscript + "' is empty.");
992 sfile = tfile.getAbsoluteFile().toURI().toURL();
993 } catch (Exception ex)
995 System.err.println("Failed to create a file URL for "
996 + tfile.getAbsoluteFile());
1003 Map<String, Object> vbinding = new HashMap<>();
1004 vbinding.put("Jalview", this);
1007 vbinding.put("currentAlFrame", af);
1009 Binding gbinding = new Binding(vbinding);
1010 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1011 gse.run(sfile.toString(), gbinding);
1012 if ("STDIN".equals(groovyscript))
1014 // delete temp file that we made -
1015 // only if it was successfully executed
1018 } catch (Exception e)
1020 System.err.println("Exception Whilst trying to execute file " + sfile
1021 + " as a groovy script.");
1022 e.printStackTrace(System.err);
1028 * Check commandline for any das server definitions or any fetchfrom switches
1030 * @return vector of DAS source nicknames to retrieve from
1032 private static Vector<String> checkDasArguments(ArgsParser aparser)
1034 Vector<String> source = null;
1036 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
1037 while ((data = aparser.getValue("dasserver", true)) != null)
1039 String nickname = null;
1041 int pos = data.indexOf('=');
1042 // determine capabilities
1045 nickname = data.substring(0, pos);
1047 url = data.substring(pos + 1);
1048 if (url != null && (url.startsWith("http:")
1049 || url.startsWith("sequence:http:")))
1051 if (nickname == null)
1055 if (locsources == null)
1063 locsources = locsources + nickname + "|" + url;
1065 "NOTE! dasserver parameter not yet really supported (got args of "
1066 + nickname + "|" + url);
1069 source = new Vector<>();
1071 source.addElement(nickname);
1074 "CMD [-dasserver " + data + "] executed successfully!");
1075 } // loop until no more server entries are found.
1076 if (locsources != null && locsources.indexOf('|') > -1)
1078 Cache.log.debug("Setting local source list in properties file to:\n"
1080 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
1082 while ((data = aparser.getValue("fetchfrom", true)) != null)
1084 System.out.println("adding source '" + data + "'");
1087 source = new Vector<>();
1089 source.addElement(data);
1095 * start a feature fetcher for every alignment frame
1099 private FeatureFetcher startFeatureFetching(
1100 final Vector<String> dasSources)
1102 FeatureFetcher ff = new FeatureFetcher();
1103 AlignFrame afs[] = Desktop.getAlignFrames();
1104 if (afs == null || afs.length == 0)
1108 for (int i = 0; i < afs.length; i++)
1110 ff.addFetcher(afs[i], dasSources);
1115 public static boolean isHeadlessMode()
1117 String isheadless = System.getProperty("java.awt.headless");
1118 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1125 public AlignFrame[] getAlignFrames()
1127 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1128 : Desktop.getAlignFrames();
1133 * Quit method delegates to Desktop.quit - unless running in headless mode
1134 * when it just ends the JVM
1138 if (desktop != null)
1148 public static AlignFrame getCurrentAlignFrame()
1150 return Jalview.currentAlignFrame;
1153 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1155 Jalview.currentAlignFrame = currentAlignFrame;