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.assertFalse;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertTrue;
28 import jalview.analysis.CrossRef;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.DBRefEntry;
31 import jalview.datamodel.DBRefSource;
32 import jalview.datamodel.FeatureProperties;
33 import jalview.datamodel.SequenceFeature;
34 import jalview.datamodel.SequenceI;
35 import jalview.gui.JvOptionPane;
36 import jalview.util.DBRefUtils;
37 import jalview.ws.SequenceFetcher;
38 import jalview.ws.dbsources.Pdb;
39 import jalview.ws.dbsources.Uniprot;
41 import java.util.ArrayList;
42 import java.util.Arrays;
43 import java.util.List;
45 import org.testng.annotations.AfterClass;
46 import org.testng.annotations.BeforeClass;
47 import org.testng.annotations.Test;
53 public class DbRefFetcherTest
56 @BeforeClass(alwaysRun = true)
57 public void setUpJvOptionPane()
59 JvOptionPane.setInteractiveMode(false);
60 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
64 * @throws java.lang.Exception
66 @BeforeClass(alwaysRun = true)
67 public static void setUpBeforeClass() throws Exception
69 jalview.bin.Cache.initLogger();
73 * @throws java.lang.Exception
75 @AfterClass(alwaysRun = true)
76 public static void tearDownAfterClass() throws Exception
81 * Tests that standard protein database sources include Uniprot (as the first)
82 * and also PDB. (Additional sources are dependent on availability of DAS
85 @Test(groups = { "Functional" })
86 public void testStandardProtDbs()
88 List<String> defdb = new ArrayList<String>();
89 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
90 defdb.add(DBRefSource.PDB);
91 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
92 SequenceFetcher sfetcher = new SequenceFetcher();
93 boolean pdbFound = false;
95 for (String ddb : defdb)
97 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
99 if (srcesfordb != null)
101 // TODO is this right? get duplicate entries
102 srces.addAll(srcesfordb);
108 for (DbSourceProxy s : srces)
110 if (s instanceof Uniprot && uniprotPos == -1)
114 if (s instanceof Pdb)
121 assertTrue("Failed to find Uniprot source as first source amongst "
122 + srces.size() + " sources (source was at position "
123 + uniprotPos + ")", uniprotPos == 0);
124 assertTrue("Failed to find PDB source amongst " + srces.size()
125 + " sources", pdbFound);
129 * Tests retrieval of one entry from EMBL. Test is dependent on availability
130 * of network and the EMBL service.
134 @Test(groups = { "External" })
135 public void testEmblUniprotProductRecovery() throws Exception
137 String retrievalId = "V00488";
138 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
139 DBRefSource.EMBL).get(0);
140 assertNotNull("Couldn't find the EMBL retrieval client", embl);
141 verifyProteinNucleotideXref(retrievalId, embl);
145 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
146 * availability of network and the EMBLCDS service.
150 @Test(groups = { "External" })
151 public void testEmblCDSUniprotProductRecovery() throws Exception
153 String retrievalId = "AAH29712";
154 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
155 DBRefSource.EMBLCDS).get(0);
156 assertNotNull("Couldn't find the EMBL retrieval client", embl);
157 verifyProteinNucleotideXref(retrievalId, embl);
161 * Helper method to perform database retrieval and verification of results.
167 private void verifyProteinNucleotideXref(String retrievalId,
168 DbSourceProxy embl) throws Exception
170 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
171 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
172 assertEquals("Didn't retrieve right number of records", 1,
174 SequenceI seq = alsq.getSequenceAt(0);
175 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
176 + retrievalId, seq.getName());
177 List<SequenceFeature> sfs = seq.getSequenceFeatures();
178 assertFalse("Sequence features missing", sfs.isEmpty());
181 FeatureProperties.isCodingFeature(embl.getDbSource(),
182 sfs.get(0).getType()));
183 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
184 DBRefEntry[] dr = DBRefUtils.selectRefs(seq.getDBRefs(),
185 new String[] { DBRefSource.UNIPROT });
187 assertEquals("Expected a single Uniprot cross reference", 1, dr.length);
188 assertEquals("Expected cross reference map to be one amino acid", dr[0]
189 .getMap().getMappedWidth(), 1);
190 assertEquals("Expected local reference map to be 3 nucleotides", dr[0]
191 .getMap().getWidth(), 3);
192 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
193 .findXrefSequences(dr[0].getSource(), true);
195 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
197 assertEquals("Didn't xref right number of records", 1,
199 SequenceI proteinSeq = sprods.getSequenceAt(0);
200 assertEquals(proteinSeq.getSequenceAsString(), dr[0].getMap().getTo()
201 .getSequenceAsString());
202 assertEquals(dr[0].getSource() + "|" + dr[0].getAccessionId(),
203 proteinSeq.getName());