fixed quality check, skip if null quality and quality_threshold == 0 or None
@@ -1538,15 +1538,13 @@ cdef class AlignmentFile(HTSFile):
cdef int c = 0
cdef int filter_method = 0
- # check base quality if quality == None or 0
- cdef int check_qual = 1 if quality_threshold else 0
if read_callback == "all":
filter_method = 1
elif read_callback == "nofilter":
filter_method = 2
- cdef int _threshold = quality_threshold if quality_threshold else 0
+ cdef int _threshold = quality_threshold or 0
for read in self.fetch(contig=contig,
reference=reference,
start=start,
@@ -1569,15 +1567,13 @@ cdef class AlignmentFile(HTSFile):
seq = read.seq
quality = read.query_qualities
- if not quality and check_qual == 1:
- raise ValueError('%s contains no QUAL field, use quality_threshold = None to ignore base quality' %read.query_name)
-
for qpos, refpos in read.get_aligned_pairs(True):
if qpos is not None and refpos is not None and \
_start <= refpos < _stop:
- # only check base quality if check_qual == 1
- if check_qual == 0 or quality[qpos] >= quality_threshold:
+ # only check base quality if _threshold > 0
+ if (_threshold and quality and quality[qpos] < _threshold) or \
+ (not _threshold and not quality):
if seq[qpos] == 'A':
count_a.data.as_ulongs[refpos - _start] += 1
if seq[qpos] == 'C':
