diff --git a/src/nf_modules/Bowtie/bowtie.config b/src/nf_modules/Bowtie/bowtie.config new file mode 100644 index 0000000000000000000000000000000000000000..93fe4a452b094540aee8d76597779e2dd09c4bbf --- /dev/null +++ b/src/nf_modules/Bowtie/bowtie.config @@ -0,0 +1,24 @@ +profiles { + docker { + docker.temp = 'auto' + docker.enabled = true + process { + $index_fasta { + container = "bowtie:1.2.2" + } + $mapping_fastq { + container = "bowtie:1.2.2" + } + } + } + sge { + process{ + $index_fasta { + beforeScript = "module purge; module load Bowtie/1.2.2" + } + $mapping_fastq { + beforeScript = "module purge; module load SAMtools/1.7; module load Bowtie/1.2.2" + } + } + } +} diff --git a/src/nf_modules/Bowtie/bowtie.nf b/src/nf_modules/Bowtie/bowtie.nf new file mode 100644 index 0000000000000000000000000000000000000000..21e329596d659ff46398bd3a5ab21556351c357c --- /dev/null +++ b/src/nf_modules/Bowtie/bowtie.nf @@ -0,0 +1,140 @@ +/* +* Bowtie : +* Imputs : fastq files +* Imputs : fasta files +* Output : bam files +*/ + +/* fasta indexing */ +params.fasta = "$baseDir/data/bam/*.fasta" + +log.info "fasta files : ${params.fasta}" + +Channel + .fromPath( params.fasta ) + .ifEmpty { error "Cannot find any bam files matching: ${params.fasta}" } + .set { fasta_file } + +process index_fasta { + tag "$fasta.baseName" + cpus 4 + publishDir "results/mapping/index/", mode: 'copy' + + input: + file fasta from fasta_file + + output: + file "*.index*" into index_files + + script: +""" +bowtie-build --threads ${task.cpus} -f ${fasta} ${fasta.baseName}.index &> ${fasta.baseName}_bowtie_report.txt + +if grep -q "Error" ${fasta.baseName}_bowtie_report.txt; then + exit 1 +fi +""" +} + + + +/* +* for paired-end data +*/ + +params.fastq = "$baseDir/data/fastq/*_{1,2}.fastq" +params.index = "$baseDir/data/index/*.index.*" + +log.info "fastq files : ${params.fastq}" +log.info "index files : ${params.index}" + +Channel + .fromFilePairs( params.fastq ) + .ifEmpty { error "Cannot find any fastq files matching: ${params.fastq}" } + .set { fastq_files } +Channel + .fromPath( params.index ) + .ifEmpty { error "Cannot find any index files matching: ${params.index}" } + .set { index_files } + +process mapping_fastq { + tag "$pair_id" + cpus 4 + publishDir "results/mapping/bams/", mode: 'copy' + + input: + set pair_id, file(reads) from fastq_files + file index from index_files.toList() + + output: + file "*.bam" into bam_files + + script: + index_id = index[0] + for (index_file in index) { + if (index_file =~ /.*\.1\.ebwt/) { + index_id = ( index_file =~ /(.*)\.1\.ebwt/)[0][1] + } + } +""" +# -v specify the max number of missmatch, -k the number of match reported per +# reads +bowtie --best -v 3 -k 1 --sam -p ${task.cpus} ${index_id} \ +-1 ${reads[0]} -2 ${reads[1]} 2> \ +${pair_id}_bowtie_report.txt | \ +samtools view -Sb - > ${pair_id}.bam + +if grep -q "Error" ${pair_id}_bowtie_report.txt; then + exit 1 +fi +""" +} + + +/* +* for single-end data +*/ +params.fastq = "$baseDir/data/fastq/*.fastq" + +log.info "fastq files : ${params.fastq}" +log.info "index files : ${params.index}" + +Channel + .fromPath( params.fastq ) + .ifEmpty { error "Cannot find any fastq files matching: ${params.fastq}" } + .set { fastq_files } +Channel + .fromPath( params.index ) + .ifEmpty { error "Cannot find any index files matching: ${params.index}" } + .set { index_files } + +process mapping_fastq { + tag "$reads.baseName" + cpus 4 + publishDir "results/mapping/bams/", mode: 'copy' + + input: + file reads from fastq_files + file index from index_files.toList() + + output: + file "*.bam" into bam_files + + script: +index_id = index[0] +for (index_file in index) { + if (index_file =~ /.*\.1\.ebwt/) { + index_id = ( index_file =~ /(.*)\.1\.ebwt/)[0][1] + } +} +""" +bowtie --best -v 3 -k 1 --sam -p ${task.cpus} ${index_id} \ +-U ${reads} 2> \ +${reads.baseName}_bowtie_report.txt | \ +samtools view -Sb - > ${reads.baseName}.bam + +if grep -q "Error" ${reads.baseName}_bowtie_report.txt; then + exit 1 +fi +""" +} diff --git a/src/nf_modules/Bowtie/tests/index.nf b/src/nf_modules/Bowtie/tests/index.nf new file mode 100644 index 0000000000000000000000000000000000000000..0b3ca58b227f49f3af6a69299ed882806f5e5cba --- /dev/null +++ b/src/nf_modules/Bowtie/tests/index.nf @@ -0,0 +1,30 @@ +params.fasta = "$baseDir/data/bam/*.fasta" + +log.info "fasta files : ${params.fasta}" + +Channel + .fromPath( params.fasta ) + .ifEmpty { error "Cannot find any bam files matching: ${params.fasta}" } + .set { fasta_file } + +process index_fasta { + tag "$fasta.baseName" + cpus 4 + publishDir "results/mapping/index/", mode: 'copy' + + input: + file fasta from fasta_file + + output: + file "*.index*" into index_files + + script: +""" +bowtie-build --threads ${task.cpus} -f ${fasta} ${fasta.baseName}.index &> ${fasta.baseName}_bowtie_report.txt + +if grep -q "Error" ${fasta.baseName}_bowtie_report.txt; then + exit 1 +fi +""" +} + diff --git a/src/nf_modules/Bowtie/tests/mapping_paired.nf b/src/nf_modules/Bowtie/tests/mapping_paired.nf new file mode 100644 index 0000000000000000000000000000000000000000..fdf9aee42a5a20e3cc86d864ac06ea581073ed1b --- /dev/null +++ b/src/nf_modules/Bowtie/tests/mapping_paired.nf @@ -0,0 +1,49 @@ +params.fastq = "$baseDir/data/fastq/*_{1,2}.fastq" +params.index = "$baseDir/data/index/*.index.*" + +log.info "fastq files : ${params.fastq}" +log.info "index files : ${params.index}" + +Channel + .fromFilePairs( params.fastq ) + .ifEmpty { error "Cannot find any fastq files matching: ${params.fastq}" } + .set { fastq_files } +Channel + .fromPath( params.index ) + .ifEmpty { error "Cannot find any index files matching: ${params.index}" } + .set { index_files } + +process mapping_fastq { + tag "$pair_id" + cpus 4 + publishDir "results/mapping/bams/", mode: 'copy' + + input: + set pair_id, file(reads) from fastq_files + file index from index_files.toList() + + output: + file "*.bam" into bam_files + + script: + index_id = index[0] + for (index_file in index) { + if (index_file =~ /.*\.1\.ebwt/) { + index_id = ( index_file =~ /(.*)\.1\.ebwt/)[0][1] + } + } +""" +# -v specify the max number of missmatch, -k the number of match reported per +# reads +bowtie --best -v 3 -k 1 --sam -p ${task.cpus} ${index_id} \ +-1 ${reads[0]} -2 ${reads[1]} 2> \ +${pair_id}_bowtie_report.txt | \ +samtools view -Sb - > ${pair_id}.bam + +if grep -q "Error" ${pair_id}_bowtie_report.txt; then + exit 1 +fi +""" +} + + diff --git a/src/nf_modules/Bowtie/tests/mapping_single.nf b/src/nf_modules/Bowtie/tests/mapping_single.nf new file mode 100644 index 0000000000000000000000000000000000000000..e8781267fd3f75b579ab9111d13a07779927c2a4 --- /dev/null +++ b/src/nf_modules/Bowtie/tests/mapping_single.nf @@ -0,0 +1,44 @@ +params.fastq = "$baseDir/data/fastq/*.fastq" + +log.info "fastq files : ${params.fastq}" +log.info "index files : ${params.index}" + +Channel + .fromPath( params.fastq ) + .ifEmpty { error "Cannot find any fastq files matching: ${params.fastq}" } + .set { fastq_files } +Channel + .fromPath( params.index ) + .ifEmpty { error "Cannot find any index files matching: ${params.index}" } + .set { index_files } + +process mapping_fastq { + tag "$reads.baseName" + cpus 4 + publishDir "results/mapping/bams/", mode: 'copy' + + input: + file reads from fastq_files + file index from index_files.toList() + + output: + file "*.bam" into bam_files + + script: +index_id = index[0] +for (index_file in index) { + if (index_file =~ /.*\.1\.ebwt/) { + index_id = ( index_file =~ /(.*)\.1\.ebwt/)[0][1] + } +} +""" +bowtie --best -v 3 -k 1 --sam -p ${task.cpus} ${index_id} \ +-U ${reads} 2> \ +${reads.baseName}_bowtie_report.txt | \ +samtools view -Sb - > ${reads.baseName}.bam + +if grep -q "Error" ${reads.baseName}_bowtie_report.txt; then + exit 1 +fi +""" +} diff --git a/src/nf_modules/Bowtie/tests/tests.sh b/src/nf_modules/Bowtie/tests/tests.sh new file mode 100755 index 0000000000000000000000000000000000000000..3b67514975afe3eb7006952bce81cee992487a32 --- /dev/null +++ b/src/nf_modules/Bowtie/tests/tests.sh @@ -0,0 +1,17 @@ +./nextflow src/nf_modules/Bowtie/tests/index.nf \ + -c src/nf_modules/Bowtie/bowtie.config \ + -profile docker \ + --fasta "data/tiny_dataset/fasta/tiny_v2.fasta" + +./nextflow src/nf_modules/Bowtie/tests/mapping_single.nf \ + -c src/nf_modules/Bowtie/bowtie.config \ + -profile docker \ + --index "results/mapping/index/*.ebwt" \ + --fastq "data/tiny_dataset/fastq/tiny*_S.fastq" + +./nextflow src/nf_modules/Bowtie/tests/mapping_paired.nf \ + -c src/nf_modules/Bowtie/bowtie.config \ + -profile docker \ + --index "results/mapping/index/*.ebwt" \ + --fastq "data/tiny_dataset/fastq/tiny*_R{1,2}.fastq" +