From ac8746eeccd41605a304b89cf43f7780526f10f8 Mon Sep 17 00:00:00 2001 From: tva Date: Fri, 28 Jun 2019 13:30:32 +0100 Subject: [PATCH] JAL-2629 add HMM Match Score colour scheme --- src/jalview/datamodel/HiddenMarkovModel.java | 27 ++++++++++++++++++++++++++ src/jalview/hmmer/HMMBuild.java | 3 +++ src/jalview/schemes/JalviewColourScheme.java | 3 ++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/jalview/datamodel/HiddenMarkovModel.java b/src/jalview/datamodel/HiddenMarkovModel.java index 975bacb..d50e66d 100644 --- a/src/jalview/datamodel/HiddenMarkovModel.java +++ b/src/jalview/datamodel/HiddenMarkovModel.java @@ -74,6 +74,9 @@ public class HiddenMarkovModel */ private Mapping mapToHmmConsensus; + // stores background frequencies of alignment from which this model came + private Map 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 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 getBackgroundFrequencies() + { + return backgroundFrequencies; + } } diff --git a/src/jalview/hmmer/HMMBuild.java b/src/jalview/hmmer/HMMBuild.java index 0b6e3ee..88f28dd 100644 --- a/src/jalview/hmmer/HMMBuild.java +++ b/src/jalview/hmmer/HMMBuild.java @@ -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) { diff --git a/src/jalview/schemes/JalviewColourScheme.java b/src/jalview/schemes/JalviewColourScheme.java index 86efa8f..eb1edf1 100644 --- a/src/jalview/schemes/JalviewColourScheme.java +++ b/src/jalview/schemes/JalviewColourScheme.java @@ -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; -- 1.7.10.2