/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Config file for defining DSL2 per module options and publishing paths
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Available keys to override module options:
        ext.args            = Additional arguments appended to command in module.
        ext.args2           = Second set of arguments appended to command in module (multi-tool modules).
        ext.args3           = Third set of arguments appended to command in module (multi-tool modules).
        ext.prefix          = File name prefix for output files.
        ext.when            = Conditional clause
----------------------------------------------------------------------------------------
*/

//
// Extract mitochondrial reads from bam and save them in fastq files
//

process {

    withName: '.*ANALYSE_MT:CONVERT_MT_BAM_TO_FASTQ:GATK4_PRINTREADS_MT' {
        beforeScript = {"mkdir ./tmp"}
        ext.args = [
            "-L ${params.mito_name}",
            "--read-filter MateOnSameContigOrNoMappedMateReadFilter",
            "--read-filter MateUnmappedAndUnmappedReadFilter"
        ].join(" ").trim()
    }

    withName: '.*ANALYSE_MT:CONVERT_MT_BAM_TO_FASTQ:GATK4_REVERTSAM_MT' {
        ext.args = '--OUTPUT_BY_READGROUP false --VALIDATION_STRINGENCY LENIENT --ATTRIBUTE_TO_CLEAR FT --ATTRIBUTE_TO_CLEAR CO --SORT_ORDER queryname --RESTORE_ORIGINAL_QUALITIES false'
    }

    withName: '.*ANALYSE_MT:CONVERT_MT_BAM_TO_FASTQ:GATK4_SAMTOFASTQ_MT' {
        ext.args = '--VALIDATION_STRINGENCY LENIENT'
    }
}
