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.asList(new DBRefEntry[] { ref1, ref2, ref3, ref4, ref5,
79 ref6, ref7, ref8, ref9 });
84 List<DBRefEntry> found = DBRefUtils.selectDbRefs(true, refs);
85 assertEquals(4, found.size());
86 assertSame(ref5, found.get(0));
87 assertSame(ref6, found.get(1));
88 assertSame(ref7, found.get(2));
89 assertSame(ref9, found.get(3));
92 * Just the protein refs:
94 found = DBRefUtils.selectDbRefs(false, refs);
95 assertEquals(4, found.size());
96 assertSame(ref1, found.get(0));
97 assertSame(ref2, found.get(1));
98 assertSame(ref4, found.get(2));
99 assertSame(ref9, found.get(3));
103 * Test the method that finds a sequence's "product" xref source databases,
104 * which may be direct (dbrefs on the sequence), or indirect (dbrefs on
105 * sequences which share a dbref with the sequence
107 @Test(groups = { "Functional" }, enabled = true)
108 public void testFindXrefSourcesForSequence_proteinToDna()
110 SequenceI seq = new Sequence("Seq1", "MGKYQARLSS");
111 List<String> sources = new ArrayList<>();
112 AlignmentI al = new Alignment(new SequenceI[] {});
115 * first with no dbrefs to search
117 sources = new CrossRef(new SequenceI[] { seq }, al)
118 .findXrefSourcesForSequences(false);
119 assertTrue(sources.isEmpty());
122 * add some dbrefs to sequence
124 // protein db is not a candidate for findXrefSources
125 seq.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
126 // dna coding databatases are
127 seq.addDBRef(new DBRefEntry("EMBL", "0", "E2345"));
128 // a second EMBL xref should not result in a duplicate
129 seq.addDBRef(new DBRefEntry("EMBL", "0", "E2346"));
130 seq.addDBRef(new DBRefEntry("EMBLCDS", "0", "E2347"));
131 seq.addDBRef(new DBRefEntry("GENEDB", "0", "E2348"));
132 seq.addDBRef(new DBRefEntry("ENSEMBL", "0", "E2349"));
133 seq.addDBRef(new DBRefEntry("ENSEMBLGENOMES", "0", "E2350"));
134 sources = new CrossRef(new SequenceI[] { seq }, al)
135 .findXrefSourcesForSequences(false);
136 // method is patched to remove EMBL from the sources to match
137 assertEquals(4, sources.size());
138 assertEquals("[EMBLCDS, GENEDB, ENSEMBL, ENSEMBLGENOMES]",
142 * add a sequence to the alignment which has a dbref to UNIPROT|A1234
143 * and others to dna coding databases
148 } catch (InvalidArgumentException e) {
149 // TODO Auto-generated catch block
152 seq.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
153 seq.addDBRef(new DBRefEntry("EMBLCDS", "0", "E2347"));
154 SequenceI seq2 = new Sequence("Seq2", "MGKYQARLSS");
155 seq2.addDBRef(new DBRefEntry("UNIPROT", "0", "A1234"));
156 seq2.addDBRef(new DBRefEntry("EMBL", "0", "E2345"));
157 seq2.addDBRef(new DBRefEntry("GENEDB", "0", "E2348"));
158 // TODO include ENSEMBLGENOMES in DBRefSource.DNACODINGDBS ?
159 al.addSequence(seq2);
160 sources = new CrossRef(new SequenceI[] { seq, seq2 }, al)
161 .findXrefSourcesForSequences(false);
162 // method removed EMBL from sources to match
163 assertEquals(2, sources.size());
164 assertEquals("[EMBLCDS, GENEDB]", sources.toString());
168 * Test for finding 'product' sequences for the case where only an indirect
169 * xref is found - not on the nucleotide sequence but on a peptide sequence in
170 * the alignment which which it shares a nucleotide dbref
172 @Test(groups = { "Functional" }, enabled = true)
173 public void testFindXrefSequences_indirectDbrefToProtein()
177 * - nucleotide dbref EMBL|AF039662
178 * - peptide dbrefs EMBL|AF039662, UNIPROT|Q9ZTS2
180 SequenceI emblSeq = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
181 emblSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
182 SequenceI uniprotSeq = new Sequence("Q9ZTS2", "MASVSATMISTS");
183 uniprotSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
184 uniprotSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
187 * Find UNIPROT xrefs for nucleotide
188 * - it has no UNIPROT dbref of its own
189 * - but peptide with matching nucleotide dbref does, so is returned
191 AlignmentI al = new Alignment(new SequenceI[] { emblSeq, uniprotSeq });
192 Alignment xrefs = new CrossRef(new SequenceI[] { emblSeq }, al)
193 .findXrefSequences("UNIPROT", true);
194 assertEquals(1, xrefs.getHeight());
195 assertSame(uniprotSeq, xrefs.getSequenceAt(0));
199 * Test for finding 'product' sequences for the case where only an indirect
200 * xref is found - not on the peptide sequence but on a nucleotide sequence in
201 * the alignment which which it shares a protein dbref
203 @Test(groups = { "Functional" }, enabled = true)
204 public void testFindXrefSequences_indirectDbrefToNucleotide()
208 * - peptide dbref UNIPROT|Q9ZTS2
209 * - nucleotide dbref EMBL|AF039662, UNIPROT|Q9ZTS2
211 SequenceI uniprotSeq = new Sequence("Q9ZTS2", "MASVSATMISTS");
212 uniprotSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
213 SequenceI emblSeq = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
214 emblSeq.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
215 emblSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
218 * find EMBL xrefs for peptide sequence - it has no direct
219 * dbrefs, but the 'corresponding' nucleotide sequence does, so is returned
222 * Find EMBL xrefs for peptide
223 * - it has no EMBL dbref of its own
224 * - but nucleotide with matching peptide dbref does, so is returned
226 AlignmentI al = new Alignment(new SequenceI[] { emblSeq, uniprotSeq });
227 Alignment xrefs = new CrossRef(new SequenceI[] { uniprotSeq }, al)
228 .findXrefSequences("EMBL", false);
229 assertEquals(1, xrefs.getHeight());
230 assertSame(emblSeq, xrefs.getSequenceAt(0));
234 * Test for finding 'product' sequences for the case where the selected
235 * sequence has no dbref to the desired source, and there are no indirect
236 * references via another sequence in the alignment
238 @Test(groups = { "Functional" })
239 public void testFindXrefSequences_noDbrefs()
242 * two nucleotide sequences, one with UNIPROT dbref
244 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
245 dna1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
246 SequenceI dna2 = new Sequence("AJ307031", "AAACCCTTT");
249 * find UNIPROT xrefs for peptide sequence - it has no direct
250 * dbrefs, and the other sequence (which has a UNIPROT dbref) is not
251 * equatable to it, so no results found
253 AlignmentI al = new Alignment(new SequenceI[] { dna1, dna2 });
254 Alignment xrefs = new CrossRef(new SequenceI[] { dna2 }, al)
255 .findXrefSequences("UNIPROT", true);
260 * Tests for the method that searches an alignment (with one sequence
261 * excluded) for protein/nucleotide sequences with a given cross-reference
263 @Test(groups = { "Functional" }, enabled = true)
264 public void testSearchDataset()
267 * nucleotide sequence with UNIPROT AND EMBL dbref
268 * peptide sequence with UNIPROT dbref
270 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
271 Mapping map = new Mapping(new Sequence("pep2", "MLAVSRG"), new MapList(
272 new int[] { 1, 21 }, new int[] { 1, 7 }, 3, 1));
273 DBRefEntry dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2", map);
274 dna1.addDBRef(dbref);
275 dna1.addDBRef(new DBRefEntry("EMBL", "0", "AF039662"));
276 SequenceI pep1 = new Sequence("Q9ZTS2", "MLAVSRGQ");
277 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
278 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
279 AlignmentI al = new Alignment(new SequenceI[] { dna1, pep1 });
281 List<SequenceI> result = new ArrayList<>();
284 * first search for a dbref nowhere on the alignment:
286 dbref = new DBRefEntry("UNIPROT", "0", "P30419");
287 CrossRef testee = new CrossRef(al.getSequencesArray(), al);
288 AlignedCodonFrame acf = new AlignedCodonFrame();
289 boolean found = testee.searchDataset(true, dna1, dbref, result, acf,
290 true, DBRefUtils.SEARCH_MODE_FULL);
292 assertTrue(result.isEmpty());
293 assertTrue(acf.isEmpty());
296 * search for a protein sequence with dbref UNIPROT:Q9ZTS2
298 acf = new AlignedCodonFrame();
299 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
300 found = testee.searchDataset(!dna1.isProtein(), dna1, dbref, result,
301 acf, false, DBRefUtils.SEARCH_MODE_FULL); // search dataset with a protein xref from a dna
302 // sequence to locate the protein product
304 assertEquals(1, result.size());
305 assertSame(pep1, result.get(0));
306 assertTrue(acf.isEmpty());
309 * search for a nucleotide sequence with dbref UNIPROT:Q9ZTS2
312 acf = new AlignedCodonFrame();
313 dbref = new DBRefEntry("UNIPROT", "0", "Q9ZTS2");
314 found = testee.searchDataset(!pep1.isProtein(), pep1, dbref, result,
315 acf, false, DBRefUtils.SEARCH_MODE_FULL); // search dataset with a protein's direct dbref to
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().addDBRef(
364 new DBRefEntry("Pfam", "0", "PF00111"));
365 pep1.addSequenceFeature(new SequenceFeature("type", "desc", 12, 14, 1f,
367 pep2.getDatasetSequence().addDBRef(new DBRefEntry("PDB", "0", "3JTK"));
368 pep2.addSequenceFeature(new SequenceFeature("type2", "desc2", 13, 15,
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(), original.getSequenceAsString());
417 * Test for finding 'product' sequences for the case where the selected
418 * sequence has a dbref with no mapping, triggering a fetch from database
420 @Test(groups = { "Functional" })
421 public void testFindXrefSequences_withFetch()
423 SequenceI dna1 = new Sequence("AF039662", "GGGGCAGCACAAGAAC");
424 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "Q9ZTS2"));
425 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "P30419"));
426 dna1.addDBRef(new DBRefEntry("UNIPROT", "ENA:0", "P00314"));
427 final SequenceI pep1 = new Sequence("Q9ZTS2", "MYQLIRSSW");
428 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "Q9ZTS2"));
430 final SequenceI pep2 = new Sequence("P00314", "MRKLLAASG");
431 pep2.addDBRef(new DBRefEntry("UNIPROT", "0", "P00314"));
434 * argument false suppresses adding DAS sources
435 * todo: define an interface type SequenceFetcherI and mock that
437 SequenceFetcher mockFetcher = new SequenceFetcher()
440 public boolean isFetchable(String source)
446 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
448 return new SequenceI[] { pep1, pep2 };
451 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
454 * find UNIPROT xrefs for nucleotide sequence
456 AlignmentI al = new Alignment(new SequenceI[] { dna1 });
457 Alignment xrefs = new CrossRef(new SequenceI[] { dna1 }, al)
458 .findXrefSequences("UNIPROT", true);
459 assertEquals(2, xrefs.getHeight());
460 assertSame(pep1, xrefs.getSequenceAt(0));
461 assertSame(pep2, xrefs.getSequenceAt(1));
465 public void tearDown()
467 SequenceFetcherFactory.setSequenceFetcher(null);
471 * Test for finding 'product' sequences for the case where both gene and
472 * transcript sequences have dbrefs to Uniprot.
474 @Test(groups = { "Functional" })
475 public void testFindXrefSequences_forGeneAndTranscripts()
480 SequenceI gene = new Sequence("ENSG00000157764", "CGCCTCCCTTCCCC");
481 gene.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
482 gene.addDBRef(new DBRefEntry("UNIPROT", "0", "H7C5K3"));
485 * 'transcript' with CDS feature (supports mapping to protein)
487 SequenceI braf001 = new Sequence("ENST00000288602", "taagATGGCGGCGCTGa");
488 braf001.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
489 braf001.addSequenceFeature(new SequenceFeature("CDS", "", 5, 16, 0f,
493 * 'spliced transcript' with CDS ranges
495 SequenceI braf002 = new Sequence("ENST00000497784", "gCAGGCtaTCTGTTCaa");
496 braf002.addDBRef(new DBRefEntry("UNIPROT", "ENSEMBL|0", "H7C5K3"));
497 braf002.addSequenceFeature(new SequenceFeature("CDS", "", 2, 6, 0f,
499 braf002.addSequenceFeature(new SequenceFeature("CDS", "", 9, 15, 0f,
503 * TODO code is fragile - use of SequenceIdMatcher depends on fetched
504 * sequences having a name starting Source|Accession
505 * which happens to be true for Uniprot,PDB,EMBL but not Pfam,Rfam,Ensembl
507 final SequenceI pep1 = new Sequence("UNIPROT|P15056", "MAAL");
508 pep1.addDBRef(new DBRefEntry("UNIPROT", "0", "P15056"));
509 final SequenceI pep2 = new Sequence("UNIPROT|H7C5K3", "QALF");
510 pep2.addDBRef(new DBRefEntry("UNIPROT", "0", "H7C5K3"));
512 * argument false suppresses adding DAS sources
513 * todo: define an interface type SequenceFetcherI and mock that
515 SequenceFetcher mockFetcher = new SequenceFetcher()
518 public boolean isFetchable(String source)
524 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
526 return new SequenceI[] { pep1, pep2 };
529 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
532 * find UNIPROT xrefs for gene and transcripts
534 * - the two proteins are retrieved but not duplicated
535 * - mappings are built from transcript (CDS) to proteins
536 * - no mappings from gene to proteins
538 SequenceI[] seqs = new SequenceI[] { gene, braf001, braf002 };
539 AlignmentI al = new Alignment(seqs);
540 Alignment xrefs = new CrossRef(seqs, al).findXrefSequences("UNIPROT",
542 assertEquals(2, xrefs.getHeight());
543 assertSame(pep1, xrefs.getSequenceAt(0));
544 assertSame(pep2, xrefs.getSequenceAt(1));
549 * Test that emulates this (real but simplified) case:
551 * UNIPROT|P0CE19 EMBL|J03321, EMBL|X06707, EMBL|M19487
552 * UNIPROT|P0CE20 EMBL|J03321, EMBL|X06707, EMBL|X07547
553 * Find cross-references for EMBL. These are mocked here as
554 * EMBL|J03321 with mappings to P0CE18, P0CE19, P0CE20
555 * EMBL|X06707 with mappings to P0CE17, P0CE19, P0CE20
556 * EMBL|M19487 with mappings to P0CE19, Q46432
557 * EMBL|X07547 with mappings to P0CE20, B0BCM4
558 * EMBL sequences are first 'fetched' (mocked here) for P0CE19.
559 * The 3 EMBL sequences are added to the alignment dataset.
560 * Their dbrefs to Uniprot products P0CE19 and P0CE20 should be matched in the
561 * alignment dataset and updated to reference the original Uniprot sequences.
562 * For the second Uniprot sequence, the J03321 and X06707 xrefs should be
563 * resolved from the dataset, and only the X07547 dbref fetched.
564 * So the end state to verify is:
565 * - 4 cross-ref sequences returned: J03321, X06707, M19487, X07547
566 * - P0CE19/20 dbrefs to EMBL sequences now have mappings
567 * - J03321 dbrefs to P0CE19/20 mapped to original Uniprot sequences
568 * - X06707 dbrefs to P0CE19/20 mapped to original Uniprot sequences
571 @Test(groups = { "Functional" })
572 public void testFindXrefSequences_uniprotEmblManyToMany()
575 * Uniprot sequences, both with xrefs to EMBL|J03321
578 SequenceI p0ce19 = new Sequence("UNIPROT|P0CE19", "KPFG");
579 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "J03321"));
580 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "X06707"));
581 p0ce19.addDBRef(new DBRefEntry("EMBL", "0", "M19487"));
582 SequenceI p0ce20 = new Sequence("UNIPROT|P0CE20", "PFGK");
583 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "J03321"));
584 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "X06707"));
585 p0ce20.addDBRef(new DBRefEntry("EMBL", "0", "X07547"));
588 * EMBL sequences to be 'fetched', complete with dbrefs and mappings
589 * to their protein products (CDS location and translations are provided
590 * in EMBL XML); these should be matched to, and replaced with,
591 * the corresponding uniprot sequences after fetching
595 * J03321 with mappings to P0CE19 and P0CE20
597 final SequenceI j03321 = new Sequence("EMBL|J03321", "AAACCCTTTGGGAAAA");
598 DBRefEntry dbref1 = new DBRefEntry("UNIPROT", "0", "P0CE19");
599 MapList mapList = new MapList(new int[] { 1, 12 }, new int[] { 1, 4 },
601 Mapping map = new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"),
603 // add a dbref to the mapped to sequence - should get copied to p0ce19
604 map.getTo().addDBRef(new DBRefEntry("PIR", "0", "S01875"));
606 j03321.addDBRef(dbref1);
607 DBRefEntry dbref2 = new DBRefEntry("UNIPROT", "0", "P0CE20");
608 mapList = new MapList(new int[] { 4, 15 }, new int[] { 2, 5 }, 3, 1);
609 dbref2.setMap(new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"),
610 new MapList(mapList)));
611 j03321.addDBRef(dbref2);
614 * X06707 with mappings to P0CE19 and P0CE20
616 final SequenceI x06707 = new Sequence("EMBL|X06707", "atgAAACCCTTTGGG");
617 DBRefEntry dbref3 = new DBRefEntry("UNIPROT", "0", "P0CE19");
618 MapList map2 = new MapList(new int[] { 4, 15 }, new int[] { 1, 4 }, 3,
620 dbref3.setMap(new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"), map2));
621 x06707.addDBRef(dbref3);
622 DBRefEntry dbref4 = new DBRefEntry("UNIPROT", "0", "P0CE20");
623 MapList map3 = new MapList(new int[] { 4, 15 }, new int[] { 1, 4 }, 3,
625 dbref4.setMap(new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"), map3));
626 x06707.addDBRef(dbref4);
629 * M19487 with mapping to P0CE19 and Q46432
631 final SequenceI m19487 = new Sequence("EMBL|M19487", "AAACCCTTTGGG");
632 DBRefEntry dbref5 = new DBRefEntry("UNIPROT", "0", "P0CE19");
633 dbref5.setMap(new Mapping(new Sequence("UNIPROT|P0CE19", "KPFG"),
634 new MapList(mapList)));
635 m19487.addDBRef(dbref5);
636 DBRefEntry dbref6 = new DBRefEntry("UNIPROT", "0", "Q46432");
637 dbref6.setMap(new Mapping(new Sequence("UNIPROT|Q46432", "KPFG"),
638 new MapList(mapList)));
639 m19487.addDBRef(dbref6);
642 * X07547 with mapping to P0CE20 and B0BCM4
644 final SequenceI x07547 = new Sequence("EMBL|X07547", "cccAAACCCTTTGGG");
645 DBRefEntry dbref7 = new DBRefEntry("UNIPROT", "0", "P0CE20");
646 dbref7.setMap(new Mapping(new Sequence("UNIPROT|P0CE20", "PFGK"),
648 x07547.addDBRef(dbref7);
649 DBRefEntry dbref8 = new DBRefEntry("UNIPROT", "0", "B0BCM4");
650 dbref8.setMap(new Mapping(new Sequence("UNIPROT|B0BCM4", "KPFG"),
652 x07547.addDBRef(dbref8);
655 * mock sequence fetcher to 'return' the EMBL sequences
656 * TODO: Mockito would allow .thenReturn().thenReturn() here,
657 * and also capture and verification of the parameters
658 * passed in calls to getSequences() - important to verify that
659 * duplicate sequence fetches are not requested
661 SequenceFetcher mockFetcher = new SequenceFetcher()
666 public boolean isFetchable(String source)
672 public SequenceI[] getSequences(List<DBRefEntry> refs, boolean dna)
677 assertEquals("Expected 3 embl seqs in first fetch", 3,
679 return new SequenceI[] { j03321, x06707, m19487 };
683 assertEquals("Expected 1 embl seq in second fetch", 1,
685 return new SequenceI[] { x07547 };
689 SequenceFetcherFactory.setSequenceFetcher(mockFetcher);
692 * find EMBL xrefs for Uniprot seqs and verify that
693 * - the EMBL xref'd sequences are retrieved without duplicates
694 * - mappings are added to the Uniprot dbrefs
695 * - mappings in the EMBL-to-Uniprot dbrefs are updated to the
696 * alignment sequences
697 * - dbrefs on the EMBL sequences are added to the original dbrefs
699 SequenceI[] seqs = new SequenceI[] { p0ce19, p0ce20 };
700 AlignmentI al = new Alignment(seqs);
701 Alignment xrefs = new CrossRef(seqs, al).findXrefSequences("EMBL",
705 * verify retrieved sequences
707 assertNotNull(xrefs);
708 assertEquals(4, xrefs.getHeight());
709 assertSame(j03321, xrefs.getSequenceAt(0));
710 assertSame(x06707, xrefs.getSequenceAt(1));
711 assertSame(m19487, xrefs.getSequenceAt(2));
712 assertSame(x07547, xrefs.getSequenceAt(3));
715 * verify mappings added to Uniprot-to-EMBL dbrefs
717 Mapping mapping = p0ce19.getDBRefs().get(0).getMap();
718 assertSame(j03321, mapping.getTo());
719 mapping = p0ce19.getDBRefs().get(1).getMap();
720 assertSame(x06707, mapping.getTo());
721 mapping = p0ce20.getDBRefs().get(0).getMap();
722 assertSame(j03321, mapping.getTo());
723 mapping = p0ce20.getDBRefs().get(1).getMap();
724 assertSame(x06707, mapping.getTo());
727 * verify dbrefs on EMBL are mapped to alignment seqs
730 assertSame(p0ce19, j03321.getDBRefs().get(0).getMap().getTo());
731 assertSame(p0ce20, j03321.getDBRefs().get(1).getMap().getTo());
732 assertSame(p0ce19, x06707.getDBRefs().get(0).getMap().getTo());
733 assertSame(p0ce20, x06707.getDBRefs().get(1).getMap().getTo());
736 * verify new dbref on EMBL dbref mapping is copied to the
737 * original Uniprot sequence
739 assertEquals(4, p0ce19.getDBRefs().size());
740 assertEquals("PIR", p0ce19.getDBRefs().get(3).getSource());
741 assertEquals("S01875", p0ce19.getDBRefs().get(3).getAccessionId());
744 @Test(groups = "Functional")
745 public void testSameSequence()
747 assertTrue(CrossRef.sameSequence(null, null));
748 SequenceI seq1 = new Sequence("seq1", "ABCDEF");
749 assertFalse(CrossRef.sameSequence(seq1, null));
750 assertFalse(CrossRef.sameSequence(null, seq1));
751 assertTrue(CrossRef.sameSequence(seq1, new Sequence("seq2", "ABCDEF")));
752 assertTrue(CrossRef.sameSequence(seq1, new Sequence("seq2", "abcdef")));
754 .sameSequence(seq1, new Sequence("seq2", "ABCDE-F")));
755 assertFalse(CrossRef.sameSequence(seq1, new Sequence("seq2", "BCDEF")));