about summary refs log tree commit diff
path: root/gn3/db
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-06-08 14:44:38 +0300
committerBonfaceKilz2023-06-12 15:35:40 +0300
commitfa2ce410d4730b136f24555c049cef3d6dac1102 (patch)
treef155fe2c8e441ba9eb2cd251131b0dfb30e29b9e /gn3/db
parente4489c48bf5d1c9cb72b8cc1eccc603f1178ecbf (diff)
downloadgenenetwork3-fa2ce410d4730b136f24555c049cef3d6dac1102.tar.gz
Fetch phenotypes from virtuoso
* gn3/api/metadata.py: Import get_phenotype_metadata.
(phenotype): New end-point.
* gn3/db/rdf.py (get_phenotype_metadata): New function.

Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/rdf.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/gn3/db/rdf.py b/gn3/db/rdf.py
index e92ccdb..0e472ce 100644
--- a/gn3/db/rdf.py
+++ b/gn3/db/rdf.py
@@ -26,6 +26,7 @@ PREFIX ncbiTaxon: <https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode
 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/>
 """
 
 
@@ -198,12 +199,48 @@ CONSTRUCT {
     return response
 
 
+def get_phenotype_metadata(
+        sparql_conn: SPARQLWrapper, name: str
 ):
+    """Return info about a phenotype with a given NAME"""
     __metadata_query = """
+$prefix
 
+CONSTRUCT {
+    ?phenotype ?pPredicate ?pValue .
+    ?phenotype ?publicationTerm ?publicationValue .
+    ?phenotype gn:speciesName ?speciesName .
+    ?phenotype gn:inbredSetName ?inbredSetBinomialName .
+    ?phenotype gn:datasetName ?datasetFullName .
+} WHERE {
+    ?phenotype ?pPredicate ?pValue .
+    OPTIONAL {
+        ?phenotype gn:phenotypeOfPublication ?publication .
+        ?publication ?publicationTerm ?publicationValue .
+    } .
+    OPTIONAL {
+        ?phenotype gn:phenotypeOfDataset ?dataset .
+        ?dataset gn:name ?datasetFullName .
+        ?dataset gn:datasetOfInbredSet ?inbredSet .
+        ?inbredSet gn:binomialName ?inbredSetBinomialName .
+        ?inbredSet gn:inbredSetOfSpecies ?species .
+        ?species gn:displayName ?speciesName .
+    } .
+    FILTER( ?phenotype = phenotype:$name ) .
+    MINUS {
+         ?phenotype rdf:type ?pValue .
+    }
+    MINUS {
+         ?publication rdf:type ?publicationValue .
+    }
 }
 """
     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