"""



"""



rule bwa_bam_to_fastq:
    message: """
    -- Extracting the fastq from the BAM/SAM files
    -- information saved in {log}
    """
    input:
        bam = "bwa_phix/contaminant.bam",
    params:
        wkdir = "bwa_phix",
    output:
        "bwa_phix/phix_stats.json"
    threads: 1
    run:
        from sequana.tools import bam_to_mapped_unmapped_fastq as bam2fastq
        stats = bam2fastq(input["bam"])
        import json
        json.dump(stats, open("%s/phix_stats.json" % params.wkdir, "w"))

        # zip the fastq files
        import glob
        tozip = glob.glob("%s/*.fastq")
        for filename in tozip:
            shell("pigz %s filename" )



