\r
String jalviewServletURL;\r
\r
- TCoffeeScoreFile tcoffeeScoreFile;\r
\r
public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet, String title, boolean embedded)\r
{\r
changeColour(new Blosum62ColourScheme());\r
}\r
else if (source == tcoffeeColour) {\r
- changeColour(new TCoffeeColourScheme(tcoffeeScoreFile));\r
+ changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));\r
}\r
else if (source == annotationColour)\r
{\r
if( file == null ) {\r
throw new RuntimeException("The file provided does not match the T-Coffee scores file format");\r
}\r
- \r
- tcoffeeColour.setEnabled(true);\r
- tcoffeeScoreFile = file;\r
- \r
- // switch to this color\r
- changeColour(new TCoffeeColourScheme(tcoffeeScoreFile));\r
+ // TODO add parameter to indicate if matching should be done\r
+ if (file.annotateAlignment(alignPanel.getAlignment(), false))\r
+ {\r
+ tcoffeeColour.setEnabled(true);\r
+ // switch to this color\r
+ changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));\r
+ }\r
+\r
}\r
\r
\r
Vector alignPanels = new Vector();
- TCoffeeScoreFile tcoffeeScoreFile;
-
/**
* Last format used to load or save alignments in this window
*/
if( result == null ) { throw new RuntimeException("The file provided does not match the T-Coffee scores file format"); }
// TODO check that the loaded scores matches the current MSA 'dimension'
- changeColour( new TCoffeeColourScheme(result) );
- tcoffeeScoreFile = result;
- tcoffeeColour.setEnabled(true);
- tcoffeeColour.setSelected(true);
-
+ if (result.annotateAlignment(alignPanel.getAlignment(), true))
+ {
+ tcoffeeColour.setEnabled(true);
+ tcoffeeColour.setSelected(true);
+ // switch to this color
+ changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
+ } else {
+ tcoffeeColour.setEnabled(false);
+ tcoffeeColour.setSelected(false);
+ }
}
catch (Exception ex) {
JOptionPane.showMessageDialog(
@Override
protected void tcoffeeColorScheme_actionPerformed(ActionEvent e) {
- if( tcoffeeScoreFile != null ) {
- changeColour( new TCoffeeColourScheme(tcoffeeScoreFile) );
- }
+ changeColour( new TCoffeeColourScheme(alignPanel.getAlignment()) );
}
// /**
package jalview.io;
+import jalview.analysis.SequenceIdMatcher;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
return items.get("cons");
}
}
-
-
+ /**
+ * TCOFFEE score colourscheme
+ */
+ static final Color[] colors = {
+ new Color( 102, 102, 255 ), // #6666FF
+ new Color( 0, 255, 0), // #00FF00
+ new Color( 102, 255, 0), // #66FF00
+ new Color( 204, 255, 0), // #CCFF00
+ new Color( 255, 255, 0), // #FFFF00
+ new Color( 255, 204, 0), // #FFCC00
+ new Color( 255, 153, 0), // #FF9900
+ new Color( 255, 102, 0), // #FF6600
+ new Color( 255, 51, 0), // #FF3300
+ new Color( 255, 34, 0) // #FF2000
+ };
+ public final static String TCOFFEE_SCORE="TCoffeeScore";
+ /**
+ * generate annotation for this TCoffee score set on the given alignment
+ * @param al alignment to annotate
+ * @param matchids if true, annotate sequences based on matching sequence names
+ * @return true if alignment annotation was modified, false otherwise.
+ */
+ public boolean annotateAlignment(AlignmentI al, boolean matchids)
+ {
+ boolean added=false;
+ int i=0;
+ SequenceIdMatcher sidmatcher = new SequenceIdMatcher(al.getSequencesArray());
+ byte[][] scoreMatrix=getScoresArray();
+ // for 2.8 - we locate any existing TCoffee annotation and remove it first before adding this.
+ for (Map.Entry<String,StringBuilder> id:scores.entrySet())
+ {
+ byte[] srow=scoreMatrix[i];
+ SequenceI s;
+ if (matchids)
+ {
+ s=sidmatcher.findIdMatch(id.getKey());
+ } else {
+ s=al.getSequenceAt(i);
+ }
+ i++;
+ if (s==null && i!=scores.size() && !id.getKey().equals("cons"))
+ {
+ System.err.println("No "+(matchids ? "match ":" sequences left ")+" for TCoffee score set : "+id.getKey());
+ continue;
+ }
+ int jSize=al.getWidth()< srow.length ? al.getWidth() : srow.length;
+ Annotation[] annotations=new Annotation[al.getWidth()];
+ for (int j=0;j<jSize;j++) {
+ byte val = srow[j];
+ annotations[j]=new Annotation(s==null ? ""+val:null,s==null ? ""+val:null,(char) val,val*1f,val >= 0 && val < colors.length ? colors[val] : Color.white);
+ }
+ AlignmentAnnotation aa=null;
+ if (s!=null)
+ {
+ // TODO - set per sequence score
+ aa=new AlignmentAnnotation(TCOFFEE_SCORE, "Score for "+id.getKey(), annotations);
+
+ aa.setSequenceRef(s);
+ aa.visible=false;
+ aa.belowAlignment=false;
+ } else {
+ aa=new AlignmentAnnotation("T-COFFEE", "TCoffee column reliability score", annotations);
+ aa.belowAlignment=true;
+ aa.visible=true;
+
+ }
+ al.addAnnotation(aa);
+ added=true;
+ }
+ return added;
+ }
+
}
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
};
- byte[][] scoreMatrix = null;
-
+ IdentityHashMap<SequenceI, Color[]> 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<AlignmentAnnotation> annots = new ArrayList<AlignmentAnnotation>();
+ // Search alignment to get all tcoffee annotation and pick one set of annotation to use to colour seqs.
+ seqMap = new IdentityHashMap<SequenceI, Color[]>();
+ 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];
}
}