JAL-3187 minor code tidying, todo removal
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 21 Aug 2019 16:01:52 +0000 (17:01 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 21 Aug 2019 16:01:52 +0000 (17:01 +0100)
src/jalview/datamodel/MappedFeatures.java

index 3f43355..4b558a5 100644 (file)
@@ -84,26 +84,21 @@ public class MappedFeatures
      * for a peptide-to-CDS mapping
      */
     int[] codonIntervals = mapping.getMap().locateInFrom(toPosition, toPosition);
-    if (codonIntervals != null)
+    int[] codonPositions = codonIntervals == null ? null
+            : MappingUtils.flattenRanges(codonIntervals);
+    if (codonPositions != null && codonPositions.length == 3)
     {
-      codonPos = MappingUtils.flattenRanges(codonIntervals);
-      if (codonPos.length == 3)
-      {
-        baseCodon = new char[3];
-        int cdsStart = fromSeq.getStart();
-        baseCodon[0] = fromSeq.getCharAt(codonPos[0] - cdsStart);
-        baseCodon[1] = fromSeq.getCharAt(codonPos[1] - cdsStart);
-        baseCodon[2] = fromSeq.getCharAt(codonPos[2] - cdsStart);
-      }
-      else
-      {
-        baseCodon = null;
-      }
+      codonPos = codonPositions;
+      baseCodon = new char[3];
+      int cdsStart = fromSeq.getStart();
+      baseCodon[0] = fromSeq.getCharAt(codonPos[0] - cdsStart);
+      baseCodon[1] = fromSeq.getCharAt(codonPos[1] - cdsStart);
+      baseCodon[2] = fromSeq.getCharAt(codonPos[2] - cdsStart);
     }
     else
     {
       codonPos = null;
-      baseCodon = null; // todo tidy!
+      baseCodon = null;
     }
   }
 
@@ -134,14 +129,16 @@ public class MappedFeatures
       if (colonPos >= 0)
       {
         String var = hgvsp.substring(colonPos + 1);
-        return var;
+        if (var.contains("p.")) // sanity check
+        {
+          return var;
+        }
       }
     }
 
     /*
      * otherwise, compute codon and peptide variant
      */
-    // todo avoid duplication of code in AlignmentUtils.buildDnaVariantsMap
     int cdsPos = sf.getBegin();
     if (cdsPos != sf.getEnd())
     {