+ Console.warn("Error when running commands");
+ }
+
+ // Check if JVM and compile version might cause problems and log if it
+ // might.
+ if (headless && !Platform.isJS() && !LaunchUtils.checkJavaVersion())
+ {
+ Console.warn("The Java version being used (Java "
+ + LaunchUtils.getJavaVersion()
+ + ") may lead to problems. This installation of Jalview should be used with Java "
+ + LaunchUtils.getJavaCompileVersion() + ".");
+ }
+
+ String file = null, data = null;
+
+ FileFormatI format = null;
+
+ DataSourceType protocol = null;
+
+ FileLoader fileLoader = new FileLoader(!headless);
+
+ String groovyscript = null; // script to execute after all loading is
+ // completed one way or another
+ // extract groovy argument and execute if necessary
+ groovyscript = aparser.getValue("groovy", true);
+ file = aparser.getValue("open", true);
+
+ if (file == null && desktop == null && !commandsSuccess)
+ {
+ Jalview.exit("No files to open!", 1);
+ }
+
+ long progress = -1;
+ // Finally, deal with the remaining input data.
+ if (file != null)
+ {
+ if (!headless)
+ {
+ desktop.setProgressBar(
+ MessageManager
+ .getString("status.processing_commandline_args"),
+ progress = System.currentTimeMillis());
+ }
+ System.out.println("CMD [-open " + file + "] executed successfully!");
+
+ if (!Platform.isJS())
+ /**
+ * ignore in JavaScript -- can't just file existence - could load it?
+ *
+ * @j2sIgnore
+ */
+ {
+ if (!HttpUtils.startsWithHttpOrHttps(file))
+ {
+ if (!(new File(file)).exists())
+ {
+ if (headless)
+ {
+ Jalview.exit(
+ "Can't find file '" + file + "' in headless mode", 1);
+ }
+ Console.warn("Can't find file'" + file + "'");
+ }
+ }
+ }
+
+ protocol = AppletFormatAdapter.checkProtocol(file);
+
+ try
+ {
+ format = new IdentifyFile().identify(file, protocol);
+ } catch (FileFormatException e1)
+ {
+ // TODO ?
+ }
+
+ AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
+ format);
+ if (af == null)
+ {
+ System.out.println("error");
+ }
+ else
+ {
+ setCurrentAlignFrame(af);
+ data = aparser.getValue("colour", true);
+ if (data != null)
+ {
+ data.replaceAll("%20", " ");
+
+ ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
+ af.getViewport(), af.getViewport().getAlignment(), data);
+
+ if (cs != null)
+ {
+ System.out.println(
+ "CMD [-colour " + data + "] executed successfully!");
+ }
+ af.changeColour(cs);
+ }
+
+ // Must maintain ability to use the groups flag
+ data = aparser.getValue("groups", true);
+ if (data != null)
+ {
+ af.parseFeaturesFile(data,
+ AppletFormatAdapter.checkProtocol(data));
+ // System.out.println("Added " + data);
+ System.out.println(
+ "CMD groups[-" + data + "] executed successfully!");
+ }
+ data = aparser.getValue("features", true);
+ if (data != null)
+ {
+ af.parseFeaturesFile(data,
+ AppletFormatAdapter.checkProtocol(data));
+ // System.out.println("Added " + data);
+ System.out.println(
+ "CMD [-features " + data + "] executed successfully!");
+ }
+
+ data = aparser.getValue("annotations", true);
+ if (data != null)
+ {
+ af.loadJalviewDataFile(data, null, null, null);
+ // System.out.println("Added " + data);
+ System.out.println(
+ "CMD [-annotations " + data + "] executed successfully!");
+ }
+ // set or clear the sortbytree flag.
+ if (aparser.contains("sortbytree"))
+ {
+ af.getViewport().setSortByTree(true);
+ if (af.getViewport().getSortByTree())
+ {
+ System.out.println("CMD [-sortbytree] executed successfully!");
+ }
+ }
+ if (aparser.contains("no-annotation"))
+ {
+ af.getViewport().setShowAnnotation(false);
+ if (!af.getViewport().isShowAnnotation())
+ {
+ System.out.println("CMD no-annotation executed successfully!");
+ }
+ }
+ if (aparser.contains("nosortbytree"))
+ {
+ af.getViewport().setSortByTree(false);
+ if (!af.getViewport().getSortByTree())
+ {
+ System.out
+ .println("CMD [-nosortbytree] executed successfully!");
+ }
+ }
+ data = aparser.getValue("tree", true);
+ if (data != null)
+ {
+ try
+ {
+ System.out.println(
+ "CMD [-tree " + data + "] executed successfully!");
+ NewickFile nf = new NewickFile(data,
+ AppletFormatAdapter.checkProtocol(data));
+ af.getViewport()
+ .setCurrentTree(af.showNewickTree(nf, data).getTree());
+ } catch (IOException ex)
+ {
+ System.err.println("Couldn't add tree " + data);
+ ex.printStackTrace(System.err);
+ }
+ }
+ // TODO - load PDB structure(s) to alignment JAL-629
+ // (associate with identical sequence in alignment, or a specified
+ // sequence)
+ if (groovyscript != null)
+ {
+ // Execute the groovy script after we've done all the rendering stuff
+ // and before any images or figures are generated.
+ System.out.println("Executing script " + groovyscript);
+ executeGroovyScript(groovyscript, af);
+ System.out.println("CMD groovy[" + groovyscript
+ + "] executed successfully!");
+ groovyscript = null;
+ }
+ String imageName = "unnamed.png";
+ while (aparser.getSize() > 1)
+ {
+ String outputFormat = aparser.nextValue();
+ file = aparser.nextValue();
+
+ if (outputFormat.equalsIgnoreCase("png"))
+ {
+ af.createPNG(new File(file));
+ imageName = (new File(file)).getName();
+ System.out.println("Creating PNG image: " + file);
+ continue;
+ }
+ else if (outputFormat.equalsIgnoreCase("svg"))
+ {
+ File imageFile = new File(file);
+ imageName = imageFile.getName();
+ af.createSVG(imageFile);
+ System.out.println("Creating SVG image: " + file);
+ continue;
+ }
+ else if (outputFormat.equalsIgnoreCase("html"))
+ {
+ File imageFile = new File(file);
+ imageName = imageFile.getName();
+ HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
+ htmlSVG.exportHTML(file);
+
+ System.out.println("Creating HTML image: " + file);
+ continue;
+ }
+ else if (outputFormat.equalsIgnoreCase("biojsmsa"))
+ {
+ if (file == null)
+ {
+ System.err.println("The output html file must not be null");
+ return;
+ }
+ try
+ {
+ BioJsHTMLOutput.refreshVersionInfo(
+ BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
+ } catch (URISyntaxException e)
+ {
+ e.printStackTrace();
+ }
+ BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
+ bjs.exportHTML(file);
+ System.out
+ .println("Creating BioJS MSA Viwer HTML file: " + file);
+ continue;
+ }
+ else if (outputFormat.equalsIgnoreCase("imgMap"))
+ {
+ af.createImageMap(new File(file), imageName);
+ System.out.println("Creating image map: " + file);
+ continue;
+ }
+ else if (outputFormat.equalsIgnoreCase("eps"))
+ {
+ File outputFile = new File(file);
+ System.out.println(
+ "Creating EPS file: " + outputFile.getAbsolutePath());
+ af.createEPS(outputFile);
+ continue;
+ }
+ FileFormatI outFormat = null;
+ try
+ {
+ outFormat = FileFormats.getInstance().forName(outputFormat);
+ } catch (Exception formatP)
+ {
+ System.out.println("Couldn't parse " + outFormat
+ + " as a valid Jalview format string.");
+ }
+ if (outFormat != null)
+ {
+ if (!outFormat.isWritable())
+ {
+ System.out.println(
+ "This version of Jalview does not support alignment export as "
+ + outputFormat);
+ }
+ else
+ {
+ af.saveAlignment(file, outFormat);
+ if (af.isSaveAlignmentSuccessful())
+ {
+ System.out.println("Written alignment in "
+ + outFormat.getName() + " format to " + file);
+ }
+ else
+ {
+ System.out.println("Error writing file " + file + " in "
+ + outFormat.getName() + " format!!");
+ }
+ }
+ }
+
+ }
+
+ while (aparser.getSize() > 0)
+ {
+ System.out.println("Unknown arg: " + aparser.nextValue());
+ }
+ }
+ }
+
+ AlignFrame startUpAlframe = null;
+ // We'll only open the default file if the desktop is visible.
+ // And the user
+ // ////////////////////
+
+ if (!Platform.isJS() && !headless && file == null
+ && Cache.getDefault("SHOW_STARTUP_FILE", true)
+ && !cmds.commandArgsProvided())
+ // don't open the startup file if command line args have been processed
+ // (&& !Commands.commandArgsProvided())
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
+ {
+ file = Cache.getDefault("STARTUP_FILE",
+ Cache.getDefault("www.jalview.org", "https://www.jalview.org")
+ + "/examples/exampleFile_2_7.jvp");
+ if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
+ || file.equals(
+ "http://www.jalview.org/examples/exampleFile_2_7.jar"))
+ {
+ file.replace("http:", "https:");
+ // hardwire upgrade of the startup file
+ file.replace("_2_3", "_2_7");
+ file.replace("2_7.jar", "2_7.jvp");
+ // and remove the stale setting
+ Cache.removeProperty("STARTUP_FILE");
+ }
+
+ protocol = AppletFormatAdapter.checkProtocol(file);
+
+ if (file.endsWith(".jar"))
+ {
+ format = FileFormat.Jalview;
+ }
+ else
+ {
+ try
+ {
+ format = new IdentifyFile().identify(file, protocol);
+ } catch (FileFormatException e)
+ {
+ // TODO what?
+ }
+ }
+
+ startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
+ format);
+ // don't ask to save when quitting if only the startup file has been
+ // opened
+ Console.debug("Resetting up-to-date flag for startup file");
+ startUpAlframe.getViewport().setSavedUpToDate(true);
+ // extract groovy arguments before anything else.
+ }
+
+ // Once all other stuff is done, execute any groovy scripts (in order)
+ if (groovyscript != null)
+ {
+ if (Cache.groovyJarsPresent())
+ {
+ System.out.println("Executing script " + groovyscript);
+ executeGroovyScript(groovyscript, startUpAlframe);
+ }
+ else
+ {
+ System.err.println(
+ "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
+ + groovyscript);
+ }
+ }
+ // and finally, turn off batch mode indicator - if the desktop still exists
+ if (desktop != null)
+ {
+ if (progress != -1)
+ {
+ desktop.setProgressBar(null, progress);
+ }
+ desktop.setInBatchMode(false);