Merge branch 'develop' into features/JAL-2446NCList
[jalview.git] / src / jalview / datamodel / AlignedCodonFrame.java
index 18aaecf..ec11fc1 100644 (file)
@@ -90,11 +90,12 @@ public class AlignedCodonFrame
         return that.mapping == null;
       }
       // TODO: can simplify by asserting fromSeq is a dataset sequence
-      return (this.fromSeq == that.fromSeq || (this.fromSeq != null
-              && that.fromSeq != null
-              && this.fromSeq.getDatasetSequence() != null && this.fromSeq
-              .getDatasetSequence() == that.fromSeq
-              .getDatasetSequence())) && this.mapping.equals(that.mapping);
+      return (this.fromSeq == that.fromSeq
+              || (this.fromSeq != null && that.fromSeq != null
+                      && this.fromSeq.getDatasetSequence() != null
+                      && this.fromSeq.getDatasetSequence() == that.fromSeq
+                              .getDatasetSequence()))
+              && this.mapping.equals(that.mapping);
     }
 
     public SequenceI getFromSeq()
@@ -128,14 +129,29 @@ public class AlignedCodonFrame
    */
   public void addMap(SequenceI dnaseq, SequenceI aaseq, MapList map)
   {
+    addMap(dnaseq, aaseq, map, null);
+  }
+
+  /**
+   * Adds a mapping between the dataset sequences for the associated dna and
+   * protein sequence objects
+   * 
+   * @param dnaseq
+   * @param aaseq
+   * @param map
+   * @param mapFromId
+   */
+  public void addMap(SequenceI dnaseq, SequenceI aaseq, MapList map,
+          String mapFromId)
+  {
     // JBPNote DEBUG! THIS !
     // dnaseq.transferAnnotation(aaseq, mp);
     // aaseq.transferAnnotation(dnaseq, new Mapping(map.getInverse()));
 
     SequenceI fromSeq = (dnaseq.getDatasetSequence() == null) ? dnaseq
             : dnaseq.getDatasetSequence();
-    SequenceI toSeq = (aaseq.getDatasetSequence() == null) ? aaseq : aaseq
-            .getDatasetSequence();
+    SequenceI toSeq = (aaseq.getDatasetSequence() == null) ? aaseq
+            : aaseq.getDatasetSequence();
 
     /*
      * if we already hold a mapping between these sequences, just add to it 
@@ -155,6 +171,7 @@ public class AlignedCodonFrame
      * otherwise, add a new sequence mapping
      */
     Mapping mp = new Mapping(toSeq, map);
+    mp.setMappedFromId(mapFromId);
     mappings.add(new SequenceToSequenceMapping(fromSeq, mp));
   }
 
@@ -285,7 +302,7 @@ public class AlignedCodonFrame
    *          where highlighted regions go
    */
   public void markMappedRegion(SequenceI seq, int index,
-          SearchResults results)
+          SearchResultsI results)
   {
     int[] codon;
     SequenceI ds = seq.getDatasetSequence();
@@ -418,8 +435,8 @@ public class AlignedCodonFrame
   {
     SequenceI targetDs = target.getDatasetSequence() == null ? target
             : target.getDatasetSequence();
-    SequenceI queryDs = query.getDatasetSequence() == null ? query : query
-            .getDatasetSequence();
+    SequenceI queryDs = query.getDatasetSequence() == null ? query
+            : query.getDatasetSequence();
     if (targetDs == null || queryDs == null /*|| dnaToProt == null*/)
     {
       return null;
@@ -472,7 +489,8 @@ public class AlignedCodonFrame
 
     for (SequenceToSequenceMapping ssm : mappings)
     {
-      if (ssm.mapping.to == protein)
+      if (ssm.mapping.to == protein
+              && ssm.mapping.getMap().getFromRatio() == 3)
       {
         ml = ssm.mapping.map;
         dnaSeq = ssm.fromSeq;
@@ -487,10 +505,11 @@ public class AlignedCodonFrame
          * Read off the mapped nucleotides (converting to position base 0)
          */
         codonPos = MappingUtils.flattenRanges(codonPos);
-        char[] dna = dnaSeq.getSequence();
         int start = dnaSeq.getStart();
-        result.add(new char[] { dna[codonPos[0] - start],
-            dna[codonPos[1] - start], dna[codonPos[2] - start] });
+        char c1 = dnaSeq.getCharAt(codonPos[0] - start);
+        char c2 = dnaSeq.getCharAt(codonPos[1] - start);
+        char c3 = dnaSeq.getCharAt(codonPos[2] - start);
+        result.add(new char[] { c1, c2, c3 });
       }
     }
     return result.isEmpty() ? null : result;
@@ -562,8 +581,9 @@ public class AlignedCodonFrame
    */
   protected int realiseWith(SequenceI seq, boolean doUpdate)
   {
-    SequenceI ds = seq.getDatasetSequence() != null ? seq
-            .getDatasetSequence() : seq;
+    SequenceI ds = seq.getDatasetSequence() != null
+            ? seq.getDatasetSequence()
+            : seq;
     int count = 0;
 
     /*
@@ -637,8 +657,8 @@ public class AlignedCodonFrame
     {
       int start = replacement.getStart();
       int end = replacement.getEnd();
-      boolean mappingOverlapsSequence = (mapStart >= start && mapStart <= end)
-              || (mapEnd >= start && mapEnd <= end);
+      boolean mappingOverlapsSequence = (mapStart >= start
+              && mapStart <= end) || (mapEnd >= start && mapEnd <= end);
       if (mappingOverlapsSequence)
       {
         return true;
@@ -702,8 +722,8 @@ public class AlignedCodonFrame
   }
 
   /**
-   * Returns the first mapping found that is between 'fromSeq' and 'toSeq', or null
-   * if none found
+   * Returns the first mapping found that is between 'fromSeq' and 'toSeq', or
+   * null if none found
    * 
    * @param fromSeq
    *          aligned or dataset sequence
@@ -715,8 +735,8 @@ public class AlignedCodonFrame
   {
     SequenceI dssFrom = fromSeq.getDatasetSequence() == null ? fromSeq
             : fromSeq.getDatasetSequence();
-    SequenceI dssTo = toSeq.getDatasetSequence() == null ? toSeq : toSeq
-            .getDatasetSequence();
+    SequenceI dssTo = toSeq.getDatasetSequence() == null ? toSeq
+            : toSeq.getDatasetSequence();
 
     for (SequenceToSequenceMapping mapping : mappings)
     {