-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add raredisease to cli cg workflow (#2649)
### Added - cli option: `cg workflow raredisease`
- Loading branch information
Showing
8 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
alembic/versions/9073c61bc72b_add_raredisease_to_analysis_options.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Init for module""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
25 changes: 25 additions & 0 deletions
25
tests/cli/workflow/raredisease/test_cli_raredisease_compound_commands.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |