From 743a4623c53d30779cb884a69d0cf2c7ff411f0a Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 9 Mar 2022 19:13:59 +0000 Subject: Add function for getting strain name from sample name --- wqflask/maintenance/gen_ind_genofiles.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'wqflask') diff --git a/wqflask/maintenance/gen_ind_genofiles.py b/wqflask/maintenance/gen_ind_genofiles.py index abca4a4a..6e818945 100644 --- a/wqflask/maintenance/gen_ind_genofiles.py +++ b/wqflask/maintenance/gen_ind_genofiles.py @@ -7,9 +7,7 @@ import MySQLdb from wqflask import app -from gn3.db.datasets import retrieve_group_samples - -def db_conn(): +def conn(): return MySQLdb.Connect(db=app.config.get("DB_NAME"), user=app.config.get("DB_USER"), passwd=app.config.get("DB_PASS"), @@ -32,6 +30,17 @@ def main(args): # Generate the output .geno files generate_new_genofiles(strain_genotypes(source_genofile), target_groups) +def get_strain_for_sample(sample): + query = ( + "SELECT CaseAttributeXRefNew.Value " + "FROM CaseAttributeXRefNew, Strain " + "WHERE CaseAttributeXRefNew.CaseAttributeId=11 " + "AND CaseAttributeXRef.New.StrainId = Strain.Id " + "AND Strain.Name = %(name)s" ) + + with conn.cursor() as cursor: + return cursor.execute(query, {"name": name}).fetchone()[0] + def group_samples(target_group: str) -> List: """ Get the group samples from its "dummy" .geno file (which still contains the sample list) @@ -115,3 +124,4 @@ def strain_genotypes(strain_genofile: str) -> List: if __name__ == "__main__": print("command line arguments:\n\t%s" % sys.argv) main(sys.argv) + -- cgit v1.2.3