JAL-2599 add ability to process RNA HMMer files
authorTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Thu, 20 Jul 2017 10:42:11 +0000 (11:42 +0100)
committerTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Thu, 20 Jul 2017 10:42:11 +0000 (11:42 +0100)
src/jalview/analysis/AAFrequency.java
src/jalview/gui/AlignFrame.java
src/jalview/io/HMMFile.java
src/jalview/schemes/HMMERColourScheme.java
src/jalview/schemes/ResidueProperties.java

index 8ff95a1..573e607 100755 (executable)
@@ -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)
           {
index cce4e67..44d96ca 100644 (file)
@@ -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);
index dc5c699..a7a0a0c 100644 (file)
@@ -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);
+  }
+
 
 
   /**
index f545fe6..09092a6 100644 (file)
@@ -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)
index 4a56fbc..8451e8a 100755 (executable)
@@ -51,8 +51,11 @@ public class ResidueProperties
   // amino acid background Frequencies
   public static final Map<Character, Float> aminoBackgroundFrequencies = new HashMap<>();
 
-  // nucleotide background Frequencies
-  public static final Map<Character, Float> nucleotideBackgroundFrequencies = new HashMap<>();
+  // dna background Frequencies
+  public static final Map<Character, Float> dnaBackgroundFrequencies = new HashMap<>();
+
+  // rna background Frequencies
+  public static final Map<Character, Float> 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);
 
   }