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 PDBFTSRestClient.setMock();
179 StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq});
180 // gets the lightweight proxy rather than the ThreeDBStructureChooserQuerySource
181 AssertJUnit.assertTrue(scquery instanceof ThreeDBStructureChooserQuerySource);
182 String query = scquery.buildQuery(upSeq);
183 AssertJUnit.assertEquals("P38398", query);
185 // query shouldn't change regardless of additional entries
186 // because 3DBeacons requires canonical entries.
187 upSeq.getAllPDBEntries().clear();
188 query = scquery.buildQuery(upSeq);
189 AssertJUnit.assertEquals("P38398", query);
190 upSeq.setDBRefs(null);
191 query = scquery.buildQuery(upSeq);
193 * legacy projects/datasets will not have canonical flags set for uniprot dbrefs
194 * graceful behaviour would be to
195 * - pick one ? not possible
196 * - iterate through all until a 200 is obtained ?
197 * ---> ideal but could be costly
198 * ---> better to do a direct retrieval from uniprot to work out which is the canonical identifier..
199 * ----> need a test to check that accessions can be promoted to canonical!
201 //FIXME - need to be able to use ID to query here ?
202 AssertJUnit.assertEquals(null, query);
209 * - no protein -> TDB not applicable, query PDBe only (consider RNA or DNA - specific query adapter ?)
210 * - protein but no uniprot -> first consider trying to get uniprot refs (need a mark to say none are available)
211 * - protein and uniprot - no canonicals -> resolve to uniprot automatically to get canonicals
212 * - query uniprot against 3DBeacons
213 * --> decorate experimental structures with additional data from PDBe
214 * - query remaining against PDBe
217 * --> in memory ranking - no need to query twice
219 * - experimental > AlphaFold -> Model
222 * -> experimental only
223 * -> experimental plus best models for other regions
225 * -> need to be able to select correct reference (the longest one that covers all) for superposition
228 // DBRefEntry uniprotDBRef = new DBRefEntry();
229 // uniprotDBRef.setAccessionId("P12345");
230 // uniprotDBRef.setSource(DBRefSource.UNIPROT);
231 // upSeq.addDBRef(uniprotDBRef);
233 // DBRefEntry pdbDBRef = new DBRefEntry();
234 // pdbDBRef.setAccessionId("1XYZ");
235 // pdbDBRef.setSource(DBRefSource.PDB);
236 // upSeq.addDBRef(pdbDBRef);
238 // for (int x = 1; x < 5; x++)
240 // DBRefEntry dbRef = new DBRefEntry();
241 // dbRef.setAccessionId("XYZ_" + x);
242 // seq.addDBRef(dbRef);
244 // System.out.println("");
245 // System.out.println(seq.getDBRefs());
246 // System.out.println(query);
247 // query = scquery.buildQuery(seq);
249 // "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
252 @Test(groups= {"Functional"})
253 public void cascadingThreeDBandPDBQuerys()
255 TDBeaconsFTSRestClientTest.setMock();
256 PDBFTSRestClient.setMock();
257 ThreeDBStructureChooserQuerySource tdbquery = new ThreeDBStructureChooserQuerySource();
258 PDBStructureChooserQuerySource pdbquery = new PDBStructureChooserQuerySource();
262 FTSRestResponse upResponse = null;
263 FTSRestResponse pdbResponse = null;
266 upResponse = tdbquery.fetchStructuresMetaData(upSeq, tdbquery.getDocFieldPrefs().getStructureSummaryFields(), null, false);
267 // test ranking without additional PDBe data
268 FTSRestResponse firstRanked = tdbquery.selectFirstRankedQuery(upSeq, upResponse.getSearchSummary(), tdbquery.getDocFieldPrefs().getStructureSummaryFields(), "", false);
269 assertTrue(firstRanked.getNumberOfItemsFound()<upResponse.getNumberOfItemsFound());
270 // NB Could have race condition here
271 String pdb_Query = tdbquery.buildPDBFTSQueryFor(upResponse);
272 assertTrue(pdb_Query.trim().length()>0);
273 pdbResponse = tdbquery.fetchStructuresMetaDataFor(pdbquery, upResponse);
274 assertTrue(pdbResponse.getNumberOfItemsFound()>0);
275 FTSRestResponse joinedResp = tdbquery.joinResponses(upResponse, pdbResponse);
276 assertEquals(upResponse.getNumberOfItemsFound(),joinedResp.getNumberOfItemsFound());
279 } catch (Exception x)
282 Assert.fail("Unexpected Exception");
284 StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq});
288 @Test(groups = { "Functional" })
289 public void sanitizeSeqNameTest()
291 String name = "ab_cdEF|fwxyz012349";
292 AssertJUnit.assertEquals(name, PDBStructureChooserQuerySource.sanitizeSeqName(name));
294 // remove a [nn] substring
295 name = "abcde12[345]fg";
296 AssertJUnit.assertEquals("abcde12fg", PDBStructureChooserQuerySource.sanitizeSeqName(name));
298 // remove characters other than a-zA-Z0-9 | or _
299 name = "ab[cd],.\t£$*!- \\\"@:e";
300 AssertJUnit.assertEquals("abcde", PDBStructureChooserQuerySource.sanitizeSeqName(name));
302 name = "abcde12[345a]fg";
303 AssertJUnit.assertEquals("abcde12345afg", PDBStructureChooserQuerySource.sanitizeSeqName(name));