Merge branch 'develop' (JAL-4102 2.11.2.6 patch release) into features/r2_11_2_alphaf...
[jalview.git] / src / jalview / datamodel / ContactMapHolder.java
1 package jalview.datamodel;
2
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.HashMap;
6 import java.util.Map;
7
8 public class ContactMapHolder implements ContactMapHolderI
9 {
10
11   Map<Object, ContactMatrixI> contactmaps = new HashMap<>();
12
13   @Override
14   public Collection<ContactMatrixI> getContactMaps()
15   {
16     if (contactmaps != null && contactmaps.size() > 0)
17     {
18       return contactmaps.values();
19     }
20     return Collections.EMPTY_LIST;
21   }
22
23   @Override
24   public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
25   {
26     ContactMatrixI cm = contactmaps.get(_aa.annotationId);
27     if (cm == null)
28     {
29       return null;
30     }
31     // TODO: could resolve sequence position to column position here
32     // TODO: what about for complexes - where contactMatrix may involve two or
33     // more sequences
34     return cm.getContactList(column);
35   }
36
37   @Override
38   public AlignmentAnnotation addContactList(ContactMatrixI cm)
39   {
40
41     AlignmentAnnotation aa = new AlignmentAnnotation(cm.getAnnotLabel(),
42             cm.getAnnotDescr(), new Annotation[0]);
43     aa.graph = AlignmentAnnotation.CUSTOMRENDERER;
44     aa.graphMin = cm.getMin();
45     aa.graphMax = cm.getMax();
46     aa.editable = false;
47
48     contactmaps.put(aa.annotationId, cm);
49     // TODO: contact matrices could be intra or inter - more than one refseq
50     // possible!
51     if (cm.hasReferenceSeq())
52     {
53       aa.setSequenceRef(cm.getReferenceSeq());
54     }
55     return aa;
56   }
57
58   @Override
59   public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
60   {
61     return contactmaps == null ? null : contactmaps.get(ann.annotationId);
62   }
63
64   @Override
65   public void addContactListFor(AlignmentAnnotation annotation,
66           ContactMatrixI cm)
67   {
68     contactmaps.put(annotation.annotationId, cm);
69   }
70 }