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;
public static AlignmentI makeExonAlignment(SequenceI[] dna,
Set<AlignedCodonFrame> mappings)
{
- Set<AlignedCodonFrame> newMappings = new HashSet<AlignedCodonFrame>();
+ Set<AlignedCodonFrame> newMappings = new LinkedHashSet<AlignedCodonFrame>();
List<SequenceI> exonSequences = new ArrayList<SequenceI>();
for (SequenceI dnaSeq : dna)
/*
* Get the codon regions as { [2, 5], [7, 12], [14, 14] etc }
*/
- List<int[]> exonRanges = seqMapping.getMap().getFromRanges();
- for (int[] range : exonRanges)
+ final List<int[]> dnaExonRanges = seqMapping.getMap().getFromRanges();
+ for (int[] range : dnaExonRanges)
{
for (int pos = range[0]; pos <= range[1]; pos++)
{
.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);
}
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;
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);
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<AlignedCodonFrame> newMappingsIterator = mappings.iterator();
+
+ // mappings for dna1 - exon1 - pep1
+ AlignedCodonFrame exonMapping = newMappingsIterator.next();
+ List<Mapping> 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<Mapping> 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());
}
}