From: TZVanaalten Date: Mon, 28 Aug 2017 10:25:44 +0000 (+0100) Subject: JAL-2629 HMMER alignment background colour scheme is functional X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=28d2a0b7dde7f6751d9e063fc2e11da065d284a4;p=jalview.git JAL-2629 HMMER alignment background colour scheme is functional --- diff --git a/src/jalview/datamodel/ResidueCount.java b/src/jalview/datamodel/ResidueCount.java index 74eb887..612969f 100644 --- a/src/jalview/datamodel/ResidueCount.java +++ b/src/jalview/datamodel/ResidueCount.java @@ -640,4 +640,17 @@ public class ResidueCount sb.append("]"); return sb.toString(); } + + public int getTotalCount() + { + int total = 0; + for (char symbol : this.getSymbolCounts().symbols) + { + if (!Comparison.isGap(symbol)) + { + total += getCount(symbol); + } + } + return total; + } } diff --git a/src/jalview/hmmer/HMMBuildThread.java b/src/jalview/hmmer/HMMBuildThread.java index b0e9d70..4e0fd08 100644 --- a/src/jalview/hmmer/HMMBuildThread.java +++ b/src/jalview/hmmer/HMMBuildThread.java @@ -130,7 +130,10 @@ public class HMMBuildThread implements Runnable } else { - alignment = viewport.getAlignment(); + if (viewport != null && alignment == null) + { + alignment = viewport.getAlignment(); + } } if (alignment != null) @@ -378,13 +381,16 @@ public class HMMBuildThread implements Runnable alignment.insertSequenceAt(0, seq); } - viewport.alignmentChanged(viewport.getAlignPanel()); - viewport.getAlignPanel().adjustAnnotationHeight(); - viewport.updateSequenceIdColours(); - - if (viewport.getAlignPanel().alignFrame.getSelectedHMM() == null) + if (viewport != null) { - viewport.getAlignPanel().alignFrame.setSelectedHMMSequence(seq); + viewport.alignmentChanged(viewport.getAlignPanel()); + viewport.getAlignPanel().adjustAnnotationHeight(); + viewport.updateSequenceIdColours(); + + if (viewport.getAlignPanel().alignFrame.getSelectedHMM() == null) + { + viewport.getAlignPanel().alignFrame.setSelectedHMMSequence(seq); + } } hmmTemp.delete(); stoTemp.delete(); diff --git a/src/jalview/schemes/HMMERAlignmentColourScheme.java b/src/jalview/schemes/HMMERAlignmentColourScheme.java index 47c065b..59c0317 100644 --- a/src/jalview/schemes/HMMERAlignmentColourScheme.java +++ b/src/jalview/schemes/HMMERAlignmentColourScheme.java @@ -2,19 +2,22 @@ package jalview.schemes; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.HiddenMarkovModel; +import jalview.datamodel.ResidueCount; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; import jalview.util.ColorUtils; import jalview.util.Comparison; import java.awt.Color; +import java.util.HashMap; import java.util.List; import java.util.Map; public class HMMERAlignmentColourScheme extends ResidueColourScheme { + Map backgroundFrequencies = new HashMap<>(); - AnnotatedCollectionI alignment; + Double maxLLR; HiddenMarkovModel hmm; @@ -65,17 +68,11 @@ public class HMMERAlignmentColourScheme extends ResidueColourScheme } Double prob; prob = hmm.getMatchEmissionProbability(position, symbol); - double freq = 0; - String alpha = hmm.getAlphabetType(); - if (!ResidueProperties.backgroundFrequencies.get(alpha) - .containsKey(symbol)) + Double freq = backgroundFrequencies.get(symbol); + if (freq == null) { return Color.white; } - else - { - freq = ResidueProperties.backgroundFrequencies.get(alpha).get(symbol); - } if (prob == 0) { return new Color(230, 0, 0); @@ -86,7 +83,7 @@ public class HMMERAlignmentColourScheme extends ResidueColourScheme { colour = ColorUtils.getGraduatedColour(value.floatValue(), 0, - Color.WHITE, 4.52f, Color.blue); + Color.WHITE, maxLLR.floatValue(), Color.blue); } else if (value < 0) { @@ -94,7 +91,6 @@ public class HMMERAlignmentColourScheme extends ResidueColourScheme } return colour; - } @Override @@ -111,6 +107,8 @@ public class HMMERAlignmentColourScheme extends ResidueColourScheme } } + count(collection); + } @Override @@ -127,7 +125,11 @@ public class HMMERAlignmentColourScheme extends ResidueColourScheme break; } } - HMMERColourScheme colour = new HMMERColourScheme(markov); + + count(sg); + + HMMERAlignmentColourScheme colour = new HMMERAlignmentColourScheme( + markov); return colour; } @@ -152,5 +154,29 @@ public class HMMERAlignmentColourScheme extends ResidueColourScheme return false; } + public void count(AnnotatedCollectionI sg) + { + ResidueCount counts = new ResidueCount(); + for (SequenceI seq : sg.getSequences()) + { + for (int i = 0; i < seq.getLength(); i++) + { + if (!Comparison.isGap(seq.getCharAt(i))) + { + counts.add(seq.getCharAt(i)); + } + } + } + + int total = counts.getTotalCount(); + + for (char symbol : counts.getSymbolCounts().symbols) + { + double count = Double.valueOf(counts.getCount(symbol)) + / Double.valueOf(total); + backgroundFrequencies.put(symbol, count); + } + maxLLR = Math.log(total); + } }