parameters - 如何确定要在工作流程中间展开的文件列表?
问题描述
在某些时候,我的 snakemake 工作流程会创建一个文件 ovlp.txt,我事先不知道它将包含多少行。然后我希望将此文件拆分为 25000 行的较小文件,这些文件都称为 ovlp_split{s}.txt。为此,我有规则拆分(见下文)。接下来,将使用规则 predict(见下文)处理每个文件,该规则将所有文件 ovlp_split{s}.txt 作为输入。最后,所有文件都在下面的规则 merge_predict 中一起处理。如您所见,我需要多次扩展所有拆分的输入或输出文件列表。但是,由于我不知道文件 ovlp.txt 的大小,直到它是由较早的规则创建的,所以我不知道会有多少拆分。我该如何解决这个问题?
我希望这足够清楚,如果有部分不是,请告诉我。
谢谢!
马琳
rule split:
input:
'ovlp.txt'
output:
expand('ovlp_split{s}.txt', s=splits)
run:
shell('split -l '+str(lines_per_file)+' -a 4 --numeric-suffixes=1 --additional-suffix=.txt ovlp.txt ovlp_split')
rule predict:
input:
'ovlp_split{s}.txt',
output:
'ovlp_predict_split{s}.txt',
run:
(command that processes the file)
rule merge_predict:
input:
expand('ovlp_predict_split{s}.txt', s=splits)
output:
'ovlp_merged.txt'
run:
(command that processed the separate files and creates one final output file)
解决方案
看来您需要使用检查点。也许沿着这些思路:
rule all:
input:
'ovlp_merged.txt',
checkpoint split:
input:
'ovlp.txt'
output:
splitd= directory('ovlp_split'),
shell:
r"""
mkdir {output.splitd}
split -l 3 -a 4 --numeric-suffixes=1 --additional-suffix=.txt ovlp.txt {output.splitd}/
"""
rule predict:
input:
'ovlp_split/{s}.txt',
output:
'ovlp_predict_split{s}.txt',
shell:
r"""
cp {input} {output}
"""
def aggregate_split(wildcards):
chkp_done = checkpoints.split.get().output.splitd
chkp_output = sorted(glob_wildcards(os.path.join(chkp_done, "{s}.txt")).s)
return expand('ovlp_predict_split{s}.txt', s= chkp_output)
rule merge_predict:
input:
aggregate_split,
output:
'ovlp_merged.txt'
shell:
r"""
cat {input} > {output}
"""
推荐阅读
- javascript - 如何在下一个上一个悬停时滑动 owl-carousel?
- node.js - 未捕获(承诺)类型错误:无法获取动态导入的模块:http://localhost:81/controllers/chatController
- sql - 使用实体框架的子查询
- java - SpringBoot:拦截器从请求中读取特定字段并将其设置在响应中
- angular - 如何实现带有角度子菜单的侧面导航?
- c# - 为从 GIT 克隆的项目添加新类和文件夹后,Visual Studio 和项目看不到新类/文件夹等
- php - 如何安装学说/mongodb-odm-bundle?
- matlab - 使用matlab绘图时如何使图例中的标记变小
- powershell - 在powershell中交换行与列
- django - 如何在django中删除所有用户并重置用户表的主键?