如何在配置文件中使用相对路径,以便用户不需要更改输出目录路径中的USER?
我有这个:
config.yml
proj_name: H1N1_rhesus
contact:
email: user.edu
person: user
01-preprocess: /home/user/2022-h1n1/01-preprocess/
02-salmon: /home/user/2022-h1n1/02-salmon/
raw-data: /tmp/H1N1_rhesus/
reference: /tmp/蛇形
#----SET VARIABLES----#
PROJ = config["proj_name"]
INPUTDIR = config["raw-data"]
PREPROCESS = config["01-preprocess"]
SALMON = config["02-salmon"]
REFERENCE = config["reference"但我想做这样的事情:
proj_name: H1N1_rhesus
contact:
email: user.edu
person: user
01-preprocess: /home/$(USER)/2022-h1n1/01-preprocess/
02-salmon: /home/$(USER)/2022-h1n1/02-salmon/
raw-data: /tmp/H1N1_rhesus/
reference: /tmp/或者这个:
proj_name: H1N1_rhesus
contact:
email: user.edu
person: user
01-preprocess: /home/$(PWD)/01-preprocess/
02-salmon: /home/$(PWD)/02-salmon/
raw-data: /tmp/H1N1_rhesus/
reference: /tmp/但我尝试过的方法都没有奏效。
发布于 2022-01-19 23:50:57
另一种选择是使用intake来定义数据目录。这允许引用环境变量,例如:
sources:
01-preprocess:
args:
url: "/home/{{env(USER)}}/2022-h1n1/01-preprocess/"在Snakefile内部,您将拥有:
import intake
cat = intake.open_catalog('config.yml')
data = cat['01-preprocess'].urlpath发布于 2022-01-19 23:33:12
一种选择是使用f-字符串格式(在Snakefile内)。因此,.yaml可以包含:
proj_name: H1N1_rhesus
paths:
01-preprocess: /home/{user}/2022-h1n1/01-preprocess/
02-salmon: /home/{user}/2022-h1n1/02-salmon/
raw-data: /tmp/H1N1_rhesus/
reference: /tmp/在Snakefile内部,您将拥有:
config: 'config.yaml'
# to identify the user, see comments: https://stackoverflow.com/a/842096/10693596
import getpass
paths = {k: v.format(user=getpass.getuser()) for k,v in config['paths'].items()}paths对象是一个具有格式化路径的字典。
https://stackoverflow.com/questions/70774795
复制相似问题