aboutsummaryrefslogtreecommitdiff
path: root/gn3/db/rdf.py
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-06-15 15:40:58 +0300
committerBonfaceKilz2023-06-15 21:27:59 +0300
commit9193597f12631bcf33ce768f2842132bd22a41c3 (patch)
tree50d3d2a66bf82f955d2d997d7bce9cf07d41074c /gn3/db/rdf.py
parentc5b64bd814937c96ef4e7c4aa027fcb03d0d33c2 (diff)
downloadgenenetwork3-9193597f12631bcf33ce768f2842132bd22a41c3.tar.gz
Fetch genotypes from virtuoso
* gn3/api/metadata.py: Import get_genotype_metadata. (genotype): 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/rdf.py')
-rw-r--r--gn3/db/rdf.py43
1 files changed, 43 insertions, 0 deletions
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