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.featureSettings.fetchDasFeatures(dasSources, true);
160 af.setProgressBar(null, id);
169 public synchronized boolean allFinished()
171 return queued == 0 && running == 0;
176 public static Jalview getInstance()
182 * main class for Jalview application
185 * open <em>filename</em>
187 public static void main(String[] args)
189 instance = new Jalview();
190 instance.doMain(args);
196 void doMain(String[] args)
198 System.setSecurityManager(null);
200 .println("Java version: " + System.getProperty("java.version"));
201 System.out.println(System.getProperty("os.arch") + " "
202 + System.getProperty("os.name") + " "
203 + System.getProperty("os.version"));
205 ArgsParser aparser = new ArgsParser(args);
206 boolean headless = false;
208 if (aparser.contains("help") || aparser.contains("h"))
213 if (aparser.contains("nodisplay") || aparser.contains("nogui")
214 || aparser.contains("headless"))
216 System.setProperty("java.awt.headless", "true");
219 String usrPropsFile = aparser.getValue("props");
220 Cache.loadProperties(usrPropsFile); // must do this before
221 if (usrPropsFile != null)
224 "CMD [-props " + usrPropsFile + "] executed successfully!");
229 final String jabawsUrl = aparser.getValue("jabaws");
230 if (jabawsUrl != null)
234 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
236 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
237 } catch (MalformedURLException e)
240 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
244 String defs = aparser.getValue("setprop");
247 int p = defs.indexOf('=');
250 System.err.println("Ignoring invalid setprop argument : " + defs);
254 System.out.println("Executing setprop argument: " + defs);
255 // DISABLED FOR SECURITY REASONS
256 // TODO: add a property to allow properties to be overriden by cli args
257 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
259 defs = aparser.getValue("setprop");
261 if (System.getProperty("java.awt.headless") != null
262 && System.getProperty("java.awt.headless").equals("true"))
266 System.setProperty("http.agent",
267 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
271 } catch (NoClassDefFoundError error)
273 error.printStackTrace();
274 System.out.println("\nEssential logging libraries not found."
275 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
283 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
284 } catch (Exception ex)
286 System.err.println("Unexpected Look and Feel Exception");
287 ex.printStackTrace();
289 if (Platform.isAMac())
292 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
294 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
296 System.setProperty("apple.laf.useScreenMenuBar", "true");
297 if (lookAndFeel != null)
301 UIManager.setLookAndFeel(lookAndFeel);
302 } catch (Throwable e)
305 "Failed to set QuaQua look and feel: " + e.toString());
308 if (lookAndFeel == null || !(lookAndFeel.getClass()
309 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
310 || !UIManager.getLookAndFeel().getClass().toString()
311 .toLowerCase().contains("quaqua"))
316 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
317 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
318 } catch (Throwable e)
321 "Failed to reset look and feel: " + e.toString());
327 * configure 'full' SO model if preferences say to,
328 * else use the default (SO Lite)
330 if (Cache.getDefault("USE_FULL_SO", false))
332 SequenceOntologyFactory.setInstance(new SequenceOntology());
337 desktop = new Desktop();
338 desktop.setInBatchMode(true); // indicate we are starting up
339 desktop.setVisible(true);
340 desktop.startServiceDiscovery();
341 if (!aparser.contains("nousagestats"))
343 startUsageStats(desktop);
347 System.err.println("CMD [-nousagestats] executed successfully!");
350 if (!aparser.contains("noquestionnaire"))
352 String url = aparser.getValue("questionnaire");
355 // Start the desktop questionnaire prompter with the specified
357 Cache.log.debug("Starting questionnaire url at " + url);
358 desktop.checkForQuestionnaire(url);
360 "CMD questionnaire[-" + url + "] executed successfully!");
364 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
366 // Start the desktop questionnaire prompter with the specified
369 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
371 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
373 "Starting questionnaire with default url: " + defurl);
374 desktop.checkForQuestionnaire(defurl);
380 System.err.println("CMD [-noquestionnaire] executed successfully!");
383 if (!aparser.contains("nonews"))
385 desktop.checkForNews();
388 BioJsHTMLOutput.updateBioJS();
391 String file = null, data = null;
392 FileFormatI format = null;
393 DataSourceType protocol = null;
394 FileLoader fileLoader = new FileLoader(!headless);
395 Vector<String> getFeatures = null; // vector of das source nicknames to
399 String groovyscript = null; // script to execute after all loading is
400 // completed one way or another
401 // extract groovy argument and execute if necessary
402 groovyscript = aparser.getValue("groovy", true);
403 file = aparser.getValue("open", true);
405 if (file == null && desktop == null)
407 System.out.println("No files to open!");
410 String vamsasImport = aparser.getValue("vdoc");
411 String vamsasSession = aparser.getValue("vsess");
412 if (vamsasImport != null || vamsasSession != null)
414 if (desktop == null || headless)
417 "Headless vamsas sessions not yet supported. Sorry.");
420 // if we have a file, start a new session and import it.
421 boolean inSession = false;
422 if (vamsasImport != null)
426 DataSourceType viprotocol = AppletFormatAdapter
427 .checkProtocol(vamsasImport);
428 if (viprotocol == DataSourceType.FILE)
430 inSession = desktop.vamsasImport(new File(vamsasImport));
432 else if (viprotocol == DataSourceType.URL)
434 inSession = desktop.vamsasImport(new URL(vamsasImport));
437 } catch (Exception e)
439 System.err.println("Exeption when importing " + vamsasImport
440 + " as a vamsas document.");
445 System.err.println("Failed to import " + vamsasImport
446 + " as a vamsas document.");
450 System.out.println("Imported Successfully into new session "
451 + desktop.getVamsasApplication().getCurrentSession());
454 if (vamsasSession != null)
456 if (vamsasImport != null)
458 // close the newly imported session and import the Jalview specific
459 // remnants into the new session later on.
460 desktop.vamsasStop_actionPerformed(null);
462 // now join the new session
465 if (desktop.joinVamsasSession(vamsasSession))
468 "Successfully joined vamsas session " + vamsasSession);
472 System.err.println("WARNING: Failed to join vamsas session "
475 } catch (Exception e)
478 "ERROR: Failed to join vamsas session " + vamsasSession);
481 if (vamsasImport != null)
483 // the Jalview specific remnants can now be imported into the new
484 // session at the user's leisure.
486 "Skipping Push for import of data into existing vamsas session."); // TODO:
491 // desktop.getVamsasApplication().push_update();
496 // Finally, deal with the remaining input data.
501 desktop.setProgressBar(
503 .getString("status.processing_commandline_args"),
504 progress = System.currentTimeMillis());
506 System.out.println("CMD [-open " + file + "] executed successfully!");
508 if (!file.startsWith("http://"))
510 if (!(new File(file)).exists())
512 System.out.println("Can't find " + file);
520 protocol = AppletFormatAdapter.checkProtocol(file);
524 format = new IdentifyFile().identify(file, protocol);
525 } catch (FileFormatException e1)
530 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
534 System.out.println("error");
538 setCurrentAlignFrame(af);
539 data = aparser.getValue("colour", true);
542 data.replaceAll("%20", " ");
544 ColourSchemeI cs = ColourSchemeProperty
545 .getColourScheme(af.getViewport().getAlignment(), data);
550 "CMD [-color " + data + "] executed successfully!");
555 // Must maintain ability to use the groups flag
556 data = aparser.getValue("groups", true);
559 af.parseFeaturesFile(data,
560 AppletFormatAdapter.checkProtocol(data));
561 // System.out.println("Added " + data);
563 "CMD groups[-" + data + "] executed successfully!");
565 data = aparser.getValue("features", true);
568 af.parseFeaturesFile(data,
569 AppletFormatAdapter.checkProtocol(data));
570 // System.out.println("Added " + data);
572 "CMD [-features " + data + "] executed successfully!");
575 data = aparser.getValue("annotations", true);
578 af.loadJalviewDataFile(data, null, null, null);
579 // System.out.println("Added " + data);
581 "CMD [-annotations " + data + "] executed successfully!");
583 // set or clear the sortbytree flag.
584 if (aparser.contains("sortbytree"))
586 af.getViewport().setSortByTree(true);
587 if (af.getViewport().getSortByTree())
589 System.out.println("CMD [-sortbytree] executed successfully!");
592 if (aparser.contains("no-annotation"))
594 af.getViewport().setShowAnnotation(false);
595 if (!af.getViewport().isShowAnnotation())
597 System.out.println("CMD no-annotation executed successfully!");
600 if (aparser.contains("nosortbytree"))
602 af.getViewport().setSortByTree(false);
603 if (!af.getViewport().getSortByTree())
606 .println("CMD [-nosortbytree] executed successfully!");
609 data = aparser.getValue("tree", true);
615 "CMD [-tree " + data + "] executed successfully!");
616 NewickFile nf = new NewickFile(data,
617 AppletFormatAdapter.checkProtocol(data));
619 .setCurrentTree(af.showNewickTree(nf, data).getTree());
620 } catch (IOException ex)
622 System.err.println("Couldn't add tree " + data);
623 ex.printStackTrace(System.err);
626 // TODO - load PDB structure(s) to alignment JAL-629
627 // (associate with identical sequence in alignment, or a specified
630 getFeatures = checkDasArguments(aparser);
631 if (af != null && getFeatures != null)
633 FeatureFetcher ff = startFeatureFetching(getFeatures);
636 while (!ff.allFinished() || af.operationInProgress())
638 // wait around until fetching is finished.
642 } catch (Exception e)
648 getFeatures = null; // have retrieved features - forget them now.
650 if (groovyscript != null)
652 // Execute the groovy script after we've done all the rendering stuff
653 // and before any images or figures are generated.
654 System.out.println("Executing script " + groovyscript);
655 executeGroovyScript(groovyscript, af);
656 System.out.println("CMD groovy[" + groovyscript
657 + "] executed successfully!");
660 String imageName = "unnamed.png";
661 while (aparser.getSize() > 1)
663 String outputFormat = aparser.nextValue();
664 file = aparser.nextValue();
666 if (outputFormat.equalsIgnoreCase("png"))
668 af.createPNG(new File(file));
669 imageName = (new File(file)).getName();
670 System.out.println("Creating PNG image: " + file);
673 else if (outputFormat.equalsIgnoreCase("svg"))
675 File imageFile = new File(file);
676 imageName = imageFile.getName();
677 af.createSVG(imageFile);
678 System.out.println("Creating SVG image: " + file);
681 else if (outputFormat.equalsIgnoreCase("html"))
683 File imageFile = new File(file);
684 imageName = imageFile.getName();
685 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
686 htmlSVG.exportHTML(file);
688 System.out.println("Creating HTML image: " + file);
691 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
695 System.err.println("The output html file must not be null");
700 BioJsHTMLOutput.refreshVersionInfo(
701 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
702 } catch (URISyntaxException e)
706 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
707 bjs.exportHTML(file);
709 .println("Creating BioJS MSA Viwer HTML file: " + file);
712 else if (outputFormat.equalsIgnoreCase("imgMap"))
714 af.createImageMap(new File(file), imageName);
715 System.out.println("Creating image map: " + file);
718 else if (outputFormat.equalsIgnoreCase("eps"))
720 File outputFile = new File(file);
722 "Creating EPS file: " + outputFile.getAbsolutePath());
723 af.createEPS(outputFile);
727 if (af.saveAlignment(file, format))
729 System.out.println("Written alignment in " + format
730 + " format to " + file);
734 System.out.println("Error writing file " + file + " in "
735 + format + " format!!");
740 while (aparser.getSize() > 0)
742 System.out.println("Unknown arg: " + aparser.nextValue());
746 AlignFrame startUpAlframe = null;
747 // We'll only open the default file if the desktop is visible.
749 // ////////////////////
751 if (!headless && file == null && vamsasImport == null
752 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
754 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
755 jalview.bin.Cache.getDefault("www.jalview.org",
756 "http://www.jalview.org")
757 + "/examples/exampleFile_2_7.jar");
759 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
761 // hardwire upgrade of the startup file
762 file.replace("_2_3.jar", "_2_7.jar");
763 // and remove the stale setting
764 jalview.bin.Cache.removeProperty("STARTUP_FILE");
767 protocol = DataSourceType.FILE;
769 if (file.indexOf("http:") > -1)
771 protocol = DataSourceType.URL;
774 if (file.endsWith(".jar"))
776 format = FileFormat.Jalview;
782 format = new IdentifyFile().identify(file, protocol);
783 } catch (FileFormatException e)
789 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
791 getFeatures = checkDasArguments(aparser);
792 // extract groovy arguments before anything else.
794 // If the user has specified features to be retrieved,
795 // or a groovy script to be executed, do them if they
796 // haven't been done already
797 // fetch features for the default alignment
798 if (getFeatures != null)
800 if (startUpAlframe != null)
802 startFeatureFetching(getFeatures);
805 // Once all other stuff is done, execute any groovy scripts (in order)
806 if (groovyscript != null)
808 if (Cache.groovyJarsPresent())
810 System.out.println("Executing script " + groovyscript);
811 executeGroovyScript(groovyscript, startUpAlframe);
816 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
820 // and finally, turn off batch mode indicator - if the desktop still exists
825 desktop.setProgressBar(null, progress);
827 desktop.setInBatchMode(false);
831 private static void showUsage()
834 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
835 + "-nodisplay\tRun Jalview without User Interface.\n"
836 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
837 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
838 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
839 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
840 + "-features FILE\tUse the given file to mark features on the alignment.\n"
841 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
842 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
843 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
844 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
845 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
846 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
847 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
848 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
849 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
850 + "-png FILE\tCreate PNG image FILE from alignment.\n"
851 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
852 + "-html FILE\tCreate HTML file from alignment.\n"
853 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
854 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
855 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
856 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
857 + "-noquestionnaire\tTurn off questionnaire check.\n"
858 + "-nonews\tTurn off check for Jalview news.\n"
859 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
860 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
862 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
863 // after all other properties files have been read\n\t
864 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
865 // passed in correctly)"
866 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
867 + "-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"
868 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
869 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
870 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
872 // "-vdoc vamsas-document\tImport vamsas document into new
873 // session or join existing session with same URN\n"
874 // + "-vses vamsas-session\tJoin session with given URN\n"
875 + "-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"
876 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
879 private static void startUsageStats(final Desktop desktop)
882 * start a User Config prompt asking if we can log usage statistics.
884 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
885 "USAGESTATS", "Jalview Usage Statistics",
886 "Do you want to help make Jalview better by enabling "
887 + "the collection of usage statistics with Google Analytics ?"
888 + "\n\n(you can enable or disable usage tracking in the preferences)",
895 "Initialising googletracker for usage stats.");
896 Cache.initGoogleTracker();
897 Cache.log.debug("Tracking enabled.");
904 Cache.log.debug("Not enabling Google Tracking.");
907 desktop.addDialogThread(prompter);
911 * Locate the given string as a file and pass it to the groovy interpreter.
913 * @param groovyscript
914 * the script to execute
915 * @param jalviewContext
916 * the Jalview Desktop object passed in to the groovy binding as the
919 private void executeGroovyScript(String groovyscript, AlignFrame af)
922 * for scripts contained in files
929 if (groovyscript.trim().equals("STDIN"))
931 // read from stdin into a tempfile and execute it
934 tfile = File.createTempFile("jalview", "groovy");
935 PrintWriter outfile = new PrintWriter(
936 new OutputStreamWriter(new FileOutputStream(tfile)));
937 BufferedReader br = new BufferedReader(
938 new InputStreamReader(System.in));
940 while ((line = br.readLine()) != null)
942 outfile.write(line + "\n");
948 } catch (Exception ex)
950 System.err.println("Failed to read from STDIN into tempfile "
951 + ((tfile == null) ? "(tempfile wasn't created)"
952 : tfile.toString()));
953 ex.printStackTrace();
958 sfile = tfile.toURI().toURL();
959 } catch (Exception x)
962 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
972 sfile = new URI(groovyscript).toURL();
973 } catch (Exception x)
975 tfile = new File(groovyscript);
978 System.err.println("File '" + groovyscript + "' does not exist.");
981 if (!tfile.canRead())
983 System.err.println("File '" + groovyscript + "' cannot be read.");
986 if (tfile.length() < 1)
988 System.err.println("File '" + groovyscript + "' is empty.");
993 sfile = tfile.getAbsoluteFile().toURI().toURL();
994 } catch (Exception ex)
996 System.err.println("Failed to create a file URL for "
997 + tfile.getAbsoluteFile());
1004 Map<String, Object> vbinding = new HashMap<>();
1005 vbinding.put("Jalview", this);
1008 vbinding.put("currentAlFrame", af);
1010 Binding gbinding = new Binding(vbinding);
1011 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1012 gse.run(sfile.toString(), gbinding);
1013 if ("STDIN".equals(groovyscript))
1015 // delete temp file that we made -
1016 // only if it was successfully executed
1019 } catch (Exception e)
1021 System.err.println("Exception Whilst trying to execute file " + sfile
1022 + " as a groovy script.");
1023 e.printStackTrace(System.err);
1029 * Check commandline for any das server definitions or any fetchfrom switches
1031 * @return vector of DAS source nicknames to retrieve from
1033 private static Vector<String> checkDasArguments(ArgsParser aparser)
1035 Vector<String> source = null;
1037 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
1038 while ((data = aparser.getValue("dasserver", true)) != null)
1040 String nickname = null;
1042 int pos = data.indexOf('=');
1043 // determine capabilities
1046 nickname = data.substring(0, pos);
1048 url = data.substring(pos + 1);
1049 if (url != null && (url.startsWith("http:")
1050 || url.startsWith("sequence:http:")))
1052 if (nickname == null)
1056 if (locsources == null)
1064 locsources = locsources + nickname + "|" + url;
1066 "NOTE! dasserver parameter not yet really supported (got args of "
1067 + nickname + "|" + url);
1070 source = new Vector<>();
1072 source.addElement(nickname);
1075 "CMD [-dasserver " + data + "] executed successfully!");
1076 } // loop until no more server entries are found.
1077 if (locsources != null && locsources.indexOf('|') > -1)
1079 Cache.log.debug("Setting local source list in properties file to:\n"
1081 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
1083 while ((data = aparser.getValue("fetchfrom", true)) != null)
1085 System.out.println("adding source '" + data + "'");
1088 source = new Vector<>();
1090 source.addElement(data);
1096 * start a feature fetcher for every alignment frame
1100 private FeatureFetcher startFeatureFetching(
1101 final Vector<String> dasSources)
1103 FeatureFetcher ff = new FeatureFetcher();
1104 AlignFrame afs[] = Desktop.getAlignFrames();
1105 if (afs == null || afs.length == 0)
1109 for (int i = 0; i < afs.length; i++)
1111 ff.addFetcher(afs[i], dasSources);
1116 public static boolean isHeadlessMode()
1118 String isheadless = System.getProperty("java.awt.headless");
1119 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1126 public AlignFrame[] getAlignFrames()
1128 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1129 : Desktop.getAlignFrames();
1134 * Quit method delegates to Desktop.quit - unless running in headless mode
1135 * when it just ends the JVM
1139 if (desktop != null)
1149 public static AlignFrame getCurrentAlignFrame()
1151 return Jalview.currentAlignFrame;
1154 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1156 Jalview.currentAlignFrame = currentAlignFrame;