rule gz_to_dsrc:
    """**Convert fastq.gz files to fastq.dsrc files**

    Here are the steps followed by the rule. Any failure stops the
    process and the original file is untouched. If all succeed, the
    input is deleted.

        #. the input GZ file is checked for integrity.
        #. the input GZ file is decompressed with **pigz** and redirected
           a pipe to **dsrc** executable into a DSRC output.
        #. the output is checked for integrity with **pigz**.
        #. the input GZ file is deleted.

    :param input: {dataset}.gz
    :param output: {dataset}.dsrc 
    :third-party executables: dsrc and pigz

    configuration requirements::

        compressor:
            - threads

    """
    input: "{dataset}.gz"
    output: "{dataset}.dsrc"
    params: "-m2"
    threads: config["compressor"]["threads"]
    run:
        
	# check integrity
        cmd = "pigz -p{threads} --test {input}" 
        shell(cmd)

	#conversion
        cmd = "pigz -d -c -p {threads} {input} | dsrc c -s -t{threads} {params} {output}"
        shell(cmd)

        # once done and integraty is checked, we removed the input file
        cmd = "rm -f {input}"
        shell(cmd)

