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.HashMap;
10 import java.util.Iterator;
11 import java.util.List;
12 import java.util.Locale;
15 import jalview.analysis.AlignmentUtils;
16 import jalview.api.structures.JalviewStructureDisplayI;
17 import jalview.bin.argparser.Arg;
18 import jalview.bin.argparser.ArgParser;
19 import jalview.bin.argparser.ArgParser.Position;
20 import jalview.bin.argparser.ArgValue;
21 import jalview.bin.argparser.ArgValuesMap;
22 import jalview.bin.argparser.SubVals;
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.SequenceI;
25 import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder;
26 import jalview.gui.AlignFrame;
27 import jalview.gui.AlignmentPanel;
28 import jalview.gui.AppJmol;
29 import jalview.gui.Desktop;
30 import jalview.gui.Preferences;
31 import jalview.gui.StructureChooser;
32 import jalview.gui.StructureViewer;
33 import jalview.gui.StructureViewer.ViewerType;
34 import jalview.io.AppletFormatAdapter;
35 import jalview.io.BackupFiles;
36 import jalview.io.BioJsHTMLOutput;
37 import jalview.io.DataSourceType;
38 import jalview.io.FileFormat;
39 import jalview.io.FileFormatException;
40 import jalview.io.FileFormatI;
41 import jalview.io.FileFormats;
42 import jalview.io.FileLoader;
43 import jalview.io.HtmlSvgOutput;
44 import jalview.io.IdentifyFile;
45 import jalview.io.NewickFile;
46 import jalview.io.exceptions.ImageOutputException;
47 import jalview.schemes.ColourSchemeI;
48 import jalview.schemes.ColourSchemeProperty;
49 import jalview.structure.StructureImportSettings.TFType;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.util.FileUtils;
52 import jalview.util.HttpUtils;
53 import jalview.util.ImageMaker;
54 import jalview.util.ImageMaker.TYPE;
55 import jalview.util.MessageManager;
56 import jalview.util.Platform;
57 import jalview.util.imagemaker.BitmapImageSizing;
63 private boolean headless;
65 private ArgParser argParser;
67 private Map<String, AlignFrame> afMap;
69 private Map<String, List<StructureViewer>> svMap;
71 private boolean commandArgsProvided = false;
73 private boolean argsWereParsed = false;
75 public Commands(ArgParser argparser, boolean headless)
77 this(Desktop.instance, argparser, headless);
80 public Commands(Desktop d, ArgParser argparser, boolean h)
82 argParser = argparser;
85 afMap = new HashMap<>();
88 protected boolean processArgs()
90 if (argParser == null)
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 boolean processLinkedOkay = processLinked(id);
104 theseArgsWereParsed &= processLinkedOkay;
106 processGroovyScript(id);
108 // wait around until alignFrame isn't busy
109 AlignFrame af = afMap.get(id);
110 while (af != null && af.getViewport().isCalcInProgress())
115 } catch (Exception q)
121 theseArgsWereParsed &= processImages(id);
123 if (processLinkedOkay)
125 theseArgsWereParsed &= processOutput(id);
129 if (avm.getBoolean(Arg.CLOSE))
134 af.closeMenuItem_actionPerformed(true);
141 if (argParser.getBoolean(Arg.QUIT))
143 Jalview.getInstance().quit();
146 // carry on with jalview.bin.Jalview
147 argsWereParsed = theseArgsWereParsed;
148 return argsWereParsed;
151 public boolean commandArgsProvided()
153 return commandArgsProvided;
156 public boolean argsWereParsed()
158 return argsWereParsed;
161 protected boolean processLinked(String id)
163 boolean theseArgsWereParsed = false;
164 ArgValuesMap avm = argParser.getLinkedArgs(id);
168 // set wrap scope here so it can be applied after structures are opened
169 boolean wrap = false;
171 if (avm.containsArg(Arg.APPEND) || avm.containsArg(Arg.OPEN))
173 commandArgsProvided = true;
176 boolean first = true;
177 boolean progressBarSet = false;
179 // Combine the APPEND and OPEN files into one list, along with whether it
180 // was APPEND or OPEN
181 List<ArgValue> openAvList = new ArrayList<>();
182 openAvList.addAll(avm.getArgValueList(Arg.OPEN));
183 openAvList.addAll(avm.getArgValueList(Arg.APPEND));
184 // sort avlist based on av.getArgIndex()
185 Collections.sort(openAvList);
186 for (ArgValue av : openAvList)
189 SubVals sv = av.getSubVals();
190 String openFile = av.getValue();
191 if (openFile == null)
194 theseArgsWereParsed = true;
198 if (!headless && desktop != null)
200 desktop.setProgressBar(
201 MessageManager.getString(
202 "status.processing_commandline_args"),
203 progress = System.currentTimeMillis());
204 progressBarSet = true;
208 if (!Platform.isJS())
210 * ignore in JavaScript -- can't just file existence - could load it?
215 if (!HttpUtils.startsWithHttpOrHttps(openFile))
217 if (!(new File(openFile)).exists())
219 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 + "'");
239 // When to open a new AlignFrame
240 if (af == null || "true".equals(av.getSubVal("new"))
241 || a == Arg.OPEN || format == FileFormat.Jalview)
245 Jalview.testoutput(argParser, Arg.OPEN, "examples/uniref50.fa",
250 "Opening '" + openFile + "' in new alignment frame");
251 FileLoader fileLoader = new FileLoader(!headless);
252 boolean xception=false;
254 af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol,
256 } catch (Throwable thr)
259 Console.error("Couldn't open '"+openFile+"' as "+format+" "+thr.getLocalizedMessage()+ " (Enable debug for full stack trace)");
260 Console.debug("Exception when opening '"+openFile+"'",thr);
264 if (af==null && !xception)
266 Console.info("Ignoring '"+openFile+"' - no alignment data found.");
272 String colour = ArgParser.getFromSubValArgOrPref(avm, av,
273 Arg.COLOUR, sv, null, "DEFAULT_COLOUR_PROT", "");
276 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
277 af.getViewport(), af.getViewport().getAlignment(),
280 if (cs == null && !"None".equals(colour))
283 "Couldn't parse '" + colour + "' as a colourscheme.");
289 Jalview.testoutput(argParser, Arg.COLOUR, "zappo", colour);
292 // Change alignment frame title
293 String title = ArgParser.getFromSubValArgOrPref(avm, av,
294 Arg.TITLE, sv, null, null, null);
298 Jalview.testoutput(argParser, Arg.TITLE, "test title", title);
302 String featuresfile = ArgParser.getValueFromSubValOrArg(avm, av,
304 if (featuresfile != null)
306 af.parseFeaturesFile(featuresfile,
307 AppletFormatAdapter.checkProtocol(featuresfile));
308 Jalview.testoutput(argParser, Arg.FEATURES,
309 "examples/testdata/plantfdx.features", featuresfile);
312 // Add annotations from file
313 String annotationsfile = ArgParser.getValueFromSubValOrArg(avm,
314 av, Arg.ANNOTATIONS, sv);
315 if (annotationsfile != null)
317 af.loadJalviewDataFile(annotationsfile, null, null, null);
318 Jalview.testoutput(argParser, Arg.ANNOTATIONS,
319 "examples/testdata/plantfdx.annotations",
323 // Set or clear the sortbytree flag
324 boolean sortbytree = ArgParser.getBoolFromSubValOrArg(avm,
328 af.getViewport().setSortByTree(true);
329 Jalview.testoutput(argParser, Arg.SORTBYTREE);
332 // Load tree from file
333 String treefile = ArgParser.getValueFromSubValOrArg(avm, av,
335 if (treefile != null)
339 NewickFile nf = new NewickFile(treefile,
340 AppletFormatAdapter.checkProtocol(treefile));
341 af.getViewport().setCurrentTree(
342 af.showNewickTree(nf, treefile).getTree());
343 Jalview.testoutput(argParser, Arg.TREE,
344 "examples/testdata/uniref50_test_tree", treefile);
345 } catch (IOException e)
347 Console.warn("Couldn't add tree " + treefile, e);
351 // Show secondary structure annotations?
352 boolean showSSAnnotations = ArgParser.getFromSubValArgOrPref(avm,
353 Arg.SHOWSSANNOTATIONS, av.getSubVals(), null,
354 "STRUCT_FROM_PDB", true);
355 af.setAnnotationsVisibility(showSSAnnotations, true, false);
357 // Show sequence annotations?
358 boolean showAnnotations = ArgParser.getFromSubValArgOrPref(avm,
359 Arg.SHOWANNOTATIONS, av.getSubVals(), null,
360 "SHOW_ANNOTATIONS", true);
361 af.setAnnotationsVisibility(showAnnotations, false, true);
363 // show temperature factor annotations?
364 if (avm.getBoolean(Arg.NOTEMPFAC))
366 // do this better (annotation types?)
367 List<String> hideThese = new ArrayList<>();
368 hideThese.add("Temperature Factor");
369 hideThese.add(AlphaFoldAnnotationRowBuilder.LABEL);
370 AlignmentUtils.showOrHideSequenceAnnotations(
371 af.getCurrentView().getAlignment(), hideThese, null,
375 // wrap alignment? do this last for formatting reasons
376 wrap = ArgParser.getFromSubValArgOrPref(avm, Arg.WRAP, sv, null,
377 "WRAP_ALIGNMENT", false);
378 // af.setWrapFormat(wrap) is applied after structures are opened for
379 // annotation reasons
381 // store the AlignFrame for this id
384 // is it its own structure file?
385 if (format.isStructureFile())
387 StructureSelectionManager ssm = StructureSelectionManager
388 .getStructureSelectionManager(Desktop.instance);
389 SequenceI seq = af.alignPanel.getAlignment().getSequenceAt(0);
390 ssm.computeMapping(false, new SequenceI[] { seq }, null,
391 openFile, DataSourceType.FILE, null, null, null, false);
397 "Opening '" + openFile + "' in existing alignment frame");
398 DataSourceType dst = HttpUtils.startsWithHttpOrHttps(openFile)
400 : DataSourceType.FILE;
401 FileLoader fileLoader = new FileLoader(!headless);
402 fileLoader.LoadFile(af.getCurrentView(), openFile, dst, null,
406 Console.debug("Command " + Arg.APPEND + " executed successfully!");
409 if (first) // first=true means nothing opened
413 Jalview.exit("Could not open any files in headless mode", 1);
417 Console.warn("No more files to open");
420 if (progressBarSet && desktop != null)
421 desktop.setProgressBar(null, progress);
425 // open the structure (from same PDB file or given PDBfile)
426 if (!avm.getBoolean(Arg.NOSTRUCTURE))
428 AlignFrame af = afMap.get(id);
429 if (avm.containsArg(Arg.STRUCTURE))
431 commandArgsProvided = true;
432 for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
434 String val = av.getValue();
435 SubVals subVals = av.getSubVals();
436 SequenceI seq = getSpecifiedSequence(af, avm, av);
439 // Could not find sequence from subId, let's assume the first
440 // sequence in the alignframe
441 AlignmentI al = af.getCurrentView().getAlignment();
442 seq = al.getSequenceAt(0);
447 Console.warn("Could not find sequence for argument "
448 + Arg.STRUCTURE.argString() + "=" + val);
449 // you probably want to continue here, not break
453 File structureFile = null;
454 if (subVals.getContent() != null
455 && subVals.getContent().length() != 0)
457 structureFile = new File(subVals.getContent());
458 Console.debug("Using structure file (from argument) '"
459 + structureFile.getAbsolutePath() + "'");
463 * PDBEntry fileEntry = new AssociatePdbFileWithSeq()
464 * .associatePdbWithSeq(selectedPdbFileName, DataSourceType.FILE,
465 * selectedSequence, true, Desktop.instance);
467 * sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, new
468 * SequenceI[] { selectedSequence });
471 /* THIS DOESN'T WORK */
472 else if (seq.getAllPDBEntries() != null
473 && seq.getAllPDBEntries().size() > 0)
475 structureFile = new File(
476 seq.getAllPDBEntries().elementAt(0).getFile());
477 Console.debug("Using structure file (from sequence) '"
478 + structureFile.getAbsolutePath() + "'");
481 if (structureFile == null)
483 Console.warn("Not provided structure file with '" + val + "'");
487 if (!structureFile.exists())
489 Console.warn("Structure file '"
490 + structureFile.getAbsoluteFile() + "' not found.");
494 Console.debug("Using structure file "
495 + structureFile.getAbsolutePath());
497 // open structure view
498 AlignmentPanel ap = af.alignPanel;
501 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
502 StructureViewer.ViewerType.JMOL.toString());
505 String structureFilepath = structureFile.getAbsolutePath();
507 // get PAEMATRIX file and label from subvals or Arg.PAEMATRIX
508 String paeFilepath = ArgParser
509 .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
510 Arg.PAEMATRIX, Position.AFTER, av, subVals, null,
512 if (paeFilepath != null)
514 File paeFile = new File(paeFilepath);
518 paeFilepath = paeFile.getCanonicalPath();
519 } catch (IOException e)
521 paeFilepath = paeFile.getAbsolutePath();
522 Console.warn("Problem with the PAE file path: '"
523 + paeFile.getPath() + "'");
527 // showing annotations from structure file or not
528 boolean ssFromStructure = ArgParser.getFromSubValArgOrPref(avm,
529 Arg.SHOWSSANNOTATIONS, subVals, null, "STRUCT_FROM_PDB",
532 // get TEMPFAC type from subvals or Arg.TEMPFAC in case user Adds
533 // reference annotations
534 String tftString = ArgParser
535 .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
536 Arg.TEMPFAC, Position.AFTER, av, subVals, null,
538 boolean notempfac = ArgParser.getFromSubValArgOrPref(avm,
539 Arg.NOTEMPFAC, subVals, null, "ADD_TEMPFACT_ANN", false,
541 TFType tft = notempfac ? null : TFType.DEFAULT;
542 if (tftString != null && !notempfac)
544 // get kind of temperature factor annotation
547 tft = TFType.valueOf(tftString.toUpperCase(Locale.ROOT));
548 Console.debug("Obtained Temperature Factor type of '" + tft
549 + "' for structure '" + structureFilepath + "'");
550 } catch (IllegalArgumentException e)
552 // Just an error message!
553 StringBuilder sb = new StringBuilder().append("Cannot set ")
554 .append(Arg.TEMPFAC.argString()).append(" to '")
556 .append("', ignoring. Valid values are: ");
557 Iterator<TFType> it = Arrays.stream(TFType.values())
561 sb.append(it.next().toString().toLowerCase(Locale.ROOT));
565 Console.warn(sb.toString());
569 String sViewer = ArgParser.getFromSubValArgOrPref(avm,
570 Arg.STRUCTUREVIEWER, Position.AFTER, av, subVals, null,
572 ViewerType viewerType = ViewerType.getFromString(sViewer);
574 // TODO use ssFromStructure
575 StructureViewer sv = StructureChooser
576 .openStructureFileForSequence(null, null, ap, seq, false,
577 structureFilepath, tft, paeFilepath, false,
578 ssFromStructure, false, viewerType);
582 Console.error("Failed to import and open structure view.");
588 while (sv.isBusy() && tries > 0)
595 "Waiting for viewer for " + structureFilepath);
598 if (tries == 0 && sv.isBusy())
601 "Gave up waiting for structure viewer to load. Something may have gone wrong.");
603 } catch (Exception x)
605 Console.warn("Exception whilst waiting for structure viewer "
606 + structureFilepath, x);
609 // add StructureViewer to svMap list
612 svMap = new HashMap<>();
614 if (svMap.get(id) == null)
616 svMap.put(id, new ArrayList<>());
618 svMap.get(id).add(sv);
621 "Successfully opened viewer for " + structureFilepath);
622 String structureImageFilename = ArgParser.getValueFromSubValOrArg(
623 avm, av, Arg.STRUCTUREIMAGE, subVals);
624 if (sv != null && structureImageFilename != null)
626 ArgValue siAv = avm.getClosestNextArgValueOfArg(av,
629 if (structureImageFilename.equals(siAv.getValue()))
631 sisv = siAv.getSubVals();
633 File structureImageFile = new File(structureImageFilename);
634 String width = ArgParser.getValueFromSubValOrArg(avm, av,
635 Arg.STRUCTUREIMAGEWIDTH, sisv);
636 String height = ArgParser.getValueFromSubValOrArg(avm, av,
637 Arg.STRUCTUREIMAGEHEIGHT, sisv);
638 String scale = ArgParser.getValueFromSubValOrArg(avm, av,
639 Arg.STRUCTUREIMAGESCALE, sisv);
640 String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
641 Arg.STRUCTUREIMAGETEXTRENDERER, sisv);
642 String typeS = ArgParser.getValueFromSubValOrArg(avm, av,
643 Arg.STRUCTUREIMAGETYPE, sisv);
644 if (typeS == null || typeS.length() == 0)
646 typeS = FileUtils.getExtension(structureImageFile);
651 imageType = Enum.valueOf(TYPE.class,
652 typeS.toUpperCase(Locale.ROOT));
653 } catch (IllegalArgumentException e)
655 Console.warn("Do not know image format '" + typeS
657 imageType = TYPE.PNG;
659 BitmapImageSizing userBis = ImageMaker
660 .parseScaleWidthHeightStrings(scale, width, height);
661 // TODO MAKE THIS VIEWER INDEPENDENT!!
662 switch (StructureViewer.getViewerType())
665 JalviewStructureDisplayI sview = sv
666 .getJalviewStructureDisplay();
667 if (sview instanceof AppJmol)
669 AppJmol jmol = (AppJmol) sview;
672 Console.debug("Rendering image to " + structureImageFile);
673 jmol.makePDBImage(structureImageFile, imageType, renderer,
675 Console.debug("Finished Rendering image to "
676 + structureImageFile);
678 } catch (ImageOutputException ioexc)
680 Console.warn("Unexpected error whilst exporting image to "
681 + structureImageFile, ioexc);
687 Console.warn("Cannot export image for structure viewer "
688 + sv.getViewerType() + " yet");
698 AlignFrame af = afMap.get(id);
701 af.setWrapFormat(wrap, true);
706 boolean doShading = avm.getBoolean(Arg.TEMPFAC_SHADING);
709 AlignFrame af = afMap.get(id);
710 for (AlignmentAnnotation aa : af.alignPanel.getAlignment()
711 .findAnnotation(PDBChain.class.getName().toString()))
713 AnnotationColourGradient acg = new AnnotationColourGradient(aa,
714 af.alignPanel.av.getGlobalColourScheme(), 0);
715 acg.setSeqAssociated(true);
716 af.changeColour(acg);
717 Console.info("Changed colour " + acg.toString());
722 return theseArgsWereParsed;
725 protected void processGroovyScript(String id)
727 ArgValuesMap avm = argParser.getLinkedArgs(id);
728 AlignFrame af = afMap.get(id);
732 Console.warn("Did not have an alignment window for id=" + id);
736 if (avm.containsArg(Arg.GROOVY))
738 String groovyscript = avm.getValue(Arg.GROOVY);
739 if (groovyscript != null)
741 // Execute the groovy script after we've done all the rendering stuff
742 // and before any images or figures are generated.
743 Console.info("Executing script " + groovyscript);
744 Jalview.getInstance().executeGroovyScript(groovyscript, af);
749 protected boolean processImages(String id)
751 ArgValuesMap avm = argParser.getLinkedArgs(id);
752 AlignFrame af = afMap.get(id);
756 Console.warn("Did not have an alignment window for id=" + id);
760 if (avm.containsArg(Arg.IMAGE))
762 for (ArgValue av : avm.getArgValueList(Arg.IMAGE))
764 String val = av.getValue();
765 SubVals subVal = av.getSubVals();
766 String fileName = subVal.getContent();
767 File file = new File(fileName);
768 String name = af.getName();
769 String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
770 Arg.TEXTRENDERER, subVal);
771 if (renderer == null)
773 String type = "png"; // default
775 String scale = ArgParser.getValueFromSubValOrArg(avm, av, Arg.SCALE,
777 String width = ArgParser.getValueFromSubValOrArg(avm, av, Arg.WIDTH,
779 String height = ArgParser.getValueFromSubValOrArg(avm, av,
781 BitmapImageSizing userBis = ImageMaker
782 .parseScaleWidthHeightStrings(scale, width, height);
784 type = ArgParser.getValueFromSubValOrArg(avm, av, Arg.TYPE, subVal);
785 if (type == null && fileName != null)
787 for (String ext : new String[] { "svg", "png", "html", "eps" })
789 if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
795 // for moment we disable JSON export
796 Cache.setPropsAreReadOnly(true);
797 Cache.setProperty("EXPORT_EMBBED_BIOJSON", "false");
799 Console.info("Writing " + file);
806 Console.debug("Outputting type '" + type + "' to " + fileName);
807 af.createSVG(file, renderer);
811 Console.debug("Outputting type '" + type + "' to " + fileName);
812 af.createPNG(file, null, userBis);
816 Console.debug("Outputting type '" + type + "' to " + fileName);
817 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
818 htmlSVG.exportHTML(fileName, renderer);
823 "Outputting BioJS MSA Viwer HTML file: " + fileName);
826 BioJsHTMLOutput.refreshVersionInfo(
827 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
828 } catch (URISyntaxException e)
832 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
833 bjs.exportHTML(fileName);
837 Console.debug("Outputting EPS file: " + fileName);
838 af.createEPS(file, renderer);
842 Console.debug("Outputting ImageMap file: " + fileName);
843 af.createImageMap(file, name);
847 Console.warn(Arg.IMAGE.argString() + " type '" + type
848 + "' not known. Ignoring");
851 } catch (Exception ioex)
853 Console.warn("Unexpected error during export", ioex);
860 protected boolean processOutput(String id)
862 ArgValuesMap avm = argParser.getLinkedArgs(id);
863 AlignFrame af = afMap.get(id);
867 Console.warn("Did not have an alignment window for id=" + id);
871 if (avm.containsArg(Arg.OUTPUT))
873 for (ArgValue av : avm.getArgValueList(Arg.OUTPUT))
875 String val = av.getValue();
876 SubVals subVals = av.getSubVals();
877 String fileName = subVals.getContent();
878 boolean stdout = ArgParser.STDOUTFILENAME.equals(fileName);
879 File file = new File(fileName);
880 boolean overwrite = ArgParser.getFromSubValArgOrPref(avm,
881 Arg.OVERWRITE, subVals, null, "OVERWRITE_OUTPUT", false);
882 // backups. Use the Arg.BACKUPS or subval "backups" setting first,
883 // otherwise if headless assume false, if not headless use the user
884 // preference with default true.
885 boolean backups = ArgParser.getFromSubValArgOrPref(avm, Arg.BACKUPS,
887 Platform.isHeadless() ? null : BackupFiles.ENABLED,
888 !Platform.isHeadless());
890 // if backups is not true then --overwrite must be specified
891 if (file.exists() && !(overwrite || backups || stdout))
893 Console.error("Won't overwrite file '" + fileName + "' without "
894 + Arg.OVERWRITE.argString() + " or "
895 + Arg.BACKUPS.argString() + " set");
899 String name = af.getName();
900 String format = ArgParser.getValueFromSubValOrArg(avm, av,
901 Arg.FORMAT, subVals);
902 FileFormats ffs = FileFormats.getInstance();
903 List<String> validFormats = ffs.getWritableFormats(false);
905 FileFormatI ff = null;
906 if (format == null && fileName != null)
908 FORMAT: for (String fname : validFormats)
910 FileFormatI tff = ffs.forName(fname);
911 String[] extensions = tff.getExtensions().split(",");
912 for (String ext : extensions)
914 if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
917 format = ff.getName();
923 if (ff == null && format != null)
925 ff = ffs.forName(format);
931 ff = FileFormat.Fasta;
935 StringBuilder validSB = new StringBuilder();
936 for (String f : validFormats)
938 if (validSB.length() > 0)
939 validSB.append(", ");
941 FileFormatI tff = ffs.forName(f);
942 validSB.append(" (");
943 validSB.append(tff.getExtensions());
947 Jalview.exit("No valid format specified for "
948 + Arg.OUTPUT.argString() + ". Valid formats are "
949 + validSB.toString() + ".", 1);
950 // this return really shouldn't happen
955 String savedBackupsPreference = Cache
956 .getDefault(BackupFiles.ENABLED, null);
957 Console.debug("Setting backups to " + backups);
958 Cache.applicationProperties.put(BackupFiles.ENABLED,
959 Boolean.toString(backups));
961 Console.info("Writing " + fileName);
963 af.saveAlignment(fileName, ff, stdout);
964 Console.debug("Returning backups to " + savedBackupsPreference);
965 if (savedBackupsPreference != null)
966 Cache.applicationProperties.put(BackupFiles.ENABLED,
967 savedBackupsPreference);
968 if (af.isSaveAlignmentSuccessful())
970 Console.debug("Written alignment '" + name + "' in "
971 + ff.getName() + " format to " + file);
975 Console.warn("Error writing file " + file + " in " + ff.getName()
984 private SequenceI getSpecifiedSequence(AlignFrame af, ArgValuesMap avm,
987 SubVals subVals = av.getSubVals();
988 ArgValue idAv = avm.getClosestNextArgValueOfArg(av, Arg.SEQID);
989 SequenceI seq = null;
990 if (subVals == null && idAv == null)
992 if (af == null || af.getCurrentView() == null)
996 AlignmentI al = af.getCurrentView().getAlignment();
1001 if (subVals != null)
1003 if (subVals.has(Arg.SEQID.getName()))
1005 seq = al.findName(subVals.get(Arg.SEQID.getName()));
1007 else if (-1 < subVals.getIndex()
1008 && subVals.getIndex() < al.getSequences().size())
1010 seq = al.getSequenceAt(subVals.getIndex());
1013 if (seq == null && idAv != null)
1015 seq = al.findName(idAv.getValue());
1020 public AlignFrame[] getAlignFrames()
1022 AlignFrame[] afs = null;
1025 afs = (AlignFrame[]) afMap.values().toArray();
1031 public List<StructureViewer> getStructureViewers()
1033 List<StructureViewer> svs = null;
1036 for (List<StructureViewer> svList : svMap.values())
1040 svs = new ArrayList<>();