繁体   English   中英

Snakemake - 将附加参数传递给输入 function

[英]Snakemake - passing additional parameters to an input function

我正在尝试创建一个采用 TSV 表配置的 Snakemake 工作流程,如下所示:

sample    path
s1    /path/to/s1_dir
s2    /path/to/s2_dir

对于每个示例,我提供了一个目录,我使用工作流程中的各种路径。
我希望能够通过单个输入 function 获得各种输入。 我试过这个:

import pandas as pd

samples = pd.read_table('samples.tsv').set_index("sample", drop=False)

rule all:
    '...'

def get(wildcards, what):
    sample_dir = samples.loc[wildcards.sample, 'path']
    if what == 1:
        return sample_dir + '/sub/' + 'someInput'
    elif what == 2:
        return sample_dir + '/sub2/' + 'otherInput'

rule rule1:
    input:
        get(what=1)
    ...

rule rule2:
    input:
        get(what=2)
    ...

但是,这会导致错误消息,并且根据文档,输入函数可能只需要一个参数(通配符)。 我想一种解决方法是有多个输入函数:

def get1(wildcards):
    sample_dir = samples.loc[wildcards.sample, 'path']
    return sample_dir + '/sub/' + 'someInput'

def get2(wildcards):
    sample_dir = samples.loc[wildcards.sample, 'path']
    return sample_dir + '/sub2/' + 'otherInput'

但是如果我有 10 个不同的输入呢? 知道怎么做吗?
谢谢!

这就是我会做的。 将您的自定义get与 lambda function 组合起来:

def get(wildcards, what):
    # Do stuff with wildcards and what
    ...

rule one:
    input:
        lambda wc: get(wc, what= 1)

rule two:
    input:
        lambda wc: get(wc, what= 2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM