Skip to content

Commit

Permalink
Implement "GET /metadata/probesets/:name".
Browse files Browse the repository at this point in the history
* gn3/api/metadata.py (fetch_group_by_species): New end-point.

Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
  • Loading branch information
BonfaceKilz committed Oct 25, 2023
1 parent fae9f56 commit aa04c68
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions gn3/api/metadata.py
Expand Up @@ -1033,3 +1033,71 @@ def fetch_group_by_species(name):
})
except (RemoteDisconnected, URLError):
return jsonify({})

@metadata.route("/probesets/<name>", methods=["GET"])
def probesets(name):
"""Fetch a probesets's metadata given it's name"""
try:
args = request.args
sparql = SPARQLWrapper(current_app.config.get("SPARQL_ENDPOINT"))
sparql.setQuery(Template("""
$prefix
CONSTRUCT {
?probeset ?predicate ?object ;
gnt:hasChip ?chipName .
} WHERE {
?probeset rdf:type gnc:Probeset ;
rdfs:label "$name" ;
?predicate ?object .
FILTER (?predicate != gnt:hasChip) .
OPTIONAL{
?probeset gnt:hasChip ?chip .
?chip rdfs:label ?chipName .
} .
}
""").substitute(prefix=RDF_PREFIXES, name=name))
results = json.loads(sparql.queryAndConvert().serialize(format="json-ld"))
if not results:
return jsonify({})
frame = {
"@context": {
"data": "@graph",
"type": "@type",
"id": "@id",
"gnt": "http://genenetwork.org/term/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"skos": "http://www.w3.org/2004/02/skos/core#",
"dct": "http://purl.org/dc/terms/",
"name": "rdfs:label",
"alias": "skos:altLabel",
"chip": "gnt:hasChip",
"targetId": "gnt:hasTargetId",
"symbol": "gnt:symbol",
"description": "dct:description",
"targetsRegion": "gnt:targetsRegion",
"chr": "gnt:chr",
"mb": "gnt:mb",
"mbMm8": "gnt:mbMm8",
"mb2016": "gnt:mb2016",
"specificity": "gnt:hasSpecificity",
"blatScore": "gnt:hasBlatScore",
"blatMbStart": "gnt:hasBlatMbStart",
"blatMbStart2016": "gnt:hasBlatMbStart2016",
"blatMbEnd": "gnt:hasBlatMbEnd",
"blatMbEnd2016": "gnt:hasBlatMbEnd2016",
"blatSeq": "gnt:hasBlatSeq",
"targetSeq": "gnt:hasTargetSeq",
"homologene": "gnt:hasHomologeneId",
"uniprot": "gnt:hasUniprotId",
"pubchem": "gnt:hasPubChemId",
"kegg": "gnt:hasKeggId",
"omim": "gnt:hasOmimId",
"chebi": "gnt:hasChebiId",
},
}
return jsonld.compact(results, frame)
# return jsonld.compact(jsonld.frame(results, frame), frame)
except (RemoteDisconnected, URLError):
return jsonify({})

0 comments on commit aa04c68

Please sign in to comment.