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.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.ArgValues;
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.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.structure.StructureImportSettings.TFType;
47 import jalview.structure.StructureSelectionManager;
48 import jalview.util.HttpUtils;
49 import jalview.util.MessageManager;
50 import jalview.util.Platform;
56 private boolean headless;
58 private ArgParser argParser;
60 private Map<String, AlignFrame> afMap;
62 private boolean commandArgsProvided = false;
64 private boolean argsWereParsed = false;
66 public Commands(ArgParser argparser, boolean headless)
68 this(Desktop.instance, argparser, headless);
71 public Commands(Desktop d, ArgParser argparser, boolean h)
73 argParser = argparser;
76 afMap = new HashMap<String, AlignFrame>();
77 if (argparser != null)
79 processArgs(argparser, headless);
83 private boolean processArgs(ArgParser argparser, boolean h)
85 argParser = argparser;
87 boolean theseArgsWereParsed = false;
89 if (argParser != null && argParser.getLinkedIds() != null)
91 for (String id : argParser.getLinkedIds())
93 ArgValuesMap avm = argParser.getLinkedArgs(id);
94 theseArgsWereParsed = true;
95 theseArgsWereParsed &= processLinked(id);
96 processGroovyScript(id);
97 boolean processLinkedOkay = theseArgsWereParsed;
98 theseArgsWereParsed &= processImages(id);
99 if (processLinkedOkay)
100 theseArgsWereParsed &= processOutput(id);
103 if (avm.getBoolean(Arg.CLOSE))
105 AlignFrame af = afMap.get(id);
108 af.closeMenuItem_actionPerformed(true);
115 if (argParser.getBoolean(Arg.QUIT))
117 Jalview.getInstance().quit();
120 // carry on with jalview.bin.Jalview
121 argsWereParsed = theseArgsWereParsed;
122 return argsWereParsed;
125 public boolean commandArgsProvided()
127 return commandArgsProvided;
130 public boolean argsWereParsed()
132 return argsWereParsed;
135 protected boolean processUnlinked(String id)
137 return processLinked(id);
140 protected boolean processLinked(String id)
142 boolean theseArgsWereParsed = false;
143 ArgValuesMap avm = argParser.getLinkedArgs(id);
148 * // script to execute after all loading is completed one way or another String
149 * groovyscript = m.get(Arg.GROOVY) == null ? null :
150 * m.get(Arg.GROOVY).getValue(); String file = m.get(Arg.OPEN) == null ? null :
151 * m.get(Arg.OPEN).getValue(); String data = null; FileFormatI format = null;
152 * DataSourceType protocol = null;
154 if (avm.containsArg(Arg.APPEND) || avm.containsArg(Arg.OPEN))
156 commandArgsProvided = true;
159 boolean first = true;
160 boolean progressBarSet = false;
162 // Combine the APPEND and OPEN files into one list, along with whether it
163 // was APPEND or OPEN
164 List<ArgValue> openAvList = new ArrayList<>();
165 openAvList.addAll(avm.getArgValueList(Arg.OPEN));
166 openAvList.addAll(avm.getArgValueList(Arg.APPEND));
167 // sort avlist based on av.getArgIndex()
168 Collections.sort(openAvList);
169 for (ArgValue av : openAvList)
172 SubVals sv = av.getSubVals();
173 String openFile = av.getValue();
174 if (openFile == null)
177 theseArgsWereParsed = true;
181 if (!headless && desktop != null)
183 desktop.setProgressBar(
184 MessageManager.getString(
185 "status.processing_commandline_args"),
186 progress = System.currentTimeMillis());
187 progressBarSet = true;
191 if (!Platform.isJS())
193 * ignore in JavaScript -- can't just file existence - could load it?
198 if (!HttpUtils.startsWithHttpOrHttps(openFile))
200 if (!(new File(openFile)).exists())
202 Console.warn("Can't find file '" + openFile + "'");
207 DataSourceType protocol = AppletFormatAdapter
208 .checkProtocol(openFile);
210 FileFormatI format = null;
213 format = new IdentifyFile().identify(openFile, protocol);
214 } catch (FileFormatException e1)
216 Console.error("Unknown file format for '" + openFile + "'");
220 // When to open a new AlignFrame
221 if (af == null || "true".equals(av.getSubVal("new"))
222 || a == Arg.OPEN || format == FileFormat.Jalview)
226 Jalview.testoutput(argParser, Arg.OPEN, "examples/uniref50.fa",
231 "Opening '" + openFile + "' in new alignment frame");
232 FileLoader fileLoader = new FileLoader(!headless);
234 af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol,
238 boolean wrap = ArgParser.getFromSubValArgOrPref(avm, Arg.WRAP, sv,
239 null, "WRAP_ALIGNMENT", false);
240 af.getCurrentView().setWrapAlignment(wrap);
243 String colour = ArgParser.getFromSubValArgOrPref(avm, av,
244 Arg.COLOUR, sv, null, "DEFAULT_COLOUR_PROT", "");
247 af.changeColour_actionPerformed(colour);
248 Jalview.testoutput(argParser, Arg.COLOUR, "zappo", colour);
251 // Change alignment frame title
252 String title = ArgParser.getFromSubValArgOrPref(avm, av,
253 Arg.TITLE, sv, null, null, null);
257 Jalview.testoutput(argParser, Arg.TITLE, "test title", title);
261 String featuresfile = ArgParser.getValueFromSubValOrArg(avm, av,
263 if (featuresfile != null)
265 af.parseFeaturesFile(featuresfile,
266 AppletFormatAdapter.checkProtocol(featuresfile));
267 Jalview.testoutput(argParser, Arg.FEATURES,
268 "examples/testdata/plantfdx.features", featuresfile);
271 // Add annotations from file
272 String annotationsfile = ArgParser.getValueFromSubValOrArg(avm,
273 av, Arg.ANNOTATIONS, sv);
274 if (annotationsfile != null)
276 af.loadJalviewDataFile(annotationsfile, null, null, null);
277 Jalview.testoutput(argParser, Arg.ANNOTATIONS,
278 "examples/testdata/plantfdx.annotations",
282 // Set or clear the sortbytree flag
283 boolean sortbytree = ArgParser.getBoolFromSubValOrArg(avm,
287 af.getViewport().setSortByTree(true);
288 Jalview.testoutput(argParser, Arg.SORTBYTREE);
291 // Load tree from file
292 String treefile = ArgParser.getValueFromSubValOrArg(avm, av,
294 if (treefile != null)
298 NewickFile nf = new NewickFile(treefile,
299 AppletFormatAdapter.checkProtocol(treefile));
300 af.getViewport().setCurrentTree(
301 af.showNewickTree(nf, treefile).getTree());
302 Jalview.testoutput(argParser, Arg.TREE,
303 "examples/testdata/uniref50_test_tree", treefile);
304 } catch (IOException e)
306 Console.warn("Couldn't add tree " + treefile, e);
310 // Show secondary structure annotations?
311 boolean showSSAnnotations = ArgParser.getFromSubValArgOrPref(avm,
312 Arg.SHOWSSANNOTATIONS, av.getSubVals(), null,
313 "STRUCT_FROM_PDB", true);
314 af.setAnnotationsVisibility(showSSAnnotations, true, false);
316 // Show sequence annotations?
317 boolean showAnnotations = ArgParser.getFromSubValArgOrPref(avm,
318 Arg.SHOWANNOTATIONS, av.getSubVals(), null,
319 "SHOW_ANNOTATIONS", true);
320 af.setAnnotationsVisibility(showAnnotations, false, true);
322 // show temperature factor annotations?
323 if (avm.getBoolean(Arg.NOTEMPFAC))
325 // do this better (annotation types?)
326 List<String> hideThese = new ArrayList<>();
327 hideThese.add("Temperature Factor");
328 hideThese.add(AlphaFoldAnnotationRowBuilder.LABEL);
329 AlignmentUtils.showOrHideSequenceAnnotations(
330 af.getCurrentView().getAlignment(), hideThese, null,
334 // store the AlignFrame for this id
337 // is it its own structure file?
338 if (format.isStructureFile())
340 StructureSelectionManager ssm = StructureSelectionManager
341 .getStructureSelectionManager(Desktop.instance);
342 SequenceI seq = af.alignPanel.getAlignment().getSequenceAt(0);
343 ssm.computeMapping(false, new SequenceI[] { seq }, null,
344 openFile, DataSourceType.FILE, null, null, null, false);
350 "Opening '" + openFile + "' in existing alignment frame");
351 DataSourceType dst = HttpUtils.startsWithHttpOrHttps(openFile)
353 : DataSourceType.FILE;
354 FileLoader fileLoader = new FileLoader(!headless);
355 fileLoader.LoadFile(af.getCurrentView(), openFile, dst, null,
359 Console.debug("Command " + Arg.APPEND + " executed successfully!");
362 if (first) // first=true means nothing opened
366 Jalview.exit("Could not open any files in headless mode", 1);
370 Console.warn("No more files to open");
373 if (progressBarSet && desktop != null)
374 desktop.setProgressBar(null, progress);
378 // open the structure (from same PDB file or given PDBfile)
379 if (!avm.getBoolean(Arg.NOSTRUCTURE))
381 AlignFrame af = afMap.get(id);
382 if (avm.containsArg(Arg.STRUCTURE))
384 commandArgsProvided = true;
385 for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
387 String val = av.getValue();
388 SubVals subVals = av.getSubVals();
389 SequenceI seq = getSpecifiedSequence(af, avm, av);
392 // Could not find sequence from subId, let's assume the first
393 // sequence in the alignframe
394 AlignmentI al = af.getCurrentView().getAlignment();
395 seq = al.getSequenceAt(0);
400 Console.warn("Could not find sequence for argument "
401 + Arg.STRUCTURE.argString() + "=" + val);
402 // you probably want to continue here, not break
406 File structureFile = null;
407 if (subVals.getContent() != null
408 && subVals.getContent().length() != 0)
410 structureFile = new File(subVals.getContent());
411 Console.debug("Using structure file (from argument) '"
412 + structureFile.getAbsolutePath() + "'");
416 * PDBEntry fileEntry = new AssociatePdbFileWithSeq()
417 * .associatePdbWithSeq(selectedPdbFileName, DataSourceType.FILE,
418 * selectedSequence, true, Desktop.instance);
420 * sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, new
421 * SequenceI[] { selectedSequence });
424 /* THIS DOESN'T WORK */
425 else if (seq.getAllPDBEntries() != null
426 && seq.getAllPDBEntries().size() > 0)
428 structureFile = new File(
429 seq.getAllPDBEntries().elementAt(0).getFile());
430 Console.debug("Using structure file (from sequence) '"
431 + structureFile.getAbsolutePath() + "'");
434 if (structureFile == null)
436 Console.warn("Not provided structure file with '" + val + "'");
440 if (!structureFile.exists())
442 Console.warn("Structure file '"
443 + structureFile.getAbsoluteFile() + "' not found.");
447 Console.debug("Using structure file "
448 + structureFile.getAbsolutePath());
450 // ##### Does this need to happen? Follow
451 // openStructureFileForSequence() below
453 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
454 .associatePdbWithSeq(structureFile.getAbsolutePath(),
455 DataSourceType.FILE, seq, true, Desktop.instance);
458 // open structure view
459 AlignmentPanel ap = af.alignPanel;
462 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
463 StructureViewer.ViewerType.JMOL.toString());
466 String structureFilepath = structureFile.getAbsolutePath();
468 // get PAEMATRIX file and label from subvals or Arg.PAEMATRIX
469 String paeFilepath = ArgParser
470 .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
471 Arg.PAEMATRIX, Position.AFTER, av, subVals, null,
473 if (paeFilepath != null)
475 File paeFile = new File(paeFilepath);
479 paeFilepath = paeFile.getCanonicalPath();
480 } catch (IOException e)
482 paeFilepath = paeFile.getAbsolutePath();
483 Console.warn("Problem with the PAE file path: '"
484 + paeFile.getPath() + "'");
488 // showing annotations from structure file or not
489 boolean ssFromStructure = ArgParser.getFromSubValArgOrPref(avm,
490 Arg.SHOWSSANNOTATIONS, subVals, null, "STRUCT_FROM_PDB",
493 // get TEMPFAC type from subvals or Arg.TEMPFAC in case user Adds
494 // reference annotations
495 String tftString = ArgParser
496 .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
497 Arg.TEMPFAC, Position.AFTER, av, subVals, null,
499 boolean notempfac = ArgParser.getBoolFromSubValOrArg(avm,
500 Arg.NOTEMPFAC, subVals);
501 TFType tft = notempfac ? null : TFType.DEFAULT;
503 String tftString = subVals.get("tempfac");
504 ArgValue tftAv = getArgAssociatedWithStructure(Arg.TEMPFAC, avm,
505 af, structureFilepath);
506 if (tftString == null && tftAv != null)
508 tftString = tftAv.getSubVals().getContent();
511 if (tftString != null && !notempfac)
513 // get kind of temperature factor annotation
516 tft = TFType.valueOf(tftString.toUpperCase(Locale.ROOT));
517 Console.debug("Obtained Temperature Factor type of '" + tft
518 + "' for structure '" + structureFilepath + "'");
519 } catch (IllegalArgumentException e)
521 // Just an error message!
522 StringBuilder sb = new StringBuilder().append("Cannot set ")
523 .append(Arg.TEMPFAC.argString()).append(" to '")
525 .append("', ignoring. Valid values are: ");
526 Iterator<TFType> it = Arrays.stream(TFType.values())
530 sb.append(it.next().toString().toLowerCase(Locale.ROOT));
534 Console.warn(sb.toString());
538 String sViewer = ArgParser.getFromSubValArgOrPref(avm,
539 Arg.STRUCTUREVIEWER, Position.AFTER, av, subVals, null,
541 ViewerType viewerType = null;
542 if (!"none".equals(sViewer))
544 for (ViewerType v : EnumSet.allOf(ViewerType.class))
546 String name = v.name().toLowerCase(Locale.ROOT)
547 .replaceAll(" ", "");
548 if (sViewer.equals(name))
556 boolean addTempFac = notempfac ? false
558 || Cache.getDefault("ADD_TEMPFACT_ANN", false));
560 // TODO use ssFromStructure
561 StructureChooser.openStructureFileForSequence(null, null, ap, seq,
562 false, structureFilepath, tft, paeFilepath, false,
563 ssFromStructure, false, viewerType);
569 boolean doShading = avm.getBoolean(Arg.TEMPFAC_SHADING);
572 AlignFrame af = afMap.get(id);
573 for (AlignmentAnnotation aa : af.alignPanel.getAlignment()
574 .findAnnotation(PDBChain.class.getName().toString()))
576 AnnotationColourGradient acg = new AnnotationColourGradient(aa,
577 af.alignPanel.av.getGlobalColourScheme(), 0);
578 acg.setSeqAssociated(true);
579 af.changeColour(acg);
580 Console.info("Changed colour " + acg.toString());
585 return theseArgsWereParsed;
588 protected void processGroovyScript(String id)
590 ArgValuesMap avm = argParser.getLinkedArgs(id);
591 AlignFrame af = afMap.get(id);
595 Console.warn("Did not have an alignment window for id=" + id);
599 if (avm.containsArg(Arg.GROOVY))
601 String groovyscript = avm.getValue(Arg.GROOVY);
602 if (groovyscript != null)
604 // Execute the groovy script after we've done all the rendering stuff
605 // and before any images or figures are generated.
606 Console.info("Executing script " + groovyscript);
607 Jalview.getInstance().executeGroovyScript(groovyscript, af);
612 protected boolean processImages(String id)
614 ArgValuesMap avm = argParser.getLinkedArgs(id);
615 AlignFrame af = afMap.get(id);
619 Console.warn("Did not have an alignment window for id=" + id);
623 if (avm.containsArg(Arg.IMAGE))
625 for (ArgValue av : avm.getArgValueList(Arg.IMAGE))
627 String val = av.getValue();
628 SubVals subVal = av.getSubVals();
629 String fileName = subVal.getContent();
630 File file = new File(fileName);
631 String name = af.getName();
632 String renderer = ArgParser.getValueFromSubValOrArg(avm, av,
633 Arg.TEXTRENDERER, subVal);
634 if (renderer == null)
636 String type = "png"; // default
638 float bitmapscale = 0.0f;
640 int bitmapheight = 0;
641 String scale = ArgParser.getValueFromSubValOrArg(avm, av, Arg.SCALE,
647 bitmapscale = Float.parseFloat(scale);
648 } catch (NumberFormatException e)
650 Console.warn("Did not understand scale '" + scale
651 + "', won't be used.");
654 String width = ArgParser.getValueFromSubValOrArg(avm, av, Arg.WIDTH,
660 bitmapwidth = Integer.parseInt(width);
661 } catch (NumberFormatException e)
663 Console.warn("Did not understand width '" + width
664 + "', won't be used.");
667 String height = ArgParser.getValueFromSubValOrArg(avm, av,
673 bitmapheight = Integer.parseInt(height);
674 } catch (NumberFormatException e)
676 Console.warn("Did not understand height '" + height
677 + "', won't be used.");
681 type = ArgParser.getValueFromSubValOrArg(avm, av, Arg.TYPE, subVal);
682 if (type == null && fileName != null)
684 for (String ext : new String[] { "svg", "png", "html", "eps" })
686 if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
692 // for moment we disable JSON export
693 Cache.setPropsAreReadOnly(true);
694 Cache.setProperty("EXPORT_EMBBED_BIOJSON", "false");
700 Console.debug("Outputting type '" + type + "' to " + fileName);
701 af.createSVG(file, renderer);
705 Console.debug("Outputting type '" + type + "' to " + fileName);
706 af.createPNG(file, null, bitmapscale, bitmapwidth, bitmapheight);
710 Console.debug("Outputting type '" + type + "' to " + fileName);
711 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
712 htmlSVG.exportHTML(fileName, renderer);
718 BioJsHTMLOutput.refreshVersionInfo(
719 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
720 } catch (URISyntaxException e)
724 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
725 bjs.exportHTML(fileName);
726 Console.debug("Creating BioJS MSA Viwer HTML file: " + fileName);
730 af.createEPS(file, name);
731 Console.debug("Creating EPS file: " + fileName);
735 af.createImageMap(file, name);
736 Console.debug("Creating ImageMap file: " + fileName);
740 Console.warn(Arg.IMAGE.argString() + " type '" + type
741 + "' not known. Ignoring");
749 protected boolean processOutput(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.OUTPUT))
762 for (ArgValue av : avm.getArgValueList(Arg.OUTPUT))
764 String val = av.getValue();
765 SubVals subVals = av.getSubVals();
766 String fileName = subVals.getContent();
767 File file = new File(fileName);
768 boolean overwrite = ArgParser.getFromSubValArgOrPref(avm,
769 Arg.OVERWRITE, subVals, null, "OVERWRITE_OUTPUT", false);
770 // backups. Use the Arg.BACKUPS or subval "backups" setting first,
771 // otherwise if headless assume false, if not headless use the user
772 // preference with default true.
773 boolean backups = ArgParser.getFromSubValArgOrPref(avm, Arg.BACKUPS,
775 Platform.isHeadless() ? null : BackupFiles.ENABLED,
776 !Platform.isHeadless());
778 // if backups is not true then --overwrite must be specified
779 if (file.exists() && !(overwrite || backups))
781 Console.error("Won't overwrite file '" + fileName + "' without "
782 + Arg.OVERWRITE.argString() + " or "
783 + Arg.BACKUPS.argString() + " set");
787 String name = af.getName();
788 String format = ArgParser.getValueFromSubValOrArg(avm, av,
789 Arg.FORMAT, subVals);
790 FileFormats ffs = FileFormats.getInstance();
791 List<String> validFormats = ffs.getWritableFormats(false);
793 FileFormatI ff = null;
794 if (format == null && fileName != null)
796 FORMAT: for (String fname : validFormats)
798 FileFormatI tff = ffs.forName(fname);
799 String[] extensions = tff.getExtensions().split(",");
800 for (String ext : extensions)
802 if (fileName.toLowerCase(Locale.ROOT).endsWith("." + ext))
805 format = ff.getName();
811 if (ff == null && format != null)
813 ff = ffs.forName(format);
817 StringBuilder validSB = new StringBuilder();
818 for (String f : validFormats)
820 if (validSB.length() > 0)
821 validSB.append(", ");
823 FileFormatI tff = ffs.forName(f);
824 validSB.append(" (");
825 validSB.append(tff.getExtensions());
829 Jalview.exit("No valid format specified for "
830 + Arg.OUTPUT.argString() + ". Valid formats are "
831 + validSB.toString() + ".", 1);
832 // this return really shouldn't happen
836 String savedBackupsPreference = Cache
837 .getDefault(BackupFiles.ENABLED, null);
838 Console.debug("Setting backups to " + backups);
839 Cache.applicationProperties.put(BackupFiles.ENABLED,
840 Boolean.toString(backups));
841 af.saveAlignment(fileName, ff);
842 Console.debug("Returning backups to " + savedBackupsPreference);
843 if (savedBackupsPreference != null)
844 Cache.applicationProperties.put(BackupFiles.ENABLED,
845 savedBackupsPreference);
846 if (af.isSaveAlignmentSuccessful())
848 Console.debug("Written alignment '" + name + "' in "
849 + ff.getName() + " format to " + file);
853 Console.warn("Error writing file " + file + " in " + ff.getName()
862 private SequenceI getSpecifiedSequence(AlignFrame af, ArgValuesMap avm,
865 SubVals subVals = av.getSubVals();
866 ArgValue idAv = avm.getClosestNextArgValueOfArg(av, Arg.SEQID);
867 SequenceI seq = null;
868 if (subVals == null && idAv == null)
870 AlignmentI al = af.getCurrentView().getAlignment();
875 if (subVals.has(Arg.SEQID.getName()))
877 seq = al.findName(subVals.get(Arg.SEQID.getName()));
879 else if (-1 < subVals.getIndex()
880 && subVals.getIndex() < al.getSequences().size())
882 seq = al.getSequenceAt(subVals.getIndex());
885 else if (idAv != null)
887 seq = al.findName(idAv.getValue());
892 // returns the first Arg value intended for the structure structFilename
893 // (in the given AlignFrame from the ArgValuesMap)
894 private ArgValue getArgAssociatedWithStructure(Arg arg, ArgValuesMap avm,
895 AlignFrame af, String structFilename)
899 for (ArgValue av : avm.getArgValueList(arg))
901 SubVals subVals = av.getSubVals();
902 String structid = subVals.get("structid");
903 String structfile = subVals.get("structfile");
905 // let's find a structure
906 if (structfile == null && structid == null)
908 ArgValue likelyStructure = avm.getClosestPreviousArgValueOfArg(av,
910 if (likelyStructure != null)
912 SubVals sv = likelyStructure.getSubVals();
913 if (sv != null && sv.has(ArgValues.ID))
915 structid = sv.get(ArgValues.ID);
919 structfile = likelyStructure.getValue();
924 if (structfile == null && structid != null)
926 StructureSelectionManager ssm = StructureSelectionManager
927 .getStructureSelectionManager(Desktop.instance);
930 structfile = ssm.findFileForPDBId(structid);
933 if (structfile != null && structfile.equals(structFilename))