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;
/**
* 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;
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
* @param end
* end residue position
*/
+ public Conservation(String name, List<SequenceI> 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<SequenceI> sequences, int start, int end)
{
{
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;
/*
*
* @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
* @return Conservation object ready for use in visualization
*/
public static Conservation calculateConservation(String name,
- int threshold, List<SequenceI> seqs, int start, int end,
- boolean positiveOnly, int maxPercentGaps, boolean calcQuality)
+ List<SequenceI> 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);
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();
}
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());
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)
}
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);
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);
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);
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);
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
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));
}
}
try
{
- cons = Conservation.calculateConservation("All", 3,
+ cons = Conservation.calculateConservation("All",
alignment.getSequences(), 0, alWidth - 1, false,
ConsPercGaps, quality != null);
} catch (IndexOutOfBoundsException x)
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