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 ? alignment
91 : alignment.getContext();
92 if (alcontext == null)
97 for (AlignmentAnnotation al : alcontext
98 .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE))
100 if (al.sequenceRef != null && !al.belowAlignment)
103 if (w < al.annotations.length)
105 w = al.annotations.length;
107 Color[] scores = new Color[al.annotations.length];
109 for (Annotation an : al.annotations)
111 scores[i++] = (an != null) ? an.colour : Color.white;
113 seqMap.put(al.sequenceRef, scores);
116 // TODO: compute average colour for each symbol type in each column - gives
117 // a second order colourscheme for colouring a sequence logo derived from
118 // the alignment (colour reflects quality of alignment for each residue
123 public Color findColour(char c, int j, SequenceI seq)
129 Color[] cols = seqMap.get(seq);
132 // see above TODO about computing a colour for each residue in each
133 // column: cc = _rcols[i][indexFor[c]];
137 if (j < 0 || j >= cols.length)
145 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
146 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
148 return new TCoffeeColourScheme(sg);
152 * Answers true if the data has TCoffee score annotation
155 public boolean isApplicableTo(AnnotatedCollectionI ac)
157 AnnotatedCollectionI alcontext = ac instanceof AlignmentI ? ac : ac
159 if (alcontext == null)
163 Iterable<AlignmentAnnotation> anns = alcontext
164 .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE);
165 return anns.iterator().hasNext();
169 public String getSchemeName()
171 return JalviewColourScheme.TCoffee.toString();
175 public boolean isSimple()