python - 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 命令如下所示:
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
在函数内部使用,但我没有给它正确的属性。
有几篇关于输入函数和通配符以及蛇形文档的帖子,但我无法真正将它们应用到我的案例中。有人可以帮我解决这个问题吗?
解决方案
下面这个呢?请注意,您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}
"""
推荐阅读
- php - 卷曲错误:无法解析主机:www.localhost
- php - 使用 ajax 和 PhP 更新表的内容而不是完整的表
- c++ - 关于 reinterpret_cast 和指针
- javascript - 通过javascript将带有用户输入的HTML表格导出到CSV
- sql - 使用 Group BY 将多个 select 语句放入不同的列
- mysql - MySQL 批量加载
- ocr - 如何对属于 Google Cloud Vision API 中较大句子的一部分的块进行分组?
- hyperledger-fabric - sendPeersProposal - 承诺被拒绝:错误:未能在截止日期前连接
- sql - 最受每个公司员工欢迎的商店对
- javascript - ASP.Net MVC 资源上传到服务器后找不到错误