Skip to content

Commit

Permalink
add raredisease to cli cg workflow (#2649)
Browse files Browse the repository at this point in the history
### Added

- cli option: `cg workflow raredisease`
  • Loading branch information
peterpru authored Oct 31, 2023
1 parent 0a6dd51 commit db8213c
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""Add raredisease to analysis options
Revision ID: 9073c61bc72b
Revises: b6f00cc615cf
Create Date: 2023-10-31 12:23:09.239741
"""
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from sqlalchemy.orm import declarative_base

from alembic import op
from cg.constants import Pipeline


# revision identifiers, used by Alembic.
revision = "9073c61bc72b"
down_revision = "b6f00cc615cf"
branch_labels = None
depends_on = None

Base = declarative_base()

old_analysis_options = (
"balsamic",
"balsamic-pon",
"balsamic-qc",
"balsamic-umi",
"demultiplex",
"fastq",
"fluffy",
"microsalt",
"mip-dna",
"mip-rna",
"rnafusion",
"rsync",
"sars-cov-2",
"spring",
"taxprofiler",
)
new_analysis_options = sorted(old_analysis_options + ("raredisease",))

old_analysis_enum = mysql.ENUM(*old_analysis_options)
new_analysis_enum = mysql.ENUM(*new_analysis_options)


class Analysis(Base):
__tablename__ = "analysis"
id = sa.Column(sa.types.Integer, primary_key=True)
pipeline = sa.Column(sa.types.Enum(*list(Pipeline)))


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


def upgrade():
op.alter_column("family", "data_analysis", type_=new_analysis_enum)
op.alter_column("analysis", "pipeline", type_=new_analysis_enum)


def downgrade():
bind = op.get_bind()
session = sa.orm.Session(bind=bind)
for analysis in session.query(Analysis).filter(Analysis.pipeline == "raredisease"):
print(
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")
family.data_analysis = "mip-dna"
op.alter_column("family", "data_analysis", type_=old_analysis_enum)
op.alter_column("analysis", "pipeline", type_=old_analysis_enum)
session.commit()
2 changes: 2 additions & 0 deletions cg/cli/workflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from cg.cli.workflow.mip_dna.base import mip_dna
from cg.cli.workflow.mip_rna.base import mip_rna
from cg.cli.workflow.mutant.base import mutant
from cg.cli.workflow.raredisease.base import raredisease
from cg.cli.workflow.rnafusion.base import rnafusion
from cg.cli.workflow.taxprofiler.base import taxprofiler

Expand All @@ -32,5 +33,6 @@ def workflow():
workflow.add_command(fluffy)
workflow.add_command(mutant)
workflow.add_command(rnafusion)
workflow.add_command(raredisease)
workflow.add_command(taxprofiler)
workflow.add_command(fastq)
1 change: 1 addition & 0 deletions cg/cli/workflow/raredisease/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Init for module"""
21 changes: 21 additions & 0 deletions cg/cli/workflow/raredisease/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""CLI support to create config and/or start RAREDISEASE."""

import logging

import click

from cg.constants.constants import MetaApis
from cg.meta.workflow.analysis import AnalysisAPI
from cg.meta.workflow.raredisease import RarediseaseAnalysisAPI

LOG = logging.getLogger(__name__)


@click.group(invoke_without_command=True)
@click.pass_context
def raredisease(context: click.Context) -> None:
"""nf-core/raredisease analysis workflow."""
AnalysisAPI.get_help(context)
context.obj.meta_apis[MetaApis.ANALYSIS_API] = RarediseaseAnalysisAPI(
config=context.obj,
)
20 changes: 20 additions & 0 deletions cg/meta/workflow/raredisease.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Module for Raredisease Analysis API."""

import logging
from cg.constants import Pipeline
from cg.meta.workflow.nf_analysis import NfAnalysisAPI
from cg.models.cg_config import CGConfig

LOG = logging.getLogger(__name__)


class RarediseaseAnalysisAPI(NfAnalysisAPI):
"""Handles communication between RAREDISEASE processes
and the rest of CG infrastructure."""

def __init__(
self,
config: CGConfig,
pipeline: Pipeline = Pipeline.RAREDISEASE,
):
super().__init__(config=config, pipeline=pipeline)
Empty file.
14 changes: 14 additions & 0 deletions tests/cli/workflow/raredisease/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Fixtures for cli workflow raredisease tests"""

import pytest
from cg.meta.workflow.raredisease import RarediseaseAnalysisAPI
from cg.models.cg_config import CGConfig


@pytest.fixture(scope="function", name="raredisease_context")
def fixture_raredisease_context(
cg_context: CGConfig,
) -> CGConfig:
"""Context to use in cli."""
cg_context.meta_apis["analysis_api"] = RarediseaseAnalysisAPI(config=cg_context)
return cg_context
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import logging

from _pytest.logging import LogCaptureFixture
from click.testing import CliRunner
from cg.cli.workflow.raredisease.base import (
raredisease,
)
from cg.constants import EXIT_SUCCESS
from cg.models.cg_config import CGConfig


def test_raredisease_no_args(cli_runner: CliRunner, raredisease_context: CGConfig):
"""Test to see that running RAREDISEASE without options prints help and doesn't result in an error."""
# GIVEN no arguments or options besides the command call

# WHEN running command
result = cli_runner.invoke(raredisease, [], obj=raredisease_context)

# THEN command runs successfully
print(result.output)

assert result.exit_code == EXIT_SUCCESS

# THEN help should be printed
assert "help" in result.output

0 comments on commit db8213c

Please sign in to comment.