From 53877492ff97dd3fb71686986723a9186008f41c Mon Sep 17 00:00:00 2001 From: Mia Croiset <mia.croiset@ens-lyon.fr> Date: Fri, 3 Mar 2023 09:26:10 +0100 Subject: [PATCH] ARGS hicstuff align_bowtie2 & fragment_enzyme --- bin/hicstuff_fragments.py | 22 +++- conf/hicstuff.config | 140 ++++++++++++---------- modules/local/hicstuff/align_bowtie2.nf | 3 +- modules/local/hicstuff/fragment_enzyme.nf | 9 +- 4 files changed, 104 insertions(+), 70 deletions(-) diff --git a/bin/hicstuff_fragments.py b/bin/hicstuff_fragments.py index c49378e..489945d 100755 --- a/bin/hicstuff_fragments.py +++ b/bin/hicstuff_fragments.py @@ -7,10 +7,22 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-e", "--enzyme") parser.add_argument("-i", "--index") + parser.add_argument("-m", "--min_size") + parser.add_argument("-c", "--circular") + parser.add_argument("-o", "--output_contigs") + parser.add_argument("-f", "--output_frags") + parser.add_argument("-p", "--plot") + parser.add_argument("-g", "--fig_path") args = parser.parse_args() enzyme = args.enzyme index = args.index + min_size = args.min_size + circular = args.circular + output_contigs = args.output_contigs + output_frags = args.output_frags + plot = args.plot + fig_path = args.fig_path #hicstuff case sensitive enzymes adaptation @@ -30,11 +42,11 @@ if __name__ == "__main__": hcd.write_frag_info( index, enzyme, - min_size=0, - circular=False, - output_contigs="info_contigs.txt", - output_frags="fragments_list.txt", + min_size, + circular, + output_contigs, + output_frags ) # Log fragment size distribution - hcd.frag_len(frags_file_name="fragments_list.txt", plot=False, fig_path="frags_hist.pdf") + hcd.frag_len(output_frags, plot=plot, fig_path=fig_path) diff --git a/conf/hicstuff.config b/conf/hicstuff.config index 6b1178a..578ded8 100644 --- a/conf/hicstuff.config +++ b/conf/hicstuff.config @@ -1,64 +1,3 @@ -process { - //Default - publishDir = [ - path: { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }, - mode: 'copy', - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - - withName: 'BOWTIE2_ALIGNMENT' { - ext.prefix = { "${meta.id}_${meta.chunk}_${meta.mates}" } - publishDir = [ - path: { "${params.outdir}/hicstuff/reads"}, - mode: 'copy' - ] - } - - withName: 'FRAGMENT_ENZYME' { - publishDir = [ - path: { "${params.outdir}/hicstuff/fragment_enzyme" }, - mode: 'copy' - ] - } - - withName: 'BAM2PAIRS' { - publishDir = [ - path: { "${params.outdir}/hicstuff/pairs" }, - mode: 'copy' - ] - } - withName: 'BUILD_MATRIX' { - publishDir = [ - path: { "${params.outdir}/hicstuff/matrix" }, - mode: 'copy' - ] - } - - //********************************************** - // PREPARE_GENOME - withName: 'BOWTIE2_BUILD' { - publishDir = [ - path: { "${params.outdir}/genome/bowtie2_index" }, - mode: 'copy' - ] - } - - withName: 'CUSTOM_GETCHROMSIZES' { - publishDir = [ - path: { "${params.outdir}/genome" }, - mode: 'copy' - ] - } - - withName: 'GET_RESTRICTION_FRAGMENTS' { - publishDir = [ - path: { "${params.outdir}/genome" }, - mode: 'copy' - ] - } - -} - params { // Input options @@ -179,7 +118,86 @@ params { max_cpus = 16 max_time = '240.h' + // Hicstuff + hicstuff_bwt2_align_opts = '--very-sensitive-local' + hicstuff_min_size = 0 + hicstuff_circular = 'False' + hicstuff_output_contigs = 'info_contigs.txt' + hicstuff_output_frags = 'fragments_list.txt' + hicstuff_frags_plot = 'False' + hicstuff_frags_plot_path = 'frags_hist.pdf' } + +process { + //Default + publishDir = [ + path: { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }, + mode: 'copy', + saveAs: { filename -> filename.equals('versions.yml') ? null : filename } + ] + + withName: 'BOWTIE2_ALIGNMENT' { + ext.prefix = { "${meta.id}_${meta.chunk}_${meta.mates}" } + ext.args = params.hicstuff_bwt2_align_opts + publishDir = [ + path: { "${params.outdir}/hicstuff/reads"}, + mode: 'copy' + ] + } + + withName: 'FRAGMENT_ENZYME' { + ext.args = { [ + " -m ${params.hicstuff_min_size}", + " -c ${params.hicstuff_circular}", + " -o ${params.hicstuff_output_contigs}", + " -f ${params.hicstuff_output_frags}", + " -p ${params.hicstuff_frags_plot}", + " -g ${params.hicstuff_frags_plot_path}" + ].join('').trim() } + publishDir = [ + path: { "${params.outdir}/hicstuff/fragment_enzyme" }, + mode: 'copy' + ] + } + + withName: 'BAM2PAIRS' { + publishDir = [ + path: { "${params.outdir}/hicstuff/pairs" }, + mode: 'copy' + ] + } + withName: 'BUILD_MATRIX' { + publishDir = [ + path: { "${params.outdir}/hicstuff/matrix" }, + mode: 'copy' + ] + } + + //********************************************** + // PREPARE_GENOME + withName: 'BOWTIE2_BUILD' { + publishDir = [ + path: { "${params.outdir}/genome/bowtie2_index" }, + mode: 'copy' + ] + } + + withName: 'CUSTOM_GETCHROMSIZES' { + publishDir = [ + path: { "${params.outdir}/genome" }, + mode: 'copy' + ] + } + + withName: 'GET_RESTRICTION_FRAGMENTS' { + publishDir = [ + path: { "${params.outdir}/genome" }, + mode: 'copy' + ] + } + +} + profiles { debug { process.beforeScript = 'echo $HOSTNAME' } conda { diff --git a/modules/local/hicstuff/align_bowtie2.nf b/modules/local/hicstuff/align_bowtie2.nf index a3f2f1c..188836d 100644 --- a/modules/local/hicstuff/align_bowtie2.nf +++ b/modules/local/hicstuff/align_bowtie2.nf @@ -16,13 +16,14 @@ process BOWTIE2_ALIGNMENT { script: def prefix = task.ext.prefix ?: "${meta.id}" + def args = task.ext.args ?: '' """ INDEX=`find -L ./ -name "*.rev.1.bt2" | sed "s/\\.rev.1.bt2\$//"` [ -z "\$INDEX" ] && INDEX=`find -L ./ -name "*.rev.1.bt2l" | sed "s/\\.rev.1.bt2l\$//"` [ -z "\$INDEX" ] && echo "Bowtie2 index files not found" 1>&2 && exit 1 - bowtie2 --very-sensitive-local -p $task.cpus -x \$INDEX -U $reads > ${prefix}.tmp + bowtie2 $args -p $task.cpus -x \$INDEX -U $reads > ${prefix}.tmp samtools view -F 2048 -h -@ $task.cpus ${prefix}.tmp | samtools sort -n -@ $task.cpus -o ${prefix}.bam - """ diff --git a/modules/local/hicstuff/fragment_enzyme.nf b/modules/local/hicstuff/fragment_enzyme.nf index dafa3cf..d17fdfe 100644 --- a/modules/local/hicstuff/fragment_enzyme.nf +++ b/modules/local/hicstuff/fragment_enzyme.nf @@ -10,12 +10,15 @@ process FRAGMENT_ENZYME { tuple val(meta), path(fasta) output: - tuple val(meta), path("info_contigs.txt") , emit: info_contigs - tuple val(meta), path("fragments_list.txt"), emit: fragments_list + tuple val(meta), path(params.hicstuff_output_contigs) , emit: info_contigs + tuple val(meta), path(params.hicstuff_output_frags), emit: fragments_list script: + + def args = task.ext.args ?: '' + """ - hicstuff_fragments.py -e ${digestion} -i ${fasta} + hicstuff_fragments.py -e ${digestion} -i ${fasta} ${args} """ } -- GitLab