admin管理员组文章数量:1316844
process extract_key_species {
input:
tuple val(sample_ID), path(fastq1), path(fastq2), path(kaiju_out), val(tax_ids)
output:
tuple val(sample_ID), file("*_R1.fastq.gz"), file("*_R2.fastq.gz")
script:
"""
echo "${tax_ids}" | tr ',' '\\n' > "${sample_ID}_tax_ids.list"
# Debugging to confirm the list was created
echo "Created tax ID list:"
cat "${sample_ID}_tax_ids.list"
while IFS= read -r tax_id; do
echo "Processing tax_id: ${tax_id}"
grep -Ew "${tax_id}" "${kaiju_out}" | cut -f2 > "${sample_ID}_${tax_id}_ids.tsv"
seqtk subseq "${fastq1}" "${sample_ID}_${tax_id}_ids.tsv" | gzip -c > "${sample_ID}_${tax_id}_R1.fastq.gz"
seqtk subseq "${fastq2}" "${sample_ID}_${tax_id}_ids.tsv" | gzip -c > "${sample_ID}_${tax_id}_R2.fastq.gz"
echo "Generated FASTQ files for tax_id: ${tax_id}"
done < "${sample_ID}_tax_ids.list"
"""
}
workflow Assemble {
assemble_input = Channel.fromPath(params.tsv)
.splitCsv(sep: "\t", header: true, strip: true)
.map { it -> [it['sample_id'], it['fastq_r1'], it['fastq_r2'], it['kaiju_out'], it['tax_ids']] }
extract_key_species_in_out = extract_key_species(assemble_input)
extract_key_species_in_out.view()
}
Here I am not able to perform while loop as it is giving the below error:
ERROR ~ Error executing process > 'Assemble:extract_key_species (sample1)'
Caused by:
No such variable: tax_id -- Check script 'mainpython1.nf' at line: 15
process extract_key_species {
input:
tuple val(sample_ID), path(fastq1), path(fastq2), path(kaiju_out), val(tax_ids)
output:
tuple val(sample_ID), file("*_R1.fastq.gz"), file("*_R2.fastq.gz")
script:
"""
echo "${tax_ids}" | tr ',' '\\n' > "${sample_ID}_tax_ids.list"
# Debugging to confirm the list was created
echo "Created tax ID list:"
cat "${sample_ID}_tax_ids.list"
while IFS= read -r tax_id; do
echo "Processing tax_id: ${tax_id}"
grep -Ew "${tax_id}" "${kaiju_out}" | cut -f2 > "${sample_ID}_${tax_id}_ids.tsv"
seqtk subseq "${fastq1}" "${sample_ID}_${tax_id}_ids.tsv" | gzip -c > "${sample_ID}_${tax_id}_R1.fastq.gz"
seqtk subseq "${fastq2}" "${sample_ID}_${tax_id}_ids.tsv" | gzip -c > "${sample_ID}_${tax_id}_R2.fastq.gz"
echo "Generated FASTQ files for tax_id: ${tax_id}"
done < "${sample_ID}_tax_ids.list"
"""
}
workflow Assemble {
assemble_input = Channel.fromPath(params.tsv)
.splitCsv(sep: "\t", header: true, strip: true)
.map { it -> [it['sample_id'], it['fastq_r1'], it['fastq_r2'], it['kaiju_out'], it['tax_ids']] }
extract_key_species_in_out = extract_key_species(assemble_input)
extract_key_species_in_out.view()
}
Here I am not able to perform while loop as it is giving the below error:
ERROR ~ Error executing process > 'Assemble:extract_key_species (sample1)'
Caused by:
No such variable: tax_id -- Check script 'mainpython1.nf' at line: 15
Share
Improve this question
edited Jan 28 at 6:30
Steve
54.6k13 gold badges93 silver badges105 bronze badges
asked Jan 28 at 5:43
C0DiFireC0DiFire
111 bronze badge
1 Answer
Reset to default 0Caused by: No such variable: tax_id -- Check script 'mainpython1.nf' at line: 15
Nextflow uses the same Bash syntax for variable substitutions. Here, the tax_id variable is being evaluated as a Nextflow variable. For it to correctly be evaluated as a Bash variable, it must be escaped with \$
. Please try the following instead:
while IFS= read -r tax_id; do
echo "Processing tax_id: \${tax_id}"
grep -Ew "\${tax_id}" "${kaiju_out}" | cut -f2 > "${sample_ID}_\${tax_id}_ids.tsv"
seqtk subseq "${fastq1}" "${sample_ID}_\${tax_id}_ids.tsv" |
gzip -c > "${sample_ID}_\${tax_id}_R1.fastq.gz"
seqtk subseq "${fastq2}" "${sample_ID}_\${tax_id}_ids.tsv" |
gzip -c > "${sample_ID}_\${tax_id}_R2.fastq.gz"
echo "Generated FASTQ files for tax_id: \${tax_id}"
done < "${sample_ID}_tax_ids.list"
本文标签: bashNextflow while loop to acces taxids at onsStack Overflow
版权声明:本文标题:bash - Nextflow while loop to acces taxids at ons - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742012770a2413201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论