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.util.Worker;
43 import jalview.ws.jws2.Jws2Discoverer;
45 import java.io.BufferedReader;
47 import java.io.FileOutputStream;
48 import java.io.IOException;
49 import java.io.InputStreamReader;
50 import java.io.OutputStreamWriter;
51 import java.io.PrintWriter;
52 import java.net.MalformedURLException;
54 import java.net.URISyntaxException;
56 import java.security.AllPermission;
57 import java.security.CodeSource;
58 import java.security.PermissionCollection;
59 import java.security.Permissions;
60 import java.security.Policy;
61 import java.util.ArrayList;
62 import java.util.Arrays;
63 import java.util.HashMap;
64 import java.util.List;
66 import java.util.Vector;
68 import javax.swing.LookAndFeel;
69 import javax.swing.UIManager;
71 import groovy.lang.Binding;
72 import groovy.util.GroovyScriptEngine;
75 * Main class for Jalview Application <br>
77 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
80 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
81 * jalview.bin.Jalview jalview.bin.Jalview
83 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
84 * embellish '*' to e.g. '*.jar')
92 * singleton instance of this class
94 private static Jalview instance;
96 private Desktop desktop;
98 public static AlignFrame currentAlignFrame;
102 // grab all the rights we can the JVM
103 Policy.setPolicy(new Policy()
106 public PermissionCollection getPermissions(CodeSource codesource)
108 Permissions perms = new Permissions();
109 perms.add(new AllPermission());
114 public void refresh()
121 * keep track of feature fetching tasks.
129 * TODO: generalise to track all jalview events to orchestrate batch
133 private int queued = 0;
135 private int running = 0;
137 public FeatureFetcher()
142 public void addFetcher(final AlignFrame af,
143 final Vector<String> dasSources)
145 final long id = System.currentTimeMillis();
147 final FeatureFetcher us = this;
148 new Thread(new Runnable()
160 af.setProgressBar(MessageManager
161 .getString("status.das_features_being_retrived"), id);
162 af.featureSettings_actionPerformed(null);
163 af.setProgressBar(null, id);
172 public synchronized boolean allFinished()
174 return queued == 0 && running == 0;
179 public static Jalview getInstance()
185 * main class for Jalview application
188 * open <em>filename</em>
190 public static void main(String[] args)
192 float ONE_MB = 1048576f;
193 Runtime runtime = Runtime.getRuntime();
194 float maxMemory = runtime.maxMemory() / ONE_MB;
195 boolean is9or10 = System.getProperty("java.version").startsWith("10.")
196 || System.getProperty("java.version").startsWith("9.")
197 || System.getProperty("java.version").startsWith("10.")
198 || System.getProperty("java.version").startsWith("1.10.")
199 || System.getProperty("java.version").startsWith("1.9.");
200 if (maxMemory < 1024 * 14)
203 for (String r : args)
205 cmd += (cmd.length() == 0) ? r : " " + r;
207 if (cmd.indexOf("-Xmx") == -1)
209 cmd = "-Xmx15G " + cmd;
210 System.err.println("relaunching with 15G: " + cmd);
211 Worker worker = Worker.jalviewDesktopRunner(false, cmd, 0,
213 + (is9or10 ? " --add-modules=\"java.se.ee\"" : ""));
217 while (worker.getExitValue() == null)
222 } catch (Exception q)
227 } catch (Exception q)
232 System.exit(worker.getExitValue());
236 List<String> rgs = new ArrayList();
237 rgs.addAll(Arrays.asList(args));
239 while (i < rgs.size())
241 if (rgs.get(i).indexOf("-Xmx") > -1)
250 instance = new Jalview();
251 instance.doMain(args);
257 void doMain(String[] args)
259 System.setSecurityManager(null);
261 .println("Java version: " + System.getProperty("java.version"));
262 System.out.println(System.getProperty("os.arch") + " "
263 + System.getProperty("os.name") + " "
264 + System.getProperty("os.version"));
266 ArgsParser aparser = new ArgsParser(args);
267 boolean headless = false;
269 if (aparser.contains("help") || aparser.contains("h"))
274 if (aparser.contains("nodisplay") || aparser.contains("nogui")
275 || aparser.contains("headless"))
277 System.setProperty("java.awt.headless", "true");
280 String usrPropsFile = aparser.getValue("props");
281 Cache.loadProperties(usrPropsFile); // must do this before
282 if (usrPropsFile != null)
285 "CMD [-props " + usrPropsFile + "] executed successfully!");
290 final String jabawsUrl = aparser.getValue("jabaws");
291 if (jabawsUrl != null)
295 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
297 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
298 } catch (MalformedURLException e)
301 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
305 String defs = aparser.getValue("setprop");
308 int p = defs.indexOf('=');
311 System.err.println("Ignoring invalid setprop argument : " + defs);
315 System.out.println("Executing setprop argument: " + defs);
316 // DISABLED FOR SECURITY REASONS
317 // TODO: add a property to allow properties to be overriden by cli args
318 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
320 defs = aparser.getValue("setprop");
322 if (System.getProperty("java.awt.headless") != null
323 && System.getProperty("java.awt.headless").equals("true"))
327 System.setProperty("http.agent",
328 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
332 } catch (NoClassDefFoundError error)
334 error.printStackTrace();
335 System.out.println("\nEssential logging libraries not found."
336 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
344 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
345 } catch (Exception ex)
347 System.err.println("Unexpected Look and Feel Exception");
348 ex.printStackTrace();
350 if (Platform.isAMac())
353 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
355 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
357 System.setProperty("apple.laf.useScreenMenuBar", "true");
358 if (lookAndFeel != null)
362 UIManager.setLookAndFeel(lookAndFeel);
363 } catch (Throwable e)
366 "Failed to set QuaQua look and feel: " + e.toString());
369 if (lookAndFeel == null || !(lookAndFeel.getClass()
370 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
371 || !UIManager.getLookAndFeel().getClass().toString()
372 .toLowerCase().contains("quaqua"))
377 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
378 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
379 } catch (Throwable e)
382 "Failed to reset look and feel: " + e.toString());
388 * configure 'full' SO model if preferences say to,
389 * else use the default (SO Lite)
391 if (Cache.getDefault("USE_FULL_SO", false))
393 SequenceOntologyFactory.setInstance(new SequenceOntology());
398 desktop = new Desktop();
399 desktop.setInBatchMode(true); // indicate we are starting up
400 desktop.setVisible(true);
401 desktop.startServiceDiscovery();
402 if (!aparser.contains("nousagestats"))
404 startUsageStats(desktop);
408 System.err.println("CMD [-nousagestats] executed successfully!");
411 if (!aparser.contains("noquestionnaire"))
413 String url = aparser.getValue("questionnaire");
416 // Start the desktop questionnaire prompter with the specified
418 Cache.log.debug("Starting questionnaire url at " + url);
419 desktop.checkForQuestionnaire(url);
421 "CMD questionnaire[-" + url + "] executed successfully!");
425 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
427 // Start the desktop questionnaire prompter with the specified
430 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
432 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
434 "Starting questionnaire with default url: " + defurl);
435 desktop.checkForQuestionnaire(defurl);
441 System.err.println("CMD [-noquestionnaire] executed successfully!");
444 if (!aparser.contains("nonews"))
446 desktop.checkForNews();
449 BioJsHTMLOutput.updateBioJS();
452 String file = null, data = null;
453 FileFormatI format = null;
454 DataSourceType protocol = null;
455 FileLoader fileLoader = new FileLoader(!headless);
456 Vector<String> getFeatures = null; // vector of das source nicknames to
460 String groovyscript = null; // script to execute after all loading is
461 // completed one way or another
462 // extract groovy argument and execute if necessary
463 groovyscript = aparser.getValue("groovy", true);
464 file = aparser.getValue("open", true);
466 if (file == null && desktop == null)
468 System.out.println("No files to open!");
471 String vamsasImport = aparser.getValue("vdoc");
472 String vamsasSession = aparser.getValue("vsess");
473 if (vamsasImport != null || vamsasSession != null)
475 if (desktop == null || headless)
478 "Headless vamsas sessions not yet supported. Sorry.");
481 // if we have a file, start a new session and import it.
482 boolean inSession = false;
483 if (vamsasImport != null)
487 DataSourceType viprotocol = AppletFormatAdapter
488 .checkProtocol(vamsasImport);
489 if (viprotocol == DataSourceType.FILE)
491 inSession = desktop.vamsasImport(new File(vamsasImport));
493 else if (viprotocol == DataSourceType.URL)
495 inSession = desktop.vamsasImport(new URL(vamsasImport));
498 } catch (Exception e)
500 System.err.println("Exeption when importing " + vamsasImport
501 + " as a vamsas document.");
506 System.err.println("Failed to import " + vamsasImport
507 + " as a vamsas document.");
511 System.out.println("Imported Successfully into new session "
512 + desktop.getVamsasApplication().getCurrentSession());
515 if (vamsasSession != null)
517 if (vamsasImport != null)
519 // close the newly imported session and import the Jalview specific
520 // remnants into the new session later on.
521 desktop.vamsasStop_actionPerformed(null);
523 // now join the new session
526 if (desktop.joinVamsasSession(vamsasSession))
529 "Successfully joined vamsas session " + vamsasSession);
533 System.err.println("WARNING: Failed to join vamsas session "
536 } catch (Exception e)
539 "ERROR: Failed to join vamsas session " + vamsasSession);
542 if (vamsasImport != null)
544 // the Jalview specific remnants can now be imported into the new
545 // session at the user's leisure.
547 "Skipping Push for import of data into existing vamsas session."); // TODO:
552 // desktop.getVamsasApplication().push_update();
557 // Finally, deal with the remaining input data.
562 desktop.setProgressBar(
564 .getString("status.processing_commandline_args"),
565 progress = System.currentTimeMillis());
567 System.out.println("CMD [-open " + file + "] executed successfully!");
569 if (!file.startsWith("http://"))
571 if (!(new File(file)).exists())
573 System.out.println("Can't find " + file);
581 protocol = AppletFormatAdapter.checkProtocol(file);
585 format = new IdentifyFile().identify(file, protocol);
586 } catch (FileFormatException e1)
591 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
595 System.out.println("error");
599 setCurrentAlignFrame(af);
600 data = aparser.getValue("colour", true);
603 data.replaceAll("%20", " ");
605 ColourSchemeI cs = ColourSchemeProperty
606 .getColourScheme(af.getViewport().getAlignment(), data);
611 "CMD [-color " + data + "] executed successfully!");
616 // Must maintain ability to use the groups flag
617 data = aparser.getValue("groups", true);
620 af.parseFeaturesFile(data,
621 AppletFormatAdapter.checkProtocol(data));
622 // System.out.println("Added " + data);
624 "CMD groups[-" + data + "] executed successfully!");
626 data = aparser.getValue("features", true);
629 af.parseFeaturesFile(data,
630 AppletFormatAdapter.checkProtocol(data));
631 // System.out.println("Added " + data);
633 "CMD [-features " + data + "] executed successfully!");
636 data = aparser.getValue("annotations", true);
639 af.loadJalviewDataFile(data, null, null, null);
640 // System.out.println("Added " + data);
642 "CMD [-annotations " + data + "] executed successfully!");
644 // set or clear the sortbytree flag.
645 if (aparser.contains("sortbytree"))
647 af.getViewport().setSortByTree(true);
648 if (af.getViewport().getSortByTree())
650 System.out.println("CMD [-sortbytree] executed successfully!");
653 if (aparser.contains("no-annotation"))
655 af.getViewport().setShowAnnotation(false);
656 if (!af.getViewport().isShowAnnotation())
658 System.out.println("CMD no-annotation executed successfully!");
661 if (aparser.contains("nosortbytree"))
663 af.getViewport().setSortByTree(false);
664 if (!af.getViewport().getSortByTree())
667 .println("CMD [-nosortbytree] executed successfully!");
670 data = aparser.getValue("tree", true);
676 "CMD [-tree " + data + "] executed successfully!");
677 NewickFile nf = new NewickFile(data,
678 AppletFormatAdapter.checkProtocol(data));
680 .setCurrentTree(af.showNewickTree(nf, data).getTree());
681 } catch (IOException ex)
683 System.err.println("Couldn't add tree " + data);
684 ex.printStackTrace(System.err);
687 // TODO - load PDB structure(s) to alignment JAL-629
688 // (associate with identical sequence in alignment, or a specified
691 getFeatures = checkDasArguments(aparser);
692 if (af != null && getFeatures != null)
694 FeatureFetcher ff = startFeatureFetching(getFeatures);
697 while (!ff.allFinished() || af.operationInProgress())
699 // wait around until fetching is finished.
703 } catch (Exception e)
709 getFeatures = null; // have retrieved features - forget them now.
711 if (groovyscript != null)
713 // Execute the groovy script after we've done all the rendering stuff
714 // and before any images or figures are generated.
715 System.out.println("Executing script " + groovyscript);
716 executeGroovyScript(groovyscript, af);
717 System.out.println("CMD groovy[" + groovyscript
718 + "] executed successfully!");
721 String imageName = "unnamed.png";
722 while (aparser.getSize() > 1)
724 String outputFormat = aparser.nextValue();
725 file = aparser.nextValue();
727 if (outputFormat.equalsIgnoreCase("png"))
729 af.createPNG(new File(file));
730 imageName = (new File(file)).getName();
731 System.out.println("Creating PNG image: " + file);
734 else if (outputFormat.equalsIgnoreCase("svg"))
736 File imageFile = new File(file);
737 imageName = imageFile.getName();
738 af.createSVG(imageFile);
739 System.out.println("Creating SVG image: " + file);
742 else if (outputFormat.equalsIgnoreCase("html"))
744 File imageFile = new File(file);
745 imageName = imageFile.getName();
746 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
747 htmlSVG.exportHTML(file);
749 System.out.println("Creating HTML image: " + file);
752 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
756 System.err.println("The output html file must not be null");
761 BioJsHTMLOutput.refreshVersionInfo(
762 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
763 } catch (URISyntaxException e)
767 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
768 bjs.exportHTML(file);
770 .println("Creating BioJS MSA Viwer HTML file: " + file);
773 else if (outputFormat.equalsIgnoreCase("imgMap"))
775 af.createImageMap(new File(file), imageName);
776 System.out.println("Creating image map: " + file);
779 else if (outputFormat.equalsIgnoreCase("eps"))
781 File outputFile = new File(file);
783 "Creating EPS file: " + outputFile.getAbsolutePath());
784 af.createEPS(outputFile);
788 if (af.saveAlignment(file, format))
790 System.out.println("Written alignment in " + format
791 + " format to " + file);
795 System.out.println("Error writing file " + file + " in "
796 + format + " format!!");
801 while (aparser.getSize() > 0)
803 System.out.println("Unknown arg: " + aparser.nextValue());
807 AlignFrame startUpAlframe = null;
808 // We'll only open the default file if the desktop is visible.
810 // ////////////////////
812 if (!headless && file == null && vamsasImport == null
813 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
815 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
816 jalview.bin.Cache.getDefault("www.jalview.org",
817 "http://www.jalview.org")
818 + "/examples/exampleFile_2_7.jar");
820 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
822 // hardwire upgrade of the startup file
823 file.replace("_2_3.jar", "_2_7.jar");
824 // and remove the stale setting
825 jalview.bin.Cache.removeProperty("STARTUP_FILE");
828 protocol = DataSourceType.FILE;
830 if (file.indexOf("http:") > -1)
832 protocol = DataSourceType.URL;
835 if (file.endsWith(".jar"))
837 format = FileFormat.Jalview;
843 format = new IdentifyFile().identify(file, protocol);
844 } catch (FileFormatException e)
850 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
852 getFeatures = checkDasArguments(aparser);
853 // extract groovy arguments before anything else.
855 // If the user has specified features to be retrieved,
856 // or a groovy script to be executed, do them if they
857 // haven't been done already
858 // fetch features for the default alignment
859 if (getFeatures != null)
861 if (startUpAlframe != null)
863 startFeatureFetching(getFeatures);
866 // Once all other stuff is done, execute any groovy scripts (in order)
867 if (groovyscript != null)
869 if (Cache.groovyJarsPresent())
871 System.out.println("Executing script " + groovyscript);
872 executeGroovyScript(groovyscript, startUpAlframe);
877 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
881 // and finally, turn off batch mode indicator - if the desktop still exists
886 desktop.setProgressBar(null, progress);
888 desktop.setInBatchMode(false);
892 private static void showUsage()
895 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
896 + "-nodisplay\tRun Jalview without User Interface.\n"
897 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
898 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
899 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
900 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
901 + "-features FILE\tUse the given file to mark features on the alignment.\n"
902 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
903 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
904 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
905 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
906 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
907 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
908 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
909 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
910 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
911 + "-png FILE\tCreate PNG image FILE from alignment.\n"
912 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
913 + "-html FILE\tCreate HTML file from alignment.\n"
914 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
915 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
916 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
917 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
918 + "-noquestionnaire\tTurn off questionnaire check.\n"
919 + "-nonews\tTurn off check for Jalview news.\n"
920 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
921 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
923 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
924 // after all other properties files have been read\n\t
925 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
926 // passed in correctly)"
927 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
928 + "-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"
929 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
930 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
931 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
933 // "-vdoc vamsas-document\tImport vamsas document into new
934 // session or join existing session with same URN\n"
935 // + "-vses vamsas-session\tJoin session with given URN\n"
936 + "-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"
937 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
940 private static void startUsageStats(final Desktop desktop)
943 * start a User Config prompt asking if we can log usage statistics.
945 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
946 "USAGESTATS", "Jalview Usage Statistics",
947 "Do you want to help make Jalview better by enabling "
948 + "the collection of usage statistics with Google Analytics ?"
949 + "\n\n(you can enable or disable usage tracking in the preferences)",
956 "Initialising googletracker for usage stats.");
957 Cache.initGoogleTracker();
958 Cache.log.debug("Tracking enabled.");
965 Cache.log.debug("Not enabling Google Tracking.");
968 desktop.addDialogThread(prompter);
972 * Locate the given string as a file and pass it to the groovy interpreter.
974 * @param groovyscript
975 * the script to execute
976 * @param jalviewContext
977 * the Jalview Desktop object passed in to the groovy binding as the
980 private void executeGroovyScript(String groovyscript, AlignFrame af)
983 * for scripts contained in files
990 if (groovyscript.trim().equals("STDIN"))
992 // read from stdin into a tempfile and execute it
995 tfile = File.createTempFile("jalview", "groovy");
996 PrintWriter outfile = new PrintWriter(
997 new OutputStreamWriter(new FileOutputStream(tfile)));
998 BufferedReader br = new BufferedReader(
999 new InputStreamReader(System.in));
1001 while ((line = br.readLine()) != null)
1003 outfile.write(line + "\n");
1009 } catch (Exception ex)
1011 System.err.println("Failed to read from STDIN into tempfile "
1012 + ((tfile == null) ? "(tempfile wasn't created)"
1013 : tfile.toString()));
1014 ex.printStackTrace();
1019 sfile = tfile.toURI().toURL();
1020 } catch (Exception x)
1023 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1025 x.printStackTrace();
1033 sfile = new URI(groovyscript).toURL();
1034 } catch (Exception x)
1036 tfile = new File(groovyscript);
1037 if (!tfile.exists())
1039 System.err.println("File '" + groovyscript + "' does not exist.");
1042 if (!tfile.canRead())
1044 System.err.println("File '" + groovyscript + "' cannot be read.");
1047 if (tfile.length() < 1)
1049 System.err.println("File '" + groovyscript + "' is empty.");
1054 sfile = tfile.getAbsoluteFile().toURI().toURL();
1055 } catch (Exception ex)
1057 System.err.println("Failed to create a file URL for "
1058 + tfile.getAbsoluteFile());
1065 Map<String, Object> vbinding = new HashMap<>();
1066 vbinding.put("Jalview", this);
1069 vbinding.put("currentAlFrame", af);
1071 Binding gbinding = new Binding(vbinding);
1072 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1073 gse.run(sfile.toString(), gbinding);
1074 if ("STDIN".equals(groovyscript))
1076 // delete temp file that we made -
1077 // only if it was successfully executed
1080 } catch (Exception e)
1082 System.err.println("Exception Whilst trying to execute file " + sfile
1083 + " as a groovy script.");
1084 e.printStackTrace(System.err);
1090 * Check commandline for any das server definitions or any fetchfrom switches
1092 * @return vector of DAS source nicknames to retrieve from
1094 private static Vector<String> checkDasArguments(ArgsParser aparser)
1096 Vector<String> source = null;
1098 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
1099 while ((data = aparser.getValue("dasserver", true)) != null)
1101 String nickname = null;
1103 int pos = data.indexOf('=');
1104 // determine capabilities
1107 nickname = data.substring(0, pos);
1109 url = data.substring(pos + 1);
1110 if (url != null && (url.startsWith("http:")
1111 || url.startsWith("sequence:http:")))
1113 if (nickname == null)
1117 if (locsources == null)
1125 locsources = locsources + nickname + "|" + url;
1127 "NOTE! dasserver parameter not yet really supported (got args of "
1128 + nickname + "|" + url);
1131 source = new Vector<>();
1133 source.addElement(nickname);
1136 "CMD [-dasserver " + data + "] executed successfully!");
1137 } // loop until no more server entries are found.
1138 if (locsources != null && locsources.indexOf('|') > -1)
1140 Cache.log.debug("Setting local source list in properties file to:\n"
1142 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
1144 while ((data = aparser.getValue("fetchfrom", true)) != null)
1146 System.out.println("adding source '" + data + "'");
1149 source = new Vector<>();
1151 source.addElement(data);
1157 * start a feature fetcher for every alignment frame
1161 private FeatureFetcher startFeatureFetching(
1162 final Vector<String> dasSources)
1164 FeatureFetcher ff = new FeatureFetcher();
1165 AlignFrame afs[] = Desktop.getAlignFrames();
1166 if (afs == null || afs.length == 0)
1170 for (int i = 0; i < afs.length; i++)
1172 ff.addFetcher(afs[i], dasSources);
1177 public static boolean isHeadlessMode()
1179 String isheadless = System.getProperty("java.awt.headless");
1180 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1187 public AlignFrame[] getAlignFrames()
1189 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1190 : Desktop.getAlignFrames();
1195 * Quit method delegates to Desktop.quit - unless running in headless mode
1196 * when it just ends the JVM
1200 if (desktop != null)
1210 public static AlignFrame getCurrentAlignFrame()
1212 return Jalview.currentAlignFrame;
1215 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1217 Jalview.currentAlignFrame = currentAlignFrame;