Clover icon

Coverage Report

  1. Project Clover database Tue Nov 4 2025 11:21:43 GMT
  2. Package jalview.structure

File StructureSelectionManagerTest.java

 

Code metrics

42
200
11
1
597
432
34
0.17
18.18
11
3.09

Classes

Class Line # Actions
StructureSelectionManagerTest 64 200 34
0.446640344.7%
 

Contributing tests

This file is covered by 9 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.structure;
22   
23    import static org.junit.Assert.assertArrayEquals;
24    import static org.mockito.Mockito.*;
25    import static org.testng.Assert.assertNotNull;
26    import static org.testng.AssertJUnit.assertEquals;
27    import static org.testng.AssertJUnit.assertTrue;
28   
29    import java.util.*;
30   
31    import org.testng.Assert;
32    import org.testng.annotations.BeforeClass;
33    import org.testng.annotations.BeforeMethod;
34    import org.testng.annotations.DataProvider;
35    import org.testng.annotations.Test;
36   
37    import jalview.analysis.AlignmentUtils;
38    import jalview.api.structures.JalviewStructureDisplayI;
39    import jalview.bin.Cache;
40    import jalview.datamodel.AlignedCodonFrame;
41    import jalview.datamodel.AlignmentAnnotation;
42    import jalview.datamodel.AlignmentI;
43    import jalview.datamodel.Annotation;
44    import jalview.datamodel.PDBEntry;
45    import jalview.datamodel.Sequence;
46    import jalview.datamodel.SequenceFeature;
47    import jalview.datamodel.SequenceI;
48    import jalview.ext.jmol.JmolCommands;
49    import jalview.gui.AlignFrame;
50    import jalview.gui.Desktop;
51    import jalview.gui.JvOptionPane;
52    import jalview.gui.SequenceRenderer;
53    import jalview.gui.StructureChooser;
54    import jalview.io.DataSourceType;
55    import jalview.io.FileLoader;
56    import jalview.io.Jalview2xmlBase;
57    import jalview.io.StructureFile;
58    import jalview.util.Constants;
59    import jalview.util.MapList;
60    import jalview.ws.DBRefFetcher;
61    import jalview.ws.sifts.SiftsSettings;
62   
63    @Test(singleThreaded = true)
 
64    public class StructureSelectionManagerTest extends Jalview2xmlBase
65    {
66   
 
67  1 toggle @Override
68    @BeforeClass(alwaysRun = true)
69    public void setUpJvOptionPane()
70    {
71  1 JvOptionPane.setInteractiveMode(false);
72  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
73    }
74   
75    private StructureSelectionManager ssm;
76   
 
77  9 toggle @BeforeMethod(alwaysRun = true)
78    public void setUp()
79    {
80  9 StructureImportSettings.setShowSeqFeatures(true);
81  9 ssm = new StructureSelectionManager();
82    }
83   
 
84  1 toggle @Test(groups = { "Functional" })
85    public void testRegisterMapping()
86    {
87  1 AlignedCodonFrame acf1 = new AlignedCodonFrame();
88  1 acf1.addMap(new Sequence("s1", "ttt"), new Sequence("p1", "p"),
89    new MapList(new int[]
90    { 1, 3 }, new int[] { 1, 1 }, 1, 1));
91  1 AlignedCodonFrame acf2 = new AlignedCodonFrame();
92  1 acf2.addMap(new Sequence("s2", "ttt"), new Sequence("p2", "p"),
93    new MapList(new int[]
94    { 1, 3 }, new int[] { 1, 1 }, 1, 1));
95   
96  1 ssm.registerMapping(acf1);
97  1 assertEquals(1, ssm.getSequenceMappings().size());
98  1 assertTrue(ssm.getSequenceMappings().contains(acf1));
99   
100  1 ssm.registerMapping(acf2);
101  1 assertEquals(2, ssm.getSequenceMappings().size());
102  1 assertTrue(ssm.getSequenceMappings().contains(acf1));
103  1 assertTrue(ssm.getSequenceMappings().contains(acf2));
104   
105    /*
106    * Re-adding the first mapping does nothing
107    */
108  1 ssm.registerMapping(acf1);
109  1 assertEquals(2, ssm.getSequenceMappings().size());
110  1 assertTrue(ssm.getSequenceMappings().contains(acf1));
111  1 assertTrue(ssm.getSequenceMappings().contains(acf2));
112    }
113   
 
114  1 toggle @Test(groups = { "Functional" })
115    public void testRegisterMappings()
116    {
117  1 AlignedCodonFrame acf1 = new AlignedCodonFrame();
118  1 acf1.addMap(new Sequence("s1", "ttt"), new Sequence("p1", "p"),
119    new MapList(new int[]
120    { 1, 3 }, new int[] { 1, 1 }, 1, 1));
121  1 AlignedCodonFrame acf2 = new AlignedCodonFrame();
122  1 acf2.addMap(new Sequence("s2", "ttt"), new Sequence("p2", "p"),
123    new MapList(new int[]
124    { 1, 3 }, new int[] { 1, 1 }, 1, 1));
125  1 AlignedCodonFrame acf3 = new AlignedCodonFrame();
126  1 acf3.addMap(new Sequence("s3", "ttt"), new Sequence("p3", "p"),
127    new MapList(new int[]
128    { 1, 3 }, new int[] { 1, 1 }, 1, 1));
129   
130  1 List<AlignedCodonFrame> set1 = new ArrayList<>();
131  1 set1.add(acf1);
132  1 set1.add(acf2);
133  1 List<AlignedCodonFrame> set2 = new ArrayList<>();
134  1 set2.add(acf2);
135  1 set2.add(acf3);
136   
137    /*
138    * Add both sets twice; each mapping should be added once only
139    */
140  1 ssm.registerMappings(set1);
141  1 ssm.registerMappings(set1);
142  1 ssm.registerMappings(set2);
143  1 ssm.registerMappings(set2);
144   
145  1 assertEquals(3, ssm.getSequenceMappings().size());
146  1 assertTrue(ssm.getSequenceMappings().contains(acf1));
147  1 assertTrue(ssm.getSequenceMappings().contains(acf2));
148  1 assertTrue(ssm.getSequenceMappings().contains(acf3));
149    }
150   
151    /**
152    * Verify that RESNUM sequence features are present after creating a PDB
153    * mapping
154    */
 
155  1 toggle @Test(groups = { "Functional" })
156    public void testSetMapping_seqFeatures()
157    {
158  1 SequenceI seq = new Sequence("1GAQ|B",
159    "ATYNVKLITPEGEVELQVPDDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKEEELTGA");
160  1 StructureSelectionManager sm = new StructureSelectionManager();
161  1 sm.setProcessSecondaryStructure(true);
162  1 sm.setAddTempFacAnnot(true);
163  1 StructureFile pmap = sm.setMapping(true, new SequenceI[] { seq },
164    new String[]
165    { null }, "examples/1gaq.txt", DataSourceType.FILE, null, null);
166  1 assertTrue(pmap != null);
167   
168  1 assertEquals(3, pmap.getSeqs().size());
169  1 assertEquals("1GAQ|A", pmap.getSeqs().get(0).getName());
170  1 assertEquals("1GAQ|B", pmap.getSeqs().get(1).getName());
171  1 assertEquals("1GAQ|C", pmap.getSeqs().get(2).getName());
172   
173    /*
174    * Verify a RESNUM sequence feature in the PDBfile sequence
175    */
176  1 SequenceFeature sf = pmap.getSeqs().get(0).getSequenceFeatures().get(0);
177  1 assertEquals("RESNUM", sf.getType());
178  1 assertEquals("1gaq", sf.getFeatureGroup());
179  1 assertEquals("GLU: 19 1gaqA", sf.getDescription());
180   
181    /*
182    * Verify a RESNUM sequence feature in the StructureSelectionManager mapped
183    * sequence
184    */
185  1 StructureMapping map = sm.getMapping("examples/1gaq.txt")[0];
186  1 sf = map.sequence.getSequenceFeatures().get(0);
187  1 assertEquals("RESNUM", sf.getType());
188  1 assertEquals("1gaq", sf.getFeatureGroup());
189  1 assertEquals("ALA: 1 1gaqB", sf.getDescription());
190    }
191   
192    /**
193    * Verify that RESNUM sequence features are present after creating a PDB
194    * mapping from a local file, then that everything stays in the same place
195    * when the file is viewed. The corner case is that 4IM2 is a fragment of a
196    * PDB file, which still includes the 'ID' field - a bug in Jalview 2.10.3
197    * causes features, annotation and positions to be remapped to the wrong place
198    * on viewing the structure
199    */
 
200  0 toggle @Test(groups = { "Network" })
201    public void testMapping_EqualsFeatures()
202    {
203    // for some reason 'BeforeMethod' (which should be inherited from
204    // Jalview2XmlBase isn't always called)...
205  0 if (Desktop.instance != null)
206  0 Desktop.instance.closeAll_actionPerformed(null);
207  0 try
208    {
209  0 Thread.sleep(200);
210    } catch (Exception foo)
211    {
212    }
213  0 ;
214  0 SequenceI seq = new Sequence("4IM2|A",
215    "LDFCIRNIEKTVMGEISDIHTKLLRLSSSQGTIE");
216  0 String P4IM2_MISSING = "examples/testdata/4IM2_missing.pdb";
217  0 StructureSelectionManager sm = new StructureSelectionManager();
218  0 sm.setProcessSecondaryStructure(true);
219  0 sm.setAddTempFacAnnot(true);
220  0 StructureFile pmap = sm.setMapping(true, new SequenceI[] { seq },
221    new String[]
222    { null }, P4IM2_MISSING, DataSourceType.FILE, null, null);
223  0 assertTrue(pmap != null);
224   
225  0 assertEquals(1, pmap.getSeqs().size());
226  0 assertEquals("4IM2|A", pmap.getSeqs().get(0).getName());
227   
228  0 List<int[]> structuremap1 = new ArrayList<>(
229    sm.getMapping(P4IM2_MISSING)[0]
230    .getPDBResNumRanges(seq.getStart(), seq.getEnd()));
231   
232    /*
233    * Verify a RESNUM sequence feature in the PDBfile sequence
234    * LEU468 - start+0
235    * VAL479 - start+11
236    * MET486 - start+12
237    * GLY496 - start+13
238    * GLU516 - start+33 (last)
239    *
240    * Expect features and mapping to resolve to same residues.
241    * Also try creating a view and test again
242    *
243    */
244  0 String[] feats = new String[] { "LEU", "468", "VAL", "479", "MET",
245    "486", "GLY", "496", "GLU", "516" };
246  0 int[] offset = new int[] { 0, 11, 12, 13, 33 };
247   
248  0 List<String> fdesc = new ArrayList<>();
249  0 for (int f = 0; f < feats.length; f += 2)
250    {
251  0 fdesc.add(feats[f] + ": " + feats[f + 1] + " 4im2A");
252    }
253  0 SequenceI pdbseq = pmap.getSeqs().get(0);
254  0 verifySeqFeats(pdbseq, offset, fdesc);
255   
256    /// Now load as a view
257   
258  0 AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
259    "examples/testdata/4IM2_missing.pdb", DataSourceType.FILE);
260  0 Desktop.addInternalFrame(alf, "examples/testdata/4IM2_missing.pdb", 800,
261    400);
262  0 AlignmentI pdbal = alf.getViewport().getAlignment();
263  0 SequenceI pdb_viewseq = pdbal.getSequenceAt(0);
264  0 assertEquals(pdb_viewseq.getSequenceAsString(),
265    seq.getSequenceAsString());
266    // verify the feature location on the sequence when pdb imported as an
267    // alignment
268  0 verifySeqFeats(pdb_viewseq, offset, fdesc);
269   
270  0 JalviewStructureDisplayI viewr = openStructureViaChooser(alf,
271    pdb_viewseq, "4IM2");
272   
273    // and check all is good with feature location still
274  0 verifySeqFeats(pdb_viewseq, offset, fdesc);
275   
276    // finally check positional mapping for sequence and structure
277  0 PDBEntry pdbe = seq.getPDBEntry("4IM2");
278  0 StructureSelectionManager apssm = alf.alignPanel
279    .getStructureSelectionManager();
280  0 StructureMapping[] smap = apssm.getMapping(pdbe.getFile());
281  0 assertNotNull(smap);
282  0 assertNotNull(smap[0]);
283    // find the last position in the alignment sequence - this is not
284    // 'SequenceI.getEnd()' - which gets the last PDBRESNUM rather than
285    // SequenceI.getStart() + number of residues in file...
286  0 int realSeqEnd = pdb_viewseq.findPosition(pdb_viewseq.getLength());
287  0 List<int[]> ranges = smap[0].getPDBResNumRanges(pdb_viewseq.getStart(),
288    realSeqEnd);
289  0 assertEquals(structuremap1.size(), ranges.size());
290  0 int tot_mapped = 0;
291  0 for (int p = 0; p < ranges.size(); p++)
292    {
293  0 assertArrayEquals(structuremap1.get(p), ranges.get(p));
294  0 tot_mapped += 1 + (structuremap1.get(p)[1] - structuremap1.get(p)[0]);
295    }
296   
297  0 assertEquals(pdb_viewseq.getLength(), tot_mapped);
298   
299  0 int lastmappedp = StructureMapping.UNASSIGNED_VALUE;
300  0 for (int rp = pdb_viewseq.getStart(), rpEnd = pdb_viewseq
301  0 .findPosition(pdb_viewseq.getLength() - 1); rp <= rpEnd; rp++)
302    {
303  0 int mappedp = smap[0].getPDBResNum(rp);
304  0 if (mappedp != StructureMapping.UNASSIGNED_VALUE)
305    {
306  0 tot_mapped--;
307  0 if (lastmappedp == mappedp)
308    {
309  0 Assert.fail("Duplicate mapped position at " + rp + " (dupe = "
310    + mappedp + ")");
311    }
312    }
313    }
314   
315  0 Assert.assertEquals(tot_mapped, 0,
316    "Different number of mapped residues compared to ranges of mapped residues");
317   
318    // positional mapping to atoms for color by structure is still wrong, even
319    // though panel looks correct.
320   
321  0 String[] smcr = new JmolCommands().colourBySequence(apssm,
322    new String[]
323    { pdbe.getFile() },
324    new SequenceI[][]
325    { new SequenceI[] { pdb_viewseq } },
326    new SequenceRenderer(alf.alignPanel.getAlignViewport()),
327    alf.alignPanel);
328    // Expected - all residues are white
329  0 for (String c : smcr)
330    {
331  0 assertTrue(c.contains("color[255,255,255]"));
332  0 System.out.println(c);
333    }
334    }
335   
 
336  0 toggle private void verifySeqFeats(SequenceI pdbseq, int[] offset,
337    List<String> fdesc)
338    {
339  0 for (int o = 0; o < offset.length; o++)
340    {
341  0 int res = pdbseq.findPosition(offset[o]);
342  0 List<SequenceFeature> sf = pdbseq.getFeatures().findFeatures(res, res,
343    "RESNUM");
344  0 assertEquals("Expected sequence feature at position " + res + "("
345    + offset[o] + ")", 1, sf.size());
346  0 assertEquals("Wrong description at " + res + "(" + offset[o] + ")",
347    fdesc.get(o), sf.get(0).getDescription());
348    }
349   
350    }
351   
 
352  0 toggle @Test(groups = { "Network" })
353    public void testAssociatedMappingToSubSeq() throws Exception
354    {
355   
356    // currently this test fails if trimming is enabled
357  0 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
358    Boolean.FALSE.toString());
359  0 String TEMP_FACTOR_AA = "Temperature Factor";
360  0 String PDBID = "4IM2";
361  0 String FullLengthSeq = ">TBK1_HUMAN Serine/threonine-protein kinase TBK1\n"
362    + "MQSTSNHLWLLSDILGQGATANVFRGRHKKTGDLFAIKVFNNISFLRPVDVQMREFEVLKKLNHKNIVKLFA\n"
363    + "IEEETTTRHKVLIMEFCPCGSLYTVLEEPSNAYGLPESEFLIVLRDVVGGMNHLRENGIVHRDIKPGNIMRV\n"
364    + "IGEDGQSVYKLTDFGAARELEDDEQFVSLYGTEEYLHPDMYERAVLRKDHQKKYGATVDLWSIGVTFYHAAT\n"
365    + "GSLPFRPFEGPRRNKEVMYKIITGKPSGAISGVQKAENGPIDWSGDMPVSCSLSRGLQVLLTPVLANILEAD\n"
366    + "QEKCWGFDQFFAETSDILHRMVIHVFSLQQMTAHKIYIHSYNTATIFHELVYKQTKIISSNQELIYEGRRLV\n"
367    + "LEPGRLAQHFPKTTEENPIFVVSREPLNTIGLIYEKISLPKVHPRYDLDGDASMAKAITGVVCYACRIASTL\n"
368    + "LLYQELMRKGIRWLIELIKDDYNETVHKKTEVVITLDFCIRNIEKTVKVYEKLMKINLEAAELGEISDIHTK\n"
369    + "LLRLSSSQGTIETSLQDIDSRLSPGGSLADAWAHQEGTHPKDRNVEKLQVLLNCMTEIYYQFKKDKAERRLA\n"
370    + "YNEEQIHKFDKQKLYYHATKAMTHFTDECVKKYEAFLNKSEEWIRKMLHLRKQLLSLTNQCFDIEEEVSKYQ\n"
371    + "EYTNELQETLPQKMFTASSGIKHTMTPIYPSSNTLVEMTLGMKKLKEEMEGVVKELAENNHILERFGSLTMD\n"
372    + "GGLRNVDCL";
373    /*
374    * annotation exported after importing full length sequence to desktop, opening 4IM2 and selecting 'Add Reference Annotation'.
375    *
376    * Note - tabs must be replaced with \t - Eclipse expands them to spaces otherwise.
377    */
378  0 String FullLengthAnnot = "JALVIEW_ANNOTATION\n"
379    + "# Created: Mon Feb 05 15:30:20 GMT 2018\n"
380    + "# Updated: Fri Feb 09 17:05:17 GMT 2018\n" + "\n" + "\n"
381    + "SEQUENCE_REF\tTBK1_HUMAN\n"
382    + "LINE_GRAPH\tTemperature Factor\tTemperature Factor for 4im2A\t125.22|128.51|120.35|113.12|122.6|114.44|91.49|102.53|98.22|111.41|111.32|116.64|103.55|100.53|95.07|105.55|114.76|128.29|133.55|142.14|121.12|110.36|95.79|95.39|87.14|99.56|93.55|94.21|100.33|110.68|97.85|82.37|75.87|76.53|77.85|82.49|80.92|96.88|122.58|133.31|160.15|180.51|||||242.88|258.97|247.01|227.12|223.24|211.62|184.65|183.51|168.96|160.04|150.88|131.68|130.43|139.87|148.59|136.57|125.7|96.51|74.49|74.08|85.87|70.93|86.47|101.59|97.51|97.39|117.19|114.27|129.5|112.98|147.52|170.26|154.98|168.18|157.51|131.95|105.85|97.78|97.35|76.51|76.31|72.55|71.43|78.82|79.94|75.04|79.54|77.95|83.56|88.5|71.51|71.73|75.96|82.36|81.75|66.51|67.23|69.35|67.92|54.75|71.19|61.85|65.34|67.97|64.51|67.41|62.28|72.85|72.76|70.64|65.23|71.07|67.73|87.72|64.93|75.92|94.02|99.35|93.71|103.59|106.29|115.46|118.69|147.18|130.62|171.64|158.95|164.11||107.42|88.53|83.52|88.06|94.06|80.82|59.01|59.73|78.89|69.21|70.34|81.95|74.53|60.92|64.65|55.79|75.71|68.86|70.95|75.08|87.76|85.43|105.84|||||||||||||||||137.46|151.33|145.17|122.79|111.56|126.72|124.06|161.75|176.84|180.51|198.49|196.75|187.41||195.23|202.27|203.16|226.55|221.75|193.83||||||172.33|177.97|151.47|132.65|99.22|93.7|91.15|88.24|72.35|70.05|70.0|74.92|66.51|68.37|65.76|70.12|74.97|76.89|80.83|70.21|69.48|79.54|82.65|96.54|114.31|140.46|168.51|176.99|205.08|209.27|155.83|139.41|151.3|129.33|111.31|119.62|121.37|102.26|115.39|129.97|128.65|110.38|110.66|116.1|82.53|84.02|82.17|87.63|86.42|77.23|91.23|95.53|102.21|120.73|133.26|109.67|108.49|93.25|92.85|86.39|95.66|94.92|85.82|80.13|76.17|86.61|78.9|77.97|105.6|70.66|69.35|78.94|66.68|63.03|69.91|79.05|75.43|70.73|70.02|80.57|81.74|77.99|84.1|91.66|92.42|94.03|116.47|132.01|154.55|163.99|161.37|155.23|132.78|109.3|90.38|101.83|99.61|91.68|82.77|86.12|82.73|90.13|85.14|79.54|74.27|74.06|72.88|86.34|72.0|69.32|60.9|68.15|52.99|63.53|61.3|66.01|68.28|77.41|71.52|67.18|66.17|71.51|65.47|52.63|65.08|66.37|73.76|77.79|67.58|79.53|84.75|87.42|78.9|79.19|85.57|73.67|80.56|86.19|72.17|66.27|72.8|86.28|78.89|74.5|90.6|80.42|92.5|92.84|96.18|92.08|88.5|87.25|64.6|68.95|65.56|67.55|71.62|78.24|84.95|71.35|86.41|84.73|94.41|95.09|84.74|87.64|88.85|75.1|86.42|79.28|73.14|78.54|80.81|60.66|67.93|71.64|59.85|64.7|61.22|63.84|65.9|62.18|74.95|72.92|93.37|90.47|96.0|93.8|88.46|79.78|83.4|66.55|68.7|73.2|78.76|85.67|84.8|89.59|96.52|79.53|103.51|134.72|126.7|145.31|156.17|149.35|128.48|117.29|118.98|131.59|109.36|90.39|87.68|91.81|78.77|80.11|91.39|75.57|78.98|71.53|76.85|70.9|64.71|73.55|73.45|60.0|69.92|57.89|69.07|66.45|62.85|57.83|57.89|66.4|61.61|60.85|66.47|63.53|63.84|65.96|73.06|70.82|64.51|63.66|73.37|73.59|68.09|78.93|76.99|75.05|71.32|88.4|78.88|93.08|110.61|94.32|99.24|128.99|129.49|132.74|124.21|120.32|142.06|166.41|149.87|153.29|172.19|165.89|181.6|223.11|237.73|176.41|171.09|189.65|188.61|154.84|142.72|154.25|170.99|175.65|||||||110.61||||||||||158.07|170.73|167.93|198.47|212.36|181.71|157.69|163.31|138.96|120.29|131.63|152.26|125.06|136.66|148.97|129.68|120.52|135.31|136.05|119.39|124.18|128.94|123.02|103.37|128.44|134.12|118.88|120.94|130.38|124.67|112.21|113.69|123.65|132.06|114.97|110.75|92.38|101.2|103.25|94.84|85.3|82.19|89.81|98.81|83.03|68.91|65.24|70.31|63.49|86.38|71.07|62.65|63.95|66.98|58.06|68.28|62.11|63.86|67.4|68.69|69.57|68.03|74.23|75.66|70.67|81.08|81.31|82.49|88.15|95.99|92.97|100.01|113.18|122.37|110.99|122.19|159.27|147.74|133.96|111.2|115.64|126.55|107.15|102.85|117.06|116.56|109.55|96.82|98.92|96.53|86.0|88.11|92.76|85.77|79.41|93.06|86.96|76.35|72.37|74.19|68.6|67.46|74.47|76.25|66.73|73.18|75.2|88.21|84.93|75.04|71.09|82.6|80.03|76.22|75.76|83.72|75.85|79.36|90.35|86.9|78.24|95.64|97.38|86.41|85.02|91.87|87.36|77.56|81.25|91.66|83.65|77.67|85.07|89.21|92.66|92.46|89.0|100.83|96.71|94.81|101.37|111.28|124.48|119.73|127.81|134.41|132.4|140.32|140.86|166.52|160.16|168.39|176.74|174.63|172.86|168.55|155.9|132.71|113.44|113.49|123.9|151.11|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"
383    + "\n" + "";
384  0 AlignFrame alf_full = new FileLoader(false)
385    .LoadFileWaitTillLoaded(FullLengthSeq, DataSourceType.PASTE);
386  0 alf_full.loadJalviewDataFile(FullLengthAnnot, DataSourceType.PASTE,
387    null, null);
388  0 AlignmentI al_full = alf_full.getViewport().getAlignment();
389  0 AlignmentAnnotation fullseq_tf = al_full
390    .findAnnotations(al_full.getSequences().get(0), null,
391    TEMP_FACTOR_AA)
392    .iterator().next();
393  0 assertNotNull(fullseq_tf);
394   
395    // getMappingFor
396    // AlignmentI al_full=alf_full.getViewport().getAlignment();
397    //
398    // // load 4IM2 (full length, SIFTS onto full alingnment)
399    // SiftsSettings.setMapWithSifts(true);
400    // StructureChooser schoose = new StructureChooser(selectedSeqs_full,
401    // seq_full,
402    // alf_full.getViewport().getAlignPanel());
403    // schoose.selectStructure(PDBID);
404    // schoose.ok_ActionPerformed();
405   
406  0 AlignFrame alf = new FileLoader(false).LoadFileWaitTillLoaded(
407    ">TBK1_HUMAN/470-502 Serine/threonine-protein kinase TBK1\nFCIRNIEKTVKVYEKLMKINLEAAELGEISDIH",
408    DataSourceType.PASTE);
409  0 Desktop.addInternalFrame(alf, "Foo", 800, 600);
410  0 ;
411  0 AlignmentI al = alf.getViewport().getAlignment();
412  0 SequenceI seq = al.getSequenceAt(0);
413  0 assertEquals(470, seq.getStart());
414    // load 4IM2 (full length, SIFTS)
415  0 SiftsSettings.setMapWithSifts(true);
416  0 StructureImportSettings.setProcessSecondaryStructure(true);
417  0 StructureImportSettings.setVisibleChainAnnotation(true);
418  0 JalviewStructureDisplayI sview = openStructureViaChooser(alf, seq,
419    PDBID);
420   
421  0 AlignmentAnnotation subseq_tf = null;
422  0 assertTrue(seq.getDBRefs() != null && seq.getDBRefs().size() > 0);
423   
424  0 if (!al.findAnnotations(seq, null, TEMP_FACTOR_AA).iterator().hasNext())
425    {
426    // FIXME JAL-2321 - don't see reference annotation on alignment the first
427    // time
428    // around
429  0 SortedMap<String, String> tipEntries = new TreeMap<>();
430  0 final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
431   
432  0 AlignmentUtils.findAddableReferenceAnnotations(al.getSequences(),
433    tipEntries, candidates, al);
434  0 AlignmentUtils.addReferenceAnnotations(candidates, al, null);
435    // FAILS BECAUSE LABEL HAS PDB ID STRING
436  0 if (!al.findAnnotations(seq, null, TEMP_FACTOR_AA).iterator()
437    .hasNext())
438    {
439  0 Assert.fail(
440    "JAL-2321 or worse has occured. No secondary structure added to alignment.");
441    }
442    }
443  0 subseq_tf = al.findAnnotations(seq, null, TEMP_FACTOR_AA).iterator()
444    .next();
445    // verify against annotation after loading 4IM2 to full length TBK1_HUMAN
446    // verify location of mapped residues
447    // verify location of secondary structure annotation
448    // Specific positions: LYS477 (h),THR478 (no helix), ... GLY496(no helix),
449    // GLU497 (helix),
450   
451    // check there is or is not a tempfactor for each mapped position, and that
452    // values are equal for those positions.
453  0 for (int p = seq.getStart(); p <= seq.getEnd(); p++)
454    {
455  0 Annotation orig, subseq;
456  0 orig = fullseq_tf.getAnnotationForPosition(p);
457  0 subseq = subseq_tf.getAnnotationForPosition(p);
458  0 if (orig == null)
459    {
460  0 Assert.assertNull(subseq,
461    "Expected no annotation transferred at position " + p);
462    }
463  0 ;
464  0 if (orig != null)
465    {
466  0 Assert.assertNotNull(subseq,
467    "Expected annotation transfer at position " + p);
468  0 assertEquals(orig.value, subseq.value);
469    }
470  0 ;
471   
472    }
473    }
474   
 
475  0 toggle private JalviewStructureDisplayI openStructureViaChooser(AlignFrame alf,
476    SequenceI seq, String pDBID)
477    {
478   
479  0 SequenceI[] selectedSeqs = new SequenceI[] { seq };
480   
481  0 StructureChooser schoose = new StructureChooser(selectedSeqs, seq,
482    alf.getViewport().getAlignPanel());
483   
484  0 try
485    {
486  0 Thread.sleep(5000);
487    } catch (InterruptedException q)
488    {
489    }
490  0 ;
491  0 Assert.assertTrue(schoose.selectStructure(pDBID),
492    "Couldn't select structure via structure chooser: " + pDBID);
493  0 schoose.showStructures(true);
494  0 return schoose.getOpenedStructureViewer();
495    }
496   
 
497  1 toggle @DataProvider(name = "annotationProviderData")
498    public Object[][] annotationProviderData()
499    {
500  1 return new Object[][] {
501    { null, "desc", true, true, true, false, false }, // null PDB path
502    { "file.pdb", "desc", false, true, true, false, false }, // no pdb seq
503    { "file.pdb", "desc", true, false, true, false, false }, // no PDB entry
504    { "file.pdb", "desc", true, true, false, false, false }, // mismatched
505    // desc
506    { "file.pdb", "desc", true, true, true, true, false }, // valid provider
507    { "file.pdb", "desc", true, true, true, false, true }, // already has
508    // provider
509    };
510    }
511   
 
512  6 toggle @Test(dataProvider = "annotationProviderData", groups = { "Functional" })
513    public void testSaveAnnotationProvider(String pdbFilePath,
514    String ssAnnotDescriptionInPDB, boolean pdbSeqNotNull,
515    boolean pdbEntryNotNull, boolean sameDescInPDB,
516    boolean providerAvailableInPDBEntry,
517    boolean providerAlreadyPresent)
518    {
519   
520  6 SequenceI seq = mock(SequenceI.class);
521  6 SequenceI datasetSeq = mock(SequenceI.class);
522  6 StructureFile pdb = mock(StructureFile.class);
523  6 when(seq.getDatasetSequence()).thenReturn(datasetSeq);
524  6 when(pdb.getInFile()).thenReturn(pdbFilePath);
525   
526    // PDBEntry and datasequence object
527  6 if (pdbSeqNotNull)
528    {
529  5 SequenceI pdbSeq = mock(SequenceI.class);
530  5 AlignmentAnnotation pdbAnnotation = new AlignmentAnnotation(
531    "Secondary Structure", ssAnnotDescriptionInPDB,
532    new Annotation[] {});
533  5 AlignmentAnnotation[] pdbAnnotations = new AlignmentAnnotation[] {
534    pdbAnnotation };
535  5 when(pdbSeq.getAnnotation(Constants.SS_ANNOTATION_LABEL))
536    .thenReturn(pdbAnnotations);
537  5 Vector<SequenceI> pdbSeqs = new Vector<>();
538  5 pdbSeqs.add(pdbSeq);
539  5 when(pdb.getSeqs()).thenReturn(pdbSeqs);
540    }
541    else
542    {
543  1 when(pdb.getSeqs()).thenReturn(null);
544    }
545   
546  6 if (pdbEntryNotNull)
547    {
548  5 PDBEntry entry = mock(PDBEntry.class);
549  5 when(entry.getFile()).thenReturn("file.pdb");
550  5 when(entry.getProvider()).thenReturn("myprovider");
551   
552  5 Vector<PDBEntry> entries = new Vector<>();
553  5 entries.add(entry);
554  5 when(datasetSeq.getAllPDBEntries()).thenReturn(entries);
555    }
556    else
557    {
558  1 when(datasetSeq.getAllPDBEntries()).thenReturn(null);
559    }
560   
561    // Dataset annotation
562  6 AlignmentAnnotation datasetAnnotation = new AlignmentAnnotation(
563    "Secondary Structure", "", new Annotation[] {});
564  6 datasetAnnotation.description = sameDescInPDB ? ssAnnotDescriptionInPDB
565    : "desc2";
566  6 if (providerAlreadyPresent)
567    {
568  1 datasetAnnotation.setProperty(Constants.SS_PROVIDER_PROPERTY,
569    "myprovider2");
570    }
571   
572  6 when(datasetSeq.getAnnotation(Constants.SS_ANNOTATION_LABEL))
573    .thenReturn(new AlignmentAnnotation[]
574    { datasetAnnotation });
575   
576    // Call method
577  6 StructureSelectionManager instance = new StructureSelectionManager();
578  6 instance.saveAnnotationProvider(pdb, seq);
579   
580    // Assert
581  6 Object result = datasetAnnotation
582    .getProperty(Constants.SS_PROVIDER_PROPERTY);
583  6 if (providerAvailableInPDBEntry)
584    {
585  1 assert "myprovider".equals(result) : "Result should be myprovider";
586    }
587  5 else if (providerAlreadyPresent)
588    {
589  1 assert "myprovider2".equals(result) : "Result should be myprovider2";
590    }
591    else
592    {
593  4 assert result == null : "Result should be null";
594    }
595    }
596   
597    }