todo for JAL-1106
[jalview.git] / src / jalview / schemes / TCoffeeColourScheme.java
1 package jalview.schemes;
2
3 import jalview.analysis.SequenceIdMatcher;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.AnnotatedCollectionI;
7 import jalview.datamodel.Annotation;
8 import jalview.datamodel.SequenceI;
9 import jalview.io.TCoffeeScoreFile;
10
11 import java.awt.Color;
12 import java.util.ArrayList;
13 import java.util.IdentityHashMap;
14 import java.util.TreeMap;
15
16 /**
17  * Defines the color score for T-Coffee MSA 
18  * <p>
19  * See http://tcoffee.org
20  * 
21  * 
22  * @author Paolo Di Tommaso
23  *
24  */
25 public class TCoffeeColourScheme extends ResidueColourScheme {
26
27         static final Color[] colors = {
28                 new Color( 102, 102, 255 ),     // #6666FF
29                 new Color( 0, 255, 0),          // #00FF00
30                 new Color( 102, 255, 0),        // #66FF00
31                 new Color( 204, 255, 0),        // #CCFF00
32                 new Color( 255, 255, 0),        // #FFFF00
33                 new Color( 255, 204, 0),        // #FFCC00
34                 new Color( 255, 153, 0),        // #FF9900
35                 new Color( 255, 102, 0),        // #FF6600
36                 new Color( 255, 51, 0),         // #FF3300
37                 new Color( 255, 34, 0)          // #FF2000
38         };
39
40
41         IdentityHashMap<SequenceI, Color[]> seqMap;
42         /**
43          * the color scheme needs to look at the alignment to get and cache T-COFFEE scores 
44          * 
45          * @param alignment - annotated sequences to be searched
46          */
47         public TCoffeeColourScheme(AnnotatedCollectionI alignment) {
48           alignmentChanged(alignment);
49         }
50         @Override public void alignmentChanged(AnnotatedCollectionI alignment)
51         {
52           // assume only one set of TCOFFEE scores - but could have more than one potentially.
53           ArrayList<AlignmentAnnotation> annots = new ArrayList<AlignmentAnnotation>();
54           // Search alignment to get all tcoffee annotation and pick one set of annotation to use to colour seqs.
55           seqMap = new IdentityHashMap<SequenceI, Color[]>();
56           int w=0;
57           for (AlignmentAnnotation al:alignment.findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE))
58           {
59             if (al.sequenceRef!=null && !al.belowAlignment)
60             {
61               annots.add(al);
62               if (w<al.annotations.length)
63               {
64                 w=al.annotations.length;
65               }
66               Color[] scores=new Color[al.annotations.length];
67               int i=0;
68               for (Annotation an:al.annotations)
69               {
70                 scores[i++]=(an!=null) ? an.colour : Color.white;
71               }
72               seqMap.put(al.sequenceRef, scores);
73             }
74           }
75     // TODO: compute average colour for each symbol type in each column - gives
76     // a second order colourscheme for colouring a sequence logo derived from
77     // the alignment (colour reflects quality of alignment for each residue
78     // class)
79         }
80         @Override
81         public Color findColour(char c, int j, SequenceI seq) {
82           Color[] cols;
83
84           if( seqMap==null || (cols=seqMap.get(seq))==null) {
85 //      see above TODO about computing a colour for each residue in each column:            cc = _rcols[i][indexFor[c]];
86             return Color.white;
87           }
88           
89           if( j < 0 || j>= cols.length ) {
90             return Color.white;
91           }
92           return cols[j];
93         }
94 }