JAL-2898 show 'stop_gained' variants on peptide sequences
[jalview.git] / src / jalview / analysis / Dna.java
index 2106dc2..ef05a58 100644 (file)
@@ -133,7 +133,8 @@ public class Dna
    * @param ac2
    * @return
    */
-  private static int jalview_2_8_2compare(AlignedCodon ac1, AlignedCodon ac2)
+  private static int jalview_2_8_2compare(AlignedCodon ac1,
+          AlignedCodon ac2)
   {
     if (ac1 == null || ac2 == null || (ac1.equals(ac2)))
     {
@@ -160,7 +161,7 @@ public class Dna
 
     int s;
     int sSize = selection.size();
-    List<SequenceI> pepseqs = new ArrayList<SequenceI>();
+    List<SequenceI> pepseqs = new ArrayList<>();
     for (s = 0; s < sSize; s++)
     {
       SequenceI newseq = translateCodingRegion(selection.get(s),
@@ -212,7 +213,7 @@ public class Dna
       if (dnarefs != null)
       {
         // intersect with pep
-        List<DBRefEntry> mappedrefs = new ArrayList<DBRefEntry>();
+        List<DBRefEntry> mappedrefs = new ArrayList<>();
         DBRefEntry[] refs = dna.getDBRefs();
         for (int d = 0; d < refs.length; d++)
         {
@@ -390,7 +391,7 @@ public class Dna
           String seqstring, AlignedCodonFrame acf,
           List<SequenceI> proteinSeqs)
   {
-    List<int[]> skip = new ArrayList<int[]>();
+    List<int[]> skip = new ArrayList<>();
     int skipint[] = null;
     ShiftList vismapping = new ShiftList(); // map from viscontigs to seqstring
     // intervals
@@ -434,7 +435,8 @@ public class Dna
         /*
          * Filled up a reading frame...
          */
-        AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1], cdp[2]);
+        AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1],
+                cdp[2]);
         String aa = ResidueProperties.codonTranslate(new String(codon));
         rf = 0;
         final String gapString = String.valueOf(gapChar);
@@ -443,10 +445,11 @@ public class Dna
           aa = gapString;
           if (skipint == null)
           {
-            skipint = new int[] { alignedCodon.pos1, alignedCodon.pos3 /*
-                                                                        * cdp[0],
-                                                                        * cdp[2]
-                                                                        */};
+            skipint = new int[] { alignedCodon.pos1,
+                alignedCodon.pos3 /*
+                                   * cdp[0],
+                                   * cdp[2]
+                                   */ };
           }
           skipint[1] = alignedCodon.pos3; // cdp[2];
         }
@@ -501,8 +504,8 @@ public class Dna
                       }
                       if (vc + 2 < t.length)
                       {
-                        System.arraycopy(scontigs, vc + 2, t, vc, t.length
-                                - vc + 2);
+                        System.arraycopy(scontigs, vc + 2, t, vc,
+                                t.length - vc + 2);
                       }
                       scontigs = t;
                     }
@@ -541,7 +544,7 @@ public class Dna
             skip.add(skipint);
             skipint = null;
           }
-          if (aa.equals("STOP"))
+          if (aa.equals(ResidueProperties.STOP))
           {
             aa = STOP_ASTERIX;
           }
@@ -595,9 +598,9 @@ public class Dna
         }
         else if (!alignedCodons[aspos].equals(alignedCodon))
         {
-          throw new IllegalStateException("Tried to coalign "
-                  + alignedCodons[aspos].toString() + " with "
-                  + alignedCodon.toString());
+          throw new IllegalStateException(
+                  "Tried to coalign " + alignedCodons[aspos].toString()
+                          + " with " + alignedCodon.toString());
         }
         if (aspos >= aaWidth)
         {
@@ -797,7 +800,7 @@ public class Dna
   public AlignmentI reverseCdna(boolean complement)
   {
     int sSize = selection.size();
-    List<SequenceI> reversed = new ArrayList<SequenceI>();
+    List<SequenceI> reversed = new ArrayList<>();
     for (int s = 0; s < sSize; s++)
     {
       SequenceI newseq = reverseSequence(selection.get(s).getName(),
@@ -848,6 +851,23 @@ public class Dna
   }
 
   /**
+   * Answers the reverse complement of the input string
+   * 
+   * @see #getComplement(char)
+   * @param s
+   * @return
+   */
+  public static String reverseComplement(String s)
+  {
+    StringBuilder sb = new StringBuilder(s.length());
+    for (int i = s.length() - 1; i >= 0; i--)
+    {
+      sb.append(Dna.getComplement(s.charAt(i)));
+    }
+    return sb.toString();
+  }
+
+  /**
    * Returns dna complement (preserving case) for aAcCgGtTuU. Ambiguity codes
    * are treated as on http://reverse-complement.com/. Anything else is left
    * unchanged.