Skip to content

Commit 61053a3

Browse files
committed
address comments
1 parent 5085c35 commit 61053a3

File tree

6 files changed

+55
-91
lines changed

6 files changed

+55
-91
lines changed

qiita_db/study.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,21 @@ def get_by_status(cls, status):
206206
return studies
207207

208208
@classmethod
209-
def get_info(cls, study_ids, info_cols=None):
209+
def get_info(cls, study_ids=None, info_cols=None):
210210
"""Returns study data for a set of study_ids
211211
212212
Parameters
213213
----------
214-
study_ids : list of ints
215-
Studies to get information for.
214+
study_ids : list of ints, optional
215+
Studies to get information for. Defauls to all studies
216216
info_cols: list of str, optional
217217
Information columns to retrieve. Defaults to all study data
218218
219219
Returns
220220
-------
221221
list of DictCursor
222222
Table-like structure of metadata, one study per row. Can be
223-
accessed as a list of dictionaries.
223+
accessed as a list of dictionaries, keyed on column name.
224224
"""
225225
if info_cols is None:
226226
info_cols = cls._info_cols
@@ -236,8 +236,10 @@ def get_info(cls, study_ids, info_cols=None):
236236
JOIN qiita.portal_type USING (portal_type_id)
237237
LEFT JOIN (SELECT study_id, array_agg(pmid ORDER BY pmid) as
238238
pmid FROM qiita.study_pmid GROUP BY study_id) sp USING (study_id)
239-
) WHERE study_id in ({1})""".format(
240-
search_cols, ','.join(str(s) for s in study_ids))
239+
)""".format(search_cols)
240+
if study_ids is not None:
241+
sql = "{0} WHERE study_id in ({1})".format(
242+
sql, ','.join(str(s) for s in study_ids))
241243

242244
conn_handler = SQLConnectionHandler()
243245
return conn_handler.execute_fetchall(sql)

qiita_db/support_files/patches/19.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ UPDATE qiita.processed_data as pd
3131
-- We no longer need the status column on the study table
3232
ALTER TABLE qiita.study DROP CONSTRAINT fk_study_study_status;
3333
DROP INDEX qiita.idx_study_0;
34-
ALTER TABLE qiita.study DROP COLUMN study_status_id;
34+
ALTER TABLE qiita.study DROP COLUMN study_status_id;

qiita_db/support_files/patches/20.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- March 19, 2015
22
-- Rename columns to be more descriptive and allow easier joins
3-
ALTER TABLE qiita.processed_data_status RENAME COLUMN description TO status_description;
3+
ALTER TABLE qiita.processed_data_status RENAME COLUMN description TO processed_data_status_description;
44
ALTER TABLE qiita.portal_type RENAME COLUMN description TO portal_description;
55
ALTER TABLE qiita.investigation RENAME COLUMN description TO investigation_description;
66
ALTER TABLE qiita.investigation RENAME COLUMN name TO investigation_name;

qiita_db/test/test_study.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def _change_processed_data_status(self, new_status):
180180
(id_status,))
181181

182182
def test_get_info(self):
183+
# Test get all info for single study
183184
obs = Study.get_info([1])
184185
self.assertEqual(len(obs), 1)
185186
obs = dict(obs[0])
@@ -213,6 +214,7 @@ def test_get_info(self):
213214
'Soils', 'number_samples_collected': 27}
214215
self.assertItemsEqual(obs, exp)
215216

217+
# Test get specific keys for single study
216218
exp_keys = ['metadata_complete', 'reprocess', 'timeseries_type',
217219
'portal_description', 'pmid', 'study_title']
218220
obs = Study.get_info([1], exp_keys)
@@ -227,6 +229,28 @@ def test_get_info(self):
227229
'Soils'}
228230
self.assertItemsEqual(obs, exp)
229231

232+
# Test get specific keys for all studies
233+
info = {
234+
'timeseries_type_id': 1,
235+
'portal_type_id': 1,
236+
'lab_person_id': None,
237+
'principal_investigator_id': 3,
238+
'metadata_complete': False,
239+
'mixs_compliant': True,
240+
'study_description': 'desc',
241+
'study_alias': 'alias',
242+
'study_abstract': 'abstract'}
243+
user = User('test@foo.bar')
244+
245+
Study.create(user, 'test_study_1', efo=[1], info=info)
246+
obs = Study.get_info(info_cols=exp_keys)
247+
exp = [[True, ['123456', '7891011'], 'EMP portal', False,
248+
'Identification of the Microbiomes for Cannabis Soils',
249+
'None'],
250+
[False, None, 'QIIME portal', False, 'test_study_1', 'None']]
251+
self.assertEqual(obs, exp)
252+
253+
230254
def test_has_access_public(self):
231255
self._change_processed_data_status('public')
232256
self.assertTrue(self.study.has_access(User("demo@microbio.me")))

qiita_pet/handlers/study_handlers/listing_handlers.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from tornado.gen import coroutine, Task
1414
from pyparsing import ParseException
1515

16-
from qiita_core.exceptions import IncompetentQiitaDeveloperError
1716
from qiita_db.user import User
1817
from qiita_db.study import Study, StudyPerson
1918
from qiita_db.search import QiitaStudySearch
@@ -43,34 +42,29 @@ def _get_shared_links_for_study(study):
4342
return ", ".join(shared)
4443

4544

46-
def _build_study_info(studytype, user, results=None):
47-
"""builds list of namedtuples for study listings"""
48-
if studytype not in {"standard", "shared"}:
49-
raise IncompetentQiitaDeveloperError("Must use standard or shared!")
45+
def _build_study_info(user, results=None):
46+
"""builds list of dicts for studies table, with all html formatted"""
5047
# get list of studies for table
51-
if studytype == "standard":
52-
studylist = user.user_studies.union(Study.get_by_status('public'))
53-
elif studytype == "shared":
54-
studylist = user.shared_studies
48+
study_list = user.user_studies.union(
49+
Study.get_by_status('public')).union(user.shared_studies)
5550
if results is not None:
56-
studylist = studylist.intersection(results)
57-
if not studylist:
51+
study_list = study_list.intersection(results)
52+
if not study_list:
5853
# No studies left so no need to continue
5954
return []
6055

6156
# get info for the studies
6257
cols = ['study_id', 'status', 'email', 'principal_investigator_id',
6358
'pmid', 'study_title', 'metadata_complete',
6459
'number_samples_collected', 'study_abstract']
65-
study_info = Study.get_info(studylist, cols)
60+
study_info = Study.get_info(study_list, cols)
6661

6762
infolist = []
6863
for row, info in enumerate(study_info):
6964
study = Study(info['study_id'])
7065
status = study.status
7166
# Just passing the email address as the name here, since
7267
# name is not a required field in qiita.qiita_user
73-
owner = study_person_linkifier((info['email'], info['email']))
7468
PI = StudyPerson(info['principal_investigator_id'])
7569
PI = study_person_linkifier((PI.email, PI.name))
7670
if info['pmid'] is not None:
@@ -85,12 +79,12 @@ def _build_study_info(studytype, user, results=None):
8579
# build the HTML elements needed for table cell
8680
title = ("<a href='#' data-toggle='modal' "
8781
"data-target='#study-abstract-modal' "
88-
"onclick='fillAbstract(\"{0}-studies-table\", {1})'>"
82+
"onclick='fillAbstract(\"studies-table\", {0})'>"
8983
"<span class='glyphicon glyphicon-file' "
9084
"aria-hidden='true'></span></a> | "
91-
"<a href='/study/description/{2}' "
92-
"id='study{1}-title'>{3}</a>").format(
93-
studytype, str(row), str(study.id), info["study_title"])
85+
"<a href='/study/description/{1}' "
86+
"id='study{0}-title'>{2}</a>").format(
87+
str(row), str(study.id), info["study_title"])
9488
meta_complete = "<span class='glyphicon glyphicon-%s'></span>" % \
9589
meta_complete_glyph
9690
if status == 'public':
@@ -112,7 +106,6 @@ def _build_study_info(studytype, user, results=None):
112106
"num_raw_data": len(study.raw_data()),
113107
"pi": PI,
114108
"pmid": pmids,
115-
"owner": owner,
116109
"status": status,
117110
"abstract": info["study_abstract"]
118111

@@ -133,9 +126,9 @@ class ListStudiesHandler(BaseHandler):
133126
def get(self):
134127
all_emails_except_current = yield Task(self._get_all_emails)
135128
all_emails_except_current.remove(self.current_user.id)
136-
availmeta = SampleTemplate.metadata_headers() +\
129+
avail_meta = SampleTemplate.metadata_headers() +\
137130
get_table_cols("study")
138-
self.render('list_studies.html', availmeta=availmeta,
131+
self.render('list_studies.html', availmeta=avail_meta,
139132
all_emails_except_current=all_emails_except_current)
140133

141134
def _get_all_emails(self, callback):
@@ -194,13 +187,6 @@ def get(self):
194187

195188

196189
class SearchStudiesAJAX(BaseHandler):
197-
def _get_standard(self, user, callback):
198-
callback(_build_study_info("standard", user))
199-
200-
def _get_shared(self, user, callback):
201-
"""builds list of tuples for studies that are shared with user"""
202-
callback(_build_study_info("shared", user))
203-
204190
@authenticated
205191
def get(self, ignore):
206192
search_type = self.get_argument('type')
@@ -215,7 +201,7 @@ def get(self, ignore):
215201
# Search for samples matching the query
216202
search = QiitaStudySearch()
217203
try:
218-
res, meta = search(query, User(user))
204+
res, meta = search(query, self.current_user)
219205
except ParseException:
220206
self.clear()
221207
self.set_status(400)
@@ -240,8 +226,7 @@ def get(self, ignore):
240226
return
241227
if not res:
242228
res = {}
243-
info = _build_study_info(search_type, self.current_user,
244-
results=res)
229+
info = _build_study_info(self.current_user, results=res)
245230
# build the table json
246231
results = {
247232
"sEcho": echo,

qiita_pet/templates/list_studies.html

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
var current_study;
1010
var ajaxURL = "/study/search/?&user={{current_user.id}}&sEcho=" + Math.floor(Math.random()*1001);
1111
$(document).ready(function() {
12-
$('#standard-studies-table').dataTable({
12+
$('#studies-table').dataTable({
1313
"columns": [
1414
{ "data": "checkbox" },
1515
{ "data": "title" },
@@ -23,7 +23,7 @@
2323
{ "data": "pmid" },
2424
{ "data": "status" }
2525
],
26-
order: [[10, "asc"], [ 1, "asc" ]],
26+
order: [[10, "desc"], [ 1, "asc" ]],
2727
columnDefs: [{type:'natural', targets:[3,4,5,9]}, {"targets": [ 2 ],"visible": false}],
2828
"oLanguage": {
2929
"sSearch": "Narrow search results by column data (Title, abstract, PI, etc):",
@@ -34,35 +34,11 @@
3434
"url": ajaxURL + "&type=standard&query=",
3535
"error": function(jqXHR, textStatus, ex) {
3636
$("#submit-button").prop("disabled",false);
37-
$("#search-error").text(jqXHR.responseText);
37+
if(jqXHR.status === 500) { $("#search-error").text("Internal Server Error, please try again later"); }
38+
else { $("#search-error").text(jqXHR.responseText); }
3839
}
3940
}
4041
});
41-
$('#shared-studies-table').dataTable({
42-
"columns": [
43-
{ "data": "checkbox" },
44-
{ "data": "title" },
45-
{ "data": "abstract" },
46-
{ "data": "id" },
47-
{ "data": "owner" },
48-
{ "data": "meta_complete" },
49-
{ "data": "num_samples" },
50-
{ "data": "num_raw_data" },
51-
{ "data": "pi" },
52-
{ "data": "pmid" }
53-
],
54-
order: [[ 1, "asc" ]],
55-
columnDefs: [{type:'natural', targets:[4,5,6]}, {"targets": [ 2 ],"visible": false}],
56-
"oLanguage": {
57-
"sSearch": "Narrow search results by column data (Title, abstract, PI, etc):",
58-
"sLoadingRecords": "Loading table data",
59-
"sZeroRecords": "No studies found"
60-
},
61-
"ajax": {
62-
"url": ajaxURL + "&type=shared&query=",
63-
"error": function(jqXHR, textStatus, ex) {}
64-
}
65-
});
6642

6743
$('#users_list').chosen({width: "100%"});
6844
$('#users_list').on('change', function(evt, params) {
@@ -126,8 +102,8 @@ <h1>Metadata Search</h1>
126102
<!--User Studies-->
127103
<div class="row">
128104
<div class="col-sm-12" id="user-studies-div">
129-
<h1>Your Studies</h1>
130-
<table id="standard-studies-table" class="display table-bordered table-hover">
105+
<h1>Available Studies</h1>
106+
<table id="studies-table" class="display table-bordered table-hover">
131107
<thead>
132108
<tr>
133109
<th></th>
@@ -146,29 +122,6 @@ <h1>Your Studies</h1>
146122
<tbody>
147123
</tbody>
148124
</table>
149-
<!--Shared Studies-->
150-
<form id="study-sel-form" name="study-sel-form">
151-
<div class="row">
152-
<div class="col-sm-12" id="user-studies-div">
153-
<h1>Shared Studies</h1>
154-
<table id="shared-studies-table" class="display table-bordered table-hover">
155-
<thead>
156-
<tr>
157-
<th></th>
158-
<th>Title</th>
159-
<th>Abstract</th>
160-
<th>Study ID</th>
161-
<th>Owner</th>
162-
<th>Metadata Complete</th>
163-
<th>Samples</th>
164-
<th>Sequence Files</th>
165-
<th>Principal Investigator</th>
166-
<th>Pubmed ID(s)</th>
167-
</tr>
168-
</thead>
169-
<tbody>
170-
</tbody>
171-
</table>
172125
<!--Abstract Modal-->
173126
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="study-abstract-modal">
174127
<div class="modal-dialog modal-med">

0 commit comments

Comments
 (0)