JAL-845 don't translate hidden annotation (plus formatting)
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 12 Dec 2014 15:29:11 +0000 (15:29 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 12 Dec 2014 15:29:11 +0000 (15:29 +0000)
src/jalview/analysis/Dna.java

index 2e56e67..675a44a 100644 (file)
  */
 package jalview.analysis;
 
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Vector;
-
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
@@ -39,6 +35,10 @@ import jalview.schemes.ResidueProperties;
 import jalview.util.MapList;
 import jalview.util.ShiftList;
 
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Vector;
+
 public class Dna
 {
   /**
@@ -52,9 +52,13 @@ public class Dna
   {
     if (cdp2 == null
             || (cdp1[0] == cdp2[0] && cdp1[1] == cdp2[1] && cdp1[2] == cdp2[2]))
+    {
       return 0;
+    }
     if (cdp1[0] < cdp2[0] || cdp1[1] < cdp2[1] || cdp1[2] < cdp2[2])
+     {
       return -1; // one base in cdp1 precedes the corresponding base in the
+    }
     // other codon
     return 1; // one base in cdp1 appears after the corresponding base in the
     // other codon.
@@ -146,7 +150,9 @@ public class Dna
       }
     }
     if (codons.aaWidth == 0)
+    {
       return null;
+    }
     SequenceI[] newseqs = new SequenceI[pepseqs.size()];
     pepseqs.copyInto(newseqs);
     AlignmentI al = new Alignment(newseqs);
@@ -264,7 +270,9 @@ public class Dna
             // generate seqstring for this sequence based on mapping
 
             if (sqstr.length() > alwidth)
+            {
               alwidth = sqstr.length();
+            }
             cdnasqs.addElement(sqstr.toString());
             cdnasqi.addElement(dna);
             cdnaprod.addElement(intersect);
@@ -312,6 +320,13 @@ public class Dna
           continue;
         }
 
+        // skip hidden sequence annotations
+        final SequenceI seqRef = annotations[i].sequenceRef;
+        if (seqRef != null && !annotations[i].visible)
+        {
+          continue;
+        }
+
         aSize = codons.getaaWidth(); // aa alignment width.
         jalview.datamodel.Annotation[] anots = (annotations[i].annotations == null) ? null
                 : new jalview.datamodel.Annotation[aSize];
@@ -320,7 +335,7 @@ public class Dna
           for (a = 0; a < aSize; a++)
           {
             // process through codon map.
-            if (codons.codons[a] != null
+            if (a < codons.codons.length && codons.codons[a] != null
                     && codons.codons[a][0] == (codons.codons[a][2] - 2))
             {
               anots[a] = getCodonAnnotation(codons.codons[a],
@@ -343,10 +358,10 @@ public class Dna
         {
           aa.setScore(annotations[i].getScore());
         }
-        if (annotations[i].sequenceRef != null)
+        if (seqRef != null)
         {
           SequenceI aaSeq = codons
-                  .getAaForDnaSeq(annotations[i].sequenceRef);
+                  .getAaForDnaSeq(seqRef);
           if (aaSeq != null)
           {
             // aa.compactAnnotationArray(); // throw away alignment annotation
@@ -407,7 +422,7 @@ public class Dna
     }
     if (contrib > 1)
     {
-      annot.value /= (float) contrib;
+      annot.value /= contrib;
     }
     return annot;
   }
@@ -429,6 +444,7 @@ public class Dna
    *             {@link #translateCodingRegion(SequenceI,String,int[],AlignedCodonFrame,char,DBRefEntry,boolean)}
    *             instead
    */
+  @Deprecated
   public static SequenceI translateCodingRegion(SequenceI selection,
           String seqstring, int[] viscontigs, AlignedCodonFrame codons,
           char gapCharacter, DBRefEntry product)
@@ -694,7 +710,9 @@ public class Dna
           scontigs = t;
         }
         if (vc <= 0)
+        {
           scontigs = null;
+        }
       }
       if (scontigs != null)
       {
@@ -705,7 +723,9 @@ public class Dna
           scontigs[vc] = selection.findPosition(scontigs[vc]); // not from 1!
           scontigs[vc + 1] = selection.findPosition(scontigs[vc + 1]); // exclusive
           if (scontigs[vc + 1] == selection.getEnd())
+          {
             break;
+          }
         }
         // trim trailing empty intervals.
         if ((vc + 2) < scontigs.length)