如何解决将大型管道转换为snakemake
我开发了MOSCA,这是一种用于元组学分析的管道(MG与MT),可通过Bioconda获得。我想将其转换为snakemake,因为它可以轻松地使MOSCA同时运行通过API进行的某些访问和一些计算量大的任务。另外,我认为这将有助于更好地将工具塑造为标准格式。
我的问题是,MOSCA有很多参数,必须将这些参数传输到配置文件中。尽管这对于大多数参数来说都是微不足道的,但同时输入MG和MT文件却比较麻烦。此外,MOSCA会一起考虑样本。所以我创建了一个示例文件samples.tsv
MG files MT files Sample
path/to/mg_R1.fastq,path/to/mg_R2.fastq path/to/mt_R1.fastq,path/to/mt_R2.fastq Sample
,我希望Snakefile读取它并保留“ Sample”信息。遵循包含MG预处理和管道装配的示例,其中preprocess.py
和assembly.py
脚本包含相应的功能。
这是Snakefile
from pandas import read_table
configfile: "config.json"
rule all:
input:
expand("{output}/Assembly/{experiment[1][Sample]}/contigs.fasta",output = config["output"],experiment = read_table(config["experiments"],"\t").iterrows())
rule mg_preprocess: # mt_preprocess make same,but data = mrna?
input:
list(expand({experiment}[1]["MG files"],"\t").iterrows()))[0]
output:
expand("{output}/Preprocess/Trimmomatic/quality_trimmed_{name}{fr}_paired.fq",fr = ['forward','reverse'],name = 'pretty_commune')
threads:
config["threads"]
run:
shell("""python preprocess.py -i {reads} -t {threads} -o {output}
-adaptdir MOSCA/Databases/illumina_adapters -rrnadbs MOSCA/Databases/rRNA_databases""",output = config["output"])
rule assembly:
input:
expand("{output}/Preprocess/Trimmomatic/quality_trimmed_{name}{fr}_paired.fq",name = 'pretty_commune')
output:
expand("{output}/Assembly/{experiment[1][Sample]}/contigs.fasta","\t").iterrows())
threads:
config["threads"]
run:
reads = ",".join(map(str,input))
shell("python assembly.py -r {input} -t {threads} -o {output}/Assembly/{sample} -a {assembler}",sample = config["experiments"][1]["sample"],assembler = config["assembler"])
这是config.json
{
"output":
"snakemake_learn","threads":
14,"experiments":
"samples.tsv","assembler":
"metaspades"
}
我得到了错误
NameError in line 12 of /path/to/Snakefile:
name 'experiment' is not defined
File "/path/to/Snakefile",line 12,in <module>
如何定义实验?
解决方法
我不确定您要做什么,但是对我来说还是行
list(expand({experiment}[1]["MG files"],experiment = read_table(config["experiments"],"\t").iterrows()))[0]
似乎太复杂了。我将样本表放在DataFrame中并使用它,而不是每次都使用read_table
中的迭代器。例如:
import pandas
ss = pandas.read_csv(config["experiments"],sep= '\t')
...
rule mg_preprocess: # mt_preprocess make same,but data = mrna?
input:
expand('{experiment}',experiment= ss["MG files"][0]),
无论如何,我认为错误name 'experiment' is not defined
是因为{experiment}
中的list(expand({experiment}[1]["MG files"]
不在可以替换为实际值的字符串中。
编辑:
实际上,行expand('{experiment}',
没有多大意义……与ss["MG files"][0]
相同
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。