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 java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.List;
32 import org.junit.Assert;
33 import org.testng.annotations.AfterClass;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
37 import jalview.analysis.CrossRef;
38 import jalview.datamodel.AlignmentAnnotation;
39 import jalview.datamodel.AlignmentI;
40 import jalview.datamodel.DBRefEntry;
41 import jalview.datamodel.DBRefSource;
42 import jalview.datamodel.FeatureProperties;
43 import jalview.datamodel.Sequence;
44 import jalview.datamodel.SequenceFeature;
45 import jalview.datamodel.SequenceI;
46 import jalview.gui.JvOptionPane;
47 import jalview.util.DBRefUtils;
48 import jalview.ws.DBRefFetcher;
49 import jalview.ws.SequenceFetcher;
50 import jalview.ws.dbsources.EBIAlfaFold;
51 import jalview.ws.dbsources.Pdb;
52 import jalview.ws.dbsources.Uniprot;
58 public class DbRefFetcherTest
61 @BeforeClass(alwaysRun = true)
62 public void setUpJvOptionPane()
64 JvOptionPane.setInteractiveMode(false);
65 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
69 * @throws java.lang.Exception
71 @BeforeClass(alwaysRun = true)
72 public static void setUpBeforeClass() throws Exception
74 jalview.bin.Console.initLogger();
78 * @throws java.lang.Exception
80 @AfterClass(alwaysRun = true)
81 public static void tearDownAfterClass() throws Exception
85 @Test(groups = { "Network" })
86 public void checkUniprotCanonicalFlagSet()
88 // TODO - mock this - for moment it is a live request.
89 SequenceI uniprotSeq = new Sequence("FER1_SPIOL",
90 "MAATTTTMMGMATTFVPKPQAPPMMAALPSNTGRSLFGLKTGSRGGRMTMAAYKVTLVTPTGNVEFQCPDDV"
91 + "YILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEE"
93 DBRefFetcher dbr = new DBRefFetcher(new SequenceI[] { uniprotSeq });
94 dbr.fetchDBRefs(true);
95 List<DBRefEntry> primRefs = uniprotSeq.getPrimaryDBRefs();
96 assertNotNull(primRefs);
97 assertTrue(primRefs.size() > 0);
98 boolean canonicalUp = false;
99 for (DBRefEntry ref : primRefs)
101 assertEquals(DBRefSource.UNIPROT, ref.getCanonicalSourceName());
102 canonicalUp |= ref.isCanonical();
104 assertTrue("No Canonical Uniprot reference detected", canonicalUp);
108 * Tests that standard protein database sources include Uniprot (as the first)
109 * and also PDB. (Additional sources are dependent on availability of DAS
112 @Test(groups = { "Functional" })
113 public void testStandardProtDbs()
115 List<String> defdb = new ArrayList<String>();
116 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
117 defdb.add(DBRefSource.PDB);
118 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
119 SequenceFetcher sfetcher = new SequenceFetcher();
120 boolean pdbFound = false;
122 for (String ddb : defdb)
124 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
126 if (srcesfordb != null)
128 // TODO is this right? get duplicate entries
129 srces.addAll(srcesfordb);
135 for (DbSourceProxy s : srces)
137 if (s instanceof Uniprot && uniprotPos == -1)
141 if (s instanceof Pdb)
148 assertTrue("Failed to find Uniprot source as first source amongst "
149 + srces.size() + " sources (source was at position "
150 + uniprotPos + ")", uniprotPos == 0);
151 assertTrue("Failed to find PDB source amongst " + srces.size()
152 + " sources", pdbFound);
156 * Tests retrieval of one entry from EMBL. Test is dependent on availability
157 * of network and the EMBL service.
161 @Test(groups = { "External" })
162 public void testEmblUniprotProductRecovery() throws Exception
164 String retrievalId = "V00488";
165 DbSourceProxy embl = new SequenceFetcher()
166 .getSourceProxy(DBRefSource.EMBL).get(0);
167 assertNotNull("Couldn't find the EMBL retrieval client", embl);
168 verifyProteinNucleotideXref(retrievalId, embl);
172 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
173 * availability of network and the EMBLCDS service.
177 @Test(groups = { "External" })
178 public void testEmblCDSUniprotProductRecovery() throws Exception
180 String retrievalId = "AAH29712";
181 DbSourceProxy embl = new SequenceFetcher()
182 .getSourceProxy(DBRefSource.EMBLCDS).get(0);
183 assertNotNull("Couldn't find the EMBL retrieval client", embl);
184 verifyProteinNucleotideXref(retrievalId, embl);
188 * Helper method to perform database retrieval and verification of results.
194 private void verifyProteinNucleotideXref(String retrievalId,
195 DbSourceProxy embl) throws Exception
197 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
198 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
199 assertEquals("Didn't retrieve right number of records", 1,
201 SequenceI seq = alsq.getSequenceAt(0);
202 assertEquals("Wrong sequence name",
203 embl.getDbSource() + "|" + retrievalId, seq.getName());
204 List<SequenceFeature> sfs = seq.getSequenceFeatures();
205 assertFalse("Sequence features missing", sfs.isEmpty());
206 assertTrue("Feature not CDS", FeatureProperties
207 .isCodingFeature(embl.getDbSource(), sfs.get(0).getType()));
208 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
209 List<DBRefEntry> dr = DBRefUtils.selectRefs(seq.getDBRefs(),
211 { DBRefSource.UNIPROT });
213 assertEquals("Expected a single Uniprot cross reference", 1, dr.size());
214 assertEquals("Expected cross reference map to be one amino acid",
215 dr.get(0).getMap().getMappedWidth(), 1);
216 assertEquals("Expected local reference map to be 3 nucleotides",
217 dr.get(0).getMap().getWidth(), 3);
218 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
219 .findXrefSequences(dr.get(0).getSource(), true);
221 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
223 assertEquals("Didn't xref right number of records", 1,
225 SequenceI proteinSeq = sprods.getSequenceAt(0);
226 assertEquals(proteinSeq.getSequenceAsString(),
227 dr.get(0).getMap().getTo().getSequenceAsString());
228 assertEquals(dr.get(0).getSource() + "|" + dr.get(0).getAccessionId(),
229 proteinSeq.getName());
233 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
234 * availability of network and the EMBLCDS service.
238 @Test(groups = { "External" })
239 public void testAlphaFoldClien() throws Exception
241 DbSourceProxy alphafold = new EBIAlfaFold();
242 AlignmentI resp = alphafold
243 .getSequenceRecords(alphafold.getTestQuery());
245 assertEquals("One sequence only", resp.getHeight(), 1);
246 for (AlignmentAnnotation aa : resp.getAlignmentAnnotation())
248 if (aa.graph == AlignmentAnnotation.CONTACT_MAP)
250 assertTrue("Contact map didn't provide valid contact",
251 resp.getContactListFor(aa, 1).getContactAt(1) != -1d);
256 Assert.fail("No pAE matrix found for alphafold structure.");