diff --git a/main.nf b/main.nf index 116f6d69b..da9009b51 100644 --- a/main.nf +++ b/main.nf @@ -253,10 +253,12 @@ if (params.sentieon) log.warn "[nf-core/sarek] Sentieon will be used, only works ================================================================================ */ + include { BWAMEM2_MEM } from './modules/local/bwamem2_mem.nf' include { GET_SOFTWARE_VERSIONS } from './modules/local/get_software_versions' include { OUTPUT_DOCUMENTATION } from './modules/local/output_documentation' include { TRIM_GALORE } from './modules/local/trim_galore.nf' +include { MERGE_BAM_MAPPED } from './modules/local/merge_mapped_bam' addParams(params) /* ================================================================================ @@ -360,6 +362,22 @@ workflow { BWAMEM2_MEM(input_sample, bwa, fasta, fai) } + BWAMEM2_MEM.out.groupTuple(by:[0, 1]) + .branch { + single: it[2].size() == 1 + multiple: it[2].size() > 1 + }.set { bam } + bam.single.map { + idPatient, idSample, idRun, bam -> + [idPatient, idSample, bam] + } + + bam.single.view() + bam.multiple.view() + + //multipleBam = multipleBam.mix(multipleBamSentieon) + MERGE_BAM_MAPPED(bam.multiple) + OUTPUT_DOCUMENTATION( output_docs, output_docs_images) diff --git a/modules/local/merge_mapped_bam.nf b/modules/local/merge_mapped_bam.nf new file mode 100644 index 000000000..9bbf8fcea --- /dev/null +++ b/modules/local/merge_mapped_bam.nf @@ -0,0 +1,16 @@ +process MERGE_BAM_MAPPED { + label 'cpus' + + tag "${idPatient}-${idSample}" + + input: + tuple idPatient, idSample, idRun, path(bam), path(bai)// from multiple + + output: + tuple idPatient, idSample, path("${idSample}.bam") //into bam_mapped_merged + + script: + """ + samtools merge --threads ${task.cpus} ${idSample}.bam ${bam} + """ +} \ No newline at end of file