From: gmungoc Date: Tue, 21 Apr 2015 12:54:13 +0000 (+0100) Subject: JAL-1693 mappings added back to the original alignment X-Git-Tag: Jalview_2_9~61 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5088f3a5830a92aca7db379a3b1d43a891611061;p=jalview.git JAL-1693 mappings added back to the original alignment --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 7dec4ec..a4aeac7 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -27,6 +27,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -1278,7 +1279,7 @@ public class AlignmentUtils public static AlignmentI makeExonAlignment(SequenceI[] dna, Set mappings) { - Set newMappings = new HashSet(); + Set newMappings = new LinkedHashSet(); List exonSequences = new ArrayList(); for (SequenceI dnaSeq : dna) @@ -1346,8 +1347,8 @@ public class AlignmentUtils /* * Get the codon regions as { [2, 5], [7, 12], [14, 14] etc } */ - List exonRanges = seqMapping.getMap().getFromRanges(); - for (int[] range : exonRanges) + final List dnaExonRanges = seqMapping.getMap().getFromRanges(); + for (int[] range : dnaExonRanges) { for (int pos = range[0]; pos <= range[1]; pos++) { @@ -1389,6 +1390,8 @@ public class AlignmentUtils .getToRanges(), 3, 1); newMapping.addMap(exon.getDatasetSequence(), seqMapping.getTo(), map); + MapList cdsToDnaMap = new MapList(dnaExonRanges, exonRange, 1, 1); + newMapping.addMap(dnaSeq, exon.getDatasetSequence(), cdsToDnaMap); exonSequences.add(exon); } diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index c19884e..9ef1b9a 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -1064,6 +1065,10 @@ public class AlignmentUtilsTests acf.addMap(dna1.getDatasetSequence(), pep3.getDatasetSequence(), map); mappings.add(acf); + /* + * Create the Exon alignment; also replaces the dna-to-protein mappings with + * exon-to-protein and exon-to-dna mappings + */ AlignmentI exal = AlignmentUtils.makeExonAlignment(new SequenceI[] { dna1 }, mappings); @@ -1099,5 +1104,48 @@ public class AlignmentUtilsTests assertEquals("EMBLCDS", cdsRef.getSource()); assertEquals("4", cdsRef.getVersion()); assertEquals("A12347", cdsRef.getAccessionId()); + + /* + * Verify there are mappings from each exon sequence to its protein product + * and also to its dna source + */ + Iterator newMappingsIterator = mappings.iterator(); + + // mappings for dna1 - exon1 - pep1 + AlignedCodonFrame exonMapping = newMappingsIterator.next(); + List dnaMappings = exonMapping.getMappingsForSequence(dna1); + assertEquals(1, dnaMappings.size()); + assertSame(exons.get(0).getDatasetSequence(), dnaMappings.get(0) + .getTo()); + assertEquals("G(1) in CDS should map to G(4) in DNA", 4, dnaMappings + .get(0).getMap().getToPosition(1)); + List peptideMappings = exonMapping + .getMappingsForSequence(pep1); + assertEquals(1, peptideMappings.size()); + assertSame(pep1.getDatasetSequence(), peptideMappings.get(0).getTo()); + + // mappings for dna1 - exon2 - pep2 + exonMapping = newMappingsIterator.next(); + dnaMappings = exonMapping.getMappingsForSequence(dna1); + assertEquals(1, dnaMappings.size()); + assertSame(exons.get(1).getDatasetSequence(), dnaMappings.get(0) + .getTo()); + assertEquals("c(4) in CDS should map to c(7) in DNA", 7, dnaMappings + .get(0).getMap().getToPosition(4)); + peptideMappings = exonMapping.getMappingsForSequence(pep2); + assertEquals(1, peptideMappings.size()); + assertSame(pep2.getDatasetSequence(), peptideMappings.get(0).getTo()); + + // mappings for dna1 - exon3 - pep3 + exonMapping = newMappingsIterator.next(); + dnaMappings = exonMapping.getMappingsForSequence(dna1); + assertEquals(1, dnaMappings.size()); + assertSame(exons.get(2).getDatasetSequence(), dnaMappings.get(0) + .getTo()); + assertEquals("T(4) in CDS should map to T(10) in DNA", 10, dnaMappings + .get(0).getMap().getToPosition(4)); + peptideMappings = exonMapping.getMappingsForSequence(pep3); + assertEquals(1, peptideMappings.size()); + assertSame(pep3.getDatasetSequence(), peptideMappings.get(0).getTo()); } }