From 2e706a2b4229f07cef65bc58afe5777f01f16cf7 Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Fri, 25 Aug 2017 17:10:28 +0100 Subject: [PATCH] JAl-2629 add new HMMER colour scheme class --- .../schemes/HMMERAlignmentColourScheme.java | 156 ++++++++++++++++++++ src/jalview/schemes/HMMERColourScheme.java | 4 +- src/jalview/schemes/JalviewColourScheme.java | 3 +- 3 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 src/jalview/schemes/HMMERAlignmentColourScheme.java diff --git a/src/jalview/schemes/HMMERAlignmentColourScheme.java b/src/jalview/schemes/HMMERAlignmentColourScheme.java new file mode 100644 index 0000000..47c065b --- /dev/null +++ b/src/jalview/schemes/HMMERAlignmentColourScheme.java @@ -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 hiddenReps) + { + List seqs = collection.getSequences(); + for (SequenceI seq : seqs) + { + if (seq.isHMMConsensusSequence()) + { + hmm = seq.getHMM(); + break; + } + } + + } + + @Override + public ColourSchemeI getInstance(AnnotatedCollectionI sg, + Map hiddenRepSequences) + { + HiddenMarkovModel markov = null; + List 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; + } + +} + diff --git a/src/jalview/schemes/HMMERColourScheme.java b/src/jalview/schemes/HMMERColourScheme.java index 61eb693..09e3293 100644 --- a/src/jalview/schemes/HMMERColourScheme.java +++ b/src/jalview/schemes/HMMERColourScheme.java @@ -127,7 +127,7 @@ public class HMMERColourScheme extends ResidueColourScheme List 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 diff --git a/src/jalview/schemes/JalviewColourScheme.java b/src/jalview/schemes/JalviewColourScheme.java index e9778b4..3d6d88d 100644 --- a/src/jalview/schemes/JalviewColourScheme.java +++ b/src/jalview/schemes/JalviewColourScheme.java @@ -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; -- 1.7.10.2