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 // BH 6/19/2018 starting to work on JS version - just discovering issues
91 * singleton instance of this class
93 private static Jalview instance;
95 private Desktop desktop;
97 public static AlignFrame currentAlignFrame;
100 * Answers true if Jalview is running as Javascript, else false. The value is
101 * set at compile time.
105 public static boolean isJS()
107 return /** @j2sNative true || */
115 // grab all the rights we can the JVM
116 Policy.setPolicy(new Policy()
119 public PermissionCollection getPermissions(CodeSource codesource)
121 Permissions perms = new Permissions();
122 perms.add(new AllPermission());
127 public void refresh()
136 * keep track of feature fetching tasks.
144 * TODO: generalise to track all jalview events to orchestrate batch
148 private int queued = 0;
150 private int running = 0;
152 public FeatureFetcher()
157 public void addFetcher(final AlignFrame af,
158 final Vector<String> dasSources)
160 final long id = System.currentTimeMillis();
162 final FeatureFetcher us = this;
163 new Thread(new Runnable()
175 af.setProgressBar(MessageManager
176 .getString("status.das_features_being_retrived"), id);
177 af.featureSettings_actionPerformed(null);
178 af.setProgressBar(null, id);
187 public synchronized boolean allFinished()
189 return queued == 0 && running == 0;
194 public static Jalview getInstance()
200 * main class for Jalview application
203 * open <em>filename</em>
205 public static void main(String[] args)
207 instance = new Jalview();
208 instance.doMain(args);
214 void doMain(String[] args)
219 System.setSecurityManager(null);
223 .println("Java version: " + System.getProperty("java.version"));
224 System.out.println(System.getProperty("os.arch") + " "
225 + System.getProperty("os.name") + " "
226 + System.getProperty("os.version"));
228 ArgsParser aparser = new ArgsParser(args);
229 boolean headless = false;
231 String usrPropsFile = aparser.getValue("props");
232 Cache.loadProperties(usrPropsFile); // must do this before
233 if (usrPropsFile != null)
236 "CMD [-props " + usrPropsFile + "] executed successfully!");
240 * BH 2018 ignoring this section for JS
245 if (aparser.contains("help") || aparser.contains("h"))
250 if (aparser.contains("nodisplay") || aparser.contains("nogui")
251 || aparser.contains("headless"))
253 System.setProperty("java.awt.headless", "true");
258 final String jabawsUrl = aparser.getValue("jabaws");
259 if (jabawsUrl != null)
263 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
265 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
266 } catch (MalformedURLException e)
269 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
274 String defs = aparser.getValue("setprop");
277 int p = defs.indexOf('=');
280 System.err.println("Ignoring invalid setprop argument : " + defs);
284 System.out.println("Executing setprop argument: " + defs);
285 // DISABLED FOR SECURITY REASONS
286 // TODO: add a property to allow properties to be overriden by cli args
287 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
289 defs = aparser.getValue("setprop");
291 if (System.getProperty("java.awt.headless") != null
292 && System.getProperty("java.awt.headless").equals("true"))
296 System.setProperty("http.agent",
297 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
301 } catch (NoClassDefFoundError error)
303 error.printStackTrace();
304 System.out.println("\nEssential logging libraries not found."
305 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
313 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
314 } catch (Exception ex)
316 System.err.println("Unexpected Look and Feel Exception");
317 ex.printStackTrace();
319 if (Platform.isAMac())
322 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
324 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
326 System.setProperty("apple.laf.useScreenMenuBar", "true");
327 if (lookAndFeel != null)
331 UIManager.setLookAndFeel(lookAndFeel);
332 } catch (Throwable e)
335 "Failed to set QuaQua look and feel: " + e.toString());
338 if (lookAndFeel == null || !(lookAndFeel.getClass()
339 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
340 || !UIManager.getLookAndFeel().getClass().toString()
341 .toLowerCase().contains("quaqua"))
346 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
347 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
348 } catch (Throwable e)
351 "Failed to reset look and feel: " + e.toString());
357 * configure 'full' SO model if preferences say to,
358 * else use the default (SO Lite)
360 if (Cache.getDefault("USE_FULL_SO", false))
362 SequenceOntologyFactory.setInstance(new SequenceOntology());
367 desktop = new Desktop();
368 desktop.setInBatchMode(true); // indicate we are starting up
369 desktop.setVisible(true);
372 * BH 2018 JS bypass this section
378 desktop.startServiceDiscovery();
379 if (!aparser.contains("nousagestats"))
381 startUsageStats(desktop);
385 System.err.println("CMD [-nousagestats] executed successfully!");
388 if (!aparser.contains("noquestionnaire"))
390 String url = aparser.getValue("questionnaire");
393 // Start the desktop questionnaire prompter with the specified
395 Cache.log.debug("Starting questionnaire url at " + url);
396 desktop.checkForQuestionnaire(url);
397 System.out.println("CMD questionnaire[-" + url
398 + "] executed successfully!");
402 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
404 // Start the desktop questionnaire prompter with the specified
407 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
409 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
411 "Starting questionnaire with default url: " + defurl);
412 desktop.checkForQuestionnaire(defurl);
419 .println("CMD [-noquestionnaire] executed successfully!");
422 if (!aparser.contains("nonews"))
424 desktop.checkForNews();
427 BioJsHTMLOutput.updateBioJS();
431 String file = null, data = null;
432 FileFormatI format = null;
433 DataSourceType protocol = null;
434 FileLoader fileLoader = new FileLoader(!headless);
435 Vector<String> getFeatures = null; // vector of das source nicknames to
439 String groovyscript = null; // script to execute after all loading is
440 // completed one way or another
441 // extract groovy argument and execute if necessary
442 groovyscript = aparser.getValue("groovy", true);
443 file = aparser.getValue("open", true);
445 if (file == null && desktop == null)
447 System.out.println("No files to open!");
450 String vamsasImport = aparser.getValue("vdoc");
451 String vamsasSession = aparser.getValue("vsess");
452 if (vamsasImport != null || vamsasSession != null)
454 if (desktop == null || headless)
457 "Headless vamsas sessions not yet supported. Sorry.");
460 // if we have a file, start a new session and import it.
461 boolean inSession = false;
462 if (vamsasImport != null)
466 DataSourceType viprotocol = AppletFormatAdapter
467 .checkProtocol(vamsasImport);
468 if (viprotocol == DataSourceType.FILE)
470 inSession = desktop.vamsasImport(new File(vamsasImport));
472 else if (viprotocol == DataSourceType.URL)
474 inSession = desktop.vamsasImport(new URL(vamsasImport));
477 } catch (Exception e)
479 System.err.println("Exeption when importing " + vamsasImport
480 + " as a vamsas document.");
485 System.err.println("Failed to import " + vamsasImport
486 + " as a vamsas document.");
490 System.out.println("Imported Successfully into new session "
491 + desktop.getVamsasApplication().getCurrentSession());
494 if (vamsasSession != null)
496 if (vamsasImport != null)
498 // close the newly imported session and import the Jalview specific
499 // remnants into the new session later on.
500 desktop.vamsasStop_actionPerformed(null);
502 // now join the new session
505 if (desktop.joinVamsasSession(vamsasSession))
508 "Successfully joined vamsas session " + vamsasSession);
512 System.err.println("WARNING: Failed to join vamsas session "
515 } catch (Exception e)
518 "ERROR: Failed to join vamsas session " + vamsasSession);
521 if (vamsasImport != null)
523 // the Jalview specific remnants can now be imported into the new
524 // session at the user's leisure.
526 "Skipping Push for import of data into existing vamsas session."); // TODO:
531 // desktop.getVamsasApplication().push_update();
536 // Finally, deal with the remaining input data.
541 desktop.setProgressBar(
543 .getString("status.processing_commandline_args"),
544 progress = System.currentTimeMillis());
546 System.out.println("CMD [-open " + file + "] executed successfully!");
548 if (!isJS() && !file.startsWith("http://"))
550 if (!(new File(file)).exists())
552 System.out.println("Can't find " + file);
560 protocol = AppletFormatAdapter.checkProtocol(file);
564 format = new IdentifyFile().identify(file, protocol);
565 } catch (FileFormatException e1)
570 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
574 System.out.println("error");
578 setCurrentAlignFrame(af);
579 data = aparser.getValue("colour", true);
582 data.replaceAll("%20", " ");
584 ColourSchemeI cs = ColourSchemeProperty
585 .getColourScheme(af.getViewport().getAlignment(), data);
590 "CMD [-color " + data + "] executed successfully!");
595 // Must maintain ability to use the groups flag
596 data = aparser.getValue("groups", true);
599 af.parseFeaturesFile(data,
600 AppletFormatAdapter.checkProtocol(data));
601 // System.out.println("Added " + data);
603 "CMD groups[-" + data + "] executed successfully!");
605 data = aparser.getValue("features", true);
608 af.parseFeaturesFile(data,
609 AppletFormatAdapter.checkProtocol(data));
610 // System.out.println("Added " + data);
612 "CMD [-features " + data + "] executed successfully!");
615 data = aparser.getValue("annotations", true);
618 af.loadJalviewDataFile(data, null, null, null);
619 // System.out.println("Added " + data);
621 "CMD [-annotations " + data + "] executed successfully!");
623 // set or clear the sortbytree flag.
624 if (aparser.contains("sortbytree"))
626 af.getViewport().setSortByTree(true);
627 if (af.getViewport().getSortByTree())
629 System.out.println("CMD [-sortbytree] executed successfully!");
632 if (aparser.contains("no-annotation"))
634 af.getViewport().setShowAnnotation(false);
635 if (!af.getViewport().isShowAnnotation())
637 System.out.println("CMD no-annotation executed successfully!");
640 if (aparser.contains("nosortbytree"))
642 af.getViewport().setSortByTree(false);
643 if (!af.getViewport().getSortByTree())
646 .println("CMD [-nosortbytree] executed successfully!");
649 data = aparser.getValue("tree", true);
655 "CMD [-tree " + data + "] executed successfully!");
656 NewickFile nf = new NewickFile(data,
657 AppletFormatAdapter.checkProtocol(data));
659 .setCurrentTree(af.showNewickTree(nf, data).getTree());
660 } catch (IOException ex)
662 System.err.println("Couldn't add tree " + data);
663 ex.printStackTrace(System.err);
666 // TODO - load PDB structure(s) to alignment JAL-629
667 // (associate with identical sequence in alignment, or a specified
670 getFeatures = checkDasArguments(aparser);
671 if (af != null && getFeatures != null)
673 FeatureFetcher ff = startFeatureFetching(getFeatures);
676 while (!ff.allFinished() || af.operationInProgress())
678 // wait around until fetching is finished.
682 } catch (Exception e)
688 getFeatures = null; // have retrieved features - forget them now.
690 if (groovyscript != null)
692 // Execute the groovy script after we've done all the rendering stuff
693 // and before any images or figures are generated.
694 System.out.println("Executing script " + groovyscript);
695 executeGroovyScript(groovyscript, af);
696 System.out.println("CMD groovy[" + groovyscript
697 + "] executed successfully!");
700 String imageName = "unnamed.png";
701 while (aparser.getSize() > 1)
703 String outputFormat = aparser.nextValue();
704 file = aparser.nextValue();
706 if (outputFormat.equalsIgnoreCase("png"))
708 af.createPNG(new File(file));
709 imageName = (new File(file)).getName();
710 System.out.println("Creating PNG image: " + file);
713 else if (outputFormat.equalsIgnoreCase("svg"))
715 File imageFile = new File(file);
716 imageName = imageFile.getName();
717 af.createSVG(imageFile);
718 System.out.println("Creating SVG image: " + file);
721 else if (outputFormat.equalsIgnoreCase("html"))
723 File imageFile = new File(file);
724 imageName = imageFile.getName();
725 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
726 htmlSVG.exportHTML(file);
728 System.out.println("Creating HTML image: " + file);
731 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
735 System.err.println("The output html file must not be null");
740 BioJsHTMLOutput.refreshVersionInfo(
741 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
742 } catch (URISyntaxException e)
746 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
747 bjs.exportHTML(file);
749 .println("Creating BioJS MSA Viwer HTML file: " + file);
752 else if (outputFormat.equalsIgnoreCase("imgMap"))
754 af.createImageMap(new File(file), imageName);
755 System.out.println("Creating image map: " + file);
758 else if (outputFormat.equalsIgnoreCase("eps"))
760 File outputFile = new File(file);
762 "Creating EPS file: " + outputFile.getAbsolutePath());
763 af.createEPS(outputFile);
767 af.saveAlignment(file, format);
768 if (af.isSaveAlignmentSuccessful())
770 System.out.println("Written alignment in " + format
771 + " format to " + file);
775 System.out.println("Error writing file " + file + " in "
776 + format + " format!!");
781 while (aparser.getSize() > 0)
783 System.out.println("Unknown arg: " + aparser.nextValue());
787 AlignFrame startUpAlframe = null;
788 // We'll only open the default file if the desktop is visible.
790 // ////////////////////
792 if (/** @j2sNative false && */ // BH 2018
793 !headless && file == null && vamsasImport == null
794 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
796 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
797 jalview.bin.Cache.getDefault("www.jalview.org",
798 "http://www.jalview.org")
799 + "/examples/exampleFile_2_7.jar");
801 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
803 // hardwire upgrade of the startup file
804 file.replace("_2_3.jar", "_2_7.jar");
805 // and remove the stale setting
806 jalview.bin.Cache.removeProperty("STARTUP_FILE");
809 protocol = DataSourceType.FILE;
811 if (file.indexOf("http:") > -1)
813 protocol = DataSourceType.URL;
816 if (file.endsWith(".jar"))
818 format = FileFormat.Jalview;
824 format = new IdentifyFile().identify(file, protocol);
825 } catch (FileFormatException e)
831 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
833 getFeatures = checkDasArguments(aparser);
834 // extract groovy arguments before anything else.
836 // If the user has specified features to be retrieved,
837 // or a groovy script to be executed, do them if they
838 // haven't been done already
839 // fetch features for the default alignment
840 if (getFeatures != null)
842 if (startUpAlframe != null)
844 startFeatureFetching(getFeatures);
847 // Once all other stuff is done, execute any groovy scripts (in order)
848 if (groovyscript != null)
850 if (Cache.groovyJarsPresent())
852 System.out.println("Executing script " + groovyscript);
853 executeGroovyScript(groovyscript, startUpAlframe);
858 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
862 // and finally, turn off batch mode indicator - if the desktop still exists
867 desktop.setProgressBar(null, progress);
869 desktop.setInBatchMode(false);
873 private static void showUsage()
876 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
877 + "-nodisplay\tRun Jalview without User Interface.\n"
878 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
879 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
880 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
881 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
882 + "-features FILE\tUse the given file to mark features on the alignment.\n"
883 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
884 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
885 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
886 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
887 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
888 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
889 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
890 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
891 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
892 + "-png FILE\tCreate PNG image FILE from alignment.\n"
893 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
894 + "-html FILE\tCreate HTML file from alignment.\n"
895 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
896 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
897 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
898 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
899 + "-noquestionnaire\tTurn off questionnaire check.\n"
900 + "-nonews\tTurn off check for Jalview news.\n"
901 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
902 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
904 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
905 // after all other properties files have been read\n\t
906 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
907 // passed in correctly)"
908 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
909 + "-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"
910 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
911 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
912 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
914 // "-vdoc vamsas-document\tImport vamsas document into new
915 // session or join existing session with same URN\n"
916 // + "-vses vamsas-session\tJoin session with given URN\n"
917 + "-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"
918 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
921 private static void startUsageStats(final Desktop desktop)
924 * start a User Config prompt asking if we can log usage statistics.
926 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
927 "USAGESTATS", "Jalview Usage Statistics",
928 "Do you want to help make Jalview better by enabling "
929 + "the collection of usage statistics with Google Analytics ?"
930 + "\n\n(you can enable or disable usage tracking in the preferences)",
937 "Initialising googletracker for usage stats.");
938 Cache.initGoogleTracker();
939 Cache.log.debug("Tracking enabled.");
946 Cache.log.debug("Not enabling Google Tracking.");
949 desktop.addDialogThread(prompter);
953 * Locate the given string as a file and pass it to the groovy interpreter.
955 * @param groovyscript
956 * the script to execute
957 * @param jalviewContext
958 * the Jalview Desktop object passed in to the groovy binding as the
961 private void executeGroovyScript(String groovyscript, AlignFrame af)
964 * for scripts contained in files
971 if (groovyscript.trim().equals("STDIN"))
973 // read from stdin into a tempfile and execute it
976 tfile = File.createTempFile("jalview", "groovy");
977 PrintWriter outfile = new PrintWriter(
978 new OutputStreamWriter(new FileOutputStream(tfile)));
979 BufferedReader br = new BufferedReader(
980 new InputStreamReader(System.in));
982 while ((line = br.readLine()) != null)
984 outfile.write(line + "\n");
990 } catch (Exception ex)
992 System.err.println("Failed to read from STDIN into tempfile "
993 + ((tfile == null) ? "(tempfile wasn't created)"
994 : tfile.toString()));
995 ex.printStackTrace();
1000 sfile = tfile.toURI().toURL();
1001 } catch (Exception x)
1004 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1006 x.printStackTrace();
1014 sfile = new URI(groovyscript).toURL();
1015 } catch (Exception x)
1017 tfile = new File(groovyscript);
1018 if (!tfile.exists())
1020 System.err.println("File '" + groovyscript + "' does not exist.");
1023 if (!tfile.canRead())
1025 System.err.println("File '" + groovyscript + "' cannot be read.");
1028 if (tfile.length() < 1)
1030 System.err.println("File '" + groovyscript + "' is empty.");
1035 sfile = tfile.getAbsoluteFile().toURI().toURL();
1036 } catch (Exception ex)
1038 System.err.println("Failed to create a file URL for "
1039 + tfile.getAbsoluteFile());
1046 Map<String, Object> vbinding = new HashMap<>();
1047 vbinding.put("Jalview", this);
1050 vbinding.put("currentAlFrame", af);
1052 Binding gbinding = new Binding(vbinding);
1053 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1054 gse.run(sfile.toString(), gbinding);
1055 if ("STDIN".equals(groovyscript))
1057 // delete temp file that we made -
1058 // only if it was successfully executed
1061 } catch (Exception e)
1063 System.err.println("Exception Whilst trying to execute file " + sfile
1064 + " as a groovy script.");
1065 e.printStackTrace(System.err);
1071 * Check commandline for any das server definitions or any fetchfrom switches
1073 * @return vector of DAS source nicknames to retrieve from
1075 private static Vector<String> checkDasArguments(ArgsParser aparser)
1077 Vector<String> source = null;
1079 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
1080 while ((data = aparser.getValue("dasserver", true)) != null)
1082 String nickname = null;
1084 int pos = data.indexOf('=');
1085 // determine capabilities
1088 nickname = data.substring(0, pos);
1090 url = data.substring(pos + 1);
1091 if (url != null && (url.startsWith("http:")
1092 || url.startsWith("sequence:http:")))
1094 if (nickname == null)
1098 if (locsources == null)
1106 locsources = locsources + nickname + "|" + url;
1108 "NOTE! dasserver parameter not yet really supported (got args of "
1109 + nickname + "|" + url);
1112 source = new Vector<>();
1114 source.addElement(nickname);
1117 "CMD [-dasserver " + data + "] executed successfully!");
1118 } // loop until no more server entries are found.
1119 if (locsources != null && locsources.indexOf('|') > -1)
1121 Cache.log.debug("Setting local source list in properties file to:\n"
1123 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
1125 while ((data = aparser.getValue("fetchfrom", true)) != null)
1127 System.out.println("adding source '" + data + "'");
1130 source = new Vector<>();
1132 source.addElement(data);
1138 * start a feature fetcher for every alignment frame
1142 private FeatureFetcher startFeatureFetching(
1143 final Vector<String> dasSources)
1145 FeatureFetcher ff = new FeatureFetcher();
1146 AlignFrame afs[] = Desktop.getAlignFrames();
1147 if (afs == null || afs.length == 0)
1151 for (int i = 0; i < afs.length; i++)
1153 ff.addFetcher(afs[i], dasSources);
1158 public static boolean isHeadlessMode()
1160 String isheadless = System.getProperty("java.awt.headless");
1161 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1168 public AlignFrame[] getAlignFrames()
1170 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1171 : Desktop.getAlignFrames();
1176 * Quit method delegates to Desktop.quit - unless running in headless mode
1177 * when it just ends the JVM
1181 if (desktop != null)
1191 public static AlignFrame getCurrentAlignFrame()
1193 return Jalview.currentAlignFrame;
1196 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1198 Jalview.currentAlignFrame = currentAlignFrame;