JAL-2349 JAL-3855 Integrate pAE retrieval in StructureFile so it can be transferred...
[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     return cm.getContactList(column);
32   }
33
34   @Override
35   public AlignmentAnnotation addContactList(ContactMatrixI cm)
36   {
37     AlignmentAnnotation aa = new AlignmentAnnotation("Contact Matrix",
38             "Contact Matrix", new Annotation[0]);
39     aa.graph = AlignmentAnnotation.CUSTOMRENDERER;
40     aa.graphMin = cm.getMin();
41     aa.graphMax = cm.getMax();
42     aa.editable = false;
43     // aa.autoCalculated = true;
44     contactmaps.put(aa.annotationId, cm);
45     // TODO: contact matrices could be intra or inter - more than one refseq
46     // possible!
47     if (cm.hasReferenceSeq())
48     {
49       aa.setSequenceRef(cm.getReferenceSeq());
50     }
51     return aa;
52   }
53
54   @Override
55   public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
56   {
57     return contactmaps == null ? null : contactmaps.get(ann.annotationId);
58   }
59
60   @Override
61   public void addContactListFor(AlignmentAnnotation annotation,
62           ContactMatrixI cm)
63   {
64     contactmaps.put(annotation.annotationId, cm);
65   }
66 }