Merge branch 'develop' into features/mchmmer
[jalview.git] / src / jalview / schemes / ResidueProperties.java
index 4a56fbc..9b0489e 100755 (executable)
@@ -32,6 +32,13 @@ import java.util.Vector;
 
 public class ResidueProperties
 {
+  // alphabet names used in Hidden Markov Model files
+  public static final String ALPHABET_RNA = "RNA";
+
+  public static final String ALPHABET_DNA = "DNA";
+
+  public static final String ALPHABET_AMINO = "amino";
+
   // Stores residue codes/names and colours and other things
   public static final int[] aaIndex; // aaHash version 2.1.1 and below
 
@@ -48,11 +55,8 @@ public class ResidueProperties
   // lookup from modified amino acid (e.g. MSE) to canonical form (e.g. MET)
   public static final Map<String, String> modifications = new HashMap<>();
 
-  // 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<>();
+  // residue background frequencies across different alphabets
+  public static final Map<String, Map<Character, Float>> backgroundFrequencies = new HashMap<>();
 
   static
   {
@@ -369,8 +373,11 @@ public class ResidueProperties
   };
 
   // Added for PurinePyrimidineColourScheme
-  public static final Color[] purinepyrimidine = {
-      new Color(255, 131, 250), // A, G, R purines purplish/orchid
+  public static final Color[] purinepyrimidine = { new Color(255, 131, 250), // A,
+                                                                             // G,
+                                                                             // R
+                                                                             // purines
+                                                                             // purplish/orchid
       new Color(64, 224, 208), // C,U, T, Y pyrimidines turquoise
       Color.white, // all other nucleotides
       Color.white // Gap
@@ -385,7 +392,7 @@ public class ResidueProperties
       Color.green, // Q
       Color.red, // E
       Color.magenta, // G
-      midBlue,// Color.red, // H
+      midBlue, // Color.red, // H
       Color.pink, // I
       Color.pink, // L
       midBlue, // K
@@ -432,9 +439,9 @@ public class ResidueProperties
       0.0 // X
   };
 
-  public static final double[] helix = { 1.42, 0.98, 0.67, 1.01, 0.70,
-      1.11, 1.51, 0.57, 1.00, 1.08, 1.21, 1.16, 1.45, 1.13, 0.57, 0.77,
-      0.83, 1.08, 0.69, 1.06, 0.84, 1.31, 1.00, 0.0 };
+  public static final double[] helix = { 1.42, 0.98, 0.67, 1.01, 0.70, 1.11,
+      1.51, 0.57, 1.00, 1.08, 1.21, 1.16, 1.45, 1.13, 0.57, 0.77, 0.83,
+      1.08, 0.69, 1.06, 0.84, 1.31, 1.00, 0.0 };
 
   public static final double helixmin = 0.57;
 
@@ -456,9 +463,9 @@ public class ResidueProperties
 
   public static final double turnmax = 1.56;
 
-  public static final double[] buried = { 1.7, 0.1, 0.4, 0.4, 4.6, 0.3,
-      0.3, 1.8, 0.8, 3.1, 2.4, 0.05, 1.9, 2.2, 0.6, 0.8, 0.7, 1.6, 0.5,
-      2.9, 0.4, 0.3, 1.358, 0.00 };
+  public static final double[] buried = { 1.7, 0.1, 0.4, 0.4, 4.6, 0.3, 0.3,
+      1.8, 0.8, 3.1, 2.4, 0.05, 1.9, 2.2, 0.6, 0.8, 0.7, 1.6, 0.5, 2.9, 0.4,
+      0.3, 1.358, 0.00 };
 
   public static final double buriedmin = 0.05;
 
@@ -499,7 +506,9 @@ public class ResidueProperties
    * Color.white, // R Color.white, // Y Color.white, // N Color.white, // Gap
    */
 
-  public static List<String> STOP = Arrays.asList("TGA", "TAA", "TAG");
+  public static String STOP = "STOP";
+
+  public static List<String> STOP_CODONS = Arrays.asList("TGA", "TAA", "TAG");
 
   public static String START = "ATG";
 
@@ -649,16 +658,16 @@ public class ResidueProperties
         }
         else
         {
-          System.err
-                  .println("Inconsistency in the IUBMB ambiguity code nomenclature table: collision for "
+          System.err.println(
+                  "Inconsistency in the IUBMB ambiguity code nomenclature table: collision for "
                           + acode.getKey() + " in residue " + r);
         }
       }
     }
     // and programmatically add in the ambiguity codes that yield the same amino
     // acid
-    String[] unambcodons = codonHash2.keySet().toArray(
-            new String[codonHash2.size()]);
+    String[] unambcodons = codonHash2.keySet()
+            .toArray(new String[codonHash2.size()]);
     for (String codon : unambcodons)
     {
       String residue = codonHash2.get(codon);
@@ -677,7 +686,8 @@ public class ResidueProperties
         }
       }
       // enumerate all combinations and test for veracity of translation
-      int tpos[] = new int[codon.length()], cpos[] = new int[codon.length()];
+      int tpos[] = new int[codon.length()],
+              cpos[] = new int[codon.length()];
       for (int i = 0; i < tpos.length; i++)
       {
         tpos[i] = -1;
@@ -930,7 +940,7 @@ public class ResidueProperties
     charged.put("Q", ZERO);
     charged.put("D", ONE);
     charged.put("N", ZERO); // Asparagine is polar but not
-                                          // charged.
+                            // charged.
     // Alternative would be charged and
     // negative (in basic form)?
     charged.put("S", ZERO);
@@ -1059,7 +1069,9 @@ public class ResidueProperties
   }
   static
   {
-    int[][] propMatrixF = new int[maxProteinIndex][maxProteinIndex], propMatrixPos = new int[maxProteinIndex][maxProteinIndex], propMatrixEpos = new int[maxProteinIndex][maxProteinIndex];
+    int[][] propMatrixF = new int[maxProteinIndex][maxProteinIndex],
+            propMatrixPos = new int[maxProteinIndex][maxProteinIndex],
+            propMatrixEpos = new int[maxProteinIndex][maxProteinIndex];
     for (int i = 0; i < maxProteinIndex; i++)
     {
       int maxF = 0, maxP = 0, maxEP = 0;
@@ -1149,7 +1161,7 @@ public class ResidueProperties
     String cdn = codonHash2.get(lccodon.toUpperCase());
     if ("*".equals(cdn))
     {
-      return "STOP";
+      return STOP;
     }
     return cdn;
   }
@@ -2517,35 +2529,53 @@ public class ResidueProperties
 
   static
   {
-    aminoBackgroundFrequencies.put('A', 0.0826f);
-    aminoBackgroundFrequencies.put('Q', 0.0393f);
-    aminoBackgroundFrequencies.put('L', 0.0965f);
-    aminoBackgroundFrequencies.put('S', 0.0661f);
-    aminoBackgroundFrequencies.put('R', 0.0553f);
-    aminoBackgroundFrequencies.put('E', 0.0674f);
-    aminoBackgroundFrequencies.put('K', 0.0582f);
-    aminoBackgroundFrequencies.put('T', 0.0535f);
-    aminoBackgroundFrequencies.put('N', 0.0406f);
-    aminoBackgroundFrequencies.put('G', 0.0708f);
-    aminoBackgroundFrequencies.put('M', 0.0241f);
-    aminoBackgroundFrequencies.put('W', 0.0109f);
-    aminoBackgroundFrequencies.put('D', 0.0546f);
-    aminoBackgroundFrequencies.put('H', 0.0227f);
-    aminoBackgroundFrequencies.put('F', 0.0386f);
-    aminoBackgroundFrequencies.put('Y', 0.0292f);
-    aminoBackgroundFrequencies.put('C', 0.0137f);
-    aminoBackgroundFrequencies.put('I', 0.0593f);
-    aminoBackgroundFrequencies.put('P', 0.0472f);
-    aminoBackgroundFrequencies.put('V', 0.0686f);
+    Map<Character, Float> amino = new HashMap<>();
+    amino.put('A', 0.0826f);
+    amino.put('Q', 0.0393f);
+    amino.put('L', 0.0965f);
+    amino.put('S', 0.0661f);
+    amino.put('R', 0.0553f);
+    amino.put('E', 0.0674f);
+    amino.put('K', 0.0582f);
+    amino.put('T', 0.0535f);
+    amino.put('N', 0.0406f);
+    amino.put('G', 0.0708f);
+    amino.put('M', 0.0241f);
+    amino.put('W', 0.0109f);
+    amino.put('D', 0.0546f);
+    amino.put('H', 0.0227f);
+    amino.put('F', 0.0386f);
+    amino.put('Y', 0.0292f);
+    amino.put('C', 0.0137f);
+    amino.put('I', 0.0593f);
+    amino.put('P', 0.0472f);
+    amino.put('V', 0.0686f);
+    backgroundFrequencies.put(ALPHABET_AMINO, amino);
+    // todo: these don't match https://www.ebi.ac.uk/uniprot/TrEMBLstats - what
+    // are they?
+  }
+
+  // TODO get correct frequencies
+
+  static
+  {
+    Map<Character, Float> dna = new HashMap<>();
+    dna.put('A', 0.25f);
+    dna.put('C', 0.25f);
+    dna.put('T', 0.25f);
+    dna.put('G', 0.25f);
+    backgroundFrequencies.put(ALPHABET_DNA, dna);
 
   }
 
   static
   {
-    nucleotideBackgroundFrequencies.put('A', 0.25f);
-    nucleotideBackgroundFrequencies.put('C', 0.25f);
-    nucleotideBackgroundFrequencies.put('T', 0.25f);
-    nucleotideBackgroundFrequencies.put('G', 0.25f);
+    Map<Character, Float> rna = new HashMap<>();
+    rna.put('A', 0.25f);
+    rna.put('C', 0.25f);
+    rna.put('T', 0.25f);
+    rna.put('G', 0.25f);
+    backgroundFrequencies.put(ALPHABET_RNA, rna);
 
   }
 
@@ -2665,8 +2695,8 @@ public class ResidueProperties
     {
       return '0';
     }
-    Integer index = ResidueProperties.aa3Hash.get(threeLetterCode
-            .toUpperCase());
+    Integer index = ResidueProperties.aa3Hash
+            .get(threeLetterCode.toUpperCase());
     return index == null ? '0' : aa[index].charAt(0);
   }
 }