Skip to content

Commit

Permalink
Fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed Dec 14, 2023
1 parent 3f23f0c commit ccfda98
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 101 deletions.
2 changes: 2 additions & 0 deletions cg/apps/demultiplex/sample_sheet/sample_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion cg/apps/demultiplex/sample_sheet/sample_sheet_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check notice on line 56 in cg/apps/demultiplex/sample_sheet/sample_sheet_creator.py

View check run for this annotation

codefactor.io / CodeFactor

cg/apps/demultiplex/sample_sheet/sample_sheet_creator.py#L56

unresolved comment '# TODO: Remove and move testst to tun parameters' (C100)
Expand Down
33 changes: 15 additions & 18 deletions tests/apps/demultiplex/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 38 additions & 11 deletions tests/apps/demultiplex/test_sample_models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Type
from unittest.mock import Mock

import pytest
Expand Down Expand Up @@ -197,39 +198,63 @@ 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(

Check notice on line 201 in tests/apps/demultiplex/test_sample_models.py

View check run for this annotation

codefactor.io / CodeFactor

tests/apps/demultiplex/test_sample_models.py#L201

unresolved comment '# TODO: Parametrise this test with different sets of samples and expected outputs:' (C100)
"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(
"run_parameters_fixture, raw_lims_samples_fixture, sample_model",
[
("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,
),

Check notice on line 260 in tests/apps/demultiplex/test_sample_models.py

View check run for this annotation

codefactor.io / CodeFactor

tests/apps/demultiplex/test_sample_models.py#L260

unresolved comment '# TODO: We need a raw FlowCellSampleBcl2Fastq and a raw FlowCellSampleBCLConvert' (C100)
Expand All @@ -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

Expand Down
61 changes: 1 addition & 60 deletions tests/apps/demultiplex/test_sample_sheet_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
47 changes: 38 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand All @@ -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
Expand All @@ -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")


Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion tests/models/demultiplexing/test_run_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit ccfda98

Please sign in to comment.