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
2 changes: 1 addition & 1 deletion qiita_db/support_files/populate_test_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ INSERT INTO qiita.message_user (message_id, email) VALUES (1, 'test@foo.bar'),(1

-- Create a loggin entry
INSERT INTO qiita.logging (time, severity_id, msg, information)
VALUES ('Sun Nov 22 21:29:30 2015', 2, 'Error message', NULL);
VALUES ('Sun Nov 22 21:29:30 2015', 2, 'Error message', '{}');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If information can't be NULL there should be an error somewhere (either the interface is assuming that is always there, or either the database should have a NOT NULL restriction and update the python code accordingly).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be blocking so I added an issue: #1553


-- Create some processing jobs
INSERT INTO qiita.processing_job
Expand Down
6 changes: 6 additions & 0 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,5 +688,11 @@ def test_infer_status(self):
obs = qdb.util.infer_status([['sandbox'], ['sandbox']])
self.assertEqual(obs, 'sandbox')

def test_get_pubmed_ids_from_dois(self):
exp = {'10.100/123456': '123456'}
obs = qdb.util.get_pubmed_ids_from_dois(['', '10.100/123456'])
self.assertEqual(obs, exp)


if __name__ == '__main__':
main()
25 changes: 25 additions & 0 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
move_filepaths_to_upload_folder
move_upload_files_to_trash
add_message
get_pubmed_ids_from_dois
"""
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
Expand Down Expand Up @@ -1057,6 +1058,30 @@ def get_timeseries_types():
return qdb.sql_connection.TRN.execute_fetchindex()


def get_pubmed_ids_from_dois(doi_ids):
"""Get the dict of pubmed ids from a list of doi ids

Parameters
----------
doi_ids : list of str
The list of doi ids

Returns
-------
dict of {doi: pubmed_id}
Return dict of doi and pubmed ids

Notes
-----
If doi doesn't exist it will not return that {key: value} pair
"""
with qdb.sql_connection.TRN:
sql = "SELECT doi, pubmed_id FROM qiita.publication WHERE doi IN %s"
qdb.sql_connection.TRN.add(sql, [tuple(doi_ids)])
return {row[0]: row [1]
for row in qdb.sql_connection.TRN.execute_fetchindex()}


def check_access_to_analysis_result(user_id, requested_path):
"""Get filepath IDs for a particular requested_path, if user has access

Expand Down
24 changes: 16 additions & 8 deletions qiita_pet/handlers/analysis_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from qiita_pet.exceptions import QiitaPetAuthorizationError
from qiita_ware.dispatchable import run_analysis
from qiita_db.analysis import Analysis
from qiita_db.artifact import Artifact
from qiita_db.job import Job, Command
from qiita_db.util import (get_db_files_base_dir,
check_access_to_analysis_result,
Expand Down Expand Up @@ -163,7 +164,7 @@ def get(self, analysis_id):
for proc_data_id, samples in viewitems(dropped_samples):
if not samples:
continue
proc_data = ProcessedData(proc_data_id)
proc_data = Artifact(proc_data_id)
data_type = proc_data.data_type()
study = proc_data.study
dropped[data_type].append((Study(study).title, len(samples),
Expand Down Expand Up @@ -214,8 +215,7 @@ def get(self):
level = self.get_argument('level', '')
user = self.current_user

analyses = [Analysis(a) for a in
user.shared_analyses | user.private_analyses]
analyses = user.shared_analyses | user.private_analyses

is_local_request = is_localhost(self.request.headers['host'])
gfi = partial(get_filepath_id, 'analysis')
Expand Down Expand Up @@ -307,13 +307,21 @@ def get(self):
# Format sel_data to get study IDs for the processed data
sel_data = defaultdict(dict)
proc_data_info = {}
sel_samps = Analysis(self.current_user.default_analysis).samples
sel_samps = self.current_user.default_analysis.samples
for pid, samps in viewitems(sel_samps):
proc_data = ProcessedData(pid)
proc_data = Artifact(pid)
sel_data[proc_data.study][pid] = samps
# Also get processed data info
proc_data_info[pid] = proc_data.processing_info
proc_data_info[pid]['data_type'] = proc_data.data_type()
# TODO plugin:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note - we will be able to duplicate this information with the artifacts, however, this is highly tied up with target gene and is not gonna work for other datatypes - so we should rethink this information.

# proc_data_info[pid] = proc_data.processing_info
proc_data_info[pid] = {'processed_date': '10/10/1981',
'algorithm': 'My algorithm',
'reference_name': 'My reference name',
'reference_version': 'My reference version',
'sequence_filepath': 'My sequence filepath',
'taxonomy_filepath': 'My taxonomy filepath',
'tree_filepath': 'My taxonomy filepath'}
proc_data_info[pid]['data_type'] = proc_data.data_type
self.render("analysis_selected.html", sel_data=sel_data,
proc_info=proc_data_info)

Expand All @@ -322,5 +330,5 @@ class AnalysisSummaryAJAX(BaseHandler):
@authenticated
@execute_as_transaction
def get(self):
info = Analysis(self.current_user.default_analysis).summary_data()
info = self.current_user.default_analysis.summary_data()
self.write(dumps(info))
2 changes: 1 addition & 1 deletion qiita_pet/handlers/preprocessing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PreprocessHandler(BaseHandler):
def post(self):
study_id = int(self.get_argument('study_id'))
prep_template_id = int(self.get_argument('prep_template_id'))
raw_data = RawData(PrepTemplate(prep_template_id).raw_data)
raw_data = PrepTemplate(prep_template_id).artifacts
param_id = int(self.get_argument('preprocessing_parameters_id'))

# Get the preprocessing parameters
Expand Down
53 changes: 31 additions & 22 deletions qiita_pet/handlers/study_handlers/listing_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@
from tornado.gen import coroutine, Task
from pyparsing import ParseException

from qiita_db.artifact import Artifact
from qiita_db.user import User
from qiita_db.study import Study, StudyPerson
from qiita_db.search import QiitaStudySearch
from qiita_db.metadata_template.sample_template import SampleTemplate
from qiita_db.logger import LogEntry
from qiita_db.exceptions import QiitaDBIncompatibleDatatypeError
from qiita_db.util import get_table_cols
from qiita_db.util import get_table_cols, get_pubmed_ids_from_dois
from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_core.util import execute_as_transaction
from qiita_pet.handlers.base_handlers import BaseHandler
from qiita_pet.handlers.util import study_person_linkifier, pubmed_linkifier
from qiita_pet.handlers.util import (
study_person_linkifier, doi_linkifier, pubmed_linkifier)


@execute_as_transaction
def _get_shared_links_for_study(study):
shared = []
for person in study.shared_with:
person = User(person)
name = person.info['name']
email = person.email
# Name is optional, so default to email if non existant
Expand Down Expand Up @@ -69,15 +70,23 @@ def _build_single_study_info(study, info, study_proc, proc_samples):
"""
PI = StudyPerson(info['principal_investigator_id'])
status = study.status
if info['pmid'] is not None:
info['pmid'] = ", ".join([pubmed_linkifier([p])
for p in info['pmid']])
if info['publication_doi'] is not None:
pmids = get_pubmed_ids_from_dois(info['publication_doi']).values()
info['pmid'] = ", ".join([pubmed_linkifier([p]) for p in pmids])
info['publication_doi'] = ", ".join([doi_linkifier([p])
for p in info['publication_doi']])

else:
info['publication_doi'] = ""
info['pmid'] = ""
if info["number_samples_collected"] is None:
info["number_samples_collected"] = 0
info["shared"] = _get_shared_links_for_study(study)
info["num_raw_data"] = len(study.raw_data())
# raw data is any artifact that is not Demultiplexed or BIOM

info["num_raw_data"] = len([a for a in study.artifacts()
if a.artifact_type not in ['Demultiplexed',
'BIOM']])
info["status"] = status
info["study_id"] = study.id
info["pi"] = study_person_linkifier((PI.email, PI.name))
Expand Down Expand Up @@ -112,11 +121,12 @@ def _build_single_proc_data_info(proc_data_id, data_type, samples):
dict
The information for the processed data, in the form {info: value, ...}
"""
proc_data = ProcessedData(proc_data_id)
proc_info = proc_data.processing_info
proc_data = Artifact(proc_data_id)
# TODO plugin:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this TODO for? Is this worth raising an issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the issue is that some of this changes depends on my changes for the plugin, but the general qiita_pet update should not be blocked due to this. This way, it is easier that we have most of the things changed and I can just search for the TODO and connect the things together in a subsequent PR.

# proc_info = proc_data.processing_info
proc_info = {'processed_date': '10/10/1981'}
proc_info['pid'] = proc_data_id
proc_info['data_type'] = data_type
proc_info['samples'] = sorted(samples)
proc_info['processed_date'] = str(proc_info['processed_date'])
return proc_info

Expand Down Expand Up @@ -166,30 +176,29 @@ def _build_study_info(user, study_proc=None, proc_samples=None):
# No studies left so no need to continue
return []

# get info for the studies
cols = ['study_id', 'email', 'principal_investigator_id',
'pmid', 'study_title', 'metadata_complete',
'publication_doi', 'study_title', 'metadata_complete',
'number_samples_collected', 'study_abstract']
study_info = Study.get_info(study_set, cols)

# get info for the studies
infolist = []
for info in study_info:
# Convert DictCursor to proper dict
info = dict(info)
study = Study(info['study_id'])
for study in study_set:
# Build the processed data info for the study if none passed
if build_samples:
proc_data_list = study.processed_data()
proc_data_list = [ar for ar in study.artifacts()
if ar.artifact_type == 'BIOM']
proc_samples = {}
study_proc = {study.id: defaultdict(list)}
for pid in proc_data_list:
proc_data = ProcessedData(pid)
study_proc[study.id][proc_data.data_type()].append(pid)
proc_samples[pid] = proc_data.samples
for proc_data in proc_data_list:
study_proc[study.id][proc_data.data_type].append(proc_data.id)
# there is only one prep template for each processed data
proc_samples[proc_data.id] = proc_data.prep_templates[0].keys()

info = dict(study.get_info(info_cols=cols)[0])
study_info = _build_single_study_info(study, info, study_proc,
proc_samples)
infolist.append(study_info)

return infolist


Expand Down
3 changes: 3 additions & 0 deletions qiita_pet/handlers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ def download_link_or_path(is_local_request, filepath, fp_id, label):
pubmed_linkifier = partial(
linkify, "<a target=\"_blank\" href=\"http://www.ncbi.nlm.nih.gov/"
"pubmed/{0}\">{0}</a>")

doi_linkifier = partial(
linkify, "<a target=\"_blank\" href=\"http://dx.doi.org/{0}\">{0}</a>")
13 changes: 8 additions & 5 deletions qiita_pet/handlers/websocket_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from moi import r_client
from qiita_pet.handlers.base_handlers import BaseHandler
from qiita_db.analysis import Analysis
from qiita_db.artifact import Artifact
from qiita_core.util import execute_as_transaction


Expand Down Expand Up @@ -85,17 +86,19 @@ def on_message(self, msg):
# When the websocket receives a message from the javascript client,
# parse into JSON
msginfo = loads(msg)
default = Analysis(self.current_user.default_analysis)
default = self.current_user.default_analysis

if 'remove_sample' in msginfo:
data = msginfo['remove_sample']
default.remove_samples([data['proc_data']], data['samples'])
artifacts = [Artifact(_id) for _id in data['proc_data']]
default.remove_samples(artifacts, data['samples'])
elif 'remove_pd' in msginfo:
data = msginfo['remove_pd']
default.remove_samples([data['proc_data']])
default.remove_samples([Artifact(data['proc_data'])])
elif 'clear' in msginfo:
data = msginfo['clear']
default.remove_samples(data['pids'])
artifacts = [Artifact(_id) for _id in data['pids']]
default.remove_samples(artifacts)
self.write_message(msg)


Expand All @@ -113,7 +116,7 @@ def on_message(self, msg):
{proc_data_id': [s1, s2, ...], ...]}
"""
msginfo = loads(msg)
default = Analysis(self.current_user.default_analysis)
default = self.current_user.default_analysis
default.add_samples(msginfo['sel'])
# Count total number of unique samples selected and return
self.write_message(dumps({
Expand Down
16 changes: 7 additions & 9 deletions qiita_pet/templates/analysis_selected.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
{% end %}

{% block content %}
{% from qiita_db.study import Study %}
{% set static_info = {'data_type', 'processed_date', 'algorithm', 'reference_name', 'reference_version', 'sequence_filepath', 'taxonomy_filepath', 'tree_filepath'}%}
&nbsp;<br/>
<h1>Selected Samples</h1>
Expand All @@ -91,13 +90,12 @@ <h3><a href="/study/list/">Please select at least one sample to continue</a><h3>
</div>
{% end %}

{% for sid, proc_datas in viewitems(sel_data) %}
{% set study = Study(sid) %}
<div class="row" id="study{{sid}}">
{% for study, proc_datas in viewitems(sel_data) %}
<div class="row" id="study{{study.id}}">
<div class="col-md-12" style="border:2px solid #a1a1a1; border-radius: 15px;">
<h2><a href="/study/description/{{sid}}">{{study.title}}</a></h2>
<h2><a href="/study/description/{{study.id}}">{{study.title}}</a></h2>
<h4>Processed Data</h4>
<table class='table table-striped' id='study{{sid}}-table'>
<table class='table table-striped' id='study{{study.id}}-table'>
<tr>
<th class="col-sm-1">id</th><th class="col-sm-1">Datatype</th><th class="col-sm-2">Processed Date</th><th class="col-sm-2">Algorithm</th><th class="col-sm-2">Reference</th><th class="col-sm-1">Samples</th><th></th><th></th>
</tr>
Expand All @@ -110,12 +108,12 @@ <h4>Processed Data</h4>
<td>{{proc_info[pid]["reference_name"]}} {{proc_info[pid]["reference_version"]}}</td>
<td><span id="proc{{pid}}-sample-count">{% raw len(samples) %}</span></td>
<td><a href="#" onclick="$('#proc{{pid}}-samples').toggle(); return false;">Show/Hide samples</a></td>
<td><a href="#" onclick = 'remove_proc_data({{pid}}, {{sid}})'>Remove</a></td>
<td><a href="#" onclick = 'remove_proc_data({{pid}}, {{study.id}})'>Remove</a></td>
</tr>
<tr id="proc{{pid}}-samples" hidden><td colspan=7>
<table class="table table-striped sample-table" id="proc{{pid}}-samples-table" style="width:50%">
{% for samp in samples %}
<tr id="{{pid}}@{{samp}}"><td>{{samp}}</td><td><a href="#" onclick="remove_sample('{{sid}}', '{{pid}}', '{{samp}}')">Remove</a></td></tr>
<tr id="{{pid}}@{{samp}}"><td>{{samp}}</td><td><a href="#" onclick="remove_sample('{{study.id}}', '{{pid}}', '{{samp}}')">Remove</a></td></tr>
{% end %}
</table>
</td></tr>
Expand Down Expand Up @@ -182,4 +180,4 @@ <h4 class="modal-title" id="myModalLabel">Create new analysis</h4>
</div>
</div>
</div>
{% end %}
{% end %}
1 change: 0 additions & 1 deletion qiita_pet/templates/error_log.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends sitebase.html %}
{% block head %}
{% from qiita_db.study import StudyPerson %}
{% from future.utils import viewitems %}

<link rel="stylesheet" href="/static/vendor/css/jquery.dataTables.css" type="text/css">
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/study_description.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
}

function delete_sample_template() {
sample_template_id = {{study.sample_template}};
sample_template_id = {{study.sample_template.id}};
if (confirm('Are you sure you want to delete sample template ID: ' + sample_template_id + '?')) {
var form = $("<form>")
.attr("action", window.location.href)
Expand Down
Loading