*/
package jalview.gui;
+import static org.junit.Assert.assertNotEquals;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotSame;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
+import java.awt.Color;
+import java.util.Iterator;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import jalview.api.FeatureColourI;
import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.HiddenColumns;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
-import jalview.io.Jalview2xmlTests;
+import jalview.project.Jalview2xmlTests;
import jalview.renderer.ResidueShaderI;
import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.FeatureColour;
import jalview.schemes.HelixColourScheme;
import jalview.schemes.JalviewColourScheme;
import jalview.schemes.StrandColourScheme;
import jalview.schemes.TurnColourScheme;
import jalview.util.MessageManager;
-import java.awt.Color;
-import java.util.List;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
public class AlignFrameTest
{
AlignFrame af;
@BeforeClass(alwaysRun = true)
- public void setUpJvOptionPane()
- {
- JvOptionPane.setInteractiveMode(false);
- JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
- }
-
- @Test(groups = "Functional")
- public void testHideFeatureColumns()
- {
- SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ");
- SequenceI seq2 = new Sequence("Seq2", "ABCDEFGHIJ");
- seq1.addSequenceFeature(new SequenceFeature("Metal", "", 1, 5,
- Float.NaN, null));
- seq2.addSequenceFeature(new SequenceFeature("Metal", "", 6, 10,
- Float.NaN, null));
- seq1.addSequenceFeature(new SequenceFeature("Turn", "", 2, 4,
- Float.NaN, null));
- seq2.addSequenceFeature(new SequenceFeature("Turn", "", 7, 9,
- Float.NaN, null));
- AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
- AlignFrame alignFrame = new AlignFrame(al, al.getWidth(), al.getHeight());
-
- /*
- * hiding a feature not present does nothing
- */
- assertFalse(alignFrame.hideFeatureColumns("exon", true));
- assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
- assertTrue(alignFrame.getViewport().getColumnSelection().getHiddenColumns()
- .isEmpty());
- assertFalse(alignFrame.hideFeatureColumns("exon", false));
- assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
- assertTrue(alignFrame.getViewport().getColumnSelection().getHiddenColumns()
- .isEmpty());
-
- /*
- * hiding a feature in all columns does nothing
- */
- assertFalse(alignFrame.hideFeatureColumns("Metal", true));
- assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
- List<int[]> hidden = alignFrame.getViewport().getColumnSelection()
- .getHiddenColumns();
- assertTrue(hidden.isEmpty());
-
- /*
- * hide a feature present in some columns
- * sequence positions [2-4], [7-9] are column positions
- * [1-3], [6-8] base zero
- */
- assertTrue(alignFrame.hideFeatureColumns("Turn", true));
- hidden = alignFrame.getViewport().getColumnSelection().getHiddenColumns();
- assertEquals(hidden.size(), 2);
- assertEquals(hidden.get(0)[0], 1);
- assertEquals(hidden.get(0)[1], 3);
- assertEquals(hidden.get(1)[0], 6);
- assertEquals(hidden.get(1)[1], 8);
- }
-
- @BeforeClass(alwaysRun = true)
public static void setUpBeforeClass() throws Exception
{
+ setUpJvOptionPane();
/*
* use read-only test properties file
*/
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- Desktop.instance.closeAll_actionPerformed(null);
+ if (Desktop.instance != null)
+ Desktop.instance.closeAll_actionPerformed(null);
}
/**
/*
* wait for Consensus thread to complete
*/
- synchronized (this)
+ do
{
- while (af.getViewport().getConsensusSeq() == null)
+ try
+ {
+ Thread.sleep(50);
+ } catch (InterruptedException x)
{
- try
- {
- wait(50);
- } catch (InterruptedException e)
- {
- }
}
- }
+ } while (af.getViewport().getCalcManager().isWorking());
+ }
+
+ public static void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ @Test(groups = "Functional")
+ public void testHideFeatureColumns()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ");
+ SequenceI seq2 = new Sequence("Seq2", "ABCDEFGHIJ");
+ seq1.addSequenceFeature(
+ new SequenceFeature("Metal", "", 1, 5, 0f, null));
+ seq2.addSequenceFeature(
+ new SequenceFeature("Metal", "", 6, 10, 10f, null));
+ seq1.addSequenceFeature(
+ new SequenceFeature("Turn", "", 2, 4, Float.NaN, null));
+ seq2.addSequenceFeature(
+ new SequenceFeature("Turn", "", 7, 9, Float.NaN, null));
+ AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
+ AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
+ al.getHeight());
+
+ /*
+ * make all features visible (select feature columns checks visibility)
+ */
+ alignFrame.getFeatureRenderer().findAllFeatures(true);
+
+ /*
+ * hiding a feature not present does nothing
+ */
+ assertFalse(alignFrame.hideFeatureColumns("exon", true));
+ assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
+
+ assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
+ .getNumberOfRegions(), 0);
+
+ assertFalse(alignFrame.hideFeatureColumns("exon", false));
+ assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
+
+ assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
+ .getNumberOfRegions(), 0);
+
+ /*
+ * hiding a feature in all columns does nothing
+ */
+ assertFalse(alignFrame.hideFeatureColumns("Metal", true));
+ assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty());
+
+ assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
+ .getNumberOfRegions(), 0);
+
+ /*
+ * threshold Metal to hide features where score < 5
+ * seq1 feature in columns 1-5 is hidden
+ * seq2 feature in columns 6-10 is shown
+ */
+ FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null,
+ 0f, 10f);
+ fc.setAboveThreshold(true);
+ fc.setThreshold(5f);
+ alignFrame.getFeatureRenderer().setColour("Metal", fc);
+ assertTrue(alignFrame.hideFeatureColumns("Metal", true));
+ HiddenColumns hidden = alignFrame.getViewport().getAlignment()
+ .getHiddenColumns();
+ assertEquals(hidden.getNumberOfRegions(), 1);
+ Iterator<int[]> regions = hidden.iterator();
+ int[] next = regions.next();
+ assertEquals(next[0], 5);
+ assertEquals(next[1], 9);
+
+ /*
+ * hide a feature present in some columns
+ * sequence positions [2-4], [7-9] are column positions
+ * [1-3], [6-8] base zero
+ */
+ alignFrame.getViewport().showAllHiddenColumns();
+ assertTrue(alignFrame.hideFeatureColumns("Turn", true));
+ regions = alignFrame.getViewport().getAlignment().getHiddenColumns()
+ .iterator();
+ assertEquals(alignFrame.getViewport().getAlignment().getHiddenColumns()
+ .getNumberOfRegions(), 2);
+ next = regions.next();
+ assertEquals(next[0], 1);
+ assertEquals(next[1], 3);
+ next = regions.next();
+ assertEquals(next[0], 6);
+ assertEquals(next[1], 8);
}
/**
* <ul>
* <li>with Apply Colour to All Groups not selected, does not change group
* colours</li>
- * <li>with Apply Colour to All Groups selected, does change group colours</li>
+ * <li>with Apply Colour to All Groups selected, does change group
+ * colours</li>
* <li>in neither case, changes alignment or group colour thresholds (PID or
* Conservation)</li>
* </ul>
af.conservationMenuItem_actionPerformed(true);
SliderPanel sp = SliderPanel.getSliderPanel();
assertEquals(sp.getTitle(), MessageManager.formatMessage(
- "label.conservation_colour_increment",
- new String[] { "Background" }));
+ "label.conservation_colour_increment", new String[]
+ { "Background" }));
assertTrue(sp.isForConservation());
sp.valueChanged(20);
assertTrue(av.getResidueShading().conservationApplied());
sp = SliderPanel.getSliderPanel();
assertFalse(sp.isForConservation());
assertEquals(sp.getTitle(), MessageManager.formatMessage(
- "label.percentage_identity_threshold",
- new String[] { "Background" }));
+ "label.percentage_identity_threshold", new String[]
+ { "Background" }));
sp.valueChanged(10);
assertEquals(av.getResidueShading().getThreshold(), 10);
assertTrue(av.getResidueShading().conservationApplied());
/*
* apply 30% Conservation to group
+ * (notice menu action applies to selection group even if mouse click
+ * is at a sequence not in the group)
*/
- PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
- popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
- .toString());
+ PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(2),
+ null);
+ popupMenu.changeColour_actionPerformed(
+ JalviewColourScheme.Strand.toString());
assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
assertEquals(al.getGroups().size(), 1);
assertSame(al.getGroups().get(0), sg);
sp = SliderPanel.getSliderPanel();
assertTrue(sp.isForConservation());
assertEquals(sp.getTitle(), MessageManager.formatMessage(
- "label.conservation_colour_increment",
- new String[] { sg.getName() }));
+ "label.conservation_colour_increment", new String[]
+ { sg.getName() }));
sp.valueChanged(30);
assertTrue(sg.getGroupColourScheme().conservationApplied());
assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
sp = SliderPanel.getSliderPanel();
assertFalse(sp.isForConservation());
assertEquals(sp.getTitle(), MessageManager.formatMessage(
- "label.percentage_identity_threshold",
- new String[] { sg.getName() }));
+ "label.percentage_identity_threshold", new String[]
+ { sg.getName() }));
sp.valueChanged(40);
assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
// conservation threshold is unchanged:
/*
* inspect the colour of
- * FER_CAPAN.9(I), column 14 (14 base 0)
+ * FER_CAPAN.9(I), column 15 (14 base 0)
* FER_CAPAN.10(SER), column 16 (15 base 0)
*/
SequenceI ferCapan = al.findName("FER_CAPAN");
SliderPanel sp = SliderPanel.getSliderPanel();
assertTrue(sp.isForConservation());
assertEquals(sp.getValue(), 30); // initial slider setting
+ c = rs.findColour('I', 14, ferCapan);
+ Color i_faded = new Color(255, 255, 255);
+ assertEquals(c, i_faded);
sp.valueChanged(10);
assertSame(rs, av.getResidueShading());
+ assertEquals(rs.getConservationInc(), 10);
c = rs.findColour('I', 14, ferCapan);
- Color i_faded = new Color(196, 186, 196);
+ i_faded = new Color(196, 186, 196);
assertEquals(c, i_faded);
c = rs.findColour('S', 15, ferCapan);
Color s_faded = new Color(144, 225, 144);
sg.setStartRes(15);
sg.setEndRes(25);
av.setSelectionGroup(sg);
- PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
- popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
- .toString());
+ PopupMenu popupMenu = new PopupMenu(af.alignPanel, al.getSequenceAt(0),
+ null);
+ popupMenu.changeColour_actionPerformed(
+ JalviewColourScheme.Strand.toString());
assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
assertEquals(al.getGroups().size(), 1);
assertSame(al.getGroups().get(0), sg);
sp = SliderPanel.getSliderPanel();
assertTrue(sp.isForConservation());
assertEquals(sp.getTitle(), MessageManager.formatMessage(
- "label.conservation_colour_increment",
- new String[] { "Background" }));
+ "label.conservation_colour_increment", new String[]
+ { "Background" }));
/*
* make a new View, verify alignment and group colour schemes
assertEquals(af.alignPanel.getViewName(), "View 1");
AlignViewport av2 = af.getViewport();
assertNotSame(av, av2);
+ assertSame(av2, af.alignPanel.av);
rs = av2.getResidueShading();
assertNotSame(av.getResidueShading(), rs);
assertEquals(rs.getThreshold(), 10);
- assertTrue(rs.conservationApplied());
+ assertTrue(rs.conservationApplied(), rs.toString());
assertEquals(rs.getConservationInc(), 20);
assertEquals(av2.getAlignment().getGroups().size(), 1);
sg = av2.getAlignment().getGroups().get(0);
sp = SliderPanel.getSliderPanel();
assertTrue(sp.isForConservation());
assertEquals(sp.getTitle(), MessageManager.formatMessage(
- "label.conservation_colour_increment",
- new String[] { "View 1" }));
+ "label.conservation_colour_increment", new String[]
+ { "View 1" }));
sp.valueChanged(22);
assertEquals(av2.getResidueShading().getConservationInc(), 22);
}
+
+ /**
+ * Verify that making a New View preserves the dataset reference for the
+ * alignment. Otherwise, see a 'duplicate jar entry' reference when trying to
+ * save alignments with multiple views, and codon mappings will not be shared
+ * across all panels in a split frame.
+ *
+ * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds()
+ */
+ @Test(groups = "Functional")
+ public void testNewView_dsRefPreserved()
+ {
+ AlignViewport av = af.getViewport();
+ AlignmentI al = av.getAlignment();
+ AlignmentI original_ds = al.getDataset();
+ af.newView_actionPerformed(null);
+ assertNotEquals("New view didn't select the a new panel", av,
+ af.getViewport());
+ org.testng.Assert.assertEquals(original_ds,
+ af.getViewport().getAlignment().getDataset(),
+ "Dataset was not preserved in new view");
+ }
}