Skip to content

Commit

Permalink
Refactor pipeline to workflow (#2885)
Browse files Browse the repository at this point in the history
### Changed

- Refactor Pipeline to workflow for enum
- Remove casting to str
  • Loading branch information
henrikstranneheim authored Feb 1, 2024
1 parent 5876541 commit c29d718
Show file tree
Hide file tree
Showing 136 changed files with 607 additions and 625 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sqlalchemy as sa

from alembic import op
from cg.constants import Pipeline
from cg.constants import Workflow

# revision identifiers, used by Alembic.
revision = "d241d8c493fb"
Expand All @@ -21,7 +21,7 @@
def upgrade():
op.add_column(
table_name="order",
column=sa.Column("workflow", sa.Enum(*tuple(Pipeline)), nullable=False),
column=sa.Column("workflow", sa.Enum(*tuple(Workflow)), nullable=False),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sqlalchemy.dialects import mysql

from alembic import op
from cg.constants import Pipeline
from cg.constants import Workflow
from cg.store.models import Analysis, Case

# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -58,12 +58,12 @@ def upgrade():

for case in session.query(Case).filter(Case.data_analysis == "sars-cov-2"):
print(f"Altering case: {str(case)}")
case.data_analysis = str(Pipeline.MUTANT)
case.data_analysis = str(Workflow.MUTANT)
print(f"Altered case: {str(case)}")

for analysis in session.query(Analysis).filter(Analysis.pipeline == "sars-cov-2"):
print(f"Altering analysis: {str(analysis)}")
analysis.pipeline = str(Pipeline.MUTANT)
analysis.pipeline = str(Workflow.MUTANT)
print(f"Altered analysis: {str(analysis)}")

session.commit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sqlalchemy.orm import declarative_base

from alembic import op
from cg.constants import DataDelivery, Pipeline
from cg.constants import DataDelivery, Workflow

Base = declarative_base()

Expand All @@ -29,7 +29,7 @@ class Case(Base):
id = sa.Column(sa.types.Integer, primary_key=True)
internal_id = sa.Column(sa.types.String(32), unique=True, nullable=False)
name = sa.Column(sa.types.String(128), nullable=False)
data_analysis = Column(types.Enum(*list(Pipeline)))
data_analysis = Column(types.Enum(*list(Workflow)))
data_delivery = Column(types.Enum(*list(DataDelivery)))

def __str__(self) -> str:
Expand Down Expand Up @@ -58,7 +58,7 @@ def upgrade():
.filter(Case.data_analysis == "")
):
print(f"Altering family: {str(family)}")
family.data_analysis = str(Pipeline.SARS_COV_2)
family.data_analysis = str(Workflow.SARS_COV_2)
print(f"Altered family: {str(family)}")

session.commit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sqlalchemy.orm import declarative_base

from alembic import op
from cg.constants import Pipeline
from cg.constants import Workflow

# revision identifiers, used by Alembic.
revision = "9008aa5065b4"
Expand Down Expand Up @@ -46,13 +46,13 @@
class Analysis(Base):
__tablename__ = "analysis"
id = sa.Column(sa.types.Integer, primary_key=True)
pipeline = sa.Column(sa.types.Enum(*list(Pipeline)))
pipeline = sa.Column(sa.types.Enum(*list(Workflow)))


class Case(Base):
__tablename__ = "family"
id = sa.Column(sa.types.Integer, primary_key=True)
data_analysis = sa.Column(sa.types.Enum(*list(Pipeline)))
data_analysis = sa.Column(sa.types.Enum(*list(Workflow)))


def upgrade():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sqlalchemy.orm import declarative_base

from alembic import op
from cg.constants import Pipeline
from cg.constants import Workflow

# revision identifiers, used by Alembic.
revision = "9073c61bc72b"
Expand Down Expand Up @@ -47,13 +47,13 @@
class Analysis(Base):
__tablename__ = "analysis"
id = sa.Column(sa.types.Integer, primary_key=True)
pipeline = sa.Column(sa.types.Enum(*list(Pipeline)))
pipeline = sa.Column(sa.types.Enum(*list(Workflow)))


class Case(Base):
__tablename__ = "family"
id = sa.Column(sa.types.Integer, primary_key=True)
data_analysis = sa.Column(sa.types.Enum(*list(Pipeline)))
data_analysis = sa.Column(sa.types.Enum(*list(Workflow)))


def upgrade():
Expand Down
12 changes: 6 additions & 6 deletions alembic/versions/998be2e367cf_fix_mip_on_fastq_wgs_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sqlalchemy.orm import declarative_base

from alembic import op
from cg.constants import PREP_CATEGORIES, DataDelivery, Pipeline
from cg.constants import PREP_CATEGORIES, DataDelivery, Workflow

Base = declarative_base()

Expand All @@ -38,7 +38,7 @@ class Case(Base):
name = sa.Column(sa.types.String(128), nullable=False)
customer_id = sa.Column(sa.ForeignKey("customer.id", ondelete="CASCADE"), nullable=False)
customer = orm.relationship(Customer, foreign_keys=[customer_id])
data_analysis = sa.Column(sa.types.Enum(*list(Pipeline)))
data_analysis = sa.Column(sa.types.Enum(*list(Workflow)))
data_delivery = sa.Column(sa.types.Enum(*list(DataDelivery)))
priority = sa.Column(sa.types.Integer, default=1, nullable=False)
_panels = sa.Column(sa.types.Text)
Expand Down Expand Up @@ -111,7 +111,7 @@ def upgrade():
session.query(Case)
.filter(Case.customer_id == 1)
.filter(Case.data_delivery == DataDelivery.FASTQ)
.filter(Case.data_analysis == Pipeline.FASTQ)
.filter(Case.data_analysis == Workflow.FASTQ)
.filter(Case.priority == "research")
.filter(Case.ordered_at >= datetime(year=2021, month=2, day=2))
):
Expand All @@ -126,7 +126,7 @@ def upgrade():
and sample.name == family.name
):
print(f"changing data analysis from FASTQ to MIP for: {family}")
family.data_analysis = Pipeline.MIP_DNA
family.data_analysis = Workflow.MIP_DNA
count += 1

session.commit()
Expand All @@ -143,7 +143,7 @@ def downgrade():
session.query(Case)
.filter(Case.customer_id == 1)
.filter(Case.data_delivery == DataDelivery.FASTQ)
.filter(Case.data_analysis == Pipeline.MIP_DNA)
.filter(Case.data_analysis == Workflow.MIP_DNA)
.filter(Case.priority == "research")
.filter(Case.ordered_at >= datetime(year=2021, month=2, day=2))
):
Expand All @@ -158,7 +158,7 @@ def downgrade():
and sample.name == family.name
):
print(f"changing data analysis from MIP to FASTQ for: {family}")
family.data_analysis = Pipeline.FASTQ
family.data_analysis = Workflow.FASTQ
count += 1

session.commit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sqlalchemy as sa

from alembic import op
from cg.constants.constants import Pipeline
from cg.constants.constants import Workflow

# revision identifiers, used by Alembic.
revision = "e853d21feaa0"
Expand All @@ -30,7 +30,7 @@ def upgrade():
sa.ForeignKey("application.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("pipeline", sa.Enum(*list(Pipeline)), nullable=False),
sa.Column("pipeline", sa.Enum(*list(Workflow)), nullable=False),
sa.Column("limitations", sa.Text()),
sa.Column("comment", sa.Text()),
sa.Column("created_at", sa.DateTime(), server_default=sa.func.now()),
Expand Down
12 changes: 6 additions & 6 deletions alembic/versions/e9df15a35de4_fix_tumour_not_to_maf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sqlalchemy.orm import declarative_base

from alembic import op
from cg.constants import PREP_CATEGORIES, DataDelivery, Pipeline
from cg.constants import PREP_CATEGORIES, DataDelivery, Workflow

# revision identifiers, used by Alembic.
revision = "e9df15a35de4"
Expand All @@ -38,7 +38,7 @@ class Case(Base):
name = sa.Column(sa.types.String(128), nullable=False)
customer_id = sa.Column(sa.ForeignKey("customer.id", ondelete="CASCADE"), nullable=False)
customer = orm.relationship(Customer, foreign_keys=[customer_id])
data_analysis = sa.Column(sa.types.Enum(*list(Pipeline)))
data_analysis = sa.Column(sa.types.Enum(*list(Workflow)))
data_delivery = sa.Column(sa.types.Enum(*list(DataDelivery)))
priority = sa.Column(sa.types.Integer, default=1, nullable=False)
_panels = sa.Column(sa.types.Text)
Expand Down Expand Up @@ -112,7 +112,7 @@ def upgrade():
session.query(Case)
.filter(Case.customer_id == 1)
.filter(Case.data_delivery == DataDelivery.FASTQ)
.filter(Case.data_analysis == Pipeline.MIP_DNA)
.filter(Case.data_analysis == Workflow.MIP_DNA)
.filter(Case.priority == "research")
):
if len(family.links) > 1:
Expand All @@ -130,7 +130,7 @@ def upgrade():
and sample.name == family.name
):
print(f"changing data analysis from MIP to FASTQ for: {family}")
family.data_analysis = Pipeline.FASTQ
family.data_analysis = Workflow.FASTQ
count += 1

session.commit()
Expand All @@ -146,7 +146,7 @@ def downgrade():
session.query(Case)
.filter(Case.customer_id == 1)
.filter(Case.data_delivery == DataDelivery.FASTQ)
.filter(Case.data_analysis == Pipeline.FASTQ)
.filter(Case.data_analysis == Workflow.FASTQ)
.filter(Case.priority == "research")
):
if len(family.links) > 1:
Expand All @@ -164,7 +164,7 @@ def downgrade():
and sample.name == family.name
):
print(f"changing data analysis from FASTQ to MIP-DNA for: {family}")
family.data_analysis = Pipeline.MIP_DNA
family.data_analysis = Workflow.MIP_DNA
count += 1

session.commit()
Expand Down
4 changes: 2 additions & 2 deletions cg/apps/demultiplex/demultiplex_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from cg.apps.housekeeper.hk import HousekeeperAPI
from cg.apps.slurm.slurm_api import SlurmAPI
from cg.apps.tb import TrailblazerAPI
from cg.constants.constants import FileFormat, Pipeline
from cg.constants.constants import FileFormat, Workflow
from cg.constants.demultiplexing import BclConverter, DemultiplexingDirsAndFiles
from cg.constants.priority import SlurmQos
from cg.constants.tb import AnalysisTypes
Expand Down Expand Up @@ -207,7 +207,7 @@ def add_to_trailblazer(
out_dir=flow_cell.trailblazer_config_path.parent.as_posix(),
slurm_quality_of_service=self.slurm_quality_of_service,
email=self.mail,
data_analysis=str(Pipeline.DEMULTIPLEX),
data_analysis=Workflow.DEMULTIPLEX,
)

def start_demultiplexing(self, flow_cell: FlowCellDirectoryData):
Expand Down
8 changes: 4 additions & 4 deletions cg/apps/orderform/json_orderform_parser.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from cg.apps.orderform.orderform_parser import OrderformParser
from cg.constants import DataDelivery, Pipeline
from cg.constants import DataDelivery, Workflow
from cg.exc import OrderFormError
from cg.models.orders.json_sample import JsonSample
from cg.models.orders.order import OrderType


class JsonOrderformParser(OrderformParser):
ACCEPTED_DATA_ANALYSES: list[str] = [
str(Pipeline.MIP_DNA),
str(Pipeline.FLUFFY),
str(Pipeline.BALSAMIC),
Workflow.MIP_DNA,
Workflow.FLUFFY,
Workflow.BALSAMIC,
]
NO_VALUE: str = "no_value"
samples: list[JsonSample] = []
Expand Down
6 changes: 3 additions & 3 deletions cg/apps/tb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from google.auth import jwt
from google.auth.crypt import RSASigner
from cg.apps.tb.dto.create_job_request import CreateJobRequest

from cg.apps.tb.dto.create_job_request import CreateJobRequest
from cg.apps.tb.models import TrailblazerAnalysis
from cg.constants import Pipeline
from cg.constants import Workflow
from cg.constants.constants import APIMethods, FileFormat, JobType, WorkflowManager
from cg.constants.priority import SlurmQos
from cg.constants.tb import AnalysisStatus
Expand Down Expand Up @@ -101,7 +101,7 @@ def add_pending_analysis(
out_dir: str,
slurm_quality_of_service: SlurmQos,
email: str = None,
data_analysis: Pipeline = None,
data_analysis: Workflow = None,
ticket: str = None,
workflow_manager: str = WorkflowManager.Slurm,
) -> TrailblazerAnalysis:
Expand Down
6 changes: 3 additions & 3 deletions cg/cli/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import click

from cg.constants import STATUS_OPTIONS, DataDelivery, Pipeline, Priority
from cg.constants import STATUS_OPTIONS, DataDelivery, Priority, Workflow
from cg.constants.archiving import PDC_ARCHIVE_LOCATION
from cg.constants.subject import Sex
from cg.meta.transfer.external_data import ExternalDataAPI
Expand Down Expand Up @@ -225,7 +225,7 @@ def add_sample(
"data_analysis",
help="Analysis workflow",
required=True,
type=EnumChoice(Pipeline),
type=EnumChoice(Workflow),
)
@click.option(
"-dd",
Expand All @@ -243,7 +243,7 @@ def add_case(
context: CGConfig,
priority: Priority,
panel_abbreviations: tuple[str],
data_analysis: Pipeline,
data_analysis: Workflow,
data_delivery: DataDelivery,
customer_id: str,
name: str,
Expand Down
6 changes: 3 additions & 3 deletions cg/cli/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
rnafusion_past_run_dirs,
rsync_past_run_dirs,
)
from cg.constants.constants import DRY_RUN, SKIP_CONFIRMATION, Pipeline
from cg.constants.constants import DRY_RUN, SKIP_CONFIRMATION, Workflow
from cg.constants.housekeeper_tags import AlignmentFileTag, ScoutTag
from cg.exc import CleanFlowCellFailedError, FlowCellError
from cg.meta.clean.api import CleanAPI
Expand Down Expand Up @@ -172,7 +172,7 @@ def hk_case_bundle_files(context: CGConfig, days_old: int, dry_run: bool = False

@clean.command("hk-bundle-files")
@click.option("-c", "--case-id", type=str, required=False)
@click.option("-p", "--pipeline", type=Pipeline, required=False)
@click.option("-p", "--pipeline", type=Workflow, required=False)
@click.option("-t", "--tags", multiple=True, required=True)
@click.option("-o", "--days-old", type=int, default=30)
@DRY_RUN
Expand All @@ -182,7 +182,7 @@ def hk_bundle_files(
case_id: str | None,
tags: list,
days_old: int | None,
pipeline: Pipeline | None,
pipeline: Workflow | None,
dry_run: bool,
):
"""Remove files found in Housekeeper bundles."""
Expand Down
4 changes: 2 additions & 2 deletions cg/cli/delete/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ARGUMENT_CASE_ID,
OPTION_LOQUSDB_SUPPORTED_PIPELINES,
)
from cg.constants.constants import DRY_RUN, SKIP_CONFIRMATION, Pipeline
from cg.constants.constants import DRY_RUN, SKIP_CONFIRMATION, Workflow
from cg.exc import CaseNotFoundError, LoqusdbError
from cg.meta.observations.balsamic_observations_api import BalsamicObservationsAPI
from cg.meta.observations.mip_dna_observations_api import MipDNAObservationsAPI
Expand Down Expand Up @@ -49,7 +49,7 @@ def delete_observations(context: CGConfig, case_id: str, dry_run: bool, yes: boo
@DRY_RUN
@click.pass_context
def delete_available_observations(
context: click.Context, pipeline: Pipeline | None, dry_run: bool, yes: bool
context: click.Context, pipeline: Workflow | None, dry_run: bool, yes: bool
):
"""Delete available observation from Loqusdb."""

Expand Down
4 changes: 2 additions & 2 deletions cg/cli/generate/report/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
get_report_api_pipeline,
get_report_case,
)
from cg.constants import EXIT_FAIL, EXIT_SUCCESS, Pipeline
from cg.constants import EXIT_FAIL, EXIT_SUCCESS, Workflow
from cg.exc import CgError
from cg.meta.report.report_api import ReportAPI
from cg.store.models import Case
Expand Down Expand Up @@ -90,7 +90,7 @@ def generate_delivery_report(
@OPTION_DRY_RUN
@click.pass_context
def generate_available_delivery_reports(
context: click.Context, pipeline: Pipeline, force_report: bool, dry_run: bool
context: click.Context, pipeline: Workflow, force_report: bool, dry_run: bool
) -> None:
"""Generates delivery reports for all cases that need one and stores them in housekeeper."""

Expand Down
Loading

0 comments on commit c29d718

Please sign in to comment.