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.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.AnnotatedCollectionI;
26 import jalview.datamodel.Annotation;
27 import jalview.datamodel.SequenceCollectionI;
28 import jalview.datamodel.SequenceI;
29 import jalview.io.TCoffeeScoreFile;
31 import java.awt.Color;
32 import java.util.ArrayList;
33 import java.util.IdentityHashMap;
34 import java.util.List;
38 * Defines the color score for T-Coffee MSA
40 * See http://tcoffee.org
43 * @author Paolo Di Tommaso
46 public class TCoffeeColourScheme extends ResidueColourScheme
48 IdentityHashMap<SequenceI, Color[]> seqMap;
51 * Default constructor (required for Class.newInstance())
53 public TCoffeeColourScheme()
59 * the color scheme needs to look at the alignment to get and cache T-COFFEE
63 * - annotated sequences to be searched
65 public TCoffeeColourScheme(AnnotatedCollectionI alignment)
67 alignmentChanged(alignment, null);
71 * Finds the TCoffeeScore annotation (if any) for each sequence and notes the
72 * annotation colour for each column position. The colours are fixed for
73 * scores 0-9 and are set when annotation is parsed.
75 * @see TCoffeeScoreFile#annotateAlignment(AlignmentI, boolean)
78 public void alignmentChanged(AnnotatedCollectionI alignment,
79 Map<SequenceI, SequenceCollectionI> hiddenReps)
81 // TODO: if sequences have been represented and they have scores, could
82 // compute an average sequence score for the representative
84 // assume only one set of TCOFFEE scores - but could have more than one
86 List<AlignmentAnnotation> annots = new ArrayList<AlignmentAnnotation>();
87 // Search alignment to get all tcoffee annotation and pick one set of
88 // annotation to use to colour seqs.
89 seqMap = new IdentityHashMap<SequenceI, Color[]>();
90 AnnotatedCollectionI alcontext = alignment instanceof AlignmentI
92 : alignment.getContext();
93 if (alcontext == null)
98 for (AlignmentAnnotation al : alcontext
99 .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE))
101 if (al.sequenceRef != null && !al.belowAlignment)
104 if (w < al.annotations.length)
106 w = al.annotations.length;
108 Color[] scores = new Color[al.annotations.length];
110 for (Annotation an : al.annotations)
112 scores[i++] = (an != null) ? an.colour : Color.white;
114 seqMap.put(al.sequenceRef, scores);
117 // TODO: compute average colour for each symbol type in each column - gives
118 // a second order colourscheme for colouring a sequence logo derived from
119 // the alignment (colour reflects quality of alignment for each residue
124 public Color findColour(char c, int j, SequenceI seq)
130 Color[] cols = seqMap.get(seq);
133 // see above TODO about computing a colour for each residue in each
134 // column: cc = _rcols[i][indexFor[c]];
138 if (j < 0 || j >= cols.length)
146 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
147 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
149 return new TCoffeeColourScheme(sg);
153 * Answers true if the data has TCoffee score annotation
156 public boolean isApplicableTo(AnnotatedCollectionI ac)
158 AnnotatedCollectionI alcontext = ac instanceof AlignmentI ? ac
160 if (alcontext == null)
164 Iterable<AlignmentAnnotation> anns = alcontext
165 .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE);
166 return anns.iterator().hasNext();
170 public String getSchemeName()
172 return JalviewColourScheme.TCoffee.toString();
176 public boolean isSimple()