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;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
+import jalview.datamodel.ContactMatrixI;
import jalview.datamodel.SearchResults;
import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SeqDistanceContactMatrix;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
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
{
@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
/*
* 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<AlignedCodonFrame> mappings = new ArrayList<>();
mappings.add(acf1);
.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<AlignedCodonFrame> mappings1 = new ArrayList<>();
mappings1.add(acf1);
.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<AlignedCodonFrame> mappings1 = new ArrayList<>();
mappings1.add(acf1);
* Test for JAL-1306 - conservation thread should run even when only Quality
* (and not Conservation) is enabled in Preferences
*/
- @Test(groups = { "Functional" }, timeOut=2000)
+ @Test(groups = { "Functional" }, timeOut = 2000)
public void testUpdateConservation_qualityOnly()
{
Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
* wait for Conservation thread to complete
*/
AlignViewport viewport = af.getViewport();
- synchronized (this)
- {
- while (viewport.getAlignmentConservationAnnotation() != null)
- {
- try
- {
- wait(50);
- } catch (InterruptedException e)
- {
- }
- }
- }
+ waitForCalculations(viewport);
AlignmentAnnotation[] anns = viewport.getAlignment()
.getAlignmentAnnotation();
assertNotNull("No annotations found", anns);
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()
{
ColourSchemeI cs = new PIDColourScheme();
AlignViewport viewport = af.getViewport();
viewport.setGlobalColourScheme(cs);
- assertFalse(viewport.getResidueShading()
- .conservationApplied());
+ assertFalse(viewport.getResidueShading().conservationApplied());
/*
* JAL-3201 groups have their own ColourSchemeI instances
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"))
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))
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
DataSourceType.PASTE);
AlignViewport testme = af.getViewport();
+ waitForCalculations(testme);
SequenceI cons = testme.getConsensusSeq();
assertEquals("A-C", cons.getSequenceAsString());
}
/*
* 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());
assertEquals(0, ranges.getStartSeq());
assertEquals(2, ranges.getEndSeq());
}
+ @Test(groups = {"Functional"})
+ public void testGetSelectionAsNewSequences_withContactMatrices()
+ {
+ SequenceI seq = new Sequence("seq","ACADA");
+ ContactMatrixI cmat = new SeqDistanceContactMatrix(5);
+ seq.addContactList(cmat);
+ Alignment al = new Alignment(new SequenceI[] {seq.deriveSequence() });
+ al.addAnnotation(al.getSequenceAt(0).getAnnotation()[0]);
+ AlignFrame af = new AlignFrame(al,500,500);
+
+ SequenceI selseqs[] = af.getViewport().getSelectionAsNewSequence();
+ assertNotNull(selseqs[0].getAnnotation());
+ assertNotNull(selseqs[0].getAnnotation()[0]);
+ assertEquals(cmat,selseqs[0].getContactMatrixFor(selseqs[0].getAnnotation()[0]));
+
+ assertNotNull(selseqs[0].getContactListFor(selseqs[0].getAnnotation()[0], 2));
+
+ // now select everything and test again
+ af.selectAllSequenceMenuItem_actionPerformed(null);
+ selseqs = af.getViewport().getSelectionAsNewSequence();
+ assertNotNull(selseqs[0].getAnnotation());
+ assertNotNull(selseqs[0].getAnnotation()[0]);
+ assertEquals(cmat,selseqs[0].getContactMatrixFor(selseqs[0].getAnnotation()[0]));
+ assertNotNull(selseqs[0].getContactListFor(selseqs[0].getAnnotation()[0], 2));
+ }
}