Skip to content

Commit

Permalink
fix sample sheet validation (#2806)(patch)
Browse files Browse the repository at this point in the history
## Description
As described in  #2804, sample sheet validation does not take into account the bcl converter of the flow cell.


### Added

- This PR adds a check inside the method `validate_sample_sheet` of the class `FlowCellDirectoryData` that compares the sample sheet type extracted from the sample sheet itself and the bcl converter of the `FlowCellDirectoryData`. If they don't match, it fails the validation and informs this mismatch in the logs as a warning.
  • Loading branch information
diitaz93 authored Jan 8, 2024
1 parent 53a4661 commit a4f37a9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cg/cli/demultiplex/demux.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def demultiplex_all(context: CGConfig, flow_cells_directory: click.Path, dry_run

if not flow_cell.validate_sample_sheet():
LOG.warning(
f"Malformed sample sheet. Run cg demultiplex samplesheet validate {flow_cell.sample_sheet_path}",
"Malformed sample sheet. "
f"Run cg demultiplex sample sheet validate {flow_cell.sample_sheet_path}",
)
continue

Expand Down
20 changes: 19 additions & 1 deletion cg/models/flow_cell/flow_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
from pydantic import ValidationError
from typing_extensions import Literal

from cg.apps.demultiplex.sample_sheet.read_sample_sheet import get_sample_sheet_from_file
from cg.apps.demultiplex.sample_sheet.read_sample_sheet import (
get_sample_sheet_from_file,
get_sample_type,
)
from cg.apps.demultiplex.sample_sheet.sample_models import (
FlowCellSample,
FlowCellSampleBcl2Fastq,
FlowCellSampleBCLConvert,
)
Expand All @@ -36,6 +40,10 @@
Sequencers.NOVASEQ: RunParametersNovaSeq6000,
Sequencers.NOVASEQX: RunParametersNovaSeqX,
}
SAMPLE_MODEL_TO_BCL_CONVERTER: dict[Type[FlowCellSample], str] = {
FlowCellSampleBCLConvert: BclConverter.DRAGEN,
FlowCellSampleBcl2Fastq: BclConverter.BCL2FASTQ,
}


class FlowCellDirectoryData:
Expand Down Expand Up @@ -213,6 +221,16 @@ def sample_sheet_exists(self) -> bool:

def validate_sample_sheet(self) -> bool:
"""Validate if sample sheet is on correct format."""
sample_type_from_sample_sheet: Type[FlowCellSample] = get_sample_type(
self.sample_sheet_path
)
if SAMPLE_MODEL_TO_BCL_CONVERTER[sample_type_from_sample_sheet] != self.bcl_converter:
LOG.warning(
f"Detected {SAMPLE_MODEL_TO_BCL_CONVERTER[sample_type_from_sample_sheet]} sample "
f"sheet for {self.bcl_converter} flow cell. "
"Generate the correct sample sheet or use the correct bcl converter."
)
return False
try:
get_sample_sheet_from_file(self.sample_sheet_path)
except (SampleSheetError, ValidationError) as error:
Expand Down
16 changes: 9 additions & 7 deletions tests/cli/demultiplex/test_demultiplex_flowcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
from cg.meta.demultiplex.housekeeper_storage_functions import add_sample_sheet_path_to_housekeeper
from cg.models.cg_config import CGConfig
from cg.models.flow_cell.flow_cell import FlowCellDirectoryData
from tests.meta.demultiplex.conftest import (
tmp_flow_cell_demux_base_path,
tmp_flow_cell_run_base_path,
)


def test_demultiplex_flow_cell_dry_run(
def test_demultiplex_bcl2fastq_flow_cell_dry_run(
cli_runner: testing.CliRunner,
tmp_flow_cells_directory_ready_for_demultiplexing_bcl2fastq: Path,
demultiplexing_context_for_demux: CGConfig,
Expand All @@ -26,7 +22,8 @@ def test_demultiplex_flow_cell_dry_run(

# GIVEN that all files are present for demultiplexing
flow_cell: FlowCellDirectoryData = FlowCellDirectoryData(
tmp_flow_cells_directory_ready_for_demultiplexing_bcl2fastq
tmp_flow_cells_directory_ready_for_demultiplexing_bcl2fastq,
bcl_converter=BclConverter.BCL2FASTQ,
)
add_sample_sheet_path_to_housekeeper(
flow_cell_directory=tmp_flow_cells_directory_ready_for_demultiplexing_bcl2fastq,
Expand All @@ -45,7 +42,12 @@ def test_demultiplex_flow_cell_dry_run(
# WHEN starting demultiplexing from the CLI with dry run flag
result: testing.Result = cli_runner.invoke(
demultiplex_flow_cell,
[str(tmp_flow_cells_directory_ready_for_demultiplexing_bcl2fastq), "--dry-run"],
[
str(tmp_flow_cells_directory_ready_for_demultiplexing_bcl2fastq),
"--dry-run",
"-b",
"bcl2fastq",
],
obj=demultiplexing_context_for_demux,
)

Expand Down

0 comments on commit a4f37a9

Please sign in to comment.