From: TZVanaalten Date: Thu, 20 Jul 2017 10:42:11 +0000 (+0100) Subject: JAL-2599 add ability to process RNA HMMer files X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d47d1eb4b1e5e7a58a220b174bf03b814ecec295;p=jalview.git JAL-2599 add ability to process RNA HMMer files --- diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 8ff95a1..573e607 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -61,6 +61,8 @@ public class AAFrequency private static final String DNA = "DNA"; + private static final String RNA = "RNA"; + /* * Quick look-up of String value of char 'A' to 'Z' */ @@ -773,7 +775,15 @@ public class AAFrequency } else if (DNA.equals(alph) && removeBelowBackground) { - freq = ResidueProperties.nucleotideBackgroundFrequencies + freq = ResidueProperties.dnaBackgroundFrequencies.get(symbol); + if (value < freq) + { + value = 0d; + } + } + else if (RNA.equals(alph) && removeBelowBackground) + { + freq = ResidueProperties.rnaBackgroundFrequencies .get(symbol); if (value < freq) { diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index cce4e67..44d96ca 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4702,6 +4702,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Integer alpha = 0; final int AMINO = 0; final int DNA = 1; + final int RNA = 2; if ("amino".equals(hmm.getAlphabetType())) { alpha = AMINO; @@ -4710,6 +4711,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { alpha = DNA; } + else if ("RNA".equals(hmm.getAlphabetType())) + { + alpha = RNA; + } int size = 0; @@ -4723,16 +4728,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .getCharAt(hmm.getNodeAlignmentColumn(l)); character = Character.toUpperCase(character); - boolean containedN; + boolean containedD; + boolean containedR; boolean containedA; - containedN = ResidueProperties.nucleotideBackgroundFrequencies + containedD = ResidueProperties.dnaBackgroundFrequencies .containsKey(character); containedA = ResidueProperties.aminoBackgroundFrequencies .containsKey(character); + containedR = ResidueProperties.rnaBackgroundFrequencies + .containsKey(character); if (!Comparison.isGap(character) - && ((alpha == DNA && containedN) + && ((alpha == DNA && containedD) || (alpha == AMINO && containedA))) { size++; @@ -4752,11 +4760,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, character = Character.toUpperCase(character); boolean containedN; boolean containedA; + boolean containedR; - containedN = ResidueProperties.nucleotideBackgroundFrequencies + containedN = ResidueProperties.dnaBackgroundFrequencies .containsKey(character); containedA = ResidueProperties.aminoBackgroundFrequencies .containsKey(character); + containedR = ResidueProperties.rnaBackgroundFrequencies + .containsKey(character); if (!Comparison.isGap(character) && ((alpha == DNA && containedN) @@ -4777,7 +4788,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (alpha == DNA) { - freq = ResidueProperties.nucleotideBackgroundFrequencies + freq = ResidueProperties.dnaBackgroundFrequencies + .get(character); + } + if (alpha == RNA) + { + freq = ResidueProperties.rnaBackgroundFrequencies .get(character); } Double doubleValue = Math.log(prob / freq); diff --git a/src/jalview/io/HMMFile.java b/src/jalview/io/HMMFile.java index dc5c699..a7a0a0c 100644 --- a/src/jalview/io/HMMFile.java +++ b/src/jalview/io/HMMFile.java @@ -110,6 +110,18 @@ public class HMMFile extends AlignFile parseModel(dataIn); } + /** + * Reads the data from HMM file into the HMM field on this object. + * + * @throws IOException + */ + + public void parse(BufferedReader br) throws IOException + { + parseFileProperties(br); + parseModel(br); + } + /** diff --git a/src/jalview/schemes/HMMERColourScheme.java b/src/jalview/schemes/HMMERColourScheme.java index f545fe6..09092a6 100644 --- a/src/jalview/schemes/HMMERColourScheme.java +++ b/src/jalview/schemes/HMMERColourScheme.java @@ -51,11 +51,35 @@ public class HMMERColourScheme extends ResidueColourScheme } Double prob; prob = hmm.getMatchEmissionProbability(position, symbol); + double freq = 0; + if ("amino".equals(hmm.getAlphabetType())) + { + if (!ResidueProperties.aminoBackgroundFrequencies.containsKey(symbol)) + { + return Color.white; + } + freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol); + } + else if ("DNA".equals(hmm.getAlphabetType())) + { + if (!ResidueProperties.dnaBackgroundFrequencies.containsKey(symbol)) + { + return Color.white; + } + freq = ResidueProperties.dnaBackgroundFrequencies.get(symbol); + } + else if ("RNA".equals(hmm.getAlphabetType())) + { + if (!ResidueProperties.rnaBackgroundFrequencies.containsKey(symbol)) + { + return Color.white; + } + freq = ResidueProperties.rnaBackgroundFrequencies.get(symbol); + } if (prob == 0) { return Color.red; } - double freq = ResidueProperties.aminoBackgroundFrequencies.get(symbol); Double value = Math.log(prob / freq); Color colour = null; if (value > 0) diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index 4a56fbc..8451e8a 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -51,8 +51,11 @@ public class ResidueProperties // amino acid background Frequencies public static final Map aminoBackgroundFrequencies = new HashMap<>(); - // nucleotide background Frequencies - public static final Map nucleotideBackgroundFrequencies = new HashMap<>(); + // dna background Frequencies + public static final Map dnaBackgroundFrequencies = new HashMap<>(); + + // rna background Frequencies + public static final Map rnaBackgroundFrequencies = new HashMap<>(); static { @@ -2540,12 +2543,23 @@ public class ResidueProperties } + // TODO get correct frequencies + + static + { + dnaBackgroundFrequencies.put('A', 0.25f); + dnaBackgroundFrequencies.put('C', 0.25f); + dnaBackgroundFrequencies.put('T', 0.25f); + dnaBackgroundFrequencies.put('G', 0.25f); + + } + static { - nucleotideBackgroundFrequencies.put('A', 0.25f); - nucleotideBackgroundFrequencies.put('C', 0.25f); - nucleotideBackgroundFrequencies.put('T', 0.25f); - nucleotideBackgroundFrequencies.put('G', 0.25f); + rnaBackgroundFrequencies.put('A', 0.25f); + rnaBackgroundFrequencies.put('C', 0.25f); + rnaBackgroundFrequencies.put('T', 0.25f); + rnaBackgroundFrequencies.put('G', 0.25f); }