-
Notifications
You must be signed in to change notification settings - Fork 80
DataTables load using AJAX, Search by metadata on studies page #1006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
616300f
d595016
90313f7
fb5eef3
1ffd4bc
16257c4
9ccc098
abeb46f
259bec2
b8472a8
cf6ca77
cd4f66e
ce4d334
58b28cd
1872555
4b7ffcf
515f0f6
21b17d6
04f87f4
ee4c9e2
ef16d18
fbe7c74
e0f22d0
0df6666
5085c35
ea69fe8
3a12f87
25ae8f2
e01e224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,12 +98,14 @@ | |
from __future__ import division | ||
from future.utils import viewitems | ||
from copy import deepcopy | ||
from itertools import chain | ||
import warnings | ||
|
||
from qiita_core.exceptions import IncompetentQiitaDeveloperError | ||
from .base import QiitaObject | ||
from .exceptions import (QiitaDBStatusError, QiitaDBColumnError, QiitaDBError) | ||
from .util import (check_required_columns, check_table_cols, convert_to_id, | ||
get_environmental_packages, infer_status) | ||
get_environmental_packages, get_table_cols, infer_status) | ||
from .sql_connection import SQLConnectionHandler | ||
|
||
|
||
|
@@ -142,7 +144,12 @@ class Study(QiitaObject): | |
""" | ||
_table = "study" | ||
# The following columns are considered not part of the study info | ||
_non_info = {"email", "study_title"} | ||
_non_info = frozenset(["email", "study_title"]) | ||
# The following tables are considered part of info | ||
_info_cols = frozenset(chain( | ||
get_table_cols('study'), get_table_cols('study_status'), | ||
get_table_cols('timeseries_type'), get_table_cols('portal_type'), | ||
get_table_cols('study_pmid'))) | ||
|
||
def _lock_non_sandbox(self, conn_handler): | ||
"""Raises QiitaDBStatusError if study is non-sandboxed""" | ||
|
@@ -198,6 +205,45 @@ def get_by_status(cls, status): | |
|
||
return studies | ||
|
||
@classmethod | ||
def get_info(cls, study_ids=None, info_cols=None): | ||
"""Returns study data for a set of study_ids | ||
|
||
Parameters | ||
---------- | ||
study_ids : list of ints, optional | ||
Studies to get information for. Defauls to all studies | ||
info_cols: list of str, optional | ||
Information columns to retrieve. Defaults to all study data | ||
|
||
Returns | ||
------- | ||
list of DictCursor | ||
Table-like structure of metadata, one study per row. Can be | ||
accessed as a list of dictionaries, keyed on column name. | ||
""" | ||
if info_cols is None: | ||
info_cols = cls._info_cols | ||
elif not cls._info_cols.issuperset(info_cols): | ||
warnings.warn("Non-info columns passed: %s" % ", ".join( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a warning or an error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A warning, as suggested by @adamrp. |
||
set(info_cols) - cls._info_cols)) | ||
|
||
search_cols = ",".join(sorted(cls._info_cols.intersection(info_cols))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might raise a warning if the user requests information columns that are not in |
||
|
||
sql = """SELECT {0} FROM ( | ||
qiita.study | ||
JOIN qiita.timeseries_type USING (timeseries_type_id) | ||
JOIN qiita.portal_type USING (portal_type_id) | ||
LEFT JOIN (SELECT study_id, array_agg(pmid ORDER BY pmid) as | ||
pmid FROM qiita.study_pmid GROUP BY study_id) sp USING (study_id) | ||
)""".format(search_cols) | ||
if study_ids is not None: | ||
sql = "{0} WHERE study_id in ({1})".format( | ||
sql, ','.join(str(s) for s in study_ids)) | ||
|
||
conn_handler = SQLConnectionHandler() | ||
return conn_handler.execute_fetchall(sql) | ||
|
||
@classmethod | ||
def exists(cls, study_title): | ||
"""Check if a study exists based on study_title, which is unique | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- March 19, 2015 | ||
-- Rename columns to be more descriptive and allow easier joins | ||
ALTER TABLE qiita.processed_data_status RENAME COLUMN description TO processed_data_status_description; | ||
ALTER TABLE qiita.portal_type RENAME COLUMN description TO portal_description; | ||
ALTER TABLE qiita.investigation RENAME COLUMN description TO investigation_description; | ||
ALTER TABLE qiita.investigation RENAME COLUMN name TO investigation_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of this information will change at runtime, right? If so, I think this could be cached in
qiita_pet.__init__
and done onceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah! nevermind, it is at the static scope of the object. it is done once