diff --git a/src/nf_modules/SAMtools/filter_bams.config b/src/nf_modules/SAMtools/filter_bams.config new file mode 100644 index 0000000000000000000000000000000000000000..066684006e4a04daef5caf26e45ba74878bb4ebf --- /dev/null +++ b/src/nf_modules/SAMtools/filter_bams.config @@ -0,0 +1,18 @@ +profiles { + docker { + docker.temp = 'auto' + docker.enabled = true + process { + $filter_bam { + container = "samtools:1.7" + } + } + } + sge { + process{ + $filter_bam { + beforeScript = "module purge; module load SAMtools/1.7" + } + } + } +} diff --git a/src/nf_modules/SAMtools/tests/filter_bams.nf b/src/nf_modules/SAMtools/filter_bams.nf similarity index 67% rename from src/nf_modules/SAMtools/tests/filter_bams.nf rename to src/nf_modules/SAMtools/filter_bams.nf index 49021362d7bc97c950042ab163a5224a2eb28d02..0812a19b227049fd05b54f46cbc30b246da73127 100644 --- a/src/nf_modules/SAMtools/tests/filter_bams.nf +++ b/src/nf_modules/SAMtools/filter_bams.nf @@ -7,6 +7,7 @@ log.info "bed file : ${params.bed}" Channel .fromPath( params.bam ) .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } + .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]} .set { bam_files } Channel .fromPath( params.bed ) @@ -14,18 +15,18 @@ Channel .set { bed_files } process filter_bam { - tag "$bam.baseName" + tag "$file_id" cpus 4 input: - file bam from bam_files + set file_id, file(bam) from bam_files file bed from bed_files output: - file "*_filtered.bam*" into filtered_bam_files + set file_id, "*_filtered.bam*" into filtered_bam_files script: """ -samtools view -@ ${task.cpus} -hb ${bam} -L ${bed} > ${bam.baseName}_filtered.bam +samtools view -@ ${task.cpus} -hb ${bam} -L ${bed} > ${file_id}_filtered.bam """ } diff --git a/src/nf_modules/SAMtools/index_bams.config b/src/nf_modules/SAMtools/index_bams.config new file mode 100644 index 0000000000000000000000000000000000000000..3b23601d9566ee96f034d14a798c6c8e08a6870f --- /dev/null +++ b/src/nf_modules/SAMtools/index_bams.config @@ -0,0 +1,18 @@ +profiles { + docker { + docker.temp = 'auto' + docker.enabled = true + process { + $index_bam { + container = "samtools:1.7" + } + } + } + sge { + process{ + $index_bam { + beforeScript = "module purge; module load SAMtools/1.7" + } + } + } +} diff --git a/src/nf_modules/SAMtools/tests/index_bams.nf b/src/nf_modules/SAMtools/index_bams.nf similarity index 63% rename from src/nf_modules/SAMtools/tests/index_bams.nf rename to src/nf_modules/SAMtools/index_bams.nf index bea5441c2c5946a705117c4422581c3e3eea6f02..489b0f4f71f39d1fdc5b7870547e9fd18a29f9af 100644 --- a/src/nf_modules/SAMtools/tests/index_bams.nf +++ b/src/nf_modules/SAMtools/index_bams.nf @@ -5,14 +5,18 @@ log.info "bams files : ${params.bam}" Channel .fromPath( params.bam ) .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } + .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]} .set { bam_files } process index_bam { - tag "$bam.baseName" + tag "$file_id" + input: - file bam from bam_files + set file_id, file(bam) from bam_files + output: - file "*bam*" into indexed_bam_file + set file_id, "*.bam*" into indexed_bam_file + script: """ samtools index ${bam} diff --git a/src/nf_modules/SAMtools/samtools.config b/src/nf_modules/SAMtools/samtools.config deleted file mode 100644 index 001a77ab24deaee43e39ed60e66f424e3020d0cc..0000000000000000000000000000000000000000 --- a/src/nf_modules/SAMtools/samtools.config +++ /dev/null @@ -1,36 +0,0 @@ -profiles { - docker { - docker.temp = 'auto' - docker.enabled = true - process { - $sort_bam { - container = "samtools:1.7" - } - $index_bam { - container = "samtools:1.7" - } - $split_bam { - container = "samtools:1.7" - } - $filter_bam { - container = "samtools:1.7" - } - } - } - sge { - process{ - $sort_bam { - beforeScript = "module purge; module load SAMtools/1.7" - } - $index_bam { - beforeScript = "module purge; module load SAMtools/1.7" - } - $split_bam { - beforeScript = "module purge; module load SAMtools/1.7" - } - $filter_bam { - beforeScript = "module purge; module load SAMtools/1.7" - } - } - } -} diff --git a/src/nf_modules/SAMtools/samtools.nf b/src/nf_modules/SAMtools/samtools.nf deleted file mode 100644 index f178bb0d706a4b656bf40beca25bf4cea69e9103..0000000000000000000000000000000000000000 --- a/src/nf_modules/SAMtools/samtools.nf +++ /dev/null @@ -1,117 +0,0 @@ -/* -* SAMtools : -* Imputs : bam files -* Output : bam files -*/ - -/* bams sorting */ -params.bam = "$baseDir/data/bam/*.bam" - -log.info "bams files : ${params.bam}" - -Channel - .fromPath( params.bam ) - .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } - .set { bam_files } - -process sort_bam { - tag "$bam.baseName" - cpus 4 - - input: - file bam from bam_files - - output: - file "*_sorted.bam" into sorted_bam_files - - script: -""" -samtools sort -@ ${task.cpus} -O BAM -o ${bam.baseName}_sorted.bam ${bam} -""" -} - -/* bams indexing */ - -params.bam = "$baseDir/data/bam/*.bam" - -log.info "bams files : ${params.bam}" - -Channel - .fromPath( params.bam ) - .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } - .set { bam_files } - -process index_bam { - tag "$bam.baseName" - input: - file bam from bam_files - output: - file "*bam*" into indexed_bam_file - script: -""" -samtools index ${bam} -""" -} - - -/* bams spliting */ -params.bam = "$baseDir/data/bam/*.bam" - -log.info "bams files : ${params.bam}" - -Channel - .fromPath( params.bam ) - .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } - .set { bam_files } - -process split_bam { - tag "$bam.baseName" - cpus 2 - - input: - file bam from bam_files - - output: - file "*_forward.bam*" into forward_bam_files - file "*_reverse.bam*" into reverse_bam_files - script: -""" -samtools view -hb -F 0x10 ${bam} > ${bam}_forward.bam & -samtools view -hb -f 0x10 ${bam} > ${bam}_reverse.bam -""" -} - - -/* bams filtering */ -params.bam = "$baseDir/data/bam/*.bam" -params.bed = "$baseDir/data/bam/*.bed" - -log.info "bams files : ${params.bam}" -log.info "bed file : ${params.bed}" - -Channel - .fromPath( params.bam ) - .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } - .set { bam_files } -Channel - .fromPath( params.bed ) - .ifEmpty { error "Cannot find any bed file matching: ${params.bed}" } - .set { bed_files } - -process filter_bam { - tag "$bam.baseName" - cpus 4 - - input: - file bam from bam_files - file bed from bed_files - - output: - file "*_filtered.bam*" into filtered_bam_files - script: -""" -samtools view -@ ${task.cpus} -hb ${bam} -L ${bed} > ${bam.baseName}_filtered.bam -""" -} - - diff --git a/src/nf_modules/SAMtools/sort_bams.config b/src/nf_modules/SAMtools/sort_bams.config new file mode 100644 index 0000000000000000000000000000000000000000..d1a8c503ace81d53fa5ff9cd382a435ac710e0cf --- /dev/null +++ b/src/nf_modules/SAMtools/sort_bams.config @@ -0,0 +1,18 @@ +profiles { + docker { + docker.temp = 'auto' + docker.enabled = true + process { + $sort_bam { + container = "samtools:1.7" + } + } + } + sge { + process{ + $sort_bam { + beforeScript = "module purge; module load SAMtools/1.7" + } + } + } +} diff --git a/src/nf_modules/SAMtools/tests/sort_bams.nf b/src/nf_modules/SAMtools/sort_bams.nf similarity index 53% rename from src/nf_modules/SAMtools/tests/sort_bams.nf rename to src/nf_modules/SAMtools/sort_bams.nf index 79a7590519616f3949aeadb651228666c172d0df..ab5c7e5140989b83eebd25f7b4dbb206520416b6 100644 --- a/src/nf_modules/SAMtools/tests/sort_bams.nf +++ b/src/nf_modules/SAMtools/sort_bams.nf @@ -5,21 +5,22 @@ log.info "bams files : ${params.bam}" Channel .fromPath( params.bam ) .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } + .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]} .set { bam_files } process sort_bam { - tag "$bams.baseName" + tag "$file_id" cpus 4 input: - file bam from bam_files + set file_id, file(bam) from bam_files output: - file "*_sorted.bam" into sorted_bam_files + set file_id, "*_sorted.bam" into sorted_bam_files script: """ -samtools sort -@ ${task.cpus} -O BAM -o ${bam.baseName}_sorted.bam ${bam} +samtools sort -@ ${task.cpus} -O BAM -o ${file_id}_sorted.bam ${bam} """ } diff --git a/src/nf_modules/SAMtools/split_bams.config b/src/nf_modules/SAMtools/split_bams.config new file mode 100644 index 0000000000000000000000000000000000000000..28b548efd5177e7457bd642b0c78198f2b48acd9 --- /dev/null +++ b/src/nf_modules/SAMtools/split_bams.config @@ -0,0 +1,18 @@ +profiles { + docker { + docker.temp = 'auto' + docker.enabled = true + process { + $split_bam { + container = "samtools:1.7" + } + } + } + sge { + process{ + $split_bam { + beforeScript = "module purge; module load SAMtools/1.7" + } + } + } +} diff --git a/src/nf_modules/SAMtools/split_bams.nf b/src/nf_modules/SAMtools/split_bams.nf new file mode 100644 index 0000000000000000000000000000000000000000..f8ba6a50c7d7aecfb7c9c7b0fff8d4436cf055a4 --- /dev/null +++ b/src/nf_modules/SAMtools/split_bams.nf @@ -0,0 +1,27 @@ +params.bam = "$baseDir/data/bam/*.bam" + +log.info "bams files : ${params.bam}" + +Channel + .fromPath( params.bam ) + .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } + .map { it -> [(it.baseName =~ /([^\.]*)/)[0][1], it]} + .set { bam_files } + +process split_bam { + tag "$file_id" + cpus 2 + + input: + set file_id, file(bam) from bam_files + + output: + set file_id, "*_forward.bam*" into forward_bam_files + set file_id, "*_reverse.bam*" into reverse_bam_files + script: +""" +samtools view -hb -F 0x10 ${bam} > ${file_id}_forward.bam & +samtools view -hb -f 0x10 ${bam} > ${file_id}_reverse.bam +""" +} + diff --git a/src/nf_modules/SAMtools/tests.sh b/src/nf_modules/SAMtools/tests.sh new file mode 100755 index 0000000000000000000000000000000000000000..99a7ff3251ee4b7fdc5ef9567c81d128843e28c7 --- /dev/null +++ b/src/nf_modules/SAMtools/tests.sh @@ -0,0 +1,20 @@ +nextflow src/nf_modules/SAMtools/sort_bams.nf \ + -c src/nf_modules/SAMtools/sort_bams.config \ + -profile docker \ + --bam "data/tiny_dataset/map/tiny_v2.bam" + +nextflow src/nf_modules/SAMtools/index_bams.nf \ + -c src/nf_modules/SAMtools/index_bams.config \ + -profile docker \ + --bam "data/tiny_dataset/map/tiny_v2.sort.bam" + +nextflow src/nf_modules/SAMtools/split_bams.nf \ + -c src/nf_modules/SAMtools/split_bams.config \ + -profile docker \ + --bam "data/tiny_dataset/map/tiny_v2.bam" + +nextflow src/nf_modules/SAMtools/filter_bams.nf \ + -c src/nf_modules/SAMtools/filter_bams.config \ + -profile docker \ + --bam "data/tiny_dataset/map/tiny_v2.bam" \ + --bed "data/tiny_dataset/OLD/2genes.bed" diff --git a/src/nf_modules/SAMtools/tests/split_bams.nf b/src/nf_modules/SAMtools/tests/split_bams.nf deleted file mode 100644 index edc20864de3c81dd4fc371d4455a62b53ed8a8f9..0000000000000000000000000000000000000000 --- a/src/nf_modules/SAMtools/tests/split_bams.nf +++ /dev/null @@ -1,26 +0,0 @@ -params.bam = "$baseDir/data/bam/*.bam" - -log.info "bams files : ${params.bam}" - -Channel - .fromPath( params.bam ) - .ifEmpty { error "Cannot find any bam files matching: ${params.bam}" } - .set { bam_files } - -process split_bam { - tag "$bam.baseName" - cpus 2 - - input: - file bam from bam_files - - output: - file "*_forward.bam*" into forward_bam_files - file "*_reverse.bam*" into reverse_bam_files - script: -""" -samtools view -hb -F 0x10 ${bam} > ${bam}_forward.bam & -samtools view -hb -f 0x10 ${bam} > ${bam}_reverse.bam -""" -} - diff --git a/src/nf_modules/SAMtools/tests/tests.sh b/src/nf_modules/SAMtools/tests/tests.sh deleted file mode 100755 index e3e809982cdf68959603f5496e49f02f2493afd6..0000000000000000000000000000000000000000 --- a/src/nf_modules/SAMtools/tests/tests.sh +++ /dev/null @@ -1,20 +0,0 @@ -nextflow src/nf_modules/SAMtools/tests/sort_bams.nf \ - -c src/nf_modules/SAMtools/samtools.config \ - -profile docker \ - --bam "data/tiny_dataset/map/tiny_v2.bam" - -nextflow src/nf_modules/SAMtools/tests/index_bams.nf \ - -c src/nf_modules/SAMtools/samtools.config \ - -profile docker \ - --bam "data/tiny_dataset/map/tiny_v2.sort.bam" - -nextflow src/nf_modules/SAMtools/tests/split_bams.nf \ - -c src/nf_modules/SAMtools/samtools.config \ - -profile docker \ - --bam "data/tiny_dataset/map/tiny_v2.bam" - -nextflow src/nf_modules/SAMtools/tests/filter_bams.nf \ - -c src/nf_modules/SAMtools/samtools.config \ - -profile docker \ - --bam "data/tiny_dataset/map/tiny_v2.bam" \ - --bed "data/tiny_dataset/OLD/2genes.bed"