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.Assert.assertNotEquals;
24 import static org.testng.AssertJUnit.assertEquals;
25 import static org.testng.AssertJUnit.assertFalse;
26 import static org.testng.AssertJUnit.assertNotNull;
27 import static org.testng.AssertJUnit.assertTrue;
29 import jalview.analysis.CrossRef;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.DBRefEntry;
33 import jalview.datamodel.DBRefSource;
34 import jalview.datamodel.FeatureProperties;
35 import jalview.datamodel.SequenceFeature;
36 import jalview.datamodel.SequenceI;
37 import jalview.gui.JvOptionPane;
38 import jalview.util.DBRefUtils;
39 import jalview.ws.SequenceFetcher;
40 import jalview.ws.dbsources.EBIAlfaFold;
41 import jalview.ws.dbsources.Pdb;
42 import jalview.ws.dbsources.Uniprot;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.List;
48 import org.junit.Assert;
49 import org.testng.annotations.AfterClass;
50 import org.testng.annotations.BeforeClass;
51 import org.testng.annotations.Test;
57 public class DbRefFetcherTest
60 @BeforeClass(alwaysRun = true)
61 public void setUpJvOptionPane()
63 JvOptionPane.setInteractiveMode(false);
64 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
68 * @throws java.lang.Exception
70 @BeforeClass(alwaysRun = true)
71 public static void setUpBeforeClass() throws Exception
73 jalview.bin.Cache.initLogger();
77 * @throws java.lang.Exception
79 @AfterClass(alwaysRun = true)
80 public static void tearDownAfterClass() throws Exception
85 * Tests that standard protein database sources include Uniprot (as the first)
86 * and also PDB. (Additional sources are dependent on availability of DAS
89 @Test(groups = { "Functional" })
90 public void testStandardProtDbs()
92 List<String> defdb = new ArrayList<String>();
93 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
94 defdb.add(DBRefSource.PDB);
95 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
96 SequenceFetcher sfetcher = new SequenceFetcher();
97 boolean pdbFound = false;
99 for (String ddb : defdb)
101 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
103 if (srcesfordb != null)
105 // TODO is this right? get duplicate entries
106 srces.addAll(srcesfordb);
112 for (DbSourceProxy s : srces)
114 if (s instanceof Uniprot && uniprotPos == -1)
118 if (s instanceof Pdb)
125 assertTrue("Failed to find Uniprot source as first source amongst "
126 + srces.size() + " sources (source was at position "
127 + uniprotPos + ")", uniprotPos == 0);
128 assertTrue("Failed to find PDB source amongst " + srces.size()
129 + " sources", pdbFound);
133 * Tests retrieval of one entry from EMBL. Test is dependent on availability
134 * of network and the EMBL service.
138 @Test(groups = { "External" })
139 public void testEmblUniprotProductRecovery() throws Exception
141 String retrievalId = "V00488";
142 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
143 DBRefSource.EMBL).get(0);
144 assertNotNull("Couldn't find the EMBL retrieval client", embl);
145 verifyProteinNucleotideXref(retrievalId, embl);
149 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
150 * availability of network and the EMBLCDS service.
154 @Test(groups = { "External" })
155 public void testEmblCDSUniprotProductRecovery() throws Exception
157 String retrievalId = "AAH29712";
158 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
159 DBRefSource.EMBLCDS).get(0);
160 assertNotNull("Couldn't find the EMBL retrieval client", embl);
161 verifyProteinNucleotideXref(retrievalId, embl);
165 * Helper method to perform database retrieval and verification of results.
171 private void verifyProteinNucleotideXref(String retrievalId,
172 DbSourceProxy embl) throws Exception
174 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
175 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
176 assertEquals("Didn't retrieve right number of records", 1,
178 SequenceI seq = alsq.getSequenceAt(0);
179 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
180 + retrievalId, seq.getName());
181 List<SequenceFeature> sfs = seq.getSequenceFeatures();
182 assertFalse("Sequence features missing", sfs.isEmpty());
185 FeatureProperties.isCodingFeature(embl.getDbSource(),
186 sfs.get(0).getType()));
187 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
188 List<DBRefEntry> dr = DBRefUtils.selectRefs(seq.getDBRefs(),
189 new String[] { DBRefSource.UNIPROT });
191 assertEquals("Expected a single Uniprot cross reference", 1, dr.size());
192 assertEquals("Expected cross reference map to be one amino acid", dr.get(0)
193 .getMap().getMappedWidth(), 1);
194 assertEquals("Expected local reference map to be 3 nucleotides", dr.get(0)
195 .getMap().getWidth(), 3);
196 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
197 .findXrefSequences(dr.get(0).getSource(), true);
199 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
201 assertEquals("Didn't xref right number of records", 1,
203 SequenceI proteinSeq = sprods.getSequenceAt(0);
204 assertEquals(proteinSeq.getSequenceAsString(), dr.get(0).getMap().getTo()
205 .getSequenceAsString());
206 assertEquals(dr.get(0).getSource() + "|" + dr.get(0).getAccessionId(),
207 proteinSeq.getName());
211 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
212 * availability of network and the EMBLCDS service.
216 @Test(groups = { "External" })
217 public void testAlphaFoldClien() throws Exception
219 DbSourceProxy alphafold = new EBIAlfaFold();
220 AlignmentI resp = alphafold.getSequenceRecords(alphafold.getTestQuery());
222 assertEquals("One sequence only",resp.getHeight(), 1);
223 for (AlignmentAnnotation aa:resp.getAlignmentAnnotation()) {
224 if (aa.graph == AlignmentAnnotation.CUSTOMRENDERER)
226 assertTrue("Contact map didn't provide valid contact",resp.getContactListFor(aa, 1).getContactAt(1)!=-1d);