X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FAlignViewportTest.java;h=b3c6b2ae1fb9fbe92c5ce1e03c8aa3ecc3c4d9db;hb=efba321f20b819819c0b1cd9c9133d9d1a2ab314;hp=812fd8ff5e6e63436f7994fce03ee6751e357237;hpb=f4766a7bbcfae845fc95923b01fa14ff83d589ff;p=jalview.git diff --git a/test/jalview/gui/AlignViewportTest.java b/test/jalview/gui/AlignViewportTest.java index 812fd8f..b3c6b2a 100644 --- a/test/jalview/gui/AlignViewportTest.java +++ b/test/jalview/gui/AlignViewportTest.java @@ -23,9 +23,18 @@ package jalview.gui; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertNotSame; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; +import java.util.ArrayList; +import java.util.List; + +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.datamodel.AlignedCodonFrame; @@ -33,8 +42,6 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; import jalview.datamodel.Sequence; @@ -42,20 +49,13 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.FileLoader; +import jalview.schemes.ClustalxColourScheme; import jalview.schemes.ColourSchemeI; import jalview.schemes.PIDColourScheme; import jalview.structure.StructureSelectionManager; import jalview.util.MapList; import jalview.viewmodel.ViewportRanges; -import java.util.ArrayList; -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - public class AlignViewportTest { @@ -73,8 +73,9 @@ public class AlignViewportTest @BeforeClass(alwaysRun = true) public static void setUpBeforeClass() throws Exception { - Jalview.main(new String[] { "-nonews", "-props", - "test/jalview/testProps.jvprops" }); + Jalview.main( + new String[] + { "-nonews", "-props", "test/jalview/testProps.jvprops" }); /* * remove any sequence mappings left lying around by other tests @@ -96,57 +97,6 @@ public class AlignViewportTest testee = new AlignViewport(al); } - @Test(groups = { "Functional" }) - public void testCollateForPdb() - { - // JBP: What behaviour is this supposed to test ? - /* - * Set up sequence pdb ids - */ - PDBEntry pdb1 = new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb"); - PDBEntry pdb2 = new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb"); - PDBEntry pdb3 = new PDBEntry("3ABC", "D", Type.PDB, "3ABC.pdb"); - - /* - * seq1 and seq3 refer to 1abcB, seq2 to 2abcC, none to 3abcD - */ - al.getSequenceAt(0).getDatasetSequence() - .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb")); - al.getSequenceAt(2).getDatasetSequence() - .addPDBId(new PDBEntry("1ABC", "B", Type.PDB, "1ABC.pdb")); - al.getSequenceAt(1).getDatasetSequence() - .addPDBId(new PDBEntry("2ABC", "C", Type.PDB, "2ABC.pdb")); - /* - * Add a second chain PDB xref to Seq2 - should not result in a duplicate in - * the results - */ - al.getSequenceAt(1).getDatasetSequence() - .addPDBId(new PDBEntry("2ABC", "D", Type.PDB, "2ABC.pdb")); - /* - * Seq3 refers to 3abc - this does not match 3ABC (as the code stands) - */ - al.getSequenceAt(2).getDatasetSequence() - .addPDBId(new PDBEntry("3abc", "D", Type.PDB, "3ABC.pdb")); - - /* - * run method under test - */ - SequenceI[][] seqs = testee.collateForPDB(new PDBEntry[] { pdb1, pdb2, - pdb3 }); - - // seq1 and seq3 refer to PDBEntry[0] - assertEquals(2, seqs[0].length); - assertSame(al.getSequenceAt(0), seqs[0][0]); - assertSame(al.getSequenceAt(2), seqs[0][1]); - - // seq2 refers to PDBEntry[1] - assertEquals(1, seqs[1].length); - assertSame(al.getSequenceAt(1), seqs[1][0]); - - // no sequence refers to PDBEntry[2] - assertEquals(0, seqs[2].length); - } - /** * Test that a mapping is not deregistered when a second view is closed but * the first still holds a reference to the mapping @@ -157,16 +107,18 @@ public class AlignViewportTest /* * alignment with reference to mappings */ - AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( - ">Seq1\nCAGT\n", DataSourceType.PASTE); + AlignFrame af1 = new FileLoader() + .LoadFileWaitTillLoaded(">Seq1\nCAGT\n", DataSourceType.PASTE); SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0); AlignedCodonFrame acf1 = new AlignedCodonFrame(); - acf1.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 1, 4 }, - 1, 1)); + acf1.addMap(s1, s1, + new MapList(new int[] + { 1, 4 }, new int[] { 1, 4 }, 1, 1)); AlignedCodonFrame acf2 = new AlignedCodonFrame(); - acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 }, - 1, 1)); + acf2.addMap(s1, s1, + new MapList(new int[] + { 1, 4 }, new int[] { 4, 1 }, 1, 1)); List mappings = new ArrayList<>(); mappings.add(acf1); @@ -207,24 +159,27 @@ public class AlignViewportTest .getStructureSelectionManager(Desktop.instance); ssm.resetAll(); - AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( - ">Seq1\nRSVQ\n", DataSourceType.PASTE); - AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded( - ">Seq2\nDGEL\n", DataSourceType.PASTE); + AlignFrame af1 = new FileLoader() + .LoadFileWaitTillLoaded(">Seq1\nRSVQ\n", DataSourceType.PASTE); + AlignFrame af2 = new FileLoader() + .LoadFileWaitTillLoaded(">Seq2\nDGEL\n", DataSourceType.PASTE); SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA"); SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA"); SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0); SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0); // need to be distinct AlignedCodonFrame acf1 = new AlignedCodonFrame(); - acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 }, - new int[] { 1, 12 }, 1, 3)); + acf1.addMap(cs1, s1, + new MapList(new int[] + { 1, 4 }, new int[] { 1, 12 }, 1, 3)); AlignedCodonFrame acf2 = new AlignedCodonFrame(); - acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 }, - new int[] { 1, 12 }, 1, 3)); + acf2.addMap(cs2, s2, + new MapList(new int[] + { 1, 4 }, new int[] { 1, 12 }, 1, 3)); AlignedCodonFrame acf3 = new AlignedCodonFrame(); - acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1, - 12 }, 1, 1)); + acf3.addMap(cs2, cs2, + new MapList(new int[] + { 1, 12 }, new int[] { 1, 12 }, 1, 1)); List mappings1 = new ArrayList<>(); mappings1.add(acf1); @@ -270,24 +225,27 @@ public class AlignViewportTest .getStructureSelectionManager(Desktop.instance); ssm.resetAll(); - AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( - ">Seq1\nRSVQ\n", DataSourceType.PASTE); - AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded( - ">Seq2\nDGEL\n", DataSourceType.PASTE); + AlignFrame af1 = new FileLoader() + .LoadFileWaitTillLoaded(">Seq1\nRSVQ\n", DataSourceType.PASTE); + AlignFrame af2 = new FileLoader() + .LoadFileWaitTillLoaded(">Seq2\nDGEL\n", DataSourceType.PASTE); SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA"); SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA"); SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0); SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0); // need to be distinct AlignedCodonFrame acf1 = new AlignedCodonFrame(); - acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 }, - new int[] { 1, 12 }, 1, 3)); + acf1.addMap(cs1, s1, + new MapList(new int[] + { 1, 4 }, new int[] { 1, 12 }, 1, 3)); AlignedCodonFrame acf2 = new AlignedCodonFrame(); - acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 }, - new int[] { 1, 12 }, 1, 3)); + acf2.addMap(cs2, s2, + new MapList(new int[] + { 1, 4 }, new int[] { 1, 12 }, 1, 3)); AlignedCodonFrame acf3 = new AlignedCodonFrame(); - acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1, - 12 }, 1, 1)); + acf3.addMap(cs2, cs2, + new MapList(new int[] + { 1, 12 }, new int[] { 1, 12 }, 1, 1)); List mappings1 = new ArrayList<>(); mappings1.add(acf1); @@ -328,7 +286,7 @@ public class AlignViewportTest * Test for JAL-1306 - conservation thread should run even when only Quality * (and not Conservation) is enabled in Preferences */ - @Test(groups = { "Functional" }) + @Test(groups = { "Functional" }, timeOut = 2000) public void testUpdateConservation_qualityOnly() { Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", @@ -343,7 +301,13 @@ public class AlignViewportTest Boolean.FALSE.toString()); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); - AlignmentAnnotation[] anns = af.viewport.getAlignment() + + /* + * wait for Conservation thread to complete + */ + AlignViewport viewport = af.getViewport(); + waitForCalculations(viewport); + AlignmentAnnotation[] anns = viewport.getAlignment() .getAlignmentAnnotation(); assertNotNull("No annotations found", anns); assertEquals("More than one annotation found", 1, anns.length); @@ -355,6 +319,27 @@ public class AlignViewportTest assertTrue("No quality value in column 1", annotations[0].value > 10f); } + /** + * Wait for consensus etc calculation threads to complete + * + * @param viewport + */ + protected void waitForCalculations(AlignViewport viewport) + { + synchronized (this) + { + do + { + try + { + wait(50); + } catch (InterruptedException e) + { + } + } while (viewport.getCalcManager().isWorking()); + } + } + @Test(groups = { "Functional" }) public void testSetGlobalColourScheme() { @@ -367,9 +352,33 @@ public class AlignViewportTest AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); ColourSchemeI cs = new PIDColourScheme(); - af.getViewport().setGlobalColourScheme(cs); - assertFalse(af.getViewport().getResidueShading() - .conservationApplied()); + AlignViewport viewport = af.getViewport(); + viewport.setGlobalColourScheme(cs); + assertFalse(viewport.getResidueShading().conservationApplied()); + + /* + * JAL-3201 groups have their own ColourSchemeI instances + */ + AlignmentI aln = viewport.getAlignment(); + SequenceGroup sg1 = new SequenceGroup(); + sg1.addSequence(aln.getSequenceAt(0), false); + sg1.addSequence(aln.getSequenceAt(2), false); + SequenceGroup sg2 = new SequenceGroup(); + sg2.addSequence(aln.getSequenceAt(1), false); + sg2.addSequence(aln.getSequenceAt(3), false); + aln.addGroup(sg1); + aln.addGroup(sg2); + viewport.setColourAppliesToAllGroups(true); + viewport.setGlobalColourScheme(new ClustalxColourScheme()); + ColourSchemeI cs0 = viewport.getGlobalColourScheme(); + ColourSchemeI cs1 = sg1.getColourScheme(); + ColourSchemeI cs2 = sg2.getColourScheme(); + assertTrue(cs0 instanceof ClustalxColourScheme); + assertTrue(cs1 instanceof ClustalxColourScheme); + assertTrue(cs2 instanceof ClustalxColourScheme); + assertNotSame(cs0, cs1); + assertNotSame(cs0, cs2); + assertNotSame(cs1, cs2); } @Test(groups = { "Functional" }) @@ -425,18 +434,22 @@ public class AlignViewportTest av.setSelectionGroup(sg3); assertTrue(sg3.isDefined()); // unchanged } + /** - * Verify that setting/clearing SHOW_OCCUPANCY preference adds or omits occupancy row from viewport + * Verify that setting/clearing SHOW_OCCUPANCY preference adds or omits + * occupancy row from viewport */ @Test(groups = { "Functional" }) public void testShowOrDontShowOccupancy() { // disable occupancy - jalview.bin.Cache.setProperty("SHOW_OCCUPANCY", Boolean.FALSE.toString()); + jalview.bin.Cache.setProperty("SHOW_OCCUPANCY", + Boolean.FALSE.toString()); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); AlignViewport av = af.getViewport(); - Assert.assertNull(av.getAlignmentGapAnnotation(), "Preference did not disable occupancy row."); + Assert.assertNull(av.getAlignmentGapAnnotation(), + "Preference did not disable occupancy row."); int c = 0; for (AlignmentAnnotation aa : av.getAlignment().findAnnotations(null, null, "Occupancy")) @@ -444,13 +457,15 @@ public class AlignViewportTest c++; } Assert.assertEquals(c, 0, "Expected zero occupancy rows."); - + // enable occupancy - jalview.bin.Cache.setProperty("SHOW_OCCUPANCY", Boolean.TRUE.toString()); - af = new FileLoader().LoadFileWaitTillLoaded( - "examples/uniref50.fa", DataSourceType.FILE); + jalview.bin.Cache.setProperty("SHOW_OCCUPANCY", + Boolean.TRUE.toString()); + af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa", + DataSourceType.FILE); av = af.getViewport(); - Assert.assertNotNull(av.getAlignmentGapAnnotation(), "Preference did not enable occupancy row."); + Assert.assertNotNull(av.getAlignmentGapAnnotation(), + "Preference did not enable occupancy row."); c = 0; for (AlignmentAnnotation aa : av.getAlignment().findAnnotations(null, null, av.getAlignmentGapAnnotation().label)) @@ -475,6 +490,7 @@ public class AlignViewportTest AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta, DataSourceType.PASTE); AlignViewport testme = af.getViewport(); + waitForCalculations(testme); SequenceI cons = testme.getConsensusSeq(); assertEquals("A-C", cons.getSequenceAsString()); } @@ -506,8 +522,9 @@ public class AlignViewportTest /* * hide first and third sequences */ - testee.hideSequence(new SequenceI[] { al.getSequenceAt(0), - al.getSequenceAt(2) }); + testee.hideSequence( + new SequenceI[] + { al.getSequenceAt(0), al.getSequenceAt(2) }); assertEquals(1, al.getHeight()); assertEquals(0, ranges.getStartSeq()); assertEquals(0, ranges.getEndSeq());