Skip to content

Commit

Permalink
Merge pull request #89 from JMencius/master
Browse files Browse the repository at this point in the history
Check if input bam file is sorted
  • Loading branch information
kcleal authored Apr 16, 2024
2 parents 57b28c0 + b664d5a commit 5a5a526
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dysgu/cluster.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,8 @@ def cluster_reads(args):
if kind2 == "stdin" or kind2 == "-" or kind2 not in opts:
raise ValueError("--ibam must be a .bam/cam/sam file")
ibam = pysam.AlignmentFile(args["ibam"], opts[kind2], threads=1,
reference_filename=None if kind2 != "cram" else args["reference"])
reference_filename=None if kind2 != "cram" else args["reference"])

if "RG" in infile.header:
rg = infile.header["RG"]
if "SM" in rg[0]:
Expand Down
17 changes: 17 additions & 0 deletions dysgu/coverage.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,24 @@ cdef class GenomeScanner:
cdef uint32_t *cigar_p
cdef int i
cdef int non_match_count, matched_bases

# first check SO tag in HD
if "HD" in file_iter.header:
hd = file_iter.header["HD"]
if "SO" in hd:
if hd["SO"] == "unsorted":
# raise ValueError for SO:unsorted
raise ValueError("Input bam file must be sorted")
else:
logging.info("Check PASS : Input BAM file has sorted header")

prev_alignment = None
for a in file_iter:
# double check with index
if prev_alignment and prev_alignment.reference_id > a.reference_id:
raise ValueError("Input bam file must be sorted")
prev_alignment = a

if ibam is None:
if a.flag & 1284 or a.mapq < self.mapq_threshold or a.cigartuples is None:
continue
Expand Down

0 comments on commit 5a5a526

Please sign in to comment.