Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.schemes

File TCoffeeColourScheme.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
0% 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.00%
 

Contributing tests

No tests hitting this source file were found.

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  0 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  0 toggle public TCoffeeColourScheme(AnnotatedCollectionI alignment)
67    {
68  0 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  0 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  0 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  0 seqMap = new IdentityHashMap<>();
91  0 AnnotatedCollectionI alcontext = alignment instanceof AlignmentI
92    ? alignment
93    : alignment.getContext();
94  0 if (alcontext == null)
95    {
96  0 return;
97    }
98  0 int w = 0;
99  0 for (AlignmentAnnotation al : alcontext
100    .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE))
101    {
102  0 if (al.sequenceRef != null && !al.belowAlignment)
103    {
104  0 annots.add(al);
105  0 if (w < al.annotations.length)
106    {
107  0 w = al.annotations.length;
108    }
109  0 Color[] scores = new Color[al.annotations.length];
110  0 int i = 0;
111  0 for (Annotation an : al.annotations)
112    {
113  0 scores[i++] = (an != null) ? an.colour : Color.white;
114    }
115  0 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  0 toggle @Override
125    public Color findColour(char c, int j, SequenceI seq)
126    {
127  0 if (seqMap == null)
128    {
129  0 return Color.WHITE;
130    }
131  0 Color[] cols = seqMap.get(seq);
132  0 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  0 if (j < 0 || j >= cols.length)
140    {
141  0 return Color.white;
142    }
143  0 return cols[j];
144    }
145   
 
146  0 toggle @Override
147    public ColourSchemeI getInstance(AlignViewportI view,
148    AnnotatedCollectionI sg)
149    {
150  0 return new TCoffeeColourScheme(sg);
151    }
152   
153    /**
154    * Answers true if the data has TCoffee score annotation
155    */
 
156  0 toggle @Override
157    public boolean isApplicableTo(AnnotatedCollectionI ac)
158    {
159  0 AnnotatedCollectionI alcontext = ac instanceof AlignmentI ? ac
160    : ac.getContext();
161  0 if (alcontext == null)
162    {
163  0 return false;
164    }
165  0 Iterable<AlignmentAnnotation> anns = alcontext
166    .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE);
167  0 return anns.iterator().hasNext();
168    }
169   
 
170  0 toggle @Override
171    public String getSchemeName()
172    {
173  0 return JalviewColourScheme.TCoffee.toString();
174    }
175   
 
176  0 toggle @Override
177    public boolean isSimple()
178    {
179  0 return false;
180    }
181    }