[英]Parallelise output of input function in Snakemake
您好Snakemake社区,
我很难在Snakemake中正确定义一个函数并在params部分中调用它。 该函数的输出是一个列表,我的目标是将列表的每一项用作shell命令的参数。 换句话说,我想使用不同的参数与同一shell命令并行运行多个作业 。
这是功能:
import os, glob
def get_scontigs_names(wildcards):
scontigs = glob.glob(os.path.join("reference", "Supercontig*"))
files = [os.path.basename(s) for s in scontigs]
return name
输出是一个看起来像这样的列表:
['Supercontig0', 'Supercontig100', 'Supercontig2', ...]
Snakemake规则是:
rule all:
input:
"updated/all_supercontigs.sorted.vcf.gz"
rule update_vcf:
input:
len="genome/genome_contigs_len_cumsum.txt",
vcf="filtered/all.vcf.gz"
output:
cat="updated/all_supercontigs.updated.list"
params:
scaf=get_scontigs_names
shell:
"""
python 3.7 scripts/update_genomic_reg.py -len {input.len} -vcf {input.vcf} -scaf {params.scaf}
ls updated/*.updated.vcf.gz > {output.cat}
"""
此代码是错误的,因为当我调用{params.scaf}
时,列表中的所有项目都已加载到shell命令中。 当前的shell命令如下所示:
python 3.7 scripts/update_genomic_reg.py -len genome/genome_contigs_len_cumsum.txt -vcf filtered/all.vcf.gz -scaf Supercontig0 Supercontig100 Supercontig2 ...
我想得到的是:*
python 3.7 scripts/update_genomic_reg.py -len genome/genome_contigs_len_cumsum.txt -vcf filtered/all.vcf.gz -scaf Supercontig0
python 3.7 scripts/update_genomic_reg.py -len genome/genome_contigs_len_cumsum.txt -vcf filtered/all.vcf.gz -scaf Supercontig100
等等。
我试图在函数内部使用wildcards
,但是我没有赋予它正确的属性。
关于输入函数和通配符,还有snakemake文档,有几篇文章,但是我不能真正将它们应用于我的案例。 有人可以帮我吗?
那下面呢? 请注意,您的get_scontigs_names
不使用通配符。
import os, glob
def get_scontigs_names():
scontigs = glob.glob(os.path.join("reference", "Supercontig*"))
files = [os.path.basename(s) for s in scontigs]
name = [i.split('_')[0] for i in files]
return name
supercontigs= get_scontigs_names()
rule all:
input:
"updated/all_supercontigs.sorted.vcf.gz"
rule update_vcf:
input:
len="genome/genome_contigs_len_cumsum.txt",
vcf="filtered/all.vcf.gz",
output:
upd= "updated/{supercontig}.updated.vcf.gz",
shell:
r"""
python 3.7 scripts/update_genomic_reg.py -len {input.len} \
-vcf {input.vcf} -scaf {wildcards.supercontig}
"""
rule list_updated:
input:
expand("updated/{supercontig}.updated.vcf.gz", supercontig= supercontigs),
output:
"updated/all_supercontigs.sorted.vcf.gz",
shell:
r"""
ls {input} > {output}
"""
我已经找到了受@dariober启发的问题的解决方案。
rule all:
input:
"updated/all_supercontigs.updated.list"
import os, glob
def get_scontigs_names(wildcards):
scontigs = glob.glob(os.path.join("reference", "Supercontig*"))
files = [os.path.basename(s) for s in scontigs]
name = [i.split('_')[0] for i in files]
return name
rule update_vcf:
input:
len="genome/genome_contigs_len_cumsum.txt",
vcf="filtered/all.vcf.gz"
output:
vcf="updated/all_{supercontig}.updated.vcf.gz"
params:
py3=config["modules"]["py3"],
scaf=get_scontigs_names
shell:
"""
{params.py3} scripts/update_genomic_reg.py -len {input.len} -vcf
{input.vcf} -scaf {wildcards.supercontig}
"""
rule list_updated:
input:
expand("updated/all_{supercontig}.updated.vcf.gz", supercontig =
supercontigs)
output:
"updated/all_supercontigs.updated.list"
shell:
"""
ls {input} > {output}
"""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.