JAL-2629 add HMM Match Score colour scheme
authortva <tva@10.205.251.175>
Fri, 28 Jun 2019 12:30:32 +0000 (13:30 +0100)
committertva <tva@10.205.251.175>
Fri, 28 Jun 2019 12:30:32 +0000 (13:30 +0100)
src/jalview/datamodel/HiddenMarkovModel.java
src/jalview/hmmer/HMMBuild.java
src/jalview/schemes/JalviewColourScheme.java

index 975bacb..d50e66d 100644 (file)
@@ -74,6 +74,9 @@ public class HiddenMarkovModel
    */
   private Mapping mapToHmmConsensus;
 
+  // stores background frequencies of alignment from which this model came
+  private Map<Character, Float> backgroundFrequencies;
+
   /**
    * Constructor
    */
@@ -97,6 +100,7 @@ public class HiddenMarkovModel
     this.symbolIndexLookup = hmm.symbolIndexLookup;
     this.fileHeader = new String(hmm.fileHeader);
     this.hmmSeq = sq;
+    this.backgroundFrequencies = hmm.getBackgroundFrequencies();
     if (sq.getDatasetSequence() == hmm.mapToHmmConsensus.getTo())
     {
       // same dataset sequence e.g. after realigning search results
@@ -640,5 +644,28 @@ public class HiddenMarkovModel
   {
     this.hmmSeq = hmmSeq;
   }
+
+  public void setBackgroundFrequencies(Map<Character, Float> bkgdFreqs)
+  {
+    backgroundFrequencies = bkgdFreqs;
+  }
+
+  public void setBackgroundFrequencies(ResidueCount bkgdFreqs)
+  {
+    backgroundFrequencies = new HashMap<>();
+
+    int total = bkgdFreqs.getTotalResidueCount();
+
+    for (char c : bkgdFreqs.getSymbolCounts().symbols)
+    {
+      backgroundFrequencies.put(c, bkgdFreqs.getCount(c) * 1f / total);
+    }
+
+  }
+
+  public Map<Character, Float> getBackgroundFrequencies()
+  {
+    return backgroundFrequencies;
+  }
 }
 
index 0b6e3ee..88f28dd 100644 (file)
@@ -6,6 +6,7 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.ResidueCount;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
@@ -362,6 +363,8 @@ public class HMMBuild extends HmmerCommand
     HMMFile file = new HMMFile(
             new FileParse(hmmFile.getAbsolutePath(), DataSourceType.FILE));
     SequenceI hmmSeq = file.getHMM().getConsensusSequence();
+    ResidueCount counts = new ResidueCount(alignment.getSequences());
+    hmmSeq.getHMM().setBackgroundFrequencies(counts);
 
     if (hmmSeq == null)
     {
index 86efa8f..eb1edf1 100644 (file)
@@ -45,7 +45,8 @@ public enum JalviewColourScheme
   TCoffee("T-Coffee Scores", TCoffeeColourScheme.class),
   IdColour("Sequence ID", IdColourScheme.class),
   HMMERU("HMMER-Uniprot", HmmerGlobalBackground.class),
-  HMMERA("HMMER-Alignment", HmmerLocalBackground.class);
+  HMMERA("HMMER-Alignment", HmmerLocalBackground.class),
+  HMMMatchScore("HMM Match Score", HMMMatchScoreColourScheme.class);
   // RNAInteraction("RNA Interaction type", RNAInteractionColourScheme.class)
 
   private String name;