diff --git a/bin/digest_genome.py b/bin/digest_genome.py index 9f05b45..4d8498e 100755 --- a/bin/digest_genome.py +++ b/bin/digest_genome.py @@ -113,6 +113,7 @@ def replaceN(cs): "specified." ), ) + parser.add_argument("--extra", default=False, action='store_false', help="Add extra BED columns") parser.add_argument("-o", "--out", default=None) args = parser.parse_args() @@ -193,8 +194,10 @@ def replaceN(cs): # allow to remove cases where the enzyme cut at # the first position of the chromosome if end > begin: - frag_id += 1 - frag_name = "HIC_{}_{}".format(str(chrom_name), int(frag_id)) - outfile.write( - "{}\t{}\t{}\t{}\t0\t+\n".format(str(chrom_name), int(begin), int(end), str(frag_name)) - ) + if args.extra: + frag_id += 1 + frag_name = "HIC_{}_{}".format(str(chrom_name), int(frag_id)) + outfile.write("{}\t{}\t{}\t{}\t0\t+\n".format(str(chrom_name), int(begin), int(end), str(frag_name))) + else: + outfile.write("{}\t{}\t{}\n".format(str(chrom_name), int(begin), int(end))) + diff --git a/conf/modules.config b/conf/modules.config index 61104f1..43e6694 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -39,6 +39,7 @@ process { mode: 'copy', enabled: params.save_reference ] + ext.args = params.processing == "hicpro" ? '--extra' : '' } //******************************************* @@ -182,8 +183,15 @@ process { } withName: 'PAIRTOOLS_PARSE' { - ext.args = { "--min-mapq 40 --walks-policy 5unique --max-inter-align-gap 30 --output-stats ${meta.id}_parse.stats --add-columns mapq --drop-sam --drop-seq" } + ext.args = { [ + '--add-columns mapq', + params.save_interaction_bam ? '' : '--drop-sam --drop-seq', + "--walks-policy 5unique --output-stats ${meta.id}_parse.stats" + ].join(' ').trim() } + } + withName: 'PAIRTOOLS_RESTRICT' { + ext.prefix = { "${meta.id}_restrict" } } withName: 'PAIRTOOLS_DEDUP' { diff --git a/modules/local/hicpro/get_restriction_fragments.nf b/modules/local/hicpro/get_restriction_fragments.nf index d810c4c..9d10014 100644 --- a/modules/local/hicpro/get_restriction_fragments.nf +++ b/modules/local/hicpro/get_restriction_fragments.nf @@ -16,8 +16,10 @@ process GET_RESTRICTION_FRAGMENTS { path("versions.yml"), emit: versions script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "restriction_fragments" """ - digest_genome.py -r ${res_site} -o restriction_fragments.bed ${fasta} + digest_genome.py ${args} -r ${res_site} -o ${prefix}.bed ${fasta} cat <<-END_VERSIONS > versions.yml "${task.process}": diff --git a/subworkflows/local/pairtools.nf b/subworkflows/local/pairtools.nf index 7470e41..80f9f17 100644 --- a/subworkflows/local/pairtools.nf +++ b/subworkflows/local/pairtools.nf @@ -31,6 +31,7 @@ workflow PAIRTOOLS { take: reads // [meta, read1, read2] index // [meta2, path] + frag chrsize // path main: @@ -39,7 +40,7 @@ workflow PAIRTOOLS { BWA_MEM( reads, index, - Channel.value("view") + Channel.value("false") ) PAIRTOOLS_PARSE( @@ -47,8 +48,13 @@ workflow PAIRTOOLS { chrsize ) + PAIRTOOLS_RESTRICT( + PAIRTOOLS_PARSE.out.pairsam, + frag.map{it->it[1]} + ) + PAIRTOOLS_SORT( - PAIRTOOLS_PARSE.out.pairsam + PAIRTOOLS_RESTRICT.out.restrict ) ch_valid_pairs = PAIRTOOLS_SORT.out.sorted.map{ it -> removeChunks(it)}.groupTuple() diff --git a/workflows/hic.nf b/workflows/hic.nf index e996a0f..6c8c252 100644 --- a/workflows/hic.nf +++ b/workflows/hic.nf @@ -193,6 +193,7 @@ workflow HIC { PAIRTOOLS( INPUT_CHECK.out.reads, PREPARE_GENOME.out.index, + PREPARE_GENOME.out.res_frag, PREPARE_GENOME.out.chromosome_size ) ch_versions = ch_versions.mix(PAIRTOOLS.out.versions)