aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2022-10-11 17:37:20 +0300
committerBonfaceKilz2022-11-02 17:36:22 +0300
commit2e85b5c7c4be181182f263fcb644abd173be83c1 (patch)
treebd34c19c3d41e6435495fa4da6dd56d886bcb96d
parent29977a9c52e95ac58cbc402908e26998788f0820 (diff)
downloadgenenetwork3-2e85b5c7c4be181182f263fcb644abd173be83c1.tar.gz
Fix pylint and mypy errors
* gn3/db/sample_data.py (get_trait_csv_sample_data): Pass __query directly to cursor.execute. Rename value to _value in for loop to make mypy pass. * gn3/db_utils.py (Connection): Add class docstring. (Connection.cursor): Add docstring. * mypy.ini: Add an entry for xapian.
-rw-r--r--gn3/db/sample_data.py38
-rw-r--r--gn3/db_utils.py2
-rw-r--r--mypy.ini3
3 files changed, 20 insertions, 23 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py
index b67fe1c..96168f1 100644
--- a/gn3/db/sample_data.py
+++ b/gn3/db/sample_data.py
@@ -63,29 +63,21 @@ def get_trait_csv_sample_data(
conn: Any, trait_name: int, phenotype_id: int
) -> str:
"""Fetch a trait and return it as a csv string"""
- __query = (
- "SELECT concat(st.Name, ',', ifnull(pd.value, 'x'), ',', "
- "ifnull(ps.error, 'x'), ',', ifnull(ns.count, 'x')) as 'Data' "
- ",ifnull(ca.Name, 'x') as 'CaseAttr', "
- "ifnull(cxref.value, 'x') as 'Value' "
- "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 "
- "LEFT JOIN PublishSE ps ON ps.DataId = pd.Id "
- "AND ps.StrainId = pd.StrainId "
- "LEFT JOIN NStrain ns ON ns.DataId = pd.Id "
- "AND ns.StrainId = pd.StrainId "
- "LEFT JOIN CaseAttributeXRefNew cxref ON "
- "(cxref.InbredSetId = px.InbredSetId AND "
- "cxref.StrainId = st.Id) "
- "LEFT JOIN CaseAttribute ca ON ca.Id = cxref.CaseAttributeId "
- "WHERE px.Id = %s AND px.PhenotypeId = %s ORDER BY st.Name"
- )
case_attr_columns = set()
csv_data: Dict = {}
with conn.cursor() as cursor:
- cursor.execute(__query, (trait_name, phenotype_id))
+ cursor.execute("""
+SELECT concat(st.Name, ',', ifnull(pd.value, 'x'), ',',
+ifnull(ps.error, 'x'), ',', ifnull(ns.count, 'x')) AS 'Data',
+ifnull(ca.Name, 'x') AS 'CaseAttr', ifnull(cxref.value, 'x') AS 'Value'
+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
+LEFT JOIN PublishSE ps ON ps.DataId = pd.Id AND ps.StrainId = pd.StrainId
+LEFT JOIN NStrain ns ON ns.DataId = pd.Id AND ns.StrainId = pd.StrainId
+LEFT JOIN CaseAttributeXRefNew cxref ON (cxref.InbredSetId = px.InbredSetId
+AND cxref.StrainId = st.Id) LEFT JOIN CaseAttribute ca
+ON ca.Id = cxref.CaseAttributeId WHERE px.Id = %s
+AND px.PhenotypeId = %s ORDER BY st.Name""", (trait_name, phenotype_id))
for data in cursor.fetchall():
if data[1] == "x":
csv_data[data[0]] = None
@@ -102,11 +94,11 @@ def get_trait_csv_sample_data(
return "Strain Name,Value,SE,Count\n" + "\n".join(csv_data.keys())
columns = sorted(case_attr_columns)
csv = "Strain Name,Value,SE,Count," + ",".join(columns) + "\n"
- for key, value in csv_data.items():
- if not value:
+ for key, _value in csv_data.items():
+ if not _value:
csv += key + (len(case_attr_columns) * ",x") + "\n"
else:
- vals = [str(value.get(column, "x")) for column in columns]
+ vals = [str(_value.get(column, "x")) for column in columns]
csv += key + "," + ",".join(vals) + "\n"
return csv
return "No Sample Data Found"
diff --git a/gn3/db_utils.py b/gn3/db_utils.py
index 4fd3666..23a570b 100644
--- a/gn3/db_utils.py
+++ b/gn3/db_utils.py
@@ -27,7 +27,9 @@ def database_connector() -> mdb.Connection:
# pylint: disable=missing-class-docstring, missing-function-docstring, too-few-public-methods
class Connection(Protocol):
+ """Type Annotation for MySQLdb's connection object"""
def cursor(self) -> Any:
+ """A cursor in which queries may be performed"""
...
diff --git a/mypy.ini b/mypy.ini
index 58f0f88..0880695 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -45,3 +45,6 @@ ignore_missing_imports = True
[mypy-scripts.argparse_actions.*]
ignore_missing_imports = True
+
+[mypy-xapian.*]
+ignore_missing_imports = True