Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / analysis / Dna.java
index 4b81785..a2b0472 100644 (file)
  */
 package jalview.analysis;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
 import jalview.api.AlignViewportI;
 import jalview.datamodel.AlignedCodon;
 import jalview.datamodel.AlignedCodonFrame;
@@ -28,7 +34,6 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
 import jalview.datamodel.FeatureProperties;
 import jalview.datamodel.GraphLine;
 import jalview.datamodel.Mapping;
@@ -41,12 +46,6 @@ import jalview.util.DBRefUtils;
 import jalview.util.MapList;
 import jalview.util.ShiftList;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-
 public class Dna
 {
   private static final String STOP_ASTERIX = "*";
@@ -163,7 +162,8 @@ public class Dna
    * @param ac2
    * @return
    */
-  public static final int compareCodonPos(AlignedCodon ac1, AlignedCodon ac2)
+  public static final int compareCodonPos(AlignedCodon ac1,
+          AlignedCodon ac2)
   {
     return comparator.compare(ac1, ac2);
     // return jalview_2_8_2compare(ac1, ac2);
@@ -194,10 +194,11 @@ public class Dna
   }
 
   /**
+   * Translates cDNA using the specified code table
    * 
    * @return
    */
-  public AlignmentI translateCdna()
+  public AlignmentI translateCdna(GeneticCodeI codeTable)
   {
     AlignedCodonFrame acf = new AlignedCodonFrame();
 
@@ -209,7 +210,7 @@ public class Dna
     for (s = 0; s < sSize; s++)
     {
       SequenceI newseq = translateCodingRegion(selection.get(s),
-              seqstring[s], acf, pepseqs);
+              seqstring[s], acf, pepseqs, codeTable);
 
       if (newseq != null)
       {
@@ -269,7 +270,7 @@ public class Dna
             mappedrefs.add(ref); // add translated protein maps
           }
         }
-        dnarefs = mappedrefs;//.toArray(new DBRefEntry[mappedrefs.size()]);
+        dnarefs = mappedrefs;// .toArray(new DBRefEntry[mappedrefs.size()]);
         for (int d = 0, nd = dnarefs.size(); d < nd; d++)
         {
           Mapping mp = dnarefs.get(d).getMap();
@@ -430,11 +431,12 @@ public class Dna
    * @param acf
    *          Definition of global ORF alignment reference frame
    * @param proteinSeqs
+   * @param codeTable
    * @return sequence ready to be added to alignment.
    */
   protected SequenceI translateCodingRegion(SequenceI selection,
           String seqstring, AlignedCodonFrame acf,
-          List<SequenceI> proteinSeqs)
+          List<SequenceI> proteinSeqs, GeneticCodeI codeTable)
   {
     List<int[]> skip = new ArrayList<>();
     int[] skipint = null;
@@ -469,7 +471,7 @@ public class Dna
          */
         AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1],
                 cdp[2]);
-        String aa = ResidueProperties.codonTranslate(new String(codon));
+        String aa = codeTable.translate(new String(codon));
         rf = 0;
         final String gapString = String.valueOf(gapChar);
         if (aa == null)
@@ -797,29 +799,29 @@ public class Dna
   private static void transferCodedFeatures(SequenceI dna, SequenceI pep,
           MapList map)
   {
-       //  BH 2019.01.25 nop?
-//    List<DBRefEntry> dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(),
-//            DBRefSource.DNACODINGDBS);
-//    if (dnarefs != null)
-//    {
-//      // intersect with pep
-//      for (int d = 0, nd = dnarefs.size(); d < nd; d++)
-//      {
-//        Mapping mp = dnarefs.get(d).getMap();
-//        if (mp != null)
-//        {
-//        }
-//      }
-//    }
+    // BH 2019.01.25 nop?
+    // List<DBRefEntry> dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(),
+    // DBRefSource.DNACODINGDBS);
+    // if (dnarefs != null)
+    // {
+    // // intersect with pep
+    // for (int d = 0, nd = dnarefs.size(); d < nd; d++)
+    // {
+    // Mapping mp = dnarefs.get(d).getMap();
+    // if (mp != null)
+    // {
+    // }
+    // }
+    // }
     for (SequenceFeature sf : dna.getFeatures().getAllFeatures())
     {
-        if (FeatureProperties.isCodingFeature(null, sf.getType()))
+      if (FeatureProperties.isCodingFeature(null, sf.getType()))
+      {
+        // if (map.intersectsFrom(sf[f].begin, sf[f].end))
         {
-          // if (map.intersectsFrom(sf[f].begin, sf[f].end))
-          {
 
-          }
         }
+      }
     }
   }