JAl-2629 add new HMMER colour scheme class
authorTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Fri, 25 Aug 2017 16:10:28 +0000 (17:10 +0100)
committerTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Fri, 25 Aug 2017 16:21:07 +0000 (17:21 +0100)
src/jalview/schemes/HMMERAlignmentColourScheme.java [new file with mode: 0644]
src/jalview/schemes/HMMERColourScheme.java
src/jalview/schemes/JalviewColourScheme.java

diff --git a/src/jalview/schemes/HMMERAlignmentColourScheme.java b/src/jalview/schemes/HMMERAlignmentColourScheme.java
new file mode 100644 (file)
index 0000000..47c065b
--- /dev/null
@@ -0,0 +1,156 @@
+package jalview.schemes;
+
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.HiddenMarkovModel;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
+import jalview.util.Comparison;
+
+import java.awt.Color;
+import java.util.List;
+import java.util.Map;
+
+public class HMMERAlignmentColourScheme extends ResidueColourScheme
+{
+
+  AnnotatedCollectionI alignment;
+
+  HiddenMarkovModel hmm;
+
+  boolean peptideSpecific;
+
+  boolean nucleotideSpecific;
+
+  public HMMERAlignmentColourScheme(HiddenMarkovModel markov)
+  {
+    hmm = markov;
+  }
+
+  public HMMERAlignmentColourScheme()
+  {
+
+  }
+
+  @Override
+  public Color findColour(char symbol, int position, SequenceI seq,
+          String consensusResidue, float pid)
+  {
+    if (hmm == null)
+    {
+      return Color.white;
+    }
+    return findColour(symbol, position);
+  }
+
+  /**
+   * Returns the colour at a particular symbol at a column in the alignment.
+   * 
+   * @param symbol
+   * @param position
+   * @return Red for an insertion, white for a gap, orange for a negative
+   *         information content, white to blue for increasing information
+   *         content.
+   */
+  private Color findColour(char symbol, int position)
+  {
+
+    if (Comparison.isGap(symbol))
+    {
+      return Color.white;
+    }
+    if (Character.isLowerCase(symbol))
+    {
+      symbol = Character.toUpperCase(symbol);
+    }
+    Double prob;
+    prob = hmm.getMatchEmissionProbability(position, symbol);
+    double freq = 0;
+    String alpha = hmm.getAlphabetType();
+    if (!ResidueProperties.backgroundFrequencies.get(alpha)
+            .containsKey(symbol))
+    {
+      return Color.white;
+    }
+    else
+    {
+      freq = ResidueProperties.backgroundFrequencies.get(alpha).get(symbol);
+    }
+    if (prob == 0)
+    {
+      return new Color(230, 0, 0);
+    }
+    Double value = Math.log(prob / freq);
+    Color colour = null;
+    if (value > 0)
+    {
+
+      colour = ColorUtils.getGraduatedColour(value.floatValue(), 0,
+              Color.WHITE, 4.52f, Color.blue);
+    }
+    else if (value < 0)
+    {
+      return Color.ORANGE;
+
+    }
+    return colour;
+
+  }
+
+  @Override
+  public void alignmentChanged(AnnotatedCollectionI collection,
+          Map<SequenceI, SequenceCollectionI> hiddenReps)
+  {
+    List<SequenceI> seqs = collection.getSequences();
+    for (SequenceI seq : seqs)
+    {
+      if (seq.isHMMConsensusSequence())
+      {
+        hmm = seq.getHMM();
+        break;
+      }
+    }
+
+  }
+
+  @Override
+  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
+          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  {
+    HiddenMarkovModel markov = null;
+    List<SequenceI> seqs = sg.getSequences();
+    for (SequenceI seq : seqs)
+    {
+      if (seq.getHMM() != null)
+      {
+        markov = seq.getHMM();
+        break;
+      }
+    }
+    HMMERColourScheme colour = new HMMERColourScheme(markov);
+    return colour;
+
+  }
+
+  @Override
+  public boolean isApplicableTo(AnnotatedCollectionI ac)
+  {
+    return true;
+
+  }
+
+  @Override
+  public String getSchemeName()
+  {
+
+    return JalviewColourScheme.HMMERA.name();
+  }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
+
+}
+
index 61eb693..09e3293 100644 (file)
@@ -127,7 +127,7 @@ public class HMMERColourScheme extends ResidueColourScheme
            List<SequenceI> seqs = sg.getSequences();
            for (SequenceI seq : seqs)
            {
-             if (seq.getHMM() != null)
+      if (seq.isHMMConsensusSequence())
              {
                markov = seq.getHMM();
                break;
@@ -149,7 +149,7 @@ public class HMMERColourScheme extends ResidueColourScheme
   public String getSchemeName()
   {
 
-    return JalviewColourScheme.HMMER.name();
+    return JalviewColourScheme.HMMERU.name();
   }
 
   @Override
index e9778b4..3d6d88d 100644 (file)
@@ -43,7 +43,8 @@ public enum JalviewColourScheme
   PurinePyrimidine("Purine/Pyrimidine", PurinePyrimidineColourScheme.class),
   RNAHelices("RNA Helices", RNAHelicesColour.class),
   TCoffee("T-Coffee Scores", TCoffeeColourScheme.class),
-  HMMER("HMMER", HMMERColourScheme.class);
+  HMMERU("HMMER-Uniprot", HMMERColourScheme.class),
+  HMMERA("HMMER-Alignment", HMMERAlignmentColourScheme.class);
   // RNAInteraction("RNA Interaction type", RNAInteractionColourScheme.class)
 
   private String name;