From d42b7588a34477b24ce97ba75788536e74e6cf86 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 4 Apr 2023 16:27:48 +0100 Subject: [PATCH] JAL-629 More consistent printing of --arguments. Example nf-core argfile --- examples/test_fab41.result/argfile.txt | 14 +++++ src/jalview/bin/Commands.java | 101 +++++++++++++----------------- src/jalview/bin/argparser/Arg.java | 8 ++- src/jalview/bin/argparser/ArgParser.java | 48 +++++++------- 4 files changed, 85 insertions(+), 86 deletions(-) create mode 100644 examples/test_fab41.result/argfile.txt diff --git a/examples/test_fab41.result/argfile.txt b/examples/test_fab41.result/argfile.txt new file mode 100644 index 0000000..ed450dd --- /dev/null +++ b/examples/test_fab41.result/argfile.txt @@ -0,0 +1,14 @@ +--substitutions +--open={argfiledirname}/sample.a2m +--colour=gecos:flower +--structure={argfiledirname}/test_fab41_unrelaxed_rank_1_model_3.pdb +--paematrix=[label=pAE R1-M3]{argfiledirname}/test_fab41_unrelaxed_rank_1_model_3_scores.json +--structure={argfiledirname}/test_fab41_unrelaxed_rank_2_model_4.pdb +--paematrix=[label=pAE R2-M4]{argfiledirname}/test_fab41_unrelaxed_rank_2_model_4_scores.json +--structure={argfiledirname}/test_fab41_unrelaxed_rank_3_model_2.pdb +--paematrix=[label=pAE R3-M2]{argfiledirname}/test_fab41_unrelaxed_rank_3_model_2_scores.json +--structure={argfiledirname}/test_fab41_unrelaxed_rank_4_model_5.pdb +--paematrix=[label=pAE R4-M5]{argfiledirname}/test_fab41_unrelaxed_rank_4_model_5_scores.json +--structure={argfiledirname}/test_fab41_unrelaxed_rank_5_model_1.pdb +--paematrix=[label=pAE R5-M1]{argfiledirname}/test_fab41_unrelaxed_rank_5_model_1_scores.json +--image={dirname}/{basename}.html diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index e92ee61..e4be614 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -150,15 +150,12 @@ public class Commands return true; /* - // script to execute after all loading is completed one way or another - String groovyscript = m.get(Arg.GROOVY) == null ? null - : m.get(Arg.GROOVY).getValue(); - String file = m.get(Arg.OPEN) == null ? null - : m.get(Arg.OPEN).getValue(); - String data = null; - FileFormatI format = null; - DataSourceType protocol = null; - */ + * // script to execute after all loading is completed one way or another String + * groovyscript = m.get(Arg.GROOVY) == null ? null : + * m.get(Arg.GROOVY).getValue(); String file = m.get(Arg.OPEN) == null ? null : + * m.get(Arg.OPEN).getValue(); String data = null; FileFormatI format = null; + * DataSourceType protocol = null; + */ if (avm.containsArg(Arg.OPEN) || avm.containsArg(Arg.OPENNEW)) { commandArgsProvided = true; @@ -233,33 +230,19 @@ public class Commands || a == Arg.OPENNEW || format == FileFormat.Jalview) { /* - * this approach isn't working yet - // get default annotations before opening AlignFrame - if (m.get(Arg.SSANNOTATION) != null) - { - Console.debug("***** SSANNOTATION=" - + m.get(Arg.SSANNOTATION).getBoolean()); - } - if (m.get(Arg.NOTEMPFAC) != null) - { - Console.debug( - "***** NOTEMPFAC=" + m.get(Arg.NOTEMPFAC).getBoolean()); - } - boolean showSecondaryStructure = (m.get(Arg.SSANNOTATION) != null) - ? m.get(Arg.SSANNOTATION).getBoolean() - : false; - boolean showTemperatureFactor = (m.get(Arg.NOTEMPFAC) != null) - ? !m.get(Arg.NOTEMPFAC).getBoolean() - : false; - Console.debug("***** tempfac=" + showTemperatureFactor - + ", showSS=" + showSecondaryStructure); - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.instance); - if (ssm != null) - { - ssm.setAddTempFacAnnot(showTemperatureFactor); - ssm.setProcessSecondaryStructure(showSecondaryStructure); - } + * this approach isn't working yet // get default annotations before opening + * AlignFrame if (m.get(Arg.SSANNOTATION) != null) { + * Console.debug("##### SSANNOTATION=" + m.get(Arg.SSANNOTATION).getBoolean()); + * } if (m.get(Arg.NOTEMPFAC) != null) { Console.debug( "##### NOTEMPFAC=" + + * m.get(Arg.NOTEMPFAC).getBoolean()); } boolean showSecondaryStructure = + * (m.get(Arg.SSANNOTATION) != null) ? m.get(Arg.SSANNOTATION).getBoolean() : + * false; boolean showTemperatureFactor = (m.get(Arg.NOTEMPFAC) != null) ? + * !m.get(Arg.NOTEMPFAC).getBoolean() : false; Console.debug("##### tempfac=" + + * showTemperatureFactor + ", showSS=" + showSecondaryStructure); + * StructureSelectionManager ssm = StructureSelectionManager + * .getStructureSelectionManager(Desktop.instance); if (ssm != null) { + * ssm.setAddTempFacAnnot(showTemperatureFactor); + * ssm.setProcessSecondaryStructure(showSecondaryStructure); } */ // get kind of temperature factor annotation @@ -277,8 +260,8 @@ public class Commands } catch (IllegalArgumentException e) { // Just an error message! - StringBuilder sb = new StringBuilder().append("Cannot set --") - .append(Arg.TEMPFAC.getName()).append(" to '") + StringBuilder sb = new StringBuilder().append("Cannot set ") + .append(Arg.TEMPFAC.argString()).append(" to '") .append(tempfacType) .append("', ignoring. Valid values are: "); Iterator it = Arrays @@ -342,9 +325,10 @@ public class Commands false, false); } else - /* comment out hacky approach up to here and add this line: - if (showTemperatureFactor) - */ + /* + * comment out hacky approach up to here and add this line: if + * (showTemperatureFactor) + */ { if (avm.containsArg(Arg.TEMPFAC_LABEL)) { @@ -419,8 +403,8 @@ public class Commands SequenceI seq = getSpecifiedSequence(af, subId); if (seq == null) { - Console.warn("Could not find sequence for argument --" - + Arg.STRUCTURE + "=" + val); + Console.warn("Could not find sequence for argument " + + Arg.STRUCTURE.argString() + "=" + val); // you probably want to continue here, not break // break; continue; @@ -436,15 +420,13 @@ public class Commands // TRY THIS /* - PDBEntry fileEntry = new AssociatePdbFileWithSeq() - .associatePdbWithSeq(selectedPdbFileName, - DataSourceType.FILE, selectedSequence, true, - Desktop.instance); - - sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, - ap, new SequenceI[] - { selectedSequence }); - + * PDBEntry fileEntry = new AssociatePdbFileWithSeq() + * .associatePdbWithSeq(selectedPdbFileName, DataSourceType.FILE, + * selectedSequence, true, Desktop.instance); + * + * sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, new + * SequenceI[] { selectedSequence }); + * */ /* THIS DOESN'T WORK */ @@ -487,12 +469,12 @@ public class Commands // get tft, paeFilename, label? /* - ArgValue tftAv = avm.getArgValuesReferringTo("structid", structId, - Arg.TEMPFAC); + * ArgValue tftAv = avm.getArgValuesReferringTo("structid", structId, + * Arg.TEMPFAC); */ StructureChooser.openStructureFileForSequence(null, null, ap, seq, false, structureFile.getAbsolutePath(), null, null); // tft, - // paeFilename); + // paeFilename); } } } @@ -549,7 +531,7 @@ public class Commands } if (structfile != null) { - Console.info("***** Attaching paeFile '" + paePath + "' to " + Console.info("##### Attaching paeFile '" + paePath + "' to " + "structfile=" + subVals.get("structfile")); EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), paeFile, subVals.getIndex(), subVals.get("structfile"), @@ -557,7 +539,7 @@ public class Commands } else if (structid != null) { - Console.info("***** Attaching paeFile '" + paePath + "' to " + Console.info("##### Attaching paeFile '" + paePath + "' to " + "structid=" + subVals.get("structid")); EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), paeFile, subVals.getIndex(), subVals.get("structid"), @@ -565,7 +547,7 @@ public class Commands } else { - Console.debug("***** Attaching paeFile '" + paePath + Console.debug("##### Attaching paeFile '" + paePath + "' to sequence index " + subVals.getIndex()); EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), paeFile, subVals.getIndex(), null, false, false, @@ -653,7 +635,8 @@ public class Commands htmlSVG.exportHTML(fileName); break; default: - Console.warn("--image type '" + type + "' not known. Ignoring"); + Console.warn(Arg.IMAGE.argString() + " type '" + type + + "' not known. Ignoring"); break; } } diff --git a/src/jalview/bin/argparser/Arg.java b/src/jalview/bin/argparser/Arg.java index 8207996..7eaac09 100644 --- a/src/jalview/bin/argparser/Arg.java +++ b/src/jalview/bin/argparser/Arg.java @@ -26,7 +26,7 @@ public enum Arg { HELP.setOptions(Opt.UNARY); CALCULATION.setOptions(true, Opt.BOOLEAN); // default "true" implies only - // expecting "--nocalculation" + // expecting "--nocalculation" MENUBAR.setOptions(true, Opt.BOOLEAN); STATUS.setOptions(true, Opt.BOOLEAN); SHOWOVERVIEW.setOptions(Opt.UNARY, Opt.LINKED); @@ -119,6 +119,12 @@ public enum Arg System.arraycopy(names, 0, this.argNames, 1, names.length); } + public String argString() + { + return new StringBuilder(ArgParser.DOUBLEDASH).append(getName()) + .toString(); + } + public String toLongString() { StringBuilder sb = new StringBuilder(); diff --git a/src/jalview/bin/argparser/ArgParser.java b/src/jalview/bin/argparser/ArgParser.java index 7d4f187..ff238da 100644 --- a/src/jalview/bin/argparser/ArgParser.java +++ b/src/jalview/bin/argparser/ArgParser.java @@ -29,7 +29,6 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import jalview.bin.Console; @@ -107,7 +106,8 @@ public class ArgParser if (argMap.containsKey(argName)) { Console.warn("Trying to add argument name multiple times: '" - + argName + "'"); // RESTORE THIS WHEN MERGED + + argName + "'"); // RESTORE THIS WHEN + // MERGED if (argMap.get(argName) != a) { Console.error( @@ -189,7 +189,7 @@ public class ArgParser if (openEachInitialFilenames && !arg.startsWith(DOUBLEDASH) && !arg.startsWith("-") && new File(arg).exists()) { - arg = DOUBLEDASH + Arg.OPENNEW.getName(); + arg = Arg.OPENNEW.argString(); } else { @@ -242,8 +242,8 @@ public class ArgParser } if (a.hasOption(Opt.PRIVATE) && !allowPrivate) { - Console.error("Argument '" + DOUBLEDASH + argName - + "' is private. Ignoring."); + Console.error( + "Argument '" + a.argString() + "' is private. Ignoring."); continue; } if (!a.hasOption(Opt.BOOLEAN) && negated) @@ -256,7 +256,7 @@ public class ArgParser if (!a.hasOption(Opt.STRING) && equalPos > -1) { // set --argname=value when arg does not accept values - Console.error("Argument '" + DOUBLEDASH + argName + Console.error("Argument '" + a.argString() + "' does not expect a value (given as '" + arg + "'). Ignoring."); continue; @@ -264,7 +264,7 @@ public class ArgParser if (!a.hasOption(Opt.LINKED) && linkedId != null) { // set --argname[linkedId] when arg does not use linkedIds - Console.error("Argument '" + DOUBLEDASH + argName + Console.error("Argument '" + a.argString() + "' does not expect a linked id (given as '" + arg + "'). Ignoring."); continue; @@ -403,7 +403,7 @@ public class ArgParser // not dealing with both NODUPLICATEVALUES and GLOB if (a.hasOption(Opt.NODUPLICATEVALUES) && avm.hasValue(a, val)) { - Console.error("Argument '" + DOUBLEDASH + argName + Console.error("Argument '" + a.argString() + "' cannot contain a duplicate value ('" + val + "'). Ignoring this and subsequent occurrences."); continue; @@ -414,7 +414,7 @@ public class ArgParser String id = idsv.get(ArgValues.ID); if (id != null && avm.hasId(a, id)) { - Console.error("Argument '" + DOUBLEDASH + argName + Console.error("Argument '" + a.argString() + "' has a duplicate id ('" + id + "'). Ignoring."); continue; } @@ -534,12 +534,11 @@ public class ArgParser /* * A helper method to take a list of String args where we're expecting * {"--previousargs", "--arg", "file1", "file2", "file3", "--otheroptionsornot"} - * and the index of the globbed arg, here 1. It returns a - * List {"file1", "file2", "file3"} - * *and remove these from the original list object* so that processing - * can continue from where it has left off, e.g. args has become - * {"--previousargs", "--arg", "--otheroptionsornot"} - * so the next increment carries on from the next --arg if available. + * and the index of the globbed arg, here 1. It returns a List {"file1", + * "file2", "file3"} *and remove these from the original list object* so that + * processing can continue from where it has left off, e.g. args has become + * {"--previousargs", "--arg", "--otheroptionsornot"} so the next increment + * carries on from the next --arg if available. */ protected static List getShellGlobbedFilenameValues(Arg a, List args, int i) @@ -658,25 +657,22 @@ public class ArgParser { if (!argFile.exists()) { - String message = DOUBLEDASH - + Arg.ARGFILE.name().toLowerCase(Locale.ROOT) + EQUALS - + "\"" + argFile.getPath() + "\": File does not exist."; + String message = Arg.ARGFILE.argString() + EQUALS + "\"" + + argFile.getPath() + "\": File does not exist."; Jalview.exit(message, 2); } try { - String setargfile = new StringBuilder(ArgParser.DOUBLEDASH) - .append(Arg.SETARGFILE.getName()).append(EQUALS) - .append(argFile.getCanonicalPath()).toString(); + String setargfile = new StringBuilder(Arg.SETARGFILE.argString()) + .append(EQUALS).append(argFile.getCanonicalPath()) + .toString(); argsList.add(setargfile); argsList.addAll(Files.readAllLines(Paths.get(argFile.getPath()))); - argsList.add(new StringBuilder(ArgParser.DOUBLEDASH) - .append(Arg.UNSETARGFILE.getName()).toString()); + argsList.add(Arg.UNSETARGFILE.argString()); } catch (IOException e) { - String message = DOUBLEDASH - + Arg.ARGFILE.name().toLowerCase(Locale.ROOT) + "=\"" - + argFile.getPath() + "\": File could not be read."; + String message = Arg.ARGFILE.argString() + "=\"" + argFile.getPath() + + "\": File could not be read."; Jalview.exit(message, 3); } } -- 1.7.10.2