Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(raredisease): Add raredisease to cg workflow #2592

Merged
merged 10 commits into from
Oct 31, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Add raredisease to analysis options

Revision ID: dbe513da5cb9
Revises: e853d21feaa0
Create Date: 2023-10-23 11:22:57.403535

"""
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 = "dbe513da5cb9"
down_revision = "e853d21feaa0"
branch_labels = None
depends_on = None

Base = declarative_base()

old_options = (
"balsamic",
"balsamic-pon",
"balsamic-qc",
"balsamic-umi",
"demultiplex",
"fastq",
"fluffy",
"microsalt",
"mip-dna",
"mip-rna",
"rnafusion",
"rsync",
"sars-cov-2",
"spring",
"taxprofiler",
)
new_options = sorted(old_options + ("raredisease",))
peterpru marked this conversation as resolved.
Show resolved Hide resolved

old_enum = mysql.ENUM(*old_options)
new_enum = mysql.ENUM(*new_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)))
peterpru marked this conversation as resolved.
Show resolved Hide resolved


def upgrade():
op.alter_column("family", "data_analysis", type_=new_enum)
op.alter_column("analysis", "pipeline", type_=new_enum)
peterpru marked this conversation as resolved.
Show resolved Hide resolved


def downgrade():
bind = op.get_bind()
session = sa.orm.Session(bind=bind)
for analysis in session.query(Analysis).filter(Analysis.pipeline == "raredisease"):
analysis.pipeline = "mip-dna"
for family in session.query(Family).filter(Family.data_analysis == "raredisease"):
family.data_analysis = "mip-dna"
peterpru marked this conversation as resolved.
Show resolved Hide resolved
op.alter_column("family", "data_analysis", type_=old_enum)
op.alter_column("analysis", "pipeline", type_=old_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 @@ -31,6 +32,7 @@ def workflow():
workflow.add_command(mip_rna)
workflow.add_command(fluffy)
workflow.add_command(mutant)
workflow.add_command(raredisease)
workflow.add_command(rnafusion)
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,
)
peterpru marked this conversation as resolved.
Show resolved Hide resolved
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):
peterpru marked this conversation as resolved.
Show resolved Hide resolved
"""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