4 import java.io.IOException;
5 import java.net.URISyntaxException;
6 import java.util.ArrayList;
7 import java.util.Arrays;
8 import java.util.Collections;
9 import java.util.EnumSet;
10 import java.util.HashMap;
11 import java.util.Iterator;
12 import java.util.List;
13 import java.util.Locale;
16 import jalview.analysis.AlignmentUtils;
17 import jalview.api.structures.JalviewStructureDisplayI;
18 import jalview.bin.argparser.Arg;
19 import jalview.bin.argparser.ArgParser;
20 import jalview.bin.argparser.ArgParser.Position;
21 import jalview.bin.argparser.ArgValue;
22 import jalview.bin.argparser.ArgValuesMap;
23 import jalview.bin.argparser.SubVals;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.SequenceI;
26 import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder;
27 import jalview.gui.AlignFrame;
28 import jalview.gui.AlignmentPanel;
29 import jalview.gui.AppJmol;
30 import jalview.gui.Desktop;
31 import jalview.gui.Preferences;
32 import jalview.gui.StructureChooser;
33 import jalview.gui.StructureViewer;
34 import jalview.gui.StructureViewer.ViewerType;
35 import jalview.io.AppletFormatAdapter;
36 import jalview.io.BackupFiles;
37 import jalview.io.BioJsHTMLOutput;
38 import jalview.io.DataSourceType;
39 import jalview.io.FileFormat;
40 import jalview.io.FileFormatException;
41 import jalview.io.FileFormatI;
42 import jalview.io.FileFormats;
43 import jalview.io.FileLoader;
44 import jalview.io.HtmlSvgOutput;
45 import jalview.io.IdentifyFile;
46 import jalview.io.NewickFile;
47 import jalview.io.exceptions.ImageOutputException;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.schemes.ColourSchemeProperty;
50 import jalview.structure.StructureImportSettings.TFType;
51 import jalview.structure.StructureSelectionManager;
52 import jalview.util.FileUtils;
53 import jalview.util.HttpUtils;
54 import jalview.util.ImageMaker;
55 import jalview.util.ImageMaker.TYPE;
56 import jalview.util.MessageManager;
57 import jalview.util.Platform;
58 import jalview.util.imagemaker.BitmapImageSizing;
64 private boolean headless;
66 private ArgParser argParser;
68 private Map<String, AlignFrame> afMap;
70 private boolean commandArgsProvided = false;
72 private boolean argsWereParsed = false;
74 public Commands(ArgParser argparser, boolean headless)
76 this(Desktop.instance, argparser, headless);
79 public Commands(Desktop d, ArgParser argparser, boolean h)
81 argParser = argparser;
84 afMap = new HashMap<>();
85 if (argparser != null)
87 processArgs(argparser, headless);
91 private boolean processArgs(ArgParser argparser, boolean h)
93 argParser = argparser;
95 boolean theseArgsWereParsed = false;
97 if (argParser != null && argParser.getLinkedIds() != null)
99 for (String id : argParser.getLinkedIds())
101 ArgValuesMap avm = argParser.getLinkedArgs(id);
102 theseArgsWereParsed = true;
103 theseArgsWereParsed &= processLinked(id);
104 processGroovyScript(id);
105 boolean processLinkedOkay = theseArgsWereParsed;
107 // wait around until alignFrame isn't busy
108 AlignFrame af=afMap.get(id);
109 while (af!=null && af.getViewport().isCalcInProgress())
113 } catch (Exception q) {};
116 theseArgsWereParsed &= processImages(id);
117 if (processLinkedOkay)
118 theseArgsWereParsed &= processOutput(id);
121 if (avm.getBoolean(Arg.CLOSE))
126 af.closeMenuItem_actionPerformed(true);
133 if (argParser.getBoolean(Arg.QUIT))
135 Jalview.getInstance().quit();
138 // carry on with jalview.bin.Jalview
139 argsWereParsed = theseArgsWereParsed;
140 return argsWereParsed;
143 public boolean commandArgsProvided()
145 return commandArgsProvided;
148 public boolean argsWereParsed()
150 return argsWereParsed;
153 protected boolean processUnlinked(String id)
155 return processLinked(id);
158 protected boolean processLinked(String id)
160 boolean theseArgsWereParsed = false;
161 ArgValuesMap avm = argParser.getLinkedArgs(id);
166 * // script to execute after all loading is completed one way or another String
167 * groovyscript = m.get(Arg.GROOVY) == null ? null :
168 * m.get(Arg.GROOVY).getValue(); String file = m.get(Arg.OPEN) == null ? null :
169 * m.get(Arg.OPEN).getValue(); String data = null; FileFormatI format = null;
170 * DataSourceType protocol = null;
172 if (avm.containsArg(Arg.APPEND) || avm.containsArg(Arg.OPEN))
174 commandArgsProvided = true;
177 boolean first = true;
178 boolean progressBarSet = false;
180 // Combine the APPEND and OPEN files into one list, along with whether it
181 // was APPEND or OPEN
182 List<ArgValue> openAvList = new ArrayList<>();
183 openAvList.addAll(avm.getArgValueList(Arg.OPEN));
184 openAvList.addAll(avm.getArgValueList(Arg.APPEND));
185 // sort avlist based on av.getArgIndex()
186 Collections.sort(openAvList);
187 for (ArgValue av : openAvList)
190 SubVals sv = av.getSubVals();
191 String openFile = av.getValue();
192 if (openFile == null)
195 theseArgsWereParsed = true;
199 if (!headless && desktop != null)
201 desktop.setProgressBar(
202 MessageManager.getString(
203 "status.processing_commandline_args"),
204 progress = System.currentTimeMillis());
205 progressBarSet = true;
209 if (!Platform.isJS())
211 * ignore in JavaScript -- can't just file existence - could load it?
216 if (!HttpUtils.startsWithHttpOrHttps(openFile))
218 if (!(new File(openFile)).exists())
220 Console.warn("Can't find file '" + openFile + "'");
225 DataSourceType protocol = AppletFormatAdapter
226 .checkProtocol(openFile);
228 FileFormatI format = null;
231 format = new IdentifyFile().identify(openFile, protocol);
232 } catch (FileFormatException e1)
234 Console.error("Unknown file format for '" + openFile + "'");
238 // When to open a new AlignFrame
239 if (af == null || "true".equals(av.getSubVal("new"))
240 || a == Arg.OPEN || format == FileFormat.Jalview)
244 Jalview.testoutput(argParser, Arg.OPEN, "examples/uniref50.fa",
249 "Opening '" + openFile + "' in new alignment frame");
250 FileLoader fileLoader = new FileLoader(!headless);
252 af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol,
256 boolean wrap = ArgParser.getFromSubValArgOrPref(avm, Arg.WRAP, sv,
257 null, "WRAP_ALIGNMENT", false);
258 af.getCurrentView().setWrapAlignment(wrap);
261 String colour = ArgParser.getFromSubValArgOrPref(avm, av,
262 Arg.COLOUR, sv, null, "DEFAULT_COLOUR_PROT", "");
265 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
266 af.getViewport(), af.getViewport().getAlignment(), colour);
268 if (cs==null && !"None".equals(colour))
270 Console.warn("Couldn't parse '"+colour+"' as a colourscheme.");
274 Jalview.testoutput(argParser, Arg.COLOUR, "zappo", colour);
277 // Change alignment frame title
278 String title = ArgParser.getFromSubValArgOrPref(avm, av,
279 Arg.TITLE, sv, null, null, null);
283 Jalview.testoutput(argParser, Arg.TITLE, "test title", title);
287 String featuresfile = ArgParser.getValueFromSubValOrArg(avm, av,
289 if (featuresfile != null)
291 af.parseFeaturesFile(featuresfile,
292 AppletFormatAdapter.checkProtocol(featuresfile));
293 Jalview.testoutput(argParser, Arg.FEATURES,
294 "examples/testdata/plantfdx.features", featuresfile);
297 // Add annotations from file
298 String annotationsfile = ArgParser.getValueFromSubValOrArg(avm,
299 av, Arg.ANNOTATIONS, sv);
300 if (annotationsfile != null)
302 af.loadJalviewDataFile(annotationsfile, null, null, null);
303 Jalview.testoutput(argParser, Arg.ANNOTATIONS,
304 "examples/testdata/plantfdx.annotations",
308 // Set or clear the sortbytree flag
309 boolean sortbytree = ArgParser.getBoolFromSubValOrArg(avm,
313 af.getViewport().setSortByTree(true);
314 Jalview.testoutput(argParser, Arg.SORTBYTREE);
317 // Load tree from file
318 String treefile = ArgParser.getValueFromSubValOrArg(avm, av,
320 if (treefile != null)
324 NewickFile nf = new NewickFile(treefile,
325 AppletFormatAdapter.checkProtocol(treefile));
326 af.getViewport().setCurrentTree(
327 af.showNewickTree(nf, treefile).getTree());
328 Jalview.testoutput(argParser, Arg.TREE,
329 "examples/testdata/uniref50_test_tree", treefile);
330 } catch (IOException e)
332 Console.warn("Couldn't add tree " + treefile, e);
336 // Show secondary structure annotations?
337 boolean showSSAnnotations = ArgParser.getFromSubValArgOrPref(avm,
338 Arg.SHOWSSANNOTATIONS, av.getSubVals(), null,
339 "STRUCT_FROM_PDB", true);
340 af.setAnnotationsVisibility(showSSAnnotations, true, false);
342 // Show sequence annotations?
343 boolean showAnnotations = ArgParser.getFromSubValArgOrPref(avm,
344 Arg.SHOWANNOTATIONS, av.getSubVals(), null,
345 "SHOW_ANNOTATIONS", true);
346 af.setAnnotationsVisibility(showAnnotations, false, true);
348 // show temperature factor annotations?
349 if (avm.getBoolean(Arg.NOTEMPFAC))
351 // do this better (annotation types?)
352 List<String> hideThese = new ArrayList<>();
353 hideThese.add("Temperature Factor");
354 hideThese.add(AlphaFoldAnnotationRowBuilder.LABEL);
355 AlignmentUtils.showOrHideSequenceAnnotations(
356 af.getCurrentView().getAlignment(), hideThese, null,
360 // store the AlignFrame for this id
363 // is it its own structure file?
364 if (format.isStructureFile())
366 StructureSelectionManager ssm = StructureSelectionManager
367 .getStructureSelectionManager(Desktop.instance);
368 SequenceI seq = af.alignPanel.getAlignment().getSequenceAt(0);
369 ssm.computeMapping(false, new SequenceI[] { seq }, null,
370 openFile, DataSourceType.FILE, null, null, null, false);
376 "Opening '" + openFile + "' in existing alignment frame");
377 DataSourceType dst = HttpUtils.startsWithHttpOrHttps(openFile)
379 : DataSourceType.FILE;
380 FileLoader fileLoader = new FileLoader(!headless);
381 fileLoader.LoadFile(af.getCurrentView(), openFile, dst, null,
385 Console.debug("Command " + Arg.APPEND + " executed successfully!");
388 if (first) // first=true means nothing opened
392 Jalview.exit("Could not open any files in headless mode", 1);
396 Console.warn("No more files to open");
399 if (progressBarSet && desktop != null)
400 desktop.setProgressBar(null, progress);
404 // open the structure (from same PDB file or given PDBfile)
405 if (!avm.getBoolean(Arg.NOSTRUCTURE))
407 AlignFrame af = afMap.get(id);
408 if (avm.containsArg(Arg.STRUCTURE))
410 commandArgsProvided = true;
411 for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
413 String val = av.getValue();
414 SubVals subVals = av.getSubVals();
415 SequenceI seq = getSpecifiedSequence(af, avm, av);
418 // Could not find sequence from subId, let's assume the first
419 // sequence in the alignframe
420 AlignmentI al = af.getCurrentView().getAlignment();
421 seq = al.getSequenceAt(0);
426 Console.warn("Could not find sequence for argument "
427 + Arg.STRUCTURE.argString() + "=" + val);
428 // you probably want to continue here, not break
432 File structureFile = null;
433 if (subVals.getContent() != null
434 && subVals.getContent().length() != 0)
436 structureFile = new File(subVals.getContent());
437 Console.debug("Using structure file (from argument) '"
438 + structureFile.getAbsolutePath() + "'");
442 * PDBEntry fileEntry = new AssociatePdbFileWithSeq()
443 * .associatePdbWithSeq(selectedPdbFileName, DataSourceType.FILE,
444 * selectedSequence, true, Desktop.instance);
446 * sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, new
447 * SequenceI[] { selectedSequence });
450 /* THIS DOESN'T WORK */
451 else if (seq.getAllPDBEntries() != null
452 && seq.getAllPDBEntries().size() > 0)
454 structureFile = new File(
455 seq.getAllPDBEntries().elementAt(0).getFile());
456 Console.debug("Using structure file (from sequence) '"
457 + structureFile.getAbsolutePath() + "'");
460 if (structureFile == null)
462 Console.warn("Not provided structure file with '" + val + "'");
466 if (!structureFile.exists())
468 Console.warn("Structure file '"
469 + structureFile.getAbsoluteFile() + "' not found.");
473 Console.debug("Using structure file "
474 + structureFile.getAbsolutePath());
476 // open structure view
477 AlignmentPanel ap = af.alignPanel;
480 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
481 StructureViewer.ViewerType.JMOL.toString());
484 String structureFilepath = structureFile.getAbsolutePath();
486 // get PAEMATRIX file and label from subvals or Arg.PAEMATRIX
487 String paeFilepath = ArgParser
488 .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
489 Arg.PAEMATRIX, Position.AFTER, av, subVals, null,
491 if (paeFilepath != null)
493 File paeFile = new File(paeFilepath);
497 paeFilepath = paeFile.getCanonicalPath();
498 } catch (IOException e)
500 paeFilepath = paeFile.getAbsolutePath();
501 Console.warn("Problem with the PAE file path: '"
502 + paeFile.getPath() + "'");
506 // showing annotations from structure file or not
507 boolean ssFromStructure = ArgParser.getFromSubValArgOrPref(avm,
508 Arg.SHOWSSANNOTATIONS, subVals, null, "STRUCT_FROM_PDB",
511 // get TEMPFAC type from subvals or Arg.TEMPFAC in case user Adds
512 // reference annotations
513 String tftString = ArgParser
514 .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
515 Arg.TEMPFAC, Position.AFTER, av, subVals, null,
517 boolean notempfac = ArgParser.getFromSubValArgOrPref(avm,
518 Arg.NOTEMPFAC, subVals, null, "ADD_TEMPFACT_ANN", false,
520 TFType tft = notempfac ? null : TFType.DEFAULT;
521 if (tftString != null && !notempfac)
523 // get kind of temperature factor annotation
526 tft = TFType.valueOf(tftString.toUpperCase(Locale.ROOT));
527 Console.debug("Obtained Temperature Factor type of '" + tft
528 + "' for structure '" + structureFilepath + "'");
529 } catch (IllegalArgumentException e)
531 // Just an error message!
532 StringBuilder sb = new StringBuilder().append("Cannot set ")
533 .append(Arg.TEMPFAC.argString()).append(" to '")
535 .append("', ignoring. Valid values are: ");
536 Iterator<TFType> it = Arrays.stream(TFType.values())
540 sb.append(it.next().toString().toLowerCase(Locale.ROOT));
544 Console.warn(sb.toString());
548 String sViewer = ArgParser.getFromSubValArgOrPref(avm,
549 Arg.STRUCTUREVIEWER, Position.AFTER, av, subVals, null,
551 ViewerType viewerType = null;
552 if (!"none".equals(sViewer))
554 for (ViewerType v : EnumSet.allOf(ViewerType.class))
556 String name = v.name().toLowerCase(Locale.ROOT)
557 .replaceAll(" ", "");
558 if (sViewer.equals(name))
566 // TODO use ssFromStructure
567 StructureViewer sv = StructureChooser
568 .openStructureFileForSequence(null, null, ap, seq, false,
569 structureFilepath, tft, paeFilepath, false,
570 ssFromStructure, false, viewerType);
574 Console.error("Failed to import and open structure view.");
588 String structureImageFilename = ArgParser.getValueFromSubValOrArg(
589 avm, av, Arg.STRUCTUREIMAGE, subVals);
590 if (sv != null && structureImageFilename != null)
592 ArgValue siAv = avm.getClosestNextArgValueOfArg(av,
595 if (structureImageFilename.equals(siAv.getValue()))
597 sisv = siAv.getSubVals();
599 File structureImageFile = new File(structureImageFilename);
600 String width = ArgParser.getValueFromSubValOrArg(avm, av,
601 Arg.STRUCTUREIMAGEWIDTH, sisv);
602 String height = ArgParser.getValueFromSubValOrArg(avm, av,
603 Arg.STRUCTUREIMAGEHEIGHT, sisv);
604 String scale = ArgParser.getValueFromSubValOrArg(avm, av,
605 Arg.STRUCTUREIMAGESCALE, sisv);
606 String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
607 Arg.STRUCTUREIMAGETEXTRENDERER, sisv);
608 String typeS = ArgParser.getValueFromSubValOrArg(avm, av,
609 Arg.STRUCTUREIMAGETYPE, sisv);
610 if (typeS == null || typeS.length() == 0)
612 typeS = FileUtils.getExtension(structureImageFile);
617 imageType = Enum.valueOf(TYPE.class,
618 typeS.toUpperCase(Locale.ROOT));
619 } catch (IllegalArgumentException e)
621 Console.warn("Do not know image format '" + typeS
623 imageType = TYPE.PNG;
625 BitmapImageSizing userBis = ImageMaker
626 .parseScaleWidthHeightStrings(scale, width, height);
627 switch (StructureViewer.getViewerType())
633 } catch (InterruptedException e)
635 // TODO Auto-generated catch block
638 JalviewStructureDisplayI sview = sv
639 .getJalviewStructureDisplay();
640 if (sview instanceof AppJmol)
642 AppJmol jmol = (AppJmol) sview;
644 jmol.makePDBImage(structureImageFile, imageType, renderer,
647 catch (ImageOutputException ioexc)
649 Console.warn("Unexpected error whilst exporting image to "+structureImageFile,ioexc);
655 Console.warn("Cannot export image for structure viewer "
656 + sv.getViewerType() + " yet");
665 boolean doShading = avm.getBoolean(Arg.TEMPFAC_SHADING);
668 AlignFrame af = afMap.get(id);
669 for (AlignmentAnnotation aa : af.alignPanel.getAlignment()
670 .findAnnotation(PDBChain.class.getName().toString()))
672 AnnotationColourGradient acg = new AnnotationColourGradient(aa,
673 af.alignPanel.av.getGlobalColourScheme(), 0);
674 acg.setSeqAssociated(true);
675 af.changeColour(acg);
676 Console.info("Changed colour " + acg.toString());
681 return theseArgsWereParsed;
684 protected void processGroovyScript(String id)
686 ArgValuesMap avm = argParser.getLinkedArgs(id);
687 AlignFrame af = afMap.get(id);
691 Console.warn("Did not have an alignment window for id=" + id);
695 if (avm.containsArg(Arg.GROOVY))
697 String groovyscript = avm.getValue(Arg.GROOVY);
698 if (groovyscript != null)
700 // Execute the groovy script after we've done all the rendering stuff
701 // and before any images or figures are generated.
702 Console.info("Executing script " + groovyscript);
703 Jalview.getInstance().executeGroovyScript(groovyscript, af);
708 protected boolean processImages(String id)
710 ArgValuesMap avm = argParser.getLinkedArgs(id);
711 AlignFrame af = afMap.get(id);
715 Console.warn("Did not have an alignment window for id=" + id);
719 if (avm.containsArg(Arg.IMAGE))
721 for (ArgValue av : avm.getArgValueList(Arg.IMAGE))
723 String val = av.getValue();
724 SubVals subVal = av.getSubVals();
725 String fileName = subVal.getContent();
726 File file = new File(fileName);
727 String name = af.getName();
728 String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
729 Arg.TEXTRENDERER, subVal);
730 if (renderer == null)
732 String type = "png"; // default
734 String scale = ArgParser.getValueFromSubValOrArg(avm, av, Arg.SCALE,
736 String width = ArgParser.getValueFromSubValOrArg(avm, av, Arg.WIDTH,
738 String height = ArgParser.getValueFromSubValOrArg(avm, av,
740 BitmapImageSizing userBis = ImageMaker
741 .parseScaleWidthHeightStrings(scale, width, height);
743 type = ArgParser.getValueFromSubValOrArg(avm, av, Arg.TYPE, subVal);
744 if (type == null && fileName != null)
746 for (String ext : new String[] { "svg", "png", "html", "eps" })
748 if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
754 // for moment we disable JSON export
755 Cache.setPropsAreReadOnly(true);
756 Cache.setProperty("EXPORT_EMBBED_BIOJSON", "false");
758 Console.info("Writing " + file);
764 Console.debug("Outputting type '" + type + "' to " + fileName);
765 af.createSVG(file, renderer);
769 Console.debug("Outputting type '" + type + "' to " + fileName);
770 af.createPNG(file, null, userBis);
774 Console.debug("Outputting type '" + type + "' to " + fileName);
775 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
776 htmlSVG.exportHTML(fileName, renderer);
780 Console.debug("Creating BioJS MSA Viwer HTML file: " + fileName);
783 BioJsHTMLOutput.refreshVersionInfo(
784 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
785 } catch (URISyntaxException e)
789 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
790 bjs.exportHTML(fileName);
794 Console.debug("Creating EPS file: " + fileName);
795 af.createEPS(file, name);
799 Console.debug("Creating ImageMap file: " + fileName);
800 af.createImageMap(file, name);
804 Console.warn(Arg.IMAGE.argString() + " type '" + type
805 + "' not known. Ignoring");
808 } catch (Exception ioex) {
809 Console.warn("Unexpected error during export",ioex);
816 protected boolean processOutput(String id)
818 ArgValuesMap avm = argParser.getLinkedArgs(id);
819 AlignFrame af = afMap.get(id);
823 Console.warn("Did not have an alignment window for id=" + id);
827 if (avm.containsArg(Arg.OUTPUT))
829 for (ArgValue av : avm.getArgValueList(Arg.OUTPUT))
831 String val = av.getValue();
832 SubVals subVals = av.getSubVals();
833 String fileName = subVals.getContent();
834 File file = new File(fileName);
835 boolean overwrite = ArgParser.getFromSubValArgOrPref(avm,
836 Arg.OVERWRITE, subVals, null, "OVERWRITE_OUTPUT", false);
837 // backups. Use the Arg.BACKUPS or subval "backups" setting first,
838 // otherwise if headless assume false, if not headless use the user
839 // preference with default true.
840 boolean backups = ArgParser.getFromSubValArgOrPref(avm, Arg.BACKUPS,
842 Platform.isHeadless() ? null : BackupFiles.ENABLED,
843 !Platform.isHeadless());
845 // if backups is not true then --overwrite must be specified
846 if (file.exists() && !(overwrite || backups))
848 Console.error("Won't overwrite file '" + fileName + "' without "
849 + Arg.OVERWRITE.argString() + " or "
850 + Arg.BACKUPS.argString() + " set");
854 String name = af.getName();
855 String format = ArgParser.getValueFromSubValOrArg(avm, av,
856 Arg.FORMAT, subVals);
857 FileFormats ffs = FileFormats.getInstance();
858 List<String> validFormats = ffs.getWritableFormats(false);
860 FileFormatI ff = null;
861 if (format == null && fileName != null)
863 FORMAT: for (String fname : validFormats)
865 FileFormatI tff = ffs.forName(fname);
866 String[] extensions = tff.getExtensions().split(",");
867 for (String ext : extensions)
869 if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
872 format = ff.getName();
878 if (ff == null && format != null)
880 ff = ffs.forName(format);
884 StringBuilder validSB = new StringBuilder();
885 for (String f : validFormats)
887 if (validSB.length() > 0)
888 validSB.append(", ");
890 FileFormatI tff = ffs.forName(f);
891 validSB.append(" (");
892 validSB.append(tff.getExtensions());
896 Jalview.exit("No valid format specified for "
897 + Arg.OUTPUT.argString() + ". Valid formats are "
898 + validSB.toString() + ".", 1);
899 // this return really shouldn't happen
903 String savedBackupsPreference = Cache
904 .getDefault(BackupFiles.ENABLED, null);
905 Console.debug("Setting backups to " + backups);
906 Cache.applicationProperties.put(BackupFiles.ENABLED,
907 Boolean.toString(backups));
909 Console.info("Writing " + fileName);
911 af.saveAlignment(fileName, ff);
912 Console.debug("Returning backups to " + savedBackupsPreference);
913 if (savedBackupsPreference != null)
914 Cache.applicationProperties.put(BackupFiles.ENABLED,
915 savedBackupsPreference);
916 if (af.isSaveAlignmentSuccessful())
918 Console.debug("Written alignment '" + name + "' in "
919 + ff.getName() + " format to " + file);
923 Console.warn("Error writing file " + file + " in " + ff.getName()
932 private SequenceI getSpecifiedSequence(AlignFrame af, ArgValuesMap avm,
935 SubVals subVals = av.getSubVals();
936 ArgValue idAv = avm.getClosestNextArgValueOfArg(av, Arg.SEQID);
937 SequenceI seq = null;
938 if (subVals == null && idAv == null)
940 if (af == null || af.getCurrentView() == null)
944 AlignmentI al = af.getCurrentView().getAlignment();
951 if (subVals.has(Arg.SEQID.getName()))
953 seq = al.findName(subVals.get(Arg.SEQID.getName()));
955 else if (-1 < subVals.getIndex()
956 && subVals.getIndex() < al.getSequences().size())
958 seq = al.getSequenceAt(subVals.getIndex());
961 else if (idAv != null)
963 seq = al.findName(idAv.getValue());