我为每个用户提供了一个输入文件(名称为db-user.participant)。我想将这些文件作为输入,然后测试脚本必须为每个参与者每个传感器输出一个文件(还有第二个包含传感器的列表)。我的代码可以正常工作,但是我想知道这是否是实现我想要的“ snakemake”方法。
SENSORS=["s1", "s2"]
DBS_USERS={"db1":["p1", "p2"]}
def db_user_path(paths):
new_paths = []
for db, users in DBS_USERS.items():
for user in users:
for path in paths:
new_paths.append(path.replace("db", db).replace("user", user))
return new_paths
print(db_user_path(expand("data/raw/db/user/{sensor}.csv", sensor=SENSORS)))
rule all:
input:
db_user_path(expand("data/raw/db/user/{sensor}.csv", sensor=SENSORS))
rule create_dataset:
input:
"data/external/{db}-{user}.participant"
output:
expand("data/raw/{{db}}/{{user}}/{sensor}.csv", sensor=SENSORS)
script:
"src/data/test.R"
例如,如果我有:
db1-p1.participant
db1-p2.participant
sensors = ["s1","s2"]
输出应为:
db1/p1/s1.csv
db1/p1/s2.csv
db1/p2/s1.csv
db1/p2/s2.csv