Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.gui

File StructureChooserTest.java

 

Code metrics

20
126
11
1
416
320
25
0.2
11.45
11
2.27

Classes

Class Line # Actions
StructureChooserTest 66 126 25
0.878980987.9%
 

Contributing tests

This file is covered by 10 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.gui;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.AssertJUnit.assertNotNull;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import java.io.File;
28    import java.util.Collection;
29    import java.util.List;
30    import java.util.Vector;
31   
32    import org.junit.Assert;
33    import org.testng.annotations.AfterMethod;
34    import org.testng.annotations.BeforeClass;
35    import org.testng.annotations.BeforeMethod;
36    import org.testng.annotations.DataProvider;
37    import org.testng.annotations.Test;
38   
39    import jalview.api.AlignViewportI;
40    import jalview.bin.Cache;
41    import jalview.bin.Jalview;
42    import jalview.datamodel.AlignmentAnnotation;
43    import jalview.datamodel.AlignmentI;
44    import jalview.datamodel.DBRefEntry;
45    import jalview.datamodel.PDBEntry;
46    import jalview.datamodel.Sequence;
47    import jalview.datamodel.SequenceI;
48    import jalview.fts.api.FTSData;
49    import jalview.fts.core.FTSRestClient;
50    import jalview.fts.service.pdb.PDBFTSRestClient;
51    import jalview.fts.service.pdb.PDBFTSRestClientTest;
52    import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
53    import jalview.fts.threedbeacons.TDBeaconsFTSRestClientTest;
54    import jalview.gui.StructureViewer.ViewerType;
55    import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
56    import jalview.io.DataSourceType;
57    import jalview.io.FileFormatException;
58    import jalview.io.FileFormatI;
59    import jalview.io.FileLoader;
60    import jalview.io.IdentifyFile;
61    import jalview.jbgui.FilterOption;
62    import jalview.structure.StructureImportSettings.TFType;
63    import junit.extensions.PA;
64   
65    @Test(singleThreaded = true)
 
66    public class StructureChooserTest
67    {
68   
 
69  1 toggle @BeforeClass(alwaysRun = true)
70    public void setUpJvOptionPane()
71    {
72  1 JvOptionPane.setInteractiveMode(false);
73  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
74    }
75   
76    Sequence seq, upSeq, upSeq_nocanonical;
77   
 
78  10 toggle @BeforeMethod(alwaysRun = true)
79    public void setUp() throws Exception
80    {
81  10 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
82    26);
83  10 seq.createDatasetSequence();
84  50 for (int x = 1; x < 5; x++)
85    {
86  40 DBRefEntry dbRef = new DBRefEntry();
87  40 dbRef.setAccessionId("XYZ_" + x);
88  40 seq.addDBRef(dbRef);
89    }
90   
91  10 PDBEntry dbRef = new PDBEntry();
92  10 dbRef.setId("1tim");
93   
94  10 Vector<PDBEntry> pdbIds = new Vector<>();
95  10 pdbIds.add(dbRef);
96   
97  10 seq.setPDBId(pdbIds);
98   
99    // Uniprot sequence for 3D-Beacons mocks
100  10 upSeq = new Sequence("P38398",
101    "MDLSALRVEEVQNVINAMQKILECPICLELIKEPVSTKCDHIFCKFCMLKLLNQKKGPSQCPLCKNDITKRS\n"
102    + "LQESTRFSQLVEELLKIICAFQLDTGLEYANSYNFAKKENNSPEHLKDEVSIIQSMGYRNRAKRLLQSEPEN\n"
103    + "PSLQETSLSVQLSNLGTVRTLRTKQRIQPQKTSVYIELGSDSSEDTVNKATYCSVGDQELLQITPQGTRDEI\n"
104    + "SLDSAKKAACEFSETDVTNTEHHQPSNNDLNTTEKRAAERHPEKYQGSSVSNLHVEPCGTNTHASSLQHENS\n"
105    + "SLLLTKDRMNVEKAEFCNKSKQPGLARSQHNRWAGSKETCNDRRTPSTEKKVDLNADPLCERKEWNKQKLPC\n"
106    + "SENPRDTEDVPWITLNSSIQKVNEWFSRSDELLGSDDSHDGESESNAKVADVLDVLNEVDEYSGSSEKIDLL\n"
107    + "ASDPHEALICKSERVHSKSVESNIEDKIFGKTYRKKASLPNLSHVTENLIIGAFVTEPQIIQERPLTNKLKR\n"
108    + "KRRPTSGLHPEDFIKKADLAVQKTPEMINQGTNQTEQNGQVMNITNSGHENKTKGDSIQNEKNPNPIESLEK\n"
109    + "ESAFKTKAEPISSSISNMELELNIHNSKAPKKNRLRRKSSTRHIHALELVVSRNLSPPNCTELQIDSCSSSE\n"
110    + "EIKKKKYNQMPVRHSRNLQLMEGKEPATGAKKSNKPNEQTSKRHDSDTFPELKLTNAPGSFTKCSNTSELKE\n"
111    + "FVNPSLPREEKEEKLETVKVSNNAEDPKDLMLSGERVLQTERSVESSSISLVPGTDYGTQESISLLEVSTLG\n"
112    + "KAKTEPNKCVSQCAAFENPKGLIHGCSKDNRNDTEGFKYPLGHEVNHSRETSIEMEESELDAQYLQNTFKVS\n"
113    + "KRQSFAPFSNPGNAEEECATFSAHSGSLKKQSPKVTFECEQKEENQGKNESNIKPVQTVNITAGFPVVGQKD\n"
114    + "KPVDNAKCSIKGGSRFCLSSQFRGNETGLITPNKHGLLQNPYRIPPLFPIKSFVKTKCKKNLLEENFEEHSM\n"
115    + "SPEREMGNENIPSTVSTISRNNIRENVFKEASSSNINEVGSSTNEVGSSINEIGSSDENIQAELGRNRGPKL\n"
116    + "NAMLRLGVLQPEVYKQSLPGSNCKHPEIKKQEYEEVVQTVNTDFSPYLISDNLEQPMGSSHASQVCSETPDD\n"
117    + "LLDDGEIKEDTSFAENDIKESSAVFSKSVQKGELSRSPSPFTHTHLAQGYRRGAKKLESSEENLSSEDEELP\n"
118    + "CFQHLLFGKVNNIPSQSTRHSTVATECLSKNTEENLLSLKNSLNDCSNQVILAKASQEHHLSEETKCSASLF\n"
119    + "SSQCSELEDLTANTNTQDPFLIGSSKQMRHQSESQGVGLSDKELVSDDEERGTGLEENNQEEQSMDSNLGEA\n"
120    + "ASGCESETSVSEDCSGLSSQSDILTTQQRDTMQHNLIKLQQEMAELEAVLEQHGSQPSNSYPSIISDSSALE\n"
121    + "DLRNPEQSTSEKAVLTSQKSSEYPISQNPEGLSADKFEVSADSSTSKNKEPGVERSSPSKCPSLDDRWYMHS\n"
122    + "CSGSLQNRNYPSQEELIKVVDVEEQQLEESGPHDLTETSYLPRQDLEGTPYLESGISLFSDDPESDPSEDRA\n"
123    + "PESARVGNIPSSTSALKVPQLKVAESAQSPAAAHTTDTAGYNAMEESVSREKPELTASTERVNKRMSMVVSG\n"
124    + "LTPEEFMLVYKFARKHHITLTNLITEETTHVVMKTDAEFVCERTLKYFLGIAGGKWVVSYFWVTQSIKERKM\n"
125    + "LNEHDFEVRGDVVNGRNHQGPKRARESQDRKIFRGLEICCYGPFTNMPTDQLEWMVQLCGASVVKELSSFTL\n"
126    + "GTGVHPIVVVQPDAWTEDNGFHAIGQMCEAPVVTREWVLDSVALYQCQELDTYLIPQIPHSHY\n"
127    + "",
128    1, 1863);
129  10 upSeq.setDescription("Breast cancer type 1 susceptibility protein");
130  10 upSeq_nocanonical = new Sequence(upSeq);
131  10 upSeq.createDatasetSequence();
132  10 upSeq.addDBRef(new DBRefEntry("UNIPROT", "0", "P38398", null, true));
133   
134  10 upSeq_nocanonical.createDatasetSequence();
135    // not a canonical reference
136  10 upSeq_nocanonical.addDBRef(new DBRefEntry("UNIPROT","0","P38398",null,false));
137    }
138   
 
139  10 toggle @AfterMethod(alwaysRun = true)
140    public void tearDown() throws Exception
141    {
142  10 seq = null;
143  10 upSeq = null;
144  10 upSeq_nocanonical = null;
145    }
146   
 
147  1 toggle @Test(groups = { "Functional" })
148    public void populateFilterComboBoxTest() throws InterruptedException
149    {
150  1 TDBeaconsFTSRestClientTest.setMock();
151  1 PDBFTSRestClientTest.setMock();
152   
153  1 SequenceI[] selectedSeqs = new SequenceI[] { seq };
154  1 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
155  1 ThreadwaitFor(200, sc);
156   
157    // if structures are not discovered then don't
158    // populate filter options
159  1 sc.populateFilterComboBox(false, false);
160  1 int optionsSize = sc.getCmbFilterOption().getItemCount();
161  1 System.out.println("Items (no data, no cache): ");
162  1 StringBuilder items = new StringBuilder();
163  3 for (int p = 0; p < optionsSize; p++)
164    {
165  2 items.append("- ")
166    .append(sc.getCmbFilterOption().getItemAt(p).getName())
167    .append("\n");
168   
169    }
170    // report items when this fails - seems to be a race condition
171  1 Assert.assertEquals(items.toString(), optionsSize, 2);
172   
173  1 sc.populateFilterComboBox(true, false);
174  1 optionsSize = sc.getCmbFilterOption().getItemCount();
175  1 assertTrue(optionsSize > 3); // if structures are found, filter options
176    // should be populated
177   
178  1 sc.populateFilterComboBox(true, true);
179  1 assertTrue(sc.getCmbFilterOption().getSelectedItem() != null);
180  1 FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption()
181    .getSelectedItem();
182  1 assertEquals("Cached Structures", filterOpt.getName());
183  1 FTSRestClient
184    .unMock((FTSRestClient) TDBeaconsFTSRestClient.getInstance());
185  1 FTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
186   
187    }
188   
 
189  1 toggle @Test(groups = { "Functional" })
190    public void displayTDBQueryTest() throws InterruptedException
191    {
192  1 TDBeaconsFTSRestClientTest.setMock();
193  1 PDBFTSRestClientTest.setMock();
194   
195  1 SequenceI[] selectedSeqs = new SequenceI[] { upSeq_nocanonical };
196  1 StructureChooser sc = new StructureChooser(selectedSeqs,
197    upSeq_nocanonical, null);
198    // mock so should be quick. Exceptions from mocked PDBFTS are expected too
199  1 ThreadwaitFor(500, sc);
200   
201  1 assertTrue(sc.isCanQueryTDB() && sc.isNotQueriedTDBYet());
202    }
203   
 
204  0 toggle @Test(groups = { "Network" })
205    public void fetchStructuresInfoTest()
206    {
207  0 FTSRestClient
208    .unMock((FTSRestClient) TDBeaconsFTSRestClient.getInstance());
209  0 PDBFTSRestClient.unMock((FTSRestClient) PDBFTSRestClient.getInstance());
210  0 SequenceI[] selectedSeqs = new SequenceI[] { seq };
211  0 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
212    // not mocked, wait for 2s
213  0 ThreadwaitFor(2000, sc);
214   
215  0 sc.fetchStructuresMetaData();
216  0 Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
217    "discoveredStructuresSet");
218  0 assertNotNull(ss);
219  0 assertTrue(ss.size() > 0);
220    }
221   
 
222  1 toggle @Test(groups = { "Functional" })
223    public void fetchStructuresInfoMockedTest()
224    {
225  1 TDBeaconsFTSRestClientTest.setMock();
226  1 PDBFTSRestClientTest.setMock();
227  1 SequenceI[] selectedSeqs = new SequenceI[] { upSeq };
228  1 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
229  1 ThreadwaitFor(500, sc);
230   
231  1 sc.fetchStructuresMetaData();
232  1 Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
233    "discoveredStructuresSet");
234  1 assertNotNull(ss);
235  1 assertTrue(ss.size() > 0);
236    }
237   
 
238  3 toggle private void ThreadwaitFor(int i, StructureChooser sc)
239    {
240  3 long timeout = i + System.currentTimeMillis();
241  17 while (!sc.isDialogVisible() && timeout > System.currentTimeMillis())
242    {
243  14 try
244    {
245  14 Thread.sleep(50);
246    } catch (InterruptedException x)
247    {
248   
249    }
250    }
251    }
 
252  1 toggle @Test(groups = { "Functional" })
253    public void sanitizeSeqNameTest()
254    {
255  1 String name = "ab_cdEF|fwxyz012349";
256  1 assertEquals(name,
257    PDBStructureChooserQuerySource.sanitizeSeqName(name));
258   
259    // remove a [nn] substring
260  1 name = "abcde12[345]fg";
261  1 assertEquals("abcde12fg",
262    PDBStructureChooserQuerySource.sanitizeSeqName(name));
263   
264    // remove characters other than a-zA-Z0-9 | or _
265  1 name = "ab[cd],.\t£$*!- \\\"@:e";
266  1 assertEquals("abcde",
267    PDBStructureChooserQuerySource.sanitizeSeqName(name));
268   
269  1 name = "abcde12[345a]fg";
270  1 assertEquals("abcde12345afg",
271    PDBStructureChooserQuerySource.sanitizeSeqName(name));
272    }
273   
 
274  6 toggle @Test(groups = { "Functional" }, dataProvider = "openStructureFileParams")
275    public void openStructureFileForSequenceTest(String alfile, String seqid,
276    String sFilename, TFType tft, String paeFilename,
277    boolean showRefAnnotations, boolean doXferSettings,
278    ViewerType viewerType, int seqNum, int annNum, int viewerNum,
279    String propsFile)
280    {
281  6 Cache.loadProperties(
282  6 propsFile == null ? "test/jalview/io/testProps.jvprops"
283    : propsFile);
284   
285  6 Jalview.main(
286  6 propsFile == null ? null : new String[]
287    { "--props", propsFile });
288  6 if (Desktop.getInstance() != null)
289  6 Desktop.getInstance().closeAll_actionPerformed(null);
290  6 JvOptionPane.setInteractiveMode(false);
291  6 JvOptionPane.setMockResponse(JvOptionPane.OK_OPTION);
292   
293  6 FileLoader fileLoader = new FileLoader(true);
294  6 FileFormatI format = null;
295  6 File alFile = new File(alfile);
296  6 try
297    {
298  6 format = new IdentifyFile().identify(alFile, DataSourceType.FILE);
299    } catch (FileFormatException e1)
300    {
301  0 Assert.fail(
302    "Unknown file format for '" + alFile.getAbsolutePath() + "'");
303    }
304   
305  6 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(alFile,
306    DataSourceType.FILE, format);
307  6 AlignmentPanel ap = af.alignPanel;
308  6 Assert.assertNotNull("No alignPanel", ap);
309   
310  6 AlignmentI al = ap.getAlignment();
311  6 Assert.assertNotNull(al);
312   
313  6 SequenceI seq = al.findName(seqid);
314  6 Assert.assertNotNull("Sequence '" + seqid + "' not found in alignment",
315    seq);
316   
317  6 StructureChooser.openStructureFileForSequence(null, null, ap, seq,
318    false, sFilename, tft, paeFilename, false, showRefAnnotations,
319    doXferSettings, viewerType);
320   
321  6 List<SequenceI> seqs = al.getSequences();
322  6 Assert.assertNotNull(seqs);
323   
324  6 Assert.assertEquals("Wrong number of sequences", seqNum, seqs.size());
325   
326  6 AlignViewportI av = ap.getAlignViewport();
327  6 Assert.assertNotNull(av);
328   
329  6 AlignmentAnnotation[] aas = al.getAlignmentAnnotation();
330  6 int visibleAnn = 0;
331  6 for (AlignmentAnnotation aa : aas)
332    {
333  36 if (aa.visible)
334  36 visibleAnn++;
335    }
336  6 Assert.assertEquals("Wrong number of viewed annotations", annNum,
337    visibleAnn);
338   
339  6 if (viewerNum > -1)
340    {
341  6 try
342    {
343  6 Thread.sleep(100);
344    } catch (InterruptedException e)
345    {
346    // TODO Auto-generated catch block
347  0 e.printStackTrace();
348    }
349  6 List<StructureViewerBase> openViewers = Desktop.getInstance()
350    .getStructureViewers(ap, null);
351  6 Assert.assertNotNull(openViewers);
352  6 int count = 0;
353  6 for (StructureViewerBase svb : openViewers)
354    {
355  3 if (svb.isVisible())
356  3 count++;
357    }
358  6 Assert.assertEquals("Wrong number of structure viewers opened",
359    viewerNum, count);
360   
361    }
362   
363  6 if (af != null)
364    {
365  6 af.setVisible(false);
366  6 af.dispose();
367    }
368    }
369   
 
370  1 toggle @DataProvider(name = "openStructureFileParams")
371    public Object[][] openStructureFileParams()
372    {
373    /*
374    String alFile,
375    String seqid,
376    String structureFilename,
377    TFType tft,
378    String paeFilename,
379    boolean showRefAnnotations,
380    boolean doXferSettings, // false for Commands
381    ViewerType viewerType,
382    int seqNum,
383    int annNum,
384    int viewerNum,
385    String propsFile
386    */
387  1 return new Object[][] {
388    /*
389    */
390    { "examples/uniref50.fa", "FER1_SPIOL",
391    "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.DEFAULT,
392    "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
393    true, false, null, 15, 7, 0, null },
394    { "examples/uniref50.fa", "FER1_SPIOL",
395    "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.PLDDT,
396    "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
397    true, false, null, 15, 7, 0, null },
398    { "examples/uniref50.fa", "FER1_SPIOL",
399    "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.PLDDT,
400    "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
401    false, false, null, 15, 4, 0, null },
402    { "examples/uniref50.fa", "FER1_SPIOL",
403    "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.DEFAULT,
404    "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
405    true, false, ViewerType.JMOL, 15, 7, 1, null },
406    { "examples/uniref50.fa", "FER1_SPIOL",
407    "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.PLDDT,
408    "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
409    true, false, ViewerType.JMOL, 15, 7, 1, null },
410    { "examples/uniref50.fa", "FER1_SPIOL",
411    "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.PLDDT,
412    "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
413    false, false, ViewerType.JMOL, 15, 4, 1, null }, };
414    }
415   
416    }