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.gui.JvOptionPane;
41 import jalview.util.DBRefUtils;
42 import jalview.util.MapList;
43 import jalview.ws.SequenceFetcher;
44 import jalview.ws.SequenceFetcherFactory;
45 import jalview.ws.params.InvalidArgumentException;
47 import java.util.ArrayList;
48 import java.util.Arrays;
49 import java.util.List;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.BeforeClass;
53 import org.testng.annotations.Test;
55 public class CrossRefTest
58 @BeforeClass(alwaysRun = true)
59 public void setUpJvOptionPane()
61 JvOptionPane.setInteractiveMode(false);
62 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
65 @Test(groups = { "Functional" })
66 public void testFindXDbRefs()
68 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "A123");
69 DBRefEntry ref2 = new DBRefEntry("UNIPROTKB/TREMBL", "1", "A123");
70 DBRefEntry ref3 = new DBRefEntry("pdb", "1", "A123");
71 DBRefEntry ref4 = new DBRefEntry("EMBLCDSPROTEIN", "1", "A123");
72 DBRefEntry ref5 = new DBRefEntry("embl", "1", "A123");
73 DBRefEntry ref6 = new DBRefEntry("emblCDS", "1", "A123");
74 DBRefEntry ref7 = new DBRefEntry("GeneDB", "1", "A123");
75 DBRefEntry ref8 = new DBRefEntry("PFAM", "1", "A123");
76 // ENSEMBL is a source of either dna or protein sequence data
77 DBRefEntry ref9 = new DBRefEntry("ENSEMBL", "1", "A123");
78 List<DBRefEntry> refs = Arrays
79 .asList(new DBRefEntry[]
80 { ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9 });
85 List<DBRefEntry> found = DBRefUtils.selectDbRefs(true, refs);
86 assertEquals(4, found.size());
87 assertSame(ref5, found.get(0));
88 assertSame(ref6, found.get(1));
89 assertSame(ref7, found.get(2));
90 assertSame(ref9, found.get(3));
93 * Just the protein refs:
95 found = DBRefUtils.selectDbRefs(false, refs);
96 assertEquals(4, found.size());
97 assertSame(ref1, found.get(0));
98 assertSame(ref2, found.get(1));
99 assertSame(ref4, found.get(2));
100 assertSame(ref9, found.get(3));
104 * Test the method that finds a sequence's "product" xref source databases,
105 * which may be direct (dbrefs on the sequence), or indirect (dbrefs on
106 * sequences which share a dbref with the sequence
108 @Test(groups = { "Functional" }, enabled = true)
109 public void testFindXrefSourcesForSequence_proteinToDna()
111 SequenceI seq = new Sequence("Seq1", "MGKYQARLSS");
112 List<String> sources = new ArrayList<>();
113 AlignmentI al = new Alignment(new SequenceI[] {});
116 * first with no dbrefs to search
118 sources = new CrossRef(new SequenceI[] { seq }, al)
119 .findXrefSourcesForSequences(false);
120 assertTrue(sources.isEmpty());
123 * add some dbrefs to sequence
125 // protein db is not a candidate for findXrefSources
126 seq.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
127 // dna coding databatases are
128 seq.addDBRef(new DBRefEntry("EMBL", "0", "E2345"));
129 // a second EMBL xref should not result in a duplicate
130 seq.addDBRef(new DBRefEntry("EMBL", "0", "E2346"));
131 seq.addDBRef(new DBRefEntry("EMBLCDS", "0", "E2347"));
132 seq.addDBRef(new DBRefEntry("GENEDB", "0", "E2348"));
133 seq.addDBRef(new DBRefEntry("ENSEMBL", "0", "E2349"));
134 seq.addDBRef(new DBRefEntry("ENSEMBLGENOMES", "0", "E2350"));
135 sources = new CrossRef(new SequenceI[] { seq }, al)
136 .findXrefSourcesForSequences(false);
137 // method is patched to remove EMBL from the sources to match
138 assertEquals(4, sources.size());
139 assertEquals("[EMBLCDS, GENEDB, ENSEMBL, ENSEMBLGENOMES]",
143 * add a sequence to the alignment which has a dbref to UNIPROT|A1234
144 * and others to dna coding databases
148 seq.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
149 seq.addDBRef(new DBRefEntry("EMBLCDS", "0", "E2347"));
150 SequenceI seq2 = new Sequence("Seq2", "MGKYQARLSS");
151 seq2.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
152 seq2.addDBRef(new DBRefEntry("EMBL", "0", "E2345"));
153 seq2.addDBRef(new DBRefEntry("GENEDB", "0", "E2348"));
154 // TODO include ENSEMBLGENOMES in DBRefSource.DNACODINGDBS ?
155 al.addSequence(seq2);
156 sources = new CrossRef(new SequenceI[] { seq, seq2 }, al)
157 .findXrefSourcesForSequences(false);
158 // method removed EMBL from sources to match
159 assertEquals(2, sources.size());
160 assertEquals("[EMBLCDS, GENEDB]", sources.toString());
164 * Test for finding 'product' sequences for the case where only an indirect
165 * xref is found - not on the nucleotide sequence but on a peptide sequence in
166 * the alignment which which it shares a nucleotide dbref
168 @Test(groups = { "Functional" }, enabled = true)
169 public void testFindXrefSequences_indirectDbrefToProtein()
173 * - nucleotide dbref EMBL|AF039662
174 * - peptide dbrefs EMBL|AF039662, UNIPROT|Q9ZTS2
176 SequenceI emblSeq = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
177 emblSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
178 SequenceI uniprotSeq = new Sequence("Q9ZTS2", "MASVSATMISTS");
179 uniprotSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
180 uniprotSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
183 * Find UNIPROT xrefs for nucleotide
184 * - it has no UNIPROT dbref of its own
185 * - but peptide with matching nucleotide dbref does, so is returned
187 AlignmentI al = new Alignment(new SequenceI[] { emblSeq, uniprotSeq });
188 Alignment xrefs = new CrossRef(new SequenceI[] { emblSeq }, al)
189 .findXrefSequences("UNIPROT", true);
190 assertEquals(1, xrefs.getHeight());
191 assertSame(uniprotSeq, xrefs.getSequenceAt(0));
195 * Test for finding 'product' sequences for the case where only an indirect
196 * xref is found - not on the peptide sequence but on a nucleotide sequence in
197 * the alignment which which it shares a protein dbref
199 @Test(groups = { "Functional" }, enabled = true)
200 public void testFindXrefSequences_indirectDbrefToNucleotide()
204 * - peptide dbref UNIPROT|Q9ZTS2
205 * - nucleotide dbref EMBL|AF039662, UNIPROT|Q9ZTS2
207 SequenceI uniprotSeq = new Sequence("Q9ZTS2", "MASVSATMISTS");
208 uniprotSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
209 SequenceI emblSeq = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
210 emblSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
211 emblSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
214 * find EMBL xrefs for peptide sequence - it has no direct
215 * dbrefs, but the 'corresponding' nucleotide sequence does, so is returned
218 * Find EMBL xrefs for peptide
219 * - it has no EMBL dbref of its own
220 * - but nucleotide with matching peptide dbref does, so is returned
222 AlignmentI al = new Alignment(new SequenceI[] { emblSeq, uniprotSeq });
223 Alignment xrefs = new CrossRef(new SequenceI[] { uniprotSeq }, al)
224 .findXrefSequences("EMBL", false);
225 assertEquals(1, xrefs.getHeight());
226 assertSame(emblSeq, xrefs.getSequenceAt(0));
230 * Test for finding 'product' sequences for the case where the selected
231 * sequence has no dbref to the desired source, and there are no indirect
232 * references via another sequence in the alignment
234 @Test(groups = { "Functional" })
235 public void testFindXrefSequences_noDbrefs()
238 * two nucleotide sequences, one with UNIPROT dbref
240 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
241 dna1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
242 SequenceI dna2 = new Sequence("AJ307031", "AAACCCTTT");
245 * find UNIPROT xrefs for peptide sequence - it has no direct
246 * dbrefs, and the other sequence (which has a UNIPROT dbref) is not
247 * equatable to it, so no results found
249 AlignmentI al = new Alignment(new SequenceI[] { dna1, dna2 });
250 Alignment xrefs = new CrossRef(new SequenceI[] { dna2 }, al)
251 .findXrefSequences("UNIPROT", true);
256 * Tests for the method that searches an alignment (with one sequence
257 * excluded) for protein/nucleotide sequences with a given cross-reference
259 @Test(groups = { "Functional" }, enabled = true)
260 public void testSearchDataset()
263 * nucleotide sequence with UNIPROT AND EMBL dbref
264 * peptide sequence with UNIPROT dbref
266 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
267 Mapping map = new Mapping(new Sequence("pep2", "MLAVSRG"),
268 new MapList(new int[]
269 { 1, 21 }, new int[] { 1, 7 }, 3, 1));
270 DBRefEntry dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2", map);
271 dna1.addDBRef(dbref);
272 dna1.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
273 SequenceI pep1 = new Sequence("Q9ZTS2", "MLAVSRGQ");
274 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
275 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
276 AlignmentI al = new Alignment(new SequenceI[] { dna1, pep1 });
278 List<SequenceI> result = new ArrayList<>();
281 * first search for a dbref nowhere on the alignment:
283 dbref = new DBRefEntry("UNIPROT", "0", "P30419");
284 CrossRef testee = new CrossRef(al.getSequencesArray(), al);
285 AlignedCodonFrame acf = new AlignedCodonFrame();
286 boolean found = testee.searchDataset(true, dna1, dbref, result, acf,
287 true, DBRefUtils.SEARCH_MODE_FULL);
289 assertTrue(result.isEmpty());
290 assertTrue(acf.isEmpty());
293 * search for a protein sequence with dbref UNIPROT:Q9ZTS2
295 acf = new AlignedCodonFrame();
296 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
297 found = testee.searchDataset(!dna1.isProtein(), dna1, dbref, result,
298 acf, false, DBRefUtils.SEARCH_MODE_FULL); // search dataset with a
299 // protein xref from a dna
300 // sequence to locate the protein product
302 assertEquals(1, result.size());
303 assertSame(pep1, result.get(0));
304 assertTrue(acf.isEmpty());
307 * search for a nucleotide sequence with dbref UNIPROT:Q9ZTS2
310 acf = new AlignedCodonFrame();
311 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
312 found = testee.searchDataset(!pep1.isProtein(), pep1, dbref, result,
313 acf, false, DBRefUtils.SEARCH_MODE_FULL); // search dataset with a
314 // protein's direct dbref
316 // locate dna sequences with matching xref
318 assertEquals(1, result.size());
319 assertSame(dna1, result.get(0));
320 // should now have a mapping from dna to pep1
321 List<SequenceToSequenceMapping> mappings = acf.getMappings();
322 assertEquals(1, mappings.size());
323 SequenceToSequenceMapping mapping = mappings.get(0);
324 assertSame(dna1, mapping.getFromSeq());
325 assertSame(pep1, mapping.getMapping().getTo());
326 MapList mapList = mapping.getMapping().getMap();
327 assertEquals(1, mapList.getToRatio());
328 assertEquals(3, mapList.getFromRatio());
329 assertEquals(1, mapList.getFromRanges().size());
330 assertEquals(1, mapList.getFromRanges().get(0)[0]);
331 assertEquals(21, mapList.getFromRanges().get(0)[1]);
332 assertEquals(1, mapList.getToRanges().size());
333 assertEquals(1, mapList.getToRanges().get(0)[0]);
334 assertEquals(7, mapList.getToRanges().get(0)[1]);
338 * Test for finding 'product' sequences for the case where the selected
339 * sequence has a dbref with a mapping to a sequence. This represents the case
342 * <li>a fetched sequence is already decorated with its cross-reference (e.g.
343 * EMBL + translation), or</li>
344 * <li>Get Cross-References has been done once resulting in instantiated
345 * cross-reference mappings</li>
348 @Test(groups = { "Functional" })
349 public void testFindXrefSequences_fromDbRefMap()
352 * scenario: nucleotide sequence AF039662
353 * with dbref + mapping to Q9ZTS2 and P30419
354 * which themselves each have a dbref and feature
356 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
357 SequenceI pep1 = new Sequence("Q9ZTS2", "MALFQRSV");
358 SequenceI pep2 = new Sequence("P30419", "MTRRSQIF");
359 dna1.createDatasetSequence();
360 pep1.createDatasetSequence();
361 pep2.createDatasetSequence();
363 pep1.getDatasetSequence()
364 .addDBRef(new DBRefEntry("Pfam", "0", "PF00111"));
365 pep1.addSequenceFeature(
366 new SequenceFeature("type", "desc", 12, 14, 1f, "group"));
367 pep2.getDatasetSequence().addDBRef(new DBRefEntry("PDB", "0", "3JTK"));
368 pep2.addSequenceFeature(
369 new SequenceFeature("type2", "desc2", 13, 15, 12f, "group2"));
371 MapList mapList = new MapList(new int[] { 1, 24 }, new int[] { 1, 3 },
373 Mapping map = new Mapping(pep1, mapList);
374 DBRefEntry dbRef1 = new DBRefEntry("UNIPROT", "0", "Q9ZTS2", map);
375 dna1.getDatasetSequence().addDBRef(dbRef1);
376 mapList = new MapList(new int[] { 1, 24 }, new int[] { 1, 3 }, 3, 1);
377 map = new Mapping(pep2, mapList);
378 DBRefEntry dbRef2 = new DBRefEntry("UNIPROT", "0", "P30419", map);
379 dna1.getDatasetSequence().addDBRef(dbRef2);
382 * find UNIPROT xrefs for nucleotide sequence - it should pick up
385 AlignmentI al = new Alignment(new SequenceI[] { dna1 });
386 Alignment xrefs = new CrossRef(new SequenceI[] { dna1 }, al)
387 .findXrefSequences("UNIPROT", true);
388 assertEquals(2, xrefs.getHeight());
391 * cross-refs alignment holds copies of the mapped sequences
392 * including copies of their dbrefs and features
394 checkCopySequence(pep1, xrefs.getSequenceAt(0));
395 checkCopySequence(pep2, xrefs.getSequenceAt(1));
399 * Helper method that verifies that 'copy' has the same name, start, end,
400 * sequence and dataset sequence object as 'original' (but is not the same
406 private void checkCopySequence(SequenceI copy, SequenceI original)
408 assertNotSame(copy, original);
409 assertSame(copy.getDatasetSequence(), original.getDatasetSequence());
410 assertEquals(copy.getName(), original.getName());
411 assertEquals(copy.getStart(), original.getStart());
412 assertEquals(copy.getEnd(), original.getEnd());
413 assertEquals(copy.getSequenceAsString(),
414 original.getSequenceAsString());
418 * Test for finding 'product' sequences for the case where the selected
419 * sequence has a dbref with no mapping, triggering a fetch from database
421 @Test(groups = { "Functional_Failing" })
422 public void testFindXrefSequences_withFetch()
424 // JBPNote: this fails because pep1 and pep2 do not have DbRefEntrys with
426 // Fix#1 would be to revise the test data so it fits with 2.11.2+ Jalview
428 // that ENA retrievals yield dbrefs with Mappings
430 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
431 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "Q9ZTS2"));
432 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "P30419"));
433 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "P00314"));
434 final SequenceI pep1 = new Sequence("Q9ZTS2", "MYQLIRSSW");
435 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2", null, true));
437 final SequenceI pep2 = new Sequence("P00314", "MRKLLAASG");
438 pep2.addDBRef(new DBRefEntry("UNIPROT", "0", "P00314", null, true));
441 * argument false suppresses adding DAS sources
442 * todo: define an interface type SequenceFetcherI and mock that
444 SequenceFetcher mockFetcher = new SequenceFetcher()
447 public boolean isFetchable(String source)
453 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
455 return new SequenceI[] { pep1, pep2 };
458 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
461 * find UNIPROT xrefs for nucleotide sequence
463 AlignmentI al = new Alignment(new SequenceI[] { dna1 });
464 Alignment xrefs = new CrossRef(new SequenceI[] { dna1 }, al)
465 .findXrefSequences("UNIPROT", true);
466 assertEquals(2, xrefs.getHeight());
467 assertSame(pep1, xrefs.getSequenceAt(0));
468 assertSame(pep2, xrefs.getSequenceAt(1));
471 @AfterClass(alwaysRun = true)
472 public void tearDown()
474 SequenceFetcherFactory.setSequenceFetcher(null);
478 * Test for finding 'product' sequences for the case where both gene and
479 * transcript sequences have dbrefs to Uniprot.
481 @Test(groups = { "Functional_Failing" })
482 public void testFindXrefSequences_forGeneAndTranscripts()
487 SequenceI gene = new Sequence("ENSG00000157764", "CGCCTCCCTTCCCC");
488 gene.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
489 gene.addDBRef(new DBRefEntry("UNIPROT", "0", "H7C5K3"));
492 * 'transcript' with CDS feature (supports mapping to protein)
494 SequenceI braf001 = new Sequence("ENST00000288602",
495 "taagATGGCGGCGCTGa");
496 braf001.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
497 braf001.addSequenceFeature(
498 new SequenceFeature("CDS", "", 5, 16, 0f, null));
501 * 'spliced transcript' with CDS ranges
503 SequenceI braf002 = new Sequence("ENST00000497784",
504 "gCAGGCtaTCTGTTCaa");
505 braf002.addDBRef(new DBRefEntry("UNIPROT", "ENSEMBL|0", "H7C5K3"));
506 braf002.addSequenceFeature(
507 new SequenceFeature("CDS", "", 2, 6, 0f, null));
508 braf002.addSequenceFeature(
509 new SequenceFeature("CDS", "", 9, 15, 0f, null));
512 * TODO code is fragile - use of SequenceIdMatcher depends on fetched
513 * sequences having a name starting Source|Accession
514 * which happens to be true for Uniprot,PDB,EMBL but not Pfam,Rfam,Ensembl
516 final SequenceI pep1 = new Sequence("UNIPROT|P15056", "MAAL");
517 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
518 final SequenceI pep2 = new Sequence("UNIPROT|H7C5K3", "QALF");
519 pep2.addDBRef(new DBRefEntry("UNIPROT", "0", "H7C5K3"));
521 * argument false suppresses adding DAS sources
522 * todo: define an interface type SequenceFetcherI and mock that
524 SequenceFetcher mockFetcher = new SequenceFetcher()
527 public boolean isFetchable(String source)
533 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
535 return new SequenceI[] { pep1, pep2 };
538 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
541 * find UNIPROT xrefs for gene and transcripts
543 * - the two proteins are retrieved but not duplicated
544 * - mappings are built from transcript (CDS) to proteins
545 * - no mappings from gene to proteins
547 SequenceI[] seqs = new SequenceI[] { gene, braf001, braf002 };
548 AlignmentI al = new Alignment(seqs);
549 Alignment xrefs = new CrossRef(seqs, al).findXrefSequences("UNIPROT",
551 assertEquals(2, xrefs.getHeight());
552 assertSame(pep1, xrefs.getSequenceAt(0));
553 assertSame(pep2, xrefs.getSequenceAt(1));
558 * Test that emulates this (real but simplified) case:
560 * UNIPROT|P0CE19 EMBL|J03321, EMBL|X06707, EMBL|M19487
561 * UNIPROT|P0CE20 EMBL|J03321, EMBL|X06707, EMBL|X07547
562 * Find cross-references for EMBL. These are mocked here as
563 * EMBL|J03321 with mappings to P0CE18, P0CE19, P0CE20
564 * EMBL|X06707 with mappings to P0CE17, P0CE19, P0CE20
565 * EMBL|M19487 with mappings to P0CE19, Q46432
566 * EMBL|X07547 with mappings to P0CE20, B0BCM4
567 * EMBL sequences are first 'fetched' (mocked here) for P0CE19.
568 * The 3 EMBL sequences are added to the alignment dataset.
569 * Their dbrefs to Uniprot products P0CE19 and P0CE20 should be matched in the
570 * alignment dataset and updated to reference the original Uniprot sequences.
571 * For the second Uniprot sequence, the J03321 and X06707 xrefs should be
572 * resolved from the dataset, and only the X07547 dbref fetched.
573 * So the end state to verify is:
574 * - 4 cross-ref sequences returned: J03321, X06707, M19487, X07547
575 * - P0CE19/20 dbrefs to EMBL sequences now have mappings
576 * - J03321 dbrefs to P0CE19/20 mapped to original Uniprot sequences
577 * - X06707 dbrefs to P0CE19/20 mapped to original Uniprot sequences
580 @Test(groups = { "Functional_Failing" })
581 public void testFindXrefSequences_uniprotEmblManyToMany()
584 * Uniprot sequences, both with xrefs to EMBL|J03321
587 SequenceI p0ce19 = new Sequence("UNIPROT|P0CE19", "KPFG");
588 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "J03321"));
589 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "X06707"));
590 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "M19487"));
591 SequenceI p0ce20 = new Sequence("UNIPROT|P0CE20", "PFGK");
592 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "J03321"));
593 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "X06707"));
594 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "X07547"));
597 * EMBL sequences to be 'fetched', complete with dbrefs and mappings
598 * to their protein products (CDS location and translations are provided
599 * in EMBL XML); these should be matched to, and replaced with,
600 * the corresponding uniprot sequences after fetching
604 * J03321 with mappings to P0CE19 and P0CE20
606 final SequenceI j03321 = new Sequence("EMBL|J03321",
608 DBRefEntry dbref1 = new DBRefEntry("UNIPROT", "0", "P0CE19");
609 MapList mapList = new MapList(new int[] { 1, 12 }, new int[] { 1, 4 },
611 Mapping map = new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"),
613 // add a dbref to the mapped to sequence - should get copied to p0ce19
614 map.getTo().addDBRef(new DBRefEntry("PIR", "0", "S01875"));
616 j03321.addDBRef(dbref1);
617 DBRefEntry dbref2 = new DBRefEntry("UNIPROT", "0", "P0CE20");
618 mapList = new MapList(new int[] { 4, 15 }, new int[] { 2, 5 }, 3, 1);
619 dbref2.setMap(new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"),
620 new MapList(mapList)));
621 j03321.addDBRef(dbref2);
624 * X06707 with mappings to P0CE19 and P0CE20
626 final SequenceI x06707 = new Sequence("EMBL|X06707", "atgAAACCCTTTGGG");
627 DBRefEntry dbref3 = new DBRefEntry("UNIPROT", "0", "P0CE19");
628 MapList map2 = new MapList(new int[] { 4, 15 }, new int[] { 1, 4 }, 3,
631 new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"), map2));
632 x06707.addDBRef(dbref3);
633 DBRefEntry dbref4 = new DBRefEntry("UNIPROT", "0", "P0CE20");
634 MapList map3 = new MapList(new int[] { 4, 15 }, new int[] { 1, 4 }, 3,
637 new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"), map3));
638 x06707.addDBRef(dbref4);
641 * M19487 with mapping to P0CE19 and Q46432
643 final SequenceI m19487 = new Sequence("EMBL|M19487", "AAACCCTTTGGG");
644 DBRefEntry dbref5 = new DBRefEntry("UNIPROT", "0", "P0CE19");
645 dbref5.setMap(new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"),
646 new MapList(mapList)));
647 m19487.addDBRef(dbref5);
648 DBRefEntry dbref6 = new DBRefEntry("UNIPROT", "0", "Q46432");
649 dbref6.setMap(new Mapping(new Sequence("UNIPROT|Q46432", "KPFG"),
650 new MapList(mapList)));
651 m19487.addDBRef(dbref6);
654 * X07547 with mapping to P0CE20 and B0BCM4
656 final SequenceI x07547 = new Sequence("EMBL|X07547", "cccAAACCCTTTGGG");
657 DBRefEntry dbref7 = new DBRefEntry("UNIPROT", "0", "P0CE20");
658 dbref7.setMap(new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"),
660 x07547.addDBRef(dbref7);
661 DBRefEntry dbref8 = new DBRefEntry("UNIPROT", "0", "B0BCM4");
662 dbref8.setMap(new Mapping(new Sequence("UNIPROT|B0BCM4", "KPFG"),
664 x07547.addDBRef(dbref8);
667 * mock sequence fetcher to 'return' the EMBL sequences
668 * TODO: Mockito would allow .thenReturn().thenReturn() here,
669 * and also capture and verification of the parameters
670 * passed in calls to getSequences() - important to verify that
671 * duplicate sequence fetches are not requested
673 SequenceFetcher mockFetcher = new SequenceFetcher()
678 public boolean isFetchable(String source)
684 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
689 assertEquals("Expected 3 embl seqs in first fetch", 3,
691 return new SequenceI[] { j03321, x06707, m19487 };
695 assertEquals("Expected 1 embl seq in second fetch", 1,
697 return new SequenceI[] { x07547 };
701 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
704 * find EMBL xrefs for Uniprot seqs and verify that
705 * - the EMBL xref'd sequences are retrieved without duplicates
706 * - mappings are added to the Uniprot dbrefs
707 * - mappings in the EMBL-to-Uniprot dbrefs are updated to the
708 * alignment sequences
709 * - dbrefs on the EMBL sequences are added to the original dbrefs
711 SequenceI[] seqs = new SequenceI[] { p0ce19, p0ce20 };
712 AlignmentI al = new Alignment(seqs);
713 Alignment xrefs = new CrossRef(seqs, al).findXrefSequences("EMBL",
717 * verify retrieved sequences
719 assertNotNull(xrefs);
720 assertEquals(4, xrefs.getHeight());
721 assertSame(j03321, xrefs.getSequenceAt(0));
722 assertSame(x06707, xrefs.getSequenceAt(1));
723 assertSame(m19487, xrefs.getSequenceAt(2));
724 assertSame(x07547, xrefs.getSequenceAt(3));
727 * verify mappings added to Uniprot-to-EMBL dbrefs
729 Mapping mapping = p0ce19.getDBRefs().get(0).getMap();
730 assertSame(j03321, mapping.getTo());
731 mapping = p0ce19.getDBRefs().get(1).getMap();
732 assertSame(x06707, mapping.getTo());
733 mapping = p0ce20.getDBRefs().get(0).getMap();
734 assertSame(j03321, mapping.getTo());
735 mapping = p0ce20.getDBRefs().get(1).getMap();
736 assertSame(x06707, mapping.getTo());
739 * verify dbrefs on EMBL are mapped to alignment seqs
742 assertSame(p0ce19, j03321.getDBRefs().get(0).getMap().getTo());
743 assertSame(p0ce20, j03321.getDBRefs().get(1).getMap().getTo());
744 assertSame(p0ce19, x06707.getDBRefs().get(0).getMap().getTo());
745 assertSame(p0ce20, x06707.getDBRefs().get(1).getMap().getTo());
748 * verify new dbref on EMBL dbref mapping is copied to the
749 * original Uniprot sequence
751 assertEquals(4, p0ce19.getDBRefs().size());
752 assertEquals("PIR", p0ce19.getDBRefs().get(3).getSource());
753 assertEquals("S01875", p0ce19.getDBRefs().get(3).getAccessionId());
756 @Test(groups = "Functional")
757 public void testSameSequence()
759 assertTrue(CrossRef.sameSequence(null, null));
760 SequenceI seq1 = new Sequence("seq1", "ABCDEF");
761 assertFalse(CrossRef.sameSequence(seq1, null));
762 assertFalse(CrossRef.sameSequence(null, seq1));
763 assertTrue(CrossRef.sameSequence(seq1, new Sequence("seq2", "ABCDEF")));
764 assertTrue(CrossRef.sameSequence(seq1, new Sequence("seq2", "abcdef")));
766 CrossRef.sameSequence(seq1, new Sequence("seq2", "ABCDE-F")));
767 assertFalse(CrossRef.sameSequence(seq1, new Sequence("seq2", "BCDEF")));