diff options
author | Munyoki Kilyungi | 2022-09-07 11:58:57 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-09-08 14:26:19 +0300 |
commit | f48d60c1f4ddb222629e19fd42c840a961666334 (patch) | |
tree | 74e9bbffc839490f0c63749d1861fe755c17984c /wqflask | |
parent | e3b7d9a24fb38397d4c393503463973d677925fb (diff) | |
download | genenetwork2-f48d60c1f4ddb222629e19fd42c840a961666334.tar.gz |
Use "%s" in sql query
* wqflask/base/mrna_assay_tissue_data.py: Delete db_tools.
(MrnaAssayTissueData.get_symbol_values_pairs): Re-format query.
* wqflask/tests/unit/base/test_mrna_assay_tissue_data.py:
(test_get_trait_symbol_and_tissue_values): Add test for above.
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/base/mrna_assay_tissue_data.py | 14 | ||||
-rw-r--r-- | wqflask/tests/unit/base/test_mrna_assay_tissue_data.py | 8 |
2 files changed, 16 insertions, 6 deletions
diff --git a/wqflask/base/mrna_assay_tissue_data.py b/wqflask/base/mrna_assay_tissue_data.py index a229151d..9a86134e 100644 --- a/wqflask/base/mrna_assay_tissue_data.py +++ b/wqflask/base/mrna_assay_tissue_data.py @@ -1,6 +1,5 @@ import collections -from utility import db_tools from utility import Bunch @@ -82,13 +81,16 @@ class MrnaAssayTissueData: symbol_values_dict = {} if len(id_list) > 0: - query = """SELECT TissueProbeSetXRef.Symbol, TissueProbeSetData.value - FROM TissueProbeSetXRef, TissueProbeSetData - WHERE TissueProbeSetData.Id IN {} and - TissueProbeSetXRef.DataId = TissueProbeSetData.Id""".format(db_tools.create_in_clause(id_list)) results = [] with self.conn.cursor() as cursor: - cursor.execute(query) + cursor.execute( + "SELECT TissueProbeSetXRef.Symbol, " + "TissueProbeSetData.value FROM " + "TissueProbeSetXRef, TissueProbeSetData " + "WHERE TissueProbeSetData.Id IN (" + f"{', '.join(['%s' * len(id_list)])}) " + "AND TissueProbeSetXRef.DataId = TissueProbeSetData.Id", + tuple(id_list)) results = cursor.fetchall() for result in results: (symbol, value) = result diff --git a/wqflask/tests/unit/base/test_mrna_assay_tissue_data.py b/wqflask/tests/unit/base/test_mrna_assay_tissue_data.py index ecaa9def..c43fb4b6 100644 --- a/wqflask/tests/unit/base/test_mrna_assay_tissue_data.py +++ b/wqflask/tests/unit/base/test_mrna_assay_tissue_data.py @@ -71,3 +71,11 @@ def test_get_trait_symbol_and_tissue_values(mocker): "k2": ["v2"], "k3": ["v3"], } + cursor.execute.assert_called_with( + "SELECT TissueProbeSetXRef.Symbol, " + "TissueProbeSetData.value FROM " + "TissueProbeSetXRef, TissueProbeSetData " + "WHERE TissueProbeSetData.Id IN (%s) " + "AND TissueProbeSetXRef.DataId = " + "TissueProbeSetData.Id", + ('112',)) |