如何将当前提交包含在 snakemake 工作流程中以供以后参考?
How to include the current commit in a snakemake workflow for later reference?
我的 snakemake 工作流程在 git 存储库中受版本控制。我希望可以包含类似 git describe --always
的输出以跟踪 git tag/commit 工作流存储库当前已检出到 在 期间工作流的运行时间。
我在工作流中添加了一个通用函数,它只是通过 subprocess
:
调用 git
def get_git_commit(wildcards):
label = subprocess.check_output(["git", "describe", "--always"]).strip().decode("utf-8")
return(label)
输出可用于规则参数,例如
params:
git_commit = get_git_commit
但是,在工作流运行期间,命令在工作目录中执行,而不是在 Snakefile 的源目录中执行。 cd
来回(进入源目录)是否可取?还是有更清洁的策略?
假设您的 Snakefile 与 .git 文件夹位于同一文件夹中,您可以通过以下方式获取 Snakefile 的路径(直接在 Snakefile 中):
wfbasedir = workflow.basedir
然后您可以使用参数 --git-dir
调用 git:
git --git-dir={wfbasedir}/.git
或您的方式:
def get_git_commit(wildcards):
label = subprocess.check_output(["git","--git-dir="+wfbasedir+"/.git", "describe", "--always"]).strip().decode("utf-8")
return(label)
我的 snakemake 工作流程在 git 存储库中受版本控制。我希望可以包含类似 git describe --always
的输出以跟踪 git tag/commit 工作流存储库当前已检出到 在 期间工作流的运行时间。
我在工作流中添加了一个通用函数,它只是通过 subprocess
:
def get_git_commit(wildcards):
label = subprocess.check_output(["git", "describe", "--always"]).strip().decode("utf-8")
return(label)
输出可用于规则参数,例如
params:
git_commit = get_git_commit
但是,在工作流运行期间,命令在工作目录中执行,而不是在 Snakefile 的源目录中执行。 cd
来回(进入源目录)是否可取?还是有更清洁的策略?
假设您的 Snakefile 与 .git 文件夹位于同一文件夹中,您可以通过以下方式获取 Snakefile 的路径(直接在 Snakefile 中):
wfbasedir = workflow.basedir
然后您可以使用参数 --git-dir
调用 git:
git --git-dir={wfbasedir}/.git
或您的方式:
def get_git_commit(wildcards):
label = subprocess.check_output(["git","--git-dir="+wfbasedir+"/.git", "describe", "--always"]).strip().decode("utf-8")
return(label)