示例#1
0
def coverage(
        request: Request,
        batch_id: str,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Batch view with coverage plot"""
    batch: Batch = find.batch(batch_id=batch_id, adapter=adapter)
    db_samples: List[DataBaseSample] = find.batch_samples(batch_id=batch_id,
                                                          adapter=adapter)
    samples: List[Sample] = [
        Sample(**db_sample.dict()) for db_sample in db_samples
    ]

    scatter_data: Dict[
        str,
        CoveragePlotSampleData] = get_scatter_data_for_coverage_plot(samples)
    box_data: Dict[int, List[float]] = get_box_data_for_coverage_plot(samples)
    return templates.TemplateResponse(
        "batch/tabs/coverage.html",
        context=dict(
            request=request,
            current_user=user,
            batch=batch.dict(),
            x_axis=list(range(1, 23)),
            scatter_data=scatter_data,
            box_data=box_data,
            page_id="batches_cov",
        ),
    )
示例#2
0
def new_user(request: Request):
    """Log in view."""
    return templates.TemplateResponse("new_user.html",
                                      context={
                                          "request": request,
                                          "current_user": ""
                                      })
示例#3
0
def Zscore(
        request: Request,
        batch_id: str,
        ncv: str,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Batch view with with Zscore plot"""

    batch: Batch = find.batch(batch_id=batch_id, adapter=adapter)

    return templates.TemplateResponse(
        "batch/tabs/Zscore.html",
        context=dict(
            request=request,
            tris_thresholds=TRISOMI_TRESHOLDS,
            batch=batch.dict(),
            chromosomes=[ncv],
            ncv_chrom_data={
                ncv: get_tris_samples(adapter=adapter,
                                      chr=ncv,
                                      batch_id=batch_id)
            },
            normal_data={ncv: get_tris_control_normal(adapter, ncv)},
            abnormal_data={ncv: get_tris_control_abnormal(adapter, ncv, 0)},
            page_id=f"batches_NCV{ncv}",
            current_user=user,
        ),
    )
示例#4
0
def sample_tris(
        request: Request,
        sample_id: str,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Sample view with trisomi plot."""
    sample: DataBaseSample = find.sample(sample_id=sample_id, adapter=adapter)
    batch: Batch = find.batch(batch_id=sample.batch_id, adapter=adapter)
    abnormal_data: Dict[str, ZscoreSamples] = get_abn_for_samp_tris_plot(
        adapter=adapter)
    normal_data: Zscore131821 = get_normal_for_samp_tris_plot(adapter=adapter)
    sample_data: ZscoreSamples = get_sample_for_samp_tris_plot(sample)
    return templates.TemplateResponse(
        "sample/sample_tris.html",
        context=dict(
            request=request,
            current_user=user,
            normal_data=normal_data.dict(exclude_none=True, by_alias=True),
            abnormal_data=abnormal_data,
            sample_data=sample_data,
            sample=Sample(**sample.dict()),
            batch=batch,
            status_colors=STATUS_COLORS,
            page_id="sample_tris",
        ),
    )
示例#5
0
def index(request: Request):
    """Log in view."""
    return templates.TemplateResponse(
        "index.html",
        context={
            "request": request,
            "current_user": "",
            "info_type": request.cookies.get("info_type"),
            "user_info": request.cookies.get("user_info"),
        },
    )
示例#6
0
def fetal_fraction_XY(
        request: Request,
        batch_id: str,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Batch view with fetal fraction (X against Y) plot"""

    batch: Batch = find.batch(batch_id=batch_id, adapter=adapter)

    cases = get_fetal_fraction.samples(adapter=adapter, batch_id=batch_id)
    control: FetalFractionSamples = get_fetal_fraction.samples(
        batch_id=batch_id, adapter=adapter, control_samples=True)
    abnormal: FetalFractionControlAbNormal = get_fetal_fraction.control_abnormal(
        adapter)
    abnormal_dict = abnormal.dict(
        exclude_none=True,
        exclude={
            "X0": {"status_data_"},
            "XXX": {"status_data_"},
            "XXY": {"status_data_"},
            "XYY": {"status_data_"},
        },
    )

    x_max = max(control.FFX + cases.FFX) + 1
    x_min = min(control.FFX + cases.FFX) - 1

    sex_thresholds = SexChromosomeThresholds(x_min=x_min, x_max=x_max)
    return templates.TemplateResponse(
        "batch/tabs/FF_XY.html",
        context=dict(
            sex_thresholds={
                "XY_fetal_fraction_y": sex_thresholds.XY_fetal_fraction_y(),
                "XX_lower": sex_thresholds.XX_lower(),
                "XX_upper": sex_thresholds.XX_upper(),
                "XY_upper": sex_thresholds.XY_upper(),
                "XY_lower": sex_thresholds.XY_lower(),
                "XXY": sex_thresholds.XXY(),
            },
            request=request,
            current_user=user,
            colors=COLORS,
            control=control,
            abnormal=abnormal_dict,
            cases=cases,
            max_x=x_max,
            min_x=x_min,
            batch=batch.dict(),
            page_id="batches_FF_XY",
        ),
    )
示例#7
0
def batches(
        request: Request,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """List of all batches"""
    all_batches: List[Batch] = find.batches(adapter=adapter)
    return templates.TemplateResponse(
        "batches.html",
        context={
            "request": request,
            "batches": all_batches,
            "current_user": user,
            "page_id": "all_batches",
        },
    )
示例#8
0
def samples(
        request: Request,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Get sample with id"""
    samples: List[DataBaseSample] = find.samples(adapter=adapter)
    return templates.TemplateResponse(
        "sample/samples.html",
        context=dict(
            request=request,
            current_user=user,
            sample_info=[Sample(**sample.dict()) for sample in samples],
            page_id="samples",
        ),
    )
示例#9
0
def statistics(
        request: Request,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Statistics view."""

    nr_batches = 20
    scatter_plots = ["Stdev_13", "Stdev_18", "Stdev_21"]
    box_plots = [
        "Chr13_Ratio",
        "Chr18_Ratio",
        "Chr21_Ratio",
        "FF_Formatted",
        "DuplicationRate",
        "MappedReads",
        "GC_Dropout",
        "AT_Dropout",
        "Bin2BinVariance",
        "Library_nM",
    ]

    batches = get_last_batches(adapter=adapter, nr_of_batches=nr_batches)
    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(
            request=request,
            current_user=user,
            ticks=list(range(0, nr_batches)),
            nr_batches=nr_batches,
            batch_ids=batch_ids,
            box_stat=box_stat,
            box_plots=box_plots,
            scatter_stat=scatter_stat,
            scatter_plots=scatter_plots,
            page_id="statistics",
        ),
    )
示例#10
0
def users(
        request: Request,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Admin view with table of all users."""
    if user.role != "admin":
        CredentialsError(message="Only admin users can access the users page")

    user_list: List[User] = find.users(adapter=adapter)
    return templates.TemplateResponse(
        "users.html",
        context={
            "request": request,
            "users": user_list,
            "page_id": "users",
            "current_user": user,
        },
    )
示例#11
0
def batch(
        request: Request,
        batch_id: str,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Batch view with table of all samples in the batch."""

    samples: List[DataBaseSample] = find.batch_samples(batch_id=batch_id,
                                                       adapter=adapter)
    return templates.TemplateResponse(
        "batch/tabs/table.html",
        context={
            "request": request,
            "batch": find.batch(batch_id=batch_id, adapter=adapter),
            "sample_info": [Sample(**sample.dict()) for sample in samples],
            "page_id": "batches",
            "current_user": user,
        },
    )
示例#12
0
def sample(
        request: Request,
        sample_id: str,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """Post sample with id"""

    sample: DataBaseSample = find.sample(sample_id=sample_id, adapter=adapter)
    batch: Batch = find.batch(batch_id=sample.batch_id, adapter=adapter)
    return templates.TemplateResponse(
        "sample/sample.html",
        context=dict(
            request=request,
            current_user=user,
            chrom_abnorm=CHROM_ABNORM,
            sample=Sample(**sample.dict()),
            status_classes=STATUS_CLASSES,
            batch=batch,
            page_id="sample",
        ),
    )
示例#13
0
def fetal_fraction(
        request: Request,
        batch_id: str,
        adapter: StatinaAdapter = Depends(get_nipt_adapter),
        user: User = Depends(get_current_user),
):
    """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(
            request=request,
            current_user=user,
            colors=COLORS,
            control=get_fetal_fraction.samples(adapter=adapter,
                                               batch_id=batch_id,
                                               control_samples=True),
            cases=get_fetal_fraction.samples(adapter=adapter,
                                             batch_id=batch_id),
            batch=batch.dict(),
            page_id="batches_FF",
        ),
    )