aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-02-15 00:24:57 +0300
committerBonfaceKilz2023-03-01 22:03:39 +0300
commit01e12ddb0c7f71c8c1700a4fac0b9447d83f3f9f (patch)
treea07d3b200e22cf2059b634a1a0665a69b2885ea3 /gn3/db
parente66e0d24f76458aade54056e18de7d4e0762d06c (diff)
downloadgenenetwork3-01e12ddb0c7f71c8c1700a4fac0b9447d83f3f9f.tar.gz
Fetch trait metadata from RDF
* gn3/db/rdf.py (get_dataset_metadata): New function. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/rdf.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/gn3/db/rdf.py b/gn3/db/rdf.py
index f46e33c..deecefa 100644
--- a/gn3/db/rdf.py
+++ b/gn3/db/rdf.py
@@ -90,3 +90,31 @@ WHERE {
)[0].items():
result[key] = value.bind(lambda x: Just(x["value"]))
return result
+
+
+def get_trait_metadata(
+ sparql_conn: SPARQLWrapper,
+ trait_name: str,
+ dataset_name: str
+):
+ """Return metadata about a given trait"""
+ __metadata_query = """
+PREFIX gn: <http://genenetwork.org/>
+
+SELECT strafter((str(?key)), "http://genenetwork.org/sampledata:") as ?key
+ ?value WHERE {
+ gn:sampledata_$trait_name gn:sampledata:dataset "$dataset_name" .
+ gn:sampledata_$trait_name ?key ?value .
+}
+"""
+ result: MonadicDict = MonadicDict()
+ for _r in sparql_query(
+ sparql_conn,
+ Template(__metadata_query)
+ .substitute(trait_name=trait_name,
+ dataset_name=dataset_name)
+ ):
+ _key = _r["key"].bind(lambda x: x["value"]) # type:ignore
+ if _key:
+ result[_key] = _r["value"].bind(lambda x: Just(x["value"])) # type:ignore
+ return result