INNER CODE UNIT · Python

detect_nanopore

nloyfer/wgbs_tools · src/python/bam2pat.py:243

def detect_nanopore(bam, genome_path):
    """Auto-detect nanopore/modification-aware BAM.
    1. Check @RG PL:ONT in header — fast, reliable for ONT BAMs.
    2. Sample 200 reads for MM:Z: / Mm:Z: tags — catches Biomodal and others
       (Biomodal uses PL:ILLUMINA so header alone is insufficient).
    Returns True if either check is positive.
    """
    header = subprocess.check_output(f'samtools view -H {bam}', shell=True).decode()
    if '\tPL:ONT' in header:
        return True
    try:
        reads = subprocess.check_output(
            f'samtools view {bam} -T {genome_path} | head -200',
            shell=True, stderr=subprocess.DEVNULL).decode()
        return any('\tMM:Z:' in line or '\tMm:Z:' in line for line in reads.splitlines())
    except subprocess.CalledProcessError:
        return False

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…