Skip to content

Commit

Permalink
refactor(rename workflow fastq to rawdata) (#3849) (major)
Browse files Browse the repository at this point in the history
# Description

refactor the workflow fastq cli to workflow raw-data
  • Loading branch information
ChrOertlin authored Oct 17, 2024
1 parent 33bb408 commit 7ad91d4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 54 deletions.
4 changes: 2 additions & 2 deletions cg/cli/workflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cg.cli.workflow.balsamic.pon import balsamic_pon
from cg.cli.workflow.balsamic.qc import balsamic_qc
from cg.cli.workflow.balsamic.umi import balsamic_umi
from cg.cli.workflow.fastq.base import fastq
from cg.cli.workflow.raw_data.base import raw_data
from cg.cli.workflow.fluffy.base import fluffy
from cg.cli.workflow.jasen.base import jasen
from cg.cli.workflow.microsalt.base import microsalt
Expand Down Expand Up @@ -39,4 +39,4 @@ def workflow():
workflow.add_command(rnafusion)
workflow.add_command(taxprofiler)
workflow.add_command(tomte)
workflow.add_command(fastq)
workflow.add_command(raw_data)
File renamed without changes.
29 changes: 18 additions & 11 deletions cg/cli/workflow/fastq/base.py → cg/cli/workflow/raw_data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from cg.cli.utils import CLICK_CONTEXT_SETTINGS
from cg.cli.workflow.commands import ARGUMENT_CASE_ID
from cg.cli.workflow.fastq.fastq_service import FastqService
from cg.cli.workflow.raw_data.raw_data_service import RawDataAnalysisService
from cg.constants.cli_options import DRY_RUN
from cg.constants.constants import Workflow
from cg.meta.workflow.analysis import AnalysisAPI
Expand All @@ -16,34 +16,41 @@

@click.group(invoke_without_command=True, context_settings=CLICK_CONTEXT_SETTINGS)
@click.pass_context
def fastq(context: click.Context):
"""Function for storing fastq-cases"""
def raw_data(context: click.Context):
"""Function for storing raw-data-cases"""
AnalysisAPI.get_help(context)


@fastq.command("store")
@raw_data.command("store")
@DRY_RUN
@ARGUMENT_CASE_ID
@click.pass_context
def store_fastq_analysis(context: click.Context, case_id: str, dry_run: bool = False):
def store_raw_data_analysis(context: click.Context, case_id: str, dry_run: bool = False):
LOG.info(f"Creating an analysis for case {case_id}")

if dry_run:
return

fastq_service = FastqService(
raw_data_service = RawDataAnalysisService(
store=context.obj.status_db,
trailblazer_api=context.obj.trailblazer_api,
)
fastq_service.store_analysis(case_id)
raw_data_service.store_analysis(case_id)


@fastq.command("store-available")
@raw_data.command("store-available")
@DRY_RUN
@click.pass_context
def store_available_fastq_analysis(context: click.Context, dry_run: bool = False):
"""Creates an analysis object in status-db for all fastq cases to be delivered."""
def store_available_raw_data_analysis(context: click.Context, dry_run: bool = False):
"""Creates an analysis object in status-db for all raw data cases to be delivered."""
status_db: Store = context.obj.status_db
for case in status_db.cases_to_analyse(workflow=Workflow.RAW_DATA):
LOG.info(f"Creating an analysis for case {case.internal_id}")
if SequencingQCService.case_pass_sequencing_qc(case):
context.invoke(store_fastq_analysis, case_id=case.internal_id, dry_run=dry_run)
if dry_run:
return
raw_data_service = RawDataAnalysisService(
store=context.obj.status_db,
trailblazer_api=context.obj.trailblazer_api,
)
raw_data_service.store_analysis(case.internal_id)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from cg.store.store import Store


class FastqService:
class RawDataAnalysisService:
def __init__(self, store: Store, trailblazer_api: TrailblazerAPI):
self.store = store
self.trailblazer_api = trailblazer_api
Expand Down
1 change: 1 addition & 0 deletions cg/services/analysis_service/analysis_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


class AnalysisService:

def __init__(self, analysis_client: TrailblazerAPI, status_db: Store):
self.status_db = status_db
self.analysis_client = analysis_client
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/workflow/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def analysis_store(base_store: Store, workflow_case_id: str, helpers: StoreHelpe


@pytest.fixture
def fastq_context(
def raw_data_fastq_context(
base_context,
cg_context: CGConfig,
fastq_case,
Expand Down
48 changes: 9 additions & 39 deletions tests/cli/workflow/fastq/test_fastq_base.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
import logging
from datetime import datetime
from cg.cli.workflow.raw_data.base import store_raw_data_analysis
from cg.store.models import Analysis, Case

from cg.cli.workflow.fastq.base import store_available_fastq_analysis, store_fastq_analysis
from cg.constants.constants import CaseActions, Workflow
from cg.store.models import Analysis, Case, Sample


def test_store_fastq_analysis(another_case_id: str, cli_runner, fastq_context, helpers):
def test_store_raw_data_analysis(another_case_id: str, cli_runner, raw_data_fastq_context, helpers):
"""Test for CLI command creating an analysis object for a fastq case"""
# GIVEN a fastq context
helpers.ensure_case(fastq_context.status_db, case_id=another_case_id)
case_obj: Case = fastq_context.status_db.get_case_by_internal_id(another_case_id)

# GIVEN a raw data fastq context
helpers.ensure_case(raw_data_fastq_context.status_db, case_id=another_case_id)
case_obj: Case = raw_data_fastq_context.status_db.get_case_by_internal_id(another_case_id)
assert not case_obj.analyses

# WHEN a command is run to create an analysis for the case
cli_runner.invoke(store_fastq_analysis, [another_case_id], obj=fastq_context)
cli_runner.invoke(store_raw_data_analysis, [another_case_id], obj=raw_data_fastq_context)

# THEN the analysis is created
assert (
len(
fastq_context.status_db._get_query(table=Analysis)
raw_data_fastq_context.status_db._get_query(table=Analysis)
.filter(Analysis.case_id == case_obj.id)
.all()
)
> 0
)


def test_store_available_fastq_analysis(
caplog, another_case_id: str, cli_runner, fastq_context, sample_id: str, helpers
):
"""Test for CLI command creating an analysis object for all fastq cases to be delivered"""
caplog.set_level(logging.INFO)

# GIVEN a case with no analysis, a sample that has been sequenced and a fastq context
sample_obj: Sample = fastq_context.status_db.get_sample_by_internal_id(internal_id=sample_id)
sample_obj.last_sequenced_at = datetime.now()

# GIVEN a case with no analysis but which is to be analyzed, a sample that has been sequenced and a fastq context
case_obj: Case = helpers.add_case_with_sample(
fastq_context.status_db, case_id=another_case_id, sample_id="sample_for_another_case_id"
)
assert not case_obj.analyses
case_obj.data_analysis = Workflow.RAW_DATA
case_obj.action = CaseActions.ANALYZE
case_obj.samples[0].last_sequenced_at = datetime.now()
case_obj.samples[0].reads = 1

# WHEN the store_available_fastq_analysis command is invoked
cli_runner.invoke(store_available_fastq_analysis, ["--dry-run"], obj=fastq_context)

# THEN the right case should be found and the store_fastq_analysis command should be reached
assert f"Creating an analysis for case {another_case_id}" in caplog.text

0 comments on commit 7ad91d4

Please sign in to comment.