Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ws.seqfetcher

File DbRefFetcherTest.java

 

Code metrics

6
51
7
1
205
134
11
0.22
7.29
7
1.57

Classes

Class Line # Actions
DbRefFetcherTest 53 51 11 32
0.550%
 

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 jalview.analysis.CrossRef;
29    import jalview.datamodel.AlignmentI;
30    import jalview.datamodel.DBRefEntry;
31    import jalview.datamodel.DBRefSource;
32    import jalview.datamodel.FeatureProperties;
33    import jalview.datamodel.SequenceFeature;
34    import jalview.datamodel.SequenceI;
35    import jalview.gui.JvOptionPane;
36    import jalview.util.DBRefUtils;
37    import jalview.ws.SequenceFetcher;
38    import jalview.ws.dbsources.Pdb;
39    import jalview.ws.dbsources.Uniprot;
40   
41    import java.util.ArrayList;
42    import java.util.Arrays;
43    import java.util.List;
44   
45    import org.testng.annotations.AfterClass;
46    import org.testng.annotations.BeforeClass;
47    import org.testng.annotations.Test;
48   
49    /**
50    * @author jimp
51    *
52    */
 
53    public class DbRefFetcherTest
54    {
55   
 
56  1 toggle @BeforeClass(alwaysRun = true)
57    public void setUpJvOptionPane()
58    {
59  1 JvOptionPane.setInteractiveMode(false);
60  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
61    }
62   
63    /**
64    * @throws java.lang.Exception
65    */
 
66  1 toggle @BeforeClass(alwaysRun = true)
67    public static void setUpBeforeClass() throws Exception
68    {
69  1 jalview.bin.Cache.initLogger();
70    }
71   
72    /**
73    * @throws java.lang.Exception
74    */
 
75  1 toggle @AfterClass(alwaysRun = true)
76    public static void tearDownAfterClass() throws Exception
77    {
78    }
79   
80    /**
81    * Tests that standard protein database sources include Uniprot (as the first)
82    * and also PDB. (Additional sources are dependent on availability of DAS
83    * services.)
84    */
 
85  1 toggle @Test(groups = { "Functional" })
86    public void testStandardProtDbs()
87    {
88  1 List<String> defdb = new ArrayList<String>();
89  1 defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS));
90  1 defdb.add(DBRefSource.PDB);
91  1 List<DbSourceProxy> srces = new ArrayList<DbSourceProxy>();
92  1 SequenceFetcher sfetcher = new SequenceFetcher();
93  1 boolean pdbFound = false;
94   
95  1 for (String ddb : defdb)
96    {
97  5 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
98   
99  5 if (srcesfordb != null)
100    {
101    // TODO is this right? get duplicate entries
102  5 srces.addAll(srcesfordb);
103    }
104    }
105   
106  1 int i = 0;
107  1 int uniprotPos = -1;
108  1 for (DbSourceProxy s : srces)
109    {
110  4 if (s instanceof Uniprot && uniprotPos == -1)
111    {
112  1 uniprotPos = i;
113    }
114  4 if (s instanceof Pdb)
115    {
116  1 pdbFound = true;
117    }
118  4 i++;
119    }
120   
121  1 assertTrue("Failed to find Uniprot source as first source amongst "
122    + srces.size() + " sources (source was at position "
123    + uniprotPos + ")", uniprotPos == 0);
124  1 assertTrue("Failed to find PDB source amongst " + srces.size()
125    + " sources", pdbFound);
126    }
127   
128    /**
129    * Tests retrieval of one entry from EMBL. Test is dependent on availability
130    * of network and the EMBL service.
131    *
132    * @throws Exception
133    */
 
134  0 toggle @Test(groups = { "External" })
135    public void testEmblUniprotProductRecovery() throws Exception
136    {
137  0 String retrievalId = "V00488";
138  0 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
139    DBRefSource.EMBL).get(0);
140  0 assertNotNull("Couldn't find the EMBL retrieval client", embl);
141  0 verifyProteinNucleotideXref(retrievalId, embl);
142    }
143   
144    /**
145    * Tests retrieval of one entry from EMBLCDS. Test is dependent on
146    * availability of network and the EMBLCDS service.
147    *
148    * @throws Exception
149    */
 
150  0 toggle @Test(groups = { "External" })
151    public void testEmblCDSUniprotProductRecovery() throws Exception
152    {
153  0 String retrievalId = "AAH29712";
154  0 DbSourceProxy embl = new SequenceFetcher().getSourceProxy(
155    DBRefSource.EMBLCDS).get(0);
156  0 assertNotNull("Couldn't find the EMBL retrieval client", embl);
157  0 verifyProteinNucleotideXref(retrievalId, embl);
158    }
159   
160    /**
161    * Helper method to perform database retrieval and verification of results.
162    *
163    * @param retrievalId
164    * @param embl
165    * @throws Exception
166    */
 
167  0 toggle private void verifyProteinNucleotideXref(String retrievalId,
168    DbSourceProxy embl) throws Exception
169    {
170  0 AlignmentI alsq = embl.getSequenceRecords(retrievalId);
171  0 assertNotNull("Couldn't find the EMBL record " + retrievalId, alsq);
172  0 assertEquals("Didn't retrieve right number of records", 1,
173    alsq.getHeight());
174  0 SequenceI seq = alsq.getSequenceAt(0);
175  0 assertEquals("Wrong sequence name", embl.getDbSource() + "|"
176    + retrievalId, seq.getName());
177  0 List<SequenceFeature> sfs = seq.getSequenceFeatures();
178  0 assertFalse("Sequence features missing", sfs.isEmpty());
179  0 assertTrue(
180    "Feature not CDS",
181    FeatureProperties.isCodingFeature(embl.getDbSource(),
182    sfs.get(0).getType()));
183  0 assertEquals(embl.getDbSource(), sfs.get(0).getFeatureGroup());
184  0 DBRefEntry[] dr = DBRefUtils.selectRefs(seq.getDBRefs(),
185    new String[] { DBRefSource.UNIPROT });
186  0 assertNotNull(dr);
187  0 assertEquals("Expected a single Uniprot cross reference", 1, dr.length);
188  0 assertEquals("Expected cross reference map to be one amino acid", dr[0]
189    .getMap().getMappedWidth(), 1);
190  0 assertEquals("Expected local reference map to be 3 nucleotides", dr[0]
191    .getMap().getWidth(), 3);
192  0 AlignmentI sprods = new CrossRef(alsq.getSequencesArray(), alsq)
193    .findXrefSequences(dr[0].getSource(), true);
194  0 assertNotNull(
195    "Couldn't recover cross reference sequence from dataset. Was it ever added ?",
196    sprods);
197  0 assertEquals("Didn't xref right number of records", 1,
198    sprods.getHeight());
199  0 SequenceI proteinSeq = sprods.getSequenceAt(0);
200  0 assertEquals(proteinSeq.getSequenceAsString(), dr[0].getMap().getTo()
201    .getSequenceAsString());
202  0 assertEquals(dr[0].getSource() + "|" + dr[0].getAccessionId(),
203    proteinSeq.getName());
204    }
205    }