Skip to content

Commit 7a054b3

Browse files
committed
make sample sheet entry one line per bam file
1 parent 4e9f232 commit 7a054b3

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

cg/meta/workflow/nallo.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import logging
44
from cg.constants import Workflow
55
from cg.constants.subject import PlinkPhenotypeStatus, PlinkSex
6-
from cg.constants.tb import AnalysisType
76
from cg.meta.workflow.nf_analysis import NfAnalysisAPI
87
from cg.models.cg_config import CGConfig
98
from cg.models.nallo.nallo import NalloSampleSheetHeaders, NalloSampleSheetEntry, NalloParameters
109
from cg.store.models import CaseSample
10+
from pathlib import Path
1111

1212
LOG = logging.getLogger(__name__)
1313

@@ -47,17 +47,21 @@ def sample_sheet_headers(self) -> list[str]:
4747
def get_sample_sheet_content_per_sample(self, case_sample: CaseSample) -> list[list[str]]:
4848
"""Collect and format information required to build a sample sheet for a single sample."""
4949
bam_unmapped_read_paths = self.get_unmapped_bam_read_paths(sample=case_sample.sample)
50-
sample_sheet_entry = NalloSampleSheetEntry(
51-
project=case_sample.case.internal_id,
52-
sample=case_sample.sample.internal_id,
53-
bam_unmapped_read_paths=bam_unmapped_read_paths,
54-
family_id=case_sample.case.internal_id,
55-
paternal_id=case_sample.get_paternal_sample_id,
56-
maternal_id=case_sample.get_maternal_sample_id,
57-
sex=self.get_sex_code(case_sample.sample.sex),
58-
phenotype=self.get_phenotype_code(case_sample.status),
59-
)
60-
return sample_sheet_entry.reformat_sample_content
50+
sample_sheet_entries = []
51+
52+
for bam_path in bam_unmapped_read_paths:
53+
sample_sheet_entry = NalloSampleSheetEntry(
54+
project=case_sample.case.internal_id,
55+
sample=case_sample.sample.internal_id,
56+
bam_unmapped_read_path=Path(bam_path),
57+
family_id=case_sample.case.internal_id,
58+
paternal_id=case_sample.get_paternal_sample_id or "0",
59+
maternal_id=case_sample.get_maternal_sample_id or "0",
60+
sex=self.get_sex_code(case_sample.sample.sex),
61+
phenotype=self.get_phenotype_code(case_sample.status),
62+
)
63+
sample_sheet_entries.extend(sample_sheet_entry.reformat_sample_content)
64+
return sample_sheet_entries
6165

6266
@staticmethod
6367
def get_phenotype_code(phenotype: str) -> int:

cg/models/nallo/nallo.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from enum import StrEnum
22
from pathlib import Path
33

4-
from pydantic import BaseModel, conlist, field_validator
4+
from pydantic import BaseModel, field_validator
55

66
from cg.exc import NfSampleSheetError
77
from cg.models.nf_analysis import WorkflowParameters
@@ -12,7 +12,7 @@ class NalloSampleSheetEntry(BaseModel):
1212

1313
project: str
1414
sample: str
15-
bam_unmapped_read_paths: conlist(Path)
15+
bam_unmapped_read_path: Path
1616
family_id: str
1717
paternal_id: str
1818
maternal_id: str
@@ -26,7 +26,7 @@ def reformat_sample_content(self) -> list[list[str]]:
2626
[
2727
self.project,
2828
self.sample,
29-
self.bam_unmapped_read_paths,
29+
self.bam_unmapped_read_path,
3030
self.family_id,
3131
self.paternal_id,
3232
self.maternal_id,
@@ -35,14 +35,13 @@ def reformat_sample_content(self) -> list[list[str]]:
3535
]
3636
]
3737

38-
@field_validator("bam_unmapped_read_paths")
38+
@field_validator("bam_unmapped_read_path")
3939
@classmethod
40-
def unmapped_bam_file_exists(cls, bam_paths: list[Path]) -> list[Path]:
40+
def unmapped_bam_file_exists(cls, bam_path: Path) -> Path:
4141
"""Verify that bam files exist."""
42-
for bam_path in bam_paths:
43-
if not bam_path.is_file():
44-
raise NfSampleSheetError(f"Bam file does not exist: {str(bam_path)}")
45-
return bam_paths
42+
if not bam_path.is_file():
43+
raise NfSampleSheetError(f"Bam file does not exist: {str(bam_path)}")
44+
return bam_path
4645

4746

4847
class NalloSampleSheetHeaders(StrEnum):

0 commit comments

Comments
 (0)