X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FStructureChooserTest.java;h=309b5ad38e0a37d5f7a0be3b48cb4b1c25b889ce;hb=bed0c230be450b16213e30ee1dcaf3e76ddfc669;hp=078174f6c66aad5714be144f11cb7f2d0c055b01;hpb=d9cedb863c0d5b665b8cdde3f8791d8a96030c6b;p=jalview.git diff --git a/test/jalview/gui/StructureChooserTest.java b/test/jalview/gui/StructureChooserTest.java index 078174f..309b5ad 100644 --- a/test/jalview/gui/StructureChooserTest.java +++ b/test/jalview/gui/StructureChooserTest.java @@ -1,30 +1,71 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.gui; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertTrue; + import jalview.datamodel.DBRefEntry; +import jalview.datamodel.DBRefSource; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; -import jalview.ws.dbsources.PDBRestClient.PDBDocField; +import jalview.fts.api.FTSData; +import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient; +import jalview.fts.threedbeacons.TDBeaconsFTSRestClientTest; +import jalview.gui.structurechooser.PDBStructureChooserQuerySource; +import jalview.gui.structurechooser.StructureChooserQuerySource; +import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource; +import jalview.jbgui.FilterOption; +import jalview.ws.params.InvalidArgumentException; -import java.util.ArrayList; -import java.util.List; +import java.util.Collection; import java.util.Vector; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import junit.extensions.PA; public class StructureChooserTest { - Sequence seq; - @Before + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + Sequence seq,upSeq; + + @BeforeMethod(alwaysRun = true) public void setUp() throws Exception { - seq = new Sequence("Test_Seq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 26); - seq.setDatasetSequence(seq); + seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, + 26); + seq.createDatasetSequence(); for (int x = 1; x < 5; x++) { DBRefEntry dbRef = new DBRefEntry(); @@ -35,66 +76,205 @@ public class StructureChooserTest PDBEntry dbRef = new PDBEntry(); dbRef.setId("1tim"); - Vector pdbIds = new Vector(); + Vector pdbIds = new Vector<>(); pdbIds.add(dbRef); seq.setPDBId(pdbIds); + + // Uniprot sequence for 3D-Beacons mocks + upSeq = new Sequence("P38398", + "MDLSALRVEEVQNVINAMQKILECPICLELIKEPVSTKCDHIFCKFCMLKLLNQKKGPSQCPLCKNDITKRS\n" + + "LQESTRFSQLVEELLKIICAFQLDTGLEYANSYNFAKKENNSPEHLKDEVSIIQSMGYRNRAKRLLQSEPEN\n" + + "PSLQETSLSVQLSNLGTVRTLRTKQRIQPQKTSVYIELGSDSSEDTVNKATYCSVGDQELLQITPQGTRDEI\n" + + "SLDSAKKAACEFSETDVTNTEHHQPSNNDLNTTEKRAAERHPEKYQGSSVSNLHVEPCGTNTHASSLQHENS\n" + + "SLLLTKDRMNVEKAEFCNKSKQPGLARSQHNRWAGSKETCNDRRTPSTEKKVDLNADPLCERKEWNKQKLPC\n" + + "SENPRDTEDVPWITLNSSIQKVNEWFSRSDELLGSDDSHDGESESNAKVADVLDVLNEVDEYSGSSEKIDLL\n" + + "ASDPHEALICKSERVHSKSVESNIEDKIFGKTYRKKASLPNLSHVTENLIIGAFVTEPQIIQERPLTNKLKR\n" + + "KRRPTSGLHPEDFIKKADLAVQKTPEMINQGTNQTEQNGQVMNITNSGHENKTKGDSIQNEKNPNPIESLEK\n" + + "ESAFKTKAEPISSSISNMELELNIHNSKAPKKNRLRRKSSTRHIHALELVVSRNLSPPNCTELQIDSCSSSE\n" + + "EIKKKKYNQMPVRHSRNLQLMEGKEPATGAKKSNKPNEQTSKRHDSDTFPELKLTNAPGSFTKCSNTSELKE\n" + + "FVNPSLPREEKEEKLETVKVSNNAEDPKDLMLSGERVLQTERSVESSSISLVPGTDYGTQESISLLEVSTLG\n" + + "KAKTEPNKCVSQCAAFENPKGLIHGCSKDNRNDTEGFKYPLGHEVNHSRETSIEMEESELDAQYLQNTFKVS\n" + + "KRQSFAPFSNPGNAEEECATFSAHSGSLKKQSPKVTFECEQKEENQGKNESNIKPVQTVNITAGFPVVGQKD\n" + + "KPVDNAKCSIKGGSRFCLSSQFRGNETGLITPNKHGLLQNPYRIPPLFPIKSFVKTKCKKNLLEENFEEHSM\n" + + "SPEREMGNENIPSTVSTISRNNIRENVFKEASSSNINEVGSSTNEVGSSINEIGSSDENIQAELGRNRGPKL\n" + + "NAMLRLGVLQPEVYKQSLPGSNCKHPEIKKQEYEEVVQTVNTDFSPYLISDNLEQPMGSSHASQVCSETPDD\n" + + "LLDDGEIKEDTSFAENDIKESSAVFSKSVQKGELSRSPSPFTHTHLAQGYRRGAKKLESSEENLSSEDEELP\n" + + "CFQHLLFGKVNNIPSQSTRHSTVATECLSKNTEENLLSLKNSLNDCSNQVILAKASQEHHLSEETKCSASLF\n" + + "SSQCSELEDLTANTNTQDPFLIGSSKQMRHQSESQGVGLSDKELVSDDEERGTGLEENNQEEQSMDSNLGEA\n" + + "ASGCESETSVSEDCSGLSSQSDILTTQQRDTMQHNLIKLQQEMAELEAVLEQHGSQPSNSYPSIISDSSALE\n" + + "DLRNPEQSTSEKAVLTSQKSSEYPISQNPEGLSADKFEVSADSSTSKNKEPGVERSSPSKCPSLDDRWYMHS\n" + + "CSGSLQNRNYPSQEELIKVVDVEEQQLEESGPHDLTETSYLPRQDLEGTPYLESGISLFSDDPESDPSEDRA\n" + + "PESARVGNIPSSTSALKVPQLKVAESAQSPAAAHTTDTAGYNAMEESVSREKPELTASTERVNKRMSMVVSG\n" + + "LTPEEFMLVYKFARKHHITLTNLITEETTHVVMKTDAEFVCERTLKYFLGIAGGKWVVSYFWVTQSIKERKM\n" + + "LNEHDFEVRGDVVNGRNHQGPKRARESQDRKIFRGLEICCYGPFTNMPTDQLEWMVQLCGASVVKELSSFTL\n" + + "GTGVHPIVVVQPDAWTEDNGFHAIGQMCEAPVVTREWVLDSVALYQCQELDTYLIPQIPHSHY\n" + + "", 1, +1863); + upSeq.createDatasetSequence(); + upSeq.setDescription("Breast cancer type 1 susceptibility protein"); + upSeq.addDBRef(new DBRefEntry("UNIPROT","0","P38398",null,true)); } - @After + @AfterMethod(alwaysRun = true) public void tearDown() throws Exception { seq = null; + upSeq=null; } - @Test - public void getPDBIdColumIndexTest() + @SuppressWarnings("deprecation") + @Test(groups = { "Functional" }) + public void buildQueryTest() { - List wantedFields = new ArrayList(); - wantedFields.add(PDBDocField.MOLECULE_TYPE); - wantedFields.add(PDBDocField.GENUS); - wantedFields.add(PDBDocField.GENE_NAME); - wantedFields.add(PDBDocField.TITLE); - wantedFields.add(PDBDocField.PDB_ID); - assertEquals(5, StructureChooser.getPDBIdColumIndex(wantedFields)); + System.out.println("seq >>>> " + seq); + + StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { seq}); + assertTrue(scquery instanceof PDBStructureChooserQuerySource); + String query = scquery.buildQuery(seq); + assertEquals("pdb_id:1tim", query); + seq.getAllPDBEntries().clear(); + query = scquery.buildQuery(seq); + assertEquals( + "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy", + query); + seq.setDBRefs(null); + query = scquery.buildQuery(seq); + System.out.println(query); + assertEquals("text:4kqy", query); + + DBRefEntry uniprotDBRef = new DBRefEntry(); + uniprotDBRef.setAccessionId("P12345"); + uniprotDBRef.setSource(DBRefSource.UNIPROT); + seq.addDBRef(uniprotDBRef); + + DBRefEntry pdbDBRef = new DBRefEntry(); + pdbDBRef.setAccessionId("1XYZ"); + pdbDBRef.setSource(DBRefSource.PDB); + seq.addDBRef(pdbDBRef); + + for (int x = 1; x < 5; x++) + { + DBRefEntry dbRef = new DBRefEntry(); + dbRef.setAccessionId("XYZ_" + x); + seq.addDBRef(dbRef); + } + System.out.println(""); + System.out.println(seq.getDBRefs()); + System.out.println(query); + query = scquery.buildQuery(seq); + assertEquals( + "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz", + query); } - @Test - public void buildQueryTest() + @SuppressWarnings("deprecation") + @Test(groups = { "Functional" }) + public void buildThreeDBQueryTest() { - assertEquals( - "1tim OR text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4", - StructureChooser.buildQuery(seq)); + System.out.println("seq >>>> " + upSeq); + TDBeaconsFTSRestClientTest.setMock(); + StructureChooserQuerySource scquery = StructureChooserQuerySource.getQuerySourceFor(new SequenceI[] { upSeq}); + assertTrue(scquery instanceof ThreeDBStructureChooserQuerySource); + String query = scquery.buildQuery(upSeq); + assertEquals("P38398", query); + + // query shouldn't change regardless of additional entries + // because 3DBeacons requires canonical entries. + upSeq.getAllPDBEntries().clear(); + query = scquery.buildQuery(upSeq); + assertEquals("P38398", query); + upSeq.setDBRefs(null); + query = scquery.buildQuery(upSeq); + /* + * legacy projects/datasets will not have canonical flags set for uniprot dbrefs + * graceful behaviour would be to + * - pick one ? not possible + * - iterate through all until a 200 is obtained ? + * ---> ideal but could be costly + * ---> better to do a direct retrieval from uniprot to work out which is the canonical identifier.. + * ----> need a test to check that accessions can be promoted to canonical! + */ + assertEquals(null, query); + + // TODO: +// +// DBRefEntry uniprotDBRef = new DBRefEntry(); +// uniprotDBRef.setAccessionId("P12345"); +// uniprotDBRef.setSource(DBRefSource.UNIPROT); +// upSeq.addDBRef(uniprotDBRef); +// +// DBRefEntry pdbDBRef = new DBRefEntry(); +// pdbDBRef.setAccessionId("1XYZ"); +// pdbDBRef.setSource(DBRefSource.PDB); +// upSeq.addDBRef(pdbDBRef); +// +// for (int x = 1; x < 5; x++) +// { +// DBRefEntry dbRef = new DBRefEntry(); +// dbRef.setAccessionId("XYZ_" + x); +// seq.addDBRef(dbRef); +// } +// System.out.println(""); +// System.out.println(seq.getDBRefs()); +// System.out.println(query); +// query = scquery.buildQuery(seq); +// assertEquals( +// "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz", +// query); } + - @Test - public void populateFilterComboBoxTest() + @Test(groups = { "Functional" }) + public void populateFilterComboBoxTest() throws InterruptedException { - SequenceI[] selectedSeqs = new SequenceI[] - { seq }; - StructureChooser sc = new StructureChooser(selectedSeqs, seq, - null); - sc.populateFilterComboBox(); + SequenceI[] selectedSeqs = new SequenceI[] { seq }; + StructureChooser sc = new StructureChooser(selectedSeqs, seq, null); + sc.populateFilterComboBox(false, false); int optionsSize = sc.getCmbFilterOption().getItemCount(); assertEquals(2, optionsSize); // if structures are not discovered then don't // populate filter options - sc.setStructuresDiscovered(true); - sc.populateFilterComboBox(); + sc.populateFilterComboBox(true, false); optionsSize = sc.getCmbFilterOption().getItemCount(); - assertTrue(optionsSize > 2); // if structures are found, filter options + assertTrue(optionsSize > 3); // if structures are found, filter options // should be populated + + sc.populateFilterComboBox(true, true); + assertTrue(sc.getCmbFilterOption().getSelectedItem() != null); + FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption() + .getSelectedItem(); + assertEquals("Cached Structures", filterOpt.getName()); } - @Test + @Test(groups = { "Network" }) public void fetchStructuresInfoTest() { - SequenceI[] selectedSeqs = new SequenceI[] - { seq }; + SequenceI[] selectedSeqs = new SequenceI[] { seq }; StructureChooser sc = new StructureChooser(selectedSeqs, seq, null); sc.fetchStructuresMetaData(); - assertTrue(sc.getDiscoveredStructuresSet() != null); - assertTrue(sc.getDiscoveredStructuresSet().size() > 0); + Collection ss = (Collection) PA.getValue(sc, + "discoveredStructuresSet"); + assertNotNull(ss); + assertTrue(ss.size() > 0); + + } + + @Test(groups = { "Functional" }) + public void sanitizeSeqNameTest() + { + String name = "ab_cdEF|fwxyz012349"; + assertEquals(name, PDBStructureChooserQuerySource.sanitizeSeqName(name)); + + // remove a [nn] substring + name = "abcde12[345]fg"; + assertEquals("abcde12fg", PDBStructureChooserQuerySource.sanitizeSeqName(name)); + + // remove characters other than a-zA-Z0-9 | or _ + name = "ab[cd],.\t£$*!- \\\"@:e"; + assertEquals("abcde", PDBStructureChooserQuerySource.sanitizeSeqName(name)); + name = "abcde12[345a]fg"; + assertEquals("abcde12345afg", PDBStructureChooserQuerySource.sanitizeSeqName(name)); } }