Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 16:21:17 GMT
  2. Package jalview.ws.seqfetcher

File DbRefFetcherTest.java

 

Code metrics

8
71
9
1
259
177
14
0.2
7.89
9
1.56

Classes

Class Line # Actions
DbRefFetcherTest 58 71 14
0.3636363736.4%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ws.seqfetcher;
22   
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;
27   
28    import java.util.ArrayList;
29    import java.util.Arrays;
30    import java.util.List;
31   
32    import org.junit.Assert;
33    import org.testng.annotations.AfterClass;
34    import org.testng.annotations.BeforeClass;
35    import org.testng.annotations.Test;
36   
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;
53   
54    /**
55    * @author jimp
56    *
57    */
 
58    public class DbRefFetcherTest
59    {
60   
 
61  1 toggle @BeforeClass(alwaysRun = true)
62    public void setUpJvOptionPane()
63    {
64  1 JvOptionPane.setInteractiveMode(false);
65  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
66    }
67   
68    /**
69    * @throws java.lang.Exception
70    */
 
71  1 toggle @BeforeClass(alwaysRun = true)
72    public static void setUpBeforeClass() throws Exception
73    {
74  1 jalview.bin.Console.initLogger();
75    }
76   
77    /**
78    * @throws java.lang.Exception
79    */
 
80  1 toggle @AfterClass(alwaysRun = true)
81    public static void tearDownAfterClass() throws Exception
82    {
83    }
84   
 
85  0 toggle @Test(groups = { "Network" })
86    public void checkUniprotCanonicalFlagSet()
87    {
88    // TODO - mock this - for moment it is a live request.
89  0 SequenceI uniprotSeq = new Sequence("FER1_SPIOL",
90    "MAATTTTMMGMATTFVPKPQAPPMMAALPSNTGRSLFGLKTGSRGGRMTMAAYKVTLVTPTGNVEFQCPDDV"
91    + "YILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEE"
92    + "LTA");
93  0 DBRefFetcher dbr = new DBRefFetcher(new SequenceI[] { uniprotSeq });
94  0 dbr.fetchDBRefs(true);
95  0 List<DBRefEntry> primRefs = uniprotSeq.getPrimaryDBRefs();
96  0 assertNotNull(primRefs);
97  0 assertTrue(primRefs.size() > 0);
98  0 boolean canonicalUp = false;
99  0 for (DBRefEntry ref : primRefs)
100    {
101  0 assertEquals(DBRefSource.UNIPROT, ref.getCanonicalSourceName());
102  0 canonicalUp |= ref.isCanonical();
103    }
104  0 assertTrue("No Canonical Uniprot reference detected", canonicalUp);
105    }
106   
107    /**
108    * Tests that standard protein database sources include Uniprot (as the first)
109    * and also PDB. (Additional sources are dependent on availability of DAS
110    * services.)
111    */
 
112  1 toggle @Test(groups = { "Functional" })
113    public void testStandardProtDbs()
114    {
115  1 List<String> defdb = new ArrayList<String>();
116  1 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
117  1 defdb.add(DBRefSource.PDB);
118  1 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
119  1 SequenceFetcher sfetcher = new SequenceFetcher();
120  1 boolean pdbFound = false;
121   
122  1 for (String ddb : defdb)
123    {
124  5 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
125   
126  5 if (srcesfordb != null)
127    {
128    // TODO is this right? get duplicate entries
129  5 srces.addAll(srcesfordb);
130    }
131    }
132   
133  1 int i = 0;
134  1 int uniprotPos = -1;
135  1 for (DbSourceProxy s : srces)
136    {
137  4 if (s instanceof Uniprot && uniprotPos == -1)
138    {
139  1 uniprotPos = i;
140    }
141  4 if (s instanceof Pdb)
142    {
143  1 pdbFound = true;
144    }
145  4 i++;
146    }
147   
148  1 assertTrue("Failed to find Uniprot source as first source amongst "
149    + srces.size() + " sources (source was at position "
150    + uniprotPos + ")", uniprotPos == 0);
151  1 assertTrue("Failed to find PDB source amongst " + srces.size()
152    + " sources", pdbFound);
153    }
154   
155    /**
156    * Tests retrieval of one entry from EMBL. Test is dependent on availability
157    * of network and the EMBL service.
158    *
159    * @throws Exception
160    */
 
161  0 toggle @Test(groups = { "External" })
162    public void testEmblUniprotProductRecovery() throws Exception
163    {
164  0 String retrievalId = "V00488";
165  0 DbSourceProxy embl = new SequenceFetcher()
166    .getSourceProxy(DBRefSource.EMBL).get(0);
167  0 assertNotNull("Couldn't find the EMBL retrieval client", embl);
168  0 verifyProteinNucleotideXref(retrievalId, embl);
169    }
170   
171    /**
172    * Tests retrieval of one entry from EMBLCDS. Test is dependent on
173    * availability of network and the EMBLCDS service.
174    *
175    * @throws Exception
176    */
 
177  0 toggle @Test(groups = { "External" })
178    public void testEmblCDSUniprotProductRecovery() throws Exception
179    {
180  0 String retrievalId = "AAH29712";
181  0 DbSourceProxy embl = new SequenceFetcher()
182    .getSourceProxy(DBRefSource.EMBLCDS).get(0);
183  0 assertNotNull("Couldn't find the EMBL retrieval client", embl);
184  0 verifyProteinNucleotideXref(retrievalId, embl);
185    }
186   
187    /**
188    * Helper method to perform database retrieval and verification of results.
189    *
190    * @param retrievalId
191    * @param embl
192    * @throws Exception
193    */
 
194  0 toggle private void verifyProteinNucleotideXref(String retrievalId,
195    DbSourceProxy embl) throws Exception
196    {
197  0 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
198  0 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
199  0 assertEquals("Didn't retrieve right number of records", 1,
200    alsq.getHeight());
201  0 SequenceI seq = alsq.getSequenceAt(0);
202  0 assertEquals("Wrong sequence name",
203    embl.getDbSource() + "|" + retrievalId, seq.getName());
204  0 List<SequenceFeature> sfs = seq.getSequenceFeatures();
205  0 assertFalse("Sequence features missing", sfs.isEmpty());
206  0 assertTrue("Feature not CDS", FeatureProperties
207    .isCodingFeature(embl.getDbSource(), sfs.get(0).getType()));
208  0 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
209  0 List<DBRefEntry> dr = DBRefUtils.selectRefs(seq.getDBRefs(),
210    new String[]
211    { DBRefSource.UNIPROT });
212  0 assertNotNull(dr);
213  0 assertEquals("Expected a single Uniprot cross reference", 1, dr.size());
214  0 assertEquals("Expected cross reference map to be one amino acid",
215    dr.get(0).getMap().getMappedWidth(), 1);
216  0 assertEquals("Expected local reference map to be 3 nucleotides",
217    dr.get(0).getMap().getWidth(), 3);
218  0 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
219    .findXrefSequences(dr.get(0).getSource(), true);
220  0 assertNotNull(
221    "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
222    sprods);
223  0 assertEquals("Didn't xref right number of records", 1,
224    sprods.getHeight());
225  0 SequenceI proteinSeq = sprods.getSequenceAt(0);
226  0 assertEquals(proteinSeq.getSequenceAsString(),
227    dr.get(0).getMap().getTo().getSequenceAsString());
228  0 assertEquals(dr.get(0).getSource() + "|" + dr.get(0).getAccessionId(),
229    proteinSeq.getName());
230    }
231   
232    /**
233    * Tests retrieval of one entry from EMBLCDS. Test is dependent on
234    * availability of network and the EMBLCDS service.
235    *
236    * @throws Exception
237    */
 
238  0 toggle @Test(groups = { "External" })
239    public void testAlphaFoldClien() throws Exception
240    {
241  0 DbSourceProxy alphafold = new EBIAlfaFold();
242  0 AlignmentI resp = alphafold
243    .getSequenceRecords(alphafold.getTestQuery());
244  0 assertNotNull(resp);
245  0 assertEquals("One sequence only", resp.getHeight(), 1);
246  0 for (AlignmentAnnotation aa : resp.getAlignmentAnnotation())
247    {
248  0 if (aa.graph == AlignmentAnnotation.CONTACT_MAP)
249    {
250  0 assertTrue("Contact map didn't provide valid contact",
251    resp.getContactListFor(aa, 1).getContactAt(1) != -1d);
252    // test passes
253  0 return;
254    }
255    }
256  0 Assert.fail("No pAE matrix found for alphafold structure.");
257    }
258   
259    }