view qualimap_bamqc.py @ 5:f18b4224ff36 draft

planemo upload for repository https://github.com/refinery-platform/qualimap2 commit d3e3edd55f03bf4f5337c2eac874d5579007eec2
author refinery-platform
date Mon, 30 Jul 2018 12:12:18 -0400
parents a6d048668f7f
children a2438e0f1bbf
line wrap: on
line source

#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
from subprocess import check_call, CalledProcessError
import shutil
import sys

QUALIMAP_OUPUT_DIR = "qualimap_results"


def qualimap_bamqc(bam_filename, jv_mem_size):
    qualimap_command = [
        "qualimap", "bamqc",
        "-bam " + bam_filename,
        "-outdir " + QUALIMAP_OUPUT_DIR,
        "--java-mem-size=" + jv_mem_size
    ]

    try:
        check_call(qualimap_command)
    except CalledProcessError:
        print("Error running the qualimap bamqc", file=sys.stderr)


def main():
    parser = argparse.ArgumentParser(
        description="Generate Bam Quality Statistics"
    )
    parser.add_argument('--input_file')
    parser.add_argument('--out_dir')
    parser.add_argument('--out_results')
    parser.add_argument('--out_zip')
    parser.add_argument('--java_mem_size')

    args = parser.parse_args()

    qualimap_bamqc(args.input_file, args.java_mem_size)

    shutil.make_archive(
        'raw_data_qualimapReport',
        'zip',
        os.path.join(QUALIMAP_OUPUT_DIR, 'raw_data_qualimapReport')
    )

    shutil.move("raw_data_qualimapReport.zip", args.out_zip)
    shutil.move(
        os.path.join(QUALIMAP_OUPUT_DIR, "genome_results.txt"),
        args.out_results
    )

if __name__ == "__main__":
    main()