Skip to content

Commit

Permalink
adjust fastq file check
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrOertlin committed Dec 16, 2024
1 parent 5aa028d commit bbc3acb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from pathlib import Path

import re
from cg.apps.lims import LimsAPI
from cg.services.deliver_files.file_fetcher.models import SampleFile
from cg.services.deliver_files.file_formatter.component_files.abstract import ComponentFormatter
Expand Down Expand Up @@ -59,6 +59,20 @@ def format_files(
)
return unique_formatted_files

@staticmethod
def _is_concatenated_file(file_path: Path) -> bool:
"""Check if the file is a concatenated file.
Returns True if the file is a concatenated file, otherwise False.
regex pattern: *._R[1,2]_[0-9]+.fastq.gz
*. is the sample id
_R[1,2] is the read direction
.fastq.gz is the file extension
args:
file_path: The file path to check
"""
pattern = ".*_[1,2].fastq.gz"
return re.fullmatch(pattern, file_path.name) is not None

def _add_lims_metadata_to_file_name(
self, formatted_files: list[FormattedFile], sample_files: list[SampleFile]
) -> list[FormattedFile]:
Expand All @@ -73,7 +87,7 @@ def _add_lims_metadata_to_file_name(
"""
appended_formatted_files: list[FormattedFile] = []
for formatted_file in formatted_files:
if self.file_formatter._is_lane_fastq_file(formatted_file.formatted_path):
if self._is_concatenated_file(formatted_file.formatted_path):
sample_id: str = self._get_sample_id_by_original_path(
original_path=formatted_file.original_path, sample_files=sample_files
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

import pytest
Expand Down Expand Up @@ -361,20 +362,20 @@ def swap_file_paths_with_inbox_paths(


@pytest.fixture
def lims_naming_matadata() -> str:
def lims_naming_metadata() -> str:
return "01_SE100_"


@pytest.fixture
def expected_mutant_formatted_files(
expected_concatenated_fastq_formatted_files, lims_naming_matadata
expected_concatenated_fastq_formatted_files, lims_naming_metadata
) -> list[FormattedFile]:
unique_combinations = []
for formatted_file in expected_concatenated_fastq_formatted_files:
formatted_file.original_path = formatted_file.formatted_path
formatted_file.formatted_path = Path(
formatted_file.formatted_path.parent,
f"{lims_naming_matadata}{formatted_file.formatted_path.name}",
f"{lims_naming_metadata}{formatted_file.formatted_path.name}",
)
if formatted_file not in unique_combinations:
unique_combinations.append(formatted_file)
Expand Down
4 changes: 2 additions & 2 deletions tests/fixture_plugins/delivery_fixtures/path_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@pytest.fixture
def delivery_fastq_file(tmp_path: Path, sample_id: str) -> Path:
file = Path(tmp_path, f"{sample_id}_R1_001{FileExtensions.FASTQ_GZ}")
file = Path(tmp_path, f"{sample_id}_L001_R1_001{FileExtensions.FASTQ_GZ}")
file.touch()
return file

Expand All @@ -34,7 +34,7 @@ def delivery_bam_file(tmp_path: Path, sample_id: str) -> Path:

@pytest.fixture
def delivery_another_fastq_file(tmp_path: Path, another_sample_id: str) -> Path:
file = Path(tmp_path, f"{another_sample_id}_R1_001{FileExtensions.FASTQ_GZ}")
file = Path(tmp_path, f"{another_sample_id}L001_R1_001{FileExtensions.FASTQ_GZ}")
file.touch()
return file

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_component_formatters(
def test_mutant_file_formatter(
mutant_moved_files: list[SampleFile],
expected_mutant_formatted_files: list[FormattedFile],
lims_naming_matadata: str,
lims_naming_metadata: str,
):
# GIVEN existing ticket directory path and a customer inbox
ticket_dir_path: Path = mutant_moved_files[0].file_path.parent
Expand All @@ -115,7 +115,7 @@ def test_mutant_file_formatter(
moved_file.file_path.touch()

lims_mock = Mock()
lims_mock.get_sample_region_and_lab_code.return_value = lims_naming_matadata
lims_mock.get_sample_region_and_lab_code.return_value = lims_naming_metadata
file_formatter = MutantFileFormatter(
file_manager=FileManager(),
file_formatter=SampleFileConcatenationFormatter(
Expand Down

0 comments on commit bbc3acb

Please sign in to comment.