aboutsummaryrefslogtreecommitdiff
path: root/gn3/api
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-10-24 12:06:34 +0300
committerBonfaceKilz2023-10-27 13:45:32 +0300
commit56c431064190f1783944b97a330adb32f933e294 (patch)
treee7da63bb75d578483def5142f4ad910f17174c14 /gn3/api
parent724f809233730782af35e5702cd6aadfac7c9512 (diff)
downloadgenenetwork3-56c431064190f1783944b97a330adb32f933e294.tar.gz
Implement "GET metadata/groups".
* gn3/api/metadata.py (fetch_species): New end-point. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/api')
-rw-r--r--gn3/api/metadata.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index ce4b689..2b0ad6c 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -710,3 +710,48 @@ CONSTRUCT {
})
except (RemoteDisconnected, URLError):
return jsonify({})
+
+
+@metadata.route("/groups", methods=["GET"])
+def groups():
+ """Fetch the list of groups"""
+ try:
+ sparql = SPARQLWrapper(current_app.config.get("SPARQL_ENDPOINT"))
+ sparql.setQuery(Template("""
+$prefix
+
+CONSTRUCT {
+ ?group ?predicate ?object .
+} WHERE {
+ ?group ^skos:member gnc:Set ;
+ ?predicate ?object .
+ VALUES ?predicate {
+ rdfs:label skos:prefLabel
+ gnt:geneticType gnt:mappingMethod
+ gnt:code gnt:family
+ }
+
+}
+""").substitute(prefix=RDF_PREFIXES))
+ 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",
+ "fullName": "skos:prefLabel",
+ },
+ })
+ except (RemoteDisconnected, URLError):
+ return jsonify({})