diff --git a/src/nf_modules/SAMtools/samtools.config b/src/nf_modules/SAMtools/samtools.config new file mode 100644 index 0000000000000000000000000000000000000000..0a4bdde404b9ff8d82418f93375b0d1b4f953c72 --- /dev/null +++ b/src/nf_modules/SAMtools/samtools.config @@ -0,0 +1,34 @@ +profiles { + docker { + 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{ + $trimming { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..f178bb0d706a4b656bf40beca25bf4cea69e9103 --- /dev/null +++ b/src/nf_modules/SAMtools/samtools.nf @@ -0,0 +1,117 @@ +/* +* 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/tests/filter_bams.nf b/src/nf_modules/SAMtools/tests/filter_bams.nf new file mode 100644 index 0000000000000000000000000000000000000000..49021362d7bc97c950042ab163a5224a2eb28d02 --- /dev/null +++ b/src/nf_modules/SAMtools/tests/filter_bams.nf @@ -0,0 +1,32 @@ +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/tests/index_bams.nf b/src/nf_modules/SAMtools/tests/index_bams.nf new file mode 100644 index 0000000000000000000000000000000000000000..bea5441c2c5946a705117c4422581c3e3eea6f02 --- /dev/null +++ b/src/nf_modules/SAMtools/tests/index_bams.nf @@ -0,0 +1,21 @@ +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} +""" +} + diff --git a/src/nf_modules/SAMtools/tests/sort_bams.nf b/src/nf_modules/SAMtools/tests/sort_bams.nf new file mode 100644 index 0000000000000000000000000000000000000000..79a7590519616f3949aeadb651228666c172d0df --- /dev/null +++ b/src/nf_modules/SAMtools/tests/sort_bams.nf @@ -0,0 +1,25 @@ +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 "$bams.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} +""" +} + diff --git a/src/nf_modules/SAMtools/tests/split_bams.nf b/src/nf_modules/SAMtools/tests/split_bams.nf new file mode 100644 index 0000000000000000000000000000000000000000..edc20864de3c81dd4fc371d4455a62b53ed8a8f9 --- /dev/null +++ b/src/nf_modules/SAMtools/tests/split_bams.nf @@ -0,0 +1,26 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..e3e809982cdf68959603f5496e49f02f2493afd6 --- /dev/null +++ b/src/nf_modules/SAMtools/tests/tests.sh @@ -0,0 +1,20 @@ +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"