diff --git a/cg/apps/demultiplex/sample_sheet/sample_models.py b/cg/apps/demultiplex/sample_sheet/sample_models.py index bbd54ed7c1..9177c212e7 100644 --- a/cg/apps/demultiplex/sample_sheet/sample_models.py +++ b/cg/apps/demultiplex/sample_sheet/sample_models.py @@ -98,6 +98,8 @@ class FlowCellSampleBCLConvert(FlowCellSample): index: str = Field(..., alias=SampleSheetBCLConvertSections.Data.INDEX_1) index2: str = Field("", alias=SampleSheetBCLConvertSections.Data.INDEX_2) override_cycles: str = Field("", alias=SampleSheetBCLConvertSections.Data.OVERRIDE_CYCLES) + adapter_read_1: str = Field("", alias=SampleSheetBCLConvertSections.Data.ADAPTER_READ_1) + adapter_read_2: str = Field("", alias=SampleSheetBCLConvertSections.Data.ADAPTER_READ_2) barcode_mismatches_1: int = Field( 1, alias=SampleSheetBCLConvertSections.Data.BARCODE_MISMATCHES_1 ) diff --git a/cg/apps/demultiplex/sample_sheet/sample_sheet_creator.py b/cg/apps/demultiplex/sample_sheet/sample_sheet_creator.py index f0b242ff75..b5d1180301 100644 --- a/cg/apps/demultiplex/sample_sheet/sample_sheet_creator.py +++ b/cg/apps/demultiplex/sample_sheet/sample_sheet_creator.py @@ -50,7 +50,7 @@ def __init__( FlowCellSampleBCLConvert | FlowCellSampleBcl2Fastq ] = flow_cell.sample_type self.force: bool = force - self.index_settings: IndexSettings = self.run_parameters.index_settings() + self.index_settings: IndexSettings = self.run_parameters.index_settings def _get_index_settings(self) -> IndexSettings: # TODO: Remove and move testst to tun parameters diff --git a/tests/apps/demultiplex/conftest.py b/tests/apps/demultiplex/conftest.py index d4dfdd7ba1..5c9fd15ccd 100644 --- a/tests/apps/demultiplex/conftest.py +++ b/tests/apps/demultiplex/conftest.py @@ -16,36 +16,33 @@ @pytest.fixture -def bcl_convert_samples_with_updated_indexes() -> list[FlowCellSampleBCLConvert]: +def bcl_convert_samples_similar_index1() -> list[FlowCellSampleBCLConvert]: """Return a list of three FlowCellSampleBCLConvert with updated indexes.""" sample_1 = FlowCellSampleBCLConvert( - lane=1, sample_id="ACC123", index="CAGAAGAT", index2="CAATGTAC" + lane=1, sample_id="ACC123", index="CAGAAGAT", index2="GCGCAAGC" ) sample_2 = FlowCellSampleBCLConvert( lane=1, sample_id="ACC456", index="CAGAAGAG", index2="CAATGTAT" ) sample_3 = FlowCellSampleBCLConvert( - lane=2, sample_id="ACC789", index="AAGCGATAGA", index2="AACCGCAACA" + lane=2, sample_id="ACC789", index="AAGCGATA", index2="AACCGCAA" ) return [sample_1, sample_2, sample_3] @pytest.fixture -def override_cycles_for_samples_with_updated_indexes() -> list[str]: - """Return the correspondent Override Cycles values for three samples.""" - return ["Y151;I8N2;I8N2;Y151", "Y151;I8N2;I8N2;Y151", "Y151;I10;I10;Y151"] - - -@pytest.fixture -def override_cycles_for_novaseq_x_samples() -> list[str]: - """Return the correspondent Override Cycles values for three samples.""" - return ["Y151;I8N2;N2I8;Y151", "Y151;I8N2;N2I8;Y151", "Y151;I10;I10;Y151"] - - -@pytest.fixture -def barcode_mismatch_values_for_samples_with_updated_indexes() -> list[tuple[int, int]]: - """Return the pairs of barcode mismatch values corresponding to three samples.""" - return [(0, 0), (0, 0), (1, 1)] +def bcl_convert_samples_similar_index2() -> list[FlowCellSampleBCLConvert]: + """Return a list of three FlowCellSampleBCLConvert with updated indexes.""" + sample_1 = FlowCellSampleBCLConvert( + lane=1, sample_id="ACC123", index="GCGCAAGC", index2="CAATGTAC" + ) + sample_2 = FlowCellSampleBCLConvert( + lane=1, sample_id="ACC456", index="CAATGTAT", index2="CAATGTAT" + ) + sample_3 = FlowCellSampleBCLConvert( + lane=2, sample_id="ACC789", index="AAGCGATA", index2="AACCGCAA" + ) + return [sample_1, sample_2, sample_3] @pytest.fixture diff --git a/tests/apps/demultiplex/test_sample_models.py b/tests/apps/demultiplex/test_sample_models.py index cc91c95acd..10b56ea021 100644 --- a/tests/apps/demultiplex/test_sample_models.py +++ b/tests/apps/demultiplex/test_sample_models.py @@ -1,3 +1,4 @@ +from typing import Type from unittest.mock import Mock import pytest @@ -197,26 +198,50 @@ def test_update_override_cycles(): # THEN the override cycles are updated with the expected value -def test_update_barcode_mismatches_1(): - # TODO: Parametrise this test with different sets of samples and expected outputs: - # One that is and one that is 1 - """.""" +@pytest.mark.parametrize( + "sample_list_fixture, expected_barcode_mismatch", + [("bcl_convert_samples_similar_index1", 0), ("bcl_convert_samples_similar_index2", 1)], + ids=["barcode1_0", "barcode1_1"], +) +def test_update_barcode_mismatches_1( + sample_list_fixture: str, expected_barcode_mismatch: int, request: pytest.FixtureRequest +): + """Test that index 1 barcode mismatch values are as expected for different sets of samples.""" + # GIVEN a list of FlowCellSampleBCLConvert + sample_list: list[FlowCellSampleBCLConvert] = request.getfixturevalue(sample_list_fixture) + # GIVEN a FlowCellSampleBCLConvert + sample_to_update: FlowCellSampleBCLConvert = sample_list[0] # WHEN updating the barcode mismatches 1 + sample_to_update.update_barcode_mismatches_1(samples_to_compare=sample_list) # THEN the barcode mismatches 1 are updated with the expected value + assert sample_to_update.barcode_mismatches_1 == expected_barcode_mismatch -def test_update_barcode_mismatches_2(): +@pytest.mark.parametrize( + "sample_list_fixture, expected_barcode_mismatch", + [("bcl_convert_samples_similar_index1", 1), ("bcl_convert_samples_similar_index2", 0)], + ids=["barcode2_0", "barcode2_1"], +) +def test_update_barcode_mismatches_2( + sample_list_fixture: str, expected_barcode_mismatch: int, request: pytest.FixtureRequest +): # TODO: Parametrise this test with different sets of samples and expected outputs: # One that is, one that is 1 and one that is 'na' - """.""" + """Test that index 2 barcode mismatch values are as expected for different sets of samples.""" + # GIVEN a list of FlowCellSampleBCLConvert + sample_list: list[FlowCellSampleBCLConvert] = request.getfixturevalue(sample_list_fixture) + # GIVEN a FlowCellSampleBCLConvert + sample_to_update: FlowCellSampleBCLConvert = sample_list[0] # WHEN updating the barcode mismatches 2 + sample_to_update.update_barcode_mismatches_2(samples_to_compare=sample_list) - # THEN the barcode mismatches 2 are updated with the expected value + # THEN the barcode mismatches 1 are updated with the expected value + assert sample_to_update.barcode_mismatches_2 == expected_barcode_mismatch @pytest.mark.parametrize( @@ -224,12 +249,12 @@ def test_update_barcode_mismatches_2(): [ ("novaseq_x_run_parameters", "novaseq_x_lims_samples", FlowCellSampleBCLConvert), ( - "novaseq_6000_pre_1_5_kits_run_parameters", + "novaseq_6000_run_parameters_pre_1_5_kits", "novaseq_6000_pre_1_5_kits_lims_samples", FlowCellSampleBCLConvert, ), ( - "novaseq_6000_post_1_5_kits_run_parameters", + "novaseq_6000_run_parameters_post_1_5_kits", "novaseq_6000_post_1_5_kits_lims_samples", FlowCellSampleBCLConvert, ), @@ -256,10 +281,12 @@ def test_update_barcode_mismatches_2(): "HiSeq2500 Bcl2Fastq", ], ) -def test_process_sample_for_sample_sheet(): +def test_process_sample_for_sample_sheet( + run_parameters_fixture: str, raw_lims_samples_fixture: str, sample_model: Type[FlowCellSample] +): # TODO: We need a raw FlowCellSampleBcl2Fastq and a raw FlowCellSampleBCLConvert """.""" - # GIVEN a FlowCellSample + # GIVEN a run parameters object and a list of samples from a flow cell # WHEN processing the sample for a sample sheet diff --git a/tests/apps/demultiplex/test_sample_sheet_creator.py b/tests/apps/demultiplex/test_sample_sheet_creator.py index 1bd226baa6..4c362d70de 100644 --- a/tests/apps/demultiplex/test_sample_sheet_creator.py +++ b/tests/apps/demultiplex/test_sample_sheet_creator.py @@ -2,7 +2,6 @@ from pathlib import Path import pytest -from _pytest.fixtures import FixtureRequest from cg.apps.demultiplex.sample_sheet.read_sample_sheet import get_validated_sample_sheet from cg.apps.demultiplex.sample_sheet.sample_models import ( @@ -15,13 +14,7 @@ SampleSheetCreatorBCLConvert, ) from cg.apps.demultiplex.sample_sheet.sample_sheet_models import SampleSheet -from cg.constants.demultiplexing import ( - NO_REVERSE_COMPLEMENTS, - NOVASEQ_6000_POST_1_5_KITS, - NOVASEQ_X_INDEX_SETTINGS, - BclConverter, - IndexSettings, -) +from cg.constants.demultiplexing import BclConverter from cg.exc import SampleSheetError from cg.models.flow_cell.flow_cell import FlowCellDirectoryData @@ -124,55 +117,3 @@ def test_remove_unwanted_samples_no_dual_index( f"Removing sample {novaseq6000_flow_cell_sample_no_dual_index} since it does not have dual index" in caplog.text ) - - -def test_add_override_cycles_to_novaseqx_samples( - novaseq_x_flow_cell: FlowCellDirectoryData, - bcl_convert_samples_with_updated_indexes: list[FlowCellSampleBCLConvert], - override_cycles_for_novaseq_x_samples: list[str], -): - """Test that OverrideCycles values are generated correctly for NovaSeqX samples.""" - # GIVEN a SampleSheetCreator with samples without Override Cycles added - sample_sheet_creator = SampleSheetCreatorBCLConvert( - flow_cell=novaseq_x_flow_cell, lims_samples=bcl_convert_samples_with_updated_indexes - ) - assert all(sample.override_cycles == "" for sample in sample_sheet_creator.lims_samples) - - # WHEN adding the correct values of override samples - sample_sheet_creator.add_override_cycles_to_samples() - - # THEN the Override Cycles attribute is added to all samples - assert all( - sample.override_cycles == override_cycles_value - for sample, override_cycles_value in zip( - sample_sheet_creator.lims_samples, - override_cycles_for_novaseq_x_samples, - ) - ) - - -def test_update_barcode_mismatch_values_for_samples( - novaseq_x_flow_cell: FlowCellDirectoryData, - bcl_convert_samples_with_updated_indexes: list[FlowCellSampleBCLConvert], - barcode_mismatch_values_for_samples_with_updated_indexes: list[tuple[int, int]], -): - """Tests that the barcode mismatch values are updated correctly for NovaSeqX samples.""" - # GIVEN a sample sheet creator with samples with barcode mismatch values equal to 1 - sample_sheet_creator = SampleSheetCreatorBCLConvert( - flow_cell=novaseq_x_flow_cell, lims_samples=bcl_convert_samples_with_updated_indexes - ) - assert all( - sample.barcode_mismatches_1 == 1 and sample.barcode_mismatches_2 == 1 - for sample in sample_sheet_creator.lims_samples - ) - - # WHEN updating the barcode mismatch values - sample_sheet_creator.update_barcode_mismatch_values_for_samples( - sample_sheet_creator.lims_samples - ) - - # THEN exactly two samples have barcode mismatches equal to zero - for sample, barcode_mismatch_tuple in zip( - sample_sheet_creator.lims_samples, barcode_mismatch_values_for_samples_with_updated_indexes - ): - assert (sample.barcode_mismatches_1, sample.barcode_mismatches_2) == barcode_mismatch_tuple diff --git a/tests/apps/demultiplex/test_sample_sheet_creator_factory.py b/tests/apps/demultiplex/test_sample_sheet_creator_factory.py index baa9dfda08..01f53d8d08 100644 --- a/tests/apps/demultiplex/test_sample_sheet_creator_factory.py +++ b/tests/apps/demultiplex/test_sample_sheet_creator_factory.py @@ -53,4 +53,3 @@ def test_sample_sheet_creator_factory_BCL_convert( # THEN the sample sheet creator is a BCL Convert sample sheet creator assert isinstance(sample_sheet_creator, SampleSheetCreatorBCLConvert) -nvert) diff --git a/tests/conftest.py b/tests/conftest.py index 58de6d1858..51eef8a1e2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1228,7 +1228,7 @@ def demux_results_not_finished_dir(demultiplex_fixtures: Path) -> Path: @pytest.fixture -def novaseq_6000_post_1_5_kits_flow_cell_dir(tmp_flow_cells_directory: Path) -> Path: +def novaseq_6000_post_1_5_kits_flow_cell(tmp_flow_cells_directory: Path) -> Path: return Path(tmp_flow_cells_directory, "230912_A00187_1009_AHK33MDRX3") @@ -1239,16 +1239,16 @@ def novaseq_6000_post_1_5_kits_flow_cell_data(flow_cells_dir: Path) -> FlowCellD @pytest.fixture def novaseq_6000_post_1_5_kits_correct_sample_sheet( - novaseq_6000_post_1_5_kits_flow_cell_dir: Path, + novaseq_6000_post_1_5_kits_flow_cell: Path, ) -> Path: - return Path(novaseq_6000_post_1_5_kits_flow_cell_dir, "CorrectSampleSheet.csv") + return Path(novaseq_6000_post_1_5_kits_flow_cell, "CorrectSampleSheet.csv") @pytest.fixture def novaseq_6000_post_1_5_kits_raw_lims_samples( - novaseq_6000_post_1_5_kits_flow_cell_dir: Path, + novaseq_6000_post_1_5_kits_flow_cell: Path, ) -> Path: - return Path(novaseq_6000_post_1_5_kits_flow_cell_dir, "HK33MDRX3_raw.json") + return Path(novaseq_6000_post_1_5_kits_flow_cell, "HK33MDRX3_raw.json") @pytest.fixture @@ -1267,7 +1267,7 @@ def novaseq_6000_pre_1_5_kits_flow_cell_data(flow_cells_dir: Path) -> FlowCellDi @pytest.fixture -def novaseq_6000_pre_1_5_kits_flow_cell_dir(tmp_flow_cells_directory: Path) -> Path: +def novaseq_6000_pre_1_5_kits_flow_cell(tmp_flow_cells_directory: Path) -> Path: return Path(tmp_flow_cells_directory, "190927_A00689_0069_BHLYWYDSXX") @@ -1432,11 +1432,22 @@ def novaseq_6000_run_parameters_path(bcl2fastq_flow_cell_dir: Path) -> Path: @pytest.fixture def novaseq_6000_run_parameters_pre_1_5_kits_path( - novaseq_6000_pre_1_5_kits_flow_cell_dir: Path, + novaseq_6000_pre_1_5_kits_flow_cell: Path, ) -> Path: - """Return the path to a NovaSeq6000 run parameters file.""" + """Return the path to a NovaSeq6000 pre 1.5 kit run parameters file.""" + return Path( + novaseq_6000_pre_1_5_kits_flow_cell, + DemultiplexingDirsAndFiles.RUN_PARAMETERS_PASCAL_CASE, + ) + + +@pytest.fixture +def novaseq_6000_run_parameters_post_1_5_kits_path( + novaseq_6000_post_1_5_kits_flow_cell: Path, +) -> Path: + """Return the path to a NovaSeq6000 post 1.5 kit run parameters file.""" return Path( - novaseq_6000_pre_1_5_kits_flow_cell_dir, + novaseq_6000_post_1_5_kits_flow_cell, DemultiplexingDirsAndFiles.RUN_PARAMETERS_PASCAL_CASE, ) @@ -1502,6 +1513,24 @@ def novaseq_6000_run_parameters( return RunParametersNovaSeq6000(run_parameters_path=novaseq_6000_run_parameters_path) +@pytest.fixture +def novaseq_6000_run_parameters_pre_1_5_kits( + novaseq_6000_run_parameters_pre_1_5_kits_path: Path, +) -> RunParametersNovaSeq6000: + """Return a NovaSeq6000 run parameters pre 1.5 kit object.""" + return RunParametersNovaSeq6000( + run_parameters_path=novaseq_6000_run_parameters_pre_1_5_kits_path + ) + + +@pytest.fixture +def novaseq_6000_run_parameters_post_1_5_kits(novaseq_6000_run_parameters_post_1_5_kits_path: Path): + """Return a NovaSeq6000 run parameters post 1.5 kit object.""" + return RunParametersNovaSeq6000( + run_parameters_path=novaseq_6000_run_parameters_post_1_5_kits_path + ) + + @pytest.fixture(scope="session") def novaseq_x_run_parameters( novaseq_x_run_parameters_path: Path, diff --git a/tests/models/demultiplexing/test_run_parameters.py b/tests/models/demultiplexing/test_run_parameters.py index 6efa3f2916..1131b01e61 100644 --- a/tests/models/demultiplexing/test_run_parameters.py +++ b/tests/models/demultiplexing/test_run_parameters.py @@ -5,7 +5,14 @@ import pytest from _pytest.fixtures import FixtureRequest -from cg.constants.demultiplexing import RunParametersXMLNodes +from cg.apps.demultiplex.sample_sheet.sample_sheet_creator import SampleSheetCreatorBCLConvert +from cg.constants.demultiplexing import ( + NO_REVERSE_COMPLEMENTS, + NOVASEQ_6000_POST_1_5_KITS, + NOVASEQ_X_INDEX_SETTINGS, + IndexSettings, + RunParametersXMLNodes, +) from cg.constants.sequencing import Sequencers from cg.exc import RunParametersError, XMLError from cg.models.demultiplex.run_parameters import (