首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Snakemake:交换变量

Snakemake:交换变量
EN

Stack Overflow用户
提问于 2019-10-30 17:26:45
回答 1查看 117关注 0票数 2

我有一些基于MINIT的ONT测序运行。因此,当我使用guppy_barcoder解复用时,我会得到每个条形码的fastq文件目录。我想使用snakemake作为工作流管理器,通过我们的分析获取这些fastq文件,但这涉及到在某个时候将{条形码}替换为{sample}。

代码语言:javascript
复制
BARCODE=['barcode01', 'barcode02', 'barcode03', 'barcode04']
SAMPLE=['sample01', 'sample02', 'sample03', 'sample04']

rule all:
    input:
        directory(expand("Sequencing_reads/demultiplexed/{barcode}", barcode=BARCODE)), #guppy_barcoder
        expand("Sequencing_reads/gathered/{sample}_ONT.fastq", sample=SAMPLE), #getting all of the fastq files with the same barcode assigned to the correct sample


rule demultiplex:
    input:
        glob.glob("Sequencing_reads/fastq_pass/*fastq")
    output:
        directory(expand("Sequencing_reads/demultiplexed/{barcode}", barcode=BARCODE))
    shell:
        "guppy_barcoder --input_path Sequencing_reads/fastq_pass --save_path Sequencing_reads/demultiplexed -r "


rule gather:
    input:
        rules.demultiplex.output
    output:
        "Sequencing_reads/gathered/{sample}_ONT.fastq"
    shell:
        "cat Sequencing_reads/demultiplexed/{wildcards.barcode}/*fastq > {output.fastq} "

这确实给了我一个错误:

RuleException in line 32 of /home/eriny/sandbox/ONT_unicycler_pipeline/ONT_pipeline.smk: 'Wildcards' object has no attribute 'barcode'

但实际上我觉得我错过了一些概念上的东西。我希望rule gather是这样的:

代码语言:javascript
复制
cat Sequencing_reads/demultiplexed/barcode01/*fastq > Sequencing_reads/gathered/sample01_ONT.fastq

我尝试过设置一些字典,以便示例和条形码被赋予相同的键,但是我的语法必须被打破。

我希望找到一种1:1的方法将一个变量名映射到另一个变量名上。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-31 09:06:44

,我希望找到一种1:1的方式将一个变量名映射到另一个变量名上。

我认为样本到字典是一种可能性,结合一个lambda作为输入函数,以获得条形码分配给一个样本。例如:

代码语言:javascript
复制
BARCODE=['barcode01', 'barcode02', 'barcode03', 'barcode04']
SAMPLE=['sample01', 'sample02', 'sample03', 'sample04']

sam2bar= dict(zip(SAMPLE, BARCODE))

rule all:
    input:
        expand("Sequencing_reads/gathered/{sample}_ONT.fastq", sample=SAMPLE), #getting all of the fastq files with the same barcode assigned to the correct sample

rule demultiplex:
    input:
        glob.glob("Sequencing_reads/fastq_pass/*fastq"),
    output:
        done= touch('demux.done'), # This signals that guppy has completed
    shell:
        "guppy_barcoder --input_path Sequencing_reads/fastq_pass --save_path Sequencing_reads/demultiplexed -r "


rule gather:
    input:
        done= 'demux.done',
        fastq= lambda wc: glob.glob("Sequencing_reads/demultiplexed/%s/*fastq" % sam2bar[wc.sample])
    output:
        fastq= "Sequencing_reads/gathered/{sample}_ONT.fastq"
    shell:
        "cat {input.fastq} > {output.fastq} "
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58630773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档