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 float ONE_MB = 1048576f;
189 Runtime runtime = Runtime.getRuntime();
190 float maxMemory = runtime.maxMemory() / ONE_MB;
191 if (maxMemory < 1024 * 15)
198 instance = new Jalview();
200 instance.doMain(args);
206 void doMain(String[] args)
208 System.setSecurityManager(null);
210 .println("Java version: " + System.getProperty("java.version"));
211 System.out.println(System.getProperty("os.arch") + " "
212 + System.getProperty("os.name") + " "
213 + System.getProperty("os.version"));
215 ArgsParser aparser = new ArgsParser(args);
216 boolean headless = false;
218 if (aparser.contains("help") || aparser.contains("h"))
223 if (aparser.contains("nodisplay") || aparser.contains("nogui")
224 || aparser.contains("headless"))
226 System.setProperty("java.awt.headless", "true");
229 String usrPropsFile = aparser.getValue("props");
230 Cache.loadProperties(usrPropsFile); // must do this before
231 if (usrPropsFile != null)
234 "CMD [-props " + usrPropsFile + "] executed successfully!");
239 final String jabawsUrl = aparser.getValue("jabaws");
240 if (jabawsUrl != null)
244 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
246 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
247 } catch (MalformedURLException e)
250 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
254 String defs = aparser.getValue("setprop");
257 int p = defs.indexOf('=');
260 System.err.println("Ignoring invalid setprop argument : " + defs);
264 System.out.println("Executing setprop argument: " + defs);
265 // DISABLED FOR SECURITY REASONS
266 // TODO: add a property to allow properties to be overriden by cli args
267 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
269 defs = aparser.getValue("setprop");
271 if (System.getProperty("java.awt.headless") != null
272 && System.getProperty("java.awt.headless").equals("true"))
276 System.setProperty("http.agent",
277 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
281 } catch (NoClassDefFoundError error)
283 error.printStackTrace();
284 System.out.println("\nEssential logging libraries not found."
285 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
293 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
294 } catch (Exception ex)
296 System.err.println("Unexpected Look and Feel Exception");
297 ex.printStackTrace();
299 if (Platform.isAMac())
302 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
304 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
306 System.setProperty("apple.laf.useScreenMenuBar", "true");
307 if (lookAndFeel != null)
311 UIManager.setLookAndFeel(lookAndFeel);
312 } catch (Throwable e)
315 "Failed to set QuaQua look and feel: " + e.toString());
318 if (lookAndFeel == null || !(lookAndFeel.getClass()
319 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
320 || !UIManager.getLookAndFeel().getClass().toString()
321 .toLowerCase().contains("quaqua"))
326 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
327 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
328 } catch (Throwable e)
331 "Failed to reset look and feel: " + e.toString());
337 * configure 'full' SO model if preferences say to,
338 * else use the default (SO Lite)
340 if (Cache.getDefault("USE_FULL_SO", false))
342 SequenceOntologyFactory.setInstance(new SequenceOntology());
347 desktop = new Desktop();
348 desktop.setInBatchMode(true); // indicate we are starting up
349 desktop.setVisible(true);
350 desktop.startServiceDiscovery();
351 if (!aparser.contains("nousagestats"))
353 startUsageStats(desktop);
357 System.err.println("CMD [-nousagestats] executed successfully!");
360 if (!aparser.contains("noquestionnaire"))
362 String url = aparser.getValue("questionnaire");
365 // Start the desktop questionnaire prompter with the specified
367 Cache.log.debug("Starting questionnaire url at " + url);
368 desktop.checkForQuestionnaire(url);
370 "CMD questionnaire[-" + url + "] executed successfully!");
374 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
376 // Start the desktop questionnaire prompter with the specified
379 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
381 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
383 "Starting questionnaire with default url: " + defurl);
384 desktop.checkForQuestionnaire(defurl);
390 System.err.println("CMD [-noquestionnaire] executed successfully!");
393 if (!aparser.contains("nonews"))
395 desktop.checkForNews();
398 BioJsHTMLOutput.updateBioJS();
401 String file = null, data = null;
402 FileFormatI format = null;
403 DataSourceType protocol = null;
404 FileLoader fileLoader = new FileLoader(!headless);
405 Vector<String> getFeatures = null; // vector of das source nicknames to
409 String groovyscript = null; // script to execute after all loading is
410 // completed one way or another
411 // extract groovy argument and execute if necessary
412 groovyscript = aparser.getValue("groovy", true);
413 file = aparser.getValue("open", true);
415 if (file == null && desktop == null)
417 System.out.println("No files to open!");
420 String vamsasImport = aparser.getValue("vdoc");
421 String vamsasSession = aparser.getValue("vsess");
422 if (vamsasImport != null || vamsasSession != null)
424 if (desktop == null || headless)
427 "Headless vamsas sessions not yet supported. Sorry.");
430 // if we have a file, start a new session and import it.
431 boolean inSession = false;
432 if (vamsasImport != null)
436 DataSourceType viprotocol = AppletFormatAdapter
437 .checkProtocol(vamsasImport);
438 if (viprotocol == DataSourceType.FILE)
440 inSession = desktop.vamsasImport(new File(vamsasImport));
442 else if (viprotocol == DataSourceType.URL)
444 inSession = desktop.vamsasImport(new URL(vamsasImport));
447 } catch (Exception e)
449 System.err.println("Exeption when importing " + vamsasImport
450 + " as a vamsas document.");
455 System.err.println("Failed to import " + vamsasImport
456 + " as a vamsas document.");
460 System.out.println("Imported Successfully into new session "
461 + desktop.getVamsasApplication().getCurrentSession());
464 if (vamsasSession != null)
466 if (vamsasImport != null)
468 // close the newly imported session and import the Jalview specific
469 // remnants into the new session later on.
470 desktop.vamsasStop_actionPerformed(null);
472 // now join the new session
475 if (desktop.joinVamsasSession(vamsasSession))
478 "Successfully joined vamsas session " + vamsasSession);
482 System.err.println("WARNING: Failed to join vamsas session "
485 } catch (Exception e)
488 "ERROR: Failed to join vamsas session " + vamsasSession);
491 if (vamsasImport != null)
493 // the Jalview specific remnants can now be imported into the new
494 // session at the user's leisure.
496 "Skipping Push for import of data into existing vamsas session."); // TODO:
501 // desktop.getVamsasApplication().push_update();
506 // Finally, deal with the remaining input data.
511 desktop.setProgressBar(
513 .getString("status.processing_commandline_args"),
514 progress = System.currentTimeMillis());
516 System.out.println("CMD [-open " + file + "] executed successfully!");
518 if (!file.startsWith("http://"))
520 if (!(new File(file)).exists())
522 System.out.println("Can't find " + file);
530 protocol = AppletFormatAdapter.checkProtocol(file);
534 format = new IdentifyFile().identify(file, protocol);
535 } catch (FileFormatException e1)
540 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
544 System.out.println("error");
548 setCurrentAlignFrame(af);
549 data = aparser.getValue("colour", true);
552 data.replaceAll("%20", " ");
554 ColourSchemeI cs = ColourSchemeProperty
555 .getColourScheme(af.getViewport().getAlignment(), data);
560 "CMD [-color " + data + "] executed successfully!");
565 // Must maintain ability to use the groups flag
566 data = aparser.getValue("groups", true);
569 af.parseFeaturesFile(data,
570 AppletFormatAdapter.checkProtocol(data));
571 // System.out.println("Added " + data);
573 "CMD groups[-" + data + "] executed successfully!");
575 data = aparser.getValue("features", true);
578 af.parseFeaturesFile(data,
579 AppletFormatAdapter.checkProtocol(data));
580 // System.out.println("Added " + data);
582 "CMD [-features " + data + "] executed successfully!");
585 data = aparser.getValue("annotations", true);
588 af.loadJalviewDataFile(data, null, null, null);
589 // System.out.println("Added " + data);
591 "CMD [-annotations " + data + "] executed successfully!");
593 // set or clear the sortbytree flag.
594 if (aparser.contains("sortbytree"))
596 af.getViewport().setSortByTree(true);
597 if (af.getViewport().getSortByTree())
599 System.out.println("CMD [-sortbytree] executed successfully!");
602 if (aparser.contains("no-annotation"))
604 af.getViewport().setShowAnnotation(false);
605 if (!af.getViewport().isShowAnnotation())
607 System.out.println("CMD no-annotation executed successfully!");
610 if (aparser.contains("nosortbytree"))
612 af.getViewport().setSortByTree(false);
613 if (!af.getViewport().getSortByTree())
616 .println("CMD [-nosortbytree] executed successfully!");
619 data = aparser.getValue("tree", true);
625 "CMD [-tree " + data + "] executed successfully!");
626 NewickFile nf = new NewickFile(data,
627 AppletFormatAdapter.checkProtocol(data));
629 .setCurrentTree(af.showNewickTree(nf, data).getTree());
630 } catch (IOException ex)
632 System.err.println("Couldn't add tree " + data);
633 ex.printStackTrace(System.err);
636 // TODO - load PDB structure(s) to alignment JAL-629
637 // (associate with identical sequence in alignment, or a specified
640 getFeatures = checkDasArguments(aparser);
641 if (af != null && getFeatures != null)
643 FeatureFetcher ff = startFeatureFetching(getFeatures);
646 while (!ff.allFinished() || af.operationInProgress())
648 // wait around until fetching is finished.
652 } catch (Exception e)
658 getFeatures = null; // have retrieved features - forget them now.
660 if (groovyscript != null)
662 // Execute the groovy script after we've done all the rendering stuff
663 // and before any images or figures are generated.
664 System.out.println("Executing script " + groovyscript);
665 executeGroovyScript(groovyscript, af);
666 System.out.println("CMD groovy[" + groovyscript
667 + "] executed successfully!");
670 String imageName = "unnamed.png";
671 while (aparser.getSize() > 1)
673 String outputFormat = aparser.nextValue();
674 file = aparser.nextValue();
676 if (outputFormat.equalsIgnoreCase("png"))
678 af.createPNG(new File(file));
679 imageName = (new File(file)).getName();
680 System.out.println("Creating PNG image: " + file);
683 else if (outputFormat.equalsIgnoreCase("svg"))
685 File imageFile = new File(file);
686 imageName = imageFile.getName();
687 af.createSVG(imageFile);
688 System.out.println("Creating SVG image: " + file);
691 else if (outputFormat.equalsIgnoreCase("html"))
693 File imageFile = new File(file);
694 imageName = imageFile.getName();
695 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
696 htmlSVG.exportHTML(file);
698 System.out.println("Creating HTML image: " + file);
701 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
705 System.err.println("The output html file must not be null");
710 BioJsHTMLOutput.refreshVersionInfo(
711 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
712 } catch (URISyntaxException e)
716 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
717 bjs.exportHTML(file);
719 .println("Creating BioJS MSA Viwer HTML file: " + file);
722 else if (outputFormat.equalsIgnoreCase("imgMap"))
724 af.createImageMap(new File(file), imageName);
725 System.out.println("Creating image map: " + file);
728 else if (outputFormat.equalsIgnoreCase("eps"))
730 File outputFile = new File(file);
732 "Creating EPS file: " + outputFile.getAbsolutePath());
733 af.createEPS(outputFile);
737 if (af.saveAlignment(file, format))
739 System.out.println("Written alignment in " + format
740 + " format to " + file);
744 System.out.println("Error writing file " + file + " in "
745 + format + " format!!");
750 while (aparser.getSize() > 0)
752 System.out.println("Unknown arg: " + aparser.nextValue());
756 AlignFrame startUpAlframe = null;
757 // We'll only open the default file if the desktop is visible.
759 // ////////////////////
761 if (!headless && file == null && vamsasImport == null
762 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
764 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
765 jalview.bin.Cache.getDefault("www.jalview.org",
766 "http://www.jalview.org")
767 + "/examples/exampleFile_2_7.jar");
769 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
771 // hardwire upgrade of the startup file
772 file.replace("_2_3.jar", "_2_7.jar");
773 // and remove the stale setting
774 jalview.bin.Cache.removeProperty("STARTUP_FILE");
777 protocol = DataSourceType.FILE;
779 if (file.indexOf("http:") > -1)
781 protocol = DataSourceType.URL;
784 if (file.endsWith(".jar"))
786 format = FileFormat.Jalview;
792 format = new IdentifyFile().identify(file, protocol);
793 } catch (FileFormatException e)
799 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
801 getFeatures = checkDasArguments(aparser);
802 // extract groovy arguments before anything else.
804 // If the user has specified features to be retrieved,
805 // or a groovy script to be executed, do them if they
806 // haven't been done already
807 // fetch features for the default alignment
808 if (getFeatures != null)
810 if (startUpAlframe != null)
812 startFeatureFetching(getFeatures);
815 // Once all other stuff is done, execute any groovy scripts (in order)
816 if (groovyscript != null)
818 if (Cache.groovyJarsPresent())
820 System.out.println("Executing script " + groovyscript);
821 executeGroovyScript(groovyscript, startUpAlframe);
826 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
830 // and finally, turn off batch mode indicator - if the desktop still exists
835 desktop.setProgressBar(null, progress);
837 desktop.setInBatchMode(false);
841 private static void showUsage()
844 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
845 + "-nodisplay\tRun Jalview without User Interface.\n"
846 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
847 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
848 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
849 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
850 + "-features FILE\tUse the given file to mark features on the alignment.\n"
851 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
852 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
853 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
854 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
855 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
856 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
857 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
858 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
859 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
860 + "-png FILE\tCreate PNG image FILE from alignment.\n"
861 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
862 + "-html FILE\tCreate HTML file from alignment.\n"
863 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
864 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
865 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
866 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
867 + "-noquestionnaire\tTurn off questionnaire check.\n"
868 + "-nonews\tTurn off check for Jalview news.\n"
869 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
870 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
872 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
873 // after all other properties files have been read\n\t
874 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
875 // passed in correctly)"
876 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
877 + "-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"
878 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
879 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
880 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
882 // "-vdoc vamsas-document\tImport vamsas document into new
883 // session or join existing session with same URN\n"
884 // + "-vses vamsas-session\tJoin session with given URN\n"
885 + "-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"
886 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
889 private static void startUsageStats(final Desktop desktop)
892 * start a User Config prompt asking if we can log usage statistics.
894 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
895 "USAGESTATS", "Jalview Usage Statistics",
896 "Do you want to help make Jalview better by enabling "
897 + "the collection of usage statistics with Google Analytics ?"
898 + "\n\n(you can enable or disable usage tracking in the preferences)",
905 "Initialising googletracker for usage stats.");
906 Cache.initGoogleTracker();
907 Cache.log.debug("Tracking enabled.");
914 Cache.log.debug("Not enabling Google Tracking.");
917 desktop.addDialogThread(prompter);
921 * Locate the given string as a file and pass it to the groovy interpreter.
923 * @param groovyscript
924 * the script to execute
925 * @param jalviewContext
926 * the Jalview Desktop object passed in to the groovy binding as the
929 private void executeGroovyScript(String groovyscript, AlignFrame af)
932 * for scripts contained in files
939 if (groovyscript.trim().equals("STDIN"))
941 // read from stdin into a tempfile and execute it
944 tfile = File.createTempFile("jalview", "groovy");
945 PrintWriter outfile = new PrintWriter(
946 new OutputStreamWriter(new FileOutputStream(tfile)));
947 BufferedReader br = new BufferedReader(
948 new InputStreamReader(System.in));
950 while ((line = br.readLine()) != null)
952 outfile.write(line + "\n");
958 } catch (Exception ex)
960 System.err.println("Failed to read from STDIN into tempfile "
961 + ((tfile == null) ? "(tempfile wasn't created)"
962 : tfile.toString()));
963 ex.printStackTrace();
968 sfile = tfile.toURI().toURL();
969 } catch (Exception x)
972 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
982 sfile = new URI(groovyscript).toURL();
983 } catch (Exception x)
985 tfile = new File(groovyscript);
988 System.err.println("File '" + groovyscript + "' does not exist.");
991 if (!tfile.canRead())
993 System.err.println("File '" + groovyscript + "' cannot be read.");
996 if (tfile.length() < 1)
998 System.err.println("File '" + groovyscript + "' is empty.");
1003 sfile = tfile.getAbsoluteFile().toURI().toURL();
1004 } catch (Exception ex)
1006 System.err.println("Failed to create a file URL for "
1007 + tfile.getAbsoluteFile());
1014 Map<String, Object> vbinding = new HashMap<>();
1015 vbinding.put("Jalview", this);
1018 vbinding.put("currentAlFrame", af);
1020 Binding gbinding = new Binding(vbinding);
1021 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1022 gse.run(sfile.toString(), gbinding);
1023 if ("STDIN".equals(groovyscript))
1025 // delete temp file that we made -
1026 // only if it was successfully executed
1029 } catch (Exception e)
1031 System.err.println("Exception Whilst trying to execute file " + sfile
1032 + " as a groovy script.");
1033 e.printStackTrace(System.err);
1039 * Check commandline for any das server definitions or any fetchfrom switches
1041 * @return vector of DAS source nicknames to retrieve from
1043 private static Vector<String> checkDasArguments(ArgsParser aparser)
1045 Vector<String> source = null;
1047 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
1048 while ((data = aparser.getValue("dasserver", true)) != null)
1050 String nickname = null;
1052 int pos = data.indexOf('=');
1053 // determine capabilities
1056 nickname = data.substring(0, pos);
1058 url = data.substring(pos + 1);
1059 if (url != null && (url.startsWith("http:")
1060 || url.startsWith("sequence:http:")))
1062 if (nickname == null)
1066 if (locsources == null)
1074 locsources = locsources + nickname + "|" + url;
1076 "NOTE! dasserver parameter not yet really supported (got args of "
1077 + nickname + "|" + url);
1080 source = new Vector<>();
1082 source.addElement(nickname);
1085 "CMD [-dasserver " + data + "] executed successfully!");
1086 } // loop until no more server entries are found.
1087 if (locsources != null && locsources.indexOf('|') > -1)
1089 Cache.log.debug("Setting local source list in properties file to:\n"
1091 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
1093 while ((data = aparser.getValue("fetchfrom", true)) != null)
1095 System.out.println("adding source '" + data + "'");
1098 source = new Vector<>();
1100 source.addElement(data);
1106 * start a feature fetcher for every alignment frame
1110 private FeatureFetcher startFeatureFetching(
1111 final Vector<String> dasSources)
1113 FeatureFetcher ff = new FeatureFetcher();
1114 AlignFrame afs[] = Desktop.getAlignFrames();
1115 if (afs == null || afs.length == 0)
1119 for (int i = 0; i < afs.length; i++)
1121 ff.addFetcher(afs[i], dasSources);
1126 public static boolean isHeadlessMode()
1128 String isheadless = System.getProperty("java.awt.headless");
1129 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1136 public AlignFrame[] getAlignFrames()
1138 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1139 : Desktop.getAlignFrames();
1144 * Quit method delegates to Desktop.quit - unless running in headless mode
1145 * when it just ends the JVM
1149 if (desktop != null)
1159 public static AlignFrame getCurrentAlignFrame()
1161 return Jalview.currentAlignFrame;
1164 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1166 Jalview.currentAlignFrame = currentAlignFrame;