4b46d7dc0783369bc6fa11b927c1455ce961f464
[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     AlignmentAnnotation aa = new AlignmentAnnotation("Contact Matrix",
41             "Contact Matrix", new Annotation[0]);
42     aa.graph = AlignmentAnnotation.CUSTOMRENDERER;
43     aa.graphMin = cm.getMin();
44     aa.graphMax = cm.getMax();
45     aa.editable = false;
46     // aa.autoCalculated = true;
47     contactmaps.put(aa.annotationId, cm);
48     // TODO: contact matrices could be intra or inter - more than one refseq
49     // possible!
50     if (cm.hasReferenceSeq())
51     {
52       aa.setSequenceRef(cm.getReferenceSeq());
53     }
54     return aa;
55   }
56
57   @Override
58   public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
59   {
60     return contactmaps == null ? null : contactmaps.get(ann.annotationId);
61   }
62
63   @Override
64   public void addContactListFor(AlignmentAnnotation annotation,
65           ContactMatrixI cm)
66   {
67     contactmaps.put(annotation.annotationId, cm);
68   }
69 }