diff --git a/cg/services/deliver_files/factory.py b/cg/services/deliver_files/factory.py index 509d87a31d..1701cba5fb 100644 --- a/cg/services/deliver_files/factory.py +++ b/cg/services/deliver_files/factory.py @@ -67,10 +67,9 @@ class DeliveryServiceFactory: """ Class to build the delivery services based on case, workflow, delivery type, delivery destination and delivery structure. The delivery destination is used to specify delivery to the customer or for external upload. - It determines how the delivery_base_path is managed and its underlying folder structure. + Workflow is used to specify the workflow of the case and is required for the tag fetcher. Delivery type is used to specify the type of delivery to perform. Delivery structure is used to specify the structure of the delivery. - """ def __init__( @@ -177,8 +176,8 @@ def _get_file_fetcher( def _convert_workflow(self, case: Case) -> Workflow: """Change the workflow of a Microbial Fastq case to Microsalt to allow the concatenation of fastq files. - With the introduction of the microbial-fastq delivery type, an unsupported combination of delivery type and - workflow setup is required. This function makes sure that a raw data workflow with microbial fastq delivery + With the introduction of the microbial-fastq delivery type, an unsupported combination of delivery type and + workflow setup is required. This function makes sure that a raw data workflow with microbial fastq delivery type is treated as a microsalt workflow so that the microbial-fastq sample files can be concatenated. args: case: The case to convert the workflow for diff --git a/cg/services/deliver_files/file_fetcher/analysis_service.py b/cg/services/deliver_files/file_fetcher/analysis_service.py index 3a55f4726c..43e0b2f920 100644 --- a/cg/services/deliver_files/file_fetcher/analysis_service.py +++ b/cg/services/deliver_files/file_fetcher/analysis_service.py @@ -44,7 +44,9 @@ def get_files_to_deliver(self, case_id: str, sample_id: str | None = None) -> De case_id: The case id to deliver files for sample_id: The sample id to deliver files for """ - LOG.debug(f"[FETCH SERVICE] Fetching analysis files for case: {case_id}, sample: {sample_id}") + LOG.debug( + f"[FETCH SERVICE] Fetching analysis files for case: {case_id}, sample: {sample_id}" + ) case: Case = self.status_db.get_case_by_internal_id(internal_id=case_id) analysis_case_files: list[CaseFile] = self._get_analysis_case_delivery_files( case=case, sample_id=sample_id diff --git a/cg/services/deliver_files/file_formatter/files/abstract.py b/cg/services/deliver_files/file_formatter/files/abstract.py index 435922d424..bb1f241b3d 100644 --- a/cg/services/deliver_files/file_formatter/files/abstract.py +++ b/cg/services/deliver_files/file_formatter/files/abstract.py @@ -6,7 +6,7 @@ class FileFormatter(ABC): - + @abstractmethod def format_files( self, moved_files: list[CaseFile | SampleFile], delivery_path: Path diff --git a/cg/services/deliver_files/file_formatter/files/concatenation_service.py b/cg/services/deliver_files/file_formatter/files/concatenation_service.py index 9eb294edd3..05c9b3a520 100644 --- a/cg/services/deliver_files/file_formatter/files/concatenation_service.py +++ b/cg/services/deliver_files/file_formatter/files/concatenation_service.py @@ -78,6 +78,17 @@ def _get_sample_names(sample_files: list[SampleFile]) -> set[str]: """Extract sample names from the sample files.""" return {sample_file.sample_name for sample_file in sample_files} + def _create_sample_directories(self, sample_names: set[str], delivery_path: Path) -> None: + """Create directories for each sample name only if the file name formatter is the NestedSampleFileFormatter. + args: + sample_names: set[str]: Set of sample names. + delivery_path: Path: Path to the delivery directory. + """ + if not isinstance(self.path_name_formatter, NestedStructurePathFormatter): + return + for sample_name in sample_names: + self.file_manager.create_directories(base_path=delivery_path, directories={sample_name}) + def _format_sample_file_paths(self, sample_files: list[SampleFile]) -> list[FormattedFile]: """ Return a list of formatted sample files. @@ -108,17 +119,6 @@ def _rename_original_files(self, formatted_files: list[FormattedFile]) -> None: src=formatted_file.original_path, dst=formatted_file.formatted_path ) - def _create_sample_directories(self, sample_names: set[str], delivery_path: Path) -> None: - """Create directories for each sample name only if the file name formatter is the NestedSampleFileFormatter. - args: - sample_names: set[str]: Set of sample names. - delivery_path: Path: Path to the delivery directory. - """ - if not isinstance(self.path_name_formatter, NestedStructurePathFormatter): - return - for sample_name in sample_names: - self.file_manager.create_directories(base_path=delivery_path, directories={sample_name}) - def _concatenate_fastq_files( self, delivery_path: Path, sample_names: set[str] ) -> dict[Path, Path]: @@ -246,7 +246,7 @@ def _group_fastq_files_per_sample( } for fastq_file in fastq_files: sample_fastq_files[fastq_file.sample_name].append(fastq_file) - self._all_sample_fastq_file_share_same_directory(sample_fastq_files=sample_fastq_files) + self._validate_sample_fastq_file_share_same_directory(sample_fastq_files=sample_fastq_files) return sample_fastq_files def _replace_fastq_paths( @@ -266,12 +266,13 @@ def _replace_fastq_paths( formatted_file.formatted_path = concatenation_maps[formatted_file.formatted_path] @staticmethod - def _all_sample_fastq_file_share_same_directory( + def _validate_sample_fastq_file_share_same_directory( sample_fastq_files: dict[str, list[FastqFile]] ) -> None: """ Assert that all fastq files for a sample share the same directory. This is to ensure that the files are concatenated within the expected directory path. + raises: ValueError if the fastq files are not in the same directory. args: sample_fastq_files: dict[str, list[FastqFile]]: Dictionary of sample names and their fastq files. """ diff --git a/cg/services/deliver_files/utils.py b/cg/services/deliver_files/utils.py index 615c1f9d06..69452ef988 100644 --- a/cg/services/deliver_files/utils.py +++ b/cg/services/deliver_files/utils.py @@ -97,7 +97,9 @@ def update_file_paths( file_model.file_path = Path(target_dir, file_model.file_path.name) return file_models - def move_and_update_files(self, file_models: list[CaseFile | SampleFile], target_dir: Path) -> list[CaseFile | SampleFile]: + def move_and_update_files( + self, file_models: list[CaseFile | SampleFile], target_dir: Path + ) -> list[CaseFile | SampleFile]: """Move files to the target directory and update the file paths. args: file_models: The file models that contain the files to move. diff --git a/tests/services/file_delivery/file_formatter/files/test_formatter_utils.py b/tests/services/file_delivery/file_formatter/files/test_formatter_utils.py index 2dab8edda7..ce440e10d7 100644 --- a/tests/services/file_delivery/file_formatter/files/test_formatter_utils.py +++ b/tests/services/file_delivery/file_formatter/files/test_formatter_utils.py @@ -70,7 +70,7 @@ ), ], ) -def test_component_formatters( +def test_file_formatters( moved_files: list[CaseFile | SampleFile], expected_formatted_files: list[FormattedFile], file_formatter: FileFormatter,