diff options
author | zsloan | 2023-05-10 22:19:09 +0000 |
---|---|---|
committer | zsloan | 2023-05-22 17:23:08 +0000 |
commit | 6a0dbddd66537cfde65c85100a4b5571a2f30bcd (patch) | |
tree | 76b91f3502080e5da8f5bfdd861dc61e1217848f /gn3/db/sample_data.py | |
parent | cd19d8fdd71811e88ad56e052ff3c70edcae7f4d (diff) | |
download | genenetwork3-6a0dbddd66537cfde65c85100a4b5571a2f30bcd.tar.gz |
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
Diffstat (limited to 'gn3/db/sample_data.py')
-rw-r--r-- | gn3/db/sample_data.py | 18 |
1 files changed, 14 insertions, 4 deletions
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( |