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.gui.JvOptionPane;
35 import jalview.util.DBRefUtils;
36 import jalview.ws.SequenceFetcher;
37 import jalview.ws.dbsources.Pdb;
38 import jalview.ws.dbsources.Uniprot;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.List;
44 import org.testng.annotations.AfterClass;
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.Test;
52 public class DbRefFetcherTest
55 @BeforeClass(alwaysRun = true)
56 public void setUpJvOptionPane()
58 JvOptionPane.setInteractiveMode(false);
59 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
63 * @throws java.lang.Exception
65 @BeforeClass(alwaysRun = true)
66 public static void setUpBeforeClass() throws Exception
68 jalview.bin.Cache.initLogger();
72 * @throws java.lang.Exception
74 @AfterClass(alwaysRun = true)
75 public static void tearDownAfterClass() throws Exception
80 * Tests that standard protein database sources include Uniprot (as the first)
81 * and also PDB. (Additional sources are dependent on availability of DAS
84 @Test(groups = { "Functional" })
85 public void testStandardProtDbs()
87 List<String> defdb = new ArrayList<String>();
88 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
89 defdb.add(DBRefSource.PDB);
90 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
91 SequenceFetcher sfetcher = new SequenceFetcher();
92 boolean pdbFound = false;
94 for (String ddb : defdb)
96 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
98 if (srcesfordb != null)
100 // TODO is this right? get duplicate entries
101 srces.addAll(srcesfordb);
107 for (DbSourceProxy s : srces)
109 if (s instanceof Uniprot && uniprotPos == -1)
113 if (s instanceof Pdb)
120 assertTrue("Failed to find Uniprot source as first source amongst "
121 + srces.size() + " sources (source was at position "
122 + uniprotPos + ")", uniprotPos == 0);
123 assertTrue("Failed to find PDB source amongst " + srces.size()
124 + " sources", pdbFound);
128 * Tests retrieval of one entry from EMBL. Test is dependent on availability
129 * of network and the EMBL service.
133 @Test(groups = { "External" })
134 public void testEmblUniprotProductRecovery() throws Exception
136 String retrievalId = "V00488";
137 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
138 DBRefSource.EMBL).get(0);
139 assertNotNull("Couldn't find the EMBL retrieval client", embl);
140 verifyProteinNucleotideXref(retrievalId, embl);
144 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
145 * availability of network and the EMBLCDS service.
149 @Test(groups = { "External" })
150 public void testEmblCDSUniprotProductRecovery() throws Exception
152 String retrievalId = "AAH29712";
153 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
154 DBRefSource.EMBLCDS).get(0);
155 assertNotNull("Couldn't find the EMBL retrieval client", embl);
156 verifyProteinNucleotideXref(retrievalId, embl);
160 * Helper method to perform database retrieval and verification of results.
166 private void verifyProteinNucleotideXref(String retrievalId,
167 DbSourceProxy embl) throws Exception
169 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
170 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
171 assertEquals("Didn't retrieve right number of records", 1,
173 SequenceI seq = alsq.getSequenceAt(0);
174 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
175 + retrievalId, seq.getName());
176 SequenceFeature[] sfs = seq.getSequenceFeatures();
177 assertNotNull("Sequence features missing", sfs);
180 FeatureProperties.isCodingFeature(embl.getDbSource(),
182 assertEquals(embl.getDbSource(), sfs[0].getFeatureGroup());
183 DBRefEntry[] dr = DBRefUtils.selectRefs(seq.getDBRefs(),
184 new String[] { DBRefSource.UNIPROT });
186 assertEquals("Expected a single Uniprot cross reference", 1, dr.length);
187 assertEquals("Expected cross reference map to be one amino acid", dr[0]
188 .getMap().getMappedWidth(), 1);
189 assertEquals("Expected local reference map to be 3 nucleotides", dr[0]
190 .getMap().getWidth(), 3);
191 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
192 .findXrefSequences(dr[0].getSource(), true);
194 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
196 assertEquals("Didn't xref right number of records", 1,
198 SequenceI proteinSeq = sprods.getSequenceAt(0);
199 assertEquals(proteinSeq.getSequenceAsString(), dr[0].getMap().getTo()
200 .getSequenceAsString());
201 assertEquals(dr[0].getSource() + "|" + dr[0].getAccessionId(),
202 proteinSeq.getName());