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.Sequence;
36 import jalview.datamodel.SequenceFeature;
37 import jalview.datamodel.SequenceI;
38 import jalview.gui.JvOptionPane;
39 import jalview.util.DBRefUtils;
40 import jalview.ws.DBRefFetcher;
41 import jalview.ws.SequenceFetcher;
42 import jalview.ws.dbsources.EBIAlfaFold;
43 import jalview.ws.dbsources.Pdb;
44 import jalview.ws.dbsources.Uniprot;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import java.util.List;
50 import org.junit.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.BeforeClass;
53 import org.testng.annotations.Test;
59 public class DbRefFetcherTest
62 @BeforeClass(alwaysRun = true)
63 public void setUpJvOptionPane()
65 JvOptionPane.setInteractiveMode(false);
66 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
70 * @throws java.lang.Exception
72 @BeforeClass(alwaysRun = true)
73 public static void setUpBeforeClass() throws Exception
75 jalview.bin.Console.initLogger();
79 * @throws java.lang.Exception
81 @AfterClass(alwaysRun = true)
82 public static void tearDownAfterClass() throws Exception
86 @Test(groups = { "Network" })
87 public void checkUniprotCanonicalFlagSet()
89 // TODO - mock this - for moment it is a live request.
90 SequenceI uniprotSeq = new Sequence("FER1_SPIOL",
91 "MAATTTTMMGMATTFVPKPQAPPMMAALPSNTGRSLFGLKTGSRGGRMTMAAYKVTLVTPTGNVEFQCPDDV"
92 + "YILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEE"
94 DBRefFetcher dbr = new DBRefFetcher(new SequenceI[] { uniprotSeq });
95 dbr.fetchDBRefs(true);
96 List<DBRefEntry> primRefs = uniprotSeq.getPrimaryDBRefs();
97 assertNotNull(primRefs);
98 assertTrue(primRefs.size() > 0);
99 boolean canonicalUp = false;
100 for (DBRefEntry ref : primRefs)
102 assertEquals(DBRefSource.UNIPROT, ref.getCanonicalSourceName());
103 canonicalUp |= ref.isCanonical();
105 assertTrue("No Canonical Uniprot reference detected", canonicalUp);
109 * Tests that standard protein database sources include Uniprot (as the first)
110 * and also PDB. (Additional sources are dependent on availability of DAS
113 @Test(groups = { "Functional" })
114 public void testStandardProtDbs()
116 List<String> defdb = new ArrayList<String>();
117 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
118 defdb.add(DBRefSource.PDB);
119 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
120 SequenceFetcher sfetcher = new SequenceFetcher();
121 boolean pdbFound = false;
123 for (String ddb : defdb)
125 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
127 if (srcesfordb != null)
129 // TODO is this right? get duplicate entries
130 srces.addAll(srcesfordb);
136 for (DbSourceProxy s : srces)
138 if (s instanceof Uniprot && uniprotPos == -1)
142 if (s instanceof Pdb)
149 assertTrue("Failed to find Uniprot source as first source amongst "
150 + srces.size() + " sources (source was at position "
151 + uniprotPos + ")", uniprotPos == 0);
152 assertTrue("Failed to find PDB source amongst " + srces.size()
153 + " sources", pdbFound);
157 * Tests retrieval of one entry from EMBL. Test is dependent on availability
158 * of network and the EMBL service.
162 @Test(groups = { "External" })
163 public void testEmblUniprotProductRecovery() throws Exception
165 String retrievalId = "V00488";
166 DbSourceProxy embl = new SequenceFetcher()
167 .getSourceProxy(DBRefSource.EMBL).get(0);
168 assertNotNull("Couldn't find the EMBL retrieval client", embl);
169 verifyProteinNucleotideXref(retrievalId, embl);
173 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
174 * availability of network and the EMBLCDS service.
178 @Test(groups = { "External" })
179 public void testEmblCDSUniprotProductRecovery() throws Exception
181 String retrievalId = "AAH29712";
182 DbSourceProxy embl = new SequenceFetcher()
183 .getSourceProxy(DBRefSource.EMBLCDS).get(0);
184 assertNotNull("Couldn't find the EMBL retrieval client", embl);
185 verifyProteinNucleotideXref(retrievalId, embl);
189 * Helper method to perform database retrieval and verification of results.
195 private void verifyProteinNucleotideXref(String retrievalId,
196 DbSourceProxy embl) throws Exception
198 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
199 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
200 assertEquals("Didn't retrieve right number of records", 1,
202 SequenceI seq = alsq.getSequenceAt(0);
203 assertEquals("Wrong sequence name",
204 embl.getDbSource() + "|" + retrievalId, seq.getName());
205 List<SequenceFeature> sfs = seq.getSequenceFeatures();
206 assertFalse("Sequence features missing", sfs.isEmpty());
207 assertTrue("Feature not CDS", FeatureProperties
208 .isCodingFeature(embl.getDbSource(), sfs.get(0).getType()));
209 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
210 List<DBRefEntry> dr = DBRefUtils.selectRefs(seq.getDBRefs(),
212 { DBRefSource.UNIPROT });
214 assertEquals("Expected a single Uniprot cross reference", 1, dr.size());
215 assertEquals("Expected cross reference map to be one amino acid",
216 dr.get(0).getMap().getMappedWidth(), 1);
217 assertEquals("Expected local reference map to be 3 nucleotides",
218 dr.get(0).getMap().getWidth(), 3);
219 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
220 .findXrefSequences(dr.get(0).getSource(), true);
222 "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
224 assertEquals("Didn't xref right number of records", 1,
226 SequenceI proteinSeq = sprods.getSequenceAt(0);
227 assertEquals(proteinSeq.getSequenceAsString(),
228 dr.get(0).getMap().getTo().getSequenceAsString());
229 assertEquals(dr.get(0).getSource() + "|" + dr.get(0).getAccessionId(),
230 proteinSeq.getName());
234 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
235 * availability of network and the EMBLCDS service.
239 @Test(groups = { "External" })
240 public void testAlphaFoldClien() throws Exception
242 DbSourceProxy alphafold = new EBIAlfaFold();
243 AlignmentI resp = alphafold.getSequenceRecords(alphafold.getTestQuery());
245 assertEquals("One sequence only",resp.getHeight(), 1);
246 for (AlignmentAnnotation aa:resp.getAlignmentAnnotation()) {
247 if (aa.graph == AlignmentAnnotation.CUSTOMRENDERER)
249 assertTrue("Contact map didn't provide valid contact",resp.getContactListFor(aa, 1).getContactAt(1)!=-1d);