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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.datamodel.DBRefEntry;
28 import jalview.datamodel.DBRefSource;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceI;
32 import jalview.fts.api.FTSData;
33 import jalview.fts.core.FTSRestClient;
34 import jalview.fts.core.FTSRestRequest;
35 import jalview.fts.service.pdb.PDBFTSRestClient;
36 import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
37 import jalview.fts.threedbeacons.TDBeaconsFTSRestClientTest;
38 import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
39 import jalview.gui.structurechooser.StructureChooserQuerySource;
40 import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
41 import jalview.jbgui.FilterOption;
42 import jalview.ws.params.InvalidArgumentException;
44 import java.util.Collection;
45 import java.util.Vector;
47 import org.junit.Assert;
48 import org.testng.annotations.AfterMethod;
49 import org.testng.annotations.BeforeClass;
50 import org.testng.annotations.BeforeMethod;
51 import org.testng.annotations.Test;
53 import junit.extensions.PA;
55 public class StructureChooserTest
58 @BeforeClass(alwaysRun = true)
59 public void setUpJvOptionPane()
61 JvOptionPane.setInteractiveMode(false);
62 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
67 @BeforeMethod(alwaysRun = true)
68 public void setUp() throws Exception
70 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
72 seq.createDatasetSequence();
73 for (int x = 1; x < 5; x++)
75 DBRefEntry dbRef = new DBRefEntry();
76 dbRef.setAccessionId("XYZ_" + x);
80 PDBEntry dbRef = new PDBEntry();
83 Vector<PDBEntry> pdbIds = new Vector<>();
88 // Uniprot sequence for 3D-Beacons mocks
89 upSeq = new Sequence("P38398",
90 "MDLSALRVEEVQNVINAMQKILECPICLELIKEPVSTKCDHIFCKFCMLKLLNQKKGPSQCPLCKNDITKRS\n"
91 + "LQESTRFSQLVEELLKIICAFQLDTGLEYANSYNFAKKENNSPEHLKDEVSIIQSMGYRNRAKRLLQSEPEN\n"
92 + "PSLQETSLSVQLSNLGTVRTLRTKQRIQPQKTSVYIELGSDSSEDTVNKATYCSVGDQELLQITPQGTRDEI\n"
93 + "SLDSAKKAACEFSETDVTNTEHHQPSNNDLNTTEKRAAERHPEKYQGSSVSNLHVEPCGTNTHASSLQHENS\n"
94 + "SLLLTKDRMNVEKAEFCNKSKQPGLARSQHNRWAGSKETCNDRRTPSTEKKVDLNADPLCERKEWNKQKLPC\n"
95 + "SENPRDTEDVPWITLNSSIQKVNEWFSRSDELLGSDDSHDGESESNAKVADVLDVLNEVDEYSGSSEKIDLL\n"
96 + "ASDPHEALICKSERVHSKSVESNIEDKIFGKTYRKKASLPNLSHVTENLIIGAFVTEPQIIQERPLTNKLKR\n"
97 + "KRRPTSGLHPEDFIKKADLAVQKTPEMINQGTNQTEQNGQVMNITNSGHENKTKGDSIQNEKNPNPIESLEK\n"
98 + "ESAFKTKAEPISSSISNMELELNIHNSKAPKKNRLRRKSSTRHIHALELVVSRNLSPPNCTELQIDSCSSSE\n"
99 + "EIKKKKYNQMPVRHSRNLQLMEGKEPATGAKKSNKPNEQTSKRHDSDTFPELKLTNAPGSFTKCSNTSELKE\n"
100 + "FVNPSLPREEKEEKLETVKVSNNAEDPKDLMLSGERVLQTERSVESSSISLVPGTDYGTQESISLLEVSTLG\n"
101 + "KAKTEPNKCVSQCAAFENPKGLIHGCSKDNRNDTEGFKYPLGHEVNHSRETSIEMEESELDAQYLQNTFKVS\n"
102 + "KRQSFAPFSNPGNAEEECATFSAHSGSLKKQSPKVTFECEQKEENQGKNESNIKPVQTVNITAGFPVVGQKD\n"
103 + "KPVDNAKCSIKGGSRFCLSSQFRGNETGLITPNKHGLLQNPYRIPPLFPIKSFVKTKCKKNLLEENFEEHSM\n"
104 + "SPEREMGNENIPSTVSTISRNNIRENVFKEASSSNINEVGSSTNEVGSSINEIGSSDENIQAELGRNRGPKL\n"
105 + "NAMLRLGVLQPEVYKQSLPGSNCKHPEIKKQEYEEVVQTVNTDFSPYLISDNLEQPMGSSHASQVCSETPDD\n"
106 + "LLDDGEIKEDTSFAENDIKESSAVFSKSVQKGELSRSPSPFTHTHLAQGYRRGAKKLESSEENLSSEDEELP\n"
107 + "CFQHLLFGKVNNIPSQSTRHSTVATECLSKNTEENLLSLKNSLNDCSNQVILAKASQEHHLSEETKCSASLF\n"
108 + "SSQCSELEDLTANTNTQDPFLIGSSKQMRHQSESQGVGLSDKELVSDDEERGTGLEENNQEEQSMDSNLGEA\n"
109 + "ASGCESETSVSEDCSGLSSQSDILTTQQRDTMQHNLIKLQQEMAELEAVLEQHGSQPSNSYPSIISDSSALE\n"
110 + "DLRNPEQSTSEKAVLTSQKSSEYPISQNPEGLSADKFEVSADSSTSKNKEPGVERSSPSKCPSLDDRWYMHS\n"
111 + "CSGSLQNRNYPSQEELIKVVDVEEQQLEESGPHDLTETSYLPRQDLEGTPYLESGISLFSDDPESDPSEDRA\n"
112 + "PESARVGNIPSSTSALKVPQLKVAESAQSPAAAHTTDTAGYNAMEESVSREKPELTASTERVNKRMSMVVSG\n"
113 + "LTPEEFMLVYKFARKHHITLTNLITEETTHVVMKTDAEFVCERTLKYFLGIAGGKWVVSYFWVTQSIKERKM\n"
114 + "LNEHDFEVRGDVVNGRNHQGPKRARESQDRKIFRGLEICCYGPFTNMPTDQLEWMVQLCGASVVKELSSFTL\n"
115 + "GTGVHPIVVVQPDAWTEDNGFHAIGQMCEAPVVTREWVLDSVALYQCQELDTYLIPQIPHSHY\n"
118 upSeq.createDatasetSequence();
119 upSeq.setDescription("Breast cancer type 1 susceptibility protein");
120 upSeq.addDBRef(new DBRefEntry("UNIPROT","0","P38398",null,true));
123 @AfterMethod(alwaysRun = true)
124 public void tearDown() throws Exception
130 @Test(groups = { "Functional" })
131 public void populateFilterComboBoxTest() throws InterruptedException
133 TDBeaconsFTSRestClientTest.setMock();
134 PDBFTSRestClient.setMock();
136 SequenceI[] selectedSeqs = new SequenceI[] { seq };
137 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
138 sc.populateFilterComboBox(false, false);
139 int optionsSize = sc.getCmbFilterOption().getItemCount();
140 assertEquals(2, optionsSize); // if structures are not discovered then don't
141 // populate filter options
143 sc.populateFilterComboBox(true, false);
144 optionsSize = sc.getCmbFilterOption().getItemCount();
145 assertTrue(optionsSize > 3); // if structures are found, filter options
146 // should be populated
148 sc.populateFilterComboBox(true, true);
149 assertTrue(sc.getCmbFilterOption().getSelectedItem() != null);
150 FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption()
152 assertEquals("Cached Structures", filterOpt.getName());
155 @Test(groups = { "Network" })
156 public void fetchStructuresInfoTest()
158 FTSRestClient.unMock((FTSRestClient) TDBeaconsFTSRestClient.getInstance());
159 PDBFTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
160 SequenceI[] selectedSeqs = new SequenceI[] { seq };
161 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
162 sc.fetchStructuresMetaData();
163 Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
164 "discoveredStructuresSet");
166 assertTrue(ss.size() > 0);
169 @Test(groups = { "Functional" })
170 public void fetchStructuresInfoMockedTest()
172 TDBeaconsFTSRestClientTest.setMock();
173 PDBFTSRestClient.setMock();
174 SequenceI[] selectedSeqs = new SequenceI[] { upSeq };
175 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
176 sc.fetchStructuresMetaData();
177 Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
178 "discoveredStructuresSet");
180 assertTrue(ss.size() > 0);
183 @Test(groups = { "Functional" })
184 public void sanitizeSeqNameTest()
186 String name = "ab_cdEF|fwxyz012349";
187 assertEquals(name, PDBStructureChooserQuerySource.sanitizeSeqName(name));
189 // remove a [nn] substring
190 name = "abcde12[345]fg";
191 assertEquals("abcde12fg", PDBStructureChooserQuerySource.sanitizeSeqName(name));
193 // remove characters other than a-zA-Z0-9 | or _
194 name = "ab[cd],.\t£$*!- \\\"@:e";
195 assertEquals("abcde", PDBStructureChooserQuerySource.sanitizeSeqName(name));
197 name = "abcde12[345a]fg";
198 assertEquals("abcde12345afg", PDBStructureChooserQuerySource.sanitizeSeqName(name));