From 424f6f03e8fb5e40cceca09fc8ffd72b41e3a9e4 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 31 Jan 2017 14:38:38 +0000 Subject: [PATCH] JAL-2385 more tests/bug fixes mostly for gui.SliderPanel and some JAL-2371 tidying --- src/jalview/api/AlignViewportI.java | 16 +- src/jalview/appletgui/AlignFrame.java | 4 +- src/jalview/appletgui/SeqPanel.java | 4 +- src/jalview/appletgui/SliderPanel.java | 16 +- src/jalview/gui/AlignFrame.java | 35 ++- src/jalview/gui/AlignViewport.java | 6 +- src/jalview/gui/PopupMenu.java | 4 +- src/jalview/gui/SeqPanel.java | 4 +- src/jalview/gui/SliderPanel.java | 80 +++--- src/jalview/renderer/ResidueShader.java | 60 +++- src/jalview/schemes/PIDColourScheme.java | 9 +- src/jalview/schemes/ResidueProperties.java | 7 - src/jalview/viewmodel/AlignmentViewport.java | 38 ++- test/jalview/gui/AlignFrameTest.java | 370 +++++++++++++++++++++++-- test/jalview/gui/AlignViewportTest.java | 3 +- test/jalview/io/FileFormatsTest.java | 9 +- test/jalview/io/Jalview2xmlTests.java | 287 +++++++++++++------ test/jalview/io/JalviewFileViewTest.java | 6 +- test/jalview/renderer/ScaleRendererTest.java | 2 +- test/jalview/schemes/PIDColourSchemeTest.java | 4 +- 20 files changed, 743 insertions(+), 221 deletions(-) diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index 9fcf89a..33a0061 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -80,6 +80,12 @@ public interface AlignViewportI extends ViewStyleI ColourSchemeI getGlobalColourScheme(); + /** + * Returns an object that describes colouring (including any thresholding or + * fading) of the alignment + * + * @return + */ ResidueShaderI getViewportColourScheme(); AlignmentI getAlignment(); @@ -160,7 +166,7 @@ public interface AlignViewportI extends ViewStyleI /** * - * @return the alignment annotatino row for the structure consensus + * @return the alignment annotation row for the structure consensus * calculation */ AlignmentAnnotation getAlignmentStrucConsensusAnnotation(); @@ -173,11 +179,13 @@ public interface AlignViewportI extends ViewStyleI void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus); /** - * set global colourscheme + * Sets the colour scheme for the background alignment (as distinct from + * sub-groups, which may have their own colour schemes). A null value is used + * for no residue colour (white). * - * @param rhc + * @param cs */ - void setGlobalColourScheme(ColourSchemeI rhc); + void setGlobalColourScheme(ColourSchemeI cs); Map getHiddenRepSequences(); diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 4c4c84f..d30f10d 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -2642,7 +2642,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, && viewport.getGlobalColourScheme() != null) { SliderPanel.setPIDSliderSource(alignPanel, - viewport.getViewportColourScheme(), "Background"); + viewport.getViewportColourScheme(), alignPanel.getViewName()); SliderPanel.showPIDSlider(); } } @@ -2653,7 +2653,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, && viewport.getGlobalColourScheme() != null) { SliderPanel.setConservationSlider(alignPanel, - viewport.getViewportColourScheme(), "Background"); + viewport.getViewportColourScheme(), alignPanel.getViewName()); SliderPanel.showConservationSlider(); } } diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index c1cddaa..41529cd 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -1506,12 +1506,12 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (av.getConservationSelected()) { SliderPanel.setConservationSlider(ap, av.getViewportColourScheme(), - "Background"); + ap.getViewName()); } if (av.getAbovePIDThreshold()) { SliderPanel.setPIDSliderSource(ap, av.getViewportColourScheme(), - "Background"); + ap.getViewName()); } } diff --git a/src/jalview/appletgui/SliderPanel.java b/src/jalview/appletgui/SliderPanel.java index 2354ba1..9154aa0 100644 --- a/src/jalview/appletgui/SliderPanel.java +++ b/src/jalview/appletgui/SliderPanel.java @@ -49,6 +49,8 @@ import java.util.Iterator; public class SliderPanel extends Panel implements ActionListener, AdjustmentListener, MouseListener { + private static final String BACKGROUND = "Background"; + AlignmentPanel ap; boolean forConservation = true; @@ -77,10 +79,9 @@ public class SliderPanel extends Panel implements ActionListener, sp.valueField.setText(String.valueOf(ccs.getConservationInc())); } - conservationSlider - .setTitle(MessageManager.formatMessage( - "label.conservation_colour_increment", - new String[] { source })); + conservationSlider.setTitle(MessageManager.formatMessage( + "label.conservation_colour_increment", + new String[] { source == null ? BACKGROUND : source })); if (ap.av.getAlignment().getGroups() != null) { sp.setAllGroupsCheckEnabled(true); @@ -136,10 +137,9 @@ public class SliderPanel extends Panel implements ActionListener, pid.cs = ccs; pid.valueField.setText(String.valueOf(ccs.getThreshold())); } - PIDSlider - .setTitle(MessageManager.formatMessage( - "label.percentage_identity_threshold", - new String[] { source })); + PIDSlider.setTitle(MessageManager.formatMessage( + "label.percentage_identity_threshold", + new String[] { source == null ? BACKGROUND : source })); if (ap.av.getAlignment().getGroups() != null) { diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 266cbcb..cf6a901 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3301,7 +3301,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param selected */ @Override - protected void applyToAllGroups_actionPerformed(boolean selected) + public void applyToAllGroups_actionPerformed(boolean selected) { viewport.setColourAppliesToAllGroups(selected); } @@ -3359,7 +3359,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void modifyPID_actionPerformed() { SliderPanel.setPIDSliderSource(alignPanel, - viewport.getViewportColourScheme(), "Background"); + viewport.getViewportColourScheme(), alignPanel.getViewName()); SliderPanel.showPIDSlider(); } @@ -3370,7 +3370,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void modifyConservation_actionPerformed() { SliderPanel.setConservationSlider(alignPanel, - viewport.getViewportColourScheme(), "Background"); + viewport.getViewportColourScheme(), alignPanel.getViewName()); SliderPanel.showConservationSlider(); } @@ -3378,7 +3378,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Action on selecting or deselecting (Colour) By Conservation */ @Override - protected void conservationMenuItem_actionPerformed(boolean selected) + public void conservationMenuItem_actionPerformed(boolean selected) { modifyConservation.setEnabled(selected); viewport.setConservationSelected(selected); @@ -3403,6 +3403,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { modifyPID.setEnabled(selected); viewport.setAbovePIDThreshold(selected); + if (!selected) + { + viewport.getViewportColourScheme().setThreshold(0, + viewport.isIgnoreGapsConsensus()); + } changeColour(viewport.getGlobalColourScheme()); if (selected) @@ -4828,6 +4833,28 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /* + * 'focus' any colour slider that is open to the selected viewport + */ + if (viewport.getConservationSelected()) + { + SliderPanel.setConservationSlider(alignPanel, + viewport.getViewportColourScheme(), alignPanel.getViewName()); + } + else + { + SliderPanel.hideConservationSlider(); + } + if (viewport.getAbovePIDThreshold()) + { + SliderPanel.setPIDSliderSource(alignPanel, + viewport.getViewportColourScheme(), alignPanel.getViewName()); + } + else + { + SliderPanel.hidePIDSlider(); + } + + /* * If there is a frame linked to this one in a SplitPane, switch it to the * same view tab index. No infinite recursion of calls should happen, since * tabSelectionChanged() should not get invoked on setting the selected diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index a201757..ea9eb21 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -385,7 +385,11 @@ public class AlignViewport extends AlignmentViewport implements super.setViewStyle(settingsForView); setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(), viewStyle.getFontSize()), false); - + if (globalColourScheme != null) + { + globalColourScheme.setConservationApplied(settingsForView + .isConservationColourSelected()); + } } /** diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 37cd8b3..c94d24d 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1534,7 +1534,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener * @param e * DOCUMENT ME! */ - protected void abovePIDColour_actionPerformed(boolean selected) + public void abovePIDColour_actionPerformed(boolean selected) { SequenceGroup sg = getGroup(); if (sg.cs == null) @@ -1585,7 +1585,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener * @param e * DOCUMENT ME! */ - protected void conservationMenuItem_actionPerformed(boolean selected) + public void conservationMenuItem_actionPerformed(boolean selected) { SequenceGroup sg = getGroup(); if (sg.cs == null) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 07dad72..6214a7c 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1656,13 +1656,13 @@ public class SeqPanel extends JPanel implements MouseListener, if (av.getConservationSelected()) { SliderPanel.setConservationSlider(ap, av.getViewportColourScheme(), - "Background"); + ap.getViewName()); } if (av.getAbovePIDThreshold()) { SliderPanel.setPIDSliderSource(ap, av.getViewportColourScheme(), - "Background"); + ap.getViewName()); } if ((stretchGroup != null) && (stretchGroup.getEndRes() == res)) { diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 1793a9b..0c4e03e 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -44,6 +44,8 @@ import javax.swing.event.InternalFrameEvent; */ public class SliderPanel extends GSliderPanel { + private static final String BACKGROUND = "Background"; + static JInternalFrame conservationSlider; static JInternalFrame PIDSlider; @@ -54,16 +56,22 @@ public class SliderPanel extends GSliderPanel ResidueShaderI cs; - private static SliderPanel sliderPanel; - /** - * Returns the currently active slider panel (or null if none). + * Returns the currently displayed slider panel (or null if none). * * @return */ public static SliderPanel getSliderPanel() { - return sliderPanel; + if (conservationSlider != null && conservationSlider.isVisible()) + { + return (SliderPanel) conservationSlider.getContentPane(); + } + if (PIDSlider != null && PIDSlider.isVisible()) + { + return (SliderPanel) PIDSlider.getContentPane(); + } + return null; } /** @@ -126,25 +134,25 @@ public class SliderPanel extends GSliderPanel } /** - * DOCUMENT ME! + * Method to 'set focus' of the Conservation slider panel * * @param ap - * DOCUMENT ME! - * @param ccs - * DOCUMENT ME! + * the panel to repaint on change of slider + * @param rs + * the colour scheme to update on change of slider * @param source - * DOCUMENT ME! + * a text description for the panel's title * - * @return DOCUMENT ME! + * @return */ public static int setConservationSlider(AlignmentPanel ap, - ResidueShaderI ccs, String source) + ResidueShaderI rs, String source) { - sliderPanel = null; + SliderPanel sliderPanel = null; if (conservationSlider == null) { - sliderPanel = new SliderPanel(ap, ccs.getConservationInc(), true, ccs); + sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs); conservationSlider = new JInternalFrame(); conservationSlider.setContentPane(sliderPanel); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -152,14 +160,15 @@ public class SliderPanel extends GSliderPanel else { sliderPanel = (SliderPanel) conservationSlider.getContentPane(); - sliderPanel.valueField.setText(String.valueOf(ccs.getConservationInc())); - sliderPanel.cs = ccs; + sliderPanel.valueField.setText(String.valueOf(rs.getConservationInc())); + sliderPanel.cs = rs; + sliderPanel.ap = ap; + sliderPanel.slider.setValue(rs.getConservationInc()); } - conservationSlider - .setTitle(MessageManager.formatMessage( - "label.conservation_colour_increment", - new String[] { source })); + conservationSlider.setTitle(MessageManager.formatMessage( + "label.conservation_colour_increment", + new String[] { source == null ? BACKGROUND : source })); if (ap.av.getAlignment().getGroups() != null) { @@ -232,25 +241,27 @@ public class SliderPanel extends GSliderPanel } /** - * DOCUMENT ME! + * Method to 'set focus' of the PID slider panel * * @param ap - * DOCUMENT ME! - * @param ccs - * DOCUMENT ME! + * the panel to repaint on change of slider + * @param rs + * the colour scheme to update on change of slider * @param source - * DOCUMENT ME! + * a text description for the panel's title * - * @return DOCUMENT ME! + * @return */ public static int setPIDSliderSource(AlignmentPanel ap, - ResidueShaderI ccs, String source) + ResidueShaderI rs, String source) { - int threshold = ccs.getThreshold(); + int threshold = rs.getThreshold(); + + SliderPanel sliderPanel = null; if (PIDSlider == null) { - sliderPanel = new SliderPanel(ap, threshold, false, ccs); + sliderPanel = new SliderPanel(ap, threshold, false, rs); PIDSlider = new JInternalFrame(); PIDSlider.setContentPane(sliderPanel); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -258,14 +269,15 @@ public class SliderPanel extends GSliderPanel else { sliderPanel = (SliderPanel) PIDSlider.getContentPane(); - sliderPanel.cs = ccs; - sliderPanel.valueField.setText(String.valueOf(ccs.getThreshold())); + sliderPanel.cs = rs; + sliderPanel.ap = ap; + sliderPanel.valueField.setText(String.valueOf(rs.getThreshold())); + sliderPanel.slider.setValue(rs.getThreshold()); } - PIDSlider - .setTitle(MessageManager.formatMessage( - "label.percentage_identity_threshold", - new String[] { source })); + PIDSlider.setTitle(MessageManager.formatMessage( + "label.percentage_identity_threshold", + new String[] { source == null ? BACKGROUND : source })); if (ap.av.getAlignment().getGroups() != null) { diff --git a/src/jalview/renderer/ResidueShader.java b/src/jalview/renderer/ResidueShader.java index c591031..3f5cd11 100644 --- a/src/jalview/renderer/ResidueShader.java +++ b/src/jalview/renderer/ResidueShader.java @@ -1,6 +1,7 @@ package jalview.renderer; import jalview.analysis.Conservation; +import jalview.api.ViewStyleI; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.ProfileI; import jalview.datamodel.ProfilesI; @@ -27,19 +28,47 @@ import java.util.Map; */ public class ResidueShader implements ResidueShaderI { + private static final int INITIAL_CONSERVATION = 30; + + /* + * the colour scheme that gives the colour of each residue + * before applying any conservation or PID shading + */ private ColourSchemeI colourScheme; + /* + * the consensus data for each column + */ private ProfilesI consensus; + /* + * if true, apply shading of colour by conservation + */ private boolean conservationColouring; + /* + * the phsyico-chemical property conservation scores for columns, with values + * 0-9, '+' (all properties conserved), '*' (residue fully conserved) or '-' (gap) + * (may be null if colour by conservation is not selected) + */ private char[] conservation; - private int threshold; + /* + * minimum percentage identity for colour to be applied; + * if above zero, residue must match consensus (or joint consensus) + * and column have >= pidThreshold identity with the residue + */ + private int pidThreshold; + /* + * if true, ignore gaps in percentage identity calculation + */ private boolean ignoreGaps; - private int inc; + /* + * setting of the By Conservation slider + */ + private int conservationIncrement = INITIAL_CONSERVATION; public ResidueShader(ColourSchemeI cs) { @@ -54,6 +83,19 @@ public class ResidueShader implements ResidueShaderI } /** + * Constructor given view style settings + * + * @param viewStyle + */ + public ResidueShader(ViewStyleI viewStyle) + { + // TODO remove duplicated storing of conservation / pid thresholds? + this(); + setConservationApplied(viewStyle.isConservationColourSelected()); + // setThreshold(viewStyle.getThreshold()); + } + + /** * @see jalview.renderer.ResidueShaderI#setConsensus(jalview.datamodel.ProfilesI) */ @Override @@ -120,7 +162,7 @@ public class ResidueShader implements ResidueShaderI @Override public void setThreshold(int consensusThreshold, boolean ignoreGaps) { - threshold = consensusThreshold; + pidThreshold = consensusThreshold; this.ignoreGaps = ignoreGaps; } @@ -130,7 +172,7 @@ public class ResidueShader implements ResidueShaderI @Override public void setConservationInc(int i) { - inc = i; + conservationIncrement = i; } /** @@ -139,7 +181,7 @@ public class ResidueShader implements ResidueShaderI @Override public int getConservationInc() { - return inc; + return conservationIncrement; } /** @@ -148,7 +190,7 @@ public class ResidueShader implements ResidueShaderI @Override public int getThreshold() { - return threshold; + return pidThreshold; } /** @@ -224,7 +266,7 @@ public class ResidueShader implements ResidueShaderI */ protected boolean aboveThreshold(char residue, int column) { - if (threshold == 0) + if (pidThreshold == 0) { return true; } @@ -248,7 +290,7 @@ public class ResidueShader implements ResidueShaderI if (profile != null && profile.getModalResidue().contains(String.valueOf(residue))) { - if (profile.getPercentageIdentity(ignoreGaps) >= threshold) + if (profile.getPercentageIdentity(ignoreGaps) >= pidThreshold) { return true; } @@ -308,7 +350,7 @@ public class ResidueShader implements ResidueShaderI * as a result, scores of: 0 1 2 3 4 5 6 7 8 9 * fade to white at slider value: 18 20 22 25 29 33 40 50 67 100% */ - bleachFactor *= (inc / 20f); + bleachFactor *= (conservationIncrement / 20f); return ColorUtils.bleachColour(currentColour, bleachFactor); } diff --git a/src/jalview/schemes/PIDColourScheme.java b/src/jalview/schemes/PIDColourScheme.java index 6ca1393..f213abe 100755 --- a/src/jalview/schemes/PIDColourScheme.java +++ b/src/jalview/schemes/PIDColourScheme.java @@ -31,16 +31,15 @@ import java.util.Map; public class PIDColourScheme extends ResidueColourScheme { - public Color[] pidColours; + private static final Color[] pidColours = { new Color(100, 100, 255), + new Color(153, 153, 255), new Color(204, 204, 255), }; - public float[] thresholds; + private static final float[] thresholds = { 80, 60, 40, }; SequenceGroup group; public PIDColourScheme() { - this.pidColours = ResidueProperties.pidColours; - this.thresholds = ResidueProperties.pidThresholds; } @Override @@ -48,7 +47,7 @@ public class PIDColourScheme extends ResidueColourScheme String consensusResidue, float pid) { /* - * make everything uppercase; note this does nothing (fast) + * make everything uppercase; note this does nothing * if consensusResidue is already uppercase */ consensusResidue = consensusResidue.toUpperCase(); diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index 4d46279..406814a 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -625,13 +625,6 @@ public class ResidueProperties scoreMatrices.put("DNA", new ScoreMatrix("DNA", DNA, 1)); } - public static final Color[] pidColours = { midBlue, - new Color(153, 153, 255), - // Color.lightGray, - new Color(204, 204, 255), }; - - public static final float[] pidThresholds = { 80, 60, 40, }; - public static List STOP = Arrays.asList("TGA", "TAA", "TAG"); public static String START = "ATG"; diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 1352cf2..544835d 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -44,9 +44,7 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.ResidueShader; import jalview.renderer.ResidueShaderI; -import jalview.schemes.Blosum62ColourScheme; import jalview.schemes.ColourSchemeI; -import jalview.schemes.PIDColourScheme; import jalview.structure.CommandListener; import jalview.structure.StructureSelectionManager; import jalview.structure.VamsasSource; @@ -607,35 +605,33 @@ public abstract class AlignmentViewport implements AlignViewportI, // TODO: logic refactored from AlignFrame changeColour - // TODO: autorecalc stuff should be changed to rely on the worker system // check to see if we should implement a changeColour(cs) method rather than - // put th logic in here + // put the logic in here // - means that caller decides if they want to just modify state and defer // calculation till later or to do all calculations in thread. // via changecolour /* - * only instantiate collection colour scheme once, thereafter update it + * only instantiate alignment colouring once, thereafter update it; * this means that any conservation or PID threshold settings * persist when the alignment colour scheme is changed */ if (globalColourScheme == null) { - globalColourScheme = new ResidueShader(); + globalColourScheme = new ResidueShader(viewStyle); } globalColourScheme.setColourScheme(cs); - // boolean recalc = false; - // TODO: do threshold and increment belong in ViewStyle or colour scheme? - // problem: groups need this but do not currently have a ViewStyle + // TODO: do threshold and increment belong in ViewStyle or ResidueShader? + // ...problem: groups need these, but do not currently have a ViewStyle if (cs != null) { - if (getConservationSelected() || getAbovePIDThreshold() - || cs instanceof PIDColourScheme - || cs instanceof Blosum62ColourScheme) + // if (getConservationSelected() || getAbovePIDThreshold() + // || cs instanceof PIDColourScheme + // || cs instanceof Blosum62ColourScheme) + if (getConservationSelected()) { globalColourScheme.setConservation(hconservation); - globalColourScheme - .setConservationApplied(getConservationSelected()); } globalColourScheme.alignmentChanged(alignment, hiddenRepSequences); } @@ -1840,7 +1836,7 @@ public abstract class AlignmentViewport implements AlignViewportI, selectionGroup.setEndRes(alWidth - 1); } - resetAllColourSchemes(); + updateAllColourSchemes(); calculator.restartWorkers(); // alignment.adjustSequenceAnnotations(); } @@ -1848,17 +1844,17 @@ public abstract class AlignmentViewport implements AlignViewportI, /** * reset scope and do calculations for all applied colourschemes on alignment */ - void resetAllColourSchemes() + void updateAllColourSchemes() { - ResidueShaderI cs = globalColourScheme; - if (cs != null) + ResidueShaderI rs = globalColourScheme; + if (rs != null) { - cs.alignmentChanged(alignment, hiddenRepSequences); + rs.alignmentChanged(alignment, hiddenRepSequences); - cs.setConsensus(hconsensus); - if (cs.conservationApplied()) + rs.setConsensus(hconsensus); + if (rs.conservationApplied()) { - cs.setConservation(Conservation.calculateConservation("All", + rs.setConservation(Conservation.calculateConservation("All", alignment.getSequences(), 0, alignment.getWidth(), false, getConsPercGaps(), false)); } diff --git a/test/jalview/gui/AlignFrameTest.java b/test/jalview/gui/AlignFrameTest.java index d71fe63..8ba165e 100644 --- a/test/jalview/gui/AlignFrameTest.java +++ b/test/jalview/gui/AlignFrameTest.java @@ -20,11 +20,14 @@ */ package jalview.gui; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertSame; -import static org.testng.AssertJUnit.assertTrue; +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 jalview.bin.Cache; +import jalview.bin.Jalview; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.Sequence; @@ -33,6 +36,8 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.FileLoader; +import jalview.io.Jalview2xmlTests; +import jalview.renderer.ResidueShaderI; import jalview.schemes.BuriedColourScheme; import jalview.schemes.HelixColourScheme; import jalview.schemes.JalviewColourScheme; @@ -40,8 +45,10 @@ 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; @@ -71,26 +78,26 @@ public class AlignFrameTest seq2.addSequenceFeature(new SequenceFeature("Turn", "", 7, 9, Float.NaN, null)); AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 }); - AlignFrame af = new AlignFrame(al, al.getWidth(), al.getHeight()); + AlignFrame alignFrame = new AlignFrame(al, al.getWidth(), al.getHeight()); /* * hiding a feature not present does nothing */ - assertFalse(af.hideFeatureColumns("exon", true)); - assertTrue(af.getViewport().getColumnSelection().isEmpty()); - assertTrue(af.getViewport().getColumnSelection().getHiddenColumns() + assertFalse(alignFrame.hideFeatureColumns("exon", true)); + assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty()); + assertTrue(alignFrame.getViewport().getColumnSelection().getHiddenColumns() .isEmpty()); - assertFalse(af.hideFeatureColumns("exon", false)); - assertTrue(af.getViewport().getColumnSelection().isEmpty()); - assertTrue(af.getViewport().getColumnSelection().getHiddenColumns() + 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(af.hideFeatureColumns("Metal", true)); - assertTrue(af.getViewport().getColumnSelection().isEmpty()); - List hidden = af.getViewport().getColumnSelection() + assertFalse(alignFrame.hideFeatureColumns("Metal", true)); + assertTrue(alignFrame.getViewport().getColumnSelection().isEmpty()); + List hidden = alignFrame.getViewport().getColumnSelection() .getHiddenColumns(); assertTrue(hidden.isEmpty()); @@ -99,20 +106,59 @@ public class AlignFrameTest * sequence positions [2-4], [7-9] are column positions * [1-3], [6-8] base zero */ - assertTrue(af.hideFeatureColumns("Turn", true)); - hidden = af.getViewport().getColumnSelection().getHiddenColumns(); - assertEquals(2, hidden.size()); - assertEquals(1, hidden.get(0)[0]); - assertEquals(3, hidden.get(0)[1]); - assertEquals(6, hidden.get(1)[0]); - assertEquals(8, hidden.get(1)[1]); + 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); } - @BeforeMethod + @BeforeClass(alwaysRun = true) + public static void setUpBeforeClass() throws Exception + { + /* + * use read-only test properties file + */ + Cache.loadProperties("test/jalview/io/testProps.jvprops"); + Jalview.main(new String[] { "-nonews" }); + } + + @AfterMethod(alwaysRun = true) + public void tearDown() + { + Desktop.instance.closeAll_actionPerformed(null); + } + + /** + * configure (read-only) properties for test to ensure Consensus is computed + * for colour Above PID testing + */ + @BeforeMethod(alwaysRun = true) public void setUp() { + Cache.loadProperties("test/jalview/io/testProps.jvprops"); + Cache.applicationProperties.setProperty("SHOW_IDENTITY", + Boolean.TRUE.toString()); af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa", DataSourceType.FILE); + + /* + * wait for Consensus thread to complete + */ + synchronized (this) + { + while (af.getViewport().getConsensusSeq() == null) + { + try + { + wait(50); + } catch (InterruptedException e) + { + } + } + } } /** @@ -125,7 +171,7 @@ public class AlignFrameTest * Conservation) * */ - @Test + @Test(groups = "Functional") public void testChangeColour_background_groupsAndThresholds() { AlignViewport av = af.getViewport(); @@ -240,4 +286,282 @@ public class AlignFrameTest assertEquals(sg.getGroupColourScheme().getConservationInc(), 30); assertEquals(sg.getGroupColourScheme().getThreshold(), 40); } + + /** + * Test residue colouring with various options + *
    + *
  1. no PID or Conservation threshold
  2. + *
  3. colour by Conservation applied
  4. + *
  5. colour by Conservation removed
  6. + *
  7. colour above PID - various values
  8. + *
  9. colour above PID removed
  10. + *
  11. Above PID plus By Conservation combined
  12. + *
  13. remove Above PID to leave just By Conservation
  14. + *
  15. re-add Above PID
  16. + *
  17. remove By Conservation to leave just Above PID
  18. + *
  19. remove Above PID to leave original colours
  20. + *
+ */ + @Test(groups = "Functional") + public void testColourThresholdActions() + { + AlignViewport av = af.getViewport(); + AlignmentI al = av.getAlignment(); + + /* + * Colour alignment by Helix Propensity, no thresholds + */ + af.applyToAllGroups_actionPerformed(false); + af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString()); + assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme); + assertFalse(av.getViewportColourScheme().conservationApplied()); + assertEquals(av.getViewportColourScheme().getThreshold(), 0); + + /* + * inspect the colour of + * FER_CAPAN.9(I), column 14 (14 base 0) + * FER_CAPAN.10(SER), column 16 (15 base 0) + */ + SequenceI ferCapan = al.findName("FER_CAPAN"); + ResidueShaderI rs = av.getViewportColourScheme(); + Color c = rs.findColour('I', 14, ferCapan); + Color i_original = new Color(138, 117, 138); + assertEquals(c, i_original); + c = rs.findColour('S', 15, ferCapan); + Color s_original = new Color(54, 201, 54); + assertEquals(c, s_original); + + /* + * colour by conservation with increment 10 + */ + af.conservationMenuItem_actionPerformed(true); + SliderPanel sp = SliderPanel.getSliderPanel(); + assertTrue(sp.isForConservation()); + assertEquals(sp.getValue(), 30); // initial slider setting + sp.valueChanged(10); + assertSame(rs, av.getViewportColourScheme()); + c = rs.findColour('I', 14, ferCapan); + Color 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); + assertEquals(c, s_faded); + + /* + * deselect By Conservation - colour should revert + */ + af.conservationMenuItem_actionPerformed(false); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_original); + + /* + * now Above PID, threshold = 0% + * should be no change + */ + af.abovePIDThreshold_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertFalse(sp.isForConservation()); + assertEquals(sp.getValue(), 0); // initial slider setting + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, i_original); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_original); + + /* + * Above PID, threshold = 1% + * 15.I becomes White because no match to consensus (V) + * 16.S remains coloured as matches 66.66% consensus + */ + sp.valueChanged(1); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, Color.white); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_original); + + /* + * threshold 66% - no further change yet... + */ + sp.valueChanged(66); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, Color.white); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_original); + + /* + * threshold 67% - now both residues are white + */ + sp.valueChanged(67); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, Color.white); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, Color.white); + + /* + * deselect Above PID - colours should revert + */ + af.abovePIDThreshold_actionPerformed(false); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, i_original); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_original); + + /* + * Now combine Above 50% PID and By Conservation 10% + * 15.I is White because no match to consensus (V) + * 16.S is coloured but faded + */ + af.abovePIDThreshold_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertFalse(sp.isForConservation()); + sp.valueChanged(50); + af.conservationMenuItem_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertTrue(sp.isForConservation()); + sp.valueChanged(10); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, Color.white); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_faded); + + /* + * turn off Above PID - should just leave Conservation fading as before + */ + af.abovePIDThreshold_actionPerformed(false); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, i_faded); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_faded); + + /* + * Now add Above 50% PID to conservation colouring + * - should give the same as PID followed by conservation (above) + */ + af.abovePIDThreshold_actionPerformed(true); + SliderPanel.getSliderPanel().valueChanged(50); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, Color.white); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_faded); + + /* + * turn off By Conservation + * should leave I white, S original (unfaded) colour + */ + af.conservationMenuItem_actionPerformed(false); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, Color.white); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_original); + + /* + * finally turn off Above PID to leave original colours + */ + af.abovePIDThreshold_actionPerformed(false); + c = rs.findColour('I', 14, ferCapan); + assertEquals(c, i_original); + c = rs.findColour('S', 15, ferCapan); + assertEquals(c, s_original); + } + + /** + * Verify that making a New View transfers alignment and group colour schemes, + * including any thresholds, to the new view. Because New View is performed by + * saving and reloading a 'project' file, this is similar to verifying a + * project save and reload. + * + * @see Jalview2xmlTests#testStoreAndRecoverColourThresholds() + */ + @Test(groups = "Functional") + public void testNewView_colourThresholds() + { + AlignViewport av = af.getViewport(); + AlignmentI al = av.getAlignment(); + + /* + * Colour alignment by Buried Index, Above 10% PID, By Conservation 20% + */ + af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString()); + assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme); + af.abovePIDThreshold_actionPerformed(true); + SliderPanel sp = SliderPanel.getSliderPanel(); + assertFalse(sp.isForConservation()); + sp.valueChanged(10); + af.conservationMenuItem_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertTrue(sp.isForConservation()); + sp.valueChanged(20); + ResidueShaderI rs = av.getViewportColourScheme(); + assertEquals(rs.getThreshold(), 10); + assertTrue(rs.conservationApplied()); + assertEquals(rs.getConservationInc(), 20); + + /* + * create a group with Strand colouring, 30% Conservation + * and 40% PID threshold + */ + SequenceGroup sg = new SequenceGroup(); + sg.addSequence(al.getSequenceAt(0), false); + sg.setStartRes(15); + sg.setEndRes(25); + av.setSelectionGroup(sg); + PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null); + popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand + .toString()); + assertTrue(sg.getColourScheme() instanceof StrandColourScheme); + assertEquals(al.getGroups().size(), 1); + assertSame(al.getGroups().get(0), sg); + popupMenu.conservationMenuItem_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertTrue(sp.isForConservation()); + sp.valueChanged(30); + popupMenu.abovePIDColour_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertFalse(sp.isForConservation()); + sp.valueChanged(40); + rs = sg.getGroupColourScheme(); + assertTrue(rs.conservationApplied()); + assertEquals(rs.getConservationInc(), 30); + assertEquals(rs.getThreshold(), 40); + + /* + * set slider panel focus to the background alignment + */ + af.conservationMenuItem_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertTrue(sp.isForConservation()); + assertEquals(sp.getTitle(), MessageManager.formatMessage( + "label.conservation_colour_increment", + new String[] { "Background" })); + + /* + * make a new View, verify alignment and group colour schemes + */ + af.newView_actionPerformed(null); + assertEquals(af.alignPanel.getViewName(), "View 1"); + AlignViewport av2 = af.getViewport(); + assertNotSame(av, av2); + rs = av2.getViewportColourScheme(); + assertNotSame(av.getViewportColourScheme(), rs); + assertEquals(rs.getThreshold(), 10); + assertTrue(rs.conservationApplied()); + assertEquals(rs.getConservationInc(), 20); + assertEquals(av2.getAlignment().getGroups().size(), 1); + sg = av2.getAlignment().getGroups().get(0); + rs = sg.getGroupColourScheme(); + assertTrue(rs.conservationApplied()); + assertEquals(rs.getConservationInc(), 30); + assertEquals(rs.getThreshold(), 40); + + /* + * check the Conservation SliderPanel (still open) is linked to + * and updates the new view (JAL-2385) + */ + sp = SliderPanel.getSliderPanel(); + assertTrue(sp.isForConservation()); + assertEquals(sp.getTitle(), MessageManager.formatMessage( + "label.conservation_colour_increment", + new String[] { "View 1" })); + sp.valueChanged(22); + assertEquals(av2.getViewportColourScheme().getConservationInc(), 22); + } } diff --git a/test/jalview/gui/AlignViewportTest.java b/test/jalview/gui/AlignViewportTest.java index fa71b2e..71a5f3c 100644 --- a/test/jalview/gui/AlignViewportTest.java +++ b/test/jalview/gui/AlignViewportTest.java @@ -70,7 +70,8 @@ public class AlignViewportTest @BeforeClass(alwaysRun = true) public static void setUpBeforeClass() throws Exception { - Jalview.main(new String[] { "-props", "test/jalview/testProps.jvprops" }); + Jalview.main(new String[] { "-nonews", "-props", + "test/jalview/testProps.jvprops" }); } @BeforeMethod(alwaysRun = true) diff --git a/test/jalview/io/FileFormatsTest.java b/test/jalview/io/FileFormatsTest.java index ffc844c..7810504 100644 --- a/test/jalview/io/FileFormatsTest.java +++ b/test/jalview/io/FileFormatsTest.java @@ -10,16 +10,23 @@ import static org.testng.Assert.assertTrue; import java.util.Iterator; import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class FileFormatsTest { - @AfterMethod() + @AfterMethod(alwaysRun = true) public void tearDown() { FileFormats.getInstance().reset(); } + @BeforeMethod(alwaysRun = true) + public void setUp() + { + FileFormats.getInstance().reset(); + } + @Test(groups = "Functional") public void testIsIdentifiable() { diff --git a/test/jalview/io/Jalview2xmlTests.java b/test/jalview/io/Jalview2xmlTests.java index 5b99fa1..af52c55 100644 --- a/test/jalview/io/Jalview2xmlTests.java +++ b/test/jalview/io/Jalview2xmlTests.java @@ -20,11 +20,11 @@ */ package jalview.io; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertSame; -import static org.testng.AssertJUnit.assertTrue; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; @@ -38,20 +38,27 @@ import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; +import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.gui.Jalview2XML; import jalview.gui.JvOptionPane; +import jalview.gui.PopupMenu; +import jalview.gui.SliderPanel; +import jalview.renderer.ResidueShaderI; import jalview.schemes.AnnotationColourGradient; +import jalview.schemes.BuriedColourScheme; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; import jalview.schemes.JalviewColourScheme; import jalview.schemes.RNAHelicesColour; +import jalview.schemes.StrandColourScheme; import jalview.schemes.TCoffeeColourScheme; import jalview.structure.StructureImportSettings; import jalview.viewmodel.AlignmentViewport; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -80,32 +87,34 @@ public class Jalview2xmlTests extends Jalview2xmlBase String inFile = "examples/RF00031_folded.stk"; String tfile = File.createTempFile("JalviewTest", ".jvp") .getAbsolutePath(); - AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( - inFile, DataSourceType.FILE); - assertTrue("Didn't read input file " + inFile, af != null); + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, + DataSourceType.FILE); + assertNotNull(af, "Didn't read input file " + inFile); int olddsann = countDsAnn(af.getViewport()); - assertTrue("Didn't find any dataset annotations", olddsann > 0); + assertTrue(olddsann > 0, "Didn't find any dataset annotations"); af.changeColour_actionPerformed(JalviewColourScheme.RNAHelices .toString()); - assertTrue("Couldn't apply RNA helices colourscheme", af.getViewport() - .getGlobalColourScheme() instanceof RNAHelicesColour); - assertTrue("Failed to store as a project.", - af.saveAlignment(tfile, FileFormat.Jalview)); + assertTrue( + af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour, + "Couldn't apply RNA helices colourscheme"); + assertTrue(af.saveAlignment(tfile, FileFormat.Jalview), + "Failed to store as a project."); af.closeMenuItem_actionPerformed(true); af = null; - af = new FileLoader().LoadFileWaitTillLoaded(tfile, DataSourceType.FILE); - assertTrue("Failed to import new project", af != null); + af = new FileLoader() + .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE); + assertNotNull(af, "Failed to import new project"); int newdsann = countDsAnn(af.getViewport()); - assertTrue( + assertEquals(olddsann, newdsann, "Differing numbers of dataset sequence annotation\nOriginally " - + olddsann + " and now " + newdsann, - olddsann == newdsann); + + olddsann + " and now " + newdsann); System.out .println("Read in same number of annotations as originally present (" + olddsann + ")"); assertTrue( - "RNA helices colourscheme was not applied on import.", - af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour); + + af.getViewport().getGlobalColourScheme() instanceof RNAHelicesColour, + "RNA helices colourscheme was not applied on import."); } @Test(groups = { "Functional" }) @@ -114,27 +123,26 @@ public class Jalview2xmlTests extends Jalview2xmlBase String inFile = "examples/uniref50.fa", inAnnot = "examples/uniref50.score_ascii"; String tfile = File.createTempFile("JalviewTest", ".jvp") .getAbsolutePath(); - AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( - inFile, DataSourceType.FILE); - assertNotNull("Didn't read input file " + inFile, af); + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, + DataSourceType.FILE); + assertNotNull(af, "Didn't read input file " + inFile); af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null); - assertSame("Didn't set T-coffee colourscheme", af.getViewport() - .getGlobalColourScheme().getClass(), TCoffeeColourScheme.class); - assertNotNull("Recognise T-Coffee score from string", - ColourSchemeProperty.getColourScheme(af.getViewport() - .getAlignment(), af.getViewport() - .getGlobalColourScheme().getSchemeName())); - - assertTrue("Failed to store as a project.", - af.saveAlignment(tfile, FileFormat.Jalview)); + assertSame(af.getViewport().getGlobalColourScheme().getClass(), + TCoffeeColourScheme.class, "Didn't set T-coffee colourscheme"); + assertNotNull(ColourSchemeProperty.getColourScheme(af.getViewport() + .getAlignment(), af.getViewport().getGlobalColourScheme() + .getSchemeName()), "Recognise T-Coffee score from string"); + + assertTrue(af.saveAlignment(tfile, FileFormat.Jalview), + "Failed to store as a project."); af.closeMenuItem_actionPerformed(true); af = null; - af = new FileLoader().LoadFileWaitTillLoaded(tfile, - DataSourceType.FILE); - assertNotNull("Failed to import new project", af); - assertSame("Didn't set T-coffee colourscheme for imported project.", af - .getViewport().getGlobalColourScheme().getClass(), - TCoffeeColourScheme.class); + af = new FileLoader() + .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE); + assertNotNull(af, "Failed to import new project"); + assertSame(af.getViewport().getGlobalColourScheme().getClass(), + TCoffeeColourScheme.class, + "Didn't set T-coffee colourscheme for imported project."); System.out .println("T-Coffee score shading successfully recovered from project."); } @@ -145,14 +153,16 @@ public class Jalview2xmlTests extends Jalview2xmlBase String inFile = "examples/uniref50.fa", inAnnot = "examples/testdata/uniref50_iupred.jva"; String tfile = File.createTempFile("JalviewTest", ".jvp") .getAbsolutePath(); - AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, DataSourceType.FILE); - assertNotNull("Didn't read input file " + inFile, af); + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, + DataSourceType.FILE); + assertNotNull(af, "Didn't read input file " + inFile); af.loadJalviewDataFile(inAnnot, DataSourceType.FILE, null, null); AlignmentAnnotation[] aa = af.getViewport().getAlignment() .getSequenceAt(0).getAnnotation("IUPredWS (Short)"); assertTrue( - "Didn't find any IUPred annotation to use to shade alignment.", - aa != null && aa.length > 0); + + aa != null && aa.length > 0, + "Didn't find any IUPred annotation to use to shade alignment."); AnnotationColourGradient cs = new AnnotationColourGradient(aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD); AnnotationColourGradient gcs = new AnnotationColourGradient(aa[0], @@ -168,24 +178,25 @@ public class Jalview2xmlTests extends Jalview2xmlBase sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false); sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true); af.alignPanel.alignmentChanged(); - assertTrue("Failed to store as a project.", - af.saveAlignment(tfile, FileFormat.Jalview)); + assertTrue(af.saveAlignment(tfile, FileFormat.Jalview), + "Failed to store as a project."); af.closeMenuItem_actionPerformed(true); af = null; - af = new FileLoader().LoadFileWaitTillLoaded(tfile, DataSourceType.FILE); - assertTrue("Failed to import new project", af != null); + af = new FileLoader() + .LoadFileWaitTillLoaded(tfile, DataSourceType.FILE); + assertNotNull(af, "Failed to import new project"); // check for group and alignment colourschemes ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme(); ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups() .get(0).getColourScheme(); - assertNotNull("Didn't recover global colourscheme", _rcs); - assertTrue("Didn't recover annotation colour global scheme", - _rcs instanceof AnnotationColourGradient); + assertNotNull(_rcs, "Didn't recover global colourscheme"); + assertTrue(_rcs instanceof AnnotationColourGradient, + "Didn't recover annotation colour global scheme"); AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs; - assertTrue("Annotation colourscheme wasn't sequence associated", - __rcs.isSeqAssociated()); + assertTrue(__rcs.isSeqAssociated(), + "Annotation colourscheme wasn't sequence associated"); boolean diffseqcols = false, diffgseqcols = false; SequenceI[] sqs = af.getViewport().getAlignment().getSequencesArray(); @@ -198,16 +209,16 @@ public class Jalview2xmlTests extends Jalview2xmlBase diffseqcols = true; } } - assertTrue("Got Different sequence colours", diffseqcols); + assertTrue(diffseqcols, "Got Different sequence colours"); System.out .println("Per sequence colourscheme (Background) successfully applied and recovered."); - assertNotNull("Didn't recover group colourscheme", _rgcs); - assertTrue("Didn't recover annotation colour group colourscheme", - _rgcs instanceof AnnotationColourGradient); + assertNotNull(_rgcs, "Didn't recover group colourscheme"); + assertTrue(_rgcs instanceof AnnotationColourGradient, + "Didn't recover annotation colour group colourscheme"); __rcs = (AnnotationColourGradient) _rgcs; - assertTrue("Group Annotation colourscheme wasn't sequence associated", - __rcs.isSeqAssociated()); + assertTrue(__rcs.isSeqAssociated(), + "Group Annotation colourscheme wasn't sequence associated"); for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize && (!diffseqcols || !diffgseqcols); p++) @@ -218,7 +229,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase diffgseqcols = true; } } - assertTrue("Got Different group sequence colours", diffgseqcols); + assertTrue(diffgseqcols, "Got Different group sequence colours"); System.out .println("Per sequence (Group) colourscheme successfully applied and recovered."); } @@ -230,9 +241,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase .getAlignFrames().length; AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); - assertNotNull("Didn't read in the example file correctly.", af); - assertTrue("Didn't gather the views in the example file.", - Desktop.getAlignFrames().length == 1 + origCount); + assertNotNull(af, "Didn't read in the example file correctly."); + assertTrue(Desktop.getAlignFrames().length == 1 + origCount, + "Didn't gather the views in the example file."); } @@ -243,7 +254,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase StructureImportSettings.setVisibleChainAnnotation(true); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); - assertNotNull("Didn't read in the example file correctly.", af); + assertNotNull(af, "Didn't read in the example file correctly."); AlignmentViewPanel sps = null; for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels()) { @@ -253,7 +264,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase break; } } - assertNotNull("Couldn't find the structure view", sps); + assertNotNull(sps, "Couldn't find the structure view"); AlignmentAnnotation refan = null; for (AlignmentAnnotation ra : sps.getAlignment() .getAlignmentAnnotation()) @@ -264,13 +275,13 @@ public class Jalview2xmlTests extends Jalview2xmlBase break; } } - assertNotNull("Annotation secondary structure not found.", refan); + assertNotNull(refan, "Annotation secondary structure not found."); SequenceI sq = sps.getAlignment().findName("1A70|"); - assertNotNull("Couldn't find 1a70 null chain", sq); + assertNotNull(sq, "Couldn't find 1a70 null chain"); // compare the manually added temperature factor annotation // to the track automatically transferred from the pdb structure on load - assertNotNull("1a70 has no annotation", sq.getDatasetSequence() - .getAnnotation()); + assertNotNull(sq.getDatasetSequence().getAnnotation(), + "1a70 has no annotation"); for (AlignmentAnnotation ala : sq.getDatasetSequence().getAnnotation()) { AlignmentAnnotation alaa; @@ -284,9 +295,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase try { assertTrue( - "Mismatch at alignment position " + p, (alaa.annotations[p] == null && refan.annotations[p] == null) - || alaa.annotations[p].value == refan.annotations[p].value); + || alaa.annotations[p].value == refan.annotations[p].value, + "Mismatch at alignment position " + p); } catch (NullPointerException q) { Assert.fail("Mismatch of alignment annotations at position " @@ -304,7 +315,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); - assertNotNull("Didn't read in the example file correctly.", af); + assertNotNull(af, "Didn't read in the example file correctly."); AlignmentViewPanel sps = null, groups = null; for (AlignmentViewPanel ap : af.alignPanel.alignFrame.getAlignPanels()) { @@ -317,8 +328,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase groups = ap; } } - assertNotNull("Couldn't find the structure view", sps); - assertNotNull("Couldn't find the MAFFT view", groups); + assertNotNull(sps, "Couldn't find the structure view"); + assertNotNull(groups, "Couldn't find the MAFFT view"); ViewStyleI structureStyle = sps.getAlignViewport().getViewStyle(); ViewStyleI groupStyle = groups.getAlignViewport().getViewStyle(); @@ -349,9 +360,10 @@ public class Jalview2xmlTests extends Jalview2xmlBase // check FileLoader returned a reference to the one alignFrame that is // actually on the Desktop - assertTrue( - "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window", - af == Desktop.getAlignFrameFor(af.getViewport())); + assertSame( + af, + Desktop.getAlignFrameFor(af.getViewport()), + "Jalview2XML.loadAlignFrame() didn't return correct AlignFrame reference for multiple view window"); Desktop.explodeViews(af); @@ -374,8 +386,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.assertEquals(Desktop.getAlignFrames().length, 0); } - af = new FileLoader().LoadFileWaitTillLoaded( - tfile.getAbsolutePath(), DataSourceType.FILE); + af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), + DataSourceType.FILE); Assert.assertNotNull(af); Assert.assertEquals( Desktop.getAlignFrames().length, @@ -397,7 +409,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase Desktop.instance.closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); - assertNotNull("Didn't read in the example file correctly.", af); + assertNotNull(af, "Didn't read in the example file correctly."); String afid = af.getViewport().getSequenceSetId(); // remember reference sequence for each panel @@ -439,8 +451,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase Assert.assertEquals(Desktop.getAlignFrames().length, 0); } - af = new FileLoader().LoadFileWaitTillLoaded( - tfile.getAbsolutePath(), DataSourceType.FILE); + af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), + DataSourceType.FILE); afid = af.getViewport().getSequenceSetId(); for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid)) @@ -530,7 +542,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase Desktop.instance.closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); - assertNotNull("Didn't read in the example file correctly.", af); + assertNotNull(af, "Didn't read in the example file correctly."); String afid = af.getViewport().getSequenceSetId(); // make a second view of the alignment af.newView_actionPerformed(null); @@ -581,7 +593,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase assertSame(repSeq, sg.getSeqrep()); assertTrue(sg.getSequences().contains(repSeq)); assertTrue(sg.getSequences().contains(precedingSeq)); - assertTrue("alignment has groups", alignment.getGroups().isEmpty()); + assertTrue(alignment.getGroups().isEmpty(), "alignment has groups"); Map hiddenRepSeqsMap = av .getHiddenRepSequences(); assertNotNull(hiddenRepSeqsMap); @@ -607,9 +619,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.assertEquals(Desktop.getAlignFrames().length, 0); } - - af = new FileLoader().LoadFileWaitTillLoaded( - tfile.getAbsolutePath(), DataSourceType.FILE); + + af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), + DataSourceType.FILE); afid = af.getViewport().getSequenceSetId(); for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid)) @@ -619,10 +631,10 @@ public class Jalview2xmlTests extends Jalview2xmlBase AlignmentI alignment = ap.getAlignment(); List groups = alignment.getGroups(); assertNotNull(groups); - assertTrue("Alignment has groups", groups.isEmpty()); + assertTrue(groups.isEmpty(), "Alignment has groups"); Map hiddenRepSeqsMap = av .getHiddenRepSequences(); - assertNotNull("No hidden represented sequences", hiddenRepSeqsMap); + assertNotNull(hiddenRepSeqsMap, "No hidden represented sequences"); assertEquals(1, hiddenRepSeqsMap.size()); assertEquals(repSeqs.get(viewName).getDisplayId(true), hiddenRepSeqsMap.keySet().iterator().next() @@ -634,8 +646,10 @@ public class Jalview2xmlTests extends Jalview2xmlBase List hidden = hiddenSeqNames.get(ap.getViewName()); HiddenSequences hs = alignment.getHiddenSequences(); assertEquals( + hidden.size(), + hs.getSize(), "wrong number of restored hidden sequences in " - + ap.getViewName(), hidden.size(), hs.getSize()); + + ap.getViewName()); } } @@ -651,7 +665,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase String exampleFile = "examples/3W5V.pdb"; AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile, DataSourceType.FILE); - assertNotNull("Didn't read in the example file correctly.", af); + assertNotNull(af, "Didn't read in the example file correctly."); String afid = af.getViewport().getSequenceSetId(); AlignmentPanel[] alignPanels = Desktop.getAlignmentPanels(afid); @@ -732,4 +746,99 @@ public class Jalview2xmlTests extends Jalview2xmlBase "Recovered PDBEntry should have a non-null file entry"); } } + + /** + * Configure an alignment and a sub-group each with distinct colour schemes, + * Conservation and PID thresholds, and confirm these are restored from the + * saved project. + * + * @throws IOException + */ + @Test(groups = { "Functional" }) + public void testStoreAndRecoverColourThresholds() throws IOException + { + Desktop.instance.closeAll_actionPerformed(null); + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + "examples/uniref50.fa", DataSourceType.FILE); + + AlignViewport av = af.getViewport(); + AlignmentI al = av.getAlignment(); + + /* + * Colour alignment by Buried Index, Above 10% PID, By Conservation 20% + */ + af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString()); + assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme); + af.abovePIDThreshold_actionPerformed(true); + SliderPanel sp = SliderPanel.getSliderPanel(); + assertFalse(sp.isForConservation()); + sp.valueChanged(10); + af.conservationMenuItem_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertTrue(sp.isForConservation()); + sp.valueChanged(20); + ResidueShaderI rs = av.getViewportColourScheme(); + assertEquals(rs.getThreshold(), 10); + assertTrue(rs.conservationApplied()); + assertEquals(rs.getConservationInc(), 20); + + /* + * create a group with Strand colouring, 30% Conservation + * and 40% PID threshold + */ + SequenceGroup sg = new SequenceGroup(); + sg.addSequence(al.getSequenceAt(0), false); + sg.setStartRes(15); + sg.setEndRes(25); + av.setSelectionGroup(sg); + PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null); + popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand + .toString()); + assertTrue(sg.getColourScheme() instanceof StrandColourScheme); + assertEquals(al.getGroups().size(), 1); + assertSame(al.getGroups().get(0), sg); + popupMenu.conservationMenuItem_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertTrue(sp.isForConservation()); + sp.valueChanged(30); + popupMenu.abovePIDColour_actionPerformed(true); + sp = SliderPanel.getSliderPanel(); + assertFalse(sp.isForConservation()); + sp.valueChanged(40); + assertTrue(sg.getGroupColourScheme().conservationApplied()); + assertEquals(sg.getGroupColourScheme().getConservationInc(), 30); + assertEquals(sg.getGroupColourScheme().getThreshold(), 40); + + /* + * save project, close windows, reload project, verify + */ + File tfile = File.createTempFile("testStoreAndRecoverColourThresholds", + ".jvp"); + tfile.deleteOnExit(); + new Jalview2XML(false).saveState(tfile); + Desktop.instance.closeAll_actionPerformed(null); + af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), + DataSourceType.FILE); + Assert.assertNotNull(af, "Failed to reload project"); + + /* + * verify alignment (background) colouring + */ + rs = af.getViewport().getViewportColourScheme(); + assertTrue(rs.getColourScheme() instanceof BuriedColourScheme); + assertEquals(rs.getThreshold(), 10); + assertTrue(rs.conservationApplied()); + assertEquals(rs.getConservationInc(), 20); + + /* + * verify group colouring + */ + assertEquals(1, af.getViewport().getAlignment().getGroups().size(), 1); + rs = af.getViewport().getAlignment().getGroups().get(0) + .getGroupColourScheme(); + assertTrue(rs.getColourScheme() instanceof StrandColourScheme); + assertEquals(rs.getThreshold(), 40); + assertTrue(rs.conservationApplied()); + assertEquals(rs.getConservationInc(), 30); + } } diff --git a/test/jalview/io/JalviewFileViewTest.java b/test/jalview/io/JalviewFileViewTest.java index d867e5e..aa124d9 100644 --- a/test/jalview/io/JalviewFileViewTest.java +++ b/test/jalview/io/JalviewFileViewTest.java @@ -14,7 +14,7 @@ import org.testng.annotations.Test; public class JalviewFileViewTest { - @Test + @Test(groups = "Functional") public void testGetImageIcon() { JalviewFileView jfv = new JalviewFileView(); @@ -36,7 +36,7 @@ public class JalviewFileViewTest assertNull(jfv.getImageIcon("images/file.png")); } - @Test + @Test(groups = "Functional") public void testGetExtension() { assertEquals(JalviewFileView.getExtension(new File("text.txt")), "txt"); @@ -48,7 +48,7 @@ public class JalviewFileViewTest "/a/longer/file/path/text"))); } - @Test + @Test(groups = "Functional") public void testGetTypeDescription() { JalviewFileView jfw = new JalviewFileView(); diff --git a/test/jalview/renderer/ScaleRendererTest.java b/test/jalview/renderer/ScaleRendererTest.java index 5588ad1..cf1039f 100644 --- a/test/jalview/renderer/ScaleRendererTest.java +++ b/test/jalview/renderer/ScaleRendererTest.java @@ -17,7 +17,7 @@ import org.testng.annotations.Test; public class ScaleRendererTest { - @Test + @Test(groups = "Functional") public void testCalculateMarks() { String data = ">Seq/20-45\nABCDEFGHIJKLMNOPQRSTUVWXYS\n"; diff --git a/test/jalview/schemes/PIDColourSchemeTest.java b/test/jalview/schemes/PIDColourSchemeTest.java index 6f60e50..8bab428 100644 --- a/test/jalview/schemes/PIDColourSchemeTest.java +++ b/test/jalview/schemes/PIDColourSchemeTest.java @@ -35,7 +35,7 @@ public class PIDColourSchemeTest *
  • case insensitive matching
  • *
      */ - @Test + @Test(groups = "Functional") public void testFindColour() { ColourSchemeI scheme = new PIDColourScheme(); @@ -65,7 +65,7 @@ public class PIDColourSchemeTest * option on the annotation label popup menu) results in a change to the * colouring */ - @Test + @Test(groups = "Functional") public void testFindColour_ignoreGaps() { /* -- 1.7.10.2