Skip to content

Commit

Permalink
Rename Family to Case (#2655)(patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
seallard authored Nov 7, 2023
1 parent ed42832 commit cccee5e
Show file tree
Hide file tree
Showing 134 changed files with 722 additions and 735 deletions.
6 changes: 3 additions & 3 deletions alembic/versions/20750539a335_add_ticket_to_families.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Base = declarative_base()


class Family(Base):
class Case(Base):
__tablename__ = "family"

id = sa.Column(sa.types.Integer, primary_key=True)
Expand All @@ -37,7 +37,7 @@ class FamilySample(Base):
family_id = sa.Column(sa.ForeignKey("family.id", ondelete="CASCADE"), nullable=False)
sample_id = sa.Column(sa.ForeignKey("sample.id", ondelete="CASCADE"), nullable=False)

family = sa.orm.relationship("Family", backref="links")
family = sa.orm.relationship("Case", backref="links")
sample = sa.orm.relationship("Sample", foreign_keys=[sample_id], backref="links")


Expand All @@ -60,7 +60,7 @@ def upgrade():
op.add_column("family", sa.Column("tickets", type_=mysql.VARCHAR(128), nullable=True))
bind = op.get_bind()
session = sa.orm.Session(bind=bind)
for family in session.query(Family):
for family in session.query(Case):
if len(family.links) == 0:
continue
family.tickets = sorted(
Expand Down
6 changes: 3 additions & 3 deletions alembic/versions/2968d39ac35f_changes_in_delivery_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}


class Family(Base):
class Case(Base):
__tablename__ = "family"
id = Column(types.Integer, primary_key=True)
data_delivery = Column(types.VARCHAR(64))
Expand All @@ -64,7 +64,7 @@ def upgrade():
op.alter_column("family", "data_delivery", type_=types.VARCHAR(64))
bind = op.get_bind()
session = sa.orm.Session(bind=bind)
for case in session.query(Family):
for case in session.query(Case):
if case.data_delivery in removed_options:
case.data_delivery = update_map[case.data_delivery]

Expand All @@ -74,7 +74,7 @@ def upgrade():
def downgrade():
bind = op.get_bind()
session = sa.orm.Session(bind=bind)
for case in session.query(Family):
for case in session.query(Case):
if case.data_delivery == "":
case.data_delivery = None
if case.data_delivery in added_options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
depends_on = None


class Family(Base):
class Case(Base):
__tablename__ = "family"

id = sa.Column(sa.types.Integer, primary_key=True)
Expand Down Expand Up @@ -52,9 +52,9 @@ def upgrade():
op.alter_column("analysis", "pipeline", type_=new_enum)

for family in (
session.query(Family)
.filter(Family.data_delivery == str(DataDelivery.FASTQ))
.filter(Family.data_analysis == "")
session.query(Case)
.filter(Case.data_delivery == str(DataDelivery.FASTQ))
.filter(Case.data_analysis == "")
):
print(f"Altering family: {str(family)}")
family.data_analysis = str(Pipeline.SARS_COV_2)
Expand Down
4 changes: 2 additions & 2 deletions alembic/versions/7e344b9438bf_petname_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Base = declarative_base()


class Family(Base):
class Case(Base):
__tablename__ = "family"

id = sa.Column(sa.types.Integer, primary_key=True)
Expand All @@ -36,7 +36,7 @@ def __str__(self) -> str:


def find_family_by_avatar_url(avatar_url, session):
return session.query(Family).filter_by(avatar_url=avatar_url).first()
return session.query(Case).filter_by(avatar_url=avatar_url).first()


def upgrade():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Analysis(Base):
pipeline = sa.Column(sa.types.Enum(*list(Pipeline)))


class Family(Base):
class Case(Base):
__tablename__ = "family"
id = sa.Column(sa.types.Integer, primary_key=True)
data_analysis = sa.Column(sa.types.Enum(*list(Pipeline)))
Expand All @@ -64,6 +64,6 @@ def downgrade():
session = sa.orm.Session(bind=bind)
for analysis in session.query(Analysis).filter(Analysis.pipeline == "taxprofiler"):
analysis.pipeline = "fastq"
for family in session.query(Family).filter(Family.data_analysis == "taxprofiler"):
for family in session.query(Case).filter(Case.data_analysis == "taxprofiler"):
family.data_analysis = "fastq"
session.commit()
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Analysis(Base):
pipeline = sa.Column(sa.types.Enum(*list(Pipeline)))


class Family(Base):
class Case(Base):
__tablename__ = "family"
id = sa.Column(sa.types.Integer, primary_key=True)
data_analysis = sa.Column(sa.types.Enum(*list(Pipeline)))
Expand All @@ -68,8 +68,8 @@ def downgrade():
f"Changing pipeline for Analysis {Analysis.family.internal_id}, {Analysis.completed_at} to mip-dna"
)
analysis.pipeline = "mip-dna"
for family in session.query(Family).filter(Family.data_analysis == "raredisease"):
print(f"Changing data_analysis for Family {family.internal_id} to mip-dna")
for family in session.query(Case).filter(Case.data_analysis == "raredisease"):
print(f"Changing data_analysis for Case {family.internal_id} to mip-dna")
family.data_analysis = "mip-dna"
op.alter_column("family", "data_analysis", type_=old_analysis_enum)
op.alter_column("analysis", "pipeline", type_=old_analysis_enum)
Expand Down
28 changes: 14 additions & 14 deletions alembic/versions/998be2e367cf_fix_mip_on_fastq_wgs_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Customer(Base):
id = sa.Column(sa.types.Integer, primary_key=True)


class Family(Base):
class Case(Base):
__tablename__ = "family"

id = sa.Column(sa.types.Integer, primary_key=True)
Expand Down Expand Up @@ -63,7 +63,7 @@ class FamilySample(Base):
mother_id = sa.Column(sa.ForeignKey("sample.id"))
father_id = sa.Column(sa.ForeignKey("sample.id"))

family = orm.relationship("Family", backref="links")
family = orm.relationship("Case", backref="links")
sample = orm.relationship("Sample", foreign_keys=[sample_id], backref="links")
mother = orm.relationship("Sample", foreign_keys=[mother_id], backref="mother_links")
father = orm.relationship("Sample", foreign_keys=[father_id], backref="father_links")
Expand Down Expand Up @@ -107,12 +107,12 @@ def upgrade():
count = 0
# change records that should have been run with MIP for MAF
for family in (
session.query(Family)
.filter(Family.customer_id == 1)
.filter(Family.data_delivery == DataDelivery.FASTQ)
.filter(Family.data_analysis == Pipeline.FASTQ)
.filter(Family.priority == "research")
.filter(Family.ordered_at >= datetime(year=2021, month=2, day=2))
session.query(Case)
.filter(Case.customer_id == 1)
.filter(Case.data_delivery == DataDelivery.FASTQ)
.filter(Case.data_analysis == Pipeline.FASTQ)
.filter(Case.priority == "research")
.filter(Case.ordered_at >= datetime(year=2021, month=2, day=2))
):
if len(family.links) > 1:
print(f"skipping case that has more than one link: {family}")
Expand All @@ -139,12 +139,12 @@ def downgrade():

count = 0
for family in (
session.query(Family)
.filter(Family.customer_id == 1)
.filter(Family.data_delivery == DataDelivery.FASTQ)
.filter(Family.data_analysis == Pipeline.MIP_DNA)
.filter(Family.priority == "research")
.filter(Family.ordered_at >= datetime(year=2021, month=2, day=2))
session.query(Case)
.filter(Case.customer_id == 1)
.filter(Case.data_delivery == DataDelivery.FASTQ)
.filter(Case.data_analysis == Pipeline.MIP_DNA)
.filter(Case.priority == "research")
.filter(Case.ordered_at >= datetime(year=2021, month=2, day=2))
):
if len(family.links) > 1:
print(f"skipping case that has more than one link: {family}")
Expand Down
24 changes: 12 additions & 12 deletions alembic/versions/e9df15a35de4_fix_tumour_not_to_maf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Customer(Base):
id = sa.Column(sa.types.Integer, primary_key=True)


class Family(Base):
class Case(Base):
__tablename__ = "family"

id = sa.Column(sa.types.Integer, primary_key=True)
Expand Down Expand Up @@ -63,7 +63,7 @@ class FamilySample(Base):
mother_id = sa.Column(sa.ForeignKey("sample.id"))
father_id = sa.Column(sa.ForeignKey("sample.id"))

family = orm.relationship("Family", backref="links")
family = orm.relationship("Case", backref="links")
sample = orm.relationship("Sample", foreign_keys=[sample_id], backref="links")
mother = orm.relationship("Sample", foreign_keys=[mother_id], backref="mother_links")
father = orm.relationship("Sample", foreign_keys=[father_id], backref="father_links")
Expand Down Expand Up @@ -108,11 +108,11 @@ def upgrade():
count = 0
# change records that should is tumour and should not be sent to MAF
for family in (
session.query(Family)
.filter(Family.customer_id == 1)
.filter(Family.data_delivery == DataDelivery.FASTQ)
.filter(Family.data_analysis == Pipeline.MIP_DNA)
.filter(Family.priority == "research")
session.query(Case)
.filter(Case.customer_id == 1)
.filter(Case.data_delivery == DataDelivery.FASTQ)
.filter(Case.data_analysis == Pipeline.MIP_DNA)
.filter(Case.priority == "research")
):
if len(family.links) > 1:
print(f"skipping case that has more than one link: {family}")
Expand Down Expand Up @@ -142,11 +142,11 @@ def downgrade():

count = 0
for family in (
session.query(Family)
.filter(Family.customer_id == 1)
.filter(Family.data_delivery == DataDelivery.FASTQ)
.filter(Family.data_analysis == Pipeline.FASTQ)
.filter(Family.priority == "research")
session.query(Case)
.filter(Case.customer_id == 1)
.filter(Case.data_delivery == DataDelivery.FASTQ)
.filter(Case.data_analysis == Pipeline.FASTQ)
.filter(Case.priority == "research")
):
if len(family.links) > 1:
print(f"skipping case that has more than one link: {family}")
Expand Down
8 changes: 4 additions & 4 deletions alembic/versions/fab30255b84f_move_synopsis_to_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
depends_on = None


class Family(Base):
class Case(Base):
__tablename__ = "family"

id = sa.Column(sa.types.Integer, primary_key=True)
Expand Down Expand Up @@ -62,7 +62,7 @@ class FamilySample(Base):
mother_id = sa.Column(sa.ForeignKey("sample.id"))
father_id = sa.Column(sa.ForeignKey("sample.id"))

family = orm.relationship("Family", backref="links")
family = orm.relationship("Case", backref="links")
sample = orm.relationship("Sample", foreign_keys=[sample_id], backref="links")
mother = orm.relationship("Sample", foreign_keys=[mother_id], backref="mother_links")
father = orm.relationship("Sample", foreign_keys=[father_id], backref="father_links")
Expand Down Expand Up @@ -122,10 +122,10 @@ def downgrade():
op.add_column("sample", sa.Column("_cohorts", sa.TEXT))

# copy data from family._synopsis to sample._synopsis
for family in session.query(Family).filter(Family._synopsis.isnot(None)):
for family in session.query(Case).filter(Case._synopsis.isnot(None)):
for link in family.links:
link.sample._synopsis = family._synopsis
for family in session.query(Family).filter(Family._cohorts.isnot(None)):
for family in session.query(Case).filter(Case._cohorts.isnot(None)):
for link in family.links:
link.sample._cohorts = family._cohorts
session.commit()
Expand Down
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 Family, FamilySample, Sample
from cg.store.models import Case, FamilySample, Sample
from cg.utils.calculations import multiply_by_million

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -67,7 +67,7 @@ def store_downsampled_case(self, downsample_data: DownsampleData) -> None:
"""
Add a down sampled case entry to StatusDB.
"""
downsampled_case: Family = downsample_data.downsampled_case
downsampled_case: Case = downsample_data.downsampled_case
if self.status_db.case_with_name_exists(case_name=downsampled_case.name):
LOG.info(f"Case with name {downsampled_case.name} already exists in StatusDB.")
return
Expand All @@ -77,7 +77,7 @@ def store_downsampled_case(self, downsample_data: DownsampleData) -> None:
LOG.info(f"New down sampled case created: {downsampled_case.internal_id}")

def _link_downsampled_sample_to_case(
self, downsample_data: DownsampleData, sample: Sample, case: Family
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(
Expand Down
6 changes: 3 additions & 3 deletions cg/cli/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ApplicationVersion,
Collaboration,
Customer,
Family,
Case,
FamilySample,
Panel,
Sample,
Expand Down Expand Up @@ -264,7 +264,7 @@ def add_case(
LOG.error(f"{panel_abbreviation}: panel not found")
raise click.Abort

new_case: Family = status_db.add_case(
new_case: Case = status_db.add_case(
data_analysis=data_analysis,
data_delivery=data_delivery,
name=name,
Expand Down Expand Up @@ -298,7 +298,7 @@ def link_sample_to_case(
status_db: Store = context.status_db
mother: Optional[Sample] = None
father: Optional[Sample] = None
case_obj: Family = status_db.get_case_by_internal_id(internal_id=case_id)
case_obj: Case = status_db.get_case_by_internal_id(internal_id=case_id)
if case_obj is None:
LOG.error("%s: family not found", case_id)
raise click.Abort
Expand Down
6 changes: 3 additions & 3 deletions cg/cli/compress/fastq.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from cg.meta.compress import CompressAPI
from cg.models.cg_config import CGConfig
from cg.store import Store
from cg.store.models import Family, Sample
from cg.store.models import Case, Sample

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -51,7 +51,7 @@ def fastq_cmd(
LOG.info("Running compress FASTQ")
compress_api: CompressAPI = context.meta_apis["compress_api"]
store: Store = context.status_db
cases: list[Family] = get_cases_to_process(case_id=case_id, days_back=days_back, store=store)
cases: list[Case] = get_cases_to_process(case_id=case_id, days_back=days_back, store=store)
if not cases:
LOG.info("No cases to compress")
return None
Expand Down Expand Up @@ -84,7 +84,7 @@ def clean_fastq(context: CGConfig, case_id: Optional[str], days_back: int, dry_r
store: Store = context.status_db
update_compress_api(compress_api, dry_run=dry_run)

cases: list[Family] = get_cases_to_process(case_id=case_id, days_back=days_back, store=store)
cases: list[Case] = get_cases_to_process(case_id=case_id, days_back=days_back, store=store)
if not cases:
return

Expand Down
14 changes: 6 additions & 8 deletions cg/cli/compress/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,25 @@
from cg.meta.compress import CompressAPI
from cg.meta.compress.files import get_spring_paths
from cg.store import Store
from cg.store.models import Family
from cg.store.models import Case
from cg.utils.date import get_date_days_ago

LOG = logging.getLogger(__name__)


def get_cases_to_process(
days_back: int, store: Store, case_id: Optional[str] = None
) -> Optional[list[Family]]:
def get_cases_to_process(days_back: int, store: Store, case_id: Optional[str] = None) -> list[Case]:
"""Return cases to process."""
cases: list[Family] = []
cases: list[Case] = []
if case_id:
case: Family = store.get_case_by_internal_id(case_id)
case: Case = store.get_case_by_internal_id(case_id)
if not case:
LOG.warning(f"Could not find case {case_id}")
return
if case.is_compressible:
cases.append(case)
else:
date_threshold: dt.datetime = get_date_days_ago(days_ago=days_back)
cases: list[Family] = store.get_cases_to_compress(date_threshold=date_threshold)
cases: list[Case] = store.get_cases_to_compress(date_threshold=date_threshold)
return cases


Expand Down Expand Up @@ -125,7 +123,7 @@ def get_true_dir(dir_path: Path) -> Optional[Path]:

def compress_sample_fastqs_in_cases(
compress_api: CompressAPI,
cases: list[Family],
cases: list[Case],
dry_run: bool,
number_of_conversions: int,
hours: int = None,
Expand Down
Loading

0 comments on commit cccee5e

Please sign in to comment.