From 6a0dbddd66537cfde65c85100a4b5571a2f30bcd Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 10 May 2023 22:19:09 +0000 Subject: Include all samples in trait sample data This is necessary in order to allow for editing the values of samples that don't currently have values --- gn3/db/sample_data.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'gn3/db') diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py index 5dad923..1f83dd2 100644 --- a/gn3/db/sample_data.py +++ b/gn3/db/sample_data.py @@ -84,12 +84,12 @@ ORDER BY st.Name""", (trait_name, phenotype_id)) return sample_data def get_trait_csv_sample_data( - conn: Any, trait_name: int, phenotype_id: int + conn: Any, trait_name: int, phenotype_id: int, sample_list: list ) -> str: """Fetch a trait and return it as a csv string""" with conn.cursor() as cursor: cursor.execute(""" -SELECT DISTINCT concat(st.Name, ',', ifnull(pd.value, 'x'), ',', +SELECT DISTINCT st.Name, concat(st.Name, ',', ifnull(pd.value, 'x'), ',', ifnull(ps.error, 'x'), ',', ifnull(ns.count, 'x')) AS 'Data' 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 @@ -99,8 +99,18 @@ WHERE px.Id = %s AND px.PhenotypeId = %s ORDER BY st.Name""", (trait_name, phenotype_id)) if not (data := cursor.fetchall()): return "No Sample Data Found" - return "Strain Name,Value,SE,Count\n" + \ - "\n".join([el[0] for el in data]) + + # Get list of samples with data in the DB + existing_samples = [el[0] for el in data] + + trait_csv = ["Strain Name,Value,SE,Count"] + for sample in sample_list: + if sample in existing_samples: + trait_csv.append(data[existing_samples.index(sample)][1]) + else: + trait_csv.append(sample + ",x,x,x") + + return "\n".join(trait_csv) def get_sample_data_ids( -- cgit v1.2.3