2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.schemes;
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;
32 import java.awt.Color;
33 import java.util.ArrayList;
34 import java.util.IdentityHashMap;
35 import java.util.List;
39 * Defines the color score for T-Coffee MSA
41 * See http://tcoffee.org
44 * @author Paolo Di Tommaso
47 public class TCoffeeColourScheme extends ResidueColourScheme
49 IdentityHashMap<SequenceI, Color[]> seqMap;
52 * Default constructor (required for Class.newInstance())
54 public TCoffeeColourScheme()
60 * the color scheme needs to look at the alignment to get and cache T-COFFEE
64 * - annotated sequences to be searched
66 public TCoffeeColourScheme(AnnotatedCollectionI alignment)
68 alignmentChanged(alignment, null);
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.
76 * @see TCoffeeScoreFile#annotateAlignment(AlignmentI, boolean)
79 public void alignmentChanged(AnnotatedCollectionI alignment,
80 Map<SequenceI, SequenceCollectionI> hiddenReps)
82 // TODO: if sequences have been represented and they have scores, could
83 // compute an average sequence score for the representative
85 // assume only one set of TCOFFEE scores - but could have more than one
87 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 seqMap = new IdentityHashMap<>();
91 AnnotatedCollectionI alcontext = alignment instanceof AlignmentI
93 : alignment.getContext();
94 if (alcontext == null)
99 for (AlignmentAnnotation al : alcontext
100 .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE))
102 if (al.sequenceRef != null && !al.belowAlignment)
105 if (w < al.annotations.length)
107 w = al.annotations.length;
109 Color[] scores = new Color[al.annotations.length];
111 for (Annotation an : al.annotations)
113 scores[i++] = (an != null) ? an.colour : Color.white;
115 seqMap.put(al.sequenceRef, scores);
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
125 public Color findColour(char c, int j, SequenceI seq)
131 Color[] cols = seqMap.get(seq);
134 // see above TODO about computing a colour for each residue in each
135 // column: cc = _rcols[i][indexFor[c]];
139 if (j < 0 || j >= cols.length)
147 public ColourSchemeI getInstance(AlignViewportI view,
148 AnnotatedCollectionI sg)
150 return new TCoffeeColourScheme(sg);
154 * Answers true if the data has TCoffee score annotation
157 public boolean isApplicableTo(AnnotatedCollectionI ac)
159 AnnotatedCollectionI alcontext = ac instanceof AlignmentI ? ac
161 if (alcontext == null)
165 Iterable<AlignmentAnnotation> anns = alcontext
166 .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE);
167 return anns.iterator().hasNext();
171 public String getSchemeName()
173 return JalviewColourScheme.TCoffee.toString();
177 public boolean isSimple()