-
We searched {{ dataset.fullname }}
+
We searched {{ dataset.fullname }}
to find all records
{% if go_term is not none %}
--
cgit v1.2.3
From 30c31955df6a9d20c28e0dcd9f99f06cbfd51a77 Mon Sep 17 00:00:00 2001
From: Munyoki Kilyungi
Date: Sun, 9 Oct 2022 14:04:29 +0300
Subject: Use the Maybe Monad when fetching the accession_id of a dataset
* wqflask/base/data_set/dataset.py: Import itertools, DictCursor, MonadicDict,
Maybe, Nothing and query_sql.
(DataSet.__init__): Initialize accession_id to Nothing.
(DataSet.as_dict): Rename this to ...
(Dataset.as_monadic_dict): ... this which returns a monadic
dictionary.
(DataSet.get_accession_id): Query for the accession_id and return it
as a maybe monad.
---
wqflask/base/data_set/dataset.py | 90 ++++++++++++++++++++++------------------
1 file changed, 50 insertions(+), 40 deletions(-)
(limited to 'wqflask')
diff --git a/wqflask/base/data_set/dataset.py b/wqflask/base/data_set/dataset.py
index b6899278..dfe09921 100644
--- a/wqflask/base/data_set/dataset.py
+++ b/wqflask/base/data_set/dataset.py
@@ -2,13 +2,15 @@
import math
import collections
-
+import itertools
from redis import Redis
-
+from MySQLdb.cursors import DictCursor
from base import species
from utility import chunks
+from gn3.monads import MonadicDict, query_sql
+from pymonad.maybe import Maybe, Nothing
from .datasetgroup import DatasetGroup
from wqflask.database import database_connection
from utility.db_tools import escape, mescape, create_in_clause
@@ -30,7 +32,7 @@ class DataSet:
self.fullname = None
self.type = None
self.data_scale = None # ZS: For example log2
- self.accession_id = None
+ self.accession_id = Nothing
self.setup()
@@ -47,50 +49,58 @@ class DataSet:
self.group.get_samplelist(redis_conn)
self.species = species.TheSpecies(dataset=self)
- def as_dict(self):
- return {
+ def as_monadic_dict(self):
+ _result = MonadicDict({
'name': self.name,
'shortname': self.shortname,
'fullname': self.fullname,
'type': self.type,
'data_scale': self.data_scale,
- 'group': self.group.name,
- 'accession_id': self.accession_id
- }
-
- def get_accession_id(self):
- results = None
- with database_connection() as conn, conn.cursor() as cursor:
+ 'group': self.group.name
+ })
+ _result["accession_id"] = self.accession_id
+ return _result
+
+ def get_accession_id(self) -> Maybe[str]:
+ """Get the accession_id of this dataset depending on the
+ dataset type."""
+ __accession_id_dict = MonadicDict()
+ with database_connection() as conn:
if self.type == "Publish":
- cursor.execute(
- "SELECT InfoFiles.GN_AccesionId FROM "
- "InfoFiles, PublishFreeze, InbredSet "
- "WHERE InbredSet.Name = %s AND "
- "PublishFreeze.InbredSetId = InbredSet.Id "
- "AND InfoFiles.InfoPageName = PublishFreeze.Name "
- "AND PublishFreeze.public > 0 AND "
- "PublishFreeze.confidentiality < 1 "
- "ORDER BY PublishFreeze.CreateTime DESC",
- (self.group.name,)
- )
- results = cursor.fetchone()
+ __accession_id_dict, = itertools.islice(
+ query_sql(conn,
+ ("SELECT InfoFiles.GN_AccesionId AS accession_id FROM "
+ "InfoFiles, PublishFreeze, InbredSet "
+ f"WHERE InbredSet.Name = '{conn.escape_string(self.group.name).decode()}' "
+ "AND PublishFreeze.InbredSetId = InbredSet.Id "
+ "AND InfoFiles.InfoPageName = PublishFreeze.Name "
+ "AND PublishFreeze.public > 0 AND "
+ "PublishFreeze.confidentiality < 1 "
+ "ORDER BY PublishFreeze.CreateTime DESC")
+ ), 1)
elif self.type == "Geno":
- cursor.execute(
- "SELECT InfoFiles.GN_AccesionId FROM "
- "InfoFiles, GenoFreeze, InbredSet "
- "WHERE InbredSet.Name = %s AND "
- "GenoFreeze.InbredSetId = InbredSet.Id "
- "AND InfoFiles.InfoPageName = GenoFreeze.ShortName "
- "AND GenoFreeze.public > 0 AND "
- "GenoFreeze.confidentiality < 1 "
- "ORDER BY GenoFreeze.CreateTime DESC",
- (self.group.name,)
- )
- results = cursor.fetchone()
-
- # Returns None by default if this is not executed
- if results:
- return str(results[0])
+ __accession_id_dict, = itertools.islice(
+ query_sql(conn,
+ ("SELECT InfoFiles.GN_AccesionId AS accession_id FROM "
+ "InfoFiles, GenoFreeze, InbredSet "
+ f"WHERE InbredSet.Name = '{conn.escape_string(self.group.name).decode()}' AND "
+ "GenoFreeze.InbredSetId = InbredSet.Id "
+ "AND InfoFiles.InfoPageName = GenoFreeze.ShortName "
+ "AND GenoFreeze.public > 0 AND "
+ "GenoFreeze.confidentiality < 1 "
+ "ORDER BY GenoFreeze.CreateTime DESC")
+ ), 1)
+ elif self.type == "ProbeSet":
+ __accession_id_dict, = itertools.islice(
+ query_sql(conn,
+ ("SELECT InfoFiles.GN_AccesionId AS accession_id "
+ f"FROM InfoFiles WHERE InfoFiles.InfoPageName = '{conn.escape_string(self.name).decode()}' "
+ f"AND InfoFiles.DB_Name = '{conn.escape_string(self.fullname).decode()}' "
+ f"OR InfoFiles.DB_Name = '{conn.escape_string(self.shortname).decode()}'")
+ ), 1)
+ else: # The Value passed is not present
+ raise LookupError
+ return __accession_id_dict["accession_id"]
def retrieve_other_names(self):
"""This method fetches the the dataset names in search_result.
--
cgit v1.2.3
From a83d95c707dbf4480a568bae4203ed5f2476cb53 Mon Sep 17 00:00:00 2001
From: Munyoki Kilyungi
Date: Sun, 9 Oct 2022 18:23:47 +0300
Subject: Rename dataset.as_dict to dataset.as_monadic_dict
* wqflask/base/data_set/dataset.py (DataSet.as_dict): Rename this to ...
(as_monadic_dict): ... this.
* wqflask/wqflask/correlation/show_corr_results.py
(set_template_vars): Rename as_dict to as_monadic_dict.
(correlation_json_for_table): Ditto.
---
wqflask/wqflask/correlation/show_corr_results.py | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
(limited to 'wqflask')
diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py
index d776c8d3..01772544 100644
--- a/wqflask/wqflask/correlation/show_corr_results.py
+++ b/wqflask/wqflask/correlation/show_corr_results.py
@@ -40,16 +40,17 @@ def set_template_vars(start_vars, correlation_data):
name=start_vars['trait_id'])
correlation_data['this_trait'] = jsonable(this_trait, this_dataset_ob)
- correlation_data['this_dataset'] = this_dataset_ob.as_dict()
+ correlation_data['this_dataset'] = this_dataset_ob.as_monadic_dict()
target_dataset_ob = create_dataset(correlation_data['target_dataset'])
- correlation_data['target_dataset'] = target_dataset_ob.as_dict()
- correlation_data['table_json'] = correlation_json_for_table(
- start_vars,
- correlation_data,
- correlation_data['this_trait'],
- correlation_data['this_dataset'],
- target_dataset_ob)
+ correlation_data['target_dataset'] = target_dataset_ob.as_monadic_dict()
+
+ table_json = correlation_json_for_table(correlation_data,
+ correlation_data['this_trait'],
+ correlation_data['this_dataset'],
+ target_dataset_ob)
+
+ correlation_data['table_json'] = table_json
if target_dataset_ob.type == "ProbeSet":
filter_cols = [7, 6]
@@ -74,12 +75,12 @@ def correlation_json_for_table(start_vars, correlation_data, this_trait, this_da
Keyword arguments:
correlation_data -- Correlation results
this_trait -- Trait being correlated against a dataset, as a dict
- this_dataset -- Dataset of this_trait, as a dict
+ this_dataset -- Dataset of this_trait, as a monadic dict
target_dataset_ob - Target dataset, as a Dataset ob
"""
this_trait = correlation_data['this_trait']
this_dataset = correlation_data['this_dataset']
- target_dataset = target_dataset_ob.as_dict()
+ target_dataset = target_dataset_ob.as_monadic_dict()
corr_results = correlation_data['correlation_results']
results_list = []
--
cgit v1.2.3
From e76f723104a1c9b4e3fc0f529e890debad8584cb Mon Sep 17 00:00:00 2001
From: Munyoki Kilyungi
Date: Sun, 9 Oct 2022 19:33:14 +0300
Subject: Convert monadic_dict to normal dictionaries
* wqflask/wqflask/correlation/show_corr_results.py
(set_template_vars): Convert monadict_dict to a normal dictionary.
(correlation_json_for_table): Ditto.
---
wqflask/wqflask/correlation/show_corr_results.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'wqflask')
diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py
index 01772544..5da8a6b9 100644
--- a/wqflask/wqflask/correlation/show_corr_results.py
+++ b/wqflask/wqflask/correlation/show_corr_results.py
@@ -40,10 +40,10 @@ def set_template_vars(start_vars, correlation_data):
name=start_vars['trait_id'])
correlation_data['this_trait'] = jsonable(this_trait, this_dataset_ob)
- correlation_data['this_dataset'] = this_dataset_ob.as_monadic_dict()
+ correlation_data['this_dataset'] = this_dataset_ob.as_monadic_dict().data
target_dataset_ob = create_dataset(correlation_data['target_dataset'])
- correlation_data['target_dataset'] = target_dataset_ob.as_monadic_dict()
+ correlation_data['target_dataset'] = target_dataset_ob.as_monadic_dict().data
table_json = correlation_json_for_table(correlation_data,
correlation_data['this_trait'],
@@ -80,7 +80,7 @@ def correlation_json_for_table(start_vars, correlation_data, this_trait, this_da
"""
this_trait = correlation_data['this_trait']
this_dataset = correlation_data['this_dataset']
- target_dataset = target_dataset_ob.as_monadic_dict()
+ target_dataset = target_dataset_ob.as_monadic_dict().data
corr_results = correlation_data['correlation_results']
results_list = []
--
cgit v1.2.3
From 97f5ab24e8ff8df638b5320058e8f0d815c28ed4 Mon Sep 17 00:00:00 2001
From: Munyoki Kilyungi
Date: Wed, 26 Oct 2022 18:20:08 +0300
Subject: Display a dataset's metadata in the "Trait Data and Analysis" page
* wqflask/wqflask/static/new/css/show_trait.css: Show a pointer when a
user hovers over summary data. Add extra styling for the metadata
table.
* wqflask/wqflask/templates/search_result_page.html: Replace
dataset.accession_id with metadata.accession_id.
* wqflask/wqflask/templates/show_metadata_details.html: New template.
file that displays a dataset's metadata in tabular form.
* wqflask/wqflask/templates/show_trait.html: Sub-template
'show_metadata_details' conditionally.
* wqflask/wqflask/views.py (show_trait_page): Explicitly pass metadata
as a dictionary to the template.
---
wqflask/wqflask/static/new/css/show_trait.css | 17 ++
wqflask/wqflask/templates/search_result_page.html | 6 +-
.../wqflask/templates/show_metadata_details.html | 186 +++++++++++++++++++++
wqflask/wqflask/templates/show_trait.html | 14 +-
wqflask/wqflask/views.py | 11 +-
5 files changed, 229 insertions(+), 5 deletions(-)
create mode 100644 wqflask/wqflask/templates/show_metadata_details.html
(limited to 'wqflask')
diff --git a/wqflask/wqflask/static/new/css/show_trait.css b/wqflask/wqflask/static/new/css/show_trait.css
index 3780a8f1..2ce07fec 100644
--- a/wqflask/wqflask/static/new/css/show_trait.css
+++ b/wqflask/wqflask/static/new/css/show_trait.css
@@ -6,6 +6,23 @@ table.dataTable tbody tr.selected {
background-color: #ffee99;
}
+table.metadata {
+ table-layout: fixed;
+}
+
+table.metadata td:nth-child(1) {
+ width: 10%;
+}
+
+table summary b {
+ cursor: pointer;
+ text-decoration: underline;
+}
+
+table details[open] {
+ width: 80%;
+}
+
#bar_chart_container {
overflow-x:scroll;
}
diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html
index 2bcfe92b..3a6f6e91 100644
--- a/wqflask/wqflask/templates/search_result_page.html
+++ b/wqflask/wqflask/templates/search_result_page.html
@@ -17,7 +17,7 @@
-
We searched {{ dataset.fullname }}
+
We searched {{ dataset.fullname }}
to find all records
{% if go_term is not none %}
@@ -97,8 +97,8 @@
- {% if dataset.accession_id is defined %}
-
+ {% if metadata.accession_id %}
+
{% endif %}
diff --git a/wqflask/wqflask/templates/show_metadata_details.html b/wqflask/wqflask/templates/show_metadata_details.html
new file mode 100644
index 00000000..36b0f9b5
--- /dev/null
+++ b/wqflask/wqflask/templates/show_metadata_details.html
@@ -0,0 +1,186 @@
+
diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html
index 0f93188b..4b92545c 100644
--- a/wqflask/wqflask/templates/show_trait.html
+++ b/wqflask/wqflask/templates/show_trait.html
@@ -51,8 +51,20 @@
{% include 'show_trait_details.html' %}
+
+ {% if metadata.accession_id %}
+
+
+ Data Set Group: {{ dataset.fullname }}
+
-