From 435e470a97b44c33a38e6391194d87d0e94ace50 Mon Sep 17 00:00:00 2001 From: ESapenaVentura Date: Wed, 29 Apr 2026 13:14:39 +0200 Subject: [PATCH 1/5] Added function to create all possible permutations of a replacement --- wetlab/utils/common.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/wetlab/utils/common.py b/wetlab/utils/common.py index eab207ae..3aba6bb2 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,26 @@ 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 = [] + + 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] = '.' + results.append(''.join(s_list)) + + return results \ No newline at end of file From e4c448f3d026d4a2b6f41367d027a07e2aa60955 Mon Sep 17 00:00:00 2001 From: ESapenaVentura Date: Wed, 29 Apr 2026 13:16:36 +0200 Subject: [PATCH 2/5] Implemented logic to parse dashes in user names --- wetlab/utils/crontab_process.py | 1 + wetlab/utils/samplesheet.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/wetlab/utils/crontab_process.py b/wetlab/utils/crontab_process.py index a53ac08b..ba0f4435 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..f3c5ae77 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 @@ -161,8 +162,19 @@ def validate_userid_in_user_iem_file(file_read, user_id_list): ) return users - userid_names = [user for user in users_in_sample_sheet if user in user_id_list] - invalid_names = [user for user in users_in_sample_sheet if user not in user_id_list] + # 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 and "wetlab.common.get_all_string_replacement_combinations" + userid_names = [] + invalid_names = [] + + for user in users_in_sample_sheet: + 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: + userid_names.append(user_permutation) + break + else: + invalid_names.append(user) if len(invalid_names) > 0: invalid_names = list(set(invalid_names)) @@ -345,6 +357,9 @@ 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 +372,17 @@ 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: DUPLICATING VALIDATION LOGIC. + 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: From ae45e75f8d0726980e3a030e3993ee3f3c5b1ef0 Mon Sep 17 00:00:00 2001 From: ESapenaVentura Date: Wed, 29 Apr 2026 13:30:07 +0200 Subject: [PATCH 3/5] Users without dashes are considered again --- wetlab/utils/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wetlab/utils/common.py b/wetlab/utils/common.py index 3aba6bb2..c68ea33d 100644 --- a/wetlab/utils/common.py +++ b/wetlab/utils/common.py @@ -515,13 +515,13 @@ def get_all_string_replacement_combinations(string: str, old: str, new: str)-> l list of strings containing all possible combinations for the replacement """ positions = [i for i, ch in enumerate(string) if ch == old] - results = [] + 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] = '.' + s_list[pos] = new results.append(''.join(s_list)) return results \ No newline at end of file From c488b0568dd831df3954e0ab50d761ee112aebd3 Mon Sep 17 00:00:00 2001 From: ESapenaVentura Date: Wed, 29 Apr 2026 13:53:10 +0200 Subject: [PATCH 4/5] black linting --- wetlab/utils/common.py | 9 ++++++--- wetlab/utils/crontab_process.py | 2 +- wetlab/utils/samplesheet.py | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/wetlab/utils/common.py b/wetlab/utils/common.py index c68ea33d..135f3ad5 100644 --- a/wetlab/utils/common.py +++ b/wetlab/utils/common.py @@ -503,7 +503,10 @@ def open_log(config_file): logger = logging.getLogger() return logger -def get_all_string_replacement_combinations(string: str, old: str, new: str)-> list[str]: + +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. @@ -522,6 +525,6 @@ def get_all_string_replacement_combinations(string: str, old: str, new: str)-> l for replace, pos in zip(combo, positions): if replace: s_list[pos] = new - results.append(''.join(s_list)) + results.append("".join(s_list)) - return results \ No newline at end of file + return results diff --git a/wetlab/utils/crontab_process.py b/wetlab/utils/crontab_process.py index ba0f4435..abd51ab1 100644 --- a/wetlab/utils/crontab_process.py +++ b/wetlab/utils/crontab_process.py @@ -2185,7 +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 f3c5ae77..c5bed429 100644 --- a/wetlab/utils/samplesheet.py +++ b/wetlab/utils/samplesheet.py @@ -162,15 +162,19 @@ def validate_userid_in_user_iem_file(file_read, user_id_list): ) return users - # FIXME: Due to samplesheet limitations, we need to check all possible combinations of "dash to dot" + # 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 and "wetlab.common.get_all_string_replacement_combinations" userid_names = [] invalid_names = [] for user in users_in_sample_sheet: - all_user_replacement_combinations = wetlab.utils.common.get_all_string_replacement_combinations(user, old="-", new=".") + 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: + if user_permutation in user_id_list: userid_names.append(user_permutation) break else: @@ -359,7 +363,6 @@ def get_user_ids_from_samplesheet( 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) @@ -376,12 +379,16 @@ def get_user_ids_from_samplesheet( userid_names = [] for user in user_ids: - all_user_replacement_combinations = wetlab.utils.common.get_all_string_replacement_combinations(user, old="-", new=".") + 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: + if user_permutation in user_id_list_db: userid_names.append(user_permutation) break - + return userid_names From 602cdf6ead3b4313aef72f3dd7cfa2dcfe9dd959 Mon Sep 17 00:00:00 2001 From: ESapenaVentura Date: Thu, 30 Apr 2026 16:45:52 +0200 Subject: [PATCH 5/5] Fixed duplicating validation logic --- wetlab/utils/samplesheet.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/wetlab/utils/samplesheet.py b/wetlab/utils/samplesheet.py index c5bed429..8ac54707 100644 --- a/wetlab/utils/samplesheet.py +++ b/wetlab/utils/samplesheet.py @@ -162,23 +162,8 @@ def validate_userid_in_user_iem_file(file_read, user_id_list): ) return users - # 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 and "wetlab.common.get_all_string_replacement_combinations" - userid_names = [] - invalid_names = [] - - for user in users_in_sample_sheet: - 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: - userid_names.append(user_permutation) - break - else: - invalid_names.append(user) + userid_names = [user for user in users_in_sample_sheet if user in user_id_list] + invalid_names = [user for user in users_in_sample_sheet if user not in user_id_list] if len(invalid_names) > 0: invalid_names = list(set(invalid_names)) @@ -375,7 +360,8 @@ def get_user_ids_from_samplesheet( if not user_ids and version == "2": user_ids = get_user_ids_from_project_name(samplesheet) - # FIXME: DUPLICATING VALIDATION LOGIC. + # 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: