2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.analysis;
24 import static org.testng.AssertJUnit.assertEquals;
25 import static org.testng.AssertJUnit.assertFalse;
26 import static org.testng.AssertJUnit.assertNull;
27 import static org.testng.AssertJUnit.assertSame;
28 import static org.testng.AssertJUnit.assertTrue;
30 import jalview.datamodel.AlignedCodonFrame;
31 import jalview.datamodel.Alignment;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.Annotation;
35 import jalview.datamodel.DBRefEntry;
36 import jalview.datamodel.Mapping;
37 import jalview.datamodel.SearchResults;
38 import jalview.datamodel.SearchResults.Match;
39 import jalview.datamodel.Sequence;
40 import jalview.datamodel.SequenceI;
41 import jalview.io.AppletFormatAdapter;
42 import jalview.io.FormatAdapter;
43 import jalview.util.MapList;
44 import jalview.util.MappingUtils;
46 import java.io.IOException;
47 import java.util.ArrayList;
48 import java.util.Arrays;
49 import java.util.Collections;
50 import java.util.HashSet;
51 import java.util.Iterator;
52 import java.util.LinkedHashSet;
53 import java.util.List;
57 import org.testng.annotations.Test;
59 public class AlignmentUtilsTests
62 private static final String TEST_DATA =
64 "#=GS D.melanogaster.1 AC AY119185.1/838-902\n" +
65 "#=GS D.melanogaster.2 AC AC092237.1/57223-57161\n" +
66 "#=GS D.melanogaster.3 AC AY060611.1/560-627\n" +
67 "D.melanogaster.1 G.AGCC.CU...AUGAUCGA\n" +
68 "#=GR D.melanogaster.1 SS ................((((\n" +
69 "D.melanogaster.2 C.AUUCAACU.UAUGAGGAU\n" +
70 "#=GR D.melanogaster.2 SS ................((((\n" +
71 "D.melanogaster.3 G.UGGCGCU..UAUGACGCA\n" +
72 "#=GR D.melanogaster.3 SS (.(((...(....(((((((\n" +
75 private static final String AA_SEQS_1 =
81 private static final String CDNA_SEQS_1 =
83 "AC-GG--CUC-CAA-CT\n" +
85 "-CG-TTA--ACG---AAGT\n";
87 private static final String CDNA_SEQS_2 =
94 // public static Sequence ts=new
95 // Sequence("short","ASDASDASDASDASDASDASDASDASDASDASDASDASD");
96 public static Sequence ts = new Sequence("short",
97 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm");
100 public void testExpandContext()
102 AlignmentI al = new Alignment(new Sequence[] {});
103 for (int i = 4; i < 14; i += 2)
105 SequenceI s1=ts.deriveSequence().getSubSequence(i, i+7);
108 System.out.println(new AppletFormatAdapter().formatSequences("Clustal", al, true));
109 for (int flnk=-1;flnk<25; flnk++)
111 AlignmentI exp = AlignmentUtils.expandContext(al, flnk);
112 System.out.println("\nFlank size: " + flnk);
113 System.out.println(new AppletFormatAdapter().formatSequences(
114 "Clustal", exp, true));
118 * Full expansion to complete sequences
120 for (SequenceI sq : exp.getSequences())
122 String ung = sq.getSequenceAsString().replaceAll("-+", "");
123 final String errorMsg = "Flanking sequence not the same as original dataset sequence.\n"
126 + sq.getDatasetSequence().getSequenceAsString();
127 assertTrue(errorMsg, ung.equalsIgnoreCase(sq.getDatasetSequence()
128 .getSequenceAsString()));
134 * Last sequence is fully expanded, others have leading gaps to match
136 assertTrue(exp.getSequenceAt(4).getSequenceAsString()
138 assertTrue(exp.getSequenceAt(3).getSequenceAsString()
139 .startsWith("--abc"));
140 assertTrue(exp.getSequenceAt(2).getSequenceAsString()
141 .startsWith("----abc"));
142 assertTrue(exp.getSequenceAt(1).getSequenceAsString()
143 .startsWith("------abc"));
144 assertTrue(exp.getSequenceAt(0).getSequenceAsString()
145 .startsWith("--------abc"));
151 * Test that annotations are correctly adjusted by expandContext
154 public void testExpandContext_annotation()
156 AlignmentI al = new Alignment(new Sequence[]
158 SequenceI ds = new Sequence("Seq1", "ABCDEFGHI");
160 SequenceI seq1 = ds.deriveSequence().getSubSequence(3, 6);
161 al.addSequence(seq1);
164 * Annotate DEF with 4/5/6 respectively
166 Annotation[] anns = new Annotation[]
167 { new Annotation(4), new Annotation(5), new Annotation(6) };
168 AlignmentAnnotation ann = new AlignmentAnnotation("SS",
169 "secondary structure", anns);
170 seq1.addAlignmentAnnotation(ann);
173 * The annotations array should match aligned positions
175 assertEquals(3, ann.annotations.length);
176 assertEquals(4, ann.annotations[0].value, 0.001);
177 assertEquals(5, ann.annotations[1].value, 0.001);
178 assertEquals(6, ann.annotations[2].value, 0.001);
181 * Check annotation to sequence position mappings before expanding the
182 * sequence; these are set up in Sequence.addAlignmentAnnotation ->
183 * Annotation.setSequenceRef -> createSequenceMappings
185 assertNull(ann.getAnnotationForPosition(1));
186 assertNull(ann.getAnnotationForPosition(2));
187 assertNull(ann.getAnnotationForPosition(3));
188 assertEquals(4, ann.getAnnotationForPosition(4).value, 0.001);
189 assertEquals(5, ann.getAnnotationForPosition(5).value, 0.001);
190 assertEquals(6, ann.getAnnotationForPosition(6).value, 0.001);
191 assertNull(ann.getAnnotationForPosition(7));
192 assertNull(ann.getAnnotationForPosition(8));
193 assertNull(ann.getAnnotationForPosition(9));
196 * Expand the subsequence to the full sequence abcDEFghi
198 AlignmentI expanded = AlignmentUtils.expandContext(al, -1);
199 assertEquals("abcDEFghi", expanded.getSequenceAt(0)
200 .getSequenceAsString());
203 * Confirm the alignment and sequence have the same SS annotation,
204 * referencing the expanded sequence
206 ann = expanded.getSequenceAt(0).getAnnotation()[0];
207 assertSame(ann, expanded.getAlignmentAnnotation()[0]);
208 assertSame(expanded.getSequenceAt(0), ann.sequenceRef);
211 * The annotations array should have null values except for annotated
214 assertNull(ann.annotations[0]);
215 assertNull(ann.annotations[1]);
216 assertNull(ann.annotations[2]);
217 assertEquals(4, ann.annotations[3].value, 0.001);
218 assertEquals(5, ann.annotations[4].value, 0.001);
219 assertEquals(6, ann.annotations[5].value, 0.001);
220 assertNull(ann.annotations[6]);
221 assertNull(ann.annotations[7]);
222 assertNull(ann.annotations[8]);
225 * sequence position mappings should be unchanged
227 assertNull(ann.getAnnotationForPosition(1));
228 assertNull(ann.getAnnotationForPosition(2));
229 assertNull(ann.getAnnotationForPosition(3));
230 assertEquals(4, ann.getAnnotationForPosition(4).value, 0.001);
231 assertEquals(5, ann.getAnnotationForPosition(5).value, 0.001);
232 assertEquals(6, ann.getAnnotationForPosition(6).value, 0.001);
233 assertNull(ann.getAnnotationForPosition(7));
234 assertNull(ann.getAnnotationForPosition(8));
235 assertNull(ann.getAnnotationForPosition(9));
239 * Test method that returns a map of lists of sequences by sequence name.
241 * @throws IOException
244 public void testGetSequencesByName() throws IOException
246 final String data = ">Seq1Name\nKQYL\n" + ">Seq2Name\nRFPW\n"
247 + ">Seq1Name\nABCD\n";
248 AlignmentI al = loadAlignment(data, "FASTA");
249 Map<String, List<SequenceI>> map = AlignmentUtils
250 .getSequencesByName(al);
251 assertEquals(2, map.keySet().size());
252 assertEquals(2, map.get("Seq1Name").size());
253 assertEquals("KQYL", map.get("Seq1Name").get(0).getSequenceAsString());
254 assertEquals("ABCD", map.get("Seq1Name").get(1).getSequenceAsString());
255 assertEquals(1, map.get("Seq2Name").size());
256 assertEquals("RFPW", map.get("Seq2Name").get(0).getSequenceAsString());
259 * Helper method to load an alignment and ensure dataset sequences are set up.
264 * @throws IOException
266 protected AlignmentI loadAlignment(final String data, String format) throws IOException
268 AlignmentI a = new FormatAdapter().readFile(data,
269 AppletFormatAdapter.PASTE, format);
275 * Test mapping of protein to cDNA, for the case where we have no sequence
276 * cross-references, so mappings are made first-served 1-1 where sequences
279 * @throws IOException
282 public void testMapProteinToCdna_noXrefs() throws IOException
284 List<SequenceI> protseqs = new ArrayList<SequenceI>();
285 protseqs.add(new Sequence("UNIPROT|V12345", "EIQ"));
286 protseqs.add(new Sequence("UNIPROT|V12346", "EIQ"));
287 protseqs.add(new Sequence("UNIPROT|V12347", "SAR"));
288 AlignmentI protein = new Alignment(protseqs.toArray(new SequenceI[3]));
289 protein.setDataset(null);
291 List<SequenceI> dnaseqs = new ArrayList<SequenceI>();
292 dnaseqs.add(new Sequence("EMBL|A11111", "TCAGCACGC")); // = SAR
293 dnaseqs.add(new Sequence("EMBL|A22222", "GAGATACAA")); // = EIQ
294 dnaseqs.add(new Sequence("EMBL|A33333", "GAAATCCAG")); // = EIQ
295 dnaseqs.add(new Sequence("EMBL|A44444", "GAAATTCAG")); // = EIQ
296 AlignmentI cdna = new Alignment(dnaseqs.toArray(new SequenceI[4]));
297 cdna.setDataset(null);
299 assertTrue(AlignmentUtils.mapProteinToCdna(protein, cdna));
301 // 3 mappings made, each from 1 to 1 sequence
302 assertEquals(3, protein.getCodonFrames().size());
303 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(0)).size());
304 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(1)).size());
305 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(2)).size());
307 // V12345 mapped to A22222
308 AlignedCodonFrame acf = protein.getCodonFrame(
309 protein.getSequenceAt(0)).get(0);
310 assertEquals(1, acf.getdnaSeqs().length);
311 assertEquals(cdna.getSequenceAt(1).getDatasetSequence(),
312 acf.getdnaSeqs()[0]);
313 Mapping[] protMappings = acf.getProtMappings();
314 assertEquals(1, protMappings.length);
315 MapList mapList = protMappings[0].getMap();
316 assertEquals(3, mapList.getFromRatio());
317 assertEquals(1, mapList.getToRatio());
318 assertTrue(Arrays.equals(new int[]
319 { 1, 9 }, mapList.getFromRanges().get(0)));
320 assertEquals(1, mapList.getFromRanges().size());
321 assertTrue(Arrays.equals(new int[]
322 { 1, 3 }, mapList.getToRanges().get(0)));
323 assertEquals(1, mapList.getToRanges().size());
325 // V12346 mapped to A33333
326 acf = protein.getCodonFrame(protein.getSequenceAt(1)).get(0);
327 assertEquals(1, acf.getdnaSeqs().length);
328 assertEquals(cdna.getSequenceAt(2).getDatasetSequence(),
329 acf.getdnaSeqs()[0]);
331 // V12347 mapped to A11111
332 acf = protein.getCodonFrame(protein.getSequenceAt(2)).get(0);
333 assertEquals(1, acf.getdnaSeqs().length);
334 assertEquals(cdna.getSequenceAt(0).getDatasetSequence(),
335 acf.getdnaSeqs()[0]);
337 // no mapping involving the 'extra' A44444
338 assertTrue(protein.getCodonFrame(cdna.getSequenceAt(3)).isEmpty());
342 * Test for the alignSequenceAs method that takes two sequences and a mapping.
345 public void testAlignSequenceAs_withMapping_noIntrons()
347 MapList map = new MapList(new int[]
352 * No existing gaps in dna:
354 checkAlignSequenceAs("GGGAAA", "-A-L-", false, false, map,
358 * Now introduce gaps in dna but ignore them when realigning.
360 checkAlignSequenceAs("-G-G-G-A-A-A-", "-A-L-", false, false, map,
364 * Now include gaps in dna when realigning. First retaining 'mapped' gaps
365 * only, i.e. those within the exon region.
367 checkAlignSequenceAs("-G-G--G-A--A-A-", "-A-L-", true, false, map,
368 "---G-G--G---A--A-A");
371 * Include all gaps in dna when realigning (within and without the exon
372 * region). The leading gap, and the gaps between codons, are subsumed by
373 * the protein alignment gap.
375 checkAlignSequenceAs("-G-GG--AA-A-", "-A-L-", true, true, map,
379 * Include only unmapped gaps in dna when realigning (outside the exon
380 * region). The leading gap, and the gaps between codons, are subsumed by
381 * the protein alignment gap.
383 checkAlignSequenceAs("-G-GG--AA-A-", "-A-L-", false, true, map,
388 * Test for the alignSequenceAs method that takes two sequences and a mapping.
391 public void testAlignSequenceAs_withMapping_withIntrons()
394 * Exons at codon 2 (AAA) and 4 (TTT)
396 MapList map = new MapList(new int[]
397 { 4, 6, 10, 12 }, new int[]
401 * Simple case: no gaps in dna
403 checkAlignSequenceAs("GGGAAACCCTTTGGG", "--A-L-", false, false, map,
404 "GGG---AAACCCTTTGGG");
407 * Add gaps to dna - but ignore when realigning.
409 checkAlignSequenceAs("-G-G-G--A--A---AC-CC-T-TT-GG-G-", "--A-L-",
410 false, false, map, "GGG---AAACCCTTTGGG");
413 * Add gaps to dna - include within exons only when realigning.
415 checkAlignSequenceAs("-G-G-G--A--A---A-C-CC-T-TT-GG-G-", "--A-L-",
416 true, false, map, "GGG---A--A---ACCCT-TTGGG");
419 * Include gaps outside exons only when realigning.
421 checkAlignSequenceAs("-G-G-G--A--A---A-C-CC-T-TT-GG-G-", "--A-L-",
422 false, true, map, "-G-G-GAAAC-CCTTT-GG-G-");
425 * Include gaps following first intron if we are 'preserving mapped gaps'
427 checkAlignSequenceAs("-G-G-G--A--A---A-C-CC-T-TT-GG-G-", "--A-L-",
428 true, true, map, "-G-G-G--A--A---A-C-CC-T-TT-GG-G-");
431 * Include all gaps in dna when realigning.
433 checkAlignSequenceAs("-G-G-G--A--A---A-C-CC-T-TT-GG-G-", "--A-L-",
434 true, true, map, "-G-G-G--A--A---A-C-CC-T-TT-GG-G-");
438 * Test for the case where not all of the protein sequence is mapped to cDNA.
441 public void testAlignSequenceAs_withMapping_withUnmappedProtein()
445 * Exons at codon 2 (AAA) and 4 (TTT) mapped to A and P
447 final MapList map = new MapList(new int[]
448 { 4, 6, 10, 12 }, new int[]
449 { 1, 1, 3, 3 }, 3, 1);
453 * Expect alignment does nothing (aborts realignment). Change this test
454 * first if different behaviour wanted.
456 checkAlignSequenceAs("GGGAAACCCTTTGGG", "-A-L-P-", false,
457 false, map, "GGGAAACCCTTTGGG");
461 * Helper method that performs and verifies the method under test.
465 * @param preserveMappedGaps
466 * @param preserveUnmappedGaps
470 protected void checkAlignSequenceAs(final String dnaSeq,
471 final String proteinSeq, final boolean preserveMappedGaps,
472 final boolean preserveUnmappedGaps, MapList map,
473 final String expected)
475 SequenceI dna = new Sequence("Seq1", dnaSeq);
476 dna.createDatasetSequence();
477 SequenceI protein = new Sequence("Seq1", proteinSeq);
478 protein.createDatasetSequence();
479 AlignedCodonFrame acf = new AlignedCodonFrame();
480 acf.addMap(dna.getDatasetSequence(), protein.getDatasetSequence(), map);
482 AlignmentUtils.alignSequenceAs(dna, protein, acf, "---", '-',
483 preserveMappedGaps, preserveUnmappedGaps);
484 assertEquals(expected, dna.getSequenceAsString());
488 * Test for the alignSequenceAs method where we preserve gaps in introns only.
491 public void testAlignSequenceAs_keepIntronGapsOnly()
495 * Intron GGGAAA followed by exon CCCTTT
497 MapList map = new MapList(new int[]
501 checkAlignSequenceAs("GG-G-AA-A-C-CC-T-TT", "AL",
502 false, true, map, "GG-G-AA-ACCCTTT");
506 * Test for the method that generates an aligned translated sequence from one
510 public void testGetAlignedTranslation_dnaLikeProtein()
512 // dna alignment will be replaced
513 SequenceI dna = new Sequence("Seq1", "T-G-CC-A--T-TAC-CAG-");
514 dna.createDatasetSequence();
515 // protein alignment will be 'applied' to dna
516 SequenceI protein = new Sequence("Seq1", "-CH-Y--Q-");
517 protein.createDatasetSequence();
518 MapList map = new MapList(new int[]
521 AlignedCodonFrame acf = new AlignedCodonFrame();
522 acf.addMap(dna.getDatasetSequence(), protein.getDatasetSequence(), map);
524 final SequenceI aligned = AlignmentUtils
525 .getAlignedTranslation(protein, '-', acf);
526 assertEquals("---TGCCAT---TAC------CAG---", aligned.getSequenceAsString());
527 assertSame(aligned.getDatasetSequence(), dna.getDatasetSequence());
531 * Test the method that realigns protein to match mapped codon alignment.
534 public void testAlignProteinAsDna()
536 // seq1 codons are [1,2,3] [4,5,6] [7,8,9] [10,11,12]
537 SequenceI dna1 = new Sequence("Seq1", "TGCCATTACCAG-");
538 // seq2 codons are [1,3,4] [5,6,7] [8,9,10] [11,12,13]
539 SequenceI dna2 = new Sequence("Seq2", "T-GCCATTACCAG");
540 // seq3 codons are [1,2,3] [4,5,7] [8,9,10] [11,12,13]
541 SequenceI dna3 = new Sequence("Seq3", "TGCCA-TTACCAG");
542 AlignmentI dna = new Alignment(new SequenceI[]
543 { dna1, dna2, dna3 });
544 dna.setDataset(null);
546 // protein alignment will be realigned like dna
547 SequenceI prot1 = new Sequence("Seq1", "CHYQ");
548 SequenceI prot2 = new Sequence("Seq2", "CHYQ");
549 SequenceI prot3 = new Sequence("Seq3", "CHYQ");
550 AlignmentI protein = new Alignment(new SequenceI[]
551 { prot1, prot2, prot3 });
552 protein.setDataset(null);
554 MapList map = new MapList(new int[]
557 AlignedCodonFrame acf = new AlignedCodonFrame();
558 acf.addMap(dna1.getDatasetSequence(), prot1.getDatasetSequence(), map);
559 acf.addMap(dna2.getDatasetSequence(), prot2.getDatasetSequence(), map);
560 acf.addMap(dna3.getDatasetSequence(), prot3.getDatasetSequence(), map);
561 protein.setCodonFrames(Collections.singleton(acf));
564 * Translated codon order is [1,2,3] [1,3,4] [4,5,6] [4,5,7] [5,6,7] [7,8,9]
565 * [8,9,10] [10,11,12] [11,12,13]
567 AlignmentUtils.alignProteinAsDna(protein, dna);
568 assertEquals("C-H--Y-Q-", prot1.getSequenceAsString());
569 assertEquals("-C--H-Y-Q", prot2.getSequenceAsString());
570 assertEquals("C--H--Y-Q", prot3.getSequenceAsString());
574 * Test the method that tests whether a CDNA sequence translates to a protein
578 public void testTranslatesAs()
580 assertTrue(AlignmentUtils.translatesAs("tttcccaaaggg".toCharArray(), 0,
581 "FPKG".toCharArray()));
583 assertTrue(AlignmentUtils.translatesAs("atgtttcccaaaggg".toCharArray(),
584 3, "FPKG".toCharArray()));
586 assertTrue(AlignmentUtils.translatesAs("tttcccaaagggtaa".toCharArray(),
587 0, "FPKG".toCharArray()));
589 assertTrue(AlignmentUtils.translatesAs("tttcccaaagggtag".toCharArray(),
590 0, "FPKG".toCharArray()));
592 assertTrue(AlignmentUtils.translatesAs("tttcccaaagggtga".toCharArray(),
593 0, "FPKG".toCharArray()));
594 // with start and stop codon1
595 assertTrue(AlignmentUtils.translatesAs(
596 "atgtttcccaaaggtaa".toCharArray(), 3, "FPKG".toCharArray()));
597 // with start and stop codon2
598 assertTrue(AlignmentUtils.translatesAs(
599 "atgtttcccaaaggtag".toCharArray(), 3, "FPKG".toCharArray()));
600 // with start and stop codon3
601 assertTrue(AlignmentUtils.translatesAs(
602 "atgtttcccaaaggtga".toCharArray(), 3, "FPKG".toCharArray()));
605 assertFalse(AlignmentUtils.translatesAs("tttcccaaaggg".toCharArray(),
607 "FPMG".toCharArray()));
611 * Test mapping of protein to cDNA, for cases where the cDNA has start and/or
612 * stop codons in addition to the protein coding sequence.
614 * @throws IOException
617 public void testMapProteinToCdna_withStartAndStopCodons()
620 List<SequenceI> protseqs = new ArrayList<SequenceI>();
621 protseqs.add(new Sequence("UNIPROT|V12345", "EIQ"));
622 protseqs.add(new Sequence("UNIPROT|V12346", "EIQ"));
623 protseqs.add(new Sequence("UNIPROT|V12347", "SAR"));
624 AlignmentI protein = new Alignment(protseqs.toArray(new SequenceI[3]));
625 protein.setDataset(null);
627 List<SequenceI> dnaseqs = new ArrayList<SequenceI>();
629 dnaseqs.add(new Sequence("EMBL|A11111", "ATGTCAGCACGC"));
631 dnaseqs.add(new Sequence("EMBL|A22222", "GAGATACAATAA"));
632 // = start +EIQ + stop
633 dnaseqs.add(new Sequence("EMBL|A33333", "ATGGAAATCCAGTAG"));
634 dnaseqs.add(new Sequence("EMBL|A44444", "GAAATTCAG"));
635 AlignmentI cdna = new Alignment(dnaseqs.toArray(new SequenceI[4]));
636 cdna.setDataset(null);
638 assertTrue(AlignmentUtils.mapProteinToCdna(protein, cdna));
640 // 3 mappings made, each from 1 to 1 sequence
641 assertEquals(3, protein.getCodonFrames().size());
642 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(0)).size());
643 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(1)).size());
644 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(2)).size());
646 // V12345 mapped from A22222
647 AlignedCodonFrame acf = protein.getCodonFrame(
648 protein.getSequenceAt(0)).get(0);
649 assertEquals(1, acf.getdnaSeqs().length);
650 assertEquals(cdna.getSequenceAt(1).getDatasetSequence(),
651 acf.getdnaSeqs()[0]);
652 Mapping[] protMappings = acf.getProtMappings();
653 assertEquals(1, protMappings.length);
654 MapList mapList = protMappings[0].getMap();
655 assertEquals(3, mapList.getFromRatio());
656 assertEquals(1, mapList.getToRatio());
657 assertTrue(Arrays.equals(new int[]
658 { 1, 9 }, mapList.getFromRanges().get(0)));
659 assertEquals(1, mapList.getFromRanges().size());
660 assertTrue(Arrays.equals(new int[]
661 { 1, 3 }, mapList.getToRanges().get(0)));
662 assertEquals(1, mapList.getToRanges().size());
664 // V12346 mapped from A33333 starting position 4
665 acf = protein.getCodonFrame(protein.getSequenceAt(1)).get(0);
666 assertEquals(1, acf.getdnaSeqs().length);
667 assertEquals(cdna.getSequenceAt(2).getDatasetSequence(),
668 acf.getdnaSeqs()[0]);
669 protMappings = acf.getProtMappings();
670 assertEquals(1, protMappings.length);
671 mapList = protMappings[0].getMap();
672 assertEquals(3, mapList.getFromRatio());
673 assertEquals(1, mapList.getToRatio());
674 assertTrue(Arrays.equals(new int[]
675 { 4, 12 }, mapList.getFromRanges().get(0)));
676 assertEquals(1, mapList.getFromRanges().size());
677 assertTrue(Arrays.equals(new int[]
678 { 1, 3 }, mapList.getToRanges().get(0)));
679 assertEquals(1, mapList.getToRanges().size());
681 // V12347 mapped to A11111 starting position 4
682 acf = protein.getCodonFrame(protein.getSequenceAt(2)).get(0);
683 assertEquals(1, acf.getdnaSeqs().length);
684 assertEquals(cdna.getSequenceAt(0).getDatasetSequence(),
685 acf.getdnaSeqs()[0]);
686 protMappings = acf.getProtMappings();
687 assertEquals(1, protMappings.length);
688 mapList = protMappings[0].getMap();
689 assertEquals(3, mapList.getFromRatio());
690 assertEquals(1, mapList.getToRatio());
691 assertTrue(Arrays.equals(new int[]
692 { 4, 12 }, mapList.getFromRanges().get(0)));
693 assertEquals(1, mapList.getFromRanges().size());
694 assertTrue(Arrays.equals(new int[]
695 { 1, 3 }, mapList.getToRanges().get(0)));
696 assertEquals(1, mapList.getToRanges().size());
698 // no mapping involving the 'extra' A44444
699 assertTrue(protein.getCodonFrame(cdna.getSequenceAt(3)).isEmpty());
703 * Test mapping of protein to cDNA, for the case where we have some sequence
704 * cross-references. Verify that 1-to-many mappings are made where
705 * cross-references exist and sequences are mappable.
707 * @throws IOException
710 public void testMapProteinToCdna_withXrefs() throws IOException
712 List<SequenceI> protseqs = new ArrayList<SequenceI>();
713 protseqs.add(new Sequence("UNIPROT|V12345", "EIQ"));
714 protseqs.add(new Sequence("UNIPROT|V12346", "EIQ"));
715 protseqs.add(new Sequence("UNIPROT|V12347", "SAR"));
716 AlignmentI protein = new Alignment(protseqs.toArray(new SequenceI[3]));
717 protein.setDataset(null);
719 List<SequenceI> dnaseqs = new ArrayList<SequenceI>();
720 dnaseqs.add(new Sequence("EMBL|A11111", "TCAGCACGC")); // = SAR
721 dnaseqs.add(new Sequence("EMBL|A22222", "ATGGAGATACAA")); // = start + EIQ
722 dnaseqs.add(new Sequence("EMBL|A33333", "GAAATCCAG")); // = EIQ
723 dnaseqs.add(new Sequence("EMBL|A44444", "GAAATTCAG")); // = EIQ
724 dnaseqs.add(new Sequence("EMBL|A55555", "GAGATTCAG")); // = EIQ
725 AlignmentI cdna = new Alignment(dnaseqs.toArray(new SequenceI[5]));
726 cdna.setDataset(null);
728 // Xref A22222 to V12345 (should get mapped)
729 dnaseqs.get(1).addDBRef(new DBRefEntry("UNIPROT", "1", "V12345"));
730 // Xref V12345 to A44444 (should get mapped)
731 protseqs.get(0).addDBRef(new DBRefEntry("EMBL", "1", "A44444"));
732 // Xref A33333 to V12347 (sequence mismatch - should not get mapped)
733 dnaseqs.get(2).addDBRef(new DBRefEntry("UNIPROT", "1", "V12347"));
734 // as V12345 is mapped to A22222 and A44444, this leaves V12346 unmapped.
735 // it should get paired up with the unmapped A33333
736 // A11111 should be mapped to V12347
737 // A55555 is spare and has no xref so is not mapped
739 assertTrue(AlignmentUtils.mapProteinToCdna(protein, cdna));
741 // 4 protein mappings made for 3 proteins, 2 to V12345, 1 each to V12346/7
742 assertEquals(3, protein.getCodonFrames().size());
743 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(0)).size());
744 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(1)).size());
745 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(2)).size());
747 // one mapping for each of the first 4 cDNA sequences
748 assertEquals(1, protein.getCodonFrame(cdna.getSequenceAt(0)).size());
749 assertEquals(1, protein.getCodonFrame(cdna.getSequenceAt(1)).size());
750 assertEquals(1, protein.getCodonFrame(cdna.getSequenceAt(2)).size());
751 assertEquals(1, protein.getCodonFrame(cdna.getSequenceAt(3)).size());
753 // V12345 mapped to A22222 and A44444
754 AlignedCodonFrame acf = protein.getCodonFrame(
755 protein.getSequenceAt(0)).get(0);
756 assertEquals(2, acf.getdnaSeqs().length);
757 assertEquals(cdna.getSequenceAt(1).getDatasetSequence(),
758 acf.getdnaSeqs()[0]);
759 assertEquals(cdna.getSequenceAt(3).getDatasetSequence(),
760 acf.getdnaSeqs()[1]);
762 // V12346 mapped to A33333
763 acf = protein.getCodonFrame(protein.getSequenceAt(1)).get(0);
764 assertEquals(1, acf.getdnaSeqs().length);
765 assertEquals(cdna.getSequenceAt(2).getDatasetSequence(),
766 acf.getdnaSeqs()[0]);
768 // V12347 mapped to A11111
769 acf = protein.getCodonFrame(protein.getSequenceAt(2)).get(0);
770 assertEquals(1, acf.getdnaSeqs().length);
771 assertEquals(cdna.getSequenceAt(0).getDatasetSequence(),
772 acf.getdnaSeqs()[0]);
774 // no mapping involving the 'extra' A55555
775 assertTrue(protein.getCodonFrame(cdna.getSequenceAt(4)).isEmpty());
779 * Test mapping of protein to cDNA, for the case where we have some sequence
780 * cross-references. Verify that once we have made an xref mapping we don't
781 * also map un-xrefd sequeces.
783 * @throws IOException
786 public void testMapProteinToCdna_prioritiseXrefs() throws IOException
788 List<SequenceI> protseqs = new ArrayList<SequenceI>();
789 protseqs.add(new Sequence("UNIPROT|V12345", "EIQ"));
790 protseqs.add(new Sequence("UNIPROT|V12346", "EIQ"));
791 AlignmentI protein = new Alignment(
792 protseqs.toArray(new SequenceI[protseqs.size()]));
793 protein.setDataset(null);
795 List<SequenceI> dnaseqs = new ArrayList<SequenceI>();
796 dnaseqs.add(new Sequence("EMBL|A11111", "GAAATCCAG")); // = EIQ
797 dnaseqs.add(new Sequence("EMBL|A22222", "GAAATTCAG")); // = EIQ
798 AlignmentI cdna = new Alignment(dnaseqs.toArray(new SequenceI[dnaseqs
800 cdna.setDataset(null);
802 // Xref A22222 to V12345 (should get mapped)
803 // A11111 should then be mapped to the unmapped V12346
804 dnaseqs.get(1).addDBRef(new DBRefEntry("UNIPROT", "1", "V12345"));
806 assertTrue(AlignmentUtils.mapProteinToCdna(protein, cdna));
808 // 2 protein mappings made
809 assertEquals(2, protein.getCodonFrames().size());
810 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(0)).size());
811 assertEquals(1, protein.getCodonFrame(protein.getSequenceAt(1)).size());
813 // one mapping for each of the cDNA sequences
814 assertEquals(1, protein.getCodonFrame(cdna.getSequenceAt(0)).size());
815 assertEquals(1, protein.getCodonFrame(cdna.getSequenceAt(1)).size());
817 // V12345 mapped to A22222
818 AlignedCodonFrame acf = protein.getCodonFrame(protein.getSequenceAt(0))
820 assertEquals(1, acf.getdnaSeqs().length);
821 assertEquals(cdna.getSequenceAt(1).getDatasetSequence(),
822 acf.getdnaSeqs()[0]);
824 // V12346 mapped to A11111
825 acf = protein.getCodonFrame(protein.getSequenceAt(1)).get(0);
826 assertEquals(1, acf.getdnaSeqs().length);
827 assertEquals(cdna.getSequenceAt(0).getDatasetSequence(),
828 acf.getdnaSeqs()[0]);
832 * Test the method that shows or hides sequence annotations by type(s) and
836 public void testShowOrHideSequenceAnnotations()
838 SequenceI seq1 = new Sequence("Seq1", "AAA");
839 SequenceI seq2 = new Sequence("Seq2", "BBB");
840 SequenceI seq3 = new Sequence("Seq3", "CCC");
841 Annotation[] anns = new Annotation[]
842 { new Annotation(2f) };
843 AlignmentAnnotation ann1 = new AlignmentAnnotation("Structure", "ann1",
845 ann1.setSequenceRef(seq1);
846 AlignmentAnnotation ann2 = new AlignmentAnnotation("Structure", "ann2",
848 ann2.setSequenceRef(seq2);
849 AlignmentAnnotation ann3 = new AlignmentAnnotation("Structure", "ann3",
851 AlignmentAnnotation ann4 = new AlignmentAnnotation("Temp", "ann4", anns);
852 ann4.setSequenceRef(seq1);
853 AlignmentAnnotation ann5 = new AlignmentAnnotation("Temp", "ann5", anns);
854 ann5.setSequenceRef(seq2);
855 AlignmentAnnotation ann6 = new AlignmentAnnotation("Temp", "ann6", anns);
856 AlignmentI al = new Alignment(new SequenceI[] {seq1, seq2, seq3});
857 al.addAnnotation(ann1); // Structure for Seq1
858 al.addAnnotation(ann2); // Structure for Seq2
859 al.addAnnotation(ann3); // Structure for no sequence
860 al.addAnnotation(ann4); // Temp for seq1
861 al.addAnnotation(ann5); // Temp for seq2
862 al.addAnnotation(ann6); // Temp for no sequence
863 List<String> types = new ArrayList<String>();
864 List<SequenceI> scope = new ArrayList<SequenceI>();
867 * Set all sequence related Structure to hidden (ann1, ann2)
869 types.add("Structure");
870 AlignmentUtils.showOrHideSequenceAnnotations(al, types, null, false,
872 assertFalse(ann1.visible);
873 assertFalse(ann2.visible);
874 assertTrue(ann3.visible); // not sequence-related, not affected
875 assertTrue(ann4.visible); // not Structure, not affected
876 assertTrue(ann5.visible); // "
877 assertTrue(ann6.visible); // not sequence-related, not affected
880 * Set Temp in {seq1, seq3} to hidden
886 AlignmentUtils.showOrHideSequenceAnnotations(al, types, scope, false,
888 assertFalse(ann1.visible); // unchanged
889 assertFalse(ann2.visible); // unchanged
890 assertTrue(ann3.visible); // not sequence-related, not affected
891 assertFalse(ann4.visible); // Temp for seq1 hidden
892 assertTrue(ann5.visible); // not in scope, not affected
893 assertTrue(ann6.visible); // not sequence-related, not affected
896 * Set Temp in all sequences to hidden
902 AlignmentUtils.showOrHideSequenceAnnotations(al, types, null, false,
904 assertFalse(ann1.visible); // unchanged
905 assertFalse(ann2.visible); // unchanged
906 assertTrue(ann3.visible); // not sequence-related, not affected
907 assertFalse(ann4.visible); // Temp for seq1 hidden
908 assertFalse(ann5.visible); // Temp for seq2 hidden
909 assertTrue(ann6.visible); // not sequence-related, not affected
912 * Set all types in {seq1, seq3} to visible
918 AlignmentUtils.showOrHideSequenceAnnotations(al, types, scope, true,
920 assertTrue(ann1.visible); // Structure for seq1 set visible
921 assertFalse(ann2.visible); // not in scope, unchanged
922 assertTrue(ann3.visible); // not sequence-related, not affected
923 assertTrue(ann4.visible); // Temp for seq1 set visible
924 assertFalse(ann5.visible); // not in scope, unchanged
925 assertTrue(ann6.visible); // not sequence-related, not affected
928 * Set all types in all scope to hidden
930 AlignmentUtils.showOrHideSequenceAnnotations(al, types, null, true,
932 assertFalse(ann1.visible);
933 assertFalse(ann2.visible);
934 assertTrue(ann3.visible); // not sequence-related, not affected
935 assertFalse(ann4.visible);
936 assertFalse(ann5.visible);
937 assertTrue(ann6.visible); // not sequence-related, not affected
941 * Tests for the method that checks if one sequence cross-references another
944 public void testHasCrossRef()
946 assertFalse(AlignmentUtils.hasCrossRef(null, null));
947 SequenceI seq1 = new Sequence("EMBL|A12345", "ABCDEF");
948 assertFalse(AlignmentUtils.hasCrossRef(seq1, null));
949 assertFalse(AlignmentUtils.hasCrossRef(null, seq1));
950 SequenceI seq2 = new Sequence("UNIPROT|V20192", "ABCDEF");
951 assertFalse(AlignmentUtils.hasCrossRef(seq1, seq2));
954 seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "v20193"));
955 assertFalse(AlignmentUtils.hasCrossRef(seq1, seq2));
957 // case-insensitive; version number is ignored
958 seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "v20192"));
959 assertTrue(AlignmentUtils.hasCrossRef(seq1, seq2));
962 seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192"));
963 assertTrue(AlignmentUtils.hasCrossRef(seq1, seq2));
964 // test is one-way only
965 assertFalse(AlignmentUtils.hasCrossRef(seq2, seq1));
969 * Tests for the method that checks if either sequence cross-references the
973 public void testHaveCrossRef()
975 assertFalse(AlignmentUtils.hasCrossRef(null, null));
976 SequenceI seq1 = new Sequence("EMBL|A12345", "ABCDEF");
977 assertFalse(AlignmentUtils.haveCrossRef(seq1, null));
978 assertFalse(AlignmentUtils.haveCrossRef(null, seq1));
979 SequenceI seq2 = new Sequence("UNIPROT|V20192", "ABCDEF");
980 assertFalse(AlignmentUtils.haveCrossRef(seq1, seq2));
982 seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192"));
983 assertTrue(AlignmentUtils.haveCrossRef(seq1, seq2));
984 // next is true for haveCrossRef, false for hasCrossRef
985 assertTrue(AlignmentUtils.haveCrossRef(seq2, seq1));
987 // now the other way round
989 seq2.addDBRef(new DBRefEntry("EMBL", "1", "A12345"));
990 assertTrue(AlignmentUtils.haveCrossRef(seq1, seq2));
991 assertTrue(AlignmentUtils.haveCrossRef(seq2, seq1));
994 seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192"));
995 assertTrue(AlignmentUtils.haveCrossRef(seq1, seq2));
996 assertTrue(AlignmentUtils.haveCrossRef(seq2, seq1));
1000 * Test the method that extracts the exon-only part of a dna alignment.
1003 public void testMakeExonAlignment()
1005 SequenceI dna1 = new Sequence("dna1", "aaaGGGcccTTTaaa");
1006 SequenceI dna2 = new Sequence("dna2", "GGGcccTTTaaaCCC");
1007 SequenceI pep1 = new Sequence("pep1", "GF");
1008 SequenceI pep2 = new Sequence("pep2", "GFP");
1009 dna1.createDatasetSequence();
1010 dna2.createDatasetSequence();
1011 pep1.createDatasetSequence();
1012 pep2.createDatasetSequence();
1014 Set<AlignedCodonFrame> mappings = new HashSet<AlignedCodonFrame>();
1015 MapList map = new MapList(new int[]
1016 { 4, 6, 10, 12 }, new int[]
1018 AlignedCodonFrame acf = new AlignedCodonFrame();
1019 acf.addMap(dna1.getDatasetSequence(), pep1.getDatasetSequence(), map);
1021 map = new MapList(new int[]
1022 { 1, 3, 7, 9, 13, 15 }, new int[]
1024 acf = new AlignedCodonFrame();
1025 acf.addMap(dna2.getDatasetSequence(), pep2.getDatasetSequence(), map);
1028 AlignmentI exons = AlignmentUtils.makeExonAlignment(new SequenceI[]
1029 { dna1, dna2 }, mappings);
1030 assertEquals(2, exons.getSequences().size());
1031 assertEquals("GGGTTT", exons.getSequenceAt(0).getSequenceAsString());
1032 assertEquals("GGGTTTCCC", exons.getSequenceAt(1).getSequenceAsString());
1035 * Verify updated mappings
1037 assertEquals(2, mappings.size());
1040 * Mapping from pep1 to GGGTTT in first new exon sequence
1042 List<AlignedCodonFrame> pep1Mapping = MappingUtils
1043 .findMappingsForSequence(pep1, mappings);
1044 assertEquals(1, pep1Mapping.size());
1046 SearchResults sr = MappingUtils.buildSearchResults(pep1, 1, mappings);
1047 assertEquals(1, sr.getResults().size());
1048 Match m = sr.getResults().get(0);
1049 assertEquals(exons.getSequenceAt(0).getDatasetSequence(),
1051 assertEquals(1, m.getStart());
1052 assertEquals(3, m.getEnd());
1054 sr = MappingUtils.buildSearchResults(pep1, 2, mappings);
1055 m = sr.getResults().get(0);
1056 assertEquals(exons.getSequenceAt(0).getDatasetSequence(),
1058 assertEquals(4, m.getStart());
1059 assertEquals(6, m.getEnd());
1062 * Mapping from pep2 to GGGTTTCCC in second new exon sequence
1064 List<AlignedCodonFrame> pep2Mapping = MappingUtils
1065 .findMappingsForSequence(pep2, mappings);
1066 assertEquals(1, pep2Mapping.size());
1068 sr = MappingUtils.buildSearchResults(pep2, 1, mappings);
1069 assertEquals(1, sr.getResults().size());
1070 m = sr.getResults().get(0);
1071 assertEquals(exons.getSequenceAt(1).getDatasetSequence(),
1073 assertEquals(1, m.getStart());
1074 assertEquals(3, m.getEnd());
1076 sr = MappingUtils.buildSearchResults(pep2, 2, mappings);
1077 m = sr.getResults().get(0);
1078 assertEquals(exons.getSequenceAt(1).getDatasetSequence(),
1080 assertEquals(4, m.getStart());
1081 assertEquals(6, m.getEnd());
1083 sr = MappingUtils.buildSearchResults(pep2, 3, mappings);
1084 m = sr.getResults().get(0);
1085 assertEquals(exons.getSequenceAt(1).getDatasetSequence(),
1087 assertEquals(7, m.getStart());
1088 assertEquals(9, m.getEnd());
1092 * Test the method that makes an exon-only sequence from a DNA sequence and
1093 * its product mapping. Test includes the expected case that the DNA sequence
1094 * already has a protein product (Uniprot translation) which in turn has an
1095 * x-ref to the EMBLCDS record.
1098 public void testMakeExonSequences()
1100 SequenceI dna1 = new Sequence("dna1", "aaaGGGcccTTTaaa");
1101 SequenceI pep1 = new Sequence("pep1", "GF");
1102 dna1.createDatasetSequence();
1103 pep1.createDatasetSequence();
1104 pep1.getDatasetSequence().addDBRef(
1105 new DBRefEntry("EMBLCDS", "2", "A12345"));
1108 * Make the mapping from dna to protein. The protein sequence has a DBRef to
1111 Set<AlignedCodonFrame> mappings = new HashSet<AlignedCodonFrame>();
1112 MapList map = new MapList(new int[]
1113 { 4, 6, 10, 12 }, new int[]
1115 AlignedCodonFrame acf = new AlignedCodonFrame();
1116 acf.addMap(dna1.getDatasetSequence(), pep1.getDatasetSequence(), map);
1119 AlignedCodonFrame newMapping = new AlignedCodonFrame();
1120 List<SequenceI> exons = AlignmentUtils.makeExonSequences(dna1, acf,
1122 assertEquals(1, exons.size());
1123 SequenceI exon = exons.get(0);
1125 assertEquals("GGGTTT", exon.getSequenceAsString());
1126 assertEquals("dna1|A12345", exon.getName());
1127 assertEquals(1, exon.getDBRef().length);
1128 DBRefEntry cdsRef = exon.getDBRef()[0];
1129 assertEquals("EMBLCDS", cdsRef.getSource());
1130 assertEquals("2", cdsRef.getVersion());
1131 assertEquals("A12345", cdsRef.getAccessionId());
1135 * Test the method that makes an exon-only alignment from a DNA sequence and
1136 * its product mappings, for the case where there are multiple exon mappings
1137 * to different protein products.
1140 public void testMakeExonAlignment_multipleProteins()
1142 SequenceI dna1 = new Sequence("dna1", "aaaGGGcccTTTaaa");
1143 SequenceI pep1 = new Sequence("pep1", "GF"); // GGGTTT
1144 SequenceI pep2 = new Sequence("pep2", "KP"); // aaaccc
1145 SequenceI pep3 = new Sequence("pep3", "KF"); // aaaTTT
1146 dna1.createDatasetSequence();
1147 pep1.createDatasetSequence();
1148 pep2.createDatasetSequence();
1149 pep3.createDatasetSequence();
1150 pep1.getDatasetSequence().addDBRef(
1151 new DBRefEntry("EMBLCDS", "2", "A12345"));
1152 pep2.getDatasetSequence().addDBRef(
1153 new DBRefEntry("EMBLCDS", "3", "A12346"));
1154 pep3.getDatasetSequence().addDBRef(
1155 new DBRefEntry("EMBLCDS", "4", "A12347"));
1158 * Make the mappings from dna to protein. Using LinkedHashset is a
1159 * convenience so results are in the input order. There is no assertion that
1160 * the generated exon sequences are in any particular order.
1162 Set<AlignedCodonFrame> mappings = new LinkedHashSet<AlignedCodonFrame>();
1163 // map ...GGG...TTT to GF
1164 MapList map = new MapList(new int[]
1165 { 4, 6, 10, 12 }, new int[]
1167 AlignedCodonFrame acf = new AlignedCodonFrame();
1168 acf.addMap(dna1.getDatasetSequence(), pep1.getDatasetSequence(), map);
1171 // map aaa...ccc to KP
1172 map = new MapList(new int[]
1173 { 1, 3, 7, 9 }, new int[]
1175 acf = new AlignedCodonFrame();
1176 acf.addMap(dna1.getDatasetSequence(), pep2.getDatasetSequence(), map);
1179 // map aaa......TTT to KF
1180 map = new MapList(new int[]
1181 { 1, 3, 10, 12 }, new int[]
1183 acf = new AlignedCodonFrame();
1184 acf.addMap(dna1.getDatasetSequence(), pep3.getDatasetSequence(), map);
1188 * Create the Exon alignment; also replaces the dna-to-protein mappings with
1189 * exon-to-protein and exon-to-dna mappings
1191 AlignmentI exal = AlignmentUtils.makeExonAlignment(new SequenceI[]
1192 { dna1 }, mappings);
1195 * Verify we have 3 exon sequences, mapped to pep1/2/3 respectively
1197 List<SequenceI> exons = exal.getSequences();
1198 assertEquals(3, exons.size());
1200 SequenceI exon = exons.get(0);
1201 assertEquals("GGGTTT", exon.getSequenceAsString());
1202 assertEquals("dna1|A12345", exon.getName());
1203 assertEquals(1, exon.getDBRef().length);
1204 DBRefEntry cdsRef = exon.getDBRef()[0];
1205 assertEquals("EMBLCDS", cdsRef.getSource());
1206 assertEquals("2", cdsRef.getVersion());
1207 assertEquals("A12345", cdsRef.getAccessionId());
1209 exon = exons.get(1);
1210 assertEquals("aaaccc", exon.getSequenceAsString());
1211 assertEquals("dna1|A12346", exon.getName());
1212 assertEquals(1, exon.getDBRef().length);
1213 cdsRef = exon.getDBRef()[0];
1214 assertEquals("EMBLCDS", cdsRef.getSource());
1215 assertEquals("3", cdsRef.getVersion());
1216 assertEquals("A12346", cdsRef.getAccessionId());
1218 exon = exons.get(2);
1219 assertEquals("aaaTTT", exon.getSequenceAsString());
1220 assertEquals("dna1|A12347", exon.getName());
1221 assertEquals(1, exon.getDBRef().length);
1222 cdsRef = exon.getDBRef()[0];
1223 assertEquals("EMBLCDS", cdsRef.getSource());
1224 assertEquals("4", cdsRef.getVersion());
1225 assertEquals("A12347", cdsRef.getAccessionId());
1228 * Verify there are mappings from each exon sequence to its protein product
1229 * and also to its dna source
1231 Iterator<AlignedCodonFrame> newMappingsIterator = mappings.iterator();
1233 // mappings for dna1 - exon1 - pep1
1234 AlignedCodonFrame exonMapping = newMappingsIterator.next();
1235 List<Mapping> dnaMappings = exonMapping.getMappingsForSequence(dna1);
1236 assertEquals(1, dnaMappings.size());
1237 assertSame(exons.get(0).getDatasetSequence(), dnaMappings.get(0)
1239 assertEquals("G(1) in CDS should map to G(4) in DNA", 4, dnaMappings
1240 .get(0).getMap().getToPosition(1));
1241 List<Mapping> peptideMappings = exonMapping
1242 .getMappingsForSequence(pep1);
1243 assertEquals(1, peptideMappings.size());
1244 assertSame(pep1.getDatasetSequence(), peptideMappings.get(0).getTo());
1246 // mappings for dna1 - exon2 - pep2
1247 exonMapping = newMappingsIterator.next();
1248 dnaMappings = exonMapping.getMappingsForSequence(dna1);
1249 assertEquals(1, dnaMappings.size());
1250 assertSame(exons.get(1).getDatasetSequence(), dnaMappings.get(0)
1252 assertEquals("c(4) in CDS should map to c(7) in DNA", 7, dnaMappings
1253 .get(0).getMap().getToPosition(4));
1254 peptideMappings = exonMapping.getMappingsForSequence(pep2);
1255 assertEquals(1, peptideMappings.size());
1256 assertSame(pep2.getDatasetSequence(), peptideMappings.get(0).getTo());
1258 // mappings for dna1 - exon3 - pep3
1259 exonMapping = newMappingsIterator.next();
1260 dnaMappings = exonMapping.getMappingsForSequence(dna1);
1261 assertEquals(1, dnaMappings.size());
1262 assertSame(exons.get(2).getDatasetSequence(), dnaMappings.get(0)
1264 assertEquals("T(4) in CDS should map to T(10) in DNA", 10, dnaMappings
1265 .get(0).getMap().getToPosition(4));
1266 peptideMappings = exonMapping.getMappingsForSequence(pep3);
1267 assertEquals(1, peptideMappings.size());
1268 assertSame(pep3.getDatasetSequence(), peptideMappings.get(0).getTo());