Skip to content

Commit

Permalink
sample search view (#98)
Browse files Browse the repository at this point in the history
* sample search view

* Update CHANGELOG.md
  • Loading branch information
mayabrandi committed Jul 9, 2021
1 parent 2ce5357 commit 24ab085
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ This change log will document the notable changes to this project in this file a


## [x.x.x]
### Added
- samples view

## [1.1.0]

Expand Down
21 changes: 20 additions & 1 deletion statina/API/external/api/api_v1/endpoints/sample.py
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, List

from fastapi import APIRouter, Depends, Request

Expand All @@ -19,6 +19,25 @@
router = APIRouter()


@router.get("/samples/")
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",
),
)


@router.get("/samples/{sample_id}/")
def sample(
request: Request,
Expand Down
Expand Up @@ -18,6 +18,8 @@
<li class="divider"></li>
<a class="active" href={{ url_for('logout') }}><i class="fa fa-sign-out"></i> Sign Out</a>
<li class="divider"></li>
<a class="active" href={{ url_for('samples') }}><i class="fa fa-sign-out"></i> All samples</a>
<li class="divider"></li>
{% if current_user.role=='admin' %}
<a class="active" href="{{ url_for('users') }}"><i class="fa fa-home"></i> Users</a>
{% endif %}
Expand Down
89 changes: 89 additions & 0 deletions statina/API/external/api/api_v1/templates/sample/samples.html
@@ -0,0 +1,89 @@
{% extends 'layout/layout.html' %}
{% include 'layout/navigation.html' %}

{% block body %}
<div class="container-fluid">
<div class="jumbotron vertical-center">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header"><strong>NIPT Samples</strong></h1>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div id="batch_list">
<div class="panel-body">
<div class="table-responsive">
<table id="sample_table" class="table table-bordered table-hover" >
<thead>
<tr>
<th>Sample Name</th>
<th>Batch ID</th>
<th>Zscore 13</th>
<th>Zscore 18</th>
<th>Zscore 21</th>
<th>Zscore X</th>
<th>FF-PF (%)</th>
<th>FF-X (%)</th>
<th>FF-Y (%)</th>
<th>Sex</th>
<th>CNVSegment</th>
<th><a href="#" data-toggle="tooltip" data-placement="bottom" title="Warning for chomosome abnormality. Automatically generated. Based on pre defined Zscore and Fetal Fraction trsholds">Warning</a></th>
<th>QC Flagg</th>
<th><a href="#" data-toggle="tooltip" data-placement="bottom" title="Chomosome abnormalies. Manually classified by user through the sample page">Status</a></th>
<th>Download</th>
<th><a href="#" data-toggle="tooltip" data-placement="bottom" title="Samples checked in the 'Include' column are added to the validation sample set for comparison. Check the checkboxes for samples to include and save. If all samples are ok, just press 'set all OK'.">Include</a></th>
<th>Comment</th>
<th>Last Change</th>
</tr>
</thead>
<tbody>
{% for sample in sample_info %}
<tr>
<td width="10%"> <a href={{ url_for('sample', sample_id=sample.sample_id) }}>{{ sample.sample_id }}</a></td>
<td width="10%"> <a href={{ url_for('batch', batch_id=sample.batch_id) }}>{{ sample.batch_id }}</a></td>
<td width="3%" class = "{{ sample.warnings.Zscore_13}}">{{ sample.Zscore_13 }}</td>
<td width="3%" class = "{{ sample.warnings.Zscore_18}}">{{ sample.Zscore_18 }}</td>
<td width="3%" class = "{{ sample.warnings.Zscore_21}}">{{ sample.Zscore_21 }}</td>
<td width="3%" class = "{{ sample.warnings.Zscore_X}}">{{ sample.Zscore_X }}</td>
<td width="3%" class = "{{sample.warnings.FF_Formatted}}">{{sample.FF_Formatted}}</td>
<td width="3%" class = "default">{{sample.FFX}}</td>
<td width="3%" class = "{{sample.warnings.FFY}}">{{sample.FFY}}</td>
<td width="3%" class = "default">{{sample.sex}}</td>
<td width="3%" class = "default">{{sample.CNVSegment}}</td>
<td width="3%"><p> <small>{{ sample.text_warning }}</small></p></td>
<td width="3%" class = "default">{{sample.QCFlag}}</td>
<td><p> <small>{{ sample.status }}</small></p></td>
<td><a class="dropdown-item" href="{{ url_for('sample_download', file_id='segmental_calls', sample_id=sample.sample_id) }}">segmental calls</a></td>
<td width="1%" {% if sample.include %}class="success"{% endif %}>{{sample.include }}</td>
<td width="18%">{{sample.comment}}</td>
<td ><small>{{sample.change_include_date}}</small></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

{% block scripts %}
<script>
$(document).ready(function () {
var table = $('#sample_table').DataTable({
order: [[1, "dec"]],
paging: true
});

table.buttons().container()
.appendTo('#sample_table_wrapper .col-sm-6:eq(0)');
});
</script>
{% endblock %}

7 changes: 7 additions & 0 deletions statina/crud/find/find.py
Expand Up @@ -28,6 +28,13 @@ def user(
return User(**raw_user)


def samples(adapter: StatinaAdapter) -> List[DataBaseSample]:
"""Return all batches from the batch collection"""

raw_samples: Iterable[dict] = adapter.sample_collection.find()
return parse_obj_as(List[DataBaseSample], list(raw_samples))


def sample(adapter: StatinaAdapter, sample_id: str) -> Optional[DataBaseSample]:
"""Find one sample from the sample collection"""

Expand Down

0 comments on commit 24ab085

Please sign in to comment.