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 boolean commandArgsProvided = false;
71 private boolean argsWereParsed = false;
73 public Commands(ArgParser argparser, boolean headless)
75 this(Desktop.instance, argparser, headless);
78 public Commands(Desktop d, ArgParser argparser, boolean h)
80 argParser = argparser;
83 afMap = new HashMap<>();
84 if (argparser != null)
86 processArgs(argparser, headless);
90 private boolean processArgs(ArgParser argparser, boolean h)
92 argParser = argparser;
94 boolean theseArgsWereParsed = false;
96 if (argParser != null && argParser.getLinkedIds() != null)
98 for (String id : argParser.getLinkedIds())
100 ArgValuesMap avm = argParser.getLinkedArgs(id);
101 theseArgsWereParsed = true;
102 theseArgsWereParsed &= processLinked(id);
103 processGroovyScript(id);
104 boolean processLinkedOkay = theseArgsWereParsed;
106 // wait around until alignFrame isn't busy
107 AlignFrame af = afMap.get(id);
108 while (af != null && af.getViewport().isCalcInProgress())
113 } catch (Exception q)
119 theseArgsWereParsed &= processImages(id);
120 if (processLinkedOkay)
121 theseArgsWereParsed &= processOutput(id);
124 if (avm.getBoolean(Arg.CLOSE))
129 af.closeMenuItem_actionPerformed(true);
136 if (argParser.getBoolean(Arg.QUIT))
138 Jalview.getInstance().quit();
141 // carry on with jalview.bin.Jalview
142 argsWereParsed = theseArgsWereParsed;
143 return argsWereParsed;
146 public boolean commandArgsProvided()
148 return commandArgsProvided;
151 public boolean argsWereParsed()
153 return argsWereParsed;
156 protected boolean processUnlinked(String id)
158 return processLinked(id);
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 + "'");
224 DataSourceType protocol = AppletFormatAdapter
225 .checkProtocol(openFile);
227 FileFormatI format = null;
230 format = new IdentifyFile().identify(openFile, protocol);
231 } catch (FileFormatException e1)
233 Console.error("Unknown file format for '" + openFile + "'");
237 // When to open a new AlignFrame
238 if (af == null || "true".equals(av.getSubVal("new"))
239 || a == Arg.OPEN || format == FileFormat.Jalview)
243 Jalview.testoutput(argParser, Arg.OPEN, "examples/uniref50.fa",
248 "Opening '" + openFile + "' in new alignment frame");
249 FileLoader fileLoader = new FileLoader(!headless);
251 af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol,
255 String colour = ArgParser.getFromSubValArgOrPref(avm, av,
256 Arg.COLOUR, sv, null, "DEFAULT_COLOUR_PROT", "");
259 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
260 af.getViewport(), af.getViewport().getAlignment(),
263 if (cs == null && !"None".equals(colour))
266 "Couldn't parse '" + colour + "' as a colourscheme.");
272 Jalview.testoutput(argParser, Arg.COLOUR, "zappo", colour);
275 // Change alignment frame title
276 String title = ArgParser.getFromSubValArgOrPref(avm, av,
277 Arg.TITLE, sv, null, null, null);
281 Jalview.testoutput(argParser, Arg.TITLE, "test title", title);
285 String featuresfile = ArgParser.getValueFromSubValOrArg(avm, av,
287 if (featuresfile != null)
289 af.parseFeaturesFile(featuresfile,
290 AppletFormatAdapter.checkProtocol(featuresfile));
291 Jalview.testoutput(argParser, Arg.FEATURES,
292 "examples/testdata/plantfdx.features", featuresfile);
295 // Add annotations from file
296 String annotationsfile = ArgParser.getValueFromSubValOrArg(avm,
297 av, Arg.ANNOTATIONS, sv);
298 if (annotationsfile != null)
300 af.loadJalviewDataFile(annotationsfile, null, null, null);
301 Jalview.testoutput(argParser, Arg.ANNOTATIONS,
302 "examples/testdata/plantfdx.annotations",
306 // Set or clear the sortbytree flag
307 boolean sortbytree = ArgParser.getBoolFromSubValOrArg(avm,
311 af.getViewport().setSortByTree(true);
312 Jalview.testoutput(argParser, Arg.SORTBYTREE);
315 // Load tree from file
316 String treefile = ArgParser.getValueFromSubValOrArg(avm, av,
318 if (treefile != null)
322 NewickFile nf = new NewickFile(treefile,
323 AppletFormatAdapter.checkProtocol(treefile));
324 af.getViewport().setCurrentTree(
325 af.showNewickTree(nf, treefile).getTree());
326 Jalview.testoutput(argParser, Arg.TREE,
327 "examples/testdata/uniref50_test_tree", treefile);
328 } catch (IOException e)
330 Console.warn("Couldn't add tree " + treefile, e);
334 // Show secondary structure annotations?
335 boolean showSSAnnotations = ArgParser.getFromSubValArgOrPref(avm,
336 Arg.SHOWSSANNOTATIONS, av.getSubVals(), null,
337 "STRUCT_FROM_PDB", true);
338 af.setAnnotationsVisibility(showSSAnnotations, true, false);
340 // Show sequence annotations?
341 boolean showAnnotations = ArgParser.getFromSubValArgOrPref(avm,
342 Arg.SHOWANNOTATIONS, av.getSubVals(), null,
343 "SHOW_ANNOTATIONS", true);
344 af.setAnnotationsVisibility(showAnnotations, false, true);
346 // show temperature factor annotations?
347 if (avm.getBoolean(Arg.NOTEMPFAC))
349 // do this better (annotation types?)
350 List<String> hideThese = new ArrayList<>();
351 hideThese.add("Temperature Factor");
352 hideThese.add(AlphaFoldAnnotationRowBuilder.LABEL);
353 AlignmentUtils.showOrHideSequenceAnnotations(
354 af.getCurrentView().getAlignment(), hideThese, null,
358 // wrap alignment? do this last for formatting reasons
359 wrap = ArgParser.getFromSubValArgOrPref(avm, Arg.WRAP, sv, null,
360 "WRAP_ALIGNMENT", false);
361 // af.setWrapFormat(wrap) is applied after structures are opened for
362 // annotation reasons
364 // store the AlignFrame for this id
367 // is it its own structure file?
368 if (format.isStructureFile())
370 StructureSelectionManager ssm = StructureSelectionManager
371 .getStructureSelectionManager(Desktop.instance);
372 SequenceI seq = af.alignPanel.getAlignment().getSequenceAt(0);
373 ssm.computeMapping(false, new SequenceI[] { seq }, null,
374 openFile, DataSourceType.FILE, null, null, null, false);
380 "Opening '" + openFile + "' in existing alignment frame");
381 DataSourceType dst = HttpUtils.startsWithHttpOrHttps(openFile)
383 : DataSourceType.FILE;
384 FileLoader fileLoader = new FileLoader(!headless);
385 fileLoader.LoadFile(af.getCurrentView(), openFile, dst, null,
389 Console.debug("Command " + Arg.APPEND + " executed successfully!");
392 if (first) // first=true means nothing opened
396 Jalview.exit("Could not open any files in headless mode", 1);
400 Console.warn("No more files to open");
403 if (progressBarSet && desktop != null)
404 desktop.setProgressBar(null, progress);
408 // open the structure (from same PDB file or given PDBfile)
409 if (!avm.getBoolean(Arg.NOSTRUCTURE))
411 AlignFrame af = afMap.get(id);
412 if (avm.containsArg(Arg.STRUCTURE))
414 commandArgsProvided = true;
415 for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
417 String val = av.getValue();
418 SubVals subVals = av.getSubVals();
419 SequenceI seq = getSpecifiedSequence(af, avm, av);
422 // Could not find sequence from subId, let's assume the first
423 // sequence in the alignframe
424 AlignmentI al = af.getCurrentView().getAlignment();
425 seq = al.getSequenceAt(0);
430 Console.warn("Could not find sequence for argument "
431 + Arg.STRUCTURE.argString() + "=" + val);
432 // you probably want to continue here, not break
436 File structureFile = null;
437 if (subVals.getContent() != null
438 && subVals.getContent().length() != 0)
440 structureFile = new File(subVals.getContent());
441 Console.debug("Using structure file (from argument) '"
442 + structureFile.getAbsolutePath() + "'");
446 * PDBEntry fileEntry = new AssociatePdbFileWithSeq()
447 * .associatePdbWithSeq(selectedPdbFileName, DataSourceType.FILE,
448 * selectedSequence, true, Desktop.instance);
450 * sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, new
451 * SequenceI[] { selectedSequence });
454 /* THIS DOESN'T WORK */
455 else if (seq.getAllPDBEntries() != null
456 && seq.getAllPDBEntries().size() > 0)
458 structureFile = new File(
459 seq.getAllPDBEntries().elementAt(0).getFile());
460 Console.debug("Using structure file (from sequence) '"
461 + structureFile.getAbsolutePath() + "'");
464 if (structureFile == null)
466 Console.warn("Not provided structure file with '" + val + "'");
470 if (!structureFile.exists())
472 Console.warn("Structure file '"
473 + structureFile.getAbsoluteFile() + "' not found.");
477 Console.debug("Using structure file "
478 + structureFile.getAbsolutePath());
480 // open structure view
481 AlignmentPanel ap = af.alignPanel;
484 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
485 StructureViewer.ViewerType.JMOL.toString());
488 String structureFilepath = structureFile.getAbsolutePath();
490 // get PAEMATRIX file and label from subvals or Arg.PAEMATRIX
491 String paeFilepath = ArgParser
492 .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
493 Arg.PAEMATRIX, Position.AFTER, av, subVals, null,
495 if (paeFilepath != null)
497 File paeFile = new File(paeFilepath);
501 paeFilepath = paeFile.getCanonicalPath();
502 } catch (IOException e)
504 paeFilepath = paeFile.getAbsolutePath();
505 Console.warn("Problem with the PAE file path: '"
506 + paeFile.getPath() + "'");
510 // showing annotations from structure file or not
511 boolean ssFromStructure = ArgParser.getFromSubValArgOrPref(avm,
512 Arg.SHOWSSANNOTATIONS, subVals, null, "STRUCT_FROM_PDB",
515 // get TEMPFAC type from subvals or Arg.TEMPFAC in case user Adds
516 // reference annotations
517 String tftString = ArgParser
518 .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
519 Arg.TEMPFAC, Position.AFTER, av, subVals, null,
521 boolean notempfac = ArgParser.getFromSubValArgOrPref(avm,
522 Arg.NOTEMPFAC, subVals, null, "ADD_TEMPFACT_ANN", false,
524 TFType tft = notempfac ? null : TFType.DEFAULT;
525 if (tftString != null && !notempfac)
527 // get kind of temperature factor annotation
530 tft = TFType.valueOf(tftString.toUpperCase(Locale.ROOT));
531 Console.debug("Obtained Temperature Factor type of '" + tft
532 + "' for structure '" + structureFilepath + "'");
533 } catch (IllegalArgumentException e)
535 // Just an error message!
536 StringBuilder sb = new StringBuilder().append("Cannot set ")
537 .append(Arg.TEMPFAC.argString()).append(" to '")
539 .append("', ignoring. Valid values are: ");
540 Iterator<TFType> it = Arrays.stream(TFType.values())
544 sb.append(it.next().toString().toLowerCase(Locale.ROOT));
548 Console.warn(sb.toString());
552 String sViewer = ArgParser.getFromSubValArgOrPref(avm,
553 Arg.STRUCTUREVIEWER, Position.AFTER, av, subVals, null,
555 ViewerType viewerType = ViewerType.getFromString(sViewer);
557 // TODO use ssFromStructure
558 StructureViewer sv = StructureChooser
559 .openStructureFileForSequence(null, null, ap, seq, false,
560 structureFilepath, tft, paeFilepath, false,
561 ssFromStructure, false, viewerType);
565 Console.error("Failed to import and open structure view.");
571 while (sv.isBusy() && tries > 0)
578 "Waiting for viewer for " + structureFilepath);
581 if (tries == 0 && sv.isBusy())
584 "Gave up waiting for structure viewer to load. Something may have gone wrong.");
586 } catch (Exception x)
588 Console.warn("Exception whilst waiting for structure viewer "
589 + structureFilepath, x);
592 "Successfully opened viewer for " + structureFilepath);
593 String structureImageFilename = ArgParser.getValueFromSubValOrArg(
594 avm, av, Arg.STRUCTUREIMAGE, subVals);
595 if (sv != null && structureImageFilename != null)
597 ArgValue siAv = avm.getClosestNextArgValueOfArg(av,
600 if (structureImageFilename.equals(siAv.getValue()))
602 sisv = siAv.getSubVals();
604 File structureImageFile = new File(structureImageFilename);
605 String width = ArgParser.getValueFromSubValOrArg(avm, av,
606 Arg.STRUCTUREIMAGEWIDTH, sisv);
607 String height = ArgParser.getValueFromSubValOrArg(avm, av,
608 Arg.STRUCTUREIMAGEHEIGHT, sisv);
609 String scale = ArgParser.getValueFromSubValOrArg(avm, av,
610 Arg.STRUCTUREIMAGESCALE, sisv);
611 String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
612 Arg.STRUCTUREIMAGETEXTRENDERER, sisv);
613 String typeS = ArgParser.getValueFromSubValOrArg(avm, av,
614 Arg.STRUCTUREIMAGETYPE, sisv);
615 if (typeS == null || typeS.length() == 0)
617 typeS = FileUtils.getExtension(structureImageFile);
622 imageType = Enum.valueOf(TYPE.class,
623 typeS.toUpperCase(Locale.ROOT));
624 } catch (IllegalArgumentException e)
626 Console.warn("Do not know image format '" + typeS
628 imageType = TYPE.PNG;
630 BitmapImageSizing userBis = ImageMaker
631 .parseScaleWidthHeightStrings(scale, width, height);
632 // TODO MAKE THIS VIEWER INDEPENDENT!!
633 switch (StructureViewer.getViewerType())
638 Thread.sleep(1000); // WHY ???
639 } catch (InterruptedException e)
641 // TODO Auto-generated catch block
644 JalviewStructureDisplayI sview = sv
645 .getJalviewStructureDisplay();
646 if (sview instanceof AppJmol)
648 AppJmol jmol = (AppJmol) sview;
651 Console.debug("Rendering image to " + structureImageFile);
652 jmol.makePDBImage(structureImageFile, imageType, renderer,
654 Console.debug("Finished Rendering image to "
655 + structureImageFile);
657 } catch (ImageOutputException ioexc)
659 Console.warn("Unexpected error whilst exporting image to "
660 + structureImageFile, ioexc);
666 Console.warn("Cannot export image for structure viewer "
667 + sv.getViewerType() + " yet");
677 AlignFrame af = afMap.get(id);
680 af.setWrapFormat(wrap);
685 boolean doShading = avm.getBoolean(Arg.TEMPFAC_SHADING);
688 AlignFrame af = afMap.get(id);
689 for (AlignmentAnnotation aa : af.alignPanel.getAlignment()
690 .findAnnotation(PDBChain.class.getName().toString()))
692 AnnotationColourGradient acg = new AnnotationColourGradient(aa,
693 af.alignPanel.av.getGlobalColourScheme(), 0);
694 acg.setSeqAssociated(true);
695 af.changeColour(acg);
696 Console.info("Changed colour " + acg.toString());
701 return theseArgsWereParsed;
704 protected void processGroovyScript(String id)
706 ArgValuesMap avm = argParser.getLinkedArgs(id);
707 AlignFrame af = afMap.get(id);
711 Console.warn("Did not have an alignment window for id=" + id);
715 if (avm.containsArg(Arg.GROOVY))
717 String groovyscript = avm.getValue(Arg.GROOVY);
718 if (groovyscript != null)
720 // Execute the groovy script after we've done all the rendering stuff
721 // and before any images or figures are generated.
722 Console.info("Executing script " + groovyscript);
723 Jalview.getInstance().executeGroovyScript(groovyscript, af);
728 protected boolean processImages(String id)
730 ArgValuesMap avm = argParser.getLinkedArgs(id);
731 AlignFrame af = afMap.get(id);
735 Console.warn("Did not have an alignment window for id=" + id);
739 if (avm.containsArg(Arg.IMAGE))
741 for (ArgValue av : avm.getArgValueList(Arg.IMAGE))
743 String val = av.getValue();
744 SubVals subVal = av.getSubVals();
745 String fileName = subVal.getContent();
746 File file = new File(fileName);
747 String name = af.getName();
748 String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
749 Arg.TEXTRENDERER, subVal);
750 if (renderer == null)
752 String type = "png"; // default
754 String scale = ArgParser.getValueFromSubValOrArg(avm, av, Arg.SCALE,
756 String width = ArgParser.getValueFromSubValOrArg(avm, av, Arg.WIDTH,
758 String height = ArgParser.getValueFromSubValOrArg(avm, av,
760 BitmapImageSizing userBis = ImageMaker
761 .parseScaleWidthHeightStrings(scale, width, height);
763 type = ArgParser.getValueFromSubValOrArg(avm, av, Arg.TYPE, subVal);
764 if (type == null && fileName != null)
766 for (String ext : new String[] { "svg", "png", "html", "eps" })
768 if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
774 // for moment we disable JSON export
775 Cache.setPropsAreReadOnly(true);
776 Cache.setProperty("EXPORT_EMBBED_BIOJSON", "false");
778 Console.info("Writing " + file);
785 Console.debug("Outputting type '" + type + "' to " + fileName);
786 af.createSVG(file, renderer);
790 Console.debug("Outputting type '" + type + "' to " + fileName);
791 af.createPNG(file, null, userBis);
795 Console.debug("Outputting type '" + type + "' to " + fileName);
796 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
797 htmlSVG.exportHTML(fileName, renderer);
802 "Creating BioJS MSA Viwer HTML file: " + fileName);
805 BioJsHTMLOutput.refreshVersionInfo(
806 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
807 } catch (URISyntaxException e)
811 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
812 bjs.exportHTML(fileName);
816 Console.debug("Creating EPS file: " + fileName);
817 af.createEPS(file, name);
821 Console.debug("Creating ImageMap file: " + fileName);
822 af.createImageMap(file, name);
826 Console.warn(Arg.IMAGE.argString() + " type '" + type
827 + "' not known. Ignoring");
830 } catch (Exception ioex)
832 Console.warn("Unexpected error during export", ioex);
839 protected boolean processOutput(String id)
841 ArgValuesMap avm = argParser.getLinkedArgs(id);
842 AlignFrame af = afMap.get(id);
846 Console.warn("Did not have an alignment window for id=" + id);
850 if (avm.containsArg(Arg.OUTPUT))
852 for (ArgValue av : avm.getArgValueList(Arg.OUTPUT))
854 String val = av.getValue();
855 SubVals subVals = av.getSubVals();
856 String fileName = subVals.getContent();
857 File file = new File(fileName);
858 boolean overwrite = ArgParser.getFromSubValArgOrPref(avm,
859 Arg.OVERWRITE, subVals, null, "OVERWRITE_OUTPUT", false);
860 // backups. Use the Arg.BACKUPS or subval "backups" setting first,
861 // otherwise if headless assume false, if not headless use the user
862 // preference with default true.
863 boolean backups = ArgParser.getFromSubValArgOrPref(avm, Arg.BACKUPS,
865 Platform.isHeadless() ? null : BackupFiles.ENABLED,
866 !Platform.isHeadless());
868 // if backups is not true then --overwrite must be specified
869 if (file.exists() && !(overwrite || backups))
871 Console.error("Won't overwrite file '" + fileName + "' without "
872 + Arg.OVERWRITE.argString() + " or "
873 + Arg.BACKUPS.argString() + " set");
877 String name = af.getName();
878 String format = ArgParser.getValueFromSubValOrArg(avm, av,
879 Arg.FORMAT, subVals);
880 FileFormats ffs = FileFormats.getInstance();
881 List<String> validFormats = ffs.getWritableFormats(false);
883 FileFormatI ff = null;
884 if (format == null && fileName != null)
886 FORMAT: for (String fname : validFormats)
888 FileFormatI tff = ffs.forName(fname);
889 String[] extensions = tff.getExtensions().split(",");
890 for (String ext : extensions)
892 if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
895 format = ff.getName();
901 if (ff == null && format != null)
903 ff = ffs.forName(format);
907 StringBuilder validSB = new StringBuilder();
908 for (String f : validFormats)
910 if (validSB.length() > 0)
911 validSB.append(", ");
913 FileFormatI tff = ffs.forName(f);
914 validSB.append(" (");
915 validSB.append(tff.getExtensions());
919 Jalview.exit("No valid format specified for "
920 + Arg.OUTPUT.argString() + ". Valid formats are "
921 + validSB.toString() + ".", 1);
922 // this return really shouldn't happen
926 String savedBackupsPreference = Cache
927 .getDefault(BackupFiles.ENABLED, null);
928 Console.debug("Setting backups to " + backups);
929 Cache.applicationProperties.put(BackupFiles.ENABLED,
930 Boolean.toString(backups));
932 Console.info("Writing " + fileName);
934 af.saveAlignment(fileName, ff);
935 Console.debug("Returning backups to " + savedBackupsPreference);
936 if (savedBackupsPreference != null)
937 Cache.applicationProperties.put(BackupFiles.ENABLED,
938 savedBackupsPreference);
939 if (af.isSaveAlignmentSuccessful())
941 Console.debug("Written alignment '" + name + "' in "
942 + ff.getName() + " format to " + file);
946 Console.warn("Error writing file " + file + " in " + ff.getName()
955 private SequenceI getSpecifiedSequence(AlignFrame af, ArgValuesMap avm,
958 SubVals subVals = av.getSubVals();
959 ArgValue idAv = avm.getClosestNextArgValueOfArg(av, Arg.SEQID);
960 SequenceI seq = null;
961 if (subVals == null && idAv == null)
963 if (af == null || af.getCurrentView() == null)
967 AlignmentI al = af.getCurrentView().getAlignment();
974 if (subVals.has(Arg.SEQID.getName()))
976 seq = al.findName(subVals.get(Arg.SEQID.getName()));
978 else if (-1 < subVals.getIndex()
979 && subVals.getIndex() < al.getSequences().size())
981 seq = al.getSequenceAt(subVals.getIndex());
984 else if (idAv != null)
986 seq = al.findName(idAv.getValue());