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.gui.StructureChooser;
49 import jalview.jbgui.FilterOption;
51 public class StructureChooserQuerySourceTest
54 @BeforeClass(alwaysRun = true)
55 public void setUpJvOptionPane()
57 JvOptionPane.setInteractiveMode(false);
58 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
63 // same set up as for structurechooser test
65 @BeforeMethod(alwaysRun = true)
66 public void setUp() throws Exception
68 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
70 seq.createDatasetSequence();
71 for (int x = 1; x < 5; x++)
73 DBRefEntry dbRef = new DBRefEntry();
74 dbRef.setAccessionId("XYZ_" + x);
78 PDBEntry dbRef = new PDBEntry();
81 Vector<PDBEntry> pdbIds = new Vector<>();
86 // Uniprot sequence for 3D-Beacons mocks
87 upSeq = new Sequence("P38398",
88 "MDLSALRVEEVQNVINAMQKILECPICLELIKEPVSTKCDHIFCKFCMLKLLNQKKGPSQCPLCKNDITKRS\n"
89 + "LQESTRFSQLVEELLKIICAFQLDTGLEYANSYNFAKKENNSPEHLKDEVSIIQSMGYRNRAKRLLQSEPEN\n"
90 + "PSLQETSLSVQLSNLGTVRTLRTKQRIQPQKTSVYIELGSDSSEDTVNKATYCSVGDQELLQITPQGTRDEI\n"
91 + "SLDSAKKAACEFSETDVTNTEHHQPSNNDLNTTEKRAAERHPEKYQGSSVSNLHVEPCGTNTHASSLQHENS\n"
92 + "SLLLTKDRMNVEKAEFCNKSKQPGLARSQHNRWAGSKETCNDRRTPSTEKKVDLNADPLCERKEWNKQKLPC\n"
93 + "SENPRDTEDVPWITLNSSIQKVNEWFSRSDELLGSDDSHDGESESNAKVADVLDVLNEVDEYSGSSEKIDLL\n"
94 + "ASDPHEALICKSERVHSKSVESNIEDKIFGKTYRKKASLPNLSHVTENLIIGAFVTEPQIIQERPLTNKLKR\n"
95 + "KRRPTSGLHPEDFIKKADLAVQKTPEMINQGTNQTEQNGQVMNITNSGHENKTKGDSIQNEKNPNPIESLEK\n"
96 + "ESAFKTKAEPISSSISNMELELNIHNSKAPKKNRLRRKSSTRHIHALELVVSRNLSPPNCTELQIDSCSSSE\n"
97 + "EIKKKKYNQMPVRHSRNLQLMEGKEPATGAKKSNKPNEQTSKRHDSDTFPELKLTNAPGSFTKCSNTSELKE\n"
98 + "FVNPSLPREEKEEKLETVKVSNNAEDPKDLMLSGERVLQTERSVESSSISLVPGTDYGTQESISLLEVSTLG\n"
99 + "KAKTEPNKCVSQCAAFENPKGLIHGCSKDNRNDTEGFKYPLGHEVNHSRETSIEMEESELDAQYLQNTFKVS\n"
100 + "KRQSFAPFSNPGNAEEECATFSAHSGSLKKQSPKVTFECEQKEENQGKNESNIKPVQTVNITAGFPVVGQKD\n"
101 + "KPVDNAKCSIKGGSRFCLSSQFRGNETGLITPNKHGLLQNPYRIPPLFPIKSFVKTKCKKNLLEENFEEHSM\n"
102 + "SPEREMGNENIPSTVSTISRNNIRENVFKEASSSNINEVGSSTNEVGSSINEIGSSDENIQAELGRNRGPKL\n"
103 + "NAMLRLGVLQPEVYKQSLPGSNCKHPEIKKQEYEEVVQTVNTDFSPYLISDNLEQPMGSSHASQVCSETPDD\n"
104 + "LLDDGEIKEDTSFAENDIKESSAVFSKSVQKGELSRSPSPFTHTHLAQGYRRGAKKLESSEENLSSEDEELP\n"
105 + "CFQHLLFGKVNNIPSQSTRHSTVATECLSKNTEENLLSLKNSLNDCSNQVILAKASQEHHLSEETKCSASLF\n"
106 + "SSQCSELEDLTANTNTQDPFLIGSSKQMRHQSESQGVGLSDKELVSDDEERGTGLEENNQEEQSMDSNLGEA\n"
107 + "ASGCESETSVSEDCSGLSSQSDILTTQQRDTMQHNLIKLQQEMAELEAVLEQHGSQPSNSYPSIISDSSALE\n"
108 + "DLRNPEQSTSEKAVLTSQKSSEYPISQNPEGLSADKFEVSADSSTSKNKEPGVERSSPSKCPSLDDRWYMHS\n"
109 + "CSGSLQNRNYPSQEELIKVVDVEEQQLEESGPHDLTETSYLPRQDLEGTPYLESGISLFSDDPESDPSEDRA\n"
110 + "PESARVGNIPSSTSALKVPQLKVAESAQSPAAAHTTDTAGYNAMEESVSREKPELTASTERVNKRMSMVVSG\n"
111 + "LTPEEFMLVYKFARKHHITLTNLITEETTHVVMKTDAEFVCERTLKYFLGIAGGKWVVSYFWVTQSIKERKM\n"
112 + "LNEHDFEVRGDVVNGRNHQGPKRARESQDRKIFRGLEICCYGPFTNMPTDQLEWMVQLCGASVVKELSSFTL\n"
113 + "GTGVHPIVVVQPDAWTEDNGFHAIGQMCEAPVVTREWVLDSVALYQCQELDTYLIPQIPHSHY\n"
116 upSeq.createDatasetSequence();
117 upSeq.setDescription("Breast cancer type 1 susceptibility protein");
118 upSeq.addDBRef(new DBRefEntry("UNIPROT","0","P38398",null,true));
121 @AfterMethod(alwaysRun = true)
122 public void tearDown() throws Exception
128 @SuppressWarnings("deprecation")
129 @Test(groups = { "Functional" })
130 public void buildPDBQueryTest()
132 System.out.println("seq >>>> " + seq);
134 StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { seq});
135 AssertJUnit.assertTrue(scquery instanceof PDBStructureChooserQuerySource);
136 String query = scquery.buildQuery(seq);
137 AssertJUnit.assertEquals("pdb_id:1tim", query);
138 seq.getAllPDBEntries().clear();
139 query = scquery.buildQuery(seq);
140 AssertJUnit.assertEquals(
141 "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy",
144 query = scquery.buildQuery(seq);
145 System.out.println(query);
146 AssertJUnit.assertEquals("text:4kqy", query);
148 DBRefEntry uniprotDBRef = new DBRefEntry();
149 uniprotDBRef.setAccessionId("P12345");
150 uniprotDBRef.setSource(DBRefSource.UNIPROT);
151 seq.addDBRef(uniprotDBRef);
153 DBRefEntry pdbDBRef = new DBRefEntry();
154 pdbDBRef.setAccessionId("1XYZ");
155 pdbDBRef.setSource(DBRefSource.PDB);
156 seq.addDBRef(pdbDBRef);
158 for (int x = 1; x < 5; x++)
160 DBRefEntry dbRef = new DBRefEntry();
161 dbRef.setAccessionId("XYZ_" + x);
164 System.out.println("");
165 System.out.println(seq.getDBRefs());
166 System.out.println(query);
167 query = scquery.buildQuery(seq);
168 AssertJUnit.assertEquals(
169 "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
173 @SuppressWarnings("deprecation")
174 @Test(groups = { "Functional" })
175 public void buildThreeDBQueryTest()
177 System.out.println("seq >>>> " + upSeq);
178 TDBeaconsFTSRestClientTest.setMock();
179 PDBFTSRestClient.setMock();
180 StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq});
181 // gets the lightweight proxy rather than the ThreeDBStructureChooserQuerySource
182 AssertJUnit.assertTrue(scquery instanceof ThreeDBStructureChooserQuerySource);
183 String query = scquery.buildQuery(upSeq);
184 AssertJUnit.assertEquals("P38398", query);
186 // query shouldn't change regardless of additional entries
187 // because 3DBeacons requires canonical entries.
188 upSeq.getAllPDBEntries().clear();
189 query = scquery.buildQuery(upSeq);
190 AssertJUnit.assertEquals("P38398", query);
191 upSeq.setDBRefs(null);
192 query = scquery.buildQuery(upSeq);
194 * legacy projects/datasets will not have canonical flags set for uniprot dbrefs
195 * graceful behaviour would be to
196 * - pick one ? not possible
197 * - iterate through all until a 200 is obtained ?
198 * ---> ideal but could be costly
199 * ---> better to do a direct retrieval from uniprot to work out which is the canonical identifier..
200 * ----> need a test to check that accessions can be promoted to canonical!
202 //FIXME - need to be able to use ID to query here ?
203 AssertJUnit.assertEquals(null, query);
210 * - no protein -> TDB not applicable, query PDBe only (consider RNA or DNA - specific query adapter ?)
211 * - protein but no uniprot -> first consider trying to get uniprot refs (need a mark to say none are available)
212 * - protein and uniprot - no canonicals -> resolve to uniprot automatically to get canonicals
213 * - query uniprot against 3DBeacons
214 * --> decorate experimental structures with additional data from PDBe
215 * - query remaining against PDBe
218 * --> in memory ranking - no need to query twice
220 * - experimental > AlphaFold -> Model
223 * -> experimental only
224 * -> experimental plus best models for other regions
226 * -> need to be able to select correct reference (the longest one that covers all) for superposition
229 // DBRefEntry uniprotDBRef = new DBRefEntry();
230 // uniprotDBRef.setAccessionId("P12345");
231 // uniprotDBRef.setSource(DBRefSource.UNIPROT);
232 // upSeq.addDBRef(uniprotDBRef);
234 // DBRefEntry pdbDBRef = new DBRefEntry();
235 // pdbDBRef.setAccessionId("1XYZ");
236 // pdbDBRef.setSource(DBRefSource.PDB);
237 // upSeq.addDBRef(pdbDBRef);
239 // for (int x = 1; x < 5; x++)
241 // DBRefEntry dbRef = new DBRefEntry();
242 // dbRef.setAccessionId("XYZ_" + x);
243 // seq.addDBRef(dbRef);
245 // System.out.println("");
246 // System.out.println(seq.getDBRefs());
247 // System.out.println(query);
248 // query = scquery.buildQuery(seq);
250 // "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
253 @Test(groups= {"Functional"})
254 public void cascadingThreeDBandPDBQuerys()
256 TDBeaconsFTSRestClientTest.setMock();
257 PDBFTSRestClient.setMock();
258 ThreeDBStructureChooserQuerySource tdbquery = new ThreeDBStructureChooserQuerySource();
259 PDBStructureChooserQuerySource pdbquery = new PDBStructureChooserQuerySource();
263 FTSRestResponse upResponse = null;
264 FTSRestResponse pdbResponse = null;
265 // TODO test available options
267 // Best Alphafold Model
268 // Best model (by confidence score)
269 // Will also need to develop a more sophisticated filtering system
270 FilterOption opt = tdbquery.getAvailableFilterOptions(StructureChooser.VIEWS_FILTER).get(0);
272 upResponse = tdbquery.fetchStructuresMetaData(upSeq, tdbquery.getDocFieldPrefs().getStructureSummaryFields(), opt, false);
273 // test ranking without additional PDBe data
274 FTSRestResponse firstRanked = tdbquery.selectFirstRankedQuery(upSeq, upResponse.getSearchSummary(), tdbquery.getDocFieldPrefs().getStructureSummaryFields(), opt.getValue(), false);
275 assertTrue(firstRanked.getNumberOfItemsFound()<upResponse.getNumberOfItemsFound());
276 // NB Could have race condition here
277 String pdb_Query = tdbquery.buildPDBFTSQueryFor(upResponse);
278 assertTrue(pdb_Query.trim().length()>0);
279 pdbResponse = tdbquery.fetchStructuresMetaDataFor(pdbquery, upResponse);
280 assertTrue(pdbResponse.getNumberOfItemsFound()>0);
281 FTSRestResponse joinedResp = tdbquery.joinResponses(upResponse, pdbResponse);
282 assertEquals(upResponse.getNumberOfItemsFound(),joinedResp.getNumberOfItemsFound());
285 } catch (Exception x)
288 Assert.fail("Unexpected Exception");
290 StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq});
294 @Test(groups = { "Functional" })
295 public void sanitizeSeqNameTest()
297 String name = "ab_cdEF|fwxyz012349";
298 AssertJUnit.assertEquals(name, PDBStructureChooserQuerySource.sanitizeSeqName(name));
300 // remove a [nn] substring
301 name = "abcde12[345]fg";
302 AssertJUnit.assertEquals("abcde12fg", PDBStructureChooserQuerySource.sanitizeSeqName(name));
304 // remove characters other than a-zA-Z0-9 | or _
305 name = "ab[cd],.\t£$*!- \\\"@:e";
306 AssertJUnit.assertEquals("abcde", PDBStructureChooserQuerySource.sanitizeSeqName(name));
308 name = "abcde12[345a]fg";
309 AssertJUnit.assertEquals("abcde12345afg", PDBStructureChooserQuerySource.sanitizeSeqName(name));