From: Jim Procter Date: Sat, 15 Oct 2022 12:00:00 +0000 (+0100) Subject: JAL-2349 reusable contact map holder for SequenceI and AnnotatedCollectionI X-Git-Tag: Release_2_11_4_0~547 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0eda79421bb03c19e3b74c4b83b1644ca12ea66c;p=jalview.git JAL-2349 reusable contact map holder for SequenceI and AnnotatedCollectionI --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 0aa8424..e1c87a9 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -26,7 +26,6 @@ import java.util.BitSet; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; -import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; @@ -2034,52 +2033,35 @@ public class Alignment implements AlignmentI, AutoCloseable } } - Map contactmaps = new HashMap<>(); + //// + //// Contact Matrix Holder Boilerplate + //// + ContactMapHolder cmholder = new ContactMapHolder(); @Override public Collection getContactMaps() { - if (contactmaps != null && contactmaps.size() > 0) - { - return contactmaps.values(); - } - return Collections.EMPTY_LIST; + return cmholder.getContactMaps(); } @Override public ContactListI getContactListFor(AlignmentAnnotation _aa, int column) { - ContactMatrixI cm = contactmaps.get(_aa.annotationId); - if (cm == null) - { - return null; - } - return cm.getContactList(column); + return cmholder.getContactListFor(_aa, column); } @Override public AlignmentAnnotation addContactList(ContactMatrixI cm) { + AlignmentAnnotation aa = cmholder.addContactList(cm); + Annotation _aa[] = new Annotation[getWidth()]; Annotation dummy = new Annotation(0.0f); for (int i = 0; i < _aa.length; _aa[i++] = dummy) { ; } - AlignmentAnnotation aa = new AlignmentAnnotation("Contact Matrix", - "Contact Matrix", _aa); - aa.graph = AlignmentAnnotation.CUSTOMRENDERER; - aa.graphMin = cm.getMin(); - aa.graphMax = cm.getMax(); - aa.editable = false; - // aa.autoCalculated = true; - contactmaps.put(aa.annotationId, cm); - // TODO: contact matrices could be intra or inter - more than one refseq - // possible! - if (cm.hasReferenceSeq()) - { - aa.setSequenceRef(cm.getReferenceSeq()); - } + aa.annotations = _aa; addAnnotation(aa); return aa; } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 93a8c26..e99563b 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -20,7 +20,6 @@ */ package jalview.datamodel; -import java.util.Collection; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -624,18 +623,4 @@ public interface AlignmentI extends AnnotatedCollectionI */ public HiddenColumns propagateInsertions(SequenceI profileseq, AlignmentView input); - - /** - * resolve a contact list instance (if any) associated with the annotation row - * and column position - * - * @param _aa - * @param column - * @return - */ - ContactListI getContactListFor(AlignmentAnnotation _aa, int column); - - AlignmentAnnotation addContactList(ContactMatrixI cm); - - Collection getContactMaps(); } diff --git a/src/jalview/datamodel/AnnotatedCollectionI.java b/src/jalview/datamodel/AnnotatedCollectionI.java index 2963fd5..17c29ef 100644 --- a/src/jalview/datamodel/AnnotatedCollectionI.java +++ b/src/jalview/datamodel/AnnotatedCollectionI.java @@ -20,7 +20,8 @@ */ package jalview.datamodel; -public interface AnnotatedCollectionI extends SequenceCollectionI +public interface AnnotatedCollectionI + extends SequenceCollectionI, ContactMapHolderI { /** diff --git a/src/jalview/datamodel/ContactMapHolder.java b/src/jalview/datamodel/ContactMapHolder.java new file mode 100644 index 0000000..5ef2b2a --- /dev/null +++ b/src/jalview/datamodel/ContactMapHolder.java @@ -0,0 +1,53 @@ +package jalview.datamodel; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class ContactMapHolder implements ContactMapHolderI +{ + + Map contactmaps = new HashMap<>(); + + @Override + public Collection getContactMaps() + { + if (contactmaps != null && contactmaps.size() > 0) + { + return contactmaps.values(); + } + return Collections.EMPTY_LIST; + } + + @Override + public ContactListI getContactListFor(AlignmentAnnotation _aa, int column) + { + ContactMatrixI cm = contactmaps.get(_aa.annotationId); + if (cm == null) + { + return null; + } + return cm.getContactList(column); + } + + @Override + public AlignmentAnnotation addContactList(ContactMatrixI cm) + { + AlignmentAnnotation aa = new AlignmentAnnotation("Contact Matrix", + "Contact Matrix", new Annotation[0]); + aa.graph = AlignmentAnnotation.CUSTOMRENDERER; + aa.graphMin = cm.getMin(); + aa.graphMax = cm.getMax(); + aa.editable = false; + // aa.autoCalculated = true; + contactmaps.put(aa.annotationId, cm); + // TODO: contact matrices could be intra or inter - more than one refseq + // possible! + if (cm.hasReferenceSeq()) + { + aa.setSequenceRef(cm.getReferenceSeq()); + } + return aa; + } +} diff --git a/src/jalview/datamodel/ContactMapHolderI.java b/src/jalview/datamodel/ContactMapHolderI.java new file mode 100644 index 0000000..624a03e --- /dev/null +++ b/src/jalview/datamodel/ContactMapHolderI.java @@ -0,0 +1,21 @@ +package jalview.datamodel; + +import java.util.Collection; + +public interface ContactMapHolderI +{ + /** + * resolve a contact list instance (if any) associated with the annotation row + * and column position + * + * @param _aa + * @param column + * @return + */ + ContactListI getContactListFor(AlignmentAnnotation _aa, int column); + + AlignmentAnnotation addContactList(ContactMatrixI cm); + + Collection getContactMaps(); + +} diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index f8e70b1..d62be17 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -20,17 +20,10 @@ */ package jalview.datamodel; -import jalview.analysis.AlignSeq; -import jalview.datamodel.features.SequenceFeatures; -import jalview.datamodel.features.SequenceFeaturesI; -import jalview.util.Comparison; -import jalview.util.DBRefUtils; -import jalview.util.MapList; -import jalview.util.StringUtils; - import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; +import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.Iterator; @@ -39,6 +32,13 @@ import java.util.ListIterator; import java.util.Vector; import fr.orsay.lri.varna.models.rna.RNA; +import jalview.analysis.AlignSeq; +import jalview.datamodel.features.SequenceFeatures; +import jalview.datamodel.features.SequenceFeaturesI; +import jalview.util.Comparison; +import jalview.util.DBRefUtils; +import jalview.util.MapList; +import jalview.util.StringUtils; /** * @@ -2107,4 +2107,38 @@ public class Sequence extends ASequence implements SequenceI // otherwise, sequence was completely hidden return 0; } + + //// + //// Contact Matrix Holder Boilerplate + //// + ContactMapHolder cmholder = new ContactMapHolder(); + + @Override + public Collection getContactMaps() + { + return cmholder.getContactMaps(); + } + + @Override + public ContactListI getContactListFor(AlignmentAnnotation _aa, int column) + { + return cmholder.getContactListFor(_aa, column); + } + + @Override + public AlignmentAnnotation addContactList(ContactMatrixI cm) + { + AlignmentAnnotation aa = cmholder.addContactList(cm); + + Annotation _aa[] = new Annotation[getLength()]; + Annotation dummy = new Annotation(0.0f); + for (int i = 0; i < _aa.length; _aa[i++] = dummy) + { + ; + } + aa.annotations = _aa; + addAlignmentAnnotation(aa); + return aa; + } + } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 5e33229..6a0e64c 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -20,20 +20,21 @@ */ package jalview.datamodel; -import jalview.analysis.AAFrequency; -import jalview.analysis.Conservation; -import jalview.renderer.ResidueShader; -import jalview.renderer.ResidueShaderI; -import jalview.schemes.ColourSchemeI; - import java.awt.Color; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; +import jalview.analysis.AAFrequency; +import jalview.analysis.Conservation; +import jalview.renderer.ResidueShader; +import jalview.renderer.ResidueShaderI; +import jalview.schemes.ColourSchemeI; + /** * Collects a set contiguous ranges on a set of sequences * @@ -1485,4 +1486,37 @@ public class SequenceGroup implements AnnotatedCollectionI { return (startRes <= apos && endRes >= apos) && sequences.contains(seq); } + + //// + //// Contact Matrix Holder Boilerplate + //// + ContactMapHolder cmholder = new ContactMapHolder(); + + @Override + public Collection getContactMaps() + { + return cmholder.getContactMaps(); + } + + @Override + public ContactListI getContactListFor(AlignmentAnnotation _aa, int column) + { + return cmholder.getContactListFor(_aa, column); + } + + @Override + public AlignmentAnnotation addContactList(ContactMatrixI cm) + { + AlignmentAnnotation aa = cmholder.addContactList(cm); + + Annotation _aa[] = new Annotation[getWidth()]; + Annotation dummy = new Annotation(0.0f); + for (int i = 0; i < _aa.length; _aa[i++] = dummy) + { + ; + } + aa.annotations = _aa; + // TODO passing annotations back to context to be added + return aa; + } } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 2f365e6..34dbab7 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -20,17 +20,16 @@ */ package jalview.datamodel; -import jalview.datamodel.Sequence.DBModList; -import jalview.datamodel.features.SequenceFeaturesI; -import jalview.util.MapList; -import jalview.ws.params.InvalidArgumentException; - import java.util.BitSet; import java.util.Iterator; import java.util.List; import java.util.Vector; import fr.orsay.lri.varna.models.rna.RNA; +import jalview.datamodel.Sequence.DBModList; +import jalview.datamodel.features.SequenceFeaturesI; +import jalview.util.MapList; +import jalview.ws.params.InvalidArgumentException; /** * Methods for manipulating a sequence, its metadata and related annotation in @@ -39,7 +38,7 @@ import fr.orsay.lri.varna.models.rna.RNA; * @author $author$ * @version $Revision$ */ -public interface SequenceI extends ASequenceI +public interface SequenceI extends ASequenceI, ContactMapHolderI { /** * Set the display name for the sequence