From: TZVanaalten Date: Fri, 25 Aug 2017 16:10:28 +0000 (+0100) Subject: JAl-2629 add new HMMER colour scheme class X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2e706a2b4229f07cef65bc58afe5777f01f16cf7;p=jalview.git JAl-2629 add new HMMER colour scheme class --- 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;