this is my code: #!/usr/bin/env nextflow nextflow.enable.dsl=2 process INDEX { input:…
- User
this is my code:
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
process INDEX { input: file(fasta)
output: path(bwa) script: def prefix = task.ext.prefix ?: "${fasta.baseName}" def args = task.ext.args ?: '' """ mkdir bwa bwa \\ index \\ $args \\ -p bwa/${prefix} \\ $fasta """}
process DEDUP {
debug true cpus 10 input: path(idx) tuple val(sample), file(reads) output: tuple val(sample), path("${sample}.dedup.bam"), emit: dedup_bam script: """ echo ${sample} INDEX=`find -L ./ -name "*.amb" | sed 's/\\.amb\$//'` bwa mem \$INDEX ${reads} -t ${task.cpus} | \\ samtools view -b | samtools sort --threads 5 -o ${sample}.bam \\ && picard MarkDuplicates -I ${sample}.bam -O ${sample}.dedup.bam \\ -M metrics.txt --REMOVE_DUPLICATES true && \\ samtools index ${sample}.dedup.bam rm ${sample}.bam """}
process CONSENSUS { publishDir "{sample}", mode: 'copy' debug true
input: path(genelist) path(db) tuple val(sample), path(bam) path fasta val out output: path(sample) script: """ mkdir ${out}/${sample} mkdir ${sample} for gene in \$(cat ${genelist}); do COORDS=\$(awk -F'\t' '{print \$5}' <(grep -w "\$gene" ${db})) samtools view -b ${bam} \$COORDS | \\ samtools sort -o \$gene.bam && \\ samtools index \$gene.bam && \\ bcftools mpileup -Ou -f ${fasta} \$gene.bam > \$gene.bcf bcftools call --ploidy 1 -m \$gene.bcf -Oz -o \$gene.vcf.gz && \\ tabix \$gene.vcf.gz && \\ samtools faidx ${fasta} \$COORDS | \\ bcftools consensus \$gene.vcf.gz > ${sample}/\$gene.fa rm \$gene.bam \$gene.bam.bai \$gene.bcf \$gene.vcf.gz \$gene.vcf.gz.tbi done """}
workflow { fasta = Channel.fromPath(params.fasta) fastqs = Channel.fromFilePairs("${params.dir}/_{1,2}.fastq.gz") genelist = Channel.fromPath(params.genelist) db = Channel.fromPath(params.db) out = file(params.out) out.mkdir()
idx = INDEX(fasta) bam = DEDUP(idx, fastqs) // CONSENSUS(genelist, db, bam, fasta, out)}
and this is my ./samples dir:
ls -lh ../samples/
total 1.7G -rw-r--r--. 1 alejandro alejandro 138M Dec 2 23:47 SRR6170145_1.fastq.gz -rw-r--r--. 1 alejandro alejandro 149M Dec 2 23:48 SRR6170145_2.fastq.gz -rw-r--r--. 1 alejandro alejandro 141M Dec 4 00:09 SRR6170205_1.fastq.gz -rw-r--r--. 1 alejandro alejandro 131M Dec 4 00:10 SRR6170205_2.fastq.gz -rw-r--r--. 1 alejandro alejandro 261M Dec 4 00:04 SRR6170260_1.fastq.gz -rw-r--r--. 1 alejandro alejandro 277M Dec 4 00:06 SRR6170260_2.fastq.gz -rw-r--r--. 1 alejandro alejandro 139M Dec 4 00:15 SRR6170338_1.fastq.gz -rw-r--r--. 1 alejandro alejandro 147M Dec 4 00:16 SRR6170338_2.fastq.gz -rw-r--r--. 1 alejandro alejandro 142M Dec 4 00:17 SRR6170513_1.fastq.gz -rw-r--r--. 1 alejandro alejandro 151M Dec 4 00:21 SRR6170513_2.fastq.gzwhy the workflow is running just for 1 sample???
nextflow run main.nf --fasta ../ref_genome/GCF_000017985.1_ASM1798v1_genomic.fna --genelist ../supp/genes.txt --db ../supp/REL606_ESSENTIAL_DB.txt --dir ../samples --out ./consensus (base) ✔ 00:36:48 N E X T F L O W ~ version 23.10.0 Launching
main.nf[voluminous_descartes] DSL2 - revision: c24dd9d1cb executor > local (2) [f1/3f0b5a] process > INDEX (1) [100%] 1 of 1 ✔ [6a/22b3ca] process > DEDUP (1) [100%] 1 of 1 ✔ SRR6170145Completed at: 04-Dec-2023 00:38:33 Duration : 1m 37s CPU hours : 0.3 Succeeded : 2
- Assistant
In your workflow, you are using
Channel.fromFilePairs(...)to create pairs from files matching the given glob pattern. By default, Nextflow will group files into pairs based on the basename of the files (everything before the first underscore,_, is considered the basename).Here is the relevant part of your code:
fastqs = Channel.fromFilePairs("${params.dir}/*_{1,2}.fastq*.gz")Your files are named like this:
SRR6170145_1.fastq.gz SRR6170145_2.fastq.gz SRR6170205_1.fastq.gz SRR6170205_2.fastq.gz ...The pattern you used (
*_{1,2}.fastq*.gz) correctly matches these filenames. TheChannel.fromFilePairsshould group them into pairs based on the common prefix before the underscore, e.g.SRR6170145,SRR6170205, etc.Given this, the workflow shouldn't be running for just 1 sample, it should be running for all paired samples. If it's only running for one sample, double-check the following:
- Ensure that all sample files are accessible and readable by Nextflow.
- Check if the input fastq files are properly named and if there are no issues with the files or naming that might prevent Nextflow from recognizing them as pairs.
- Make sure there are no additional or stray input files in the
../samplesdirectory that might be causing Nextflow to misinterpret the file pairs.
If everything looks fine and the problem still persists, you can add debugging statements to help identify the issue. For example, log the file pairs as they are recognized by Nextflow:
fastqs.println()Additionally, you commented out the
CONSENSUSprocess call at the end of the workflow. If you enable that line of code again, it might help to diagnose the issue:// CONSENSUS(genelist, db, bam, fasta, out)If the
DEDUPprocess yields the expected samples deduplicated BAM files, the CONSENSUS process should run for each one of them if everything is correct in the setup.Lastly, make sure to pass the correct directory path to the
--diroption when executing the workflow and ensure that the path delimiter (/) is properly used according to the file system in use.