Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 18:06:40 GMT
  2. Package jalview.ws.dbsources

File RemoteFormatTest.java

 

Code metrics

0
35
4
1
142
94
4
0.11
8.75
4
1

Classes

Class Line # Actions
RemoteFormatTest 60 35 4
0.1282051412.8%
 

Contributing tests

No tests hitting this source file were found.

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.dbsources;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertNotNull;
26    import static org.testng.Assert.assertTrue;
27   
28    import jalview.analysis.AlignSeq;
29    import jalview.bin.Cache;
30    import jalview.datamodel.AlignmentI;
31    import jalview.datamodel.DBRefSource;
32    import jalview.datamodel.SequenceI;
33    import jalview.ext.ensembl.EnsemblGenomes;
34    import jalview.fts.api.FTSData;
35    import jalview.fts.api.FTSDataColumnI;
36    import jalview.fts.api.FTSRestClientI;
37    import jalview.fts.core.FTSRestRequest;
38    import jalview.fts.core.FTSRestResponse;
39    import jalview.fts.service.uniprot.UniProtFTSRestClient;
40    import jalview.ws.SequenceFetcher;
41    import jalview.ws.seqfetcher.DbSourceProxy;
42   
43    import java.util.ArrayList;
44    import java.util.List;
45   
46    import org.testng.annotations.BeforeTest;
47    import org.testng.annotations.DataProvider;
48    import org.testng.annotations.Test;
49   
50    /**
51    * A class to verify that remotely fetched data has an expected format and can
52    * be successfully processed by Jalview. This is intended as a first line of
53    * defence and early warning of service affecting changes to data fetched
54    * externally.
55    * <p>
56    * This is class is not intended to cover remote services e.g. alignment. Nor
57    * should it duplicate tests already provided by other classes (such as
58    * PDBFTSRestClientTest). Or maybe we will relocate those tests here...
59    */
 
60    public class RemoteFormatTest
61    {
62    SequenceFetcher sf;
63   
 
64  4 toggle @BeforeTest(alwaysRun = true)
65    public void setUp() throws Exception
66    {
67  4 Cache.loadProperties("test/jalview/io/testProps.jvprops");
68    // ensure 'add annotation from structure' is selected
69  4 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
70    Boolean.TRUE.toString());
71  4 Cache.applicationProperties.setProperty("ADD_SS_ANN",
72    Boolean.TRUE.toString());
73   
74  4 sf = new SequenceFetcher();
75    }
76   
 
77  0 toggle @DataProvider(name = "AccessionData")
78    protected Object[][] getAccessions()
79    {
80  0 return new Object[][] { { DBRefSource.UNIPROT, "P30419" },
81    { DBRefSource.PDB, "1QIP" },
82    { DBRefSource.EMBL, "X53828" },
83    { DBRefSource.EMBLCDS, "CAA37824" },
84    { DBRefSource.ENSEMBL, "ENSG00000157764" },
85    { new EnsemblGenomes().getDbSource(), "DDB_G0283883" },
86    { new PfamFull().getDbSource(), "PF03760" },
87    { new PfamSeed().getDbSource(), "PF03760" },
88    { new RfamSeed().getDbSource(), "RF00014" } };
89    }
90   
 
91  0 toggle @Test(groups = "Network", dataProvider = "AccessionData")
92    public void testFetchAccession(String dbSource, String accessionId)
93    throws Exception
94    {
95  0 System.out.println("Fetching " + accessionId + " from " + dbSource);
96  0 List<DbSourceProxy> sps = sf.getSourceProxy(dbSource);
97  0 assertFalse(sps.isEmpty());
98  0 AlignmentI al = sps.get(0).getSequenceRecords(accessionId);
99  0 assertNotNull(al);
100  0 assertTrue(al.getHeight() > 0);
101  0 SequenceI sq = al.getSequenceAt(0);
102    // suppress this check as only Uniprot and PDB acquire PDB refs
103    // assertTrue(sq.getAllPDBEntries().size() > 0, "No PDBEntry on sequence.");
104  0 assertTrue(sq.getDBRefs().size() > 0, "No DBRef on sequence.");
105    // suppress this test as only certain databases provide 'primary' dbrefs
106    // assertFalse(sq.getPrimaryDBRefs().isEmpty());
107  0 int length = AlignSeq.extractGaps("-. ", sq.getSequenceAsString())
108    .length();
109  0 assertEquals(sq.getEnd() - sq.getStart() + 1, length,
110    "Sequence start/end doesn't match number of residues in sequence");
111    }
112   
 
113  0 toggle @Test(groups = { "Network" })
114    public void testUniprotFreeTextSearch() throws Exception
115    {
116  0 List<FTSDataColumnI> wantedFields = new ArrayList<>();
117  0 FTSRestClientI client = UniProtFTSRestClient.getInstance();
118  0 wantedFields.add(client.getDataColumnByNameOrCode("id"));
119  0 wantedFields.add(client.getDataColumnByNameOrCode("entry name"));
120  0 wantedFields.add(client.getDataColumnByNameOrCode("organism"));
121  0 wantedFields.add(client.getDataColumnByNameOrCode("reviewed")); // Status
122  0 wantedFields.add(client.getDataColumnByNameOrCode("length"));
123   
124  0 FTSRestRequest request = new FTSRestRequest();
125  0 request.setAllowEmptySeq(false);
126  0 request.setResponseSize(100);
127  0 request.setFieldToSearchBy("Search All");
128  0 request.setSearchTerm("metanephrops"); // lobster!
129  0 request.setWantedFields(wantedFields);
130   
131  0 FTSRestResponse response;
132  0 response = client.executeRequest(request);
133  0 assertTrue(response.getNumberOfItemsFound() > 20);
134  0 assertTrue(response.getSearchSummary() != null);
135  0 assertTrue(response.getSearchSummary().size() > 20);
136    // verify we successfully filtered out the header row (JAL-2485)
137  0 FTSData header = response.getSearchSummary().iterator().next();
138  0 assertFalse(
139    header.getSummaryData()[0].toString().equalsIgnoreCase("Entry"),
140    "Failed to filter out summary header row");
141    }
142    }