Skip to content

Commit ea0e6e6

Browse files
committed
fix: unmapped reads are ignored, no longer cause length-check crash; version -> 2.9.1
1 parent 9e0fc3b commit ea0e6e6

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

gffquant/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
""" module docstring """
22

3-
__version__ = "2.9"
3+
__version__ = "2.9.1"

gffquant/alignment/bamreader.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,26 @@
1717

1818
class SamFlags:
1919
PAIRED = 0x1
20+
PROPERLY_PAIRED = 0x2
21+
UNMAPPED = 0x4
2022
MATE_UNMAPPED = 0x8
2123
REVERSE = 0x10
24+
MATE_REVERSE = 0x20
2225
FIRST_IN_PAIR = 0x40
2326
SECOND_IN_PAIR = 0x80
2427
SECONDARY_ALIGNMENT = 0x100
28+
QUAL_CHECK_FAILURE = 0x200
29+
PCR_OPTICAL_DUPLICATE = 0x400
2530
SUPPLEMENTARY_ALIGNMENT = 0x800
2631

2732
@staticmethod
2833
def is_reverse_strand(flag):
2934
return bool(flag & SamFlags.REVERSE)
3035

36+
@staticmethod
37+
def is_unmapped(flag):
38+
return bool(flag & SamFlags.UNMAPPED)
39+
3140

3241
class CigarOps:
3342
CIGAR_OPS = "MIDNSHP=X"

gffquant/alignment/pysam_alignment_processor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pysam
44

5-
from .bamreader import BamAlignment
5+
from .bamreader import BamAlignment, SamFlags
66

77

88
class AlignmentProcessor:
@@ -69,6 +69,9 @@ def get_alignments(
6969
dict(pysam_aln.tags)
7070
)
7171

72+
if SamFlags.is_unmapped(aln.flag):
73+
continue
74+
7275
if aln.flag & filter_flags:
7376
continue
7477

0 commit comments

Comments
 (0)