+ Jalview.exit("Could not open any files in headless mode",
+ ExitCode.NO_FILES);
+ }
+ else
+ {
+ Console.info("No more files to open");
+ }
+ }
+ if (progressBarSet && desktop != null)
+ desktop.setProgressBar(null, progress);
+
+ }
+
+ // open the structure (from same PDB file or given PDBfile)
+ if (!avm.getBoolean(Arg.NOSTRUCTURE))
+ {
+ AlignFrame af = afMap.get(id);
+ if (avm.containsArg(Arg.STRUCTURE))
+ {
+ commandArgsProvided = true;
+ for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
+ {
+ String val = av.getValue();
+ SubVals subVals = av.getSubVals();
+ SequenceI seq = getSpecifiedSequence(af, avm, av);
+ if (seq == null)
+ {
+ // Could not find sequence from subId, let's assume the first
+ // sequence in the alignframe
+ AlignmentI al = af.getCurrentView().getAlignment();
+ seq = al.getSequenceAt(0);
+ }
+
+ if (seq == null)
+ {
+ addWarn("Could not find sequence for argument "
+ + Arg.STRUCTURE.argString() + "=" + val);
+ continue;
+ }
+ File structureFile = null;
+ if (subVals.getContent() != null
+ && subVals.getContent().length() != 0)
+ {
+ structureFile = new File(subVals.getContent());
+ Console.debug("Using structure file (from argument) '"
+ + structureFile.getAbsolutePath() + "'");
+ }
+ // TRY THIS
+ /*
+ * PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+ * .associatePdbWithSeq(selectedPdbFileName, DataSourceType.FILE,
+ * selectedSequence, true, Desktop.instance);
+ *
+ * sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, new
+ * SequenceI[] { selectedSequence });
+ *
+ */
+ /* THIS DOESN'T WORK */
+ else if (seq.getAllPDBEntries() != null
+ && seq.getAllPDBEntries().size() > 0)
+ {
+ structureFile = new File(
+ seq.getAllPDBEntries().elementAt(0).getFile());
+ Console.debug("Using structure file (from sequence) '"
+ + structureFile.getAbsolutePath() + "'");
+ }
+
+ if (structureFile == null)
+ {
+ addWarn("Not provided structure file with '" + val + "'");
+ continue;
+ }
+
+ if (!structureFile.exists())
+ {
+ addWarn("Structure file '" + structureFile.getAbsoluteFile()
+ + "' not found.");
+ continue;
+ }
+
+ Console.debug("Using structure file "
+ + structureFile.getAbsolutePath());
+
+ // open structure view
+ AlignmentPanel ap = af.alignPanel;
+ if (headless)
+ {
+ Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
+ StructureViewer.ViewerType.JMOL.toString());
+ }
+
+ String structureFilepath = structureFile.getAbsolutePath();
+
+ // get PAEMATRIX file and label from subvals or Arg.PAEMATRIX
+ String paeFilepath = ArgParser
+ .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
+ Arg.PAEMATRIX, Position.AFTER, av, subVals, null,
+ null, null);
+ if (paeFilepath != null)
+ {
+ File paeFile = new File(paeFilepath);
+
+ try
+ {
+ paeFilepath = paeFile.getCanonicalPath();
+ } catch (IOException e)
+ {
+ paeFilepath = paeFile.getAbsolutePath();
+ addWarn("Problem with the PAE file path: '"
+ + paeFile.getPath() + "'");
+ }
+ }
+
+ // showing annotations from structure file or not
+ boolean ssFromStructure = ArgParser.getFromSubValArgOrPref(avm,
+ Arg.SHOWSSANNOTATIONS, subVals, null, "STRUCT_FROM_PDB",
+ true);
+
+ // get TEMPFAC type from subvals or Arg.TEMPFAC in case user Adds
+ // reference annotations
+ String tftString = ArgParser
+ .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
+ Arg.TEMPFAC, Position.AFTER, av, subVals, null,
+ null, null);
+ boolean notempfac = ArgParser.getFromSubValArgOrPref(avm,
+ Arg.NOTEMPFAC, subVals, null, "ADD_TEMPFACT_ANN", false,
+ true);
+ TFType tft = notempfac ? null : TFType.DEFAULT;
+ if (tftString != null && !notempfac)
+ {
+ // get kind of temperature factor annotation
+ try
+ {
+ tft = TFType.valueOf(tftString.toUpperCase(Locale.ROOT));
+ Console.debug("Obtained Temperature Factor type of '" + tft
+ + "' for structure '" + structureFilepath + "'");
+ } catch (IllegalArgumentException e)
+ {
+ // Just an error message!
+ StringBuilder sb = new StringBuilder().append("Cannot set ")
+ .append(Arg.TEMPFAC.argString()).append(" to '")
+ .append(tft)
+ .append("', ignoring. Valid values are: ");
+ Iterator<TFType> it = Arrays.stream(TFType.values())
+ .iterator();
+ while (it.hasNext())
+ {
+ sb.append(it.next().toString().toLowerCase(Locale.ROOT));
+ if (it.hasNext())
+ sb.append(", ");
+ }
+ addWarn(sb.toString());
+ }
+ }
+
+ String sViewer = ArgParser.getFromSubValArgOrPref(avm,
+ Arg.STRUCTUREVIEWER, Position.AFTER, av, subVals, null,
+ null, "jmol");
+ ViewerType viewerType = ViewerType.getFromString(sViewer);
+
+ // TODO use ssFromStructure
+ StructureViewer sv = StructureChooser
+ .openStructureFileForSequence(null, null, ap, seq, false,
+ structureFilepath, tft, paeFilepath, false,
+ ssFromStructure, false, viewerType);
+
+ if (sv == null)
+ {
+ addError("Failed to import and open structure view for file '"
+ + structureFile + "'.");
+ continue;
+ }
+ try
+ {
+ long tries = 1000;
+ while (sv.isBusy() && tries > 0)
+ {
+ Thread.sleep(25);
+ if (sv.isBusy())
+ {
+ tries--;
+ Console.debug(
+ "Waiting for viewer for " + structureFilepath);
+ }
+ }
+ if (tries == 0 && sv.isBusy())
+ {
+ addWarn("Gave up waiting for structure viewer to load file '"
+ + structureFile
+ + "'. Something may have gone wrong.");
+ }
+ } catch (Exception x)
+ {
+ addError("Exception whilst waiting for structure viewer "
+ + structureFilepath, x);
+ isError = true;
+ }
+
+ // add StructureViewer to svMap list
+ if (svMap == null)
+ {
+ svMap = new HashMap<>();
+ }
+ if (svMap.get(id) == null)
+ {
+ svMap.put(id, new ArrayList<>());
+ }
+ svMap.get(id).add(sv);
+
+ Console.debug(
+ "Successfully opened viewer for " + structureFilepath);
+ String structureImageFilename = ArgParser.getValueFromSubValOrArg(
+ avm, av, Arg.STRUCTUREIMAGE, subVals);
+ if (sv != null && structureImageFilename != null)
+ {
+ ArgValue siAv = avm.getClosestNextArgValueOfArg(av,
+ Arg.STRUCTUREIMAGE);
+ SubVals sisv = null;
+ if (structureImageFilename.equals(siAv.getValue()))
+ {
+ sisv = siAv.getSubVals();
+ }
+ File structureImageFile = new File(structureImageFilename);
+ String width = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGEWIDTH, sisv);
+ String height = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGEHEIGHT, sisv);
+ String scale = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGESCALE, sisv);
+ String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGETEXTRENDERER, sisv);
+ String typeS = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.STRUCTUREIMAGETYPE, sisv);
+ if (typeS == null || typeS.length() == 0)
+ {
+ typeS = FileUtils.getExtension(structureImageFile);
+ }
+ TYPE imageType;
+ try
+ {
+ imageType = Enum.valueOf(TYPE.class,
+ typeS.toUpperCase(Locale.ROOT));
+ } catch (IllegalArgumentException e)
+ {
+ addWarn("Do not know image format '" + typeS
+ + "', using PNG");
+ imageType = TYPE.PNG;
+ }
+ BitmapImageSizing userBis = ImageMaker
+ .parseScaleWidthHeightStrings(scale, width, height);
+ // TODO MAKE THIS VIEWER INDEPENDENT!!
+ switch (StructureViewer.getViewerType())
+ {
+ case JMOL:
+ JalviewStructureDisplayI sview = sv
+ .getJalviewStructureDisplay();
+ if (sview instanceof AppJmol)
+ {
+ AppJmol jmol = (AppJmol) sview;
+ try
+ {
+ boolean success = this.checksBeforeWritingToFile(avm,
+ subVals, false, structureImageFilename,
+ "structure image", isError);
+ if (!success)
+ {
+ continue;
+ }
+
+ Console.debug("Rendering image to " + structureImageFile);
+ jmol.makePDBImage(structureImageFile, imageType, renderer,
+ userBis);
+ Console.debug("Finished Rendering image to "
+ + structureImageFile);
+
+ } catch (ImageOutputException ioexc)
+ {
+ addError("Unexpected error whilst exporting image to "
+ + structureImageFile, ioexc);
+ isError = true;
+ continue;
+ }
+
+ }
+ break;
+ default:
+ addWarn("Cannot export image for structure viewer "
+ + sv.getViewerType() + " yet");
+ continue;
+ }
+ }
+ }
+ }
+ }
+
+ if (wrap)
+ {
+ AlignFrame af = afMap.get(id);
+ if (af != null)
+ {
+ af.setWrapFormat(wrap, true);
+ }
+ }
+
+ /*
+ boolean doShading = avm.getBoolean(Arg.TEMPFAC_SHADING);
+ if (doShading)
+ {
+ AlignFrame af = afMap.get(id);
+ for (AlignmentAnnotation aa : af.alignPanel.getAlignment()
+ .findAnnotation(PDBChain.class.getName().toString()))
+ {
+ AnnotationColourGradient acg = new AnnotationColourGradient(aa,
+ af.alignPanel.av.getGlobalColourScheme(), 0);
+ acg.setSeqAssociated(true);
+ af.changeColour(acg);
+ Console.info("Changed colour " + acg.toString());
+ }
+ }
+ */
+
+ return theseArgsWereParsed && !isError;
+ }
+
+ protected void processGroovyScript(String id)
+ {
+ ArgValuesMap avm = argParser.getLinkedArgs(id);
+ AlignFrame af = afMap.get(id);
+
+ if (af == null)
+ {
+ addWarn("Did not have an alignment window for id=" + id);
+ return;
+ }
+
+ if (avm.containsArg(Arg.GROOVY))
+ {
+ String groovyscript = avm.getValue(Arg.GROOVY);
+ if (groovyscript != null)
+ {
+ // Execute the groovy script after we've done all the rendering stuff
+ // and before any images or figures are generated.
+ Console.info("Executing script " + groovyscript);
+ Jalview.getInstance().executeGroovyScript(groovyscript, af);
+ }
+ }
+ }
+
+ protected boolean processImages(String id)
+ {
+ ArgValuesMap avm = argParser.getLinkedArgs(id);
+ AlignFrame af = afMap.get(id);
+
+ if (af == null)
+ {
+ addWarn("Did not have an alignment window for id=" + id);
+ return false;
+ }
+
+ Boolean isError = Boolean.valueOf(false);
+ if (avm.containsArg(Arg.IMAGE))
+ {
+ for (ArgValue av : avm.getArgValueList(Arg.IMAGE))
+ {
+ String val = av.getValue();
+ SubVals subVal = av.getSubVals();
+ String fileName = subVal.getContent();
+ File file = new File(fileName);
+ String name = af.getName();
+ String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.TEXTRENDERER, subVal);
+ if (renderer == null)
+ renderer = "text";
+ String type = "png"; // default
+
+ String scale = ArgParser.getValueFromSubValOrArg(avm, av, Arg.SCALE,
+ subVal);
+ String width = ArgParser.getValueFromSubValOrArg(avm, av, Arg.WIDTH,
+ subVal);
+ String height = ArgParser.getValueFromSubValOrArg(avm, av,
+ Arg.HEIGHT, subVal);
+ BitmapImageSizing userBis = ImageMaker
+ .parseScaleWidthHeightStrings(scale, width, height);
+
+ type = ArgParser.getValueFromSubValOrArg(avm, av, Arg.TYPE, subVal);
+ if (type == null && fileName != null)
+ {
+ for (String ext : new String[] { "svg", "png", "html", "eps" })
+ {
+ if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
+ {
+ type = ext;
+ }
+ }
+ }
+ // for moment we disable JSON export
+ Cache.setPropsAreReadOnly(true);
+ Cache.setProperty("EXPORT_EMBBED_BIOJSON", "false");
+
+ Console.info("Writing " + file);
+
+ boolean success = checksBeforeWritingToFile(avm, subVal, false,
+ fileName, "image", isError);
+ if (!success)
+ {
+ continue;
+ }
+
+ try
+ {
+ switch (type)
+ {
+
+ case "svg":
+ Console.debug("Outputting type '" + type + "' to " + fileName);
+ af.createSVG(file, renderer);
+ break;
+
+ case "png":
+ Console.debug("Outputting type '" + type + "' to " + fileName);
+ af.createPNG(file, null, userBis);
+ break;
+
+ case "html":
+ Console.debug("Outputting type '" + type + "' to " + fileName);
+ HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
+ htmlSVG.exportHTML(fileName, renderer);
+ break;
+
+ case "biojs":
+ Console.debug(
+ "Outputting BioJS MSA Viwer HTML file: " + fileName);
+ try
+ {
+ BioJsHTMLOutput.refreshVersionInfo(
+ BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
+ } catch (URISyntaxException e)
+ {
+ e.printStackTrace();
+ }
+ BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
+ bjs.exportHTML(fileName);
+ break;
+
+ case "eps":
+ Console.debug("Outputting EPS file: " + fileName);
+ af.createEPS(file, renderer);
+ break;
+
+ case "imagemap":
+ Console.debug("Outputting ImageMap file: " + fileName);
+ af.createImageMap(file, name);
+ break;
+
+ default:
+ addWarn(Arg.IMAGE.argString() + " type '" + type
+ + "' not known. Ignoring");
+ break;
+ }
+ } catch (Exception ioex)
+ {
+ addError("Unexpected error during export to '" + fileName + "'",
+ ioex);
+ isError = true;