Snakemake在python函数的路径中使用通配符 [英] Snakemake use wildcards in path of python function

查看:80
本文介绍了Snakemake在python函数的路径中使用通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的函数,可以读取文件(一行)并在拆分后获取第一个元素.

I have a simple function that read a file (one line) and get the first element after split.

def get_wc(wc):
    file = open(wc,"r")
    normalization_value = file.readline().split(' ')[0]
    return(normalization_value)

我在蛇形规则中使用此函数.

I use this function in a rule snakemake.

rule compute_fc:
input:
    "data/annotated_clones/{cdna}_paste_{lib}.annotated.bed"
output:
    "data/fold_change/{cdna}_paste_{lib}.fc.bed"
params:
    size_cdna=get_wc("data/wc_bed/cdna/{cdna}.wc.txt"),
    size_lib=get_wc("data/wc_bed/library/{lib}.wc.txt")
shell:'''
    awk -v cdna1={params.size_cdna} -v inp={params.size_lib} -v addon=1 -v FS='\t' -v OFS='\t' '/^chr/{{ratio=(($7+addon)/($8+addon))*(inp/cdna1);print $0,ratio}}' {input} > {output}
'''

我正在尝试获取 get_wc 函数返回的值并将其用作蛇形规则中的参数.

I'm trying to get the value that get_wc function return and use it as params in snakemake rule.

但是 Snakemake 没有获取带有通配符的路径,因此它尝试获取带有通配符的路径,显然它不起作用.

But Snakemake don't get the path with the wildcards so it try to get the path with the wildcards and obviously it don't works.

[Errno 2] No such file or directory: 'data/wc_bed/cdna/{cdna}.wc.txt'

推荐答案

我认为像这样使用 lambda 函数应该可以:

I think using a lambda function, like this, should work:

params:
    size_cdna = lambda wildcards: get_wc(f"data/wc_bed/cdna/{wildcards.cdna}.wc.txt")
    size_lib = lambda wildcards: get_wc(f"data/wc_bed/library/{wildcards.lib}.wc.txt")

看看这里 用于文档.

这篇关于Snakemake在python函数的路径中使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆