Skip to content

Commit 4f81e76

Browse files
committed
Address comments
1 parent de30b5c commit 4f81e76

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

cg/apps/housekeeper/hk.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def get_files_from_latest_version(self, bundle_name: str, tags: list[str]) -> Qu
403403
return self.files(version=version.id, tags=tags)
404404

405405
def is_fastq_or_spring_in_all_bundles(self, bundle_names: list[str]) -> bool:
406-
"""Return whether or not all FASTQ/SPRING files are included for the given bundles."""
406+
"""Return whether all FASTQ/SPRING files are included for the given bundles."""
407407
sequencing_files_in_hk: dict[str, bool] = {}
408408
if not bundle_names:
409409
return False
@@ -423,11 +423,11 @@ def is_fastq_or_spring_in_all_bundles(self, bundle_names: list[str]) -> bool:
423423
return all(sequencing_files_in_hk.values())
424424

425425
def get_non_archived_files(self, bundle_name: str, tags: Optional[list] = None) -> list[File]:
426-
"""Returns all non-archived_files from a given bundle, tagged with the given tags"""
426+
"""Returns all non-archived files from a given bundle, tagged with the given tags"""
427427
return self._store.get_non_archived_files(bundle_name=bundle_name, tags=tags or [])
428428

429429
def get_archived_files(self, bundle_name: str, tags: list | None = None) -> list[File]:
430-
"""Returns all archived_files from a given bundle, tagged with the given tags"""
430+
"""Returns all archived files from a given bundle, tagged with the given tags"""
431431
return self._store.get_archived_files(bundle_name=bundle_name, tags=tags or [])
432432

433433
def add_archives(self, files: list[Path], archive_task_id: int) -> None:

cg/constants/archiving.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ class ArchiveLocations(StrEnum):
55
"""Demultiplexing related directories and files."""
66

77
KAROLINSKA_BUCKET: str = "karolinska_bucket"
8+
PDC: str = "PDC"

cg/meta/archive/archive.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,21 @@ def archive_all_non_archived_spring_files(
9898
files_and_samples: list[FileAndSample] = self.add_samples_to_files(files_to_archive)
9999

100100
for archive_location in ArchiveLocations:
101-
self.archive_to_location(
102-
files_and_samples=files_and_samples,
103-
archive_location=archive_location,
104-
)
101+
if archive_location != ArchiveLocations.PDC:
102+
self.archive_to_location(
103+
files_and_samples=files_and_samples,
104+
archive_location=archive_location,
105+
)
105106

106-
def retrieve_case(self, case_id: str):
107+
def retrieve_case(self, case_id: str) -> None:
108+
"""Submits jobs to retrieve any archived files belonging to the given case, and updates the Archive entries
109+
with the retrieval job id."""
107110
case = self.status_db.get_case_by_internal_id(case_id)
108-
self.retrieve_samples(self.get_archived_samples(case))
111+
self.retrieve_samples(self.get_samples_with_archived_spring_files(case))
109112

110-
def get_archived_samples(self, case: Case):
113+
def get_samples_with_archived_spring_files(self, case: Case) -> list[Sample]:
114+
"""Returns a list of samples which have archived Spring files, i.e. they have entries in the Archive table
115+
in Housekeeper."""
111116
return [
112117
link.sample
113118
for link in case.links

cg/meta/workflow/analysis.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Priority,
1919
SequencingFileTag,
2020
)
21+
from cg.constants.archiving import ArchiveLocations
2122
from cg.constants.constants import AnalysisType, CaseActions, WorkflowManager
2223
from cg.constants.priority import PRIORITY_TO_SLURM_QOS
2324
from cg.exc import AnalysisNotReadyError, BundleAlreadyAddedError, CgDataError, CgError
@@ -491,7 +492,7 @@ def ensure_flow_cells_on_disk(self, case_id: str) -> None:
491492
self.status_db.request_flow_cells_for_case(case_id)
492493

493494
def is_case_ready_for_analysis(self, case_id: str) -> bool:
494-
if self.get_archive_location_for_case(case_id) == "PDC":
495+
if self.get_archive_location_for_case(case_id) == ArchiveLocations.PDC:
495496
if self._is_flow_cell_check_applicable(
496497
case_id
497498
) and not self.status_db.are_all_flow_cells_on_disk(case_id):
@@ -516,9 +517,9 @@ def prepare_fastq_files(self, case_id: str, dry_run: bool) -> None:
516517
if not self.is_case_ready_for_analysis(case_id):
517518
raise AnalysisNotReadyError("FASTQ file are not present for the analysis to start")
518519

519-
def ensure_files_are_not_archived(self, case_id):
520+
def ensure_files_are_not_archived(self, case_id: str):
520521
"""Checks if any files are archived and submits a job to retrieve any which are."""
521-
if self.get_archive_location_for_case(case_id) == "PDC":
522+
if self.get_archive_location_for_case(case_id) == ArchiveLocations.PDC:
522523
self.ensure_flow_cells_on_disk(case_id)
523524
else:
524525
if not self.are_all_files_present(case_id):
@@ -529,7 +530,9 @@ def ensure_files_are_not_archived(self, case_id):
529530
)
530531
spring_archive_api.retrieve_case(case_id)
531532

532-
def are_all_files_present(self, case_id):
533+
def are_all_files_present(self, case_id: str) -> bool:
534+
"""Returns true if no Spring files are archived in the data location used by the customer tied to the given
535+
case, and false otherwise."""
533536
case: Case = self.status_db.get_case_by_internal_id(case_id)
534537
for sample in [link.sample for link in case.links]:
535538
if (
@@ -540,5 +543,5 @@ def are_all_files_present(self, case_id):
540543
return False
541544
return True
542545

543-
def get_archive_location_for_case(self, case_id: str):
546+
def get_archive_location_for_case(self, case_id: str) -> str:
544547
return self.status_db.get_case_by_internal_id(case_id).customer.data_archive_location

0 commit comments

Comments
 (0)