aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-10-24 12:43:01 +0300
committerBonfaceKilz2023-10-27 13:45:32 +0300
commite9b74f85c4626d42ec933e6e2dd08f16edc456c5 (patch)
tree58feedfce1490d91e8c5757e08d710325a4add8d
parent56c431064190f1783944b97a330adb32f933e294 (diff)
downloadgenenetwork3-e9b74f85c4626d42ec933e6e2dd08f16edc456c5.tar.gz
Implement "GET /group/:name".
* gn3/api/metadata.py (fetch_group_by_species): New end-point. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn3/api/metadata.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index 2b0ad6c..0c5e0a6 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -750,6 +750,48 @@ CONSTRUCT {
"shortName": "gnt:shortName",
"code": "gnt:code",
"mappingMethod": "gnt:mappingMethod",
+@metadata.route("/groups/<name>", methods=["GET"])
+def fetch_group_by_species(name):
+ """Fetch the list of groups"""
+ try:
+ sparql = SPARQLWrapper(current_app.config.get("SPARQL_ENDPOINT"))
+ sparql.setQuery(Template("""
+$prefix
+
+CONSTRUCT {
+ ?group ?predicate ?object .
+} WHERE {
+ ?species gnt:shortName "$name" ;
+ ^skos:member gnc:Species .
+ ?group ^skos:member gnc:Set ;
+ xkos:generalizes ?species ;
+ ?predicate ?object .
+ VALUES ?predicate {
+ rdfs:label skos:prefLabel
+ gnt:geneticType gnt:mappingMethod
+ gnt:code gnt:family
+ }
+
+}
+""").substitute(prefix=RDF_PREFIXES, name=name))
+ results = sparql.queryAndConvert()
+ results = json.loads(
+ results.serialize(format="json-ld")
+ )
+ return jsonld.compact(results, {
+ "@context": {
+ "data": "@graph",
+ "type": "@type",
+ "id": "@id",
+ "skos": "http://www.w3.org/2004/02/skos/core#",
+ "gnt": "http://genenetwork.org/term/",
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
+ "name": "rdfs:label",
+ "family": "gnt:family",
+ "shortName": "gnt:shortName",
+ "code": "gnt:code",
+ "mappingMethod": "gnt:mappingMethod",
+ "geneticType": "gnt:geneticType",
"fullName": "skos:prefLabel",
},
})