aboutsummaryrefslogtreecommitdiff
path: root/gn3/api
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/api')
-rw-r--r--gn3/api/metadata.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index c501331..3731cc1 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -1187,3 +1187,99 @@ CONSTRUCT {
except (RemoteDisconnected, URLError):
return jsonify({})
+@metadata.route("/genewikis/ncbi/<symbol>", methods=["GET"])
+def get_ncbi_genewiki_entries(symbol):
+ """Fetch the NCBI GeneRIF entries"""
+ try:
+ args = request.args
+ page = args.get("page", 0)
+ page_size = args.get("per-page", 10)
+ sparql = SPARQLWrapper(current_app.config.get("SPARQL_ENDPOINT"))
+ sparql.setQuery(Template("""
+$prefix
+
+CONSTRUCT {
+ ?symbol ex:entries [
+ rdfs:comment ?comment ;
+ gnt:hasGeneId ?geneId ;
+ ex:species ?species_ ;
+ dct:created ?createTime ;
+ dct:references ?pmids ;
+ dct:creator ?creator ;
+ ] .
+ ?symbol rdf:type gnc:GNWikiEntry ;
+ ex:totalCount ?totalCount ;
+ ex:currentPage $offset .
+} WHERE {
+{
+ SELECT ?symbol ?comment ?geneId (GROUP_CONCAT(DISTINCT ?speciesName; SEPARATOR='; ') AS ?species_)
+ ?createTime ?creator
+ (GROUP_CONCAT(DISTINCT ?pubmed; SEPARATOR='; ') AS ?pmids)
+ WHERE {
+ ?symbol rdfs:label ?label ;
+ rdfs:comment _:entry .
+ ?label bif:contains "'$symbol'" .
+ _:entry rdf:type gnc:NCBIWikiEntry ;
+ rdfs:comment ?comment .
+ OPTIONAL {
+ ?species ^xkos:classifiedUnder _:entry ;
+ ^skos:member gnc:Species ;
+ skos:prefLabel ?speciesName .
+ } .
+ OPTIONAL { _:entry gnt:hasGeneId ?geneId . } .
+ OPTIONAL { _:entry dct:created ?createTime . } .
+ OPTIONAL { _:entry dct:references ?pubmed . } .
+ OPTIONAL {
+ ?investigator foaf:name ?creator ;
+ ^dct:creator _:entry .
+ } .
+ } GROUP BY ?comment ?symbol ?createTime ?creator ?geneId ORDER BY ?createTime LIMIT $limit OFFSET $offset
+}
+
+{
+ SELECT (COUNT(DISTINCT ?comment)/$limit+1 AS ?totalCount) WHERE {
+ ?symbol rdfs:comment _:entry ;
+ rdfs:label ?label .
+ _:entry rdfs:comment ?comment ;
+ rdf:type gnc:NCBIWikiEntry .
+ ?label bif:contains "'$symbol'" .
+ }
+}
+}
+""").substitute(prefix=RDF_PREFIXES, symbol=symbol,
+ limit=page_size, offset=page))
+ results = sparql.queryAndConvert()
+ results = json.loads(results.serialize(format="json-ld"))
+ context = {
+ "@context": {
+ "data": "@graph",
+ "type": "@type",
+ "id": "@id",
+ "ex": "http://example.org/stuff/1.0/",
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
+ "gnt": "http://genenetwork.org/term/",
+ "gnc": "http://genenetwork.org/category/",
+ "dct": "http://purl.org/dc/terms/",
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
+ "entries": "ex:entries",
+ "comment": "rdfs:comment",
+ "category": 'gnt:belongsToCategory',
+ "author": "dct:creator",
+ "species": "ex:species",
+ "geneId": "gnt:hasGeneId",
+ "pubmed": "dct:references",
+ "currentPage": "ex:currentPage",
+ "pages": "ex:totalCount",
+ "created": {
+ "@id": "dct:created",
+ "@type": "xsd:datetime"
+ },
+ },
+ "type": "gnc:GNWikiEntry"
+ }
+ return jsonld.compact(
+ jsonld.frame(results, context),
+ context)
+ except (RemoteDisconnected, URLError):
+ return jsonify({})
+