Snakemake Python包装器中未找到通配符。

huangapple go评论67阅读模式
英文:

Snakemake wildcards from python wrapper not found

问题

It appears that you have a variable naming issue in your code. The error "name 'taxon' is not defined" suggests that the variable 'taxon' is not recognized within the scope of your Snakefile.

Make sure that you properly pass the 'taxon' variable to your Snakefile when you call Snakemake. Double-check the variable names and ensure they match between your Python wrapper file and your Snakefile.

Additionally, there's a typo in your Python code where you have used 'SNPwoAssembly≈.smk' instead of 'SNPwoAssembly.smk'. Make sure to correct this typo as well.

英文:

I am new to using snakemake and I am having difficulty. I have written a python wrapper file to run make snakefile. The wrapper takes a samples.txt with taxon, read1, read2, adapters, and assembly (Y/N). If assembly is needed, the snakefile with assembly is run, if N, a snakefile without assembly is run. It seems like the correct snakefile is being run, but the information for the wildcards isn't being transferred from the wrapper to the snakefile.

samples.txt

Solatube DRR350770_1.fastq.gz DRR350770_2.fastq.gz all.fa Y

run_pipeline.py

import argparse
import os

parser = argparse.ArgumentParser(description="Run Snakemake pipeline with Trinity assemble or not")
parser.add_argument("samples", help="path to samples.txt")
args = parser.parse_args()

with open(args.samples) as f:
    for line in f:
        taxon, read1, read2, adapters, assembly = [x.strip() for x in line.split()]
        if assembly == "Y":
            os.system(f"snakemake -s SNPwAssembly.smk --cores 16 --config taxon={taxon} read1={read1} read2={read2} adapters={adapters}")
        elif assembly == "N":
            os.system(f"snakemake -s SNPwoAssembly≈.smk --cores 16 --config taxon={taxon} read1={read1} read2={read2} adapters={adapters}")
        else:
            print(f"Invalid value for assembly in line: {line}")

SNPwAssembly.smk begins:

import os

# define rules                                                                                                                                                                                  
rule all:                                                                                                                                                                                               
    input: expand("{taxon}.snpden", taxon = taxon)                                                                                                                                                         
                                                                                                                                                                                                        
rule trinity_assembly:                                                                                                                                                                                  

input:                                                                                                                                                                                              
    read1 = "{taxon}/{read1}",                                                                                                                                                                      
    read2 = "{taxon}/{read2}",                                                                                                                                                                      
    adapters = "{adapters}"                                                                                                                                                                         
output:                                                                                                                                                                                             
    "{taxon}/trinity_out_dir/Trinity.fasta"                                                                                                                                                         
threads: 15                                                                                                                                                                                         
shell:                                                                                                                                                                                              
    '''                                                                                                                                                                                             
    singularity exec -e {trinity_path} Trinity --seqType fq --max_memory 450G --left SRR12102895_1.fastq.gz --right SRR12102895_2.fastq.gz --CPU 15 --trimmomatic --quality_trimming_params "all.fa:2:30:10 SLIDINGWINDOW:4:5 LEADING:5 TRAILING:5 MINLEN:25" --output trinity_out_dir                                                                                                                                                                                         
    '''     

when I run python3 run_pipeline.py samples.txt, I get the error:

name 'taxon' is not defined

答案1

得分: 1

Here is the translated content you provided:

最小示例:

对于sample.txt,我将提供sample而不是reads

Solatube DRR350770 all.fa Y

run_pipeline.py

import argparse
import os

parser = argparse.ArgumentParser(description="运行 Snakemake 管道是否装配 Trinity")
parser.add_argument("samples", help="样本.txt 的路径")
args = parser.parse_args()

with open(args.samples) as f:
    for line in f:
        taxon, sample, adapters, assembly = [x.strip() for x in line.split()]
        if assembly == "Y":
            os.system(f"snakemake -s SNPwAssembly.smk --cores 16 --config taxon={taxon} sample={sample} adapters={adapters}")

对于您的 SNPwAssembly.smk 文件:

TAXON = config['taxon']
SAMPLES = config['sample']
ADAPTERS = config['adapters']

print(TAXON)
print(SAMPLES)
print(ADAPTERS)

rule all:
    input:
        expand("{taxon}/{sample}_trinity/Trinity.fastq", taxon=TAXON, sample=SAMPLES)

rule test:
    input:
        read1 = "{taxon}/{sample}_1.fastq.gz",
        read2 = "{taxon}/{sample}_2.fastq.gz", 
    output:
        "{taxon}/{sample}_trinity/Trinity.fastq"
    params:
        adaptor = config['adapters']
    threads: 1
    shell:
        """
        echo {input.read1} {input.read2} {params} {threads} > {output}
        """
英文:

Minimum example:

For sample.txt, I would provide sample instead of reads.

Solatube DRR350770 all.fa Y

run_pipeline.py

import argparse
import os

parser = argparse.ArgumentParser(description="Run Snakemake pipeline with Trinity assemble or not")
parser.add_argument("samples", help="path to samples.txt")
args = parser.parse_args()

with open(args.samples) as f:
    for line in f:
        taxon, sample, adapters, assembly = [x.strip() for x in line.split()]
        if assembly == "Y":
            os.system(f"snakemake -s SNPwAssembly.smk --cores 16 --config taxon={taxon} sample={sample} adapters={adapters}")

For your SNPwAssembly.smk file:

TAXON = config['taxon']
SAMPLES = config['sample']
ADAPTERS = config['adapters']


print (TAXON)
print (SAMPLES)
print (ADAPTERS)

rule all:
    input:
        expand("{taxon}/{sample}_trinity/Trinity.fastq", taxon = TAXON, sample = SAMPLES)


rule test:
    input:
        read1 = "{taxon}/{sample}_1.fastq.gz",
        read2 = "{taxon}/{sample}_2.fastq.gz", 
    output:
        "{taxon}/{sample}_trinity/Trinity.fastq"
    params:
        adaptor = config['adapters']
    threads: 1
    shell:                                                                                                    
        """
        echo {input.read1} {input.read2} {params} {threads} > {output}
        """                                                   

huangapple
  • 本文由 发表于 2023年4月20日 05:18:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058889.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定