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;
37 import java.util.ArrayList;
38 import java.util.List;
40 import org.testng.annotations.AfterClass;
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.Test;
48 public class DbRefFetcherTest
52 * @throws java.lang.Exception
54 @BeforeClass(alwaysRun = true)
55 public static void setUpBeforeClass() throws Exception
57 jalview.bin.Cache.initLogger();
61 * @throws java.lang.Exception
64 public static void tearDownAfterClass() throws Exception
69 * Tests that standard protein database sources include Uniprot (as the first)
70 * and also PDB. (Additional sources are dependent on available of DAS
73 @Test(groups = { "Functional" })
74 public void testStandardProtDbs()
76 String[] defdb = DBRefSource.PROTEINDBS;
77 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
78 for (String ddb : defdb)
80 SequenceFetcher sfetcher = new SequenceFetcher();
81 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
83 if (srcesfordb != null)
85 srces.addAll(srcesfordb);
92 // append the selected sequence sources to the default dbs
93 for (DbSourceProxy s : srces)
95 if (s instanceof jalview.ws.dbsources.Uniprot)
99 if (s instanceof jalview.ws.dbsources.Pdb)
106 assertTrue("Failed to find Uniprot source as first source amongst "
107 + srces.size() + " sources (source was at position "
108 + uniprotPos + ")", uniprotPos == 0);
109 assertTrue("Failed to find PDB source amongst " + srces.size()
110 + " sources", pdbPos >= 0);
114 * Tests retrieval of one entry from EMBL. Test is dependent on availability
115 * of network and the EMBL service.
119 @Test(groups = { "External" })
120 public void testEmblUniprotProductRecovery() throws Exception
122 String retrievalId = "V00488";
123 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
124 DBRefSource.EMBL).get(0);
125 assertNotNull("Couldn't find the EMBL retrieval client", embl);
126 verifyProteinNucleotideXref(retrievalId, embl);
130 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
131 * availability of network and the EMBLCDS service.
135 @Test(groups = { "External" })
136 public void testEmblCDSUniprotProductRecovery() throws Exception
138 String retrievalId = "AAH29712";
139 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
140 DBRefSource.EMBLCDS).get(0);
141 assertNotNull("Couldn't find the EMBL retrieval client", embl);
142 verifyProteinNucleotideXref(retrievalId, embl);
146 * Helper method to perform database retrieval and verification of results.
152 private void verifyProteinNucleotideXref(String retrievalId,
153 DbSourceProxy embl) throws Exception
155 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
156 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
157 assertEquals("Didn't retrieve right number of records", 1,
159 SequenceI seq = alsq.getSequenceAt(0);
160 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
161 + retrievalId, seq.getName());
162 SequenceFeature[] sfs = seq.getSequenceFeatures();
163 assertNotNull("Sequence features missing", sfs);
166 FeatureProperties.isCodingFeature(embl.getDbSource(),
168 assertEquals(embl.getDbSource(), sfs[0].getFeatureGroup());
169 DBRefEntry[] dr = DBRefUtils.selectRefs(seq.getDBRefs(),
170 DBRefSource.PROTEINSEQ);
172 assertEquals("Expected a single Uniprot cross reference", 1, dr.length);
173 assertEquals("Expected cross reference map to be one amino acid", dr[0]
174 .getMap().getMappedWidth(), 1);
175 assertEquals("Expected local reference map to be 3 nucleotides", dr[0]
176 .getMap().getWidth(), 3);
177 AlignmentI sprods = CrossRef.findXrefSequences(
178 alsq.getSequencesArray(), true, dr[0].getSource(),
181 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
183 assertEquals("Didn't xref right number of records", 1,
185 SequenceI proteinSeq = sprods.getSequenceAt(0);
186 assertEquals(proteinSeq.getSequenceAsString(), dr[0].getMap().getTo()
187 .getSequenceAsString());
188 assertEquals(dr[0].getSource() + "|" + dr[0].getAccessionId(),
189 proteinSeq.getName());