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.ws.seqfetcher;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.analysis.CrossRef;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.DBRefEntry;
30 import jalview.datamodel.DBRefSource;
31 import jalview.datamodel.FeatureProperties;
32 import jalview.datamodel.SequenceFeature;
33 import jalview.datamodel.SequenceI;
34 import jalview.util.DBRefUtils;
35 import jalview.ws.SequenceFetcher;
36 import jalview.ws.dbsources.Pdb;
37 import jalview.ws.dbsources.Uniprot;
39 import java.util.ArrayList;
40 import java.util.List;
42 import org.testng.annotations.AfterClass;
43 import org.testng.annotations.BeforeClass;
44 import org.testng.annotations.Test;
50 public class DbRefFetcherTest
54 * @throws java.lang.Exception
56 @BeforeClass(alwaysRun = true)
57 public static void setUpBeforeClass() throws Exception
59 jalview.bin.Cache.initLogger();
63 * @throws java.lang.Exception
65 @AfterClass(alwaysRun = true)
66 public static void tearDownAfterClass() throws Exception
71 * Tests that standard protein database sources include Uniprot (as the first)
72 * and also PDB. (Additional sources are dependent on availability of DAS
75 @Test(groups = { "Functional" })
76 public void testStandardProtDbs()
78 String[] defdb = DBRefSource.PROTEINDBS;
79 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
80 SequenceFetcher sfetcher = new SequenceFetcher();
81 boolean pdbFound = false;
83 for (String ddb : defdb)
85 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
87 if (srcesfordb != null)
89 // TODO is this right? get duplicate entries
90 srces.addAll(srcesfordb);
96 for (DbSourceProxy s : srces)
98 if (s instanceof Uniprot && uniprotPos == -1)
102 if (s instanceof Pdb)
109 assertTrue("Failed to find Uniprot source as first source amongst "
110 + srces.size() + " sources (source was at position "
111 + uniprotPos + ")", uniprotPos == 0);
112 assertTrue("Failed to find PDB source amongst " + srces.size()
113 + " sources", pdbFound);
117 * Tests retrieval of one entry from EMBL. Test is dependent on availability
118 * of network and the EMBL service.
122 @Test(groups = { "External" })
123 public void testEmblUniprotProductRecovery() throws Exception
125 String retrievalId = "V00488";
126 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
127 DBRefSource.EMBL).get(0);
128 assertNotNull("Couldn't find the EMBL retrieval client", embl);
129 verifyProteinNucleotideXref(retrievalId, embl);
133 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
134 * availability of network and the EMBLCDS service.
138 @Test(groups = { "External" })
139 public void testEmblCDSUniprotProductRecovery() throws Exception
141 String retrievalId = "AAH29712";
142 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
143 DBRefSource.EMBLCDS).get(0);
144 assertNotNull("Couldn't find the EMBL retrieval client", embl);
145 verifyProteinNucleotideXref(retrievalId, embl);
149 * Helper method to perform database retrieval and verification of results.
155 private void verifyProteinNucleotideXref(String retrievalId,
156 DbSourceProxy embl) throws Exception
158 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
159 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
160 assertEquals("Didn't retrieve right number of records", 1,
162 SequenceI seq = alsq.getSequenceAt(0);
163 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
164 + retrievalId, seq.getName());
165 SequenceFeature[] sfs = seq.getSequenceFeatures();
166 assertNotNull("Sequence features missing", sfs);
169 FeatureProperties.isCodingFeature(embl.getDbSource(),
171 assertEquals(embl.getDbSource(), sfs[0].getFeatureGroup());
172 DBRefEntry[] dr = DBRefUtils.selectRefs(seq.getDBRefs(),
173 new String[] { DBRefSource.UNIPROT, DBRefSource.UNIPROTKB,
174 DBRefSource.EMBLCDSProduct, DBRefSource.ENSEMBL });
176 assertEquals("Expected a single Uniprot cross reference", 1, dr.length);
177 assertEquals("Expected cross reference map to be one amino acid", dr[0]
178 .getMap().getMappedWidth(), 1);
179 assertEquals("Expected local reference map to be 3 nucleotides", dr[0]
180 .getMap().getWidth(), 3);
181 AlignmentI sprods = CrossRef.findXrefSequences(
182 alsq.getSequencesArray(), true, dr[0].getSource(), alsq);
184 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
186 assertEquals("Didn't xref right number of records", 1,
188 SequenceI proteinSeq = sprods.getSequenceAt(0);
189 assertEquals(proteinSeq.getSequenceAsString(), dr[0].getMap().getTo()
190 .getSequenceAsString());
191 assertEquals(dr[0].getSource() + "|" + dr[0].getAccessionId(),
192 proteinSeq.getName());