584937424e2b5f183049e5410d0151067a099ed5
[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.CONTACT_MAP;
44     aa.graphMin = cm.getMin();
45     aa.graphMax = cm.getMax();
46     aa.editable = false;
47     aa.calcId=cm.getType();
48
49     contactmaps.put(aa.annotationId, cm);
50     // TODO: contact matrices could be intra or inter - more than one refseq
51     // possible!
52     if (cm.hasReferenceSeq())
53     {
54       aa.setSequenceRef(cm.getReferenceSeq());
55     }
56     return aa;
57   }
58
59   @Override
60   public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
61   {
62     return contactmaps == null ? null : contactmaps.get(ann.annotationId);
63   }
64
65   @Override
66   public void addContactListFor(AlignmentAnnotation annotation,
67           ContactMatrixI cm)
68   {
69     // update annotation with data from contact map
70     annotation.graphMin = cm.getMin();
71     annotation.graphMax = cm.getMax();
72     annotation.editable = false;
73     annotation.graph = AlignmentAnnotation.CONTACT_MAP;
74     annotation.calcId = cm.getType();
75     annotation.label = cm.getAnnotLabel();
76     annotation.description = cm.getAnnotDescr();
77     contactmaps.put(annotation.annotationId, cm);
78   }
79 }