aboutsummaryrefslogtreecommitdiff
path: root/gn3/api
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-11-20 17:42:59 +0300
committerBonfaceKilz2023-11-27 12:29:25 +0300
commit59c8bc53f8aa386a1052478c8553c523bfaaeb3d (patch)
tree2a5548201442a3e5790cf52e79f034e900d20b03 /gn3/api
parent31a9f9af4b87dcbc8e07785bcc2bbe59963e69bc (diff)
downloadgenenetwork3-59c8bc53f8aa386a1052478c8553c523bfaaeb3d.tar.gz
Attach phenotype endpoints to one function.
* gn3/api/metadata.py (phenotypes): Add "/phenotypes/<group>/<name>" to this endpoint. (fetch_phenotype_by_group): Delete. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/api')
-rw-r--r--gn3/api/metadata.py64
1 files changed, 5 insertions, 59 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index b97a4c4..45bef41 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -416,13 +416,14 @@ CONSTRUCT {
except (RemoteDisconnected, URLError):
return jsonify({})
-
-@metadata.route("/phenotypes/<name>", methods=["GET"])
-def phenotypes(name):
+@metadata.route("/phenotypes/<name>",methods=["GET"])
+@metadata.route("/phenotypes/<group>/<name>", methods=["GET"])
+def phenotypes(name, group=None):
"""Fetch a phenotype's metadata given it's name"""
try:
args = request.args
- dataset = args.get("dataset", "")
+ if group:
+ name = f"{group}_{name}"
_query = Template("""
$prefix
@@ -476,61 +477,6 @@ CONSTRUCT {
return jsonify({})
-@metadata.route("/phenotypes/<group>/<name>", methods=["GET"])
-def fetch_phenotype_by_group(group, name):
- """Fetch a phenotype's metadata given it's name"""
- try:
- args = request.args
- dataset = args.get("dataset", "")
- _query = Template("""
-$prefix
-
-CONSTRUCT {
- ?phenotype ?predicate ?object ;
- ?pubPredicate ?pubObject ;
- ex:species ?speciesName ;
- ex:inbredSet ?inbredSetName ;
- ex:dataset ?datasetName .
-} WHERE {
- ?phenotype rdfs:label "$name" ;
- xkos:classifiedUnder ?inbredSet ;
- ?predicate ?object .
- ?inbredSet ^xkos:classifiedUnder ?phenotype ;
- (rdfs:label|skos:prefLabel|gnt:code) "$group" ;
- xkos:generalizes ?species .
- ?species skos:prefLabel ?speciesName .
- FILTER (!regex(str(?predicate), '(classifiedUnder)', 'i')) .
- OPTIONAL {
- ?publication ^dct:isReferencedBy ?phenotype ;
- rdf:type fabio:ResearchPaper ;
- ?pubPredicate ?pubObject .
- FILTER (!regex(str(?pubPredicate), '(hasPubMedId|type)', 'i')) .
- } .
- OPTIONAL {
- ?dataset rdf:type dcat:Dataset ;
- xkos:classifiedUnder ?type;
- rdfs:label "$dataset" ;
- skos:prefLabel ?datasetName .
- ?type ^skos:member gnc:DatasetType .
- FILTER(?type = gnc:Phenotype) .
- }
-}
-""").substitute(prefix=RDF_PREFIXES,
- group=group,
- name=name,
- dataset=dataset)
- _context = {
- "@context": PHENOTYPE_CONTEXT,
- "type": "gnc:Phenotype",
- }
- return query_frame_and_compact(
- _query, _context,
- current_app.config.get("SPARQL_ENDPOINT")
- )
- except (RemoteDisconnected, URLError):
- return jsonify({})
-
-
@metadata.route("/genotypes/<name>", methods=["GET"])
def genotypes(name):
"""Fetch a genotype's metadata given it's name"""