JAL-3748 pass a list to findAlignedSequence to return mapping that relates CDS and...
[jalview.git] / src / jalview / datamodel / AlignedCodonFrame.java
index 9fa11cc..d1b12d3 100644 (file)
@@ -455,6 +455,20 @@ public class AlignedCodonFrame
    */
   public SequenceI findAlignedSequence(SequenceI seq, AlignmentI al)
   {
+    return findAlignedSequence(seq, al, null);
+  }
+  /**
+   * Convenience method to return the first aligned sequence in the given
+   * alignment whose dataset has a mapping with the given (aligned or dataset)
+   * sequence, and optionally the mapping that relates them 
+   * 
+   * @param seq
+   * @param al
+   * @param map - list to add the mapping to
+   * @return sequence from al that maps to seq
+   */
+  public SequenceI findAlignedSequence(SequenceI seq, AlignmentI al,List<SequenceToSequenceMapping> map)
+  {
     /*
      * Search mapped protein ('to') sequences first.
      */
@@ -464,9 +478,12 @@ public class AlignedCodonFrame
       {
         for (SequenceI sourceAligned : al.getSequences())
         {
-          if (ssm.mapping.to == sourceAligned.getDatasetSequence()
-                  || ssm.mapping.to == sourceAligned)
+          if (ssm.covers(sourceAligned,true))
           {
+            if (map != null)
+            {
+              map.add(ssm);
+            }
             return sourceAligned;
           }
         }
@@ -483,8 +500,12 @@ public class AlignedCodonFrame
       {
         for (SequenceI sourceAligned : al.getSequences())
         {
-          if (ssm.fromSeq == sourceAligned.getDatasetSequence())
+          if (ssm.covers(sourceAligned,true))
           {
+            if (map != null)
+            {
+              map.add(ssm);
+            }
             return sourceAligned;
           }
         }