aboutsummaryrefslogtreecommitdiff
path: root/gn3/db/rdf.py
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-06-07 09:39:58 +0300
committerBonfaceKilz2023-06-07 09:42:25 +0300
commit4da80ca9c17bdd28e2689895ab6acb1ec0c70d33 (patch)
treea7854686d22a4f6bd64c2ecbb71aa405c7df1cb0 /gn3/db/rdf.py
parentc68d64a2966750283ecd1290d26eee2797fedcad (diff)
downloadgenenetwork3-4da80ca9c17bdd28e2689895ab6acb1ec0c70d33.tar.gz
Add publication end-point
* gn3/api/metadata.py: Import get_publication_metadata (publication): New endpoint. * gn3/db/rdf.py (get_dataset_metadata): New function. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db/rdf.py')
-rw-r--r--gn3/db/rdf.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/gn3/db/rdf.py b/gn3/db/rdf.py
index 5b62b46..c559774 100644
--- a/gn3/db/rdf.py
+++ b/gn3/db/rdf.py
@@ -156,6 +156,46 @@ CONSTRUCT {
):
response[key] = value.map(get_url_local_name) # type: ignore
return response
+
+
+def get_publication_metadata(
+ sparql_conn: SPARQLWrapper, name: str
+):
+ """Return info about a publication with a given NAME"""
+ __metadata_query = """
+$prefix
+
+CONSTRUCT {
+ gn:publication ?publicationTerm ?publicationValue .
+ gn:publication ?predicate ?subject .
+} WHERE {
+ $name ?publicationTerm ?publicationValue .
+ ?publication ?publicationTerm ?publicationValue .
+ OPTIONAL {
+ ?subject ?predicate ?publication .
+ } .
+ VALUES ?publicationTerm {
+ gn:pubMedId gn:title gn:volume
+ gn:abstract gn:pages gn:month gn:year gn:author
+ }
+ VALUES ?predicate {
+ gn:phenotypeOfPublication
+ }
+}
+"""
+ response: MonadicDict = MonadicDict()
+
+ for key, value in sparql_query(
+ sparql_conn,
+ Template(__metadata_query)
+ .substitute(
+ prefix=RDF_PREFIXES,
+ name=name
+ )
+ )[0].items():
+ response[key] = value
+ if isinstance(value, str) and not key.endswith("pubMedId"):
+ response[key] = value.map(get_url_local_name) # type: ignore
return response