/*
* proportion of aligned sequence that is ungapped
- * (note: not normalised by alignment width here)
+ * (note: normalised by alignment width here)
*/
- float ungapped = (seqLength - gapCount) / (float) seqLength;
+ float ungapped = (seqWidth - gapCount) / (float) seqWidth;
maxUngapped = Math.max(maxUngapped, ungapped);
minUngapped = Math.min(minUngapped, ungapped);
}
appendRow(sb, "Maximum (sequence length / width)",
String.format(PCT_FORMAT, maxUngapped * 100f), html);
appendRow(sb, "Residue density", String.format(PCT_FORMAT,
- (totalLength - totalGaps) * 100f / totalLength), html);
+ (height * width - totalGaps) * 100f / (height * width)), html);
appendRow(sb, "Gap density",
- String.format(PCT_FORMAT, totalGaps * 100f / totalLength),
+ String.format(PCT_FORMAT, totalGaps * 100f / (height * width)),
html);
sb.append(html ? "</table>" : nl);
--- /dev/null
+package jalview.io;
+
+import static org.testng.Assert.assertEquals;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import org.testng.annotations.Test;
+
+public class AlignmentPropertiesTest
+{
+ @Test(groups="Functional")
+ public void testWriteProperties_asHtml()
+ {
+ SequenceI seq1 = new Sequence("Seq1", "--ABC-DEFGH-"); // 8 residues
+ SequenceI seq2 = new Sequence("Seq2", "---BC-DE-KH-"); // 6
+ SequenceI seq3 = new Sequence("Seq3", "-RABCFDE-KH-"); // 9
+ AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2, seq3 });
+
+ AlignmentProperties ap = new AlignmentProperties(al);
+ StringBuilder sb = ap.writeProperties(true);
+ String expected = "<table border=\"1\">"
+ + "<tr><td>Sequences</td><td>3</td></tr>"
+ + "<tr><td>Alignment width</td><td>12</td></tr>"
+ + "<tr><td>Minimum Sequence Length</td><td>6</td></tr>"
+ + "<tr><td>Maximum Sequence Length</td><td>9</td></tr>"
+ + "<tr><td>Average Length</td><td>7</td></tr>"
+ + "<tr><td>Minimum (sequence length / width)</td><td>50.0%</td></tr>" // 6/12
+ + "<tr><td>Maximum (sequence length / width)</td><td>75.0%</td></tr>" // 9/12
+ + "<tr><td>Residue density</td><td>63.9%</td></tr>" // 23/36
+ + "<tr><td>Gap density</td><td>36.1%</td></tr>" + "</table>";
+ assertEquals(sb.toString(), expected);
+ }
+}