我试图在nextflow中创建一个进程,它需要2个输入,krakenfile
将直接使用,fungalname
包含多行,每行包含一个物种的名称。
我想在fungalname
文件中进行一次迭代,逐行读取,对于每一行/种类,我将查找krakenfile
中第3列包含该名称的所有行。
例如,如果我的fungalname
包含以下内容:
Aspergillus fumigatus
Candida albicans
字符串
而krakenfile
包含
xxxx 548 Aspergillus fumigatus
zzzz 566 Candida albicans
aaaa 598 Aspergillus fumigatus
kkk 888 Candida albicans
型
我的输出应该是2个文件,ASpergillus_fumigatus_lines.txt
和Candida_albicans_lines.txt
,每个文件都包含2行(如上例)
问题是,我的输出文件总是空的,虽然我肯定的格式,我的输入文件的本地化,我认为这是一个过程的问题,任何人都可以请帮助我,这是我的代码:
params.fungaalnames="/home/aziz/pipeline/results/extraction/fungal_species.txt"
params.krakeenfile="/home/aziz/pipeline/results/classification_before_filtration/output.kraken"
fungalnames = file(params.fungaalnames)
krakenfile = file(params.krakeenfile)
process fungal_reads_extraction {
input:
file fungalnames
file krakenfile
output:
path "*" , emit: reads_extracted_out
script:
"""
while IFS= read -r species_name; do
awk -F'\t' '\$3 ~ "'\$species_name'" {print}' $krakenfile > "\${species_name}_lines.txt"
done < $fungalnames
"""
}
workflow {
fungalnames_ch=Channel.fromPath(params.fungaalnames)
krakenfile_ch=Channel.fromPath(params.krakeenfile)
fungal_reads_extraction(fungalnames_ch, krakenfile_ch) | view
}
型
1条答案
按热度按时间uxh89sit1#
只关注
awk
脚本;我将把它留给OP来根据需要进行(重新)格式化,以便包含在nextflow
脚本文件中...一种
awk
方法:字符串
注意事项:
while/read/awk
循环awk
可能会抱怨打开的文件描述符太多;取消对close(fname[$3])
命令的注解可以缓解这个问题,但会导致脚本运行速度变慢这产生:
型
如果物种的数量“太大”,需要过多的
close()
调用,我们可以预排序krakenfile
;减少close()
调用的数量可以提高性能:型
这产生:
型
注意事项:
*_lines.txt
文件中的行的顺序基于从krakenfile
读取的行的顺序*_lines.txt
内容需要按其他列排序,OP可以包含更多的-k#,#
参数