aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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