diff --git a/NIPTool/API/external/api/api_v1/endpoints/batches.py b/NIPTool/API/external/api/api_v1/endpoints/batches.py index f51d06aa..4d1716f5 100644 --- a/NIPTool/API/external/api/api_v1/endpoints/batches.py +++ b/NIPTool/API/external/api/api_v1/endpoints/batches.py @@ -5,6 +5,7 @@ from NIPTool.API.external.utils import * from NIPTool.API.external.constants import TRISOMI_TRESHOLDS from NIPTool.API.external.api.deps import get_nipt_adapter + from fastapi.templating import Jinja2Templates router = APIRouter() @@ -68,6 +69,7 @@ def batch(request: Request, batch_id: str, adapter: NiptAdapter = Depends(get_ni @router.post("/{batch_id}/") def batch(request: Request, batch_id: str, adapter: NiptAdapter = Depends(get_nipt_adapter)): """Batch view with table of all samples in the batch.""" + samples: List[Sample] = find.batch_samples(batch_id=batch_id, adapter=adapter) return templates.TemplateResponse( "batch/tabs/table.html", @@ -85,6 +87,7 @@ def batch(request: Request, batch_id: str, adapter: NiptAdapter = Depends(get_ni def NCV(request: Request, batch_id: str, ncv, adapter: NiptAdapter = Depends(get_nipt_adapter)): """Batch view with with NCV plot""" batch: Batch = find.batch(batch_id=batch_id, adapter=adapter) + return templates.TemplateResponse( "batch/tabs/NCV.html", context=dict( @@ -107,6 +110,7 @@ def fetal_fraction_XY( ): """Batch view with fetal fraction (X against Y) plot""" batch: Batch = find.batch(batch_id=batch_id, adapter=adapter) + control = get_ff_control_normal(adapter) abnormal = get_ff_control_abnormal(adapter) return templates.TemplateResponse( @@ -131,6 +135,7 @@ def fetal_fraction( ): """Batch view with fetal fraction plot""" batch: Batch = find.batch(batch_id=batch_id, adapter=adapter) + return templates.TemplateResponse( "batch/tabs/FF.html", context=dict( @@ -149,6 +154,7 @@ def coverage(request: Request, batch_id: str, adapter: NiptAdapter = Depends(get """Batch view with coverage plot""" batch: Batch = find.batch(batch_id=batch_id, adapter=adapter) samples: List[Sample] = find.batch_samples(batch_id=batch_id, adapter=adapter) + scatter_data = get_scatter_data_for_coverage_plot(samples) box_data = get_box_data_for_coverage_plot(samples) return templates.TemplateResponse( @@ -173,6 +179,7 @@ def report( batch: Batch = find.batch(batch_id=batch_id, adapter=adapter) samples: List[Sample] = find.batch_samples(batch_id=batch_id, adapter=adapter) + scatter_data = get_scatter_data_for_coverage_plot(samples) box_data = get_box_data_for_coverage_plot(samples) control = get_ff_control_normal(adapter) diff --git a/NIPTool/API/external/api/api_v1/endpoints/sample.py b/NIPTool/API/external/api/api_v1/endpoints/sample.py index 8763aa1e..e4b9123b 100644 --- a/NIPTool/API/external/api/api_v1/endpoints/sample.py +++ b/NIPTool/API/external/api/api_v1/endpoints/sample.py @@ -4,6 +4,7 @@ from NIPTool.models.database import User from NIPTool.API.external.utils import * from NIPTool.API.external.api.deps import get_nipt_adapter + from fastapi.templating import Jinja2Templates router = APIRouter() diff --git a/NIPTool/API/external/api/api_v1/endpoints/statistics.py b/NIPTool/API/external/api/api_v1/endpoints/statistics.py index 62c014d4..8fece86c 100644 --- a/NIPTool/API/external/api/api_v1/endpoints/statistics.py +++ b/NIPTool/API/external/api/api_v1/endpoints/statistics.py @@ -9,6 +9,7 @@ get_statistics_for_scatter_plot, ) from NIPTool.API.external.api.deps import get_nipt_adapter + from fastapi.templating import Jinja2Templates router = APIRouter() @@ -35,6 +36,7 @@ def statistics(request: Request, adapter: NiptAdapter = Depends(get_nipt_adapter batch_ids = [batch.get("batch_id") for batch in batches] box_stat = get_statistics_for_box_plot(adapter=adapter, batches=batch_ids, fields=box_plots) scatter_stat = get_statistics_for_scatter_plot(batches=batches, fields=scatter_plots) + return templates.TemplateResponse( "statistics.html", context=dict( diff --git a/NIPTool/API/external/utils.py b/NIPTool/API/external/utils.py index f5ff909f..b0298169 100644 --- a/NIPTool/API/external/utils.py +++ b/NIPTool/API/external/utils.py @@ -24,6 +24,7 @@ def get_sample_info(sample: Sample): "FFY", "Zscore_X", ] + for key in sample_info_keys: val = sample.get(key) if isinstance(val, (float, int)): @@ -82,6 +83,7 @@ def _get_ff_warning(fetal_fraction): def get_sample_warnings(sample: Sample): """""" sample = sample.dict() + sample_warnings = {} fetal_fraction = sample.get("FF_Formatted") sample_warnings["FF_Formatted"] = _get_ff_warning(fetal_fraction) @@ -258,6 +260,7 @@ def get_tris_control_normal(adapter, chr): if not list(find.sample_aggregate(pipe=pipe, adapter=adapter)): return [] data = list(find.sample_aggregate(pipe=pipe, adapter=adapter))[0] + data["values"] = [value for value in data.get("values", [])] return data @@ -286,6 +289,7 @@ def get_tris_control_abnormal(adapter, chr, x_axis): ] for status_dict in find.sample_aggregate(pipe=pipe, adapter=adapter): + status = status_dict["_id"][f"status_{chr}"] plot_data[status] = { "values": [value for value in status_dict.get("values")], @@ -389,6 +393,7 @@ def get_statistics_for_scatter_plot(batches: list, fields: list) -> dict: for batch in batches: batch_id = batch.get("batch_id") scatter_plot_data[batch_id] = {"date": batch.get("SequencingDate")} + for field in fields: scatter_plot_data[batch_id][field] = batch.get(field) diff --git a/NIPTool/adapter/plugin.py b/NIPTool/adapter/plugin.py index 18d2d3c3..8ba2fe0d 100644 --- a/NIPTool/adapter/plugin.py +++ b/NIPTool/adapter/plugin.py @@ -5,6 +5,7 @@ from mongo_adapter import MongoAdapter + LOG = logging.getLogger(__name__) diff --git a/NIPTool/models/database/batch.py b/NIPTool/models/database/batch.py index 67ed3cb0..878bccec 100644 --- a/NIPTool/models/database/batch.py +++ b/NIPTool/models/database/batch.py @@ -4,7 +4,7 @@ class Batch(BaseModel): - batch_id: str=Field(..., alias='SampleProject') + batch_id: str = Field(..., alias="SampleProject") result_file: Optional[str] multiqc_report: Optional[str] segmental_calls: Optional[str] diff --git a/NIPTool/models/database/sample.py b/NIPTool/models/database/sample.py index 1d15b5aa..c312df20 100644 --- a/NIPTool/models/database/sample.py +++ b/NIPTool/models/database/sample.py @@ -4,8 +4,8 @@ class Sample(BaseModel): - sample_id: str= Field(..., alias='SampleID') - batch_id: str= Field(..., alias='SampleProject') + sample_id: str = Field(..., alias="SampleID") + batch_id: str = Field(..., alias="SampleProject") SampleType: Optional[str] Description: Optional[str] Flowcell: Optional[str]