Combining graphs from multiple data sources
Contents
Combining graphs from multiple data sources#
In this notebook you will be able to search for protein interactions (Uniprot), expressions in tissues (Bgee). Finally you will lear how to assemble a new graph of co-expressed gene.
!pip install rdflib
!pip install sparqlwrapper
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: rdflib in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (6.2.0)
Requirement already satisfied: pyparsing in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from rdflib) (3.0.9)
Requirement already satisfied: isodate in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from rdflib) (0.6.1)
Requirement already satisfied: setuptools in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from rdflib) (65.3.0)
Requirement already satisfied: six in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from isodate->rdflib) (1.16.0)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: sparqlwrapper in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (2.0.0)
Requirement already satisfied: rdflib>=6.1.1 in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from sparqlwrapper) (6.2.0)
Requirement already satisfied: pyparsing in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from rdflib>=6.1.1->sparqlwrapper) (3.0.9)
Requirement already satisfied: isodate in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from rdflib>=6.1.1->sparqlwrapper) (0.6.1)
Requirement already satisfied: setuptools in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from rdflib>=6.1.1->sparqlwrapper) (65.3.0)
Requirement already satisfied: six in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from isodate->rdflib>=6.1.1->sparqlwrapper) (1.16.0)
import rdflib
from SPARQLWrapper import SPARQLWrapper, JSON, TURTLE
1. Find interacting proteins with SCN5A (from Uniprot)#
By browsing http://uniprot.org, find the web page describing SCN5A_HUMAN.
2. Look at the RDF graph describing SCN5A#
You can directly access RDF https://www.uniprot.org/uniprotkb/Q14524.ttl .
By using the following graph pattern write a SPARQL query to find the proteins interacting with SCN5A.
https://www.uniprot.org/uniprotkb/Q14524.ttl
Find all PPI in which Q14524 is a participant. You can use the following graph pattern :
VALUES ?P1 {uniprot:Q14524}
?interaction up:participant ?P1 .
?interaction up:participant ?P2 .
?P1 up:mnemonic ?P1_label .
?P2 up:mnemonic ?P2_label .
FILTER (?P2 != ?P1)
uniprot_query = """
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX taxon: <http://purl.uniprot.org/taxonomy/>
PREFIX uniprot: <http://purl.uniprot.org/uniprot/>
PREFIX up:<http://purl.uniprot.org/core/>
SELECT * WHERE {
VALUES ?P1 {uniprot:Q14524}
?P1 up:mnemonic ?P1_label .
?P1 up:organism ?org .
?P1 up:interaction ?interaction .
?P2 up:interaction ?interaction .
?P2 up:mnemonic ?P2_label .
?interaction up:experiments ?nb_exp .
} limit 10
"""
sparql = SPARQLWrapper("http://sparql.uniprot.org/sparql/")
sparql.setQuery(uniprot_query)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
print(results['results']['bindings'])
list_of_genes = ["SCN5A"]
for r in results['results']['bindings']:
#print(f"{r['P1_label']['value']} <-> {r['P2_label']['value']} in {r['nb_expe']['value']} experiments.")
#list_of_genes.append(r['P2_label']['value'].split("_HUMAN")[0])
print(f"{r}")
list_of_genes
[{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '3'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/11524452-14276801'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q8N9N5'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '3'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'BANP_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/11524452-14276801'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q9Y3B6'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '3'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'EMC9_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/748366-14276801'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '3'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/748366-14276801'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '4'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/726858-10699759'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/P61328'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '4'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'FGF12_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/726858-10699759'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '16'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/351018-726858'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q13557'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '16'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'KCC2D_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/351018-726858'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/P26045'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '2'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'PTN3_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/726858-1047946'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}, {'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '2'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/726858-1047946'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}]
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '3'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/11524452-14276801'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q8N9N5'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '3'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'BANP_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/11524452-14276801'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q9Y3B6'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '3'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'EMC9_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/748366-14276801'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '3'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/748366-14276801'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '4'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/726858-10699759'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/P61328'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '4'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'FGF12_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/726858-10699759'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '16'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/351018-726858'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q13557'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '16'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'KCC2D_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/351018-726858'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/P26045'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '2'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'PTN3_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/726858-1047946'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
{'P1': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'P2': {'type': 'uri', 'value': 'http://purl.uniprot.org/uniprot/Q14524'}, 'nb_exp': {'datatype': 'http://www.w3.org/2001/XMLSchema#int', 'type': 'literal', 'value': '2'}, 'org': {'type': 'uri', 'value': 'http://purl.uniprot.org/taxonomy/9606'}, 'P2_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}, 'interaction': {'type': 'uri', 'value': 'http://purl.uniprot.org/intact/726858-1047946'}, 'P1_label': {'type': 'literal', 'value': 'SCN5A_HUMAN'}}
['SCN5A']
!pip install networkx
!pip install matplotlib
!pip install scipy
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: networkx in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (3.0)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: matplotlib in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (3.6.3)
Requirement already satisfied: contourpy>=1.0.1 in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from matplotlib) (1.0.7)
Requirement already satisfied: kiwisolver>=1.0.1 in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from matplotlib) (1.4.4)
Requirement already satisfied: pyparsing>=2.2.1 in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from matplotlib) (3.0.9)
Requirement already satisfied: fonttools>=4.22.0 in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from matplotlib) (4.38.0)
Requirement already satisfied: python-dateutil>=2.7 in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from matplotlib) (2.8.2)
Requirement already satisfied: packaging>=20.0 in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from matplotlib) (21.3)
Requirement already satisfied: cycler>=0.10 in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from matplotlib) (0.11.0)
Requirement already satisfied: numpy>=1.19 in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from matplotlib) (1.24.1)
Requirement already satisfied: pillow>=6.2.0 in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from matplotlib) (9.4.0)
Requirement already satisfied: six>=1.5 in /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: scipy in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (1.10.0)
Requirement already satisfied: numpy<1.27.0,>=1.19.5 in /shared/ifbstor1/home/tdenecker/.local/lib/python3.10/site-packages (from scipy) (1.24.1)
import networkx as nx
from matplotlib import pyplot as plt
g = nx.Graph()
for r in results['results']['bindings']:
g.add_edge(r['P1_label']['value'], r['P2_label']['value'], nbExperiments = r['nb_exp']['value'])
nx.draw(g, with_labels=True)
plt.show()

3. Post process your results get a list of gene identifiers (remove the “_HUMAN” postfix)#
you should get something like ['SCN5A', 'KCC2D', 'FGF12', 'ZMY19', 'EMC9', 'BANP', 'Q49AR9', 'TEKT4', 'PTN3']
genes = '\"'+"\" \"".join(list_of_genes)+'\"'
genes
'"SCN5A"'
4. Filter tissues in which genes are expressed (from Bgee)#
4.1. Find tissues in which SCN5A is expressed#
Bgee is a gene expression RDF dataset which integrates GTex.
Based on the following graph patterns, assemble a SPARQL query to retrieve tissues in which TEKT4 is expressed, for HUMANS (http://purl.uniprot.org/taxonomy/9606).
Anatomical entities
?anatEntity a genex:AnatomicalEntity ;
rdfs:label ?anatName .
Case insensitive matching of a string value
FILTER (?geneName = 'TEKT4')
Human organisms
?organism obo:RO_0002162 <http://purl.uniprot.org/taxonomy/9606> .
Some genes from some organisms
?seq a orth:Gene;
orth:organism ?organism ;
rdfs:label ?geneName .
Some genes expressed in some tissues
?seq genex:isExpressedIn ?anatEntity.
bgee_query = """
PREFIX orth: <http://purl.org/net/orth#>
PREFIX genex: <http://purl.org/genex#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
SELECT DISTINCT ?anatEntity ?anatName WHERE {
?anatEntity a genex:AnatomicalEntity ;
rdfs:label ?anatName .
?organism obo:RO_0002162 <http://purl.uniprot.org/taxonomy/9606> .
?seq a orth:Gene;
orth:organism ?organism ;
rdfs:label ?geneName .
?seq genex:isExpressedIn ?anatEntity.
FILTER (?geneName = 'TEKT4')
}
"""
sparql = SPARQLWrapper("http://bgee.org/sparql")
sparql.setQuery(bgee_query)
sparql.setReturnFormat(JSON)
res = sparql.query().convert()
#print(res["results"]["bindings"])
for r in res["results"]["bindings"]:
print(f"{r['anatEntity']['value']}: {r['anatName']['value']}")
http://purl.obolibrary.org/obo/UBERON_0000007: pituitary gland
http://purl.obolibrary.org/obo/UBERON_0001898: hypothalamus
http://purl.obolibrary.org/obo/UBERON_0002046: thyroid gland
http://purl.obolibrary.org/obo/UBERON_0002369: adrenal gland
http://purl.obolibrary.org/obo/UBERON_0003296: gland of diencephalon
http://purl.obolibrary.org/obo/UBERON_0000029: lymph node
http://purl.obolibrary.org/obo/UBERON_0001871: temporal lobe
http://purl.obolibrary.org/obo/UBERON_0002465: lymphoid system
http://purl.obolibrary.org/obo/UBERON_0001514: descending aorta
http://purl.obolibrary.org/obo/UBERON_0002345: descending thoracic aorta
http://purl.obolibrary.org/obo/UBERON_0003516: hindlimb blood vessel
http://purl.obolibrary.org/obo/UBERON_0007304: appendage vasculature
http://purl.obolibrary.org/obo/UBERON_0001516: abdominal aorta
http://purl.obolibrary.org/obo/CL_0000000: cell
http://purl.obolibrary.org/obo/UBERON_0000014: zone of skin
http://purl.obolibrary.org/obo/UBERON_0000020: sense organ
http://purl.obolibrary.org/obo/UBERON_0000033: head
http://purl.obolibrary.org/obo/UBERON_0000061: anatomical structure
http://purl.obolibrary.org/obo/UBERON_0000072: proximo-distal subdivision of respiratory tract
http://purl.obolibrary.org/obo/UBERON_0000079: male reproductive system
http://purl.obolibrary.org/obo/UBERON_0000082: adult mammalian kidney
http://purl.obolibrary.org/obo/UBERON_0000160: intestine
http://purl.obolibrary.org/obo/UBERON_0000165: mouth
http://purl.obolibrary.org/obo/UBERON_0000383: musculature of body
http://purl.obolibrary.org/obo/UBERON_0000465: material anatomical entity
http://purl.obolibrary.org/obo/UBERON_0000467: anatomical system
http://purl.obolibrary.org/obo/UBERON_0000468: multicellular organism
http://purl.obolibrary.org/obo/UBERON_0000473: testis
http://purl.obolibrary.org/obo/UBERON_0000474: female reproductive system
http://purl.obolibrary.org/obo/UBERON_0000475: organism subdivision
http://purl.obolibrary.org/obo/UBERON_0000915: thoracic segment of trunk
http://purl.obolibrary.org/obo/UBERON_0000916: abdomen
http://purl.obolibrary.org/obo/UBERON_0000945: stomach
http://purl.obolibrary.org/obo/UBERON_0000948: heart
http://purl.obolibrary.org/obo/UBERON_0000949: endocrine system
http://purl.obolibrary.org/obo/UBERON_0000955: brain
http://purl.obolibrary.org/obo/UBERON_0000990: reproductive system
http://purl.obolibrary.org/obo/UBERON_0000991: gonad
http://purl.obolibrary.org/obo/UBERON_0000992: ovary
http://purl.obolibrary.org/obo/UBERON_0001004: respiratory system
http://purl.obolibrary.org/obo/UBERON_0001007: digestive system
http://purl.obolibrary.org/obo/UBERON_0001008: renal system
http://purl.obolibrary.org/obo/UBERON_0001015: musculature
http://purl.obolibrary.org/obo/UBERON_0001016: nervous system
http://purl.obolibrary.org/obo/UBERON_0001017: central nervous system
http://purl.obolibrary.org/obo/UBERON_0001032: sensory system
http://purl.obolibrary.org/obo/UBERON_0001041: foregut
http://purl.obolibrary.org/obo/UBERON_0001044: saliva-secreting gland
http://purl.obolibrary.org/obo/UBERON_0001062: anatomical entity
http://purl.obolibrary.org/obo/UBERON_0001264: pancreas
http://purl.obolibrary.org/obo/UBERON_0001444: subdivision of head
http://purl.obolibrary.org/obo/UBERON_0001456: face
http://purl.obolibrary.org/obo/UBERON_0001555: digestive tract
http://purl.obolibrary.org/obo/UBERON_0001558: lower respiratory tract
http://purl.obolibrary.org/obo/UBERON_0001869: cerebral hemisphere
http://purl.obolibrary.org/obo/UBERON_0001890: forebrain
http://purl.obolibrary.org/obo/UBERON_0001893: telencephalon
http://purl.obolibrary.org/obo/UBERON_0001895: metencephalon
http://purl.obolibrary.org/obo/UBERON_0002028: hindbrain
http://purl.obolibrary.org/obo/UBERON_0002037: cerebellum
http://purl.obolibrary.org/obo/UBERON_0002048: lung
http://purl.obolibrary.org/obo/UBERON_0002075: viscus
http://purl.obolibrary.org/obo/UBERON_0002097: skin of body
http://purl.obolibrary.org/obo/UBERON_0002100: trunk
http://purl.obolibrary.org/obo/UBERON_0002106: spleen
http://purl.obolibrary.org/obo/UBERON_0002107: liver
http://purl.obolibrary.org/obo/UBERON_0002108: small intestine
http://purl.obolibrary.org/obo/UBERON_0002113: kidney
http://purl.obolibrary.org/obo/UBERON_0002193: hemolymphoid system
http://purl.obolibrary.org/obo/UBERON_0002199: integument
http://purl.obolibrary.org/obo/UBERON_0002204: musculoskeletal system
http://purl.obolibrary.org/obo/UBERON_0002365: exocrine gland
http://purl.obolibrary.org/obo/UBERON_0002368: endocrine gland
http://purl.obolibrary.org/obo/UBERON_0002385: muscle tissue
http://purl.obolibrary.org/obo/UBERON_0002390: hematopoietic system
http://purl.obolibrary.org/obo/UBERON_0002416: integumental system
http://purl.obolibrary.org/obo/UBERON_0002417: abdominal segment of trunk
http://purl.obolibrary.org/obo/UBERON_0002423: hepatobiliary system
http://purl.obolibrary.org/obo/UBERON_0002530: gland
http://purl.obolibrary.org/obo/UBERON_0002616: regional part of brain
http://purl.obolibrary.org/obo/UBERON_0003100: female organism
http://purl.obolibrary.org/obo/UBERON_0003101: male organism
http://purl.obolibrary.org/obo/UBERON_0003133: reproductive organ
http://purl.obolibrary.org/obo/UBERON_0003134: female reproductive organ
http://purl.obolibrary.org/obo/UBERON_0004121: ectoderm-derived structure
http://purl.obolibrary.org/obo/UBERON_0004535: cardiovascular system
http://purl.obolibrary.org/obo/UBERON_0005057: immune organ
http://purl.obolibrary.org/obo/UBERON_0005409: alimentary part of gastrointestinal system
http://purl.obolibrary.org/obo/UBERON_0007811: craniocervical region
http://purl.obolibrary.org/obo/UBERON_0010047: oral gland
http://purl.obolibrary.org/obo/UBERON_0010314: structure with developmental contribution from neural crest
http://purl.obolibrary.org/obo/UBERON_0013702: body proper
http://purl.obolibrary.org/obo/UBERON_0013765: digestive system element
http://purl.obolibrary.org/obo/CL_0002371: somatic cell
http://purl.obolibrary.org/obo/UBERON_0001242: intestinal mucosa
http://purl.obolibrary.org/obo/UBERON_0001262: wall of intestine
http://purl.obolibrary.org/obo/UBERON_0001894: diencephalon
http://purl.obolibrary.org/obo/UBERON_0004786: gastrointestinal system mucosa
http://purl.obolibrary.org/obo/CL_0002320: connective tissue cell
http://purl.obolibrary.org/obo/UBERON_0000004: nose
http://purl.obolibrary.org/obo/UBERON_0000411: visual cortex
http://purl.obolibrary.org/obo/UBERON_0001013: adipose tissue
http://purl.obolibrary.org/obo/UBERON_0001225: cortex of kidney
http://purl.obolibrary.org/obo/UBERON_0001383: muscle of leg
http://purl.obolibrary.org/obo/UBERON_0001557: upper respiratory tract
http://purl.obolibrary.org/obo/UBERON_0001826: nasal cavity mucosa
http://purl.obolibrary.org/obo/UBERON_0001954: Ammon's horn
http://purl.obolibrary.org/obo/UBERON_0002021: occipital lobe
http://purl.obolibrary.org/obo/UBERON_0002129: cerebellar cortex
http://purl.obolibrary.org/obo/UBERON_0002268: olfactory organ
http://purl.obolibrary.org/obo/UBERON_0002384: connective tissue
http://purl.obolibrary.org/obo/UBERON_0002421: hippocampal formation
http://purl.obolibrary.org/obo/UBERON_0002436: primary visual cortex
http://purl.obolibrary.org/obo/UBERON_0002661: superior frontal gyrus
http://purl.obolibrary.org/obo/UBERON_0003661: limb muscle
http://purl.obolibrary.org/obo/UBERON_0004252: hindlimb stylopod muscle
http://purl.obolibrary.org/obo/UBERON_0004480: musculature of limb
http://purl.obolibrary.org/obo/UBERON_0005386: olfactory segment of nasal mucosa
http://purl.obolibrary.org/obo/UBERON_0005725: olfactory system
http://purl.obolibrary.org/obo/UBERON_0007271: appendage musculature
http://purl.obolibrary.org/obo/UBERON_0009834: dorsolateral prefrontal cortex
http://purl.obolibrary.org/obo/UBERON_0010890: pelvic complex muscle
http://purl.obolibrary.org/obo/UBERON_0016540: occipital cortex
http://purl.obolibrary.org/obo/UBERON_0003343: mucosa of oral region
http://purl.obolibrary.org/obo/UBERON_0005334: oral lamina propria
http://purl.obolibrary.org/obo/UBERON_0005609: iliac artery
http://purl.obolibrary.org/obo/CL_0000081: blood cell
http://purl.obolibrary.org/obo/CL_0000094: granulocyte
http://purl.obolibrary.org/obo/UBERON_0000059: large intestine
http://purl.obolibrary.org/obo/UBERON_0001134: skeletal muscle tissue
http://purl.obolibrary.org/obo/UBERON_0001155: colon
http://purl.obolibrary.org/obo/UBERON_0001630: muscle organ
http://purl.obolibrary.org/obo/UBERON_0002036: striated muscle tissue
http://purl.obolibrary.org/obo/UBERON_0014892: skeletal muscle organ
http://purl.obolibrary.org/obo/UBERON_0018254: skeletal musculature
http://purl.obolibrary.org/obo/UBERON_0000203: pallium
http://purl.obolibrary.org/obo/UBERON_0000451: prefrontal cortex
http://purl.obolibrary.org/obo/UBERON_0000956: cerebral cortex
http://purl.obolibrary.org/obo/UBERON_0001870: frontal cortex
http://purl.obolibrary.org/obo/UBERON_0001950: neocortex
http://purl.obolibrary.org/obo/UBERON_0002020: gray matter
http://purl.obolibrary.org/obo/UBERON_0003528: brain gray matter
http://purl.obolibrary.org/obo/UBERON_0005401: cerebral hemisphere gray matter
http://purl.obolibrary.org/obo/UBERON_0016525: frontal lobe
http://purl.obolibrary.org/obo/UBERON_0008952: upper lobe of left lung
http://purl.obolibrary.org/obo/CL_0002255: stromal cell of endometrium
http://purl.obolibrary.org/obo/UBERON_0000458: endocervix
http://purl.obolibrary.org/obo/UBERON_0001119: right lobe of thyroid gland
http://purl.obolibrary.org/obo/UBERON_0001120: left lobe of thyroid gland
http://purl.obolibrary.org/obo/UBERON_0001154: vermiform appendix
http://purl.obolibrary.org/obo/UBERON_0001157: transverse colon
http://purl.obolibrary.org/obo/UBERON_0001159: sigmoid colon
http://purl.obolibrary.org/obo/UBERON_0001233: right adrenal gland
http://purl.obolibrary.org/obo/UBERON_0001234: left adrenal gland
http://purl.obolibrary.org/obo/UBERON_0001302: right uterine tube
http://purl.obolibrary.org/obo/UBERON_0001303: left uterine tube
http://purl.obolibrary.org/obo/UBERON_0001323: tibial nerve
http://purl.obolibrary.org/obo/UBERON_0001625: right coronary artery
http://purl.obolibrary.org/obo/UBERON_0001626: left coronary artery
http://purl.obolibrary.org/obo/UBERON_0002098: apex of heart
http://purl.obolibrary.org/obo/UBERON_0002118: right ovary
http://purl.obolibrary.org/obo/UBERON_0002119: left ovary
http://purl.obolibrary.org/obo/UBERON_0002250: popliteal artery
http://purl.obolibrary.org/obo/UBERON_0002810: right frontal lobe
http://purl.obolibrary.org/obo/UBERON_0004533: left testis
http://purl.obolibrary.org/obo/UBERON_0004534: right testis
http://purl.obolibrary.org/obo/UBERON_0004991: mucosa of transverse colon
http://purl.obolibrary.org/obo/UBERON_0006469: C1 segment of cervical spinal cord
http://purl.obolibrary.org/obo/UBERON_0007610: tibial artery
http://purl.obolibrary.org/obo/UBERON_0009835: anterior cingulate cortex
http://purl.obolibrary.org/obo/UBERON_0009853: body of uterus
http://purl.obolibrary.org/obo/UBERON_0012249: ectocervix
http://purl.obolibrary.org/obo/UBERON_0013473: lower esophagus
http://purl.obolibrary.org/obo/UBERON_0013540: Brodmann (1909) area 9
http://purl.obolibrary.org/obo/UBERON_0014890: right hemisphere of cerebellum
http://purl.obolibrary.org/obo/UBERON_0035805: muscle layer of sigmoid colon
http://purl.obolibrary.org/obo/UBERON_0035825: left adrenal gland cortex
http://purl.obolibrary.org/obo/UBERON_0035827: right adrenal gland cortex
http://purl.obolibrary.org/obo/UBERON_0035833: lower esophagus muscularis layer
http://purl.obolibrary.org/obo/UBERON_0035834: lower esophagus mucosa
http://purl.obolibrary.org/obo/UBERON_0035841: esophagogastric junction muscularis propria
http://purl.obolibrary.org/obo/UBERON_0001150: body of pancreas
http://purl.obolibrary.org/obo/UBERON_0001621: coronary artery
http://purl.obolibrary.org/obo/UBERON_0012489: muscle layer of colon
http://purl.obolibrary.org/obo/UBERON_0001511: skin of leg
http://purl.obolibrary.org/obo/UBERON_0001830: minor salivary gland
http://purl.obolibrary.org/obo/UBERON_0000310: breast
http://purl.obolibrary.org/obo/UBERON_0000317: colonic mucosa
http://purl.obolibrary.org/obo/UBERON_0000376: hindlimb stylopod
http://purl.obolibrary.org/obo/UBERON_0000978: leg
http://purl.obolibrary.org/obo/UBERON_0001153: caecum
http://purl.obolibrary.org/obo/UBERON_0001207: mucosa of large intestine
http://purl.obolibrary.org/obo/UBERON_0002101: limb
http://purl.obolibrary.org/obo/UBERON_0002103: hindlimb
http://purl.obolibrary.org/obo/UBERON_0009854: digestive tract diverticulum
http://purl.obolibrary.org/obo/UBERON_0000178: blood
http://purl.obolibrary.org/obo/UBERON_0000459: uterine wall
http://purl.obolibrary.org/obo/UBERON_0000993: oviduct
http://purl.obolibrary.org/obo/UBERON_0000995: uterus
http://purl.obolibrary.org/obo/UBERON_0001295: endometrium
http://purl.obolibrary.org/obo/UBERON_0001987: placenta
http://purl.obolibrary.org/obo/UBERON_0002240: spinal cord
http://purl.obolibrary.org/obo/UBERON_0004716: conceptus
http://purl.obolibrary.org/obo/UBERON_0016887: entire extraembryonic component
http://purl.obolibrary.org/obo/UBERON_0001161: body of stomach
http://purl.obolibrary.org/obo/UBERON_0000002: uterine cervix
http://purl.obolibrary.org/obo/UBERON_0000006: islet of Langerhans
http://purl.obolibrary.org/obo/UBERON_0000010: peripheral nervous system
http://purl.obolibrary.org/obo/UBERON_0000016: endocrine pancreas
http://purl.obolibrary.org/obo/UBERON_0000081: metanephros
http://purl.obolibrary.org/obo/UBERON_0000204: ventral part of telencephalon
http://purl.obolibrary.org/obo/UBERON_0000369: corpus striatum
http://purl.obolibrary.org/obo/UBERON_0000947: aorta
http://purl.obolibrary.org/obo/UBERON_0000996: vagina
http://purl.obolibrary.org/obo/UBERON_0001021: nerve
http://purl.obolibrary.org/obo/UBERON_0001043: esophagus
http://purl.obolibrary.org/obo/UBERON_0001096: wall of esophagus
http://purl.obolibrary.org/obo/UBERON_0001113: lobe of liver
http://purl.obolibrary.org/obo/UBERON_0001114: right lobe of liver
http://purl.obolibrary.org/obo/UBERON_0001118: lobe of thyroid gland
http://purl.obolibrary.org/obo/UBERON_0001135: smooth muscle tissue
http://purl.obolibrary.org/obo/UBERON_0001160: fundus of stomach
http://purl.obolibrary.org/obo/UBERON_0001167: wall of stomach
http://purl.obolibrary.org/obo/UBERON_0001168: wall of small intestine
http://purl.obolibrary.org/obo/UBERON_0001199: mucosa of stomach
http://purl.obolibrary.org/obo/UBERON_0001204: mucosa of small intestine
http://purl.obolibrary.org/obo/UBERON_0001211: Peyer's patch
http://purl.obolibrary.org/obo/UBERON_0001235: adrenal cortex
http://purl.obolibrary.org/obo/UBERON_0001255: urinary bladder
http://purl.obolibrary.org/obo/UBERON_0001296: myometrium
http://purl.obolibrary.org/obo/UBERON_0001322: sciatic nerve
http://purl.obolibrary.org/obo/UBERON_0001388: gastrocnemius
http://purl.obolibrary.org/obo/UBERON_0001416: skin of abdomen
http://purl.obolibrary.org/obo/UBERON_0001419: skin of limb
http://purl.obolibrary.org/obo/UBERON_0001496: ascending aorta
http://purl.obolibrary.org/obo/UBERON_0001515: thoracic aorta
http://purl.obolibrary.org/obo/UBERON_0001637: artery
http://purl.obolibrary.org/obo/UBERON_0001665: triceps surae
http://purl.obolibrary.org/obo/UBERON_0001813: spinal nerve plexus
http://purl.obolibrary.org/obo/UBERON_0001815: lumbosacral nerve plexus
http://purl.obolibrary.org/obo/UBERON_0001876: amygdala
http://purl.obolibrary.org/obo/UBERON_0001882: nucleus accumbens
http://purl.obolibrary.org/obo/UBERON_0001891: midbrain
http://purl.obolibrary.org/obo/UBERON_0001911: mammary gland
http://purl.obolibrary.org/obo/UBERON_0001948: regional part of spinal cord
http://purl.obolibrary.org/obo/UBERON_0001981: blood vessel
http://purl.obolibrary.org/obo/UBERON_0002038: substantia nigra
http://purl.obolibrary.org/obo/UBERON_0002049: vasculature
http://purl.obolibrary.org/obo/UBERON_0002078: right cardiac atrium
http://purl.obolibrary.org/obo/UBERON_0002081: cardiac atrium
http://purl.obolibrary.org/obo/UBERON_0002082: cardiac ventricle
http://purl.obolibrary.org/obo/UBERON_0002084: heart left ventricle
http://purl.obolibrary.org/obo/UBERON_0002110: gall bladder
http://purl.obolibrary.org/obo/UBERON_0002167: right lung
http://purl.obolibrary.org/obo/UBERON_0002168: left lung
http://purl.obolibrary.org/obo/UBERON_0002190: subcutaneous adipose tissue
http://purl.obolibrary.org/obo/UBERON_0002196: adenohypophysis
http://purl.obolibrary.org/obo/UBERON_0002201: vasculature of trunk
http://purl.obolibrary.org/obo/UBERON_0002308: nucleus of brain
http://purl.obolibrary.org/obo/UBERON_0002358: peritoneum
http://purl.obolibrary.org/obo/UBERON_0002367: prostate gland
http://purl.obolibrary.org/obo/UBERON_0002435: striatum
http://purl.obolibrary.org/obo/UBERON_0002469: esophagus mucosa
http://purl.obolibrary.org/obo/UBERON_0002743: basal forebrain
http://purl.obolibrary.org/obo/UBERON_0003027: cingulate cortex
http://purl.obolibrary.org/obo/UBERON_0003454: small intestine Peyer's patch
http://purl.obolibrary.org/obo/UBERON_0003509: arterial blood vessel
http://purl.obolibrary.org/obo/UBERON_0003513: trunk blood vessel
http://purl.obolibrary.org/obo/UBERON_0003586: trunk connective tissue
http://purl.obolibrary.org/obo/UBERON_0003697: abdominal wall
http://purl.obolibrary.org/obo/UBERON_0003729: mouth mucosa
http://purl.obolibrary.org/obo/UBERON_0003823: hindlimb zeugopod
http://purl.obolibrary.org/obo/UBERON_0003889: fallopian tube
http://purl.obolibrary.org/obo/UBERON_0004256: hindlimb zeugopod muscle
http://purl.obolibrary.org/obo/UBERON_0004537: blood vasculature
http://purl.obolibrary.org/obo/UBERON_0004572: arterial system
http://purl.obolibrary.org/obo/UBERON_0005200: thoracic mammary gland
http://purl.obolibrary.org/obo/UBERON_0005382: dorsal striatum
http://purl.obolibrary.org/obo/UBERON_0005383: caudate-putamen
http://purl.obolibrary.org/obo/UBERON_0005399: male reproductive gland
http://purl.obolibrary.org/obo/UBERON_0005906: serous sac
http://purl.obolibrary.org/obo/UBERON_0006876: vasculature of organ
http://purl.obolibrary.org/obo/UBERON_0007798: vascular system
http://purl.obolibrary.org/obo/UBERON_0008951: left lung lobe
http://purl.obolibrary.org/obo/UBERON_0009661: midbrain nucleus
http://purl.obolibrary.org/obo/UBERON_0009663: telencephalic nucleus
http://purl.obolibrary.org/obo/UBERON_0010011: collection of basal ganglia
http://purl.obolibrary.org/obo/UBERON_0010533: metanephros cortex
http://purl.obolibrary.org/obo/UBERON_0013768: great vessel of heart
http://purl.obolibrary.org/obo/UBERON_0035820: peritoneal sac
http://purl.obolibrary.org/obo/UBERON_0003498: heart blood vessel
http://purl.obolibrary.org/obo/UBERON_0003532: hindlimb skin
http://purl.obolibrary.org/obo/UBERON_0001873: caudate nucleus
http://purl.obolibrary.org/obo/UBERON_0008948: upper lobe of lung
http://purl.obolibrary.org/obo/UBERON_0001178: visceral peritoneum
http://purl.obolibrary.org/obo/UBERON_0002245: cerebellar hemisphere
http://purl.obolibrary.org/obo/UBERON_0001874: putamen
http://purl.obolibrary.org/obo/UBERON_0007808: adipose tissue of abdominal region
http://purl.obolibrary.org/obo/UBERON_0010414: omental fat pad
http://purl.obolibrary.org/obo/UBERON_0003688: omentum
http://purl.obolibrary.org/obo/UBERON_0006631: right atrium auricular region
4.2. Build a subgraph with a CONSTRUCT … WHERE query#
A “CONSTRUCT” query builds a sub-graph from a graph pattern matched in the where clause.
Structure of a “CONSTRUCT” query:
CONSTRUCT {
... sub graph pattern ...
} WHERE {
... graph pattern ...
}
Reuse the “WHERE” clause of the previous query to build a subgraph with only genex:isExpressedIn
and rdfs:label
relations.
bgee_subgraph = """
PREFIX orth: <http://purl.org/net/orth#>
PREFIX genex: <http://purl.org/genex#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX etbii: <http://etbii/>
CONSTRUCT {
?seq etbii:isTissu ?anatName .
} WHERE {
?anatEntity a genex:AnatomicalEntity ;
rdfs:label ?anatName .
?organism obo:RO_0002162 <http://purl.uniprot.org/taxonomy/9606> .
?seq a orth:Gene;
orth:organism ?organism ;
rdfs:label ?geneName .
?seq genex:isExpressedIn ?anatEntity.
FILTER (?geneName = 'TEKT4')
}
"""
sparql = SPARQLWrapper("http://bgee.org/sparql")
sparql.setQuery(bgee_subgraph)
results = sparql.query().convert()
print(len(results))
#print(results)
print(results.serialize(format="turtle"))
KG = results
301
@prefix ns2: <http://etbii/> .
<http://omabrowser.org/ontology/oma#GENE_ENSG00000163060> ns2:isTissu "Ammon's horn",
"Brodmann (1909) area 9",
"C1 segment of cervical spinal cord",
"Peyer's patch",
"abdomen",
"abdominal aorta",
"abdominal segment of trunk",
"abdominal wall",
"adenohypophysis",
"adipose tissue",
"adipose tissue of abdominal region",
"adrenal cortex",
"adrenal gland",
"adult mammalian kidney",
"alimentary part of gastrointestinal system",
"amygdala",
"anatomical entity",
"anatomical structure",
"anatomical system",
"anterior cingulate cortex",
"aorta",
"apex of heart",
"appendage musculature",
"appendage vasculature",
"arterial blood vessel",
"arterial system",
"artery",
"ascending aorta",
"basal forebrain",
"blood",
"blood cell",
"blood vasculature",
"blood vessel",
"body of pancreas",
"body of stomach",
"body of uterus",
"body proper",
"brain",
"brain gray matter",
"breast",
"caecum",
"cardiac atrium",
"cardiac ventricle",
"cardiovascular system",
"caudate nucleus",
"caudate-putamen",
"cell",
"central nervous system",
"cerebellar cortex",
"cerebellar hemisphere",
"cerebellum",
"cerebral cortex",
"cerebral hemisphere",
"cerebral hemisphere gray matter",
"cingulate cortex",
"collection of basal ganglia",
"colon",
"colonic mucosa",
"conceptus",
"connective tissue",
"connective tissue cell",
"coronary artery",
"corpus striatum",
"cortex of kidney",
"craniocervical region",
"descending aorta",
"descending thoracic aorta",
"diencephalon",
"digestive system",
"digestive system element",
"digestive tract",
"digestive tract diverticulum",
"dorsal striatum",
"dorsolateral prefrontal cortex",
"ectocervix",
"ectoderm-derived structure",
"endocervix",
"endocrine gland",
"endocrine pancreas",
"endocrine system",
"endometrium",
"entire extraembryonic component",
"esophagogastric junction muscularis propria",
"esophagus",
"esophagus mucosa",
"exocrine gland",
"face",
"fallopian tube",
"female organism",
"female reproductive organ",
"female reproductive system",
"forebrain",
"foregut",
"frontal cortex",
"frontal lobe",
"fundus of stomach",
"gall bladder",
"gastrocnemius",
"gastrointestinal system mucosa",
"gland",
"gland of diencephalon",
"gonad",
"granulocyte",
"gray matter",
"great vessel of heart",
"head",
"heart",
"heart blood vessel",
"heart left ventricle",
"hematopoietic system",
"hemolymphoid system",
"hepatobiliary system",
"hindbrain",
"hindlimb",
"hindlimb blood vessel",
"hindlimb skin",
"hindlimb stylopod",
"hindlimb stylopod muscle",
"hindlimb zeugopod",
"hindlimb zeugopod muscle",
"hippocampal formation",
"hypothalamus",
"iliac artery",
"immune organ",
"integument",
"integumental system",
"intestinal mucosa",
"intestine",
"islet of Langerhans",
"kidney",
"large intestine",
"left adrenal gland",
"left adrenal gland cortex",
"left coronary artery",
"left lobe of thyroid gland",
"left lung",
"left lung lobe",
"left ovary",
"left testis",
"left uterine tube",
"leg",
"limb",
"limb muscle",
"liver",
"lobe of liver",
"lobe of thyroid gland",
"lower esophagus",
"lower esophagus mucosa",
"lower esophagus muscularis layer",
"lower respiratory tract",
"lumbosacral nerve plexus",
"lung",
"lymph node",
"lymphoid system",
"male organism",
"male reproductive gland",
"male reproductive system",
"mammary gland",
"material anatomical entity",
"metanephros",
"metanephros cortex",
"metencephalon",
"midbrain",
"midbrain nucleus",
"minor salivary gland",
"mouth",
"mouth mucosa",
"mucosa of large intestine",
"mucosa of oral region",
"mucosa of small intestine",
"mucosa of stomach",
"mucosa of transverse colon",
"multicellular organism",
"muscle layer of colon",
"muscle layer of sigmoid colon",
"muscle of leg",
"muscle organ",
"muscle tissue",
"musculature",
"musculature of body",
"musculature of limb",
"musculoskeletal system",
"myometrium",
"nasal cavity mucosa",
"neocortex",
"nerve",
"nervous system",
"nose",
"nucleus accumbens",
"nucleus of brain",
"occipital cortex",
"occipital lobe",
"olfactory organ",
"olfactory segment of nasal mucosa",
"olfactory system",
"omental fat pad",
"omentum",
"oral gland",
"oral lamina propria",
"organism subdivision",
"ovary",
"oviduct",
"pallium",
"pancreas",
"pelvic complex muscle",
"peripheral nervous system",
"peritoneal sac",
"peritoneum",
"pituitary gland",
"placenta",
"popliteal artery",
"prefrontal cortex",
"primary visual cortex",
"prostate gland",
"proximo-distal subdivision of respiratory tract",
"putamen",
"regional part of brain",
"regional part of spinal cord",
"renal system",
"reproductive organ",
"reproductive system",
"respiratory system",
"right adrenal gland",
"right adrenal gland cortex",
"right atrium auricular region",
"right cardiac atrium",
"right coronary artery",
"right frontal lobe",
"right hemisphere of cerebellum",
"right lobe of liver",
"right lobe of thyroid gland",
"right lung",
"right ovary",
"right testis",
"right uterine tube",
"saliva-secreting gland",
"sciatic nerve",
"sense organ",
"sensory system",
"serous sac",
"sigmoid colon",
"skeletal muscle organ",
"skeletal muscle tissue",
"skeletal musculature",
"skin of abdomen",
"skin of body",
"skin of leg",
"skin of limb",
"small intestine",
"small intestine Peyer's patch",
"smooth muscle tissue",
"somatic cell",
"spinal cord",
"spinal nerve plexus",
"spleen",
"stomach",
"striated muscle tissue",
"striatum",
"stromal cell of endometrium",
"structure with developmental contribution from neural crest",
"subcutaneous adipose tissue",
"subdivision of head",
"substantia nigra",
"superior frontal gyrus",
"telencephalic nucleus",
"telencephalon",
"temporal lobe",
"testis",
"thoracic aorta",
"thoracic mammary gland",
"thoracic segment of trunk",
"thyroid gland",
"tibial artery",
"tibial nerve",
"transverse colon",
"triceps surae",
"trunk",
"trunk blood vessel",
"trunk connective tissue",
"upper lobe of left lung",
"upper lobe of lung",
"upper respiratory tract",
"urinary bladder",
"uterine cervix",
"uterine wall",
"uterus",
"vagina",
"vascular system",
"vasculature",
"vasculature of organ",
"vasculature of trunk",
"ventral part of telencephalon",
"vermiform appendix",
"visceral peritoneum",
"viscus",
"visual cortex",
"wall of esophagus",
"wall of intestine",
"wall of small intestine",
"wall of stomach",
"zone of skin" .
Now you can use a VALUES clause to inject the results of the previous query VALUES ?x { v1 v2 v3 ... vN }
in this new query.
Modify the query to inject "SCN5A" "KCC2D" "FGF12" "ZMY19" "EMC9" "BANP" "Q49AR9" "TEKT4" "PTN3"
as gene of interest.
bgee_subgraph = """
PREFIX orth: <http://purl.org/net/orth#>
PREFIX genex: <http://purl.org/genex#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
CONSTRUCT {
?seq genex:isExpressedIn ?anatEntity ;
rdfs:label ?geneName .
} WHERE {
VALUE(?g_label {"""+genes+"""}) .
?anatEntity a genex:AnatomicalEntity ;
rdfs:label ?anatName .
?organism obo:RO_0002162 <http://purl.uniprot.org/taxonomy/9606> .
?seq a orth:Gene;
orth:organism ?organism ;
rdfs:label ?geneName .
?seq genex:isExpressedIn ?anatEntity.
FILTER (regex(?anatEntity, "CL_"))
}
"""
sparql = SPARQLWrapper("http://bgee.org/sparql")
sparql.setQuery(bgee_subgraph)
results = sparql.query().convert()
print(len(results))
#print(results)
print(results.serialize(format="turtle"))
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
File ~/.local/lib/python3.10/site-packages/SPARQLWrapper/Wrapper.py:926, in SPARQLWrapper._query(self)
925 else:
--> 926 response = urlopener(request)
927 return response, self.returnFormat
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
215 opener = _opener
--> 216 return opener.open(url, data, timeout)
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:525, in OpenerDirector.open(self, fullurl, data, timeout)
524 meth = getattr(processor, meth_name)
--> 525 response = meth(req, response)
527 return response
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:634, in HTTPErrorProcessor.http_response(self, request, response)
633 if not (200 <= code < 300):
--> 634 response = self.parent.error(
635 'http', request, response, code, msg, hdrs)
637 return response
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:557, in OpenerDirector.error(self, proto, *args)
556 args = (dict, proto, meth_name) + args
--> 557 result = self._call_chain(*args)
558 if result:
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
495 func = getattr(handler, meth_name)
--> 496 result = func(*args)
497 if result is not None:
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:749, in HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
747 fp.close()
--> 749 return self.parent.open(new, timeout=req.timeout)
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:525, in OpenerDirector.open(self, fullurl, data, timeout)
524 meth = getattr(processor, meth_name)
--> 525 response = meth(req, response)
527 return response
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:634, in HTTPErrorProcessor.http_response(self, request, response)
633 if not (200 <= code < 300):
--> 634 response = self.parent.error(
635 'http', request, response, code, msg, hdrs)
637 return response
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:563, in OpenerDirector.error(self, proto, *args)
562 args = (dict, 'default', 'http_error_default') + orig_args
--> 563 return self._call_chain(*args)
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
495 func = getattr(handler, meth_name)
--> 496 result = func(*args)
497 if result is not None:
File /shared/ifbstor1/software/miniconda/envs/jupyter-book-0.13.1/lib/python3.10/urllib/request.py:643, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
642 def http_error_default(self, req, fp, code, msg, hdrs):
--> 643 raise HTTPError(req.full_url, code, msg, hdrs, fp)
HTTPError: HTTP Error 400: Bad Request
During handling of the above exception, another exception occurred:
QueryBadFormed Traceback (most recent call last)
Cell In[9], line 25
23 sparql = SPARQLWrapper("http://bgee.org/sparql")
24 sparql.setQuery(bgee_subgraph)
---> 25 results = sparql.query().convert()
26 print(len(results))
27 #print(results)
File ~/.local/lib/python3.10/site-packages/SPARQLWrapper/Wrapper.py:960, in SPARQLWrapper.query(self)
942 def query(self) -> "QueryResult":
943 """
944 Execute the query.
945 Exceptions can be raised if either the URI is wrong or the HTTP sends back an error (this is also the
(...)
958 :rtype: :class:`QueryResult` instance
959 """
--> 960 return QueryResult(self._query())
File ~/.local/lib/python3.10/site-packages/SPARQLWrapper/Wrapper.py:930, in SPARQLWrapper._query(self)
928 except urllib.error.HTTPError as e:
929 if e.code == 400:
--> 930 raise QueryBadFormed(e.read())
931 elif e.code == 404:
932 raise EndPointNotFound(e.read())
QueryBadFormed: QueryBadFormed: A bad request has been sent to the endpoint: probably the SPARQL query is badly formed.
Response:
b'Virtuoso 37000 Error SP030: SPARQL compiler, line 13: syntax error at \'VALUE\' before \'(\'\n\nSPARQL query:\ndefine sql:big-data-const 0 \n#output-format:application/sparql-results+xml\n\nPREFIX orth: <http://purl.org/net/orth#>\nPREFIX genex: <http://purl.org/genex#>\nPREFIX obo: <http://purl.obolibrary.org/obo/>\n\nCONSTRUCT {\n ?seq genex:isExpressedIn ?anatEntity ;\n rdfs:label ?geneName .\n\n} WHERE {\n VALUE(?g_label {"SCN5A"}) .\n\n ?anatEntity a genex:AnatomicalEntity ;\n rdfs:label ?anatName .\n ?organism obo:RO_0002162 <http://purl.uniprot.org/taxonomy/9606> . \n ?seq a orth:Gene;\n orth:organism ?organism ;\n rdfs:label ?geneName .\n ?seq genex:isExpressedIn ?anatEntity.\n FILTER (regex(?anatEntity, "CL_"))\n}\n'
5. Build a network of genes that are co-expressed in the same tissue#
The result of a “CONSTRUCT” is a graph object. You can now write and execute a CONSTRUCT query on this graph to create new coExpressedWith
between genes.
q2 = """
PREFIX genex: <http://purl.org/genex#>
PREFIX etbii:<http://etbii.fr/ontology/>
CONSTRUCT {
?gene1 etbii:coExpressedWith ?gene2 .
} WHERE {
gene1 genex:isExpressedIN ?tissue .
gene2 genex:isExpressedIN ?tissue .
FILTER(gene1 != gene2)
}
"""
coExNet = KG.query(q2)
print(coExNet.serialize(format="turtle").decode())