aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-09-09 15:11:48 +0300
committerFrederick Muriuki Muriithi2022-09-09 15:11:48 +0300
commitd153147cfbd891d886519da5f0b08f6441f63b3c (patch)
tree0b5789879e1c91cb2a13652e8d7d5bd341ee6533 /wqflask
parent2852eb1725bc9bd6de0c02be84e5ac93eea33704 (diff)
downloadgenenetwork2-d153147cfbd891d886519da5f0b08f6441f63b3c.tar.gz
Fix query: remove string interpolation.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/correlation/rust_correlation.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py
index ef3988e5..92cb362c 100644
--- a/wqflask/wqflask/correlation/rust_correlation.py
+++ b/wqflask/wqflask/correlation/rust_correlation.py
@@ -134,20 +134,21 @@ def compute_top_n_sample(start_vars, dataset, trait_list):
with database_connector() as conn:
with conn.cursor() as curr:
# fetching strain data in bulk
+ query = (
+ "SELECT * from ProbeSetData "
+ f"WHERE StrainID IN ({', '.join(['%s'] * len(sample_ids))})"
+ "AND id IN ("
+ " SELECT ProbeSetXRef.DataId "
+ " FROM (ProbeSet, ProbeSetXRef, ProbeSetFreeze) "
+ " WHERE ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id "
+ " AND ProbeSetFreeze.Name = %s "
+ " AND ProbeSet.Name "
+ f" IN ({', '.join(['%s'] * len(trait_list))})"
+ " ProbeSet.Id = ProbeSetXRef.ProbeSetId)"
+ ")")
curr.execute(
- """
- SELECT * from ProbeSetData
- where StrainID in {}
- and id in (SELECT ProbeSetXRef.DataId
- FROM (ProbeSet, ProbeSetXRef, ProbeSetFreeze)
- WHERE ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id
- and ProbeSetFreeze.Name = '{}'
- and ProbeSet.Name in {}
- and ProbeSet.Id = ProbeSetXRef.ProbeSetId)
- """.format(
- create_in_clause(list(sample_ids.values())),
- dataset.name,
- create_in_clause(trait_list)))
+ query,
+ tuple(sample_ids.values()) + (dataset.name,) + tuple(trait_list))
corr_data = chunk_dataset(
list(curr.fetchall()), len(sample_ids.values()), dataset.name)