aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonfaceKilz2021-04-13 08:21:15 +0300
committerBonfaceKilz2021-05-08 19:19:47 +0300
commit6ec8a5d1de6b6f0f84a76d0d52c77f3d96420479 (patch)
treec0aadbacf4688c802a001ac50397c681b001f424
parentc6f9aca5917d9838680349dc91db215c9a38ecda (diff)
downloadgenenetwork3-6ec8a5d1de6b6f0f84a76d0d52c77f3d96420479.tar.gz
Add method for inserting publications
-rw-r--r--gn3/db/traits.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/gn3/db/traits.py b/gn3/db/traits.py
index b0d1831..5ac342f 100644
--- a/gn3/db/traits.py
+++ b/gn3/db/traits.py
@@ -1,7 +1,7 @@
"""This contains all the necessary functions that are required to add traits
to the published database"""
from collections import namedtuple
-from typing import Any
+from typing import Any, Dict, Optional
riset = namedtuple('riset', ['name', 'id'])
@@ -29,3 +29,22 @@ def get_riset(data_type: str, name: str, conn: Any):
if _name == "BXD300":
_name = "BXD"
return riset(_name, _id)
+
+
+def insert_publication(pubmed_id: int, publication: Optional[Dict],
+ conn: Any):
+ """Creates a new publication record if it's not available"""
+ sql = ("SELECT Id FROM Publication where "
+ "PubMed_ID = %d" % pubmed_id)
+ _id = None
+ with conn.cursor() as cursor:
+ cursor.execute(sql)
+ _id = cursor.fetchone()
+ if not _id:
+ # The Publication contains the fields: 'authors', 'title', 'abstract',
+ # 'journal','volume','pages','month','year'
+ insert_query = ("INSERT into Publication (%s) Values (%s)" %
+ (", ".join(publication.keys()),
+ ", ".join(['%s'] * len(publication))))
+ with conn.cursor() as cursor:
+ cursor.execute(insert_query, tuple(publication.values()))