aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorBonfaceKilz2021-05-05 14:37:35 +0300
committerBonfaceKilz2021-05-08 19:19:47 +0300
commit83dfbe112f32511b4f656de7f387470cff0680ed (patch)
treed1561b8391a8842e28e02701d10c06ede4c8cef0 /gn3
parent5217a366e7904142fc443594facb126d28cd2b25 (diff)
downloadgenenetwork3-83dfbe112f32511b4f656de7f387470cff0680ed.tar.gz
Fix pep-8 errors
Diffstat (limited to 'gn3')
-rw-r--r--gn3/api/data_entry.py2
-rw-r--r--gn3/db/traits.py67
-rw-r--r--gn3/db_utils.py3
3 files changed, 14 insertions, 58 deletions
diff --git a/gn3/api/data_entry.py b/gn3/api/data_entry.py
index e69a6cb..0a093d1 100644
--- a/gn3/api/data_entry.py
+++ b/gn3/api/data_entry.py
@@ -9,10 +9,12 @@ data_entry = Blueprint("data_entry", __name__)
@data_entry.route("/phenotype", methods=["POST"],
strict_slashes=False)
def load_phenotype():
+ """Load the phenotype"""
return jsonify("Pass")
@data_entry.route("/genotype", methods=["POST"],
strict_slashes=False)
def load_genotype():
+ """Load the genotype"""
return jsonify("Pass")
diff --git a/gn3/db/traits.py b/gn3/db/traits.py
index 0cebe2c..4860a07 100644
--- a/gn3/db/traits.py
+++ b/gn3/db/traits.py
@@ -1,23 +1,21 @@
"""This contains all the necessary functions that are required to add traits
to the published database"""
from dataclasses import dataclass
-from itertools import chain
-from typing import Optional
-from typing import Any, Dict, List, Optional
+from typing import Any, Dict, Optional
@dataclass(frozen=True)
-class riset:
+class Riset:
"""Class for keeping track of riset. A riset is a group e.g. rat HSNIH-Palmer,
BXD
"""
- name: str
- r_id: int
+ name: Optional[str]
+ r_id: Optional[int]
@dataclass(frozen=True)
-class webqtlCaseData:
+class WebqtlCaseData:
"""Class for keeping track of one case data in one trait"""
value: Optional[float] = None
variance: Optional[float] = None
@@ -48,6 +46,10 @@ HLCPublish."""
def get_riset(data_type: str, name: str, conn: Any):
+ """Get the groups given the data type and it's PublishFreeze or GenoFreeze
+name
+
+ """
query, _name, _id = None, None, None
if data_type == "Publish":
query = ("SELECT InbredSet.Name, InbredSet.Id FROM InbredSet, "
@@ -68,7 +70,7 @@ def get_riset(data_type: str, name: str, conn: Any):
_name, _id = cursor.fetchone()
if _name == "BXD300":
_name = "BXD"
- return riset(_name, _id)
+ return Riset(_name, _id)
def insert_publication(pubmed_id: int, publication: Optional[Dict],
@@ -80,7 +82,7 @@ def insert_publication(pubmed_id: int, publication: Optional[Dict],
with conn.cursor() as cursor:
cursor.execute(sql)
_id = cursor.fetchone()
- if not _id:
+ if not _id and publication:
# The Publication contains the fields: 'authors', 'title', 'abstract',
# 'journal','volume','pages','month','year'
insert_query = ("INSERT into Publication (%s) Values (%s)" %
@@ -88,50 +90,3 @@ def insert_publication(pubmed_id: int, publication: Optional[Dict],
", ".join(['%s'] * len(publication))))
with conn.cursor() as cursor:
cursor.execute(insert_query, tuple(publication.values()))
-
-
-def insert_publication_data(riset_id: int, strains: List, conn: Any):
- species_id = None
- with conn.cursor() as cursor:
- cursor.execute("SELECT SpeciesId from InbredSet where "
- "Id=%s" % riset_id)
- species_id, *_ = cursor.fetchone()
- cursor.execute(
- "SELECT Id FROM Strain WHERE SpeciesId="
- "%s AND Name in (%s)"
- % (riset_id, ", ".join(f"'{strain}'" for strain in strains)))
- strain_ids = cursor.fetchall()
- data_id, *_ = cursor.execute("SELECT max(Id) "
- "from PublishData").fetchone()
-
- if strain_ids:
- strain_ids = list(chain(*strain_ids))
- for strain, strain_id in zip(strains, strain_ids):
- # TODO: Fetch this values correctly using sql
- value, variance, trait_np = 1, 1, 1
- if value:
- cursor.execute(
- "INSERT INTO PublishData values (%d, %d, %s)" %
- (data_id, strain_id, value))
- if variance:
- cursor.execute(
- "INSERT INTO PublishSE values (%d, %d, %s)" %
- (data_id, strain_id, variance))
- if trait_np:
- cursor.execute(
- "INSERT INTO NStrain values (%d, %d, %s)" %
- (data_id, strain_id, trait_np))
- inbred_set_id = lookup_webqtldataset_name(riset_name="",
- conn=conn)
- cursor.execute(
- "SELECT max(Sequence) FROM PublishXRef where "
- "InbredSetId = %d and PhenotypeId = %d and PublicationId = %d" %
- (inbred_set_id, phenotype_id, publication_id))
-
-
-def insert_phenotype(phenotype: Optional[Dict], conn: Any):
- insert_query = ("INSERT into Phenotype (%s) Values (%s)" %
- (", ".join(phenotype.keys()),
- ", ".join(['%s'] * len(phenotype))))
- with conn.cursor() as cursor:
- cursor.execute(insert_query, tuple(phenotype.values()))
diff --git a/gn3/db_utils.py b/gn3/db_utils.py
index 34c5bf0..9dd3215 100644
--- a/gn3/db_utils.py
+++ b/gn3/db_utils.py
@@ -14,11 +14,10 @@ def parse_db_url() -> Tuple:
parsed_db.password, parsed_db.path[1:])
-def database_connector()->Tuple:
+def database_connector() -> Tuple:
"""function to create db connector"""
host, user, passwd, db_name = parse_db_url()
conn = mdb.connect(host, user, passwd, db_name)
cursor = conn.cursor()
return (conn, cursor)
- \ No newline at end of file