![](/img/trans.png)
[英]snakemake Wildcards in input files cannot be determined from output files:
[英]Snakemake wildcards: Using wildcarded files from directory output
我是 Snakemake 的新手,並嘗試在規則中使用特定文件,來自另一個規則的directory()
output 克隆 git 回購。
目前,這給我一個錯誤Wildcards in input files cannot be determined from output files: 'json_file'
,我不明白為什么。 我之前已經完成了https://carpentries-incubator.github.io/workflows-snakemake/index.html的教程。
我的工作流程和教程工作流程之間的區別在於,我想創建稍后在第一步中使用的數據,而在教程中,數據已經存在。
純文本工作流程描述:
GIT_PATH = config['git_local_path'] # git/
PARSED_JSON_PATH = f'{GIT_PATH}parsed/'
GIT_URL = config['git_url']
# A single parsed JSON file
PARSED_JSON_FILE = f'{PARSED_JSON_PATH}{{json_file}}.json'
# Build a list of parsed JSON file names
PARSED_JSON_FILE_NAMES = glob_wildcards(PARSED_JSON_FILE).json_file
# All parsed JSON files
ALL_PARSED_JSONS = expand(PARSED_JSON_FILE, json_file=PARSED_JSON_FILE_NAMES)
rule all:
input: 'result.json'
rule clone_git:
output: directory(GIT_PATH)
threads: 1
conda: f'{ENVS_DIR}git.yml'
shell: f'git clone --depth 1 {GIT_URL} {{output}}'
rule extract_json:
input:
cmd='scripts/extract_json.py',
json_file=PARSED_JSON_FILE
output: 'result.json'
threads: 50
shell: 'python {input.cmd} {input.json_file} {output}'
僅運行clone_git
工作正常(如果我設置GIT_PATH
的all
input
)。
為什么我會收到錯誤消息? 這是因為工作流啟動時 JSON 文件不存在嗎?
另外 - 我不知道這是否重要 - 這是與module
一起使用的子工作流。
您需要的似乎是一個首先執行的checkpoint
規則,然后snakemake
確定存在哪些.json
文件並運行您的提取/聚合函數。 這是一個改編的例子:
我很難完全理解克隆 git 存儲庫后得到的文件和文件夾結構。 所以我又回到了 Snakemake 的最佳實踐,即使用下載的resources
和創建的文件的results
。
您需要重新調整這些路徑以再次匹配您的情況:
GIT_PATH = config["git_local_path"] # git/
GIT_URL = config["git_url"]
checkpoint clone_git:
output:
git=directory(GIT_PATH),
threads: 1
conda:
f"{ENVS_DIR}git.yml"
shell:
f"git clone --depth 1 {GIT_URL} {{output.git}}"
rule extract_json:
input:
cmd="scripts/extract_json.py",
json_file="resources/{file_name}.json",
output:
"results/parsed_files/{file_name}.json",
shell:
"python {input.cmd} {input.json_file} {output}"
def get_all_json_file_names(wildcards):
git_dir = checkpoints.clone_git.get(**wildcards).output["git"]
file_names = glob_wildcards(
"resources/{file_name}.json"
).file_name
return expand(
"results/parsed_files/{file_name}.json",
file_name=file_names,
)
# Rule has checkpoint dependency: Only after the checkpoint is executed
# the rule is executed which then evaluates the function to determine all
# json files downloaded from the git repo
rule aggregate:
input:
get_all_json_file_names
output:
"result.json",
default_target: True
shell:
# TODO: Action which combines all JSON files
編輯:將expand(...)
從rule aggregate
移動到get_all_json_file_names
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.