diff --git a/sinto/filterbarcodes.py b/sinto/filterbarcodes.py index 3309b06..df31ba7 100644 --- a/sinto/filterbarcodes.py +++ b/sinto/filterbarcodes.py @@ -33,6 +33,9 @@ def _iterate_reads( bamlist = [pysam.AlignmentFile(x, filemode, header=newhead) for x in filelist] for i in intervals: for r in inputBam.fetch(i[0], i[1], i[2]): + # skip reads owned by the previous chunk (fetch returns overlaps); unmapped reads have reference_start < 0 + if r.reference_start >= 0 and r.reference_start < i[1]: + continue if readname_barcode is not None: re_match = readname_barcode.search(r.qname) cell_barcode = re_match.group()