From: gmungoc Date: Wed, 2 Nov 2016 12:09:49 +0000 (+0000) Subject: JAL-98 JAL-1854 encapsulate 'magic number' threshold 3 in Conservation X-Git-Tag: Release_2_11_0~62^2~77 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0eb7bbd7c1c29eae73f872693ae033003be1031c;p=jalview.git JAL-98 JAL-1854 encapsulate 'magic number' threshold 3 in Conservation --- diff --git a/src/jalview/analysis/Conservation.java b/src/jalview/analysis/Conservation.java index 7e72dcd..7b9da46 100755 --- a/src/jalview/analysis/Conservation.java +++ b/src/jalview/analysis/Conservation.java @@ -23,9 +23,9 @@ package jalview.analysis; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ResidueCount; +import jalview.datamodel.ResidueCount.SymbolCounts; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; -import jalview.datamodel.ResidueCount.SymbolCounts; import jalview.schemes.ResidueProperties; import jalview.util.Comparison; @@ -38,12 +38,15 @@ import java.util.Vector; /** * Calculates conservation values for a given set of sequences - * - * @author $author$ - * @version $Revision$ */ public class Conservation { + /* + * need to have a minimum of 3% of sequences with a residue + * for it to be included in the conservation calculation + */ + private static final int THRESHOLD_PERCENT = 3; + private static final int TOUPPERCASE = 'a' - 'A'; SequenceI[] sequences; @@ -92,12 +95,10 @@ public class Conservation private String[] consSymbs; /** - * Creates a new Conservation object. + * Constructor using default threshold of 3% * * @param name * Name of conservation - * @param threshold - * to count the residues in residueHash(). commonly used value is 3 * @param sequences * sequences to be used in calculation * @param start @@ -105,6 +106,27 @@ public class Conservation * @param end * end residue position */ + public Conservation(String name, List sequences, int start, + int end) + { + this(name, THRESHOLD_PERCENT, sequences, start, end); + } + + /** + * Constructor + * + * @param name + * Name of conservation + * @param threshold + * percentage of sequences at or below which property conservation is + * ignored + * @param sequences + * sequences to be used in calculation + * @param start + * start column position + * @param end + * end column position + */ public Conservation(String name, int threshold, List sequences, int start, int end) { @@ -210,7 +232,9 @@ public class Conservation { ResidueCount values = countResidues(column); - // TODO is threshold a percentage or count value? + /* + * percentage count at or below which we ignore residues + */ int thresh = (threshold * height) / 100; /* @@ -781,9 +805,6 @@ public class Conservation * * @param name * - name of conservation - * @param threshold - * - minimum number of conserved residues needed to indicate - * conservation (typically 3) * @param seqs * @param start * first column in calculation window @@ -799,10 +820,10 @@ public class Conservation * @return Conservation object ready for use in visualization */ public static Conservation calculateConservation(String name, - int threshold, List seqs, int start, int end, - boolean positiveOnly, int maxPercentGaps, boolean calcQuality) + List seqs, int start, int end, boolean positiveOnly, + int maxPercentGaps, boolean calcQuality) { - Conservation cons = new Conservation(name, threshold, seqs, start, end); + Conservation cons = new Conservation(name, seqs, start, end); cons.calculate(); cons.verdict(positiveOnly, maxPercentGaps); diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index c30fdad..7b0d4fb 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -1206,11 +1206,10 @@ public class APopupMenu extends java.awt.PopupMenu implements if (conservationMenuItem.getState()) { - - sg.cs.setConservation(Conservation.calculateConservation("Group", 3, - sg.getSequences(ap.av.getHiddenRepSequences()), 0, ap.av - .getAlignment().getWidth(), false, ap.av - .getConsPercGaps(), false)); + sg.cs.setConservation(Conservation.calculateConservation("Group", sg + .getSequences(ap.av.getHiddenRepSequences()), 0, ap.av + .getAlignment().getWidth(), false, ap.av.getConsPercGaps(), + false)); SliderPanel.setConservationSlider(ap, sg.cs, sg.getName()); SliderPanel.showConservationSlider(); } diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 3b509e5..8292a5a 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -676,8 +676,8 @@ public class TreeCanvas extends Panel implements MouseListener, if (av.getGlobalColourScheme() != null && av.getGlobalColourScheme().conservationApplied()) { - Conservation c = new Conservation("Group", 3, - sg.getSequences(null), sg.getStartRes(), sg.getEndRes()); + Conservation c = new Conservation("Group", sg.getSequences(null), + sg.getStartRes(), sg.getEndRes()); c.calculate(); c.verdict(false, av.getConsPercGaps()); diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 2870a2c..ca90003 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -543,8 +543,8 @@ public class SequenceGroup implements AnnotatedCollectionI if ((conservation != null) || (cs != null && cs.conservationApplied())) { - Conservation c = new Conservation(groupName, 3, sequences, - startRes, endRes + 1); + Conservation c = new Conservation(groupName, sequences, startRes, + endRes + 1); c.calculate(); c.verdict(false, consPercGaps); if (conservation != null) diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 1c90889..bc5e1d8 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -3401,8 +3401,8 @@ public class Jalview2XML } if (jGroup.getConsThreshold() != 0) { - Conservation c = new Conservation("All", 3, - sg.getSequences(null), 0, sg.getWidth() - 1); + Conservation c = new Conservation("All", sg.getSequences(null), + 0, sg.getWidth() - 1); c.calculate(); c.verdict(false, 25); sg.cs.setConservation(c); diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index f8a296f..3b39be7 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -359,8 +359,8 @@ public class Jalview2XML_V1 if (groups[i].getConsThreshold() != 0) { - Conservation c = new Conservation("All", 3, - sg.getSequences(null), 0, sg.getWidth() - 1); + Conservation c = new Conservation("All", sg.getSequences(null), + 0, sg.getWidth() - 1); c.calculate(); c.verdict(false, 25); sg.cs.setConservation(c); diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index e2d397f..7b70ff0 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -2048,7 +2048,7 @@ public class PopupMenu extends JPopupMenu if (conservationMenuItem.isSelected()) { // JBPNote: Conservation name shouldn't be i18n translated - Conservation c = new Conservation("Group", 3, sg.getSequences(ap.av + Conservation c = new Conservation("Group", sg.getSequences(ap.av .getHiddenRepSequences()), sg.getStartRes(), sg.getEndRes() + 1); diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 0e513f7..84fd82f 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -1017,8 +1017,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (aps[a].av.getGlobalColourScheme() != null && aps[a].av.getGlobalColourScheme().conservationApplied()) { - Conservation c = new Conservation("Group", 3, - sg.getSequences(null), sg.getStartRes(), sg.getEndRes()); + Conservation c = new Conservation("Group", sg.getSequences(null), + sg.getStartRes(), sg.getEndRes()); c.calculate(); c.verdict(false, aps[a].av.getConsPercGaps()); sg.cs.setConservation(c); diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 34fdabe..61a30f8 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -1637,9 +1637,8 @@ public class AnnotationFile else if (key.equalsIgnoreCase("consThreshold")) { sg.cs.setConservationInc(Integer.parseInt(value)); - Conservation c = new Conservation("Group", 3, - sg.getSequences(null), sg.getStartRes(), - sg.getEndRes() + 1); + Conservation c = new Conservation("Group", sg.getSequences(null), + sg.getStartRes(), sg.getEndRes() + 1); c.calculate(); c.verdict(false, 25); // TODO: refer to conservation percent threshold diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 254a201..57258ef 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -1867,7 +1867,7 @@ public abstract class AlignmentViewport implements AlignViewportI, cs.setConsensus(hconsensus); if (cs.conservationApplied()) { - cs.setConservation(Conservation.calculateConservation("All", 3, + cs.setConservation(Conservation.calculateConservation("All", alignment.getSequences(), 0, alignment.getWidth(), false, getConsPercGaps(), false)); } diff --git a/src/jalview/workers/ConservationThread.java b/src/jalview/workers/ConservationThread.java index 11ec521..e71c4f5 100644 --- a/src/jalview/workers/ConservationThread.java +++ b/src/jalview/workers/ConservationThread.java @@ -94,7 +94,7 @@ public class ConservationThread extends AlignCalcWorker } try { - cons = Conservation.calculateConservation("All", 3, + cons = Conservation.calculateConservation("All", alignment.getSequences(), 0, alWidth - 1, false, ConsPercGaps, quality != null); } catch (IndexOutOfBoundsException x) diff --git a/test/jalview/analysis/ConservationTest.java b/test/jalview/analysis/ConservationTest.java index c419687..123fcd6 100644 --- a/test/jalview/analysis/ConservationTest.java +++ b/test/jalview/analysis/ConservationTest.java @@ -48,7 +48,7 @@ public class ConservationTest seqs.add(new Sequence("seq3", "VG-Y")); seqs.add(new Sequence("seq4", "VGNW")); - Conservation cons = new Conservation("", 3, seqs, 0, 50); + Conservation cons = new Conservation("", seqs, 0, 50); int[] counts = cons.countConservationAndGaps(0); assertEquals(counts[0], 1); // conserved assertEquals(counts[1], 1); // gap count