From f52d881ba992cf5d4570d487f6319666f13263a9 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 12 Apr 2023 11:21:44 +0100 Subject: [PATCH] JAL-629 parse SubVals once with ArgValue. Ensure SubVals exists. Change to setprops in Jalview.java comment --- src/jalview/bin/Commands.java | 48 ++++++++++++++++-------------- src/jalview/bin/Jalview.java | 2 +- src/jalview/bin/argparser/ArgValue.java | 6 ++-- src/jalview/bin/argparser/ArgValues.java | 2 +- src/jalview/bin/argparser/SubVals.java | 38 ++++++++++++----------- 5 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 9ff95e3..4a70bd9 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -399,7 +399,7 @@ public class Commands for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE)) { String val = av.getValue(); - SubVals subId = new SubVals(val); + SubVals subId = av.getSubVals(); SequenceI seq = getSpecifiedSequence(af, subId); if (seq == null) { @@ -494,7 +494,7 @@ public class Commands for (ArgValue av : avm.getArgValueList(Arg.PAEMATRIX)) { String val = av.getValue(); - SubVals subVals = ArgParser.getSubVals(val); + SubVals subVals = av.getSubVals(); String paeLabel = subVals.get("label"); File paeFile = new File(subVals.getContent()); String paePath = null; @@ -507,10 +507,14 @@ public class Commands Console.warn( "Problem with the PAE file path: '" + paePath + "'"); } - String structid = null; - String structfile = null; - int seqindex = SubVals.NOTSET; - if (subVals.notSet()) + String structid = subVals.get("structid"); + String structfile = subVals.get("structfile"); + String seqid = subVals.get("seqid"); + int seqindex = subVals.getIndex(); + + // let's find a structure + if (structfile == null && structid == null && seqid == null + && seqindex == SubVals.NOTSET) { ArgValue likelyStructure = avm .getClosestPreviousArgValueOfArg(av, Arg.STRUCTURE); @@ -530,41 +534,39 @@ public class Commands } } } - else if (subVals.has("structfile")) - { - structfile = subVals.get("structfile"); - } - else if (subVals.has("structid")) - { - structid = subVals.get("structid"); - } + if (structfile != null) { - Console.info("##### Attaching paeFile '" + paePath + "' to " + Console.debug("##### Attaching paeFile '" + paePath + "' to " + "structfile=" + structfile); EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), paeFile, seqindex, structfile, true, false, paeLabel); } else if (structid != null) { - Console.info("##### Attaching paeFile '" + paePath + "' to " + Console.debug("##### Attaching paeFile '" + paePath + "' to " + "structid=" + structid); EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), - paeFile, seqindex, subVals.get("structid"), true, true, - paeLabel); + paeFile, seqindex, structid, true, true, paeLabel); } - else + else if (seqid != null) + { + Console.debug("##### Attaching paeFile '" + paePath + "' to " + + "seqid=" + seqid); + EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), + paeFile, seqindex, seqid, false, false, paeLabel); + } + else if (seqindex >= 0) { - seqindex = subVals.getIndex(); Console.debug("##### Attaching paeFile '" + paePath + "' to sequence index " + seqindex); EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(), paeFile, seqindex, null, false, false, paeLabel); - // required to readjust the height and position of the PAE - // annotation } for (AlignmentViewPanel ap : af.getAlignPanels()) { + // required to readjust the height and position of the PAE + // annotation ap.adjustAnnotationHeight(); } } @@ -605,7 +607,7 @@ public class Commands for (ArgValue av : avm.getArgValueList(Arg.IMAGE)) { String val = av.getValue(); - SubVals subVal = new SubVals(val); + SubVals subVal = av.getSubVals(); String type = "png"; // default String fileName = subVal.getContent(); File file = new File(fileName); diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 951578a..44494e2 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -526,7 +526,7 @@ public class Jalview } // DISABLED FOR SECURITY REASONS // TODO: add a property to allow properties to be overriden by cli args - // Cache.setProperty(defs.substring(0,p), defs.substring(p+1)); + // Cache.setProperty(setprop.substring(0,p), setprop.substring(p+1)); } } if (System.getProperty("java.awt.headless") != null diff --git a/src/jalview/bin/argparser/ArgValue.java b/src/jalview/bin/argparser/ArgValue.java index 28cead9..c9e86b8 100644 --- a/src/jalview/bin/argparser/ArgValue.java +++ b/src/jalview/bin/argparser/ArgValue.java @@ -11,19 +11,19 @@ public class ArgValue private String id; - private SubVals subVals = null; + private SubVals subVals; protected ArgValue(SubVals sv, String content, int argIndex) { this.value = content; this.argIndex = argIndex; - this.subVals = sv; + this.subVals = sv == null ? new SubVals("") : sv; } protected ArgValue(String value, int argIndex) { this.argIndex = argIndex; - this.subVals = ArgParser.getSubVals(value); + this.subVals = new SubVals(value); this.value = getSubVals().getContent(); } diff --git a/src/jalview/bin/argparser/ArgValues.java b/src/jalview/bin/argparser/ArgValues.java index 27d52ba..c166da0 100644 --- a/src/jalview/bin/argparser/ArgValues.java +++ b/src/jalview/bin/argparser/ArgValues.java @@ -123,7 +123,7 @@ public class ArgValues { argValueList = new ArrayList(); } - SubVals sv = ArgParser.getSubVals(av.getValue()); + SubVals sv = new SubVals(av.getValue()); if (sv.has(ID)) { String id = sv.get(ID); diff --git a/src/jalview/bin/argparser/SubVals.java b/src/jalview/bin/argparser/SubVals.java index 3c7ba7c..6708cf9 100644 --- a/src/jalview/bin/argparser/SubVals.java +++ b/src/jalview/bin/argparser/SubVals.java @@ -19,7 +19,7 @@ public class SubVals private int index = NOTSET; - private Map subVals = null; + private Map subValMap; private static char SEPARATOR = ';'; @@ -27,18 +27,24 @@ public class SubVals private String content = null; - public SubVals(SubVals sv, String c) + protected SubVals(SubVals sv, String c) { - if (sv != null) + if (sv == null) { - this.subVals = sv.getSubValsMap(); + this.subValMap = new HashMap<>(); + } + else + { + this.subValMap = sv == null ? new HashMap<>() : sv.getSubValMap(); this.index = sv.getIndex(); } this.content = c; } - public SubVals(String item) + protected SubVals(String item) { + if (subValMap == null) + subValMap = new HashMap<>(); this.parseVals(item); } @@ -56,8 +62,6 @@ public class SubVals for (String subvalString : subvalsString .split(Character.toString(SEPARATOR))) { - if (subVals == null) - subVals = new HashMap<>(); int equals = subvalString.indexOf(EQUALS); if (equals > -1) { @@ -73,7 +77,7 @@ public class SubVals } catch (NumberFormatException e) { // store this non-numeric key as a "true" value - subVals.put(subvalString, "true"); + this.put(subvalString, "true"); } } } @@ -91,25 +95,23 @@ public class SubVals protected void put(String key, String val) { - if (subVals == null) - subVals = new HashMap<>(); - subVals.put(key, val); + subValMap.put(key, val); } public boolean notSet() { // notSet is true if content present but nonsensical - return index == NOTSET && subVals == null; + return index == NOTSET && (subValMap == null || subValMap.size() == 0); } public String get(String key) { - return subVals == null ? null : subVals.get(key); + return subValMap.get(key); } public boolean has(String key) { - return subVals == null ? false : subVals.containsKey(key); + return subValMap.containsKey(key); } public int getIndex() @@ -122,19 +124,19 @@ public class SubVals return content; } - protected Map getSubValsMap() + protected Map getSubValMap() { - return subVals; + return subValMap; } public String toString() { - if (subVals == null && getIndex() == NOTSET) + if (subValMap == null && getIndex() == NOTSET) return ""; StringBuilder sb = new StringBuilder(); List entries = new ArrayList<>(); - subVals.entrySet().stream().forEachOrdered( + subValMap.entrySet().stream().forEachOrdered( m -> entries.add(m.getValue().equals("true") ? m.getKey() : new StringBuilder().append(m.getKey()).append(EQUALS) .append(m.getValue()).toString())); -- 1.7.10.2