Skip to content

Commit

Permalink
Rename family sample model (#2669)(patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
seallard authored Nov 8, 2023
1 parent 4b579c9 commit 3a6fe4f
Show file tree
Hide file tree
Showing 41 changed files with 223 additions and 222 deletions.
6 changes: 3 additions & 3 deletions cg/apps/downsample/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from cg.meta.workflow.downsample.downsample import DownsampleWorkflow
from cg.models.cg_config import CGConfig
from cg.models.downsample.downsample_data import DownsampleData
from cg.store.models import Case, FamilySample, Sample
from cg.store.models import Case, CaseSample, Sample
from cg.utils.calculations import multiply_by_million

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -80,8 +80,8 @@ def _link_downsampled_sample_to_case(
self, downsample_data: DownsampleData, sample: Sample, case: Case
) -> None:
"""Create a link between sample and case in statusDB."""
sample_case_link: FamilySample = self.status_db.relate_sample(
family=case,
sample_case_link: CaseSample = self.status_db.relate_sample(
case=case,
sample=sample,
status=downsample_data.get_sample_status(),
)
Expand Down
6 changes: 3 additions & 3 deletions cg/cli/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Collaboration,
Customer,
Case,
FamilySample,
CaseSample,
Panel,
Sample,
User,
Expand Down Expand Up @@ -320,8 +320,8 @@ def link_sample_to_case(
LOG.error("%s: father not found", father_id)
raise click.Abort

new_record: FamilySample = status_db.relate_sample(
family=case_obj, sample=sample, status=status, mother=mother, father=father
new_record: CaseSample = status_db.relate_sample(
case=case_obj, sample=sample, status=status, mother=mother, father=father
)
status_db.session.add(new_record)
status_db.session.commit()
Expand Down
6 changes: 3 additions & 3 deletions cg/meta/deliver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from cg.constants.constants import DataDelivery
from cg.exc import MissingFilesError
from cg.store import Store
from cg.store.models import Case, FamilySample, Sample
from cg.store.models import Case, CaseSample, Sample

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,7 +77,7 @@ def deliver_files(self, case_obj: Case):
LOG.info(f"Could not find any version for {case_id}")
elif not self.skip_missing_bundle:
raise SyntaxError(f"Could not find any version for {case_id}")
links: list[FamilySample] = self.store.get_case_samples_by_case_id(case_internal_id=case_id)
links: list[CaseSample] = self.store.get_case_samples_by_case_id(case_internal_id=case_id)
if not links:
LOG.warning(f"Could not find any samples linked to case {case_id}")
return
Expand All @@ -98,7 +98,7 @@ def deliver_files(self, case_obj: Case):
if not self.sample_tags:
return

link: FamilySample
link: CaseSample
for link in links:
if link.sample.sequencing_qc or self.deliver_failed_samples:
sample_id: str = link.sample.internal_id
Expand Down
8 changes: 4 additions & 4 deletions cg/meta/orders/case_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cg.meta.orders.submitter import Submitter
from cg.models.orders.order import OrderIn
from cg.models.orders.samples import Of1508Sample, OrderInSample
from cg.store.models import ApplicationVersion, Customer, Case, FamilySample, Sample
from cg.store.models import ApplicationVersion, Customer, Case, CaseSample, Sample

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -265,12 +265,12 @@ def store_items_in_status(
sample_mother: Sample = case_samples.get(sample.get(Pedigree.MOTHER))
sample_father: Sample = case_samples.get(sample.get(Pedigree.FATHER))
with self.status.session.no_autoflush:
case_sample: FamilySample = self.status.get_case_sample_link(
case_sample: CaseSample = self.status.get_case_sample_link(
case_internal_id=status_db_case.internal_id,
sample_internal_id=sample["internal_id"],
)
if not case_sample:
case_sample: FamilySample = self._create_link(
case_sample: CaseSample = self._create_link(
case_obj=status_db_case,
family_samples=case_samples,
father_obj=sample_father,
Expand Down Expand Up @@ -311,7 +311,7 @@ def _update_relationship(father_obj, link_obj, mother_obj, sample):

def _create_link(self, case_obj, family_samples, father_obj, mother_obj, sample):
link_obj = self.status.relate_sample(
family=case_obj,
case=case_obj,
sample=family_samples[sample["name"]],
status=sample["status"],
mother=mother_obj,
Expand Down
8 changes: 4 additions & 4 deletions cg/meta/orders/fastq_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cg.meta.orders.submitter import Submitter
from cg.models.orders.order import OrderIn
from cg.models.orders.sample_base import StatusEnum
from cg.store.models import ApplicationVersion, Customer, Case, FamilySample, Sample
from cg.store.models import ApplicationVersion, Customer, Case, CaseSample, Sample


class FastqSubmitter(Submitter):
Expand Down Expand Up @@ -68,8 +68,8 @@ def create_maf_case(self, sample_obj: Sample) -> None:
case.customer = self.status.get_customer_by_internal_id(
customer_internal_id=CustomerNames.CG_INTERNAL_CUSTOMER
)
relationship: FamilySample = self.status.relate_sample(
family=case, sample=sample_obj, status=StatusEnum.unknown
relationship: CaseSample = self.status.relate_sample(
case=case, sample=sample_obj, status=StatusEnum.unknown
)
self.status.session.add_all([case, relationship])

Expand Down Expand Up @@ -126,7 +126,7 @@ def store_items_in_status(
self.create_maf_case(sample_obj=new_sample)
case.customer = customer
new_relationship = self.status.relate_sample(
family=case, sample=new_sample, status=StatusEnum.unknown
case=case, sample=new_sample, status=StatusEnum.unknown
)
new_delivery = self.status.add_delivery(destination="caesar", sample=new_sample)
self.status.session.add_all([case, new_relationship, new_delivery])
Expand Down
6 changes: 3 additions & 3 deletions cg/meta/orders/metagenome_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from cg.models.orders.order import OrderIn
from cg.models.orders.sample_base import StatusEnum
from cg.models.orders.samples import MetagenomeSample
from cg.store.models import ApplicationVersion, Customer, Case, FamilySample, Sample
from cg.store.models import ApplicationVersion, Customer, Case, CaseSample, Sample


class MetagenomeSubmitter(Submitter):
Expand Down Expand Up @@ -128,8 +128,8 @@ def store_items_in_status(
self.status.session.add(case)
self.status.session.commit()

new_relationship: FamilySample = self.status.relate_sample(
family=case, sample=new_sample, status=StatusEnum.unknown
new_relationship: CaseSample = self.status.relate_sample(
case=case, sample=new_sample, status=StatusEnum.unknown
)
self.status.session.add(new_relationship)

Expand Down
6 changes: 3 additions & 3 deletions cg/meta/orders/microbial_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ApplicationVersion,
Customer,
Case,
FamilySample,
CaseSample,
Organism,
Sample,
)
Expand Down Expand Up @@ -144,8 +144,8 @@ def store_items_in_status(

priority = new_sample.priority
sample_objs.append(new_sample)
link: FamilySample = self.status.relate_sample(
family=case, sample=new_sample, status="unknown"
link: CaseSample = self.status.relate_sample(
case=case, sample=new_sample, status="unknown"
)
self.status.session.add(link)
new_samples.append(new_sample)
Expand Down
6 changes: 3 additions & 3 deletions cg/meta/orders/pool_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ApplicationVersion,
Customer,
Case,
FamilySample,
CaseSample,
Pool,
Sample,
)
Expand Down Expand Up @@ -168,8 +168,8 @@ def store_items_in_status(
no_invoice=True,
)
new_samples.append(new_sample)
link: FamilySample = self.status.relate_sample(
family=case, sample=new_sample, status="unknown"
link: CaseSample = self.status.relate_sample(
case=case, sample=new_sample, status="unknown"
)
self.status.session.add(link)
new_delivery = self.status.add_delivery(destination="caesar", pool=new_pool)
Expand Down
4 changes: 2 additions & 2 deletions cg/meta/report/report_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Application,
ApplicationLimitations,
Case,
FamilySample,
CaseSample,
Sample,
)

Expand Down Expand Up @@ -228,7 +228,7 @@ def get_case_data(
def get_samples_data(self, case: Case, analysis_metadata: AnalysisModel) -> list[SampleModel]:
"""Extracts all the samples associated to a specific case and their attributes."""
samples = list()
case_samples: list[FamilySample] = self.status_db.get_case_samples_by_case_id(
case_samples: list[CaseSample] = self.status_db.get_case_samples_by_case_id(
case_internal_id=case.internal_id
)
for case_sample in case_samples:
Expand Down
6 changes: 3 additions & 3 deletions cg/meta/upload/scout/balsamic_config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from cg.meta.upload.scout.scout_config_builder import ScoutConfigBuilder
from cg.meta.workflow.balsamic import BalsamicAnalysisAPI
from cg.models.scout.scout_load_config import BalsamicLoadConfig, ScoutCancerIndividual
from cg.store.models import Analysis, FamilySample, Sample
from cg.store.models import Analysis, CaseSample, Sample

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -50,7 +50,7 @@ def include_sample_files(self, config_sample: ScoutCancerIndividual) -> None:
hk_tags=self.sample_tags.vcf2cytosure, sample_id=sample_id
)

def build_config_sample(self, case_sample: FamilySample) -> ScoutCancerIndividual:
def build_config_sample(self, case_sample: CaseSample) -> ScoutCancerIndividual:
"""Build a sample with balsamic specific information."""
config_sample = ScoutCancerIndividual()
self.add_common_sample_info(config_sample=config_sample, case_sample=case_sample)
Expand Down Expand Up @@ -91,7 +91,7 @@ def build_load_config(self) -> None:
self.include_case_files()

LOG.info("Building samples")
db_sample: FamilySample
db_sample: CaseSample

for db_sample in self.analysis_obj.case.links:
self.load_config.samples.append(self.build_config_sample(case_sample=db_sample))
6 changes: 3 additions & 3 deletions cg/meta/upload/scout/mip_config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ScoutLoadConfig,
ScoutMipIndividual,
)
from cg.store.models import Analysis, Case, FamilySample
from cg.store.models import Analysis, Case, CaseSample

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -67,7 +67,7 @@ def build_load_config(self, rank_score_threshold: int = 5) -> None:
self.include_case_files()

LOG.info("Building samples")
db_sample: FamilySample
db_sample: CaseSample
for db_sample in self.analysis_obj.case.links:
self.load_config.samples.append(self.build_config_sample(case_sample=db_sample))
self.include_pedigree_picture()
Expand All @@ -82,7 +82,7 @@ def include_pedigree_picture(self) -> None:
else:
LOG.info("family of 1 sample - skip pedigree graph")

def build_config_sample(self, case_sample: FamilySample) -> ScoutMipIndividual:
def build_config_sample(self, case_sample: CaseSample) -> ScoutMipIndividual:
"""Build a sample with mip specific information"""

config_sample = ScoutMipIndividual()
Expand Down
6 changes: 3 additions & 3 deletions cg/meta/upload/scout/rnafusion_config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cg.meta.upload.scout.hk_tags import CaseTags, SampleTags
from cg.meta.upload.scout.scout_config_builder import ScoutConfigBuilder
from cg.models.scout.scout_load_config import RnafusionLoadConfig, ScoutCancerIndividual
from cg.store.models import Analysis, FamilySample
from cg.store.models import Analysis, CaseSample

LOG = logging.getLogger(__name__)

Expand All @@ -36,7 +36,7 @@ def build_load_config(self) -> None:
self.include_case_files()

LOG.info("Building samples")
db_sample: FamilySample
db_sample: CaseSample

for db_sample in self.analysis_obj.case.links:
self.load_config.samples.append(self.build_config_sample(case_sample=db_sample))
Expand All @@ -56,7 +56,7 @@ def _include_file(self, scout_key) -> None:
self.get_file_from_hk(getattr(self.case_tags, scout_key)),
)

def build_config_sample(self, case_sample: FamilySample) -> ScoutCancerIndividual:
def build_config_sample(self, case_sample: CaseSample) -> ScoutCancerIndividual:
"""Build a sample with rnafusion specific information."""
config_sample = ScoutCancerIndividual()

Expand Down
12 changes: 6 additions & 6 deletions cg/meta/upload/scout/scout_config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cg.apps.lims import LimsAPI
from cg.meta.upload.scout.hk_tags import CaseTags, SampleTags
from cg.models.scout.scout_load_config import ScoutIndividual, ScoutLoadConfig
from cg.store.models import Analysis, FamilySample, Sample
from cg.store.models import Analysis, CaseSample, Sample

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -40,7 +40,7 @@ def add_common_info_to_load_config(self) -> None:
self.include_phenotype_terms()

def add_common_sample_info(
self, config_sample: ScoutIndividual, case_sample: FamilySample
self, config_sample: ScoutIndividual, case_sample: CaseSample
) -> None:
"""Add the information to a sample that is common for different analysis types"""
sample_id: str = case_sample.sample.internal_id
Expand All @@ -64,15 +64,15 @@ def add_common_sample_info(
def add_common_sample_files(
self,
config_sample: ScoutIndividual,
case_sample: FamilySample,
case_sample: CaseSample,
) -> None:
"""Add common sample files for different analysis types."""
sample_id: str = case_sample.sample.internal_id
LOG.info(f"Adding common files for sample {sample_id}")
self.include_sample_alignment_file(config_sample=config_sample)
self.include_sample_files(config_sample=config_sample)

def build_config_sample(self, case_sample: FamilySample) -> ScoutIndividual:
def build_config_sample(self, case_sample: CaseSample) -> ScoutIndividual:
"""Build a sample for the scout load config"""
raise NotImplementedError

Expand All @@ -91,7 +91,7 @@ def include_case_files(self) -> None:
def include_phenotype_terms(self) -> None:
LOG.info("Adding phenotype terms to scout load config")
phenotype_terms: set[str] = set()
link_obj: FamilySample
link_obj: CaseSample
for link_obj in self.analysis_obj.case.links:
sample_obj: Sample = link_obj.sample
for phenotype_term in sample_obj.phenotype_terms:
Expand All @@ -107,7 +107,7 @@ def include_phenotype_terms(self) -> None:
def include_phenotype_groups(self) -> None:
LOG.info("Adding phenotype groups to scout load config")
phenotype_groups: set[str] = set()
link_obj: FamilySample
link_obj: CaseSample
for link_obj in self.analysis_obj.case.links:
sample_obj: Sample = link_obj.sample
for phenotype_group in sample_obj.phenotype_groups:
Expand Down
4 changes: 2 additions & 2 deletions cg/meta/workflow/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from cg.meta.workflow.fastq import FastqHandler
from cg.models.analysis import AnalysisModel
from cg.models.cg_config import CGConfig
from cg.store.models import Analysis, BedVersion, Case, FamilySample, Sample
from cg.store.models import Analysis, BedVersion, Case, CaseSample, Sample

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -379,7 +379,7 @@ def decompress_case(self, case_id: str, dry_run: bool) -> None:
self.decompression_running(case_id=case_id)
return
case_obj: Case = self.status_db.get_case_by_internal_id(internal_id=case_id)
link: FamilySample
link: CaseSample
any_decompression_started = False
for link in case_obj.links:
sample_id: str = link.sample.internal_id
Expand Down
6 changes: 3 additions & 3 deletions cg/meta/workflow/balsamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
BalsamicWGSQCMetrics,
)
from cg.models.cg_config import CGConfig
from cg.store.models import Case, FamilySample, Sample
from cg.store.models import Case, CaseSample, Sample
from cg.utils import Process
from cg.utils.utils import build_command_from_dict, get_string_from_list_by_pattern

Expand Down Expand Up @@ -154,7 +154,7 @@ def link_fastq_files(self, case_id: str, dry_run: bool = False) -> None:
case_obj=case_obj, sample_obj=link.sample, concatenate=True
)

def get_concatenated_fastq_path(self, link_object: FamilySample) -> Path:
def get_concatenated_fastq_path(self, link_object: CaseSample) -> Path:
"""Returns path to the concatenated FASTQ file of a sample"""
file_collection: list[dict] = self.gather_file_metadata_for_sample(link_object.sample)
fastq_data = file_collection[0]
Expand Down Expand Up @@ -538,7 +538,7 @@ def get_case_application_type(self, case_id: str) -> str:
return application_types.pop().lower()

def resolve_target_bed(
self, panel_bed: Optional[str], link_object: FamilySample
self, panel_bed: Optional[str], link_object: CaseSample
) -> Optional[str]:
if panel_bed:
return panel_bed
Expand Down
Loading

0 comments on commit 3a6fe4f

Please sign in to comment.