Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  2. Package jalview.datamodel

File ContactMapHolder.java

 

Coverage histogram

../../img/srcFileCovDistChart9.png
13% of files have more coverage

Code metrics

16
31
5
1
119
79
16
0.52
6.2
5
3.2

Classes

Class Line # Actions
ContactMapHolder 31 31 16
0.826923182.7%
 

Contributing tests

This file is covered by 66 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.datamodel;
22   
23    import java.util.Collection;
24    import java.util.Collections;
25    import java.util.HashMap;
26    import java.util.HashSet;
27    import java.util.Map;
28   
29    import jalview.ws.datamodel.MappableContactMatrixI;
30   
 
31    public class ContactMapHolder implements ContactMapHolderI
32    {
33   
34    Map<Object, ContactMatrixI> contactmaps = new HashMap<>();
35   
 
36  33 toggle @Override
37    public Collection<ContactMatrixI> getContactMaps()
38    {
39  33 if (contactmaps != null && contactmaps.size() > 0)
40    {
41    // defensive copy, and return non redundant set of ContactMatrixI
42    // instances
43  12 return new HashSet<ContactMatrixI>(contactmaps.values());
44    }
45  21 return Collections.EMPTY_LIST;
46    }
47   
 
48  7077 toggle @Override
49    public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
50    {
51  7077 ContactMatrixI cm = contactmaps.get(_aa.annotationId);
52  7077 if (cm == null)
53    {
54  3476 return null;
55    }
56  3601 if (cm instanceof MappableContactMatrixI)
57    {
58  3601 if (_aa.sequenceRef != null)
59    {
60  3601 return ((MappableContactMatrixI) cm)
61    .getMappableContactList(_aa.sequenceRef, column);
62    }
63    }
64    // TODO: could resolve sequence position to column position here
65    // TODO: what about for complexes - where contactMatrix may involve two or
66    // more sequences
67  0 return cm.getContactList(column);
68    }
69   
 
70  118 toggle @Override
71    public AlignmentAnnotation addContactList(ContactMatrixI cm)
72    {
73   
74  118 AlignmentAnnotation aa = new AlignmentAnnotation(cm.getAnnotLabel(),
75    cm.getAnnotDescr(), new Annotation[0]);
76  118 aa.graph = AlignmentAnnotation.CONTACT_MAP;
77  118 aa.graphMin = cm.getMin();
78  118 aa.graphMax = cm.getMax();
79  118 aa.editable = false;
80  118 aa.calcId = cm.getType();
81   
82  118 contactmaps.put(aa.annotationId, cm);
83    // TODO: contact matrices could be intra or inter - more than one refseq
84    // possible!
85  118 if (cm instanceof MappableContactMatrixI)
86    {
87  118 aa.setSequenceRef(((MappableContactMatrixI) cm).getReferenceSeq());
88    }
89  118 return aa;
90    }
91   
 
92  597 toggle @Override
93    public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
94    {
95  597 return contactmaps == null ? null : contactmaps.get(ann.annotationId);
96    }
97   
 
98  74 toggle @Override
99    public void addContactListFor(AlignmentAnnotation annotation,
100    ContactMatrixI cm)
101    {
102    // update annotation with data from contact map
103  74 annotation.graphMin = cm.getMin();
104  74 annotation.graphMax = cm.getMax();
105  74 annotation.editable = false;
106  74 annotation.graph = AlignmentAnnotation.CONTACT_MAP;
107  74 annotation.calcId = cm.getType();
108  74 if (annotation.label == null || "".equals(annotation.label))
109    {
110  0 annotation.label = cm.getAnnotLabel();
111   
112    }
113  74 if (annotation.description == null || "".equals(annotation.description))
114    {
115  0 annotation.description = cm.getAnnotDescr();
116    }
117  74 contactmaps.put(annotation.annotationId, cm);
118    }
119    }