diff --git a/alembic/versions/9073c61bc72b_add_raredisease_to_analysis_options.py b/alembic/versions/9073c61bc72b_add_raredisease_to_analysis_options.py new file mode 100644 index 0000000000..c7e8abeb86 --- /dev/null +++ b/alembic/versions/9073c61bc72b_add_raredisease_to_analysis_options.py @@ -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() diff --git a/cg/cli/workflow/base.py b/cg/cli/workflow/base.py index 4bd25014bd..98cded1c73 100644 --- a/cg/cli/workflow/base.py +++ b/cg/cli/workflow/base.py @@ -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 @@ -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) diff --git a/cg/cli/workflow/raredisease/__init__.py b/cg/cli/workflow/raredisease/__init__.py new file mode 100644 index 0000000000..d3a1fde1a8 --- /dev/null +++ b/cg/cli/workflow/raredisease/__init__.py @@ -0,0 +1 @@ +"""Init for module""" diff --git a/cg/cli/workflow/raredisease/base.py b/cg/cli/workflow/raredisease/base.py new file mode 100644 index 0000000000..0891d953f2 --- /dev/null +++ b/cg/cli/workflow/raredisease/base.py @@ -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, + ) diff --git a/cg/meta/workflow/raredisease.py b/cg/meta/workflow/raredisease.py new file mode 100644 index 0000000000..1223a0446a --- /dev/null +++ b/cg/meta/workflow/raredisease.py @@ -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) diff --git a/cg/models/raredisease/__init__.py b/cg/models/raredisease/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/cli/workflow/raredisease/conftest.py b/tests/cli/workflow/raredisease/conftest.py new file mode 100644 index 0000000000..a9fd2f9120 --- /dev/null +++ b/tests/cli/workflow/raredisease/conftest.py @@ -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 diff --git a/tests/cli/workflow/raredisease/test_cli_raredisease_compound_commands.py b/tests/cli/workflow/raredisease/test_cli_raredisease_compound_commands.py new file mode 100644 index 0000000000..0bd0e2a3dd --- /dev/null +++ b/tests/cli/workflow/raredisease/test_cli_raredisease_compound_commands.py @@ -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