Snakemake: How to save and access sample details in config.yml file?

佐手、 提交于 2019-12-01 11:24:35

I would suggest using a tab-delimited file in order to store samples information.

sample.tab:

Sample     Tag      
1          S1   
2          S2

You could store the path to this file in the config file, and read it in your Snakefile.

config.yaml:

sample_file: "sample.tab"

Snakefile:

configfile: "config.yaml"

sample_file = config["sample_file"]

samples = read_table(sample_file)['Sample']
tags    = read_table(sample_file)['Tag']

This way your can re-use your workflow for any number of samples, with any number of columns.

Apart from that, in Snakemake usually you can escape curly brackets by doubling them, maybe you could try that.

Good luck!

In the params section, you need to provide a function of wildcards. The following modification of your workflow seems to work:

configfile: "config.yaml"

rule final: 
    input: expand("{sample}.txt", sample=config["samples"])

rule rule1:
    output:
        "{sample}.txt"
    params:
        tag = lambda wildcards: config[wildcards.sample]["tag"]
    shell:
        """
        touch {output}
        echo {params.tag} > {output}
        """
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!