JAL-1636 translate stop codon as '*', mouseover * as STOP
[jalview.git] / src / jalview / schemes / ResidueProperties.java
index 0f34824..ce83875 100755 (executable)
@@ -50,6 +50,9 @@ public class ResidueProperties
 
   public static final Map<String, String> nucleotideName = new HashMap<String, String>();
 
+  // lookup from modified amino acid (e.g. MSE) to canonical form (e.g. MET)
+  public static final Map<String, String> modifications = new HashMap<String, String>();
+
   static
   {
     aaIndex = new int[255];
@@ -1506,7 +1509,7 @@ public class ResidueProperties
       return _codonTranslate(lccodon);
     }
     String cdn = codonHash2.get(lccodon.toUpperCase());
-    if (cdn != null && cdn.equals("*"))
+    if ("*".equals(cdn))
     {
       return "STOP";
     }
@@ -1703,6 +1706,26 @@ public class ResidueProperties
     }
   }
 
+  static
+  {
+    modifications.put("MSE", "MET"); // Selenomethionine
+    // the rest tbc; from
+    // http://sourceforge.net/p/jmol/mailman/message/12833570/
+    // modifications.put("CSE", "CYS"); // Selenocysteine
+    // modifications.put("PTR", "TYR"); // Phosphotyrosine
+    // modifications.put("SEP", "SER"); // Phosphoserine
+    // modifications.put("HYP", "PRO"); // 4-hydroxyproline
+    // modifications.put("5HP", "GLU"); // Pyroglutamic acid; 5-hydroxyproline
+    // modifications.put("PCA", "GLU"); // Pyroglutamic acid
+    // modifications.put("LYZ", "LYS"); // 5-hydroxylysine
+  }
+
+  public static String getCanonicalAminoAcid(String aa)
+  {
+    String canonical = modifications.get(aa);
+    return canonical == null ? aa : canonical;
+  }
+
   /**
    * translate to RNA secondary structure representation
    * 
@@ -1787,4 +1810,69 @@ public class ResidueProperties
   }
   // to here
 
+  /**
+   * Returns a list of residue characters for the specified inputs
+   * 
+   * @param nucleotide
+   * @param includeAmbiguous
+   * @return
+   */
+  public static List<String> getResidues(boolean nucleotide,
+          boolean includeAmbiguous)
+  {
+    List<String> result = new ArrayList<String>();
+    if (nucleotide)
+    {
+      for (String nuc : nucleotideName.keySet())
+      {
+        int val = nucleotideIndex[nuc.charAt(0)];
+        if ((!includeAmbiguous && val > 4) || (val >= maxNucleotideIndex))
+        {
+          continue;
+        }
+        nuc = nuc.toUpperCase();
+        if (!result.contains(nuc))
+        {
+          result.add(nuc);
+        }
+      }
+    } else {
+      /*
+       * Peptide
+       */
+      for (String res : aa3Hash.keySet())
+      {
+        int index = aa3Hash.get(res).intValue();
+        if ((!includeAmbiguous && index >= 20) || index >= maxProteinIndex)
+        {
+          continue;
+        }
+        res = res.toUpperCase();
+        if (!result.contains(res))
+        {
+          result.add(res);
+        }
+      }
+    }
+
+    return result;
+  }
+
+  /**
+   * Returns the single letter code for a three letter code, or '0' if not known
+   * 
+   * @param threeLetterCode
+   *          not case sensitive
+   * @return
+   */
+  public static char getSingleCharacterCode(String threeLetterCode)
+  {
+    if (threeLetterCode == null)
+    {
+      return '0';
+    }
+    Integer index = ResidueProperties.aa3Hash.get(threeLetterCode
+            .toUpperCase());
+    return index == null ? '0' : aa[index].charAt(0);
+  }
 }