Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions qiita_pet/handlers/api_proxy/studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def study_prep_get_req(study_id, user_id):
prep_info = defaultdict(list)
editable = study.can_edit(User(user_id))
for dtype in study.data_types:
dtype_infos = list()
for prep in study.prep_templates(dtype):
if prep.status != 'public' and not editable:
continue
Expand All @@ -214,11 +215,18 @@ def study_prep_get_req(study_id, user_id):
'name': prep.name,
'id': prep.id,
'status': prep.status,
'total_samples': len(prep),
'creation_timestamp': prep.creation_timestamp,
'modification_timestamp': prep.modification_timestamp
}
if start_artifact is not None:
youngest_artifact = prep.artifact.youngest_artifact
info['start_artifact'] = start_artifact.artifact_type
info['start_artifact_id'] = start_artifact.id
info['num_artifact_children'] = len(start_artifact.children)
info['youngest_artifact_name'] = youngest_artifact.name
info['youngest_artifact_type'] = \
youngest_artifact.artifact_type
info['youngest_artifact'] = '%s - %s' % (
youngest_artifact.name, youngest_artifact.artifact_type)
info['ebi_experiment'] = len(
Expand All @@ -228,9 +236,15 @@ def study_prep_get_req(study_id, user_id):
info['start_artifact'] = None
info['start_artifact_id'] = None
info['youngest_artifact'] = None
info['ebi_experiment'] = False
info['ebi_experiment'] = 0

prep_info[dtype].append(info)
dtype_infos.append(info)

# default sort is in ascending order of creation timestamp
sorted_info = sorted(dtype_infos,
key=lambda k: k['creation_timestamp'],
reverse=False)
prep_info[dtype] = sorted_info

return {'status': 'success',
'message': '',
Expand Down
133 changes: 79 additions & 54 deletions qiita_pet/handlers/api_proxy/tests/test_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from os import remove
from shutil import rmtree
from tempfile import mkdtemp
from collections import defaultdict

import pandas as pd
import numpy.testing as npt
Expand Down Expand Up @@ -228,15 +229,19 @@ def test_study_prep_get_req_failed_EBI(self):

# actual test
obs = study_prep_get_req(study.id, user_email)
temp_info = defaultdict(list)
temp_info['16S'] = [
{"status": 'sandbox',
'name': 'Prep information %d' % pt.id,
'start_artifact': None, 'youngest_artifact': None,
'ebi_experiment': False, 'id': pt.id,
'start_artifact_id': None,
'creation_timestamp': pt.creation_timestamp,
'modification_timestamp': pt.modification_timestamp,
'total_samples': 3}]

exp = {
'info': {
'16S': [
{'status': 'sandbox',
'name': 'Prep information %d' % pt.id,
'start_artifact': None, 'youngest_artifact': None,
'ebi_experiment': False, 'id': pt.id,
'start_artifact_id': None}]
},
'info': temp_info,
'message': '',
'status': 'success'}
self.assertEqual(obs, exp)
Expand Down Expand Up @@ -516,24 +521,43 @@ class TestStudyAPI2(TestStudyAPI):
# This test expects a clean DB so creating it's own class
def test_study_prep_get_req(self):
obs = study_prep_get_req(1, 'test@foo.bar')
obs_info = obs['info']['18S']
temp_info = defaultdict(list)
temp_info['18S'] = [{
'id': 1,
'status': 'private',
'name': 'Prep information 1',
'start_artifact_id': 1,
'start_artifact': 'FASTQ',
'youngest_artifact': 'BIOM - BIOM',
'youngest_artifact_name': 'BIOM',
'youngest_artifact_type': 'BIOM',
'num_artifact_children': 2,
'total_samples': 27,
'ebi_experiment': 27,
'modification_timestamp':
obs_info[0]['modification_timestamp'],
'creation_timestamp':
obs_info[0]['creation_timestamp']}, {
'id': 2,
'status': 'private',
'name': 'Prep information 2',
'start_artifact': 'BIOM',
'youngest_artifact': 'BIOM - BIOM',
'youngest_artifact_name': 'BIOM',
'youngest_artifact_type': 'BIOM',
'total_samples': 27,
'num_artifact_children': 0,
'ebi_experiment': 27,
'start_artifact_id': 7,
'modification_timestamp':
obs_info[1]['modification_timestamp'],
'creation_timestamp':
obs_info[1]['creation_timestamp']
}]
exp = {'status': 'success',
'message': '',
'info': {
'18S': [{
'id': 1,
'status': 'private',
'name': 'Prep information 1',
'start_artifact_id': 1,
'start_artifact': 'FASTQ',
'youngest_artifact': 'BIOM - BIOM',
'ebi_experiment': 27}, {
'id': 2,
'status': 'private',
'name': 'Prep information 2',
'start_artifact': 'BIOM',
'youngest_artifact': 'BIOM - BIOM',
'ebi_experiment': 27,
'start_artifact_id': 7}]}}
'info': temp_info}
self.assertEqual(obs, exp)

# Add a new prep template
Expand All @@ -543,47 +567,48 @@ def test_study_prep_get_req(self):
pd.DataFrame({'new_col': {'1.SKD6.640190': 1}}),
qdb.study.Study(1), '16S')
obs = study_prep_get_req(1, 'test@foo.bar')
temp_info['16S'] = [{'id': pt.id,
'status': 'sandbox',
'name': 'Prep information %d' % pt.id,
'creation_timestamp': pt.creation_timestamp,
'modification_timestamp':
pt.modification_timestamp,
'total_samples': 1,
'start_artifact_id': None,
'start_artifact': None,
'youngest_artifact': None,
'ebi_experiment': 0}]
exp = {'status': 'success',
'message': '',
'info': {
'18S': [{'id': 1,
'status': 'private',
'name': 'Prep information 1',
'start_artifact_id': 1,
'start_artifact': 'FASTQ',
'youngest_artifact': 'BIOM - BIOM',
'ebi_experiment': 27},
{'id': 2,
'status': 'private',
'name': 'Prep information 2',
'start_artifact_id': 7,
'start_artifact': 'BIOM',
'youngest_artifact': 'BIOM - BIOM',
'ebi_experiment': 27}],
'16S': [{'id': pt.id,
'status': 'sandbox',
'name': 'Prep information %d' % pt.id,
'start_artifact_id': None,
'start_artifact': None,
'youngest_artifact': None,
'ebi_experiment': 0}]}}
'info': temp_info}
self.assertEqual(obs, exp)

obs = study_prep_get_req(1, 'admin@foo.bar')
self.assertEqual(obs, exp)

qdb.artifact.Artifact(1).visibility = 'public'
obs = study_prep_get_req(1, 'demo@microbio.me')
temp_info = defaultdict(list)
temp_info['18S'] = [{
'id': 1,
'status': 'public',
'name': 'Prep information 1',
'start_artifact_id': 1,
'start_artifact': 'FASTQ',
'youngest_artifact': 'BIOM - BIOM',
'youngest_artifact_name': 'BIOM',
'youngest_artifact_type': 'BIOM',
'num_artifact_children': 2,
'total_samples': 27,
'ebi_experiment': 27,
'modification_timestamp':
obs_info[0]['modification_timestamp'],
'creation_timestamp':
obs_info[0]['creation_timestamp']}]
temp_info['16S'] = []
exp = {'status': 'success',
'message': '',
'info': {
'18S': [{'id': 1,
'status': 'public',
'name': 'Prep information 1',
'start_artifact_id': 1,
'start_artifact': 'FASTQ',
'youngest_artifact': 'BIOM - BIOM',
'ebi_experiment': 27}]}}
'info': temp_info}
self.assertEqual(obs, exp)
# Reset visibility of the artifacts
for i in range(4, 0, -1):
Expand Down
24 changes: 18 additions & 6 deletions qiita_pet/templates/study_ajax/data_type_menu.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{% from qiita_core.qiita_settings import qiita_config %}

<style>
.green {
color: green;
}

.red {
color: red;
}
</style>


<script type="text/javascript">
function toggle_color_prep(div){
div.parent().children().each(function() {
Expand All @@ -9,6 +20,8 @@
}
</script>

<!-- <script src="https://use.fontawesome.com/0c9cdb020f.js"></script> -->

{% if prep_info %}
<h3>Data Types <small>(click on the tabs)</small></h3>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
Expand All @@ -27,15 +40,14 @@ <h4 class="panel-title">
<div class="panel-body" style="padding: 0px 0px 0px 0px; border: none;">
{% for prep in prep_info[dt] %}
<div class="panel-body-element" style="padding: 20px 20px 20px 20px;">
{% if prep['ebi_experiment'] %}
<img src="{% raw qiita_config.portal_dir %}/static/img/ena.png" style="width:20px;height:20px;"> ({{prep['ebi_experiment']}})
{% end %}
Samples: {{ prep['total_samples'] }}{% if prep['ebi_experiment'] %}, <img src="{% raw qiita_config.portal_dir %}/static/img/ena.png" style="width:20px;height:20px;"> {{prep['ebi_experiment']}} {% end %}
<a href="#" style="display:block;color:black;" onclick="toggle_color_prep($(this).parent()); populate_main_div('{% raw qiita_config.portal_dir %}/study/description/prep_template/', { prep_id: {{prep['id']}}, study_id: {{study_id}} });">
<span id="prep-header-{{prep['id']}}">
{{prep['name']}} - ID {{prep['id']}} - {{prep['status']}}
{{prep['name']}} - ID: {{prep['id']}} - {{prep['status']}}
</span><br/>
{{prep['start_artifact']}} - ID {{prep['start_artifact_id']}}<br/>
{{prep['youngest_artifact']}}
Raw files {% if prep['start_artifact'] == 'FASTQ' %}<i class="fa fa-check green"></i>{% else %}<i class="fa fa-times red"></i>{% end %}, processed {% if prep['num_artifact_children'] > 0 %}<i class="fa fa-check green"></i> {% if prep['num_artifact_children'] > 1 %} <i class="fa fa-check green"></i>{% end%}{% else %}<i class="fa fa-times red"></i>{% end %}, BIOM {% if prep['youngest_artifact_type'] == 'BIOM' %}<i class="fa fa-check green"></i>{% else %}<i class="fa fa-times red"></i>{% end %}
<br />
Created: {{prep['creation_timestamp'].strftime('%B %-d, %Y')}}, last updated: {{prep['modification_timestamp'].strftime('%B %-d, %Y')}}
</a>
</div>
{% end %}
Expand Down