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.gui.structurechooser;
24 import static org.testng.Assert.assertEquals;
25 import static org.testng.Assert.assertTrue;
27 import java.util.Collection;
28 import java.util.Vector;
30 import org.junit.Assert;
31 import org.testng.AssertJUnit;
32 import org.testng.annotations.AfterMethod;
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
37 import jalview.datamodel.DBRefEntry;
38 import jalview.datamodel.DBRefSource;
39 import jalview.datamodel.PDBEntry;
40 import jalview.datamodel.Sequence;
41 import jalview.datamodel.SequenceI;
42 import jalview.fts.api.FTSData;
43 import jalview.fts.core.FTSRestRequest;
44 import jalview.fts.core.FTSRestResponse;
45 import jalview.fts.service.pdb.PDBFTSRestClient;
46 import jalview.fts.threedbeacons.TDBeaconsFTSRestClientTest;
47 import jalview.gui.JvOptionPane;
48 import jalview.jbgui.FilterOption;
50 public class StructureChooserQuerySourceTest
53 @BeforeClass(alwaysRun = true)
54 public void setUpJvOptionPane()
56 JvOptionPane.setInteractiveMode(false);
57 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
62 // same set up as for structurechooser test
64 @BeforeMethod(alwaysRun = true)
65 public void setUp() throws Exception
67 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
69 seq.createDatasetSequence();
70 for (int x = 1; x < 5; x++)
72 DBRefEntry dbRef = new DBRefEntry();
73 dbRef.setAccessionId("XYZ_" + x);
77 PDBEntry dbRef = new PDBEntry();
80 Vector<PDBEntry> pdbIds = new Vector<>();
85 // Uniprot sequence for 3D-Beacons mocks
86 upSeq = new Sequence("P38398",
87 "MDLSALRVEEVQNVINAMQKILECPICLELIKEPVSTKCDHIFCKFCMLKLLNQKKGPSQCPLCKNDITKRS\n"
88 + "LQESTRFSQLVEELLKIICAFQLDTGLEYANSYNFAKKENNSPEHLKDEVSIIQSMGYRNRAKRLLQSEPEN\n"
89 + "PSLQETSLSVQLSNLGTVRTLRTKQRIQPQKTSVYIELGSDSSEDTVNKATYCSVGDQELLQITPQGTRDEI\n"
90 + "SLDSAKKAACEFSETDVTNTEHHQPSNNDLNTTEKRAAERHPEKYQGSSVSNLHVEPCGTNTHASSLQHENS\n"
91 + "SLLLTKDRMNVEKAEFCNKSKQPGLARSQHNRWAGSKETCNDRRTPSTEKKVDLNADPLCERKEWNKQKLPC\n"
92 + "SENPRDTEDVPWITLNSSIQKVNEWFSRSDELLGSDDSHDGESESNAKVADVLDVLNEVDEYSGSSEKIDLL\n"
93 + "ASDPHEALICKSERVHSKSVESNIEDKIFGKTYRKKASLPNLSHVTENLIIGAFVTEPQIIQERPLTNKLKR\n"
94 + "KRRPTSGLHPEDFIKKADLAVQKTPEMINQGTNQTEQNGQVMNITNSGHENKTKGDSIQNEKNPNPIESLEK\n"
95 + "ESAFKTKAEPISSSISNMELELNIHNSKAPKKNRLRRKSSTRHIHALELVVSRNLSPPNCTELQIDSCSSSE\n"
96 + "EIKKKKYNQMPVRHSRNLQLMEGKEPATGAKKSNKPNEQTSKRHDSDTFPELKLTNAPGSFTKCSNTSELKE\n"
97 + "FVNPSLPREEKEEKLETVKVSNNAEDPKDLMLSGERVLQTERSVESSSISLVPGTDYGTQESISLLEVSTLG\n"
98 + "KAKTEPNKCVSQCAAFENPKGLIHGCSKDNRNDTEGFKYPLGHEVNHSRETSIEMEESELDAQYLQNTFKVS\n"
99 + "KRQSFAPFSNPGNAEEECATFSAHSGSLKKQSPKVTFECEQKEENQGKNESNIKPVQTVNITAGFPVVGQKD\n"
100 + "KPVDNAKCSIKGGSRFCLSSQFRGNETGLITPNKHGLLQNPYRIPPLFPIKSFVKTKCKKNLLEENFEEHSM\n"
101 + "SPEREMGNENIPSTVSTISRNNIRENVFKEASSSNINEVGSSTNEVGSSINEIGSSDENIQAELGRNRGPKL\n"
102 + "NAMLRLGVLQPEVYKQSLPGSNCKHPEIKKQEYEEVVQTVNTDFSPYLISDNLEQPMGSSHASQVCSETPDD\n"
103 + "LLDDGEIKEDTSFAENDIKESSAVFSKSVQKGELSRSPSPFTHTHLAQGYRRGAKKLESSEENLSSEDEELP\n"
104 + "CFQHLLFGKVNNIPSQSTRHSTVATECLSKNTEENLLSLKNSLNDCSNQVILAKASQEHHLSEETKCSASLF\n"
105 + "SSQCSELEDLTANTNTQDPFLIGSSKQMRHQSESQGVGLSDKELVSDDEERGTGLEENNQEEQSMDSNLGEA\n"
106 + "ASGCESETSVSEDCSGLSSQSDILTTQQRDTMQHNLIKLQQEMAELEAVLEQHGSQPSNSYPSIISDSSALE\n"
107 + "DLRNPEQSTSEKAVLTSQKSSEYPISQNPEGLSADKFEVSADSSTSKNKEPGVERSSPSKCPSLDDRWYMHS\n"
108 + "CSGSLQNRNYPSQEELIKVVDVEEQQLEESGPHDLTETSYLPRQDLEGTPYLESGISLFSDDPESDPSEDRA\n"
109 + "PESARVGNIPSSTSALKVPQLKVAESAQSPAAAHTTDTAGYNAMEESVSREKPELTASTERVNKRMSMVVSG\n"
110 + "LTPEEFMLVYKFARKHHITLTNLITEETTHVVMKTDAEFVCERTLKYFLGIAGGKWVVSYFWVTQSIKERKM\n"
111 + "LNEHDFEVRGDVVNGRNHQGPKRARESQDRKIFRGLEICCYGPFTNMPTDQLEWMVQLCGASVVKELSSFTL\n"
112 + "GTGVHPIVVVQPDAWTEDNGFHAIGQMCEAPVVTREWVLDSVALYQCQELDTYLIPQIPHSHY\n"
115 upSeq.createDatasetSequence();
116 upSeq.setDescription("Breast cancer type 1 susceptibility protein");
117 upSeq.addDBRef(new DBRefEntry("UNIPROT","0","P38398",null,true));
120 @AfterMethod(alwaysRun = true)
121 public void tearDown() throws Exception
127 @SuppressWarnings("deprecation")
128 @Test(groups = { "Functional" })
129 public void buildPDBQueryTest()
131 System.out.println("seq >>>> " + seq);
133 StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { seq});
134 AssertJUnit.assertTrue(scquery instanceof PDBStructureChooserQuerySource);
135 String query = scquery.buildQuery(seq);
136 AssertJUnit.assertEquals("pdb_id:1tim", query);
137 seq.getAllPDBEntries().clear();
138 query = scquery.buildQuery(seq);
139 AssertJUnit.assertEquals(
140 "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy",
143 query = scquery.buildQuery(seq);
144 System.out.println(query);
145 AssertJUnit.assertEquals("text:4kqy", query);
147 DBRefEntry uniprotDBRef = new DBRefEntry();
148 uniprotDBRef.setAccessionId("P12345");
149 uniprotDBRef.setSource(DBRefSource.UNIPROT);
150 seq.addDBRef(uniprotDBRef);
152 DBRefEntry pdbDBRef = new DBRefEntry();
153 pdbDBRef.setAccessionId("1XYZ");
154 pdbDBRef.setSource(DBRefSource.PDB);
155 seq.addDBRef(pdbDBRef);
157 for (int x = 1; x < 5; x++)
159 DBRefEntry dbRef = new DBRefEntry();
160 dbRef.setAccessionId("XYZ_" + x);
163 System.out.println("");
164 System.out.println(seq.getDBRefs());
165 System.out.println(query);
166 query = scquery.buildQuery(seq);
167 AssertJUnit.assertEquals(
168 "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
172 @SuppressWarnings("deprecation")
173 @Test(groups = { "Functional" })
174 public void buildThreeDBQueryTest()
176 System.out.println("seq >>>> " + upSeq);
177 TDBeaconsFTSRestClientTest.setMock();
178 StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq});
179 AssertJUnit.assertTrue(scquery instanceof ThreeDBStructureChooserQuerySource);
180 String query = scquery.buildQuery(upSeq);
181 AssertJUnit.assertEquals("P38398", query);
183 // query shouldn't change regardless of additional entries
184 // because 3DBeacons requires canonical entries.
185 upSeq.getAllPDBEntries().clear();
186 query = scquery.buildQuery(upSeq);
187 AssertJUnit.assertEquals("P38398", query);
188 upSeq.setDBRefs(null);
189 query = scquery.buildQuery(upSeq);
191 * legacy projects/datasets will not have canonical flags set for uniprot dbrefs
192 * graceful behaviour would be to
193 * - pick one ? not possible
194 * - iterate through all until a 200 is obtained ?
195 * ---> ideal but could be costly
196 * ---> better to do a direct retrieval from uniprot to work out which is the canonical identifier..
197 * ----> need a test to check that accessions can be promoted to canonical!
199 //FIXME - need to be able to use ID to query here ?
200 AssertJUnit.assertEquals(null, query);
207 * - no protein -> TDB not applicable, query PDBe only (consider RNA or DNA - specific query adapter ?)
208 * - protein but no uniprot -> first consider trying to get uniprot refs (need a mark to say none are available)
209 * - protein and uniprot - no canonicals -> resolve to uniprot automatically to get canonicals
210 * - query uniprot against 3DBeacons
211 * --> decorate experimental structures with additional data from PDBe
212 * - query remaining against PDBe
215 * --> in memory ranking - no need to query twice
217 * - experimental > AlphaFold -> Model
220 * -> experimental only
221 * -> experimental plus best models for other regions
223 * -> need to be able to select correct reference (the longest one that covers all) for superposition
226 // DBRefEntry uniprotDBRef = new DBRefEntry();
227 // uniprotDBRef.setAccessionId("P12345");
228 // uniprotDBRef.setSource(DBRefSource.UNIPROT);
229 // upSeq.addDBRef(uniprotDBRef);
231 // DBRefEntry pdbDBRef = new DBRefEntry();
232 // pdbDBRef.setAccessionId("1XYZ");
233 // pdbDBRef.setSource(DBRefSource.PDB);
234 // upSeq.addDBRef(pdbDBRef);
236 // for (int x = 1; x < 5; x++)
238 // DBRefEntry dbRef = new DBRefEntry();
239 // dbRef.setAccessionId("XYZ_" + x);
240 // seq.addDBRef(dbRef);
242 // System.out.println("");
243 // System.out.println(seq.getDBRefs());
244 // System.out.println(query);
245 // query = scquery.buildQuery(seq);
247 // "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
250 @Test(groups= {"Functional"})
251 public void cascadingThreeDBandPDBQuerys()
253 TDBeaconsFTSRestClientTest.setMock();
254 PDBFTSRestClient.setMock();
255 ThreeDBStructureChooserQuerySource tdbquery = new ThreeDBStructureChooserQuerySource();
256 PDBStructureChooserQuerySource pdbquery = new PDBStructureChooserQuerySource();
260 FTSRestResponse upResponse = null;
261 FTSRestResponse pdbResponse = null;
264 upResponse = tdbquery.fetchStructuresMetaData(upSeq, tdbquery.getDocFieldPrefs().getStructureSummaryFields(), null, false);
265 // test ranking without additional PDBe data
266 FTSRestResponse firstRanked = tdbquery.selectFirstRankedQuery(upSeq, upResponse.getSearchSummary(), tdbquery.getDocFieldPrefs().getStructureSummaryFields(), "", false);
267 assertTrue(firstRanked.getNumberOfItemsFound()==upResponse.getNumberOfItemsFound());
268 // NB Could have race condition here
269 String pdb_Query = tdbquery.buildPDBFTSQueryFor(upResponse);
270 assertTrue(pdb_Query.trim().length()>0);
271 pdbResponse = tdbquery.fetchStructuresMetaDataFor(pdbquery, upResponse);
272 assertTrue(pdbResponse.getNumberOfItemsFound()>0);
273 FTSRestResponse joinedResp = tdbquery.joinResponses(upResponse, pdbResponse);
274 assertEquals(upResponse.getNumberOfItemsFound(),joinedResp.getNumberOfItemsFound());
277 } catch (Exception x)
280 Assert.fail("Unexpected Exception");
282 StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq});
286 @Test(groups = { "Functional" })
287 public void sanitizeSeqNameTest()
289 String name = "ab_cdEF|fwxyz012349";
290 AssertJUnit.assertEquals(name, PDBStructureChooserQuerySource.sanitizeSeqName(name));
292 // remove a [nn] substring
293 name = "abcde12[345]fg";
294 AssertJUnit.assertEquals("abcde12fg", PDBStructureChooserQuerySource.sanitizeSeqName(name));
296 // remove characters other than a-zA-Z0-9 | or _
297 name = "ab[cd],.\t£$*!- \\\"@:e";
298 AssertJUnit.assertEquals("abcde", PDBStructureChooserQuerySource.sanitizeSeqName(name));
300 name = "abcde12[345a]fg";
301 AssertJUnit.assertEquals("abcde12345afg", PDBStructureChooserQuerySource.sanitizeSeqName(name));