INNER CODE UNIT · Python
validate_bam
nloyfer/wgbs_tools · src/python/bam2pat.py:212
def validate_bam(bam):
# validate bam path:
eprint('[wt bam2pat] bam:', bam)
if not (op.isfile(bam) and bam.endswith(('.bam', '.cram'))):
eprint(f'[wt bam2pat] Invalid bam: {bam}')
return False
return True
def is_bam_sorted(bam):
# check if bam is sorted by coordinate:
peek_cmd = f'samtools view -H {bam}| head -1'
hd_line = subprocess.check_output(peek_cmd, shell=True).decode()
if hd_line.startswith('@HD') and 'coordinate' not in hd_line:
eprint(f'[wt bam2pat] WARNING: based on the @HD, bam file is not sorted: {bam}')
return False