From: gmungoc Date: Thu, 21 Nov 2019 13:09:19 +0000 (+0000) Subject: JAL-3484 temporary override of autocalc preferences for project load X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=21fcce633c77a700ee488806f60b5e4dc8f6895b;p=jalview.git JAL-3484 temporary override of autocalc preferences for project load --- diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index febc107..318b857 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -42,7 +42,9 @@ import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; import java.util.Enumeration; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; import java.util.TreeSet; @@ -575,6 +577,25 @@ public class Cache { return applicationProperties.getProperty(key); } + + /** + * A convenience method that returns a map holding property values for the + * specified keys. A null entry in the map indicates a property that is either + * not set, or set with value null. + * + * @param key + * @return + */ + public static Map getProperties(String... key) + { + Map map = new HashMap<>(); + for (String k : key) + { + map.put(k, getProperty(k)); + } + return map; + } + /** * These methods are used when checking if the saved preference is different * to the default setting diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 59275cd..d80fd86 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -4034,9 +4034,17 @@ public class Jalview2XML if (isnewview) { - af = loadViewport(file, jseqs, hiddenSeqs, al, jalviewModel, view, - uniqueSeqSetId, viewId); - // TODO restore autocalc preferences if overridden earlier? + Map originalPreferences = null; + try + { + originalPreferences = setAutocalcPreferences(jalviewModel); + af = loadViewport(file, jseqs, hiddenSeqs, al, jalviewModel, view, + uniqueSeqSetId, viewId); + } finally + { + restoreAutocalcPreferences(originalPreferences); + } + /* * resort annotations to their order in the project * (also sets height and visibility for autocalc'd annotation) @@ -4064,6 +4072,93 @@ public class Jalview2XML } /** + * Restores previously captured preferences (or deletes the preference if the + * map entry value is null) + * + * @param originalPreferences + */ + private void restoreAutocalcPreferences( + Map originalPreferences) + { + for (Entry entry : originalPreferences.entrySet()) + { + String key = entry.getKey(); + String value = entry.getValue(); + if (value == null) + { + Cache.removeProperty(key); + } + else + { + Cache.setProperty(key, value); + } + } + } + + /** + * Inspects saved annotations and temporarily sets preferences for whether + * autocalculated annotations should be created for Conservation, Consensus, + * Quality, Occupancy. Returns a map containing the original values (which may + * be null if property is not set, or is set to null). + * + * @param jalviewModel + * @return + */ + private Map setAutocalcPreferences( + JalviewModel jalviewModel) + { + Map original = Cache.getProperties( + AutoAnnotation.OCCUPANCY.preferenceKey, + AutoAnnotation.CONSERVATION.preferenceKey, + AutoAnnotation.QUALITY.preferenceKey, + AutoAnnotation.CONSENSUS.preferenceKey); + + Cache.setProperty(AutoAnnotation.OCCUPANCY.preferenceKey, FALSE); + Cache.setProperty(AutoAnnotation.CONSERVATION.preferenceKey, FALSE); + Cache.setProperty(AutoAnnotation.QUALITY.preferenceKey, FALSE); + Cache.setProperty(AutoAnnotation.CONSENSUS.preferenceKey, FALSE); + + List sequenceSet = jalviewModel.getVamsasModel() + .getSequenceSet(); + + /* + * expect sequenceSet to have just one entry + */ + if (sequenceSet.size() != 1) + { + System.err.println( + "Unexpected sequenceSet size: " + sequenceSet.size()); + return original; + } + List anns = sequenceSet.get(0).getAnnotation(); + for (Annotation ann : anns) + { + if (ann.isAutoCalculated()) + { + String label = ann.getLabel(); + if (AutoAnnotation.CONSERVATION.label.equals(label)) + { + Cache.setProperty(AutoAnnotation.CONSERVATION.preferenceKey, + TRUE); + } + else if (AutoAnnotation.QUALITY.label.equals(label)) + { + Cache.setProperty(AutoAnnotation.QUALITY.preferenceKey, TRUE); + } + else if (AutoAnnotation.CONSENSUS.label.equals(label)) + { + Cache.setProperty(AutoAnnotation.CONSENSUS.preferenceKey, TRUE); + } + else if (AutoAnnotation.OCCUPANCY.label.equals(label)) + { + Cache.setProperty(AutoAnnotation.OCCUPANCY.preferenceKey, TRUE); + } + } + } + return original; + } + + /** * Instantiate and link any saved RNA (Varna) viewers. The state of the Varna * panel is restored from separate jar entries, two (gapped and trimmed) per * sequence and secondary structure.