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) {
101 assertEquals(DBRefSource.UNIPROT, ref.getCanonicalSourceName());
102 canonicalUp |= ref.isCanonical();
104 assertTrue("No Canonical Uniprot reference detected", canonicalUp);
107 * Tests that standard protein database sources include Uniprot (as the first)
108 * and also PDB. (Additional sources are dependent on availability of DAS
111 @Test(groups = { "Functional" })
112 public void testStandardProtDbs()
114 List<String> defdb = new ArrayList<String>();
115 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
116 defdb.add(DBRefSource.PDB);
117 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
118 SequenceFetcher sfetcher = new SequenceFetcher();
119 boolean pdbFound = false;
121 for (String ddb : defdb)
123 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
125 if (srcesfordb != null)
127 // TODO is this right? get duplicate entries
128 srces.addAll(srcesfordb);
134 for (DbSourceProxy s : srces)
136 if (s instanceof Uniprot && uniprotPos == -1)
140 if (s instanceof Pdb)
147 assertTrue("Failed to find Uniprot source as first source amongst "
148 + srces.size() + " sources (source was at position "
149 + uniprotPos + ")", uniprotPos == 0);
150 assertTrue("Failed to find PDB source amongst " + srces.size()
151 + " sources", pdbFound);
155 * Tests retrieval of one entry from EMBL. Test is dependent on availability
156 * of network and the EMBL service.
160 @Test(groups = { "External" })
161 public void testEmblUniprotProductRecovery() throws Exception
163 String retrievalId = "V00488";
164 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
165 DBRefSource.EMBL).get(0);
166 assertNotNull("Couldn't find the EMBL retrieval client", embl);
167 verifyProteinNucleotideXref(retrievalId, embl);
171 * Tests retrieval of one entry from EMBLCDS. Test is dependent on
172 * availability of network and the EMBLCDS service.
176 @Test(groups = { "External" })
177 public void testEmblCDSUniprotProductRecovery() throws Exception
179 String retrievalId = "AAH29712";
180 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
181 DBRefSource.EMBLCDS).get(0);
182 assertNotNull("Couldn't find the EMBL retrieval client", embl);
183 verifyProteinNucleotideXref(retrievalId, embl);
187 * Helper method to perform database retrieval and verification of results.
193 private void verifyProteinNucleotideXref(String retrievalId,
194 DbSourceProxy embl) throws Exception
196 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
197 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
198 assertEquals("Didn't retrieve right number of records", 1,
200 SequenceI seq = alsq.getSequenceAt(0);
201 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
202 + retrievalId, seq.getName());
203 List<SequenceFeature> sfs = seq.getSequenceFeatures();
204 assertFalse("Sequence features missing", sfs.isEmpty());
207 FeatureProperties.isCodingFeature(embl.getDbSource(),
208 sfs.get(0).getType()));
209 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
210 List<DBRefEntry> dr = DBRefUtils.selectRefs(seq.getDBRefs(),
211 new String[] { DBRefSource.UNIPROT });
213 assertEquals("Expected a single Uniprot cross reference", 1, dr.size());
214 assertEquals("Expected cross reference map to be one amino acid", dr.get(0)
215 .getMap().getMappedWidth(), 1);
216 assertEquals("Expected local reference map to be 3 nucleotides", dr.get(0)
217 .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(), dr.get(0).getMap().getTo()
227 .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.getSequenceRecords(alphafold.getTestQuery());
244 assertEquals("One sequence only",resp.getHeight(), 1);
245 for (AlignmentAnnotation aa:resp.getAlignmentAnnotation()) {
246 if (aa.graph == AlignmentAnnotation.CUSTOMRENDERER)
248 assertTrue("Contact map didn't provide valid contact",resp.getContactListFor(aa, 1).getContactAt(1)!=-1d);