aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/metadata.py16
-rw-r--r--gn3/db/rdf.py43
2 files changed, 59 insertions, 0 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index a2eff05..f21739a 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -11,6 +11,7 @@ from SPARQLWrapper import SPARQLWrapper
from gn3.db.rdf import get_dataset_metadata
from gn3.db.rdf import get_publication_metadata
from gn3.db.rdf import get_phenotype_metadata
+from gn3.db.rdf import get_genotype_metadata
from gn3.db.rdf import sparql_query
from gn3.db.rdf import RDF_PREFIXES
@@ -67,6 +68,21 @@ def phenotype(name):
return jsonify({})
+@metadata.route("/genotype/<name>", methods=["GET"])
+def genotype(name):
+ """Fetch a genotype's metadata given it's name"""
+ try:
+ return jsonify(
+ get_genotype_metadata(
+ SPARQLWrapper(current_app.config.get("SPARQL_ENDPOINT")),
+ name,
+ ).data
+ )
+ # The virtuoso server is misconfigured or it isn't running at all
+ except (RemoteDisconnected, URLError):
+ return jsonify({})
+
+
@metadata.route("/genewiki/<symbol>", methods=["GET"])
def get_genewiki_entries(symbol):
"""Fetch the GN and NCBI GeneRIF entries"""
diff --git a/gn3/db/rdf.py b/gn3/db/rdf.py
index 83bc46b..ad2e3be 100644
--- a/gn3/db/rdf.py
+++ b/gn3/db/rdf.py
@@ -26,6 +26,7 @@ PREFIX up: <http://purl.uniprot.org/core/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX publication: <http://genenetwork.org/publication/>
PREFIX phenotype: <http://genenetwork.org/phenotype/>
+PREFIX genotype: <http://genenetwork.org/genotype/>
"""
@@ -243,3 +244,45 @@ CONSTRUCT {
)[0].items():
result[key] = value
return result
+
+
+def get_genotype_metadata(
+ sparql_conn: SPARQLWrapper, name: str
+):
+ """Return info about a phenotype with a given NAME"""
+ __metadata_query = """
+$prefix
+
+CONSTRUCT {
+ ?genotype ?pPredicate ?pValue .
+ ?genotype gn:speciesName ?speciesName .
+ ?genotype gn:inbredSetName ?inbredSetBinomialName .
+ ?genotype gn:datasetName ?datasetFullName .
+} WHERE {
+ ?genotype ?pPredicate ?pValue .
+ OPTIONAL {
+ ?genotype gn:genotypeOfDataset ?dataset .
+ ?dataset gn:fullName ?datasetFullName .
+ }.
+ OPTIONAL {
+ ?genotype gn:genotypeOfDataset ?dataset .
+ ?dataset gn:datasetOfInbredSet ?inbredSet .
+ ?inbredSet gn:binomialName ?inbredSetBinomialName .
+ ?inbredSet gn:inbredSetOfSpecies ?species .
+ ?species gn:displayName ?speciesName .
+ } .
+ FILTER( ?genotype = genotype:$name ) .
+ MINUS {
+ ?genotype rdf:type ?pValue .
+ }
+}
+"""
+ result: MonadicDict = MonadicDict()
+ for key, value in sparql_query(
+ sparql_conn,
+ Template(__metadata_query)
+ .substitute(name=name,
+ prefix=RDF_PREFIXES)
+ )[0].items():
+ result[key] = value
+ return result