Skip to content

Commit

Permalink
Move metrics-deliver to command.py for taxprofiler and rnafusion
Browse files Browse the repository at this point in the history
  • Loading branch information
sofstam committed Dec 8, 2023
1 parent b3c6a5a commit e7a1a91
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 45 deletions.
27 changes: 26 additions & 1 deletion cg/cli/workflow/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cg.apps.housekeeper.hk import HousekeeperAPI
from cg.constants import EXIT_FAIL, EXIT_SUCCESS
from cg.constants.observations import LOQUSDB_SUPPORTED_PIPELINES
from cg.exc import FlowCellsNeededError
from cg.exc import FlowCellsNeededError, CgError
from cg.meta.rsync import RsyncAPI
from cg.meta.workflow.analysis import AnalysisAPI
from cg.meta.workflow.balsamic import BalsamicAnalysisAPI
Expand All @@ -22,6 +22,8 @@
from cg.meta.workflow.mip_rna import MipRNAAnalysisAPI
from cg.meta.workflow.mutant import MutantAnalysisAPI
from cg.meta.workflow.rnafusion import RnafusionAnalysisAPI
from cg.meta.workflow.taxprofiler import TaxprofilerAnalysisAPI
from cg.meta.workflow.nf_analysis import NfAnalysisAPI
from cg.models.cg_config import CGConfig
from cg.store import Store

Expand Down Expand Up @@ -89,6 +91,29 @@ def link(context: CGConfig, case_id: str, dry_run: bool):
analysis_api.link_fastq_files(case_id=case_id)


@click.command("metrics-deliver")
@ARGUMENT_CASE_ID
@OPTION_DRY
@click.pass_obj
def metrics_deliver(context: CGConfig, case_id: str, dry_run: bool) -> None:
"""Create and validate a metrics deliverables file for given case id.
If QC metrics are met it sets the status in Trailblazer to complete.
If failed, it sets it as failed and adds a comment with information of the failed metrics."""

analysis_api: RnafusionAnalysisAPI | TaxprofilerAnalysisAPI = context.meta_apis["analysis_api"]

try:
analysis_api.status_db.verify_case_exists(case_internal_id=case_id)
except CgError as error:
raise click.Abort() from error

analysis_api.write_metrics_deliverables(case_id=case_id, dry_run=dry_run)
try:
analysis_api.validate_qc_metrics(case_id=case_id, dry_run=dry_run)
except CgError as error:
raise click.Abort() from error


@click.command("store")
@ARGUMENT_CASE_ID
@OPTION_DRY
Expand Down
24 changes: 2 additions & 22 deletions cg/cli/workflow/rnafusion/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pydantic.v1 import ValidationError

from cg.apps.housekeeper.hk import HousekeeperAPI
from cg.cli.workflow.commands import ARGUMENT_CASE_ID, resolve_compression
from cg.cli.workflow.commands import ARGUMENT_CASE_ID, resolve_compression, metrics_deliver
from cg.cli.workflow.nf_analysis import (
OPTION_COMPUTE_ENV,
OPTION_CONFIG,
Expand Down Expand Up @@ -222,27 +222,7 @@ def start_available(context: click.Context, dry_run: bool = False) -> None:
raise click.Abort


@rnafusion.command("metrics-deliver")
@ARGUMENT_CASE_ID
@DRY_RUN
@click.pass_obj
def metrics_deliver(context: CGConfig, case_id: str, dry_run: bool) -> None:
"""Create and validate a metrics deliverables file for given case id.
If QC metrics are met it sets the status in Trailblazer to complete.
If failed, it sets it as failed and adds a comment with information of the failed metrics."""

analysis_api: RnafusionAnalysisAPI = context.meta_apis[MetaApis.ANALYSIS_API]

try:
analysis_api.status_db.verify_case_exists(case_internal_id=case_id)
except CgError as error:
raise click.Abort() from error

analysis_api.write_metrics_deliverables(case_id=case_id, dry_run=dry_run)
try:
analysis_api.validate_qc_metrics(case_id=case_id, dry_run=dry_run)
except CgError as error:
raise click.Abort() from error
rnafusion.add_command(metrics_deliver)


@rnafusion.command("report-deliver")
Expand Down
24 changes: 2 additions & 22 deletions cg/cli/workflow/taxprofiler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import click
from pydantic.v1 import ValidationError

from cg.cli.workflow.commands import ARGUMENT_CASE_ID, resolve_compression
from cg.cli.workflow.commands import ARGUMENT_CASE_ID, resolve_compression, metrics_deliver
from cg.cli.workflow.nf_analysis import (
OPTION_COMPUTE_ENV,
OPTION_CONFIG,
Expand Down Expand Up @@ -211,24 +211,4 @@ def start_available(context: click.Context, dry_run: bool = False) -> None:
raise click.Abort


@taxprofiler.command("metrics-deliver")
@ARGUMENT_CASE_ID
@DRY_RUN
@click.pass_obj
def metrics_deliver(context: CGConfig, case_id: str, dry_run: bool) -> None:
"""Create and validate a metrics deliverables file for given case id.
If QC metrics are met it sets the status in Trailblazer to complete.
If failed, it sets it as failed and adds a comment with information of the failed metrics."""

analysis_api: TaxprofilerAnalysisAPI = context.meta_apis[MetaApis.ANALYSIS_API]

try:
analysis_api.status_db.verify_case_exists(case_internal_id=case_id)
except CgError as error:
raise click.Abort() from error

analysis_api.write_metrics_deliverables(case_id=case_id, dry_run=dry_run)
try:
analysis_api.validate_qc_metrics(case_id=case_id, dry_run=dry_run)
except CgError as error:
raise click.Abort() from error
taxprofiler.add_command(metrics_deliver)
4 changes: 4 additions & 0 deletions cg/meta/workflow/nf_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def create_case_directory(self, case_id: str, dry_run: bool = False) -> None:
if not dry_run:
Path(self.get_case_path(case_id=case_id)).mkdir(parents=True, exist_ok=True)

def write_metrics_deliverables(self, case_id: str, dry_run: bool = False) -> None:
"""Write <case>_metrics_deliverables.yaml file."""
raise NotImplementedError

def get_log_path(self, case_id: str, pipeline: str, log: str = None) -> Path:
"""Path to NF log."""
if log:
Expand Down

0 comments on commit e7a1a91

Please sign in to comment.