Skip to content

Commit 59461ce

Browse files
committed
Update qual method documentation and enhance tests for base qualities
1 parent 778e174 commit 59461ce

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/hts/bam/record.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,11 @@ def base(n)
272272
SEQ_NT16_STR[LibHTS.bam_seqi(r, n)]
273273
end
274274

275-
# Get the base qualities.
276-
# @return [Array] base qualities
275+
# Get the base qualities as raw PHRED bytes.
276+
# Ruby has no UInt8 type, so this returns an Array<Integer> with values in 0..255,
277+
# corresponding to Crystal's Array(UInt8).
278+
# Use qual_string for the SAM-style ASCII representation.
279+
# @return [Array<Integer>] base qualities as unsigned bytes
277280
def qual
278281
q_ptr = LibHTS.bam_get_qual(@bam1)
279282
q_ptr.read_array_of_uint8(len)

test/bam/record_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ def test_base
214214
def test_qual
215215
assert_equal ([17] * 70), @aln1.qual
216216
assert_equal ([255] * 10), @aln2.qual
217+
assert_equal true, @aln1.qual.all? { |q| q.is_a?(Integer) && q.between?(0, 255) }
218+
assert_equal true, @aln2.qual.all? { |q| q.is_a?(Integer) && q.between?(0, 255) }
217219
end
218220

219221
def test_base_qual

0 commit comments

Comments
 (0)