Skip to content

Commit

Permalink
Merge 1a50f0c into 3116fea
Browse files Browse the repository at this point in the history
  • Loading branch information
josenavas committed Nov 20, 2016
2 parents 3116fea + 1a50f0c commit 5b87ca8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
13 changes: 11 additions & 2 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ def test_supported_filepath_types(self):
self.assertItemsEqual(obs, exp)


@qiita_test_checker()
class UtilTests(TestCase):
"""Tests for the util functions that do not need to access the DB"""

Expand Down Expand Up @@ -813,6 +814,8 @@ def test_generate_study_list(self):
obs_info = qdb.util.generate_study_list([1, 2, 3, 4], False)
self.assertEqual(obs_info, exp_info)

qdb.artifact.Artifact(4).visibility = 'public'
exp_info[0]['status'] = 'public'
exp_info[0]['proc_data_info'] = [{
'data_type': '18S',
'algorithm': 'QIIME (Pick closed-reference OTUs)',
Expand All @@ -834,7 +837,13 @@ def test_generate_study_list(self):
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}, {
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}]
obs_info = qdb.util.generate_study_list([1, 2, 3, 4], True,
public_only=True)
self.assertEqual(obs_info, exp_info)

exp_info[0]['proc_data_info'].extend(
[{
'data_type': '18S',
'algorithm': 'QIIME (Pick closed-reference OTUs)',
'pid': 5,
Expand Down Expand Up @@ -888,7 +897,7 @@ def test_generate_study_list(self):
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192'],
'data_type': '16S'}]
'data_type': '16S'}])

obs_info = qdb.util.generate_study_list([1, 2, 3, 4], True)
self.assertEqual(obs_info, exp_info)
Expand Down
26 changes: 23 additions & 3 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ def supported_filepath_types(artifact_type):
return qdb.sql_connection.TRN.execute_fetchindex()


def generate_study_list(study_ids, build_samples):
def generate_study_list(study_ids, build_samples, public_only=False):
"""Get general study information
Parameters
Expand All @@ -1233,6 +1233,8 @@ def generate_study_list(study_ids, build_samples):
build_samples : bool
If true the sample information for each process artifact within each
study will be included
public_only : bool, optional
If true, return only public BIOM artifacts. Default: false.
Returns
-------
Expand Down Expand Up @@ -1289,6 +1291,14 @@ def generate_study_list(study_ids, build_samples):
LEFT JOIN qiita.artifact_type USING (artifact_type_id)
WHERE artifact_type='BIOM' AND
study_id = qiita.study.study_id) AS artifact_biom_ts,
- all the BIOM visibility sorted by artifact_id that belong to the study
(SELECT array_agg(visibility ORDER BY artifact_id)
FROM qiita.study_artifact
LEFT JOIN qiita.artifact USING (artifact_id)
LEFT JOIN qiita.artifact_type USING (artifact_type_id)
LEFT JOIN qiita.visibility USING (visibility_id)
WHERE artifact_type='BIOM' AND
study_id = qiita.study.study_id) AS artifact_biom_vis,
- all the visibilities of all artifacts that belong to the study
(SELECT array_agg(DISTINCT visibility)
FROM qiita.study_artifact
Expand Down Expand Up @@ -1352,6 +1362,13 @@ def generate_study_list(study_ids, build_samples):
LEFT JOIN qiita.artifact_type USING (artifact_type_id)
WHERE artifact_type='BIOM' AND
study_id = qiita.study.study_id) AS artifact_biom_ts,
(SELECT array_agg(visibility ORDER BY artifact_id)
FROM qiita.study_artifact
LEFT JOIN qiita.artifact USING (artifact_id)
LEFT JOIN qiita.artifact_type USING (artifact_type_id)
LEFT JOIN qiita.visibility USING (visibility_id)
WHERE artifact_type='BIOM' AND
study_id = qiita.study.study_id) AS artifact_biom_vis,
(SELECT array_agg(DISTINCT visibility)
FROM qiita.study_artifact
LEFT JOIN qiita.artifact USING (artifact_id)
Expand Down Expand Up @@ -1414,8 +1431,10 @@ def generate_study_list(study_ids, build_samples):
to_loop = zip(
info['artifact_biom_ids'], info['artifact_biom_dts'],
info['artifact_biom_ts'], info['artifact_biom_params'],
info['artifact_biom_cmd'])
for artifact_id, dt, ts, params, cmd in to_loop:
info['artifact_biom_cmd'], info['artifact_biom_vis'])
for artifact_id, dt, ts, params, cmd, vis in to_loop:
if public_only and vis != 'public':
continue
proc_info = {'processed_date': str(ts)}
proc_info['pid'] = artifact_id
proc_info['data_type'] = dt
Expand Down Expand Up @@ -1476,6 +1495,7 @@ def generate_study_list(study_ids, build_samples):
del info["artifact_biom_ts"]
del info["artifact_biom_params"]
del info['artifact_biom_cmd']
del info['artifact_biom_vis']

infolist.append(info)

Expand Down
3 changes: 2 additions & 1 deletion qiita_pet/handlers/study_handlers/listing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def _build_study_info(user, search_type, study_proc=None, proc_samples=None):
# No studies left so no need to continue
return []

return generate_study_list([s.id for s in study_set], build_samples)
return generate_study_list([s.id for s in study_set], build_samples,
public_only=(search_type == 'public'))


class ListStudiesHandler(BaseHandler):
Expand Down

0 comments on commit 5b87ca8

Please sign in to comment.