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;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertNotSame;
27 import static org.testng.AssertJUnit.assertNull;
28 import static org.testng.AssertJUnit.assertSame;
29 import static org.testng.AssertJUnit.assertTrue;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
33 import jalview.datamodel.Alignment;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.DBRefEntry;
36 import jalview.datamodel.Mapping;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceFeature;
39 import jalview.datamodel.SequenceI;
40 import jalview.util.DBRefUtils;
41 import jalview.util.MapList;
42 import jalview.ws.SequenceFetcher;
43 import jalview.ws.SequenceFetcherFactory;
45 import java.util.ArrayList;
46 import java.util.List;
48 import org.testng.annotations.AfterClass;
49 import org.testng.annotations.Test;
51 public class CrossRefTest
53 @Test(groups = { "Functional" })
54 public void testFindXDbRefs()
56 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "A123");
57 DBRefEntry ref2 = new DBRefEntry("UNIPROTKB/TREMBL", "1", "A123");
58 DBRefEntry ref3 = new DBRefEntry("pdb", "1", "A123");
59 DBRefEntry ref4 = new DBRefEntry("EMBLCDSPROTEIN", "1", "A123");
60 DBRefEntry ref5 = new DBRefEntry("embl", "1", "A123");
61 DBRefEntry ref6 = new DBRefEntry("emblCDS", "1", "A123");
62 DBRefEntry ref7 = new DBRefEntry("GeneDB", "1", "A123");
63 DBRefEntry ref8 = new DBRefEntry("PFAM", "1", "A123");
64 // ENSEMBL is a source of either dna or protein sequence data
65 DBRefEntry ref9 = new DBRefEntry("ENSEMBL", "1", "A123");
66 DBRefEntry[] refs = new DBRefEntry[] { ref1, ref2, ref3, ref4, ref5,
67 ref6, ref7, ref8, ref9 };
72 DBRefEntry[] found = DBRefUtils.selectDbRefs(true, refs);
73 assertEquals(4, found.length);
74 assertSame(ref5, found[0]);
75 assertSame(ref6, found[1]);
76 assertSame(ref7, found[2]);
77 assertSame(ref9, found[3]);
80 * Just the protein refs:
82 found = DBRefUtils.selectDbRefs(false, refs);
83 assertEquals(4, found.length);
84 assertSame(ref1, found[0]);
85 assertSame(ref2, found[1]);
86 assertSame(ref4, found[2]);
87 assertSame(ref9, found[3]);
91 * Test the method that finds a sequence's "product" xref source databases,
92 * which may be direct (dbrefs on the sequence), or indirect (dbrefs on
93 * sequences which share a dbref with the sequence
95 @Test(groups = { "Functional" }, enabled = true)
96 public void testFindXrefSourcesForSequence_proteinToDna()
98 SequenceI seq = new Sequence("Seq1", "MGKYQARLSS");
99 List<String> sources = new ArrayList<String>();
100 AlignmentI al = new Alignment(new SequenceI[] {});
103 * first with no dbrefs to search
105 sources = new CrossRef(new SequenceI[] { seq }, al)
106 .findXrefSourcesForSequences(false);
107 assertTrue(sources.isEmpty());
110 * add some dbrefs to sequence
112 // protein db is not a candidate for findXrefSources
113 seq.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
114 // dna coding databatases are
115 seq.addDBRef(new DBRefEntry("EMBL", "0", "E2345"));
116 // a second EMBL xref should not result in a duplicate
117 seq.addDBRef(new DBRefEntry("EMBL", "0", "E2346"));
118 seq.addDBRef(new DBRefEntry("EMBLCDS", "0", "E2347"));
119 seq.addDBRef(new DBRefEntry("GENEDB", "0", "E2348"));
120 seq.addDBRef(new DBRefEntry("ENSEMBL", "0", "E2349"));
121 seq.addDBRef(new DBRefEntry("ENSEMBLGENOMES", "0", "E2350"));
122 sources = new CrossRef(new SequenceI[] { seq }, al)
123 .findXrefSourcesForSequences(false);
124 // method is patched to remove EMBL from the sources to match
125 assertEquals(3, sources.size());
126 assertEquals("[EMBLCDS, GENEDB, ENSEMBL]", sources.toString());
129 * add a sequence to the alignment which has a dbref to UNIPROT|A1234
130 * and others to dna coding databases
134 seq.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
135 seq.addDBRef(new DBRefEntry("EMBLCDS", "0", "E2347"));
136 SequenceI seq2 = new Sequence("Seq2", "MGKYQARLSS");
137 seq2.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
138 seq2.addDBRef(new DBRefEntry("EMBL", "0", "E2345"));
139 seq2.addDBRef(new DBRefEntry("GENEDB", "0", "E2348"));
140 // TODO include ENSEMBLGENOMES in DBRefSource.DNACODINGDBS ?
141 al.addSequence(seq2);
142 sources = new CrossRef(new SequenceI[] { seq, seq2 }, al)
143 .findXrefSourcesForSequences(false);
144 // method removed EMBL from sources to match
145 assertEquals(2, sources.size());
146 assertEquals("[EMBLCDS, GENEDB]", sources.toString());
150 * Test for finding 'product' sequences for the case where only an indirect
151 * xref is found - not on the nucleotide sequence but on a peptide sequence in
152 * the alignment which which it shares a nucleotide dbref
154 @Test(groups = { "Functional" }, enabled = true)
155 public void testFindXrefSequences_indirectDbrefToProtein()
159 * - nucleotide dbref EMBL|AF039662
160 * - peptide dbrefs EMBL|AF039662, UNIPROT|Q9ZTS2
162 SequenceI emblSeq = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
163 emblSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
164 SequenceI uniprotSeq = new Sequence("Q9ZTS2", "MASVSATMISTS");
165 uniprotSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
166 uniprotSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
169 * Find UNIPROT xrefs for nucleotide
170 * - it has no UNIPROT dbref of its own
171 * - but peptide with matching nucleotide dbref does, so is returned
173 AlignmentI al = new Alignment(new SequenceI[] { emblSeq, uniprotSeq });
174 Alignment xrefs = new CrossRef(new SequenceI[] { emblSeq }, al)
175 .findXrefSequences("UNIPROT", true);
176 assertEquals(1, xrefs.getHeight());
177 assertSame(uniprotSeq, xrefs.getSequenceAt(0));
181 * Test for finding 'product' sequences for the case where only an indirect
182 * xref is found - not on the peptide sequence but on a nucleotide sequence in
183 * the alignment which which it shares a protein dbref
185 @Test(groups = { "Functional" }, enabled = true)
186 public void testFindXrefSequences_indirectDbrefToNucleotide()
190 * - peptide dbref UNIPROT|Q9ZTS2
191 * - nucleotide dbref EMBL|AF039662, UNIPROT|Q9ZTS2
193 SequenceI uniprotSeq = new Sequence("Q9ZTS2", "MASVSATMISTS");
194 uniprotSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
195 SequenceI emblSeq = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
196 emblSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
197 emblSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
200 * find EMBL xrefs for peptide sequence - it has no direct
201 * dbrefs, but the 'corresponding' nucleotide sequence does, so is returned
204 * Find EMBL xrefs for peptide
205 * - it has no EMBL dbref of its own
206 * - but nucleotide with matching peptide dbref does, so is returned
208 AlignmentI al = new Alignment(new SequenceI[] { emblSeq, uniprotSeq });
209 Alignment xrefs = new CrossRef(new SequenceI[] { uniprotSeq }, al)
210 .findXrefSequences("EMBL", false);
211 assertEquals(1, xrefs.getHeight());
212 assertSame(emblSeq, xrefs.getSequenceAt(0));
216 * Test for finding 'product' sequences for the case where the selected
217 * sequence has no dbref to the desired source, and there are no indirect
218 * references via another sequence in the alignment
220 @Test(groups = { "Functional" })
221 public void testFindXrefSequences_noDbrefs()
224 * two nucleotide sequences, one with UNIPROT dbref
226 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
227 dna1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
228 SequenceI dna2 = new Sequence("AJ307031", "AAACCCTTT");
231 * find UNIPROT xrefs for peptide sequence - it has no direct
232 * dbrefs, and the other sequence (which has a UNIPROT dbref) is not
233 * equatable to it, so no results found
235 AlignmentI al = new Alignment(new SequenceI[] { dna1, dna2 });
236 Alignment xrefs = new CrossRef(new SequenceI[] { dna2 }, al)
237 .findXrefSequences("UNIPROT", true);
242 * Tests for the method that searches an alignment (with one sequence
243 * excluded) for protein/nucleotide sequences with a given cross-reference
245 @Test(groups = { "Functional" }, enabled = true)
246 public void testSearchDataset()
249 * nucleotide sequence with UNIPROT AND EMBL dbref
250 * peptide sequence with UNIPROT dbref
252 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
253 Mapping map = new Mapping(new Sequence("pep2", "MLAVSRG"), new MapList(
254 new int[] { 1, 21 }, new int[] {
256 DBRefEntry dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2", map);
257 dna1.addDBRef(dbref);
258 dna1.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
259 SequenceI pep1 = new Sequence("Q9ZTS2", "MLAVSRGQ");
260 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
261 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
262 AlignmentI al = new Alignment(new SequenceI[] { dna1, pep1 });
264 List<SequenceI> result = new ArrayList<SequenceI>();
267 * first search for a dbref nowhere on the alignment:
269 dbref = new DBRefEntry("UNIPROT", "0", "P30419");
270 CrossRef testee = new CrossRef(al.getSequencesArray(), al);
271 AlignedCodonFrame acf = new AlignedCodonFrame();
272 boolean found = testee.searchDataset(true, dna1, dbref, result, acf,
275 assertTrue(result.isEmpty());
276 assertTrue(acf.isEmpty());
279 * search for a protein sequence with dbref UNIPROT:Q9ZTS2
281 acf = new AlignedCodonFrame();
282 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
283 found = testee.searchDataset(!dna1.isProtein(), dna1, dbref, result,
284 acf, false); // search dataset with a protein xref from a dna
285 // sequence to locate the protein product
287 assertEquals(1, result.size());
288 assertSame(pep1, result.get(0));
289 assertTrue(acf.isEmpty());
292 * search for a nucleotide sequence with dbref UNIPROT:Q9ZTS2
295 acf = new AlignedCodonFrame();
296 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
297 found = testee.searchDataset(!pep1.isProtein(), pep1, dbref, result,
298 acf, false); // search dataset with a protein's direct dbref to
299 // locate dna sequences with matching xref
301 assertEquals(1, result.size());
302 assertSame(dna1, result.get(0));
303 // should now have a mapping from dna to pep1
304 List<SequenceToSequenceMapping> mappings = acf.getMappings();
305 assertEquals(1, mappings.size());
306 SequenceToSequenceMapping mapping = mappings.get(0);
307 assertSame(dna1, mapping.getFromSeq());
308 assertSame(pep1, mapping.getMapping().getTo());
309 MapList mapList = mapping.getMapping().getMap();
310 assertEquals(1, mapList.getToRatio());
311 assertEquals(3, mapList.getFromRatio());
312 assertEquals(1, mapList.getFromRanges().size());
313 assertEquals(1, mapList.getFromRanges().get(0)[0]);
314 assertEquals(21, mapList.getFromRanges().get(0)[1]);
315 assertEquals(1, mapList.getToRanges().size());
316 assertEquals(1, mapList.getToRanges().get(0)[0]);
317 assertEquals(7, mapList.getToRanges().get(0)[1]);
321 * Test for finding 'product' sequences for the case where the selected
322 * sequence has a dbref with a mapping to a sequence. This represents the case
325 * <li>a fetched sequence is already decorated with its cross-reference (e.g.
326 * EMBL + translation), or</li>
327 * <li>Get Cross-References has been done once resulting in instantiated
328 * cross-reference mappings</li>
331 @Test(groups = { "Functional" })
332 public void testFindXrefSequences_fromDbRefMap()
335 * scenario: nucleotide sequence AF039662
336 * with dbref + mapping to Q9ZTS2 and P30419
337 * which themselves each have a dbref and feature
339 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
340 SequenceI pep1 = new Sequence("Q9ZTS2", "MALFQRSV");
341 SequenceI pep2 = new Sequence("P30419", "MTRRSQIF");
342 dna1.createDatasetSequence();
343 pep1.createDatasetSequence();
344 pep2.createDatasetSequence();
346 pep1.getDatasetSequence().addDBRef(
347 new DBRefEntry("Pfam", "0", "PF00111"));
348 pep1.addSequenceFeature(new SequenceFeature("type", "desc", 12, 14, 1f,
350 pep2.getDatasetSequence().addDBRef(new DBRefEntry("PDB", "0", "3JTK"));
351 pep2.addSequenceFeature(new SequenceFeature("type2", "desc2", 13, 15,
354 MapList mapList = new MapList(new int[] { 1, 24 }, new int[] { 1, 3 },
356 Mapping map = new Mapping(pep1, mapList);
357 DBRefEntry dbRef1 = new DBRefEntry("UNIPROT", "0", "Q9ZTS2", map);
358 dna1.getDatasetSequence().addDBRef(dbRef1);
359 mapList = new MapList(new int[] { 1, 24 }, new int[] { 1, 3 }, 3, 1);
360 map = new Mapping(pep2, mapList);
361 DBRefEntry dbRef2 = new DBRefEntry("UNIPROT", "0", "P30419", map);
362 dna1.getDatasetSequence().addDBRef(dbRef2);
365 * find UNIPROT xrefs for nucleotide sequence - it should pick up
368 AlignmentI al = new Alignment(new SequenceI[] { dna1 });
369 Alignment xrefs = new CrossRef(new SequenceI[] { dna1 }, al)
370 .findXrefSequences("UNIPROT", true);
371 assertEquals(2, xrefs.getHeight());
374 * cross-refs alignment holds copies of the mapped sequences
375 * including copies of their dbrefs and features
377 checkCopySequence(pep1, xrefs.getSequenceAt(0));
378 checkCopySequence(pep2, xrefs.getSequenceAt(1));
382 * Helper method that verifies that 'copy' has the same name, start, end,
383 * sequence and dataset sequence object as 'original' (but is not the same
389 private void checkCopySequence(SequenceI copy, SequenceI original)
391 assertNotSame(copy, original);
392 assertSame(copy.getDatasetSequence(), original.getDatasetSequence());
393 assertEquals(copy.getName(), original.getName());
394 assertEquals(copy.getStart(), original.getStart());
395 assertEquals(copy.getEnd(), original.getEnd());
396 assertEquals(copy.getSequenceAsString(), original.getSequenceAsString());
400 * Test for finding 'product' sequences for the case where the selected
401 * sequence has a dbref with no mapping, triggering a fetch from database
403 @Test(groups = { "Functional" })
404 public void testFindXrefSequences_withFetch()
406 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
407 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "Q9ZTS2"));
408 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "P30419"));
409 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "P00314"));
410 final SequenceI pep1 = new Sequence("Q9ZTS2", "MYQLIRSSW");
411 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
413 final SequenceI pep2 = new Sequence("P00314", "MRKLLAASG");
414 pep2.addDBRef(new DBRefEntry("UNIPROT", "0", "P00314"));
417 * argument false suppresses adding DAS sources
418 * todo: define an interface type SequenceFetcherI and mock that
420 SequenceFetcher mockFetcher = new SequenceFetcher(false)
423 public boolean isFetchable(String source)
429 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
431 return new SequenceI[] { pep1, pep2 };
434 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
437 * find UNIPROT xrefs for nucleotide sequence
439 AlignmentI al = new Alignment(new SequenceI[] { dna1 });
440 Alignment xrefs = new CrossRef(new SequenceI[] { dna1 }, al)
441 .findXrefSequences("UNIPROT", true);
442 assertEquals(2, xrefs.getHeight());
443 assertSame(pep1, xrefs.getSequenceAt(0));
444 assertSame(pep2, xrefs.getSequenceAt(1));
448 public void tearDown()
450 SequenceFetcherFactory.setSequenceFetcher(null);
454 * Test for finding 'product' sequences for the case where both gene and
455 * transcript sequences have dbrefs to Uniprot.
457 @Test(groups = { "Functional" })
458 public void testFindXrefSequences_forGeneAndTranscripts()
463 SequenceI gene = new Sequence("ENSG00000157764", "CGCCTCCCTTCCCC");
464 gene.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
465 gene.addDBRef(new DBRefEntry("UNIPROT", "0", "H7C5K3"));
468 * 'transcript' with CDS feature (supports mapping to protein)
470 SequenceI braf001 = new Sequence("ENST00000288602", "taagATGGCGGCGCTGa");
471 braf001.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
472 braf001.addSequenceFeature(new SequenceFeature("CDS", "", 5, 16, 0f,
476 * 'spliced transcript' with CDS ranges
478 SequenceI braf002 = new Sequence("ENST00000497784", "gCAGGCtaTCTGTTCaa");
479 braf002.addDBRef(new DBRefEntry("UNIPROT", "ENSEMBL|0", "H7C5K3"));
480 braf002.addSequenceFeature(new SequenceFeature("CDS", "", 2, 6, 0f,
482 braf002.addSequenceFeature(new SequenceFeature("CDS", "", 9, 15, 0f,
486 * TODO code is fragile - use of SequenceIdMatcher depends on fetched
487 * sequences having a name starting Source|Accession
488 * which happens to be true for Uniprot,PDB,EMBL but not Pfam,Rfam,Ensembl
490 final SequenceI pep1 = new Sequence("UNIPROT|P15056", "MAAL");
491 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
492 final SequenceI pep2 = new Sequence("UNIPROT|H7C5K3", "QALF");
493 pep2.addDBRef(new DBRefEntry("UNIPROT", "0", "H7C5K3"));
495 * argument false suppresses adding DAS sources
496 * todo: define an interface type SequenceFetcherI and mock that
498 SequenceFetcher mockFetcher = new SequenceFetcher(false)
501 public boolean isFetchable(String source)
507 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
509 return new SequenceI[] { pep1, pep2 };
512 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
515 * find UNIPROT xrefs for gene and transcripts
517 * - the two proteins are retrieved but not duplicated
518 * - mappings are built from transcript (CDS) to proteins
519 * - no mappings from gene to proteins
521 SequenceI[] seqs = new SequenceI[] { gene, braf001, braf002 };
522 AlignmentI al = new Alignment(seqs);
523 Alignment xrefs = new CrossRef(seqs, al).findXrefSequences("UNIPROT",
525 assertEquals(2, xrefs.getHeight());
526 assertSame(pep1, xrefs.getSequenceAt(0));
527 assertSame(pep2, xrefs.getSequenceAt(1));
532 * Test that emulates this (real but simplified) case:
534 * UNIPROT|P0CE19 EMBL|J03321, EMBL|X06707, EMBL|M19487
535 * UNIPROT|P0CE20 EMBL|J03321, EMBL|X06707, EMBL|X07547
536 * Find cross-references for EMBL. These are mocked here as
537 * EMBL|J03321 with mappings to P0CE18, P0CE19, P0CE20
538 * EMBL|X06707 with mappings to P0CE17, P0CE19, P0CE20
539 * EMBL|M19487 with mappings to P0CE19, Q46432
540 * EMBL|X07547 with mappings to P0CE20, B0BCM4
541 * EMBL sequences are first 'fetched' (mocked here) for P0CE19.
542 * The 3 EMBL sequences are added to the alignment dataset.
543 * Their dbrefs to Uniprot products P0CE19 and P0CE20 should be matched in the
544 * alignment dataset and updated to reference the original Uniprot sequences.
545 * For the second Uniprot sequence, the J03321 and X06707 xrefs should be
546 * resolved from the dataset, and only the X07547 dbref fetched.
547 * So the end state to verify is:
548 * - 4 cross-ref sequences returned: J03321, X06707, M19487, X07547
549 * - P0CE19/20 dbrefs to EMBL sequences now have mappings
550 * - J03321 dbrefs to P0CE19/20 mapped to original Uniprot sequences
551 * - X06707 dbrefs to P0CE19/20 mapped to original Uniprot sequences
554 @Test(groups = { "Functional" })
555 public void testFindXrefSequences_uniprotEmblManyToMany()
558 * Uniprot sequences, both with xrefs to EMBL|J03321
561 SequenceI p0ce19 = new Sequence("UNIPROT|P0CE19", "KPFG");
562 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "J03321"));
563 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "X06707"));
564 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "M19487"));
565 SequenceI p0ce20 = new Sequence("UNIPROT|P0CE20", "PFGK");
566 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "J03321"));
567 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "X06707"));
568 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "X07547"));
571 * EMBL sequences to be 'fetched', complete with dbrefs and mappings
572 * to their protein products (CDS location and translations are provided
573 * in EMBL XML); these should be matched to, and replaced with,
574 * the corresponding uniprot sequences after fetching
578 * J03321 with mappings to P0CE19 and P0CE20
580 final SequenceI j03321 = new Sequence("EMBL|J03321", "AAACCCTTTGGGAAAA");
581 DBRefEntry dbref1 = new DBRefEntry("UNIPROT", "0", "P0CE19");
582 MapList mapList = new MapList(new int[] { 1, 12 }, new int[] { 1, 4 },
584 Mapping map = new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"),
586 // add a dbref to the mapped to sequence - should get copied to p0ce19
587 map.getTo().addDBRef(new DBRefEntry("PIR", "0", "S01875"));
589 j03321.addDBRef(dbref1);
590 DBRefEntry dbref2 = new DBRefEntry("UNIPROT", "0", "P0CE20");
591 mapList = new MapList(new int[] { 4, 15 }, new int[] { 2, 5 }, 3, 1);
592 dbref2.setMap(new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"),
593 new MapList(mapList)));
594 j03321.addDBRef(dbref2);
597 * X06707 with mappings to P0CE19 and P0CE20
599 final SequenceI x06707 = new Sequence("EMBL|X06707", "atgAAACCCTTTGGG");
600 DBRefEntry dbref3 = new DBRefEntry("UNIPROT", "0", "P0CE19");
601 MapList map2 = new MapList(new int[] { 4, 15 }, new int[] { 1, 4 }, 3,
603 dbref3.setMap(new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"), map2));
604 x06707.addDBRef(dbref3);
605 DBRefEntry dbref4 = new DBRefEntry("UNIPROT", "0", "P0CE20");
606 MapList map3 = new MapList(new int[] { 4, 15 }, new int[] { 1, 4 }, 3,
608 dbref4.setMap(new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"), map3));
609 x06707.addDBRef(dbref4);
612 * M19487 with mapping to P0CE19 and Q46432
614 final SequenceI m19487 = new Sequence("EMBL|M19487", "AAACCCTTTGGG");
615 DBRefEntry dbref5 = new DBRefEntry("UNIPROT", "0", "P0CE19");
616 dbref5.setMap(new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"),
617 new MapList(mapList)));
618 m19487.addDBRef(dbref5);
619 DBRefEntry dbref6 = new DBRefEntry("UNIPROT", "0", "Q46432");
620 dbref6.setMap(new Mapping(new Sequence("UNIPROT|Q46432", "KPFG"),
621 new MapList(mapList)));
622 m19487.addDBRef(dbref6);
625 * X07547 with mapping to P0CE20 and B0BCM4
627 final SequenceI x07547 = new Sequence("EMBL|X07547", "cccAAACCCTTTGGG");
628 DBRefEntry dbref7 = new DBRefEntry("UNIPROT", "0", "P0CE20");
629 dbref7.setMap(new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"),
631 x07547.addDBRef(dbref7);
632 DBRefEntry dbref8 = new DBRefEntry("UNIPROT", "0", "B0BCM4");
633 dbref8.setMap(new Mapping(new Sequence("UNIPROT|B0BCM4", "KPFG"),
635 x07547.addDBRef(dbref8);
638 * mock sequence fetcher to 'return' the EMBL sequences
639 * TODO: Mockito would allow .thenReturn().thenReturn() here,
640 * and also capture and verification of the parameters
641 * passed in calls to getSequences() - important to verify that
642 * duplicate sequence fetches are not requested
644 SequenceFetcher mockFetcher = new SequenceFetcher(false)
649 public boolean isFetchable(String source)
655 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
660 assertEquals("Expected 3 embl seqs in first fetch", 3,
662 return new SequenceI[] { j03321, x06707, m19487 };
666 assertEquals("Expected 1 embl seq in second fetch", 1,
668 return new SequenceI[] { x07547 };
672 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
675 * find EMBL xrefs for Uniprot seqs and verify that
676 * - the EMBL xref'd sequences are retrieved without duplicates
677 * - mappings are added to the Uniprot dbrefs
678 * - mappings in the EMBL-to-Uniprot dbrefs are updated to the
679 * alignment sequences
680 * - dbrefs on the EMBL sequences are added to the original dbrefs
682 SequenceI[] seqs = new SequenceI[] { p0ce19, p0ce20 };
683 AlignmentI al = new Alignment(seqs);
684 Alignment xrefs = new CrossRef(seqs, al).findXrefSequences("EMBL",
688 * verify retrieved sequences
690 assertNotNull(xrefs);
691 assertEquals(4, xrefs.getHeight());
692 assertSame(j03321, xrefs.getSequenceAt(0));
693 assertSame(x06707, xrefs.getSequenceAt(1));
694 assertSame(m19487, xrefs.getSequenceAt(2));
695 assertSame(x07547, xrefs.getSequenceAt(3));
698 * verify mappings added to Uniprot-to-EMBL dbrefs
700 Mapping mapping = p0ce19.getDBRefs()[0].getMap();
701 assertSame(j03321, mapping.getTo());
702 mapping = p0ce19.getDBRefs()[1].getMap();
703 assertSame(x06707, mapping.getTo());
704 mapping = p0ce20.getDBRefs()[0].getMap();
705 assertSame(j03321, mapping.getTo());
706 mapping = p0ce20.getDBRefs()[1].getMap();
707 assertSame(x06707, mapping.getTo());
710 * verify dbrefs on EMBL are mapped to alignment seqs
712 assertSame(p0ce19, j03321.getDBRefs()[0].getMap().getTo());
713 assertSame(p0ce20, j03321.getDBRefs()[1].getMap().getTo());
714 assertSame(p0ce19, x06707.getDBRefs()[0].getMap().getTo());
715 assertSame(p0ce20, x06707.getDBRefs()[1].getMap().getTo());
718 * verify new dbref on EMBL dbref mapping is copied to the
719 * original Uniprot sequence
721 assertEquals(4, p0ce19.getDBRefs().length);
722 assertEquals("PIR", p0ce19.getDBRefs()[3].getSource());
723 assertEquals("S01875", p0ce19.getDBRefs()[3].getAccessionId());
726 @Test(groups = "Functional")
727 public void testSameSequence()
729 assertTrue(CrossRef.sameSequence(null, null));
730 SequenceI seq1 = new Sequence("seq1", "ABCDEF");
731 assertFalse(CrossRef.sameSequence(seq1, null));
732 assertFalse(CrossRef.sameSequence(null, seq1));
733 assertTrue(CrossRef.sameSequence(seq1, new Sequence("seq2", "ABCDEF")));
734 assertTrue(CrossRef.sameSequence(seq1, new Sequence("seq2", "abcdef")));
736 .sameSequence(seq1, new Sequence("seq2", "ABCDE-F")));
737 assertFalse(CrossRef.sameSequence(seq1, new Sequence("seq2", "BCDEF")));