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.Console.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)
98 assertEquals(DBRefSource.UNIPROT, ref.getCanonicalSourceName());
99 canonicalUp |= ref.isCanonical();
101 assertTrue("No Canonical Uniprot reference detected", canonicalUp);
105 * Tests that standard protein database sources include Uniprot (as the first)
106 * and also PDB. (Additional sources are dependent on availability of DAS
109 @Test(groups = { "Functional" })
110 public void testStandardProtDbs()
112 List<String> defdb = new ArrayList<String>();
113 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
114 defdb.add(DBRefSource.PDB);
115 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
116 SequenceFetcher sfetcher = new SequenceFetcher();
117 boolean pdbFound = false;
119 for (String ddb : defdb)
121 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
123 if (srcesfordb != null)
125 // TODO is this right? get duplicate entries
126 srces.addAll(srcesfordb);
132 for (DbSourceProxy s : srces)
134 if (s instanceof Uniprot && uniprotPos == -1)
138 if (s instanceof Pdb)
145 assertTrue("Failed to find Uniprot source as first source amongst "
146 + srces.size() + " sources (source was at position "
147 + uniprotPos + ")", uniprotPos == 0);
148 assertTrue("Failed to find PDB source amongst " + srces.size()
149 + " sources", pdbFound);
153 * Tests retrieval of one entry from EMBL. Test is dependent on availability
154 * of network and the EMBL service.
158 @Test(groups = { "External" })
159 public void testEmblUniprotProductRecovery() throws Exception
161 String retrievalId = "V00488";
162 DbSourceProxy embl = new SequenceFetcher()
163 .getSourceProxy(DBRefSource.EMBL).get(0);
164 assertNotNull("Couldn't find the EMBL retrieval client", embl);
165 verifyProteinNucleotideXref(retrievalId, embl);
169 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
170 * availability of network and the EMBLCDS service.
174 @Test(groups = { "External" })
175 public void testEmblCDSUniprotProductRecovery() throws Exception
177 String retrievalId = "AAH29712";
178 DbSourceProxy embl = new SequenceFetcher()
179 .getSourceProxy(DBRefSource.EMBLCDS).get(0);
180 assertNotNull("Couldn't find the EMBL retrieval client", embl);
181 verifyProteinNucleotideXref(retrievalId, embl);
185 * Helper method to perform database retrieval and verification of results.
191 private void verifyProteinNucleotideXref(String retrievalId,
192 DbSourceProxy embl) throws Exception
194 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
195 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
196 assertEquals("Didn't retrieve right number of records", 1,
198 SequenceI seq = alsq.getSequenceAt(0);
199 assertEquals("Wrong sequence name",
200 embl.getDbSource() + "|" + retrievalId, seq.getName());
201 List<SequenceFeature> sfs = seq.getSequenceFeatures();
202 assertFalse("Sequence features missing", sfs.isEmpty());
203 assertTrue("Feature not CDS", FeatureProperties
204 .isCodingFeature(embl.getDbSource(), sfs.get(0).getType()));
205 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
206 List<DBRefEntry> dr = DBRefUtils.selectRefs(seq.getDBRefs(),
208 { DBRefSource.UNIPROT });
210 assertEquals("Expected a single Uniprot cross reference", 1, dr.size());
211 assertEquals("Expected cross reference map to be one amino acid",
212 dr.get(0).getMap().getMappedWidth(), 1);
213 assertEquals("Expected local reference map to be 3 nucleotides",
214 dr.get(0).getMap().getWidth(), 3);
215 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
216 .findXrefSequences(dr.get(0).getSource(), true);
218 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
220 assertEquals("Didn't xref right number of records", 1,
222 SequenceI proteinSeq = sprods.getSequenceAt(0);
223 assertEquals(proteinSeq.getSequenceAsString(),
224 dr.get(0).getMap().getTo().getSequenceAsString());
225 assertEquals(dr.get(0).getSource() + "|" + dr.get(0).getAccessionId(),
226 proteinSeq.getName());