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.Arrays;
41 import java.util.List;
43 import org.testng.annotations.AfterClass;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.Test;
51 public class DbRefFetcherTest
55 * @throws java.lang.Exception
57 @BeforeClass(alwaysRun = true)
58 public static void setUpBeforeClass() throws Exception
60 jalview.bin.Cache.initLogger();
64 * @throws java.lang.Exception
66 @AfterClass(alwaysRun = true)
67 public static void tearDownAfterClass() throws Exception
72 * Tests that standard protein database sources include Uniprot (as the first)
73 * and also PDB. (Additional sources are dependent on availability of DAS
76 @Test(groups = { "Functional" })
77 public void testStandardProtDbs()
79 List<String> defdb = new ArrayList<String>();
80 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
81 defdb.add(DBRefSource.PDB);
82 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
83 SequenceFetcher sfetcher = new SequenceFetcher();
84 boolean pdbFound = false;
86 for (String ddb : defdb)
88 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
90 if (srcesfordb != null)
92 // TODO is this right? get duplicate entries
93 srces.addAll(srcesfordb);
99 for (DbSourceProxy s : srces)
101 if (s instanceof Uniprot && uniprotPos == -1)
105 if (s instanceof Pdb)
112 assertTrue("Failed to find Uniprot source as first source amongst "
113 + srces.size() + " sources (source was at position "
114 + uniprotPos + ")", uniprotPos == 0);
115 assertTrue("Failed to find PDB source amongst " + srces.size()
116 + " sources", pdbFound);
120 * Tests retrieval of one entry from EMBL. Test is dependent on availability
121 * of network and the EMBL service.
125 @Test(groups = { "External" })
126 public void testEmblUniprotProductRecovery() throws Exception
128 String retrievalId = "V00488";
129 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
130 DBRefSource.EMBL).get(0);
131 assertNotNull("Couldn't find the EMBL retrieval client", embl);
132 verifyProteinNucleotideXref(retrievalId, embl);
136 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
137 * availability of network and the EMBLCDS service.
141 @Test(groups = { "External" })
142 public void testEmblCDSUniprotProductRecovery() throws Exception
144 String retrievalId = "AAH29712";
145 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
146 DBRefSource.EMBLCDS).get(0);
147 assertNotNull("Couldn't find the EMBL retrieval client", embl);
148 verifyProteinNucleotideXref(retrievalId, embl);
152 * Helper method to perform database retrieval and verification of results.
158 private void verifyProteinNucleotideXref(String retrievalId,
159 DbSourceProxy embl) throws Exception
161 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
162 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
163 assertEquals("Didn't retrieve right number of records", 1,
165 SequenceI seq = alsq.getSequenceAt(0);
166 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
167 + retrievalId, seq.getName());
168 SequenceFeature[] sfs = seq.getSequenceFeatures();
169 assertNotNull("Sequence features missing", sfs);
172 FeatureProperties.isCodingFeature(embl.getDbSource(),
174 assertEquals(embl.getDbSource(), sfs[0].getFeatureGroup());
175 DBRefEntry[] dr = DBRefUtils.selectRefs(seq.getDBRefs(),
176 new String[] { DBRefSource.UNIPROT });
178 assertEquals("Expected a single Uniprot cross reference", 1, dr.length);
179 assertEquals("Expected cross reference map to be one amino acid", dr[0]
180 .getMap().getMappedWidth(), 1);
181 assertEquals("Expected local reference map to be 3 nucleotides", dr[0]
182 .getMap().getWidth(), 3);
183 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
184 .findXrefSequences(dr[0].getSource(), true);
186 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
188 assertEquals("Didn't xref right number of records", 1,
190 SequenceI proteinSeq = sprods.getSequenceAt(0);
191 assertEquals(proteinSeq.getSequenceAsString(), dr[0].getMap().getTo()
192 .getSequenceAsString());
193 assertEquals(dr[0].getSource() + "|" + dr[0].getAccessionId(),
194 proteinSeq.getName());