From c1afdc1bc2fe6e6e337f4dd33b46b93ffa6d2c21 Mon Sep 17 00:00:00 2001 From: Alexis Lucattini Date: Sun, 15 Sep 2024 15:41:39 +1000 Subject: [PATCH 1/2] Add lane to bclconvert samplesheet if it doesn't exist --- .../helper/icav2_analysis/analysis_helper.py | 3 +- .../helper/runinfo/__init__.py | 3 +- .../helper/runinfo/runinfo_helper.py | 9 ++++ .../helper/samplesheet/samplesheet_helper.py | 45 +++++++++++++++++-- .../icav2_event_translator.py | 2 + 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/icav2_analysis/analysis_helper.py b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/icav2_analysis/analysis_helper.py index 35d0dbadd..824014fc9 100644 --- a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/icav2_analysis/analysis_helper.py +++ b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/icav2_analysis/analysis_helper.py @@ -197,7 +197,8 @@ def collect_analysis_objects(project_id: str, analysis_id: str) -> Dict: logger.info("Reading in the samplesheet") samplesheet_dict = read_v2_samplesheet( project_id=project_id, - data_id=samplesheet_file_id + samplesheet_data_id=samplesheet_file_id, + runinfo_data_id=run_info_file_id ) return { diff --git a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/runinfo/__init__.py b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/runinfo/__init__.py index 319209c86..88e888e9a 100644 --- a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/runinfo/__init__.py +++ b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/runinfo/__init__.py @@ -1,5 +1,6 @@ -from .runinfo_helper import get_run_id_from_run_info +from .runinfo_helper import get_run_id_from_run_info, get_num_lanes_from_run_info __all__ = [ + 'get_num_lanes_from_run_info', 'get_run_id_from_run_info' ] \ No newline at end of file diff --git a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/runinfo/runinfo_helper.py b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/runinfo/runinfo_helper.py index 386612e4c..44161005a 100644 --- a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/runinfo/runinfo_helper.py +++ b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/runinfo/runinfo_helper.py @@ -100,3 +100,12 @@ def get_run_id_from_run_info(project_id: str, data_id: str) -> str: """ return read_runinfo_xml(project_id, data_id)['RunInfo']['Run']['@Id'] + +def get_num_lanes_from_run_info(project_id: str, data_id: str) -> int: + """ + Get the number of lanes in a run info object + :param project_id: + :param data_id: + :return: + """ + return int(read_runinfo_xml(project_id, data_id)['RunInfo']['Run']['FlowcellLayout']['@LaneCount']) \ No newline at end of file diff --git a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/samplesheet/samplesheet_helper.py b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/samplesheet/samplesheet_helper.py index 2639b8186..5fc1d3aa4 100644 --- a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/samplesheet/samplesheet_helper.py +++ b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/helper/samplesheet/samplesheet_helper.py @@ -7,6 +7,7 @@ from io import StringIO from typing import Dict +from more_itertools import flatten # UMCCR Libraries from v2_samplesheet_maker.functions.v2_samplesheet_reader import v2_samplesheet_reader from wrapica.project_data import read_icav2_file_contents_to_string @@ -19,12 +20,17 @@ logger.setLevel(logging.INFO) -def read_v2_samplesheet(project_id: str, data_id: str) -> Dict: +def read_v2_samplesheet( + project_id: str, + samplesheet_data_id: str, + runinfo_data_id: str +) -> Dict: """ Given a v2 samplesheet path, read in the file as a v2 samplesheet (we first convert to json) :param project_id: - :param data_id: + :param samplesheet_data_id: + :param runinfo_data_id :return: A dictionary @@ -90,12 +96,43 @@ def read_v2_samplesheet(project_id: str, data_id: str) -> Dict: ] } """ + from ..runinfo import get_num_lanes_from_run_info - return v2_samplesheet_reader( + v2_samplesheet_dict = v2_samplesheet_reader( StringIO( read_icav2_file_contents_to_string( project_id=project_id, - data_id=data_id + data_id=samplesheet_data_id ) ) ) + + # Get bclconvert data from the v2 samplesheet dict + # And confirm that the lane column is present + if 'lane' in v2_samplesheet_dict['bclconvert_data'][0].keys(): + # Return the samplesheet as is + return v2_samplesheet_dict + + # Otherwise we read the runinfo file + num_lanes = get_num_lanes_from_run_info( + project_id=project_id, + data_id=runinfo_data_id + ) + + # And now append the lane attribute to every + v2_samplesheet_dict['bclconvert_data'] = flatten( + map( + lambda bclconvert_data_row_iter: list( + map( + lambda lane_iter: { + **bclconvert_data_row_iter, + **{"lane": lane_iter + 1} + }, + range(num_lanes) + ) + ), + v2_samplesheet_dict['bclconvert_data'] + ), + ) + + return v2_samplesheet_dict diff --git a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/icav2_event_translator.py b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/icav2_event_translator.py index 9e807fdb3..3f4a37876 100644 --- a/lib/workload/stateless/stacks/bclconvert-manager/translator_service/icav2_event_translator.py +++ b/lib/workload/stateless/stacks/bclconvert-manager/translator_service/icav2_event_translator.py @@ -499,3 +499,5 @@ def parse_event_code(event_code): # # "statusCode": 200, # # "body": "\"Internal event sent to the event bus and both msg stored in the DynamoDB table.\"" # # } + + From 2c692f4e8198035416062aa4796568b019d69a3a Mon Sep 17 00:00:00 2001 From: Alexis Lucattini Date: Sun, 15 Sep 2024 22:02:05 +1000 Subject: [PATCH 2/2] Added more-itertools to the requirements list --- .../stateless/stacks/bclconvert-manager/deps/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/workload/stateless/stacks/bclconvert-manager/deps/requirements.txt b/lib/workload/stateless/stacks/bclconvert-manager/deps/requirements.txt index 477366077..c9885d74f 100644 --- a/lib/workload/stateless/stacks/bclconvert-manager/deps/requirements.txt +++ b/lib/workload/stateless/stacks/bclconvert-manager/deps/requirements.txt @@ -4,3 +4,4 @@ wrapica==2.27.1.post20240830140737 xmltodict==0.13.0 mypy_boto3_ssm>=1.16.0 mypy_boto3_secretsmanager>=1.16.0 +more-itertools>=10.3.0