From 66d4791637065bc1fe5e090682e7ab6f64e246f5 Mon Sep 17 00:00:00 2001 From: nservant Date: Fri, 22 Dec 2023 15:06:34 +0100 Subject: [PATCH] [MODIF] fix pairtools subwkflow --- conf/modules.config | 77 ++++++++++++++++++++------------- subworkflows/local/pairtools.nf | 22 +++++----- 2 files changed, 59 insertions(+), 40 deletions(-) diff --git a/conf/modules.config b/conf/modules.config index 808358f..687fd4e 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -142,7 +142,6 @@ process { [ path: { "${params.outdir}/hicpro/valid_pairs" }, mode: 'copy', - saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, pattern: "*Pairs" ] ] @@ -152,7 +151,6 @@ process { withName: 'MERGE_STATS' { publishDir = [ path: { "${params.outdir}/hicpro/stats/${meta.id}" }, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, mode: 'copy', pattern: "*stat" ] @@ -190,14 +188,17 @@ process { publishDir = [ path: { "${params.outdir}/bwa" }, saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, - mode: 'copy' + mode: 'copy', + enabled: params.save_aligned_intermediates ] ext.args = params.bwa_opts ?: '' } withName: 'PAIRTOOLS_PARSE' { publishDir = [ - enabled: false + path: { "${params.outdir}/pairtools/stats/" }, + mode: 'copy', + pattern: "*pairsam.stat" ] ext.args = { [ '--add-columns mapq', @@ -226,49 +227,64 @@ process { withName: 'PAIRTOOLS_MERGE' { publishDir = [ enabled: false - ] + ] ext.prefix = { "${meta.id}_merged" } } - withName: 'PAIRTOOLS_DEDUP' { + withName: 'PAIRTOOLS_SPLIT' { publishDir = [ - enabled: false + path: { "${params.outdir}/pairtools" }, + saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, + mode: 'copy', + pattern: "*pairs.gz", + enabled: params.save_pairs_intermediates ] - ext.args = { "--mark-dups" } - ext.prefix = { "${meta.id}_dedup" } - ext.when = !params.keep_dups + ext.args = { params.save_interaction_bam ? "--output-sam ${meta.id}_pairtools.bam" : '' } + } + + withName: 'SAMTOOLS_SORT' { + publishDir = [ + path: { "${params.outdir}/pairtools" }, + saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, + mode: 'copy', + enabled: params.save_pairs_intermediates + ] + ext.prefix = { "${meta.id}_pairtools_sorted" } } - withName: 'PAIRTOOLS_SPLIT' { - publishDir = [ + withName: 'SAMTOOLS_INDEX' { + publishDir = [ path: { "${params.outdir}/pairtools" }, saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, mode: 'copy', enabled: params.save_pairs_intermediates ] - ext.args = { params.save_interaction_bam ? "--output-sam ${meta.id}_pairtools.bam" : '' } + } + + withName: 'PAIRTOOLS_DEDUP' { + publishDir = [ + path: { "${params.outdir}/pairtools/stats/" }, + mode: 'copy', + pattern: "*.pairs.stat" + ] + ext.args = { "--mark-dups" } + ext.prefix = { "${meta.id}_dedup" } + ext.when = !params.keep_dups } withName: 'PAIRTOOLS_SELECT' { publishDir = [ - [ - path: { "${params.outdir}/pairtools/" }, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, - mode: 'copy', - pattern: "*pairs.gz" - ], - [ - path: { "${params.outdir}/pairtools/stats/" }, - mode: 'copy', - pattern: "*stats.txt" - ] + path: { "${params.outdir}/pairtools/" }, + saveAs: { filename -> filename.equals('versions.yml') ? null : filename }, + mode: 'copy', + pattern: "*pairs.gz" ] ext.args = { [ params.min_mapq > 0 ? "(mapq1>${params.min_mapq} and mapq2>${params.min_mapq})" : '', - params.min_cis_dist > 0 ? " and (abs(pos1-pos2) > ${params.min_cis_dist})" : '', - params.keep_multi ? " and ((pair_type=='UU') or (pair_type=='UR') or (pair_type=='RU') or (pair_type=='MM') or (pair_type=='MU'))" : - " and ((pair_type=='UU') or (pair_type=='UR') or (pair_type=='RU'))", - params.dnase ? '' : " and (abs(int(rfrag1) - int(rfrag2)) > 1)", + params.min_cis_dist > 0 ? " and ((chrom1==chrom2 and abs(pos1-pos2) > ${params.min_cis_dist}) or chrom1!=chrom2)" : '', + params.keep_multi ? " and ((pair_type.upper()=='UU') or (pair_type.upper()=='UR') or (pair_type.upper()=='RU') or (pair_type.upper()=='MM') or (pair_type.upper()=='MU'))" : + " and ((pair_type.upper()=='UU') or (pair_type.upper()=='UR') or (pair_type.upper()=='RU'))", + params.dnase ? '' : " and ((chrom1==chrom2 and abs(int(rfrag1) - int(rfrag2)) > 1) or chrom1!=chrom2)", //params.min_insert_size > 0 ? " and ( (rfrag_end1 - r1pos) + (rfrag_end2 - r2pos)) > ${params.min_insert_size}" : '', //params.max_insert_size > 0 ? " and ( (rfrag_end1 - r1pos) + (rfrag_end2 - r2pos)) < ${params.max_insert_size}" : '', //params.min_restriction_fragment_size > 0 ? " -t ${params.min_restriction_fragment_size}" : '', @@ -278,10 +294,11 @@ process { withName: 'PAIRTOOLS_STATS' { publishDir = [ - path: { "${params.outdir}/pairtools/stats/" }, + path: { "${params.outdir}/pairtools/stats/" }, mode: 'copy', - pattern: "*stats.txt" + saveAs: { filename -> filename.equals('versions.yml') ? null : filename } ] + ext.prefix = { "${meta.id}_select.pairs.stat" } } withName: 'PAIRIX' { diff --git a/subworkflows/local/pairtools.nf b/subworkflows/local/pairtools.nf index b641709..dbb7004 100644 --- a/subworkflows/local/pairtools.nf +++ b/subworkflows/local/pairtools.nf @@ -68,17 +68,12 @@ workflow PAIRTOOLS { ch_valid_pairs.multiple ) - PAIRTOOLS_MERGE.out.pairs.mix(ch_valid_pairs.single).view() - - PAIRTOOLS_DEDUP( - PAIRTOOLS_MERGE.out.pairs.mix(ch_valid_pairs.single) - ) - - ch_pairsam2split = params.keep_dups ? PAIRTOOLS_MERGE.out.pairs.mix(ch_valid_pairs.single) : PAIRTOOLS_DEDUP.out.pairs + // Separate pairs/bam files PAIRTOOLS_SPLIT( - ch_pairsam2split + PAIRTOOLS_MERGE.out.pairs.mix(ch_valid_pairs.single) ) + // Manage BAM files SAMTOOLS_SORT( PAIRTOOLS_SPLIT.out.bam ) @@ -87,12 +82,19 @@ workflow PAIRTOOLS { SAMTOOLS_SORT.out.bam ) - PAIRTOOLS_SELECT( + // TODO - add samtools flagstat + + PAIRTOOLS_DEDUP( PAIRTOOLS_SPLIT.out.pairs ) + ch_pairselect = params.keep_dups ? PAIRTOOLS_SPLIT.out.pairs : PAIRTOOLS_DEDUP.out.pairs + PAIRTOOLS_SELECT( + ch_pairselect + ) + PAIRTOOLS_STATS( - PAIRTOOLS_SPLIT.out.pairs + PAIRTOOLS_SELECT.out.selected ) PAIRIX(