diff --git a/wetlab/utils/common.py b/wetlab/utils/common.py index eab207ae..135f3ad5 100644 --- a/wetlab/utils/common.py +++ b/wetlab/utils/common.py @@ -5,6 +5,7 @@ import socket import traceback from datetime import datetime, timezone +from itertools import product from logging.config import fileConfig from django.contrib.auth.models import User @@ -501,3 +502,29 @@ def open_log(config_file): fileConfig(config_file, disable_existing_loggers=False) logger = logging.getLogger() return logger + + +def get_all_string_replacement_combinations( + string: str, old: str, new: str +) -> list[str]: + """ + Description: + Get all replacement combinations for a string. This is used to validate user IDs. + Input: + string # string to return replacements + old # Substring to be replaced + new # Substring to replace old by + Return: + list of strings containing all possible combinations for the replacement + """ + positions = [i for i, ch in enumerate(string) if ch == old] + results = [string] + + for combo in product([False, True], repeat=len(positions)): + s_list = list(string) + for replace, pos in zip(combo, positions): + if replace: + s_list[pos] = new + results.append("".join(s_list)) + + return results diff --git a/wetlab/utils/crontab_process.py b/wetlab/utils/crontab_process.py index a53ac08b..abd51ab1 100644 --- a/wetlab/utils/crontab_process.py +++ b/wetlab/utils/crontab_process.py @@ -2185,6 +2185,7 @@ def _get_existing_stats_folder(conn, run_folder, experiment_name=""): logger = logging.getLogger(__name__) shared_folder = get_samba_shared_folder() base_folder = get_samba_application_shared_folder() + stats_file_paths = getattr( wetlab.config, "STATS_FILE_PATHS", [wetlab.config.STATS_FILE_PATH] ) diff --git a/wetlab/utils/samplesheet.py b/wetlab/utils/samplesheet.py index 9c364230..8ac54707 100644 --- a/wetlab/utils/samplesheet.py +++ b/wetlab/utils/samplesheet.py @@ -10,6 +10,7 @@ # Local imports import wetlab.config +import wetlab.utils.common # import wetlab.models @@ -345,6 +346,8 @@ def get_user_ids_from_samplesheet( version = samplesheet_version(samplesheet) iskylims_user_column = wetlab.config.TABULAR_DATA_ISKYLIMS_USER_COLUMN.get(version) + user_id_list_db = wetlab.utils.common.get_userid_list() + user_ids = [] if iskylims_user_column: user_ids = get_column_from_tabular_data(data, iskylims_user_column) @@ -357,7 +360,22 @@ def get_user_ids_from_samplesheet( if not user_ids and version == "2": user_ids = get_user_ids_from_project_name(samplesheet) - return user_ids + # FIXME: Due to samplesheet limitations, we need to check all possible combinations of "dash to dot" + # FIXME: When we develop a final solution, change below. + userid_names = [] + + for user in user_ids: + all_user_replacement_combinations = ( + wetlab.utils.common.get_all_string_replacement_combinations( + user, old="-", new="." + ) + ) + for user_permutation in all_user_replacement_combinations: + if user_permutation in user_id_list_db: + userid_names.append(user_permutation) + break + + return userid_names def get_projects_in_sample_sheet(samplesheet) -> list: