X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=321eee3c5ab502839122a17286318fec97d94c6d;hb=fea1abc4a4d2c45a1ba6e6127bac5d2466de18fc;hp=ea04361d94d261f98f9109520f21b8e69a77d788;hpb=4548727494c3bf521eeec90a07e3bc6c0bdfb64e;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index ea04361..321eee3 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -23,9 +23,9 @@ package jalview.datamodel; 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.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; @@ -1653,8 +1653,10 @@ public class Alignment implements AlignmentI, AutoCloseable public Iterable findAnnotations(SequenceI seq, String calcId, String label) { - return AlignmentAnnotation.findAnnotations( - Arrays.asList(getAlignmentAnnotation()), seq, calcId, label); + return annotations == null ? null + : AlignmentAnnotation.findAnnotations( + Arrays.asList(getAlignmentAnnotation()), seq, calcId, + label); } @Override @@ -2033,42 +2035,82 @@ public class Alignment implements AlignmentI, AutoCloseable } } - Map contactmaps = new HashMap<>(); + //// + //// Contact Matrix Holder Boilerplate + //// + ContactMapHolder cmholder = new ContactMapHolder(); + + @Override + public Collection getContactMaps() + { + return cmholder.getContactMaps(); + } + + @Override + public ContactMatrixI getContactMatrixFor(AlignmentAnnotation _aa) + { + ContactMatrixI cm = cmholder.getContactMatrixFor(_aa); + if (cm==null && _aa.groupRef!=null) + { + cm = _aa.groupRef.getContactMatrixFor(_aa); + } + if (cm==null && _aa.sequenceRef!=null) + { + cm = _aa.sequenceRef.getContactMatrixFor(_aa); + if (cm==null) + { + // TODO fix up this logic and unify with getContactListFor + cm = _aa.sequenceRef.getDatasetSequence().getContactMatrixFor(_aa); + } + } + return cm; + } + @Override public ContactListI getContactListFor(AlignmentAnnotation _aa, int column) { - ContactMatrixI cm = contactmaps.get(_aa.annotationId); - if (cm == null) + ContactListI cl = cmholder.getContactListFor(_aa, column); + if (cl == null && _aa.groupRef != null) { - return null; + cl = _aa.groupRef.getContactListFor(_aa, column); + } + if (cl == null && _aa.sequenceRef != null) + { + int spos = _aa.sequenceRef.findPosition(column); + if (spos >= _aa.sequenceRef.getStart() + && spos <= 1 + _aa.sequenceRef.getEnd()) + { + cl = _aa.sequenceRef.getContactListFor(_aa, spos); + if (cl == null && _aa.sequenceRef.getDatasetSequence() != null) + { + _aa.sequenceRef.getDatasetSequence().getContactListFor(_aa, spos); + } + } } - return cm.getContactList(column); + return cl; } @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; } + + @Override + public void addContactListFor(AlignmentAnnotation annotation, + ContactMatrixI cm) + { + cmholder.addContactListFor(annotation, cm); + + } }