X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureSelectionManager.java;fp=src%2Fjalview%2Fstructure%2FStructureSelectionManager.java;h=43598774a8451a7431379e88470b813c1fcdc11f;hb=f06554784411ddbf871d642e66c8dcb7f147d4a8;hp=ac14b529706f3599434c41cfe71562fe022fd3ad;hpb=cf06ee5d732af6cc874115aece1138adafca8ad7;p=jalview.git diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index ac14b52..4359877 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -20,6 +20,22 @@ */ package jalview.structure; +import jalview.analysis.AlignSeq; +import jalview.api.StructureSelectionManagerProvider; +import jalview.commands.CommandI; +import jalview.commands.EditCommand; +import jalview.commands.OrderCommand; +import jalview.datamodel.AlignedCodonFrame; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.Annotation; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.util.MappingUtils; +import jalview.util.MessageManager; + import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; @@ -37,22 +53,6 @@ import MCview.Atom; import MCview.PDBChain; import MCview.PDBfile; -import jalview.analysis.AlignSeq; -import jalview.api.StructureSelectionManagerProvider; -import jalview.commands.CommandI; -import jalview.commands.EditCommand; -import jalview.commands.OrderCommand; -import jalview.datamodel.AlignedCodonFrame; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.Annotation; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SearchResults; -import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; -import jalview.util.MappingUtils; -import jalview.util.MessageManager; - public class StructureSelectionManager { public final static String NEWLINE = System.lineSeparator(); @@ -70,13 +70,7 @@ public class StructureSelectionManager /* * Set of any registered mappings between (dataset) sequences. */ - Set seqmappings = new LinkedHashSet(); - - /* - * Reference counters for the above mappings. Remove mappings when ref count - * goes to zero. - */ - Map seqMappingRefCounts = new HashMap(); + public Set seqmappings = new LinkedHashSet(); private List commandListeners = new ArrayList(); @@ -518,8 +512,12 @@ public class StructureSelectionManager if (resNum != tmp.resNumber && tmp.alignmentMapping != -1) { resNum = tmp.resNumber; - mapping[tmp.alignmentMapping + 1][0] = tmp.resNumber; - mapping[tmp.alignmentMapping + 1][1] = tmp.atomIndex; + if (tmp.alignmentMapping >= -1) + { + // TODO (JAL-1836) address root cause: negative residue no in PDB file + mapping[tmp.alignmentMapping + 1][0] = tmp.resNumber; + mapping[tmp.alignmentMapping + 1][1] = tmp.atomIndex; + } } index++; @@ -721,13 +719,16 @@ public class StructureSelectionManager { results = MappingUtils.buildSearchResults(seq, index, seqmappings); - } + } if (handlingVamsasMo) { results.addResult(seq, index, index); } - seqListener.highlightSequence(results); + if (!results.isEmpty()) + { + seqListener.highlightSequence(results); + } } } } @@ -908,80 +909,89 @@ public class StructureSelectionManager } /** - * Decrement the reference counter for each of the given mappings, and remove - * it entirely if its reference counter reduces to zero. + * Remove the given mapping * - * @param set + * @param acf */ - public void removeMappings(Set set) + public void deregisterMapping(AlignedCodonFrame acf) { - if (set != null) + if (acf != null) { - for (AlignedCodonFrame acf : set) - { - removeMapping(acf); + boolean removed = seqmappings.remove(acf); + if (removed && seqmappings.isEmpty()) + { // debug + System.out.println("All mappings removed"); } } } /** - * Decrement the reference counter for the given mapping, and remove it - * entirely if its reference counter reduces to zero. + * Add each of the given codonFrames to the stored set, if not aready present. * - * @param acf + * @param set */ - public void removeMapping(AlignedCodonFrame acf) + public void registerMappings(Set set) { - if (acf != null && seqmappings.contains(acf)) + if (set != null) { - int count = seqMappingRefCounts.get(acf); - count--; - if (count > 0) - { - seqMappingRefCounts.put(acf, count); - } - else + for (AlignedCodonFrame acf : set) { - seqmappings.remove(acf); - seqMappingRefCounts.remove(acf); + registerMapping(acf); } } } /** - * Add each of the given codonFrames to the stored set. If not aready present, - * increments its reference count instead. - * - * @param set + * Add the given mapping to the stored set, unless already stored. */ - public void addMappings(Set set) + public void registerMapping(AlignedCodonFrame acf) { - if (set != null) + if (acf != null) { - for (AlignedCodonFrame acf : set) + if (!seqmappings.contains(acf)) { - addMapping(acf); + seqmappings.add(acf); } } } /** - * Add the given mapping to the stored set, or if already stored, increment - * its reference counter. + * Resets this object to its initial state by removing all registered + * listeners, codon mappings, PDB file mappings */ - public void addMapping(AlignedCodonFrame acf) + public void resetAll() { - if (acf != null) + if (mappings != null) { - if (seqmappings.contains(acf)) - { - seqMappingRefCounts.put(acf, seqMappingRefCounts.get(acf) + 1); - } - else - { - seqmappings.add(acf); - seqMappingRefCounts.put(acf, 1); - } + mappings.clear(); + } + if (seqmappings != null) + { + seqmappings.clear(); + } + if (sel_listeners != null) + { + sel_listeners.clear(); + } + if (listeners != null) + { + listeners.clear(); + } + if (commandListeners != null) + { + commandListeners.clear(); + } + if (view_listeners != null) + { + view_listeners.clear(); + } + if (pdbFileNameId != null) + { + pdbFileNameId.clear(); + } + if (pdbIdFileName != null) + { + pdbIdFileName.clear(); } }