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

2024-09-29 21:30:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我开发了MOSCA,一个元组学分析管道(MG和MT),可通过Bioconda获得。我想把它转换成snakemake,因为它很容易让MOSCA通过API同时运行一些访问和一些计算要求很高的任务。此外,我认为这将有助于更好地将工具塑造成标准格式

我的问题是,MOSCA有很多参数,必须将这些参数传输到配置文件中。虽然这对于大多数参数来说是微不足道的,但同时输入MG和MT文件则更为棘手。此外,莫斯卡将样品放在一起考虑。所以我创建了一个示例文件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>

实验是如何定义的


Tags: tosamplepathnameconfiginputoutputfastq
1条回答
网友
1楼 · 发布于 2024-09-29 21:30:12

我不知道你想干什么,但请告诉我电话号码

list(expand({experiment}[1]["MG files"], experiment = read_table(config["experiments"], "\t").iterrows()))[0]

看起来太复杂了。我会将示例表放在一个数据框架中,并使用它,而不是每次都使用来自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]一样

相关问题 更多 >

    热门问题