diff options
author | Munyoki Kilyungi | 2022-08-30 21:39:38 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-08-31 23:14:30 +0300 |
commit | d9a6e9433e4fd5cc20ed45a53c34cab4357eac8e (patch) | |
tree | ddef02f3325e32119d8f72addd3930304d5d7fc6 /wqflask/db/webqtlDatabaseFunction.py | |
parent | 2d9ad72cf8078610fc2cff8726e68a40dcf64685 (diff) | |
download | genenetwork2-d9a6e9433e4fd5cc20ed45a53c34cab4357eac8e.tar.gz |
Replace fetchall, fetchone, fetch1 with database_connection
* wqflask/base/data_set.py: Replace "db.call" import with
"database_connection".
(create_datasets_list): Use "database_connection" to fetch data.
(DatasetGroup.__init__): Ditto.
(DataSet.retrieve_other_names): Ditto.
(PhenotypeDataSet.setup): Remove query escaping in string and format
the string.
(GenotypeDataSet.setup): Ditto.
(MrnaAssayDataSet.setup): Ditto.
* wqflask/db/webqtlDatabaseFunction.py: Remove db.call import.
(retrieve_species): Use database_connection() to fetch data.
(retrieve_species_id): Ditto.
Diffstat (limited to 'wqflask/db/webqtlDatabaseFunction.py')
-rw-r--r-- | wqflask/db/webqtlDatabaseFunction.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/wqflask/db/webqtlDatabaseFunction.py b/wqflask/db/webqtlDatabaseFunction.py index 9ec650a4..122c546f 100644 --- a/wqflask/db/webqtlDatabaseFunction.py +++ b/wqflask/db/webqtlDatabaseFunction.py @@ -20,19 +20,23 @@ # # This module is used by GeneNetwork project (www.genenetwork.org) -from db.call import fetch1 +from wqflask.database import database_connection def retrieve_species(group): """Get the species of a group (e.g. returns string "mouse" on "BXD" """ - result = fetch1("select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % ( - group), "/cross/" + group + ".json", lambda r: (r["species"],))[0] + with database_connection() as conn, conn.cursor() as cursor: + cursor.execute( + "SELECT Species.Name FROM Species, InbredSet WHERE InbredSet.Name = %s AND InbredSet.SpeciesId = Species.Id", + (group,)) + return cursor.fetchone()[0] return result def retrieve_species_id(group): - result = fetch1("select SpeciesId from InbredSet where Name = '%s'" % ( - group), "/cross/" + group + ".json", lambda r: (r["species_id"],))[0] - return result + with database_connection() as conn, conn.cursor() as cursor: + cursor.execute("SELECT SpeciesId FROM InbredSet WHERE Name = %s", + (group,)) + return cursor.fetchone()[0] |