Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions wetlab/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions wetlab/utils/crontab_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand Down
20 changes: 19 additions & 1 deletion wetlab/utils/samplesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Local imports
import wetlab.config
import wetlab.utils.common

# import wetlab.models

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
Loading