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.Sequence;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceI;
36 import jalview.gui.JvOptionPane;
37 import jalview.util.DBRefUtils;
38 import jalview.ws.DBRefFetcher;
39 import jalview.ws.SequenceFetcher;
40 import jalview.ws.dbsources.Pdb;
41 import jalview.ws.dbsources.Uniprot;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.List;
47 import org.testng.annotations.AfterClass;
48 import org.testng.annotations.BeforeClass;
49 import org.testng.annotations.Test;
55 public class DbRefFetcherTest
58 @BeforeClass(alwaysRun = true)
59 public void setUpJvOptionPane()
61 JvOptionPane.setInteractiveMode(false);
62 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
66 * @throws java.lang.Exception
68 @BeforeClass(alwaysRun = true)
69 public static void setUpBeforeClass() throws Exception
71 jalview.bin.Cache.initLogger();
75 * @throws java.lang.Exception
77 @AfterClass(alwaysRun = true)
78 public static void tearDownAfterClass() throws Exception
82 @Test(groups= {"Network"})
83 public void checkUniprotCanonicalFlagSet()
85 // TODO - mock this - for moment it is a live request.
86 SequenceI uniprotSeq = new Sequence("FER1_SPIOL",
87 "MAATTTTMMGMATTFVPKPQAPPMMAALPSNTGRSLFGLKTGSRGGRMTMAAYKVTLVTPTGNVEFQCPDDV"
88 + "YILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEE"
90 DBRefFetcher dbr = new DBRefFetcher(new SequenceI[] { uniprotSeq });
91 dbr.fetchDBRefs(true);
92 List<DBRefEntry> primRefs = uniprotSeq.getPrimaryDBRefs();
93 assertNotNull(primRefs);
94 assertTrue(primRefs.size()>0);
95 boolean canonicalUp=false;
96 for (DBRefEntry ref:primRefs) {
97 assertEquals(DBRefSource.UNIPROT, ref.getCanonicalSourceName());
98 canonicalUp |= ref.isCanonical();
100 assertTrue("No Canonical Uniprot reference detected", canonicalUp);
103 * Tests that standard protein database sources include Uniprot (as the first)
104 * and also PDB. (Additional sources are dependent on availability of DAS
107 @Test(groups = { "Functional" })
108 public void testStandardProtDbs()
110 List<String> defdb = new ArrayList<String>();
111 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
112 defdb.add(DBRefSource.PDB);
113 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
114 SequenceFetcher sfetcher = new SequenceFetcher();
115 boolean pdbFound = false;
117 for (String ddb : defdb)
119 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
121 if (srcesfordb != null)
123 // TODO is this right? get duplicate entries
124 srces.addAll(srcesfordb);
130 for (DbSourceProxy s : srces)
132 if (s instanceof Uniprot && uniprotPos == -1)
136 if (s instanceof Pdb)
143 assertTrue("Failed to find Uniprot source as first source amongst "
144 + srces.size() + " sources (source was at position "
145 + uniprotPos + ")", uniprotPos == 0);
146 assertTrue("Failed to find PDB source amongst " + srces.size()
147 + " sources", pdbFound);
151 * Tests retrieval of one entry from EMBL. Test is dependent on availability
152 * of network and the EMBL service.
156 @Test(groups = { "External" })
157 public void testEmblUniprotProductRecovery() throws Exception
159 String retrievalId = "V00488";
160 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
161 DBRefSource.EMBL).get(0);
162 assertNotNull("Couldn't find the EMBL retrieval client", embl);
163 verifyProteinNucleotideXref(retrievalId, embl);
167 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
168 * availability of network and the EMBLCDS service.
172 @Test(groups = { "External" })
173 public void testEmblCDSUniprotProductRecovery() throws Exception
175 String retrievalId = "AAH29712";
176 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
177 DBRefSource.EMBLCDS).get(0);
178 assertNotNull("Couldn't find the EMBL retrieval client", embl);
179 verifyProteinNucleotideXref(retrievalId, embl);
183 * Helper method to perform database retrieval and verification of results.
189 private void verifyProteinNucleotideXref(String retrievalId,
190 DbSourceProxy embl) throws Exception
192 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
193 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
194 assertEquals("Didn't retrieve right number of records", 1,
196 SequenceI seq = alsq.getSequenceAt(0);
197 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
198 + retrievalId, seq.getName());
199 List<SequenceFeature> sfs = seq.getSequenceFeatures();
200 assertFalse("Sequence features missing", sfs.isEmpty());
203 FeatureProperties.isCodingFeature(embl.getDbSource(),
204 sfs.get(0).getType()));
205 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
206 List<DBRefEntry> dr = DBRefUtils.selectRefs(seq.getDBRefs(),
207 new String[] { DBRefSource.UNIPROT });
209 assertEquals("Expected a single Uniprot cross reference", 1, dr.size());
210 assertEquals("Expected cross reference map to be one amino acid", dr.get(0)
211 .getMap().getMappedWidth(), 1);
212 assertEquals("Expected local reference map to be 3 nucleotides", dr.get(0)
213 .getMap().getWidth(), 3);
214 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
215 .findXrefSequences(dr.get(0).getSource(), true);
217 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
219 assertEquals("Didn't xref right number of records", 1,
221 SequenceI proteinSeq = sprods.getSequenceAt(0);
222 assertEquals(proteinSeq.getSequenceAsString(), dr.get(0).getMap().getTo()
223 .getSequenceAsString());
224 assertEquals(dr.get(0).getSource() + "|" + dr.get(0).getAccessionId(),
225 proteinSeq.getName());