Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch tissue type from original sample #3979

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cg/meta/workflow/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ def get_case_source_type(self, case_id: str) -> str | None:
Raises:
CgError: If different sources are set for the samples linked to a case.
"""
sample_ids: Iterator[str] = self.status_db.get_sample_ids_by_case_id(case_id=case_id)
sample_ids: Iterator[str] = self.status_db.get_original_sample_ids_by_case_id(
case_id=case_id
)
source_types: set[str | None] = {
self.lims_api.get_source(sample_id) for sample_id in sample_ids
}
Expand Down
10 changes: 10 additions & 0 deletions cg/store/crud/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ def get_sample_ids_by_case_id(self, case_id: str = None) -> Iterator[str]:
for link in case.links:
yield link.sample.internal_id

def get_original_sample_ids_by_case_id(self, case_id: str = None) -> Iterator[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a unit test for this function?

"""Return original sample ids (go to original sample id for downloaded samples) from case id."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Return original sample ids (go to original sample id for downloaded samples) from case id."""
"""Return original sample id from case id."""

case: Case = self.get_case_by_internal_id(internal_id=case_id)
self._is_case_found(case=case, case_id=case_id)
for link in case.links:
if link.sample.from_sample:
original_sample: Sample = link.sample.from_sample
yield original_sample.internal_id
yield link.sample.internal_id
Comment on lines +348 to +356
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we require.a yield here as we only fetch one id it seems?

Suggested change
def get_original_sample_ids_by_case_id(self, case_id: str = None) -> Iterator[str]:
"""Return original sample ids (go to original sample id for downloaded samples) from case id."""
case: Case = self.get_case_by_internal_id(internal_id=case_id)
self._is_case_found(case=case, case_id=case_id)
for link in case.links:
if link.sample.from_sample:
original_sample: Sample = link.sample.from_sample
yield original_sample.internal_id
yield link.sample.internal_id
def get_original_sample_ids_by_case_id(self, case_id: str = None) -> str:
"""Return original sample ids (go to original sample id for downloaded samples) from case id."""
case: Case = self.get_case_by_internal_id(internal_id=case_id)
self._is_case_found(case=case, case_id=case_id)
for link in case.links:
if link.sample.from_sample:
original_sample: Sample = link.sample.from_sample
return original_sample.internal_id
return link.sample.internal_id


def get_case_by_name_and_customer(self, customer: Customer, case_name: str) -> Case:
"""Find a case by case name within a customer."""
return apply_case_filter(
Expand Down
Loading