aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-01-10 13:51:12 +0300
committerBonfaceKilz2024-01-10 13:56:55 +0300
commit5295c4d9d7e7c17dcbb8127d6f4b6c67aad6baa7 (patch)
tree8841e31ce1a8981728821cc61a65f967f6eb5800 /gn3
parenta3f0be01324f0e9430e6376e70537a8c90a41378 (diff)
downloadgenenetwork3-5295c4d9d7e7c17dcbb8127d6f4b6c67aad6baa7.tar.gz
Optionally fetch dataset metadata if provided during genotype fetch.
* gn3/api/metadata.py (genotypes): If a dataset name is provided fetch the group it belongs to and the dataset's full and short name. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3')
-rw-r--r--gn3/api/metadata.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index 7657fe3..dcb06f4 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -491,7 +491,8 @@ CONSTRUCT {
@metadata.route("/genotypes/<name>", methods=["GET"])
-def genotypes(name):
+@metadata.route("/genotypes/<dataset>/<name>", methods=["GET"])
+def genotypes(name, dataset=""):
"""Fetch a genotype's metadata given it's name"""
try:
_query = Template("""
@@ -499,7 +500,11 @@ $prefix
CONSTRUCT {
?genotype ?predicate ?object .
+ ?genotype dcat:dataset ?dataset .
?species gnt:shortName ?speciesShortName .
+ ?dataset rdfs:label ?datasetName ;
+ skos:prefLabel ?datasetFullName ;
+ gnt:belongsToGroup ?groupName .
} WHERE {
?genotype rdf:type gnc:Genotype ;
rdfs:label "$name" ;
@@ -508,8 +513,17 @@ CONSTRUCT {
?species ^gnt:belongsToSpecies ?genotype ;
gnt:shortName ?speciesShortName .
} .
+ OPTIONAL {
+ ?dataset rdf:type dcat:Dataset ;
+ (rdfs:label|dct:identifier|skos:prefLabel) "$dataset" ;
+ rdfs:label ?datasetName ;
+ skos:prefLabel ?datasetFullName ;
+ gnt:belongsToGroup ?inbredSet .
+ ?inbredSet rdfs:label ?groupName .
+ } .
}
-""").substitute(prefix=RDF_PREFIXES, name=name)
+""").substitute(prefix=RDF_PREFIXES,
+ name=name, dataset=dataset)
_context = {
"@context": BASE_CONTEXT | {
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
@@ -519,6 +533,10 @@ CONSTRUCT {
"xsd": "http://www.w3.org/2001/XMLSchema#",
"name": "rdfs:label",
"chr": "gnt:chr",
+ "skos": "http://www.w3.org/2004/02/skos/core#",
+ "prefLabel": "skos:prefLabel",
+ "dcat": "http://www.w3.org/ns/dcat#",
+ "dataset": "dcat:dataset",
"mb": "gnt:mb",
"mbMm8": "gnt:mbMm8",
"mb2016": "gnt:mb2016",
@@ -528,6 +546,7 @@ CONSTRUCT {
"speciesName": "gnt:shortName",
"alternateSource": "gnt:hasAltSourceName",
"comments": "rdfs:comments",
+ "group": "gnt:belongsToGroup",
"chrNum": {
"@id": "gnt:chrNum",
"@type": "xsd:int",
@@ -959,8 +978,7 @@ CONSTRUCT {
?species gnt:shortName ?speciesShortName .
} .
}
-""").substitute(prefix=RDF_PREFIXES,
- name=name, dataset=dataset)
+""").substitute(prefix=RDF_PREFIXES, name=name, dataset=dataset)
_context = {
"@context": BASE_CONTEXT | {
"alias": "skos:altLabel",