From 23f0aaba3a3dec2dd3eaf36265508d92aa74f8bc Mon Sep 17 00:00:00 2001 From: junos Date: Wed, 16 Mar 2022 18:28:57 +0100 Subject: [PATCH] Get the name of the questionnaire from Snakefile. --- rules/features.smk | 2 +- src/features/phone_esm/straw/preprocess.py | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/rules/features.smk b/rules/features.smk index 359a8aba..f778eada 100644 --- a/rules/features.smk +++ b/rules/features.smk @@ -327,7 +327,7 @@ rule conversation_r_features: rule preprocess_esm: input: "data/raw/{pid}/phone_esm_with_datetime.csv" params: - questionnaire_names = lambda wildcards: config["PHONE_ESM"]["PROVIDERS"][wildcards.feature]["FEATURES"] + questionnaire_name = "{feature}" output: "data/interim/{pid}/phone_esm_{feature}_clean.csv" script: "../src/features/phone_esm/straw/preprocess.py" diff --git a/src/features/phone_esm/straw/preprocess.py b/src/features/phone_esm/straw/preprocess.py index 6894404a..e3805a77 100644 --- a/src/features/phone_esm/straw/preprocess.py +++ b/src/features/phone_esm/straw/preprocess.py @@ -1,17 +1,16 @@ from esm_preprocess import * -questionnaire_names = snakemake.params["questionnaire_names"] +questionnaire_name = snakemake.params["questionnaire_name"] df_esm = pd.read_csv(snakemake.input[0]) df_esm_preprocessed = preprocess_esm(df_esm) -for questionnaire_name in questionnaire_names: - try: - questionnaire_id = QUESTIONNAIRE_IDS[questionnaire_name] - except ValueError: - print("The requested questionnaire name should be one of the following:") - print(QUESTIONNAIRE_IDS.keys()) - else: - df_esm_selected = df_esm_preprocessed[df_esm_preprocessed["questionnaire_id"] == questionnaire_id] - df_esm_clean = clean_up_esm(df_esm_selected) - df_esm_clean.to_csv(snakemake.output[0]) +try: + questionnaire_id = QUESTIONNAIRE_IDS[questionnaire_name] +except ValueError: + print("The requested questionnaire name should be one of the following:") + print(QUESTIONNAIRE_IDS.keys()) +else: + df_esm_selected = df_esm_preprocessed[df_esm_preprocessed["questionnaire_id"] == questionnaire_id] + df_esm_clean = clean_up_esm(df_esm_selected) + df_esm_clean.to_csv(snakemake.output[0])