Skip to content

Commit

Permalink
Merge pull request #288 from Clinical-Genomics/more_coverage_threshol…
Browse files Browse the repository at this point in the history
…ds_on_report

Custom coverage thresholds on report
  • Loading branch information
northwestwitch authored Apr 18, 2024
2 parents d7d322f + ec1efdd commit 315adef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# MYSQL_DATABASE_NAME=chanjo2_test
# MYSQL_HOST_NAME=localhost
# MYSQL_PORT=3306
# REPORT_COVERAGE_LEVELS=[100,150,200,300,500]
DEMO=Y
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [unreleased]
### Added
- Coverage report and genes coverage overview endpoints now accept also requests with application/x-www-form-urlencoded data
- Allow system admin to customise coverage levels to be used in reports' metrics by editing the REPORT_COVERAGE_LEVELS in .env file
### Changed
- Templates form submit data as application/x-www-form-urlencoded without having to transform it into json
### Fixed
Expand Down
14 changes: 11 additions & 3 deletions src/chanjo2/models/pydantic_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import os
from datetime import datetime
from enum import Enum
from pathlib import Path
Expand All @@ -20,6 +21,13 @@
LOG = logging.getLogger("uvicorn.access")


def default_report_coverage_levels() -> List[int]:
"""Sets the coverage thresholds to be used for report metrics whenever a request doesn't contain 'completeness_thresholds' values."""
if os.getenv("REPORT_COVERAGE_LEVELS"):
return json.loads(os.getenv("REPORT_COVERAGE_LEVELS"))
return DEFAULT_COMPLETENESS_LEVELS


class Builds(str, Enum):
build_37 = "GRCh37"
build_38 = "GRCh38"
Expand Down Expand Up @@ -223,7 +231,7 @@ class ReportQuerySample(BaseModel):

class ReportQuery(BaseModel):
build: Builds
completeness_thresholds: Optional[List[int]] = DEFAULT_COMPLETENESS_LEVELS
completeness_thresholds: Optional[List[int]] = default_report_coverage_levels()
ensembl_gene_ids: Optional[List[str]] = None
hgnc_gene_ids: Optional[List[int]] = None
hgnc_gene_symbols: Optional[List[str]] = None
Expand Down Expand Up @@ -253,7 +261,7 @@ def as_form(cls, form_data: FormData) -> "ReportQuery":
comma_sep_values=form_data.get("completeness_thresholds"),
items_format=int,
)
or DEFAULT_COMPLETENESS_LEVELS,
or default_report_coverage_levels(),
ensembl_gene_ids=cls.comma_sep_values_to_list(
comma_sep_values=form_data.get("ensembl_gene_ids"), items_format=str
),
Expand Down Expand Up @@ -294,7 +302,7 @@ def check_genes_lists(cls, values: dict):

class GeneReportForm(BaseModel):
build: Builds
completeness_thresholds: Optional[List[int]] = DEFAULT_COMPLETENESS_LEVELS
completeness_thresholds: Optional[List[int]] = default_report_coverage_levels()
hgnc_gene_id: int
default_level: int = 10
samples: List[ReportQuerySample]
Expand Down

0 comments on commit 315adef

Please sign in to comment.