Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.schemes

File TCoffeeColourScheme.java

 

Coverage histogram

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

Code metrics

20
33
8
1
181
106
20
0.61
4.12
8
2.5

Classes

Class Line # Actions
TCoffeeColourScheme 47 33 20
0.819672182%
 

Contributing tests

This file is covered by 189 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.schemes;
22   
23    import jalview.api.AlignViewportI;
24    import jalview.datamodel.AlignmentAnnotation;
25    import jalview.datamodel.AlignmentI;
26    import jalview.datamodel.AnnotatedCollectionI;
27    import jalview.datamodel.Annotation;
28    import jalview.datamodel.SequenceCollectionI;
29    import jalview.datamodel.SequenceI;
30    import jalview.io.TCoffeeScoreFile;
31   
32    import java.awt.Color;
33    import java.util.ArrayList;
34    import java.util.IdentityHashMap;
35    import java.util.List;
36    import java.util.Map;
37   
38    /**
39    * Defines the color score for T-Coffee MSA
40    * <p>
41    * See http://tcoffee.org
42    *
43    *
44    * @author Paolo Di Tommaso
45    *
46    */
 
47    public class TCoffeeColourScheme extends ResidueColourScheme
48    {
49    IdentityHashMap<SequenceI, Color[]> seqMap;
50   
51    /**
52    * Default constructor (required for Class.newInstance())
53    */
 
54  50 toggle public TCoffeeColourScheme()
55    {
56   
57    }
58   
59    /**
60    * the color scheme needs to look at the alignment to get and cache T-COFFEE
61    * scores
62    *
63    * @param alignment
64    * - annotated sequences to be searched
65    */
 
66  11 toggle public TCoffeeColourScheme(AnnotatedCollectionI alignment)
67    {
68  11 alignmentChanged(alignment, null);
69    }
70   
71    /**
72    * Finds the TCoffeeScore annotation (if any) for each sequence and notes the
73    * annotation colour for each column position. The colours are fixed for
74    * scores 0-9 and are set when annotation is parsed.
75    *
76    * @see TCoffeeScoreFile#annotateAlignment(AlignmentI, boolean)
77    */
 
78  15 toggle @Override
79    public void alignmentChanged(AnnotatedCollectionI alignment,
80    Map<SequenceI, SequenceCollectionI> hiddenReps)
81    {
82    // TODO: if sequences have been represented and they have scores, could
83    // compute an average sequence score for the representative
84   
85    // assume only one set of TCOFFEE scores - but could have more than one
86    // potentially.
87  15 List<AlignmentAnnotation> annots = new ArrayList<>();
88    // Search alignment to get all tcoffee annotation and pick one set of
89    // annotation to use to colour seqs.
90  15 seqMap = new IdentityHashMap<>();
91  15 AnnotatedCollectionI alcontext = alignment instanceof AlignmentI
92    ? alignment
93    : alignment.getContext();
94  15 if (alcontext == null)
95    {
96  0 return;
97    }
98  15 int w = 0;
99  15 for (AlignmentAnnotation al : alcontext
100    .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE))
101    {
102  114 if (al.sequenceRef != null && !al.belowAlignment)
103    {
104  105 annots.add(al);
105  105 if (w < al.annotations.length)
106    {
107  7 w = al.annotations.length;
108    }
109  105 Color[] scores = new Color[al.annotations.length];
110  105 int i = 0;
111  105 for (Annotation an : al.annotations)
112    {
113  16485 scores[i++] = (an != null) ? an.colour : Color.white;
114    }
115  105 seqMap.put(al.sequenceRef, scores);
116    }
117    }
118    // TODO: compute average colour for each symbol type in each column - gives
119    // a second order colourscheme for colouring a sequence logo derived from
120    // the alignment (colour reflects quality of alignment for each residue
121    // class)
122    }
123   
 
124  8283 toggle @Override
125    public Color findColour(char c, int j, SequenceI seq)
126    {
127  8283 if (seqMap == null)
128    {
129  0 return Color.WHITE;
130    }
131  8283 Color[] cols = seqMap.get(seq);
132  8283 if (cols == null)
133    {
134    // see above TODO about computing a colour for each residue in each
135    // column: cc = _rcols[i][indexFor[c]];
136  0 return Color.white;
137    }
138   
139  8283 if (j < 0 || j >= cols.length)
140    {
141  0 return Color.white;
142    }
143  8283 return cols[j];
144    }
145   
 
146  4 toggle @Override
147    public ColourSchemeI getInstance(AlignViewportI view,
148    AnnotatedCollectionI sg)
149    {
150  4 return new TCoffeeColourScheme(sg);
151    }
152   
153    /**
154    * Answers true if the data has TCoffee score annotation
155    */
 
156  466 toggle @Override
157    public boolean isApplicableTo(AnnotatedCollectionI ac)
158    {
159  466 AnnotatedCollectionI alcontext = ac instanceof AlignmentI ? ac
160    : ac.getContext();
161  466 if (alcontext == null)
162    {
163  0 return false;
164    }
165  466 Iterable<AlignmentAnnotation> anns = alcontext
166    .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE);
167  466 return anns.iterator().hasNext();
168    }
169   
 
170  572 toggle @Override
171    public String getSchemeName()
172    {
173  572 return JalviewColourScheme.TCoffee.toString();
174    }
175   
 
176  47 toggle @Override
177    public boolean isSimple()
178    {
179  47 return false;
180    }
181    }