aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorBonfaceKilz2021-05-08 16:02:29 +0300
committerBonfaceKilz2021-05-08 19:19:47 +0300
commita460bab0b127c4c992e36a26e3882d863909df0a (patch)
treeaf2f1533156c075a3f0fec78a41fe67f7fe80e25 /gn3
parentedf8dbeeb888a72bb0cf7afc1825af00038f4a8d (diff)
downloadgenenetwork3-a460bab0b127c4c992e36a26e3882d863909df0a.tar.gz
db: species: Fetch chromosomes using a group or species name
* gn3/db/species.py (get_chromosome): New function.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/db/species.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/gn3/db/species.py b/gn3/db/species.py
new file mode 100644
index 0000000..91b78e2
--- /dev/null
+++ b/gn3/db/species.py
@@ -0,0 +1,24 @@
+"""This module contains db functions that get data related to species or
+groups. Particularly useful when generating the menu
+
+"""
+from typing import Any, Optional, Tuple
+from MySQLdb import escape_string
+
+
+def get_chromosome(name: str, is_species: bool, conn: Any) -> Optional[Tuple]:
+ """Given either a group or a species Name, return all the species"""
+ _sql = ("SELECT Chr_Length.Name, Chr_Length.OrderId, "
+ "Length FROM Chr_Length, Species WHERE "
+ "Chr_Length.SpeciesId = Species.SpeciesId AND "
+ "Species.Name = "
+ f"'{escape_string(name).decode('UTF-8')}' ORDER BY OrderId")
+ if not is_species:
+ _sql = ("SELECT Chr_Length.Name, Chr_Length.OrderId, "
+ "Length FROM Chr_Length, InbredSet WHERE "
+ "Chr_Length.SpeciesId = InbredSet.SpeciesId AND "
+ "InbredSet.Name = "
+ f"'{escape_string(name).decode('UTF-8')}' ORDER BY OrderId")
+ with conn.cursor() as cursor:
+ cursor.execute(_sql)
+ return cursor.fetchall()