From: gmungoc Date: Thu, 7 Mar 2019 09:11:24 +0000 (+0000) Subject: JAL-722 redone additional derived alignment statistics X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=74237ef1010deae009bf37a34dfaa8cde0c56ced;p=jalview.git JAL-722 redone additional derived alignment statistics --- diff --git a/src/jalview/io/AlignmentProperties.java b/src/jalview/io/AlignmentProperties.java index a65b83d..69bd658 100644 --- a/src/jalview/io/AlignmentProperties.java +++ b/src/jalview/io/AlignmentProperties.java @@ -83,9 +83,9 @@ public class AlignmentProperties /* * 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); } @@ -105,9 +105,9 @@ public class AlignmentProperties 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 ? "" : nl); diff --git a/test/jalview/io/AlignmentPropertiesTest.java b/test/jalview/io/AlignmentPropertiesTest.java new file mode 100644 index 0000000..a3f58ce --- /dev/null +++ b/test/jalview/io/AlignmentPropertiesTest.java @@ -0,0 +1,36 @@ +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 = "" + + "" + + "" + + "" + + "" + + "" + + "" // 6/12 + + "" // 9/12 + + "" // 23/36 + + "" + "
Sequences3
Alignment width12
Minimum Sequence Length6
Maximum Sequence Length9
Average Length7
Minimum (sequence length / width)50.0%
Maximum (sequence length / width)75.0%
Residue density63.9%
Gap density36.1%
"; + assertEquals(sb.toString(), expected); + } +}