aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/search_results.py180
1 files changed, 108 insertions, 72 deletions
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py
index f23c0582..8edf6147 100644
--- a/wqflask/wqflask/search_results.py
+++ b/wqflask/wqflask/search_results.py
@@ -4,6 +4,7 @@ from math import *
import time
import re
import requests
+from types import SimpleNamespace
from pprint import pformat as pf
@@ -11,6 +12,7 @@ import json
from base.data_set import create_dataset
from base.trait import create_trait
+from base.webqtlConfig import PUBMEDLINK_URL
from wqflask import parser
from wqflask import do_search
from db import webqtlDatabaseFunction
@@ -18,12 +20,15 @@ from db import webqtlDatabaseFunction
from flask import Flask, g
from utility import hmac, helper_functions
+from utility.authentication_tools import check_resource_availability
from utility.tools import GN2_BASE_URL
from utility.type_checking import is_str
from utility.logger import getLogger
logger = getLogger(__name__ )
+from utility.benchmark import Bench
+
class SearchResultPage(object):
#maxReturn = 3000
@@ -39,9 +44,7 @@ class SearchResultPage(object):
self.uc_id = uuid.uuid4()
self.go_term = None
- logger.debug("uc_id:", self.uc_id) # contains a unique id
- logger.debug("kw is:", kw) # dict containing search terms
if kw['search_terms_or']:
self.and_or = "or"
self.search_terms = kw['search_terms_or']
@@ -70,11 +73,11 @@ class SearchResultPage(object):
assert(is_str(kw.get('dataset')))
self.dataset = create_dataset(kw['dataset'], dataset_type)
- logger.debug("search_terms:", self.search_terms)
#ZS: I don't like using try/except, but it seems like the easiest way to account for all possible bad searches here
try:
- self.search()
+ with Bench("Doing Query"):
+ self.search()
except:
self.search_term_exists = False
@@ -95,83 +98,118 @@ class SearchResultPage(object):
trait_list = []
json_trait_list = []
- species = webqtlDatabaseFunction.retrieve_species(self.dataset.group.name)
# result_set represents the results for each search term; a search of
# "shh grin2b" would have two sets of results, one for each term
- logger.debug("self.results is:", pf(self.results))
+
+ if self.dataset.type == "ProbeSet":
+ self.header_data_names = ['index', 'display_name', 'symbol', 'description', 'location', 'mean', 'lrs_score', 'lrs_location', 'additive']
+ elif self.dataset.type == "Publish":
+ self.header_data_names = ['index', 'display_name', 'description', 'mean', 'authors', 'pubmed_text', 'lrs_score', 'lrs_location', 'additive']
+ elif self.dataset.type == "Geno":
+ self.header_data_names = ['index', 'display_name', 'location']
for index, result in enumerate(self.results):
if not result:
continue
- #### Excel file needs to be generated ####
-
trait_dict = {}
- trait_id = result[0]
- this_trait = create_trait(dataset=self.dataset, name=trait_id, get_qtl_info=True, get_sample_info=False)
- if this_trait:
- trait_dict['index'] = index + 1
- trait_dict['name'] = this_trait.name
- if this_trait.dataset.type == "Publish":
- trait_dict['display_name'] = this_trait.display_name
+ trait_dict['index'] = index + 1
+ trait_dict['name'] = result[0]
+
+ #ZS: Check permissions on a trait-by-trait basis for phenotype traits
+ if self.dataset.type == "Publish":
+ permissions = check_resource_availability(self.dataset, trait_dict['name'])
+ if "view" not in permissions['data']:
+ continue
+
+ trait_dict['display_name'] = result[0]
+ if self.dataset.type == "Publish":
+ if self.dataset.group_code:
+ trait_dict['display_name'] = self.dataset.group_code + "_" + result[0]
+
+ trait_dict['dataset'] = self.dataset.name
+ trait_dict['hmac'] = hmac.data_hmac('{}:{}'.format(trait_dict['name'], trait_dict['dataset']))
+ if self.dataset.type == "ProbeSet":
+ trait_dict['symbol'] = "N/A"
+ if result[10]:
+ trait_dict['symbol'] = result[10]
+ trait_dict['description'] = "N/A"
+ description_string = result[2]
+ if str(description_string) != "" and description_string != None:
+ description_display = description_string
+ else:
+ description_display = trait_dict['symbol']
+
+ target_string = result[3]
+ if str(target_string) != "" and target_string != None:
+ description_display = description_display + "; " + target_string.strip()
+ trait_dict['description'] = description_display
+
+ trait_dict['location'] = "N/A"
+ if (result[8] != "NULL" and result[8] != "") and (result[9] != 0):
+ trait_dict['location'] = f"Chr{result[8]}: {float(result[9]):.6f}"
+ trait_dict['mean'] = "N/A"
+ trait_dict['additive'] = "N/A"
+ if result[4] != "" and result[4] != None:
+ trait_dict['mean'] = f"{result[4]:.3f}"
+ try:
+ trait_dict['lod_score'] = f"{float(result[5]) / 4.61:.1f}"
+ except:
+ trait_dict['lod_score'] = "N/A"
+ try:
+ trait_dict['lrs_location'] = f"Chr{result[12]}: {float(result[13]):.6f}"
+ except:
+ trait_dict['lrs_location'] = "N/A"
+ if result[5] != "":
+ trait_dict['additive'] = f"{result[7]:.3f}"
+ elif self.dataset.type == "Geno":
+ trait_dict['location'] = "N/A"
+ if (result[4] != "NULL" and result[4] != "") and (result[5] != 0):
+ trait_dict['location'] = f"Chr{result[4]}: {float(result[5]):.6f}"
+ elif self.dataset.type == "Publish":
+ trait_dict['description'] = "N/A"
+ trait_dict['pubmed_id'] = "N/A"
+ trait_dict['pubmed_link'] = "N/A"
+ trait_dict['pubmed_text'] = "N/A"
+ trait_dict['mean'] = "N/A"
+ trait_dict['additive'] = "N/A"
+ pre_pub_description = result[2].strip()
+ post_pub_description = result[3].strip()
+ if result[1] != "NULL" and result[1] != None:
+ trait_dict['pubmed_id'] = result[1]
+ trait_dict['pubmed_link'] = PUBMEDLINK_URL % trait_dict['pubmed_id']
+ trait_dict['description'] = post_pub_description
else:
- trait_dict['display_name'] = this_trait.name
- trait_dict['dataset'] = this_trait.dataset.name
- trait_dict['hmac'] = hmac.data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name))
- if this_trait.dataset.type == "ProbeSet":
- trait_dict['symbol'] = this_trait.symbol
- trait_dict['description'] = "N/A"
- if this_trait.description_display:
- trait_dict['description'] = this_trait.description_display
- trait_dict['location'] = this_trait.location_repr
- trait_dict['mean'] = "N/A"
- trait_dict['additive'] = "N/A"
- if this_trait.mean != "" and this_trait.mean != None:
- trait_dict['mean'] = f"{this_trait.mean:.3f}"
- try:
- trait_dict['lod_score'] = f"{float(this_trait.LRS_score_repr) / 4.61:.1f}"
- except:
- trait_dict['lod_score'] = "N/A"
- trait_dict['lrs_location'] = this_trait.LRS_location_repr
- if this_trait.additive != "":
- trait_dict['additive'] = f"{this_trait.additive:.3f}"
- elif this_trait.dataset.type == "Geno":
- trait_dict['location'] = this_trait.location_repr
- elif this_trait.dataset.type == "Publish":
- trait_dict['description'] = "N/A"
- if this_trait.description_display:
- trait_dict['description'] = this_trait.description_display
- trait_dict['authors'] = this_trait.authors
- trait_dict['pubmed_id'] = "N/A"
- if this_trait.pubmed_id:
- trait_dict['pubmed_id'] = this_trait.pubmed_id
- trait_dict['pubmed_link'] = this_trait.pubmed_link
- trait_dict['pubmed_text'] = this_trait.pubmed_text
- trait_dict['mean'] = "N/A"
- if this_trait.mean != "" and this_trait.mean != None:
- trait_dict['mean'] = f"{this_trait.mean:.3f}"
- try:
- trait_dict['lod_score'] = f"{float(this_trait.LRS_score_repr) / 4.61:.1f}"
- except:
- trait_dict['lod_score'] = "N/A"
- trait_dict['lrs_location'] = this_trait.LRS_location_repr
- trait_dict['additive'] = "N/A"
- if this_trait.additive != "":
- trait_dict['additive'] = f"{this_trait.additive:.3f}"
- # Convert any bytes in dict to a normal utf-8 string
- for key in trait_dict.keys():
- if isinstance(trait_dict[key], bytes):
- trait_dict[key] = trait_dict[key].decode('utf-8')
- trait_list.append(trait_dict)
+ trait_dict['description'] = pre_pub_description
- self.trait_list = trait_list
+ if result[6].isdigit():
+ trait_dict['pubmed_text'] = result[6]
- if self.dataset.type == "ProbeSet":
- self.header_data_names = ['index', 'display_name', 'symbol', 'description', 'location', 'mean', 'lrs_score', 'lrs_location', 'additive']
- elif self.dataset.type == "Publish":
- self.header_data_names = ['index', 'display_name', 'description', 'mean', 'authors', 'pubmed_text', 'lrs_score', 'lrs_location', 'additive']
- elif self.dataset.type == "Geno":
- self.header_data_names = ['index', 'display_name', 'location']
+ trait_dict['authors'] = result[5]
+
+ if result[4] != "" and result[4] != None:
+ trait_dict['mean'] = f"{result[4]:.3f}"
+
+ try:
+ trait_dict['lod_score'] = f"{float(result[5]) / 4.61:.1f}"
+ except:
+ trait_dict['lod_score'] = "N/A"
+
+ try:
+ trait_dict['lrs_location'] = f"Chr{result[9]}: {float(result[10]):.6f}"
+ except:
+ trait_dict['lrs_location'] = "N/A"
+
+ if result[5] != "":
+ trait_dict['additive'] = f"{result[6]:.3f}"
+
+ # Convert any bytes in dict to a normal utf-8 string
+ for key in trait_dict.keys():
+ if isinstance(trait_dict[key], bytes):
+ trait_dict[key] = trait_dict[key].decode('utf-8')
+ trait_list.append(trait_dict)
+
+ self.trait_list = trait_list
def search(self):
"""
@@ -179,13 +217,11 @@ class SearchResultPage(object):
"""
self.search_terms = parser.parse(self.search_terms)
- logger.debug("After parsing:", self.search_terms)
combined_from_clause = ""
combined_where_clause = ""
previous_from_clauses = [] #The same table can't be referenced twice in the from clause
- logger.debug("len(search_terms)>1")
symbol_list = []
if self.dataset.type == "ProbeSet":
for a_search in self.search_terms: