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

后端 未结 2 1328
忘掉有多难
忘掉有多难 2021-01-06 16:34

Can anybody help me understand if it is possible to access sample details from a config.yml file when the sample names are not written in the snakemake workflow? This is so

相关标签:
2条回答
  • 2021-01-06 16:54

    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}
            """
    
    0 讨论(0)
  • 2021-01-06 17:02

    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!

    0 讨论(0)
提交回复
热议问题