Skip to content

Commit

Permalink
sovling merge conflict with master
Browse files Browse the repository at this point in the history
  • Loading branch information
mayabrandi committed Mar 30, 2021
1 parent ab98308 commit 9c6df7e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions NIPTool/API/external/api/api_v1/endpoints/batches.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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",
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NIPTool/API/external/api/api_v1/endpoints/sample.py
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions NIPTool/API/external/api/api_v1/endpoints/statistics.py
Expand Up @@ -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()
Expand All @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions NIPTool/API/external/utils.py
Expand Up @@ -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)):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")],
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions NIPTool/adapter/plugin.py
Expand Up @@ -5,6 +5,7 @@

from mongo_adapter import MongoAdapter


LOG = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion NIPTool/models/database/batch.py
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions NIPTool/models/database/sample.py
Expand Up @@ -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]
Expand Down

0 comments on commit 9c6df7e

Please sign in to comment.