JAL-3748 pass a list to findAlignedSequence to return mapping that relates CDS and...
authorJim Procter <jprocter@issues.jalview.org>
Wed, 16 Sep 2020 16:39:22 +0000 (17:39 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 16 Sep 2020 16:42:16 +0000 (17:42 +0100)
src/jalview/analysis/AlignmentUtils.java
src/jalview/datamodel/AlignedCodonFrame.java

index 2b88cb0..cd142ca 100644 (file)
@@ -960,11 +960,12 @@ public class AlignmentUtils
             .findMappingsForSequence(cdsSeq, mappings);
     for (AlignedCodonFrame mapping : dnaMappings)
     {
-      SequenceI peptide = mapping.findAlignedSequence(cdsSeq, protein);
+      List<SequenceToSequenceMapping> foundMap=new ArrayList<>();
+      SequenceI peptide = mapping.findAlignedSequence(cdsSeq, protein,foundMap);
       if (peptide != null)
       {
         final int peptideLength = peptide.getLength();
-        Mapping map = mapping.getMappingBetween(cdsSeq, peptide);
+        Mapping map = foundMap.get(0).getMapping();
         if (map != null)
         {
           MapList mapList = map.getMap();
index fbc8a61..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.
      */
@@ -466,6 +480,10 @@ public class AlignedCodonFrame
         {
           if (ssm.covers(sourceAligned,true))
           {
+            if (map != null)
+            {
+              map.add(ssm);
+            }
             return sourceAligned;
           }
         }
@@ -484,6 +502,10 @@ public class AlignedCodonFrame
         {
           if (ssm.covers(sourceAligned,true))
           {
+            if (map != null)
+            {
+              map.add(ssm);
+            }
             return sourceAligned;
           }
         }