Skip to content

Commit 9350269

Browse files
committed
Merge pull request #1006 from squirrelo/cart
DataTables load using AJAX, Search by metadata on studies page
2 parents e1c7a7c + e01e224 commit 9350269

File tree

15 files changed

+2537
-2463
lines changed

15 files changed

+2537
-2463
lines changed

qiita_db/study.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@
9898
from __future__ import division
9999
from future.utils import viewitems
100100
from copy import deepcopy
101+
from itertools import chain
102+
import warnings
101103

102104
from qiita_core.exceptions import IncompetentQiitaDeveloperError
103105
from .base import QiitaObject
104106
from .exceptions import (QiitaDBStatusError, QiitaDBColumnError, QiitaDBError)
105107
from .util import (check_required_columns, check_table_cols, convert_to_id,
106-
get_environmental_packages, infer_status)
108+
get_environmental_packages, get_table_cols, infer_status)
107109
from .sql_connection import SQLConnectionHandler
108110

109111

@@ -142,7 +144,12 @@ class Study(QiitaObject):
142144
"""
143145
_table = "study"
144146
# The following columns are considered not part of the study info
145-
_non_info = {"email", "study_title"}
147+
_non_info = frozenset(["email", "study_title"])
148+
# The following tables are considered part of info
149+
_info_cols = frozenset(chain(
150+
get_table_cols('study'), get_table_cols('study_status'),
151+
get_table_cols('timeseries_type'), get_table_cols('portal_type'),
152+
get_table_cols('study_pmid')))
146153

147154
def _lock_non_sandbox(self, conn_handler):
148155
"""Raises QiitaDBStatusError if study is non-sandboxed"""
@@ -198,6 +205,45 @@ def get_by_status(cls, status):
198205

199206
return studies
200207

208+
@classmethod
209+
def get_info(cls, study_ids=None, info_cols=None):
210+
"""Returns study data for a set of study_ids
211+
212+
Parameters
213+
----------
214+
study_ids : list of ints, optional
215+
Studies to get information for. Defauls to all studies
216+
info_cols: list of str, optional
217+
Information columns to retrieve. Defaults to all study data
218+
219+
Returns
220+
-------
221+
list of DictCursor
222+
Table-like structure of metadata, one study per row. Can be
223+
accessed as a list of dictionaries, keyed on column name.
224+
"""
225+
if info_cols is None:
226+
info_cols = cls._info_cols
227+
elif not cls._info_cols.issuperset(info_cols):
228+
warnings.warn("Non-info columns passed: %s" % ", ".join(
229+
set(info_cols) - cls._info_cols))
230+
231+
search_cols = ",".join(sorted(cls._info_cols.intersection(info_cols)))
232+
233+
sql = """SELECT {0} FROM (
234+
qiita.study
235+
JOIN qiita.timeseries_type USING (timeseries_type_id)
236+
JOIN qiita.portal_type USING (portal_type_id)
237+
LEFT JOIN (SELECT study_id, array_agg(pmid ORDER BY pmid) as
238+
pmid FROM qiita.study_pmid GROUP BY study_id) sp USING (study_id)
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))
243+
244+
conn_handler = SQLConnectionHandler()
245+
return conn_handler.execute_fetchall(sql)
246+
201247
@classmethod
202248
def exists(cls, study_title):
203249
"""Check if a study exists based on study_title, which is unique

qiita_db/support_files/patches/20.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- March 19, 2015
2+
-- Rename columns to be more descriptive and allow easier joins
3+
ALTER TABLE qiita.processed_data_status RENAME COLUMN description TO processed_data_status_description;
4+
ALTER TABLE qiita.portal_type RENAME COLUMN description TO portal_description;
5+
ALTER TABLE qiita.investigation RENAME COLUMN description TO investigation_description;
6+
ALTER TABLE qiita.investigation RENAME COLUMN name TO investigation_name;

qiita_db/support_files/populate_test_db.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ INSERT INTO qiita.study_users (study_id, email) VALUES (1, 'shared@foo.bar');
4949
INSERT INTO qiita.study_pmid (study_id, pmid) VALUES (1, '123456'), (1, '7891011');
5050

5151
-- Insert an investigation
52-
INSERT INTO qiita.investigation (name, description, contact_person_id) VALUES
52+
INSERT INTO qiita.investigation (investigation_name, investigation_description, contact_person_id) VALUES
5353
('TestInvestigation', 'An investigation for testing purposes', 3);
5454

5555
-- Insert investigation_study (link study 1 with investigation 1)

qiita_db/support_files/qiita-db.dbs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@
518518
<table name="investigation" >
519519
<comment>Overarching investigation information.An investigation comprises one or more individual studies.</comment>
520520
<column name="investigation_id" type="bigserial" jt="-5" mandatory="y" />
521-
<column name="name" type="varchar" jt="12" mandatory="y" />
522-
<column name="description" type="varchar" jt="12" mandatory="y" >
521+
<column name="investigation_name" type="varchar" jt="12" mandatory="y" />
522+
<column name="investigation_description" type="varchar" jt="12" mandatory="y" >
523523
<comment><![CDATA[Describes the overarching goal of the investigation]]></comment>
524524
</column>
525525
<column name="contact_person_id" type="bigint" jt="-5" />
@@ -682,7 +682,7 @@
682682
<comment>What portals are available to show a study in</comment>
683683
<column name="portal_type_id" type="bigserial" jt="-5" mandatory="y" />
684684
<column name="portal" type="varchar" jt="12" mandatory="y" />
685-
<column name="description" type="varchar" jt="12" mandatory="y" />
685+
<column name="portal_description" type="varchar" jt="12" mandatory="y" />
686686
<index name="pk_portal_type" unique="PRIMARY_KEY" >
687687
<column name="portal_type_id" />
688688
</index>
@@ -1000,7 +1000,7 @@
10001000
<table name="processed_data_status" >
10011001
<column name="processed_data_status_id" type="bigserial" jt="-5" mandatory="y" />
10021002
<column name="processed_data_status" type="varchar" jt="12" mandatory="y" />
1003-
<column name="description" type="varchar" jt="12" mandatory="y" />
1003+
<column name="processed_data_status_description" type="varchar" jt="12" mandatory="y" />
10041004
<index name="pk_study_status" unique="PRIMARY_KEY" >
10051005
<column name="processed_data_status_id" />
10061006
</index>
@@ -1565,7 +1565,6 @@ Controlled Vocabulary]]></comment>
15651565
<connector name="PostgreSQL" database="PostgreSQL" driver_class="org.postgresql.Driver" driver_jar="postgresql-9.2-1003.jdbc3.jar" host="localhost" port="5432" instance="qiita_test" user="mcdonadt" schema_mapping="" />
15661566
<layout id="Layout669806" name="qiita" show_relation_columns="y" >
15671567
<entity schema="qiita" name="controlled_vocab_values" color="d0def5" x="45" y="1545" />
1568-
<entity schema="qiita" name="investigation" color="c0d4f3" x="2100" y="255" />
15691568
<entity schema="qiita" name="investigation_study" color="c0d4f3" x="2100" y="405" />
15701569
<entity schema="qiita" name="job_results_filepath" color="c0d4f3" x="405" y="855" />
15711570
<entity schema="qiita" name="analysis_job" color="d0def5" x="285" y="930" />
@@ -1635,10 +1634,11 @@ Controlled Vocabulary]]></comment>
16351634
<entity schema="qiita" name="analysis" color="d0def5" x="225" y="720" />
16361635
<entity schema="qiita" name="study_experimental_factor" color="c0d4f3" x="2100" y="495" />
16371636
<entity schema="qiita" name="study_pmid" color="c0d4f3" x="2145" y="600" />
1638-
<entity schema="qiita" name="portal_type" color="c0d4f3" x="1995" y="660" />
16391637
<entity schema="qiita" name="study" color="d0def5" x="1815" y="60" />
16401638
<entity schema="qiita" name="processed_data" color="d0def5" x="1275" y="960" />
1641-
<entity schema="qiita" name="processed_data_status" color="c0d4f3" x="1530" y="1050" />
1639+
<entity schema="qiita" name="investigation" color="c0d4f3" x="2100" y="255" />
1640+
<entity schema="qiita" name="processed_data_status" color="c0d4f3" x="1500" y="1050" />
1641+
<entity schema="qiita" name="portal_type" color="c0d4f3" x="1995" y="660" />
16421642
<group name="Group_analyses" color="c4e0f9" >
16431643
<comment>analysis tables</comment>
16441644
<entity schema="qiita" name="analysis" />

0 commit comments

Comments
 (0)