aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2023-04-13 19:02:59 +0000
committerzsloan2023-05-22 17:23:08 +0000
commit3404fda373f52213a44c6b04a7348308b2619139 (patch)
tree02da3ee8d462115dd0815d8a663ccc04b083e7f0
parent0e42d84dbeee042e3ba9086e8edf5160eb45ff9c (diff)
downloadgenenetwork3-3404fda373f52213a44c6b04a7348308b2619139.tar.gz
Add function for retrieving phenotype sample data as dict
-rw-r--r--gn3/db/sample_data.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py
index 4062705..d8232cb 100644
--- a/gn3/db/sample_data.py
+++ b/gn3/db/sample_data.py
@@ -57,6 +57,31 @@ def __extract_actions(
)
return result
+def get_trait_sample_data(
+ conn: Any, trait_name: int, phenotype_id: int
+) -> str:
+ """Fetch a trait's sample data and return it as a dict"""
+ with conn.cursor() as cursor:
+ cursor.execute("""
+SELECT st.Name, ifnull(pd.value, 'x'), ifnull(ps.error, 'x'), ifnull(ns.count, 'x')
+FROM PublishFreeze pf JOIN PublishXRef px ON px.InbredSetId = pf.InbredSetId
+ JOIN PublishData pd ON pd.Id = px.DataId JOIN Strain st ON pd.StrainId = st.Id
+ LEFT JOIN PublishSE ps ON ps.DataId = pd.Id AND ps.StrainId = pd.StrainId
+ LEFT JOIN NStrain ns ON ns.DataId = pd.Id AND ns.StrainId = pd.StrainId
+ AND px.Id = %s AND px.PhenotypeId = %s
+ORDER BY st.Name""", (trait_name, phenotype_id))
+
+ sample_data = {}
+ for data in cursor.fetchall():
+ this_data = {}
+ sample, value, error, n_cases = data
+ sample_data[sample] = {
+ 'value': value,
+ 'error': error,
+ 'n_cases:': n_cases
+ }
+
+ return sample_data
def get_trait_csv_sample_data(
conn: Any, trait_name: int, phenotype_id: int