JAL-2023 fix for CDS shared dataset, robust load of split frame project
[jalview.git] / src / jalview / analysis / AlignmentUtils.java
index f2262fb..332c649 100644 (file)
@@ -1302,7 +1302,9 @@ public class AlignmentUtils
 
   /**
    * Constructs an alignment consisting of the mapped exon regions in the given
-   * nucleotide sequences, and updates mappings to match.
+   * nucleotide sequences, and updates mappings to match. The new alignment's
+   * sequences are added to the parent alignment's dataset, and both alignments
+   * share the same dataset.
    * 
    * @param dna
    *          aligned dna sequences
@@ -1312,7 +1314,7 @@ public class AlignmentUtils
    *         sequences (or null if no exons are found)
    */
   public static AlignmentI makeExonAlignment(SequenceI[] dna,
-          Set<AlignedCodonFrame> mappings)
+          Set<AlignedCodonFrame> mappings, AlignmentI al)
   {
     Set<AlignedCodonFrame> newMappings = new LinkedHashSet<AlignedCodonFrame>();
     List<SequenceI> exonSequences = new ArrayList<SequenceI>();
@@ -1334,9 +1336,21 @@ public class AlignmentUtils
         }
       }
     }
-    AlignmentI al = new Alignment(
+    AlignmentI cds = new Alignment(
             exonSequences.toArray(new SequenceI[exonSequences.size()]));
-    al.setDataset(null);
+
+    /*
+     * add new sequences to the shared dataset, set it on the new alignment
+     */
+    List<SequenceI> dsseqs = al.getDataset().getSequences();
+    for (SequenceI seq : cds.getSequences())
+    {
+      if (!dsseqs.contains(seq.getDatasetSequence()))
+      {
+        dsseqs.add(seq.getDatasetSequence());
+      }
+    }
+    cds.setDataset(al.getDataset());
 
     /*
      * Replace the old mappings with the new ones
@@ -1344,7 +1358,7 @@ public class AlignmentUtils
     mappings.clear();
     mappings.addAll(newMappings);
 
-    return al;
+    return cds;
   }
 
   /**