将大型管道转换为蛇形管道



我开发了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读取它并保留";样品";信息遵循包含MG预处理和流水线组装的示例,其中preprocess.pyassembly.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"], experiment = read_table(config["experiments"], "t").iterrows()))[0]
output:
expand("{output}/Preprocess/Trimmomatic/quality_trimmed_{name}{fr}_paired.fq", 
fr = ['forward', 'reverse'], output = config["output"], 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", 
fr = ['forward', 'reverse'], output = config["output"], name = 'pretty_commune')
output:
expand("{output}/Assembly/{experiment[1][Sample]}/contigs.fasta", 
output = config["output"], experiment = read_table(config["experiments"], "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}", 
output = config["output"], 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是因为list(expand({experiment}[1]["MG files"]中的{experiment}不在可以用实际值替换的字符串中。


编辑:

事实上,expand('{experiment}', experiment= ss["MG files"][0]),这条线没有多大意义。。。与ss["MG files"][0]相同

最新更新