X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FHmmerColourScheme.java;h=0f81ec1f35f398105067abd21437c64ac40ea84e;hb=d25ed8f9fb513fe5c33823afbeeb557c73a8c27b;hp=d31f0e18b2af3282c2eaf45341982e277979c658;hpb=787c729c03ee03aa76de75ccea53afb22e4c5927;p=jalview.git
diff --git a/src/jalview/schemes/HmmerColourScheme.java b/src/jalview/schemes/HmmerColourScheme.java
index d31f0e1..0f81ec1 100644
--- a/src/jalview/schemes/HmmerColourScheme.java
+++ b/src/jalview/schemes/HmmerColourScheme.java
@@ -8,14 +8,15 @@ import jalview.util.ColorUtils;
import jalview.util.Comparison;
import java.awt.Color;
+import java.util.List;
import java.util.Map;
/**
* Base class for colour schemes based on a selected Hidden Markov Model. The
- * colour is
+ * colour is with reference to an HMM consensus sequence and HMM profile
*
* - white for a gap
- * - red for an insertion
+ * - red for an insertion (position is gapped in the HMM consensus)
* - orange for negative information content
* - white to blue for increasing information content
*
@@ -35,18 +36,26 @@ public abstract class HmmerColourScheme extends ResidueColourScheme
{
private static final Color INSERTION_COLOUR = new Color(230, 0, 0); // reddish
+ /*
+ * the aligned HMM consensus sequence to use as reference for colouring
+ */
+ private SequenceI hmmSeq;
+
private HiddenMarkovModel hmm;
private Map frequencies;
/**
- * Constructor given a Hidden Markov Model
+ * Constructor given a list of Hidden Markov Model consensus sequences. The
+ * first sequence provides the HMM profile from which we can read the emission
+ * probabilities that determine the colour.
*
- * @param markov
+ * @param hmmSeqs
*/
- public HmmerColourScheme(HiddenMarkovModel markov)
+ public HmmerColourScheme(List hmmSeqs)
{
- hmm = markov;
+ hmmSeq = hmmSeqs.isEmpty() ? null : hmmSeqs.get(0);
+ hmm = hmmSeq == null ? null : hmmSeq.getHMM();
}
/**
@@ -57,10 +66,10 @@ public abstract class HmmerColourScheme extends ResidueColourScheme
}
@Override
- public Color findColour(char symbol, int position, SequenceI seq,
+ public Color findColour(char symbol, int column, SequenceI seq,
String consensusResidue, float pid)
{
- return findColour(symbol, position);
+ return findColour(symbol, column);
}
/**
@@ -82,6 +91,10 @@ public abstract class HmmerColourScheme extends ResidueColourScheme
{
return Color.white;
}
+ if (Comparison.isGap(hmmSeq.getCharAt(column)))
+ {
+ return INSERTION_COLOUR;
+ }
if (Character.isLowerCase(symbol))
{
symbol = Character.toUpperCase(symbol);
@@ -100,19 +113,22 @@ public abstract class HmmerColourScheme extends ResidueColourScheme
{
freq = frequencies.get(symbol);
}
- if (prob == 0D)
- {
- return INSERTION_COLOUR;
- }
- double value = Math.log(prob / freq.floatValue());
- Color colour = null;
- if (value < 0)
+
+ /*
+ * Orange if match emission probability is less than background probability
+ */
+ double infoRatio = prob / freq.floatValue();
+ Color colour = Color.ORANGE;
+ if (infoRatio >= 1)
{
- return Color.ORANGE;
+ /*
+ * log-scale graduated shade of blue if prob is greater than background
+ */
+ float infoLog = (float) Math.log(infoRatio);
+ colour = ColorUtils.getGraduatedColour(infoLog, 0, Color.WHITE,
+ getMaxInformationScore(), Color.blue);
}
- colour = ColorUtils.getGraduatedColour((float) value, 0, Color.WHITE,
- getMaxInformationScore(), Color.blue);
return colour;
}
@@ -124,16 +140,6 @@ public abstract class HmmerColourScheme extends ResidueColourScheme
*/
abstract float getMaxInformationScore();
- @Override
- public void alignmentChanged(AnnotatedCollectionI collection,
- Map hiddenReps)
- {
- /*
- * ? no need to do anything if alignment is adjusted
- * since findColour() handles everything
- */
- }
-
/**
* Answers a new colour scheme instance based on the HMM of the first sequence
* in ac that has an HMM
@@ -142,21 +148,16 @@ public abstract class HmmerColourScheme extends ResidueColourScheme
public ColourSchemeI getInstance(AnnotatedCollectionI ac,
Map hiddenRepSequences)
{
- SequenceI hmmSeq = ac.getHmmConsensus();
- HiddenMarkovModel model = hmmSeq == null ? null : hmmSeq.getHMM();
-
- return newInstance(ac, model);
+ return newInstance(ac);
}
/**
* Answers a new instance of the colour scheme for the given HMM
*
* @param ac
- * @param model
* @return
*/
- protected abstract HmmerColourScheme newInstance(AnnotatedCollectionI ac,
- HiddenMarkovModel model);
+ protected abstract HmmerColourScheme newInstance(AnnotatedCollectionI ac);
@Override
public boolean isSimple()
@@ -171,7 +172,7 @@ public abstract class HmmerColourScheme extends ResidueColourScheme
@Override
public boolean isApplicableTo(AnnotatedCollectionI ac)
{
- return ac.getHmmConsensus() != null;
+ return !ac.getHmmSequences().isEmpty();
}
protected Map getFrequencies()
@@ -189,4 +190,8 @@ public abstract class HmmerColourScheme extends ResidueColourScheme
return hmm;
}
+ protected SequenceI getHmmSequence()
+ {
+ return hmmSeq;
+ }
}