aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/computations/partial_correlations.py2
-rw-r--r--gn3/db/partial_correlations.py12
-rw-r--r--gn3/db/traits.py2
-rw-r--r--gn3/fs_helpers.py5
-rw-r--r--tests/unit/db/test_traits.py36
5 files changed, 29 insertions, 28 deletions
diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py
index f7ddfd0..7110cc5 100644
--- a/gn3/computations/partial_correlations.py
+++ b/gn3/computations/partial_correlations.py
@@ -141,7 +141,7 @@ def find_identical_traits(
return acc + ident[1]
def __dictify_controls__(acc, control_item):
- ckey = tuple("{item:.3f}" for item in control_item[0])
+ ckey = tuple(f"{item:.3f}" for item in control_item[0])
return {**acc, ckey: acc.get(ckey, tuple()) + (control_item[1],)}
return (reduce(## for identical control traits
diff --git a/gn3/db/partial_correlations.py b/gn3/db/partial_correlations.py
index a28b111..72dbf1a 100644
--- a/gn3/db/partial_correlations.py
+++ b/gn3/db/partial_correlations.py
@@ -48,7 +48,7 @@ def temp_traits_data(conn, traits):
"FROM TempData, Temp, Strain "
"WHERE TempData.StrainId = Strain.Id "
"AND TempData.Id = Temp.DataId "
- "AND Temp.name IN ({', '.join(['%s'] * len(traits))}) "
+ f"AND Temp.name IN ({', '.join(['%s'] * len(traits))}) "
"ORDER BY Strain.Name")
with conn.cursor(cursorclass=DictCursor) as cursor:
cursor.execute(
@@ -386,7 +386,7 @@ def temp_traits_info(
"""
query = (
"SELECT Name as trait_name, name, description FROM Temp "
- "WHERE Name IN ({', '.join(['%s'] * len(traits))})")
+ f"WHERE Name IN ({', '.join(['%s'] * len(traits))})")
with conn.cursor(cursorclass=DictCursor) as cursor:
cursor.execute(
query,
@@ -450,7 +450,7 @@ def publish_datasets_groups(conn: Any, dataset_names: Tuple[str]):
"InbredSet.Id "
"FROM InbredSet, PublishFreeze "
"WHERE PublishFreeze.InbredSetId = InbredSet.Id "
- "AND PublishFreeze.Name IN ({', '.join(['%s'] * len(dataset_names))})")
+ f"AND PublishFreeze.Name IN ({', '.join(['%s'] * len(dataset_names))})")
with conn.cursor(cursorclass=DictCursor) as cursor:
cursor.execute(query, tuple(dataset_names))
return organise_groups_by_dataset(cursor.fetchall())
@@ -500,7 +500,7 @@ def probeset_datasets_groups(conn, dataset_names):
"FROM InbredSet, ProbeSetFreeze, ProbeFreeze "
"WHERE ProbeFreeze.InbredSetId = InbredSet.Id "
"AND ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId "
- "AND ProbeSetFreeze.Name IN ({', '.join(['%s'] * len(dataset_names))})")
+ f"AND ProbeSetFreeze.Name IN ({', '.join(['%s'] * len(dataset_names))})")
with conn.cursor(cursorclass=DictCursor) as cursor:
cursor.execute(query, tuple(dataset_names))
return organise_groups_by_dataset(cursor.fetchall())
@@ -547,7 +547,7 @@ def geno_datasets_groups(conn, dataset_names):
"SELECT GenoFreeze.Name AS dataset_name, InbredSet.Name, InbredSet.Id "
"FROM InbredSet, GenoFreeze "
"WHERE GenoFreeze.InbredSetId = InbredSet.Id "
- "AND GenoFreeze.Name IN ({', '.join(['%s'] * len(dataset_names))})")
+ f"AND GenoFreeze.Name IN ({', '.join(['%s'] * len(dataset_names))})")
with conn.cursor(cursorclass=DictCursor) as cursor:
cursor.execute(query, tuple(dataset_names))
return organise_groups_by_dataset(cursor.fetchall())
@@ -575,7 +575,7 @@ def temp_datasets_groups(conn, dataset_names):
"SELECT Temp.Name AS dataset_name, InbredSet.Name, InbredSet.Id "
"FROM InbredSet, Temp "
"WHERE Temp.InbredSetId = InbredSet.Id "
- "AND Temp.Name IN ({', '.join(['%s'] * len(dataset_names))})")
+ f"AND Temp.Name IN ({', '.join(['%s'] * len(dataset_names))})")
with conn.cursor(cursorclass=DictCursor) as cursor:
cursor.execute(query, tuple(dataset_names))
return organise_groups_by_dataset(cursor.fetchall())
diff --git a/gn3/db/traits.py b/gn3/db/traits.py
index 90d1e9d..6f979d8 100644
--- a/gn3/db/traits.py
+++ b/gn3/db/traits.py
@@ -402,7 +402,7 @@ def retrieve_probeset_trait_info(trait_data_source: Dict[str, Any], conn: Any):
"probe_set_note_by_rw", "flag")
columns = (f"ProbeSet.{x}" for x in keys)
query = (
- f"SELECT {','.join(columns)} "
+ f"SELECT {', '.join(columns)} "
"FROM "
"ProbeSet, ProbeSetFreeze, ProbeSetXRef "
"WHERE "
diff --git a/gn3/fs_helpers.py b/gn3/fs_helpers.py
index e2f7ee2..73f6567 100644
--- a/gn3/fs_helpers.py
+++ b/gn3/fs_helpers.py
@@ -71,8 +71,9 @@ contents to TARGET_DIR/<dir-hash>.
os.mkdir(os.path.join(target_dir, token))
gzipped_file.save(tar_target_loc)
# Extract to "tar_target_loc/token"
- with tarfile.open(tar_target_loc) as tar:
- tar.extractall(path=os.path.join(target_dir, token))
+ tar = tarfile.open(tar_target_loc)
+ tar.extractall(path=os.path.join(target_dir, token))
+ tar.close()
# pylint: disable=W0703
except Exception:
return {"status": 128, "error": "gzip failed to unpack file"}
diff --git a/tests/unit/db/test_traits.py b/tests/unit/db/test_traits.py
index d7c0b27..de65348 100644
--- a/tests/unit/db/test_traits.py
+++ b/tests/unit/db/test_traits.py
@@ -137,11 +137,10 @@ class TestTraitsDBFunctions(TestCase):
"SELECT "
"Geno.name, Geno.chr, Geno.mb, Geno.source2, Geno.sequence "
"FROM "
- "Geno, GenoFreeze, GenoXRef "
+ "Geno INNER JOIN GenoXRef ON GenoXRef.GenoId = Geno.Id "
+ "INNER JOIN GenoFreeze ON GenoFreeze.Id = GenoXRef.GenoFreezeId "
"WHERE "
- "GenoXRef.GenoFreezeId = GenoFreeze.Id "
- "AND GenoXRef.GenoId = Geno.Id "
- "AND GenoFreeze.Name = %(trait_dataset_name)s "
+ "GenoFreeze.Name = %(trait_dataset_name)s "
"AND Geno.Name = %(trait_name)s"),
trait_source)
@@ -232,20 +231,21 @@ class TestTraitsDBFunctions(TestCase):
error=2.3, count=2),
(1, 1, 1))
cursor.execute.assert_has_calls(
- [mock.call('SELECT Strain.Id, PublishData.Id FROM'
- ' (PublishData, Strain, PublishXRef, '
- 'PublishFreeze) LEFT JOIN PublishSE ON '
- '(PublishSE.DataId = PublishData.Id '
- 'AND PublishSE.StrainId = '
- 'PublishData.StrainId) LEFT JOIN NStrain ON '
- '(NStrain.DataId = PublishData.Id AND '
- 'NStrain.StrainId = PublishData.StrainId) WHERE '
- 'PublishXRef.InbredSetId = '
- 'PublishFreeze.InbredSetId AND PublishData.Id = '
- 'PublishXRef.DataId AND PublishXRef.Id = 1 AND '
- 'PublishXRef.PhenotypeId = 10 AND '
- 'PublishData.StrainId = Strain.Id AND '
- 'Strain.Name = "BXD11"'),
+ [mock.call(('SELECT Strain.Id, PublishData.Id FROM'
+ ' (PublishData, Strain, PublishXRef, '
+ 'PublishFreeze) LEFT JOIN PublishSE ON '
+ '(PublishSE.DataId = PublishData.Id '
+ 'AND PublishSE.StrainId = '
+ 'PublishData.StrainId) LEFT JOIN NStrain ON '
+ '(NStrain.DataId = PublishData.Id AND '
+ 'NStrain.StrainId = PublishData.StrainId) WHERE '
+ 'PublishXRef.InbredSetId = '
+ 'PublishFreeze.InbredSetId AND PublishData.Id = '
+ 'PublishXRef.DataId AND PublishXRef.Id = %s AND '
+ 'PublishXRef.PhenotypeId = %s AND '
+ 'PublishData.StrainId = Strain.Id AND '
+ 'Strain.Name = %s'),
+ ("1", 10, "BXD11")),
mock.call(PUBLISH_DATA_SQL, (18.7, 1, 1)),
mock.call(PUBLISH_SE_SQL, (2.3, 1, 1)),
mock.call(N_STRAIN_SQL, (2, 1, 1))]