aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2022-08-11 18:24:13 +0000
committerzsloan2022-08-11 18:24:13 +0000
commit55c237db53037ee1f13ce782e224013aa12c51b9 (patch)
tree84c2cb87aa76bba2c244a2226c5d9dc24624d99f
parent91441796bd4ff36711804ee404e7870709d212dd (diff)
downloadgenenetwork2-55c237db53037ee1f13ce782e224013aa12c51b9.tar.gz
Add data-trait-info attribute to checkboxes on search results page
Currently there's a separate trait_info_str function in search_results.py, because search_results.py doesn't build the trait objects (so it can't use the one in collect.py unless I change that to accept traits as either a GeneralTrait class or dict - which might be better, I'm not sure)
-rw-r--r--wqflask/wqflask/search_results.py45
-rw-r--r--wqflask/wqflask/templates/search_result_page.html2
2 files changed, 46 insertions, 1 deletions
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py
index a82390cb..7134cc24 100644
--- a/wqflask/wqflask/search_results.py
+++ b/wqflask/wqflask/search_results.py
@@ -188,6 +188,8 @@ class SearchResultPage:
trait_dict['additive'] = "N/A" if not result[8] else f"{result[8]:.3f}"
+ trait_dict['trait_info_str'] = trait_info_str(trait_dict, self.dataset.type)
+
# Convert any bytes in dict to a normal utf-8 string
for key in trait_dict.keys():
if isinstance(trait_dict[key], bytes):
@@ -332,6 +334,49 @@ class SearchResultPage:
else:
return None
+def trait_info_str(trait, dataset_type):
+ """Provide a string representation for given trait"""
+ def __trait_desc(trt):
+ if dataset_type == "Geno":
+ return f"Marker: {trait['display_name']}"
+ return trait['description'] or "N/A"
+
+ def __symbol(trt):
+ if dataset_type == "ProbeSet":
+ return (trait['symbol'] or "N/A")[:20]
+
+ def __lrs(trt):
+ if dataset_type == "Geno":
+ return 0
+ else:
+ if trait['lod_score'] != "N/A":
+ return (
+ f"{float(trait['lod_score']):0.3f}" if float(trait['lod_score']) > 0
+ else f"{trait['lod_score']}")
+ else:
+ return "N/A"
+
+ def __lrs_location(trt):
+ if 'lrs_location' in trait:
+ return trait['lrs_location']
+ else:
+ return "N/A"
+
+ def __location(trt):
+ if 'location' in trait:
+ return trait['location']
+ else:
+ return None
+
+ def __mean(trt):
+ if 'mean' in trait:
+ return trait['mean']
+ else:
+ return 0
+
+ return "{}|||{}|||{}|||{}|||{}|||{}|||{}|||{}".format(
+ trait['display_name'], trait['dataset'], __trait_desc(trait), __symbol(trait),
+ __location(trait), __mean(trait), __lrs(trait), __lrs_location(trait))
def get_GO_symbols(a_search):
query = """SELECT genes
diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html
index f0e179da..264b383d 100644
--- a/wqflask/wqflask/templates/search_result_page.html
+++ b/wqflask/wqflask/templates/search_result_page.html
@@ -200,7 +200,7 @@
'orderDataType': "dom-checkbox",
'targets': 0,
'render': function(data, type, row, meta) {
- return '<input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="' + data.hmac + '">'
+ return '<input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="' + data.hmac + '" data-trait-info="' + data.trait_info_str + '">'
}
},
{