From 79456f40b33e73e2fb5420a3287ae80854281ef6 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 11 May 2023 11:34:39 +0100 Subject: [PATCH] JAL-629 Added linkedId to ArgValuesMap for reference. Updated Arg descriptions. Made --quiet work better. --- src/jalview/bin/Cache.java | 7 +++- src/jalview/bin/Commands.java | 13 +++---- src/jalview/bin/Console.java | 3 +- src/jalview/bin/Jalview.java | 8 +++- src/jalview/bin/argparser/Arg.java | 55 +++++++++++++++------------ src/jalview/bin/argparser/ArgParser.java | 46 ++++++++++++++++------ src/jalview/bin/argparser/ArgValue.java | 2 + src/jalview/bin/argparser/ArgValuesMap.java | 13 ++++++- test/jalview/bin/CommandsTest2.java | 2 + 9 files changed, 97 insertions(+), 52 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 4df2e0a..769c868 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -676,8 +676,11 @@ public class Cache new BuildDetails(codeVersion, null, codeInstallation); if (printVersion && reportVersion) { - System.out.println(ChannelProperties.getProperty("app_name") - + " Version: " + codeVersion + codeInstallation); + if (!Jalview.quiet()) + { + System.out.println(ChannelProperties.getProperty("app_name") + + " Version: " + codeVersion + codeInstallation); + } } } diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index af4c675..3608295 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -466,14 +466,13 @@ public class Commands String structureFilepath = structureFile.getAbsolutePath(); // get PAEMATRIX file and label from subvals or Arg.PAEMATRIX - String paeFilepath = subVals.getWithSubstitutions(argParser, id, - "paematrix"); - ArgValue paeAv = getArgAssociatedWithStructure(Arg.PAEMATRIX, avm, - af, structureFilepath); - if (paeFilepath == null && paeAv != null) + String paeFilepath = ArgParser + .getFromSubValArgOrPrefWithSubstitutions(argParser, avm, + Arg.PAEMATRIX, Position.AFTER, av, subVals, null, + null, null); + if (paeFilepath != null) { - SubVals sv = paeAv.getSubVals(); - File paeFile = new File(sv.getContent()); + File paeFile = new File(paeFilepath); try { diff --git a/src/jalview/bin/Console.java b/src/jalview/bin/Console.java index a382ac7..4b18484 100644 --- a/src/jalview/bin/Console.java +++ b/src/jalview/bin/Console.java @@ -242,8 +242,7 @@ public class Console if (!Platform.isJS()) { - if (Jalview.getInstance() == null || (Jalview.getInstance() != null - && !Jalview.getInstance().quiet())) + if (!Jalview.quiet()) { System.err.println( "Setting initial log level to " + logLevel.name()); diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 09d83ce..1021a69 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -140,9 +140,9 @@ public class Jalview private boolean QUIET = false; - public boolean quiet() + public static boolean quiet() { - return QUIET; + return Jalview.getInstance() != null && Jalview.getInstance().QUIET; } static @@ -490,7 +490,11 @@ public class Jalview } if (aparser.contains("help") || aparser.contains("h")) { + /* + * Now using new usage statement. showUsage(); + */ + System.out.println(Arg.usage()); Jalview.exit(null, 0); } diff --git a/src/jalview/bin/argparser/Arg.java b/src/jalview/bin/argparser/Arg.java index 02584fb..95b6b43 100644 --- a/src/jalview/bin/argparser/Arg.java +++ b/src/jalview/bin/argparser/Arg.java @@ -33,22 +33,23 @@ public enum Arg WEBSERVICEDISCOVERY( "Attempt (or don't attempt) to connect to JABAWS web services.", true, Opt.BOOLEAN, Opt.BOOTSTRAP), - PROPS("Use file filename as the preferences file instead of the usual ~/.jalview_properties file.", - Opt.STRING, Opt.BOOTSTRAP), + PROPS("Use a file as the preferences file instead of the usual ~/" + + ChannelProperties.getProperty("preferences.filename") + + " file.", Opt.STRING, Opt.BOOTSTRAP), DEBUG("Start Jalview in debug log level.", Opt.BOOLEAN, Opt.BOOTSTRAP), TRACE("Start Jalview in trace log level.", Opt.BOOLEAN, Opt.BOOTSTRAP, Opt.SECRET), QUIET("Stop all output to STDOUT (after the Java Virtual Machine has started). Use ‑‑quiet a second time to stop all output to STDERR.", Opt.UNARY, Opt.MULTI, Opt.BOOTSTRAP), INITSUBSTITUTIONS( - "Assume that ‑‑substitutions are initially enabled (or initially disabled).", + "Set ‑‑substitutions to be initially enabled (or initially disabled).", true, Opt.BOOLEAN, Opt.BOOTSTRAP, Opt.NOACTION), // Opening an alignment - OPEN("Opens one or more alignment files filename or URLs URL in new alignment windows.", + OPEN("Opens one or more alignment files or URLs in new alignment windows.", Opt.STRING, Opt.LINKED, Opt.INCREMENTDEFAULTCOUNTER, Opt.MULTI, Opt.GLOB, Opt.ALLOWSUBSTITUTIONS, Opt.INPUT), - APPEND("Appends one or more alignment files filename or URLs URL to the open alignment window (or opens a new alignment if none already open).", + APPEND("Appends one or more alignment files or URLs to the open alignment window (or opens a new alignment if none already open).", Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.GLOB, Opt.ALLOWSUBSTITUTIONS, Opt.INPUT), TITLE("Specifies the title for the open alignment window as string.", @@ -62,15 +63,14 @@ public enum Arg + "nucleotide-ambiguity,\n" + "purine-pyrimidine,\n" + "rna-helices,\n" + "t-coffee-scores,\n" + "sequence-id.", Opt.STRING, Opt.LINKED), - FEATURES("Add a feature file filename or URL URL to the open alignment.", - Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), - TREE("Add a tree file filename or URL URL to the open alignment.", - Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), + FEATURES("Add a feature file or URL to the open alignment.", Opt.STRING, + Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), + TREE("Add a tree file or URL to the open alignment.", Opt.STRING, + Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), SORTBYTREE( - "Enforces sorting (or not sorting) the alignment in the order of an attached phylogenetic tree.", + "Enforces sorting (or not sorting) the open alignment in the order of an attached phylogenetic tree.", true, Opt.LINKED, Opt.BOOLEAN), - ANNOTATIONS( - "Add an annotations file filename or URL URL to the open alignment.", + ANNOTATIONS("Add an annotations file or URL to the open alignment.", Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), SHOWANNOTATIONS( "Enforces showing (or not showing) alignment annotations.", @@ -83,18 +83,19 @@ public enum Arg // Adding a 3D structure STRUCTURE( - "Load a structure file filename or URL URL associated with a sequence in the open alignment. The sequence to be associated with can be specified with a following --seqid argument, or the subval modifier seqid=ID can be used. A subval INDEX can also be used to specify the INDEX-th sequence in the open alignment.", + "Load a structure file or URL associated with a sequence in the open alignment.\n" + + "The sequence to be associated with can be specified with a following --seqid argument, or the subval modifier seqid=ID can be used. A subval INDEX can also be used to specify the INDEX-th sequence in the open alignment.", Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), SEQID("Specify the sequence name for the preceding --structure to be associated with.", Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), - PAEMATRIX( - "Add a PAE json matrix file filename to the preceding --structure.", + PAEMATRIX("Add a PAE json matrix file to the preceding --structure.", Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), - TEMPFAC("Set the type of temperature factor. Possible values for name are default, plddt.", - Opt.STRING, Opt.LINKED), + TEMPFAC("Set the type of temperature factor. Possible values are:\n" + + "default,\n" + "plddt.", Opt.STRING, Opt.LINKED), STRUCTUREVIEWER( "Set the structure viewer to use to open the 3d structure file specified in previous --structure to name. Possible values of name are:\n" - + "none, jmol, chimera, chimerax, pymol.", + + "none,\n" + "jmol,\n" + "chimera,\n" + "chimerax,\n" + + "pymol.", Opt.STRING, Opt.LINKED, Opt.MULTI), NOTEMPFAC( "Do not show the temperature factor annotation for the preceding --structure.", @@ -102,13 +103,16 @@ public enum Arg SHOWSSANNOTATIONS(null, Opt.BOOLEAN, Opt.LINKED), // Outputting files - IMAGE("Output an image of the open alignment window. Format is specified by the subval modifier, a following --type argument or guessed from the file extension. Valid formats/extensions are: svg, png, eps, html, biojs.", + IMAGE("Output an image of the open alignment window. Format is specified by the subval modifier, a following --type argument or guessed from the file extension. Valid formats/extensions are:\n" + + "svg,\n" + "png,\n" + "eps,\n" + "html,\n" + "biojs.", Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS, Opt.ALLOWALL, Opt.REQUIREINPUT), - TYPE("Set the image format for the preceding --image to name. Valid values for name are: svg, png, eps, html, biojs.", - Opt.STRING, Opt.LINKED, Opt.ALLOWALL), + TYPE("Set the image format for the preceding --image to name. Valid values for name are: svg,\n" + + "png,\n" + "eps,\n" + "html,\n" + "biojs.", Opt.STRING, + Opt.LINKED, Opt.ALLOWALL), TEXTRENDERER( - "Sets whether text in a vector image format (SVG, HTML, EPS) should be rendered as text or vector line-art. Possible values for name are: text, lineart.", + "Sets whether text in a vector image format (SVG, HTML, EPS) should be rendered as text or vector line-art. Possible values for name are:\n" + + "text,\n" + "lineart.", Opt.STRING, Opt.LINKED, Opt.ALLOWALL), OUTPUT("Export the open alignment to file filename. The format name is specified by the subval modifier format=name, a following --format name argument or guessed from the file extension. Valid format names (and file extensions) are:\n" + "fasta (fa, fasta, mfa, fastq),\n" + "pfam (pfam),\n" @@ -123,12 +127,12 @@ public enum Arg + "phylip,\n" + "jalview.", Opt.STRING, Opt.LINKED, Opt.ALLOWALL), GROOVY("Process a groovy script in the file for the open alignment.", Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.ALLOWSUBSTITUTIONS), - BACKUPS("Enable (or disable) writing backup files when saving an ‑‑output file. This applies to the current open alignment -- to apply to all ‑‑output and ‑‑image files, use after ‑‑all.", + BACKUPS("Enable (or disable) writing backup files when saving an ‑‑output file. This applies to the current open alignment. To apply to all ‑‑output and ‑‑image files, use after ‑‑all.", true, Opt.BOOLEAN, Opt.LINKED, Opt.ALLOWALL), OVERWRITE( - "Enable (or disable) overwriting of output files without backups enabled. This applies to the current open alignment -- to apply to all ‑‑output and ‑‑image files, use after ‑‑all.", + "Enable (or disable) overwriting of output files without backups enabled. This applies to the current open alignment. To apply to all ‑‑output and ‑‑image files, use after ‑‑all.", Opt.BOOLEAN, Opt.LINKED, Opt.ALLOWALL), - CLOSE("Close the current open alignment window. This occurs after other output arguments. This applies to the current open alignment -- to apply to all ‑‑output and ‑‑image files, use after ‑‑all.", + CLOSE("Close the current open alignment window. This occurs after other output arguments. This applies to the current open alignment. To apply to all ‑‑output and ‑‑image files, use after ‑‑all.", Opt.UNARY, Opt.LINKED, Opt.ALLOWALL), // controlling flow of arguments @@ -144,6 +148,7 @@ public enum Arg + "{} - the value of the current alignment window default index.", true, Opt.BOOLEAN, Opt.MULTI, Opt.NOACTION), ARGFILE("Open one or more files filename and read, line-by-line, as arguments to Jalview.\n" + + "Values in an argfile should be given with an equals sign (\"=\") separator with no spaces.\n" + "Note that if you use one or more --argfile arguments then all other non-initialising arguments will be ignored.", Opt.STRING, Opt.MULTI, Opt.BOOTSTRAP, Opt.GLOB, Opt.ALLOWSUBSTITUTIONS), diff --git a/src/jalview/bin/argparser/ArgParser.java b/src/jalview/bin/argparser/ArgParser.java index c7fb323..38cb2d4 100644 --- a/src/jalview/bin/argparser/ArgParser.java +++ b/src/jalview/bin/argparser/ArgParser.java @@ -430,10 +430,7 @@ public class ArgParser if (a.hasOption(Opt.NOACTION)) continue; - if (!linkedArgs.containsKey(linkedId)) - linkedArgs.put(linkedId, new ArgValuesMap()); - - ArgValuesMap avm = linkedArgs.get(linkedId); + ArgValuesMap avm = getOrCreateLinkedArgValuesMap(linkedId); // not dealing with both NODUPLICATEVALUES and GLOB if (a.hasOption(Opt.NODUPLICATEVALUES) && avm.hasValue(a, val)) @@ -543,8 +540,7 @@ public class ArgParser .toString(); } } - if (!linkedArgs.containsKey(defaultLinkedId)) - linkedArgs.put(defaultLinkedId, new ArgValuesMap()); + getOrCreateLinkedArgValuesMap(defaultLinkedId); return defaultLinkedId; } @@ -817,22 +813,38 @@ public class ArgParser Position pos, ArgValue av, SubVals sv, String key, String pref, String def) { + return getFromSubValArgOrPrefWithSubstitutions(null, avm, a, pos, av, + sv, key, pref, def); + } + + public static String getFromSubValArgOrPrefWithSubstitutions(ArgParser ap, + ArgValuesMap avm, Arg a, Position pos, ArgValue av, SubVals sv, + String key, String pref, String def) + { if (key == null) key = a.getName(); + String value = null; if (sv != null && sv.has(key) && sv.get(key) != null) - return sv.get(key); - if (avm != null && avm.containsArg(a)) + { + value = ap == null ? sv.get(key) + : sv.getWithSubstitutions(ap, avm.getLinkedId(), key); + } + else if (avm != null && avm.containsArg(a)) { if (pos == Position.FIRST && avm.getValue(a) != null) - return avm.getValue(a); + value = avm.getValue(a); else if (pos == Position.BEFORE && avm.getClosestPreviousArgValueOfArg(av, a) != null) - return avm.getClosestPreviousArgValueOfArg(av, a).getValue(); + value = avm.getClosestPreviousArgValueOfArg(av, a).getValue(); else if (pos == Position.AFTER && avm.getClosestNextArgValueOfArg(av, a) != null) - return avm.getClosestNextArgValueOfArg(av, a).getValue(); + value = avm.getClosestNextArgValueOfArg(av, a).getValue(); } - return pref != null ? Cache.getDefault(pref, def) : def; + else + { + value = pref != null ? Cache.getDefault(pref, def) : def; + } + return value; } public static boolean getBoolFromSubValOrArg(ArgValuesMap avm, Arg a, @@ -1041,4 +1053,14 @@ public class ArgParser } } + private ArgValuesMap getOrCreateLinkedArgValuesMap(String linkedId) + { + if (linkedArgs.containsKey(linkedId) + && linkedArgs.get(linkedId) != null) + return linkedArgs.get(linkedId); + + linkedArgs.put(linkedId, new ArgValuesMap(linkedId)); + return linkedArgs.get(linkedId); + } + } \ No newline at end of file diff --git a/src/jalview/bin/argparser/ArgValue.java b/src/jalview/bin/argparser/ArgValue.java index 36901df..1643713 100644 --- a/src/jalview/bin/argparser/ArgValue.java +++ b/src/jalview/bin/argparser/ArgValue.java @@ -11,6 +11,8 @@ public class ArgValue implements Comparable private String value; + // This id is set by a subVal id= to identify the product of this ArgValue + // later. Set but not currently used. private String id; private SubVals subVals; diff --git a/src/jalview/bin/argparser/ArgValuesMap.java b/src/jalview/bin/argparser/ArgValuesMap.java index 340d65a..158041b 100644 --- a/src/jalview/bin/argparser/ArgValuesMap.java +++ b/src/jalview/bin/argparser/ArgValuesMap.java @@ -18,16 +18,25 @@ public class ArgValuesMap { protected Map m; - protected ArgValuesMap() + private String linkedId; + + protected ArgValuesMap(String linkedId) { + this.linkedId = linkedId; this.newMap(); } - protected ArgValuesMap(Map map) + protected ArgValuesMap(String linkedId, Map map) { + this.linkedId = linkedId; this.m = map; } + public String getLinkedId() + { + return linkedId; + } + private Map getMap() { return m; diff --git a/test/jalview/bin/CommandsTest2.java b/test/jalview/bin/CommandsTest2.java index a4366c2..f056da2 100644 --- a/test/jalview/bin/CommandsTest2.java +++ b/test/jalview/bin/CommandsTest2.java @@ -182,6 +182,8 @@ public class CommandsTest2 16, 19, 3 }, { "--nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile2 ", 16, 0, 2 }, + /* + */ // }; } -- 1.7.10.2