X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FTCoffeeColourScheme.java;fp=src%2Fjalview%2Fschemes%2FTCoffeeColourScheme.java;h=bbd2a23c4c4bce57c2a004f31d8f9d8f6b04aabb;hb=6a3f4318037072a77588afb951a5a53835d5da99;hp=740c15ec6388b0b30bbdf82f33a624bf0d40caa8;hpb=1379350f04bc63ca05bd428afb86717c4764755d;p=jalview.git diff --git a/src/jalview/schemes/TCoffeeColourScheme.java b/src/jalview/schemes/TCoffeeColourScheme.java index 740c15e..bbd2a23 100644 --- a/src/jalview/schemes/TCoffeeColourScheme.java +++ b/src/jalview/schemes/TCoffeeColourScheme.java @@ -1,8 +1,17 @@ package jalview.schemes; +import jalview.analysis.SequenceIdMatcher; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.AnnotatedCollectionI; +import jalview.datamodel.Annotation; +import jalview.datamodel.SequenceI; import jalview.io.TCoffeeScoreFile; import java.awt.Color; +import java.util.ArrayList; +import java.util.IdentityHashMap; +import java.util.TreeMap; /** * Defines the color score for T-Coffee MSA @@ -29,38 +38,47 @@ public class TCoffeeColourScheme extends ResidueColourScheme { }; - byte[][] scoreMatrix = null; - + IdentityHashMap seqMap; /** - * Initialize the color sheme based on the content of the T-Coffee score file + * the color scheme needs to look at the alignment to get and cache T-COFFEE scores * - * @param scoreFile + * @param alignment - annotated sequences to be searched */ - public TCoffeeColourScheme(TCoffeeScoreFile scoreFile) { - - scoreMatrix = scoreFile != null ? scoreFile.getScoresArray() : null; - + public TCoffeeColourScheme(AnnotatedCollectionI alignment) { + alignmentChanged(alignment); + } + @Override public void alignmentChanged(AnnotatedCollectionI alignment) + { + // assume only one set of TCOFFEE scores - but could have more than one potentially. + ArrayList annots = new ArrayList(); + // Search alignment to get all tcoffee annotation and pick one set of annotation to use to colour seqs. + seqMap = new IdentityHashMap(); + for (AlignmentAnnotation al:alignment.getAlignmentAnnotation()) + { + if (al.sequenceRef!=null && !al.belowAlignment && al.label!=null && (al.label==TCoffeeScoreFile.TCOFFEE_SCORE || al.label.equals(TCoffeeScoreFile.TCOFFEE_SCORE))) + { + annots.add(al); + Color[] scores=new Color[al.annotations.length]; + int i=0; + for (Annotation an:al.annotations) + { + scores[i++]=(an!=null) ? an.colour : Color.white; + } + seqMap.put(al.sequenceRef, scores); + } + } } - @Override - public Color findColour(char c, int j, int sequenceIndex) { - - if( scoreMatrix == null ) { - return Color.white; - } - - if( sequenceIndex<0 || sequenceIndex >= scoreMatrix.length ) { - System.out.printf("Sequence index out of range for the T-Coffee color scheme. Index: %s\n", sequenceIndex); - return Color.white; - } + public Color findColour(char c, int j, SequenceI seq) { + Color[] cols; - byte[] seqScores = scoreMatrix[sequenceIndex]; - if( j < 0 || j>= seqScores.length ) { - System.out.printf("Residue index out of range for the T-Coffee color scheme. Sequence %s - residue: %s\n", sequenceIndex, j); - return Color.white; - } - - byte val = seqScores[j]; - return val >= 0 && val < colors.length ? colors[val] : Color.white; + if( seqMap==null || (cols=seqMap.get(seq))==null) { + return Color.white; + } + + if( j < 0 || j>= cols.length ) { + return Color.white; + } + return cols[j]; } }