LifeSciencesQueries/SPARQL
Appearance
SPARQL queries
Transations of queries from http://www.isb-sib.ch/~ejain/expasy4j-webng/query.html#examples into SPARQL.
# ==== Ex 1 : Names of proteins with a gene with a specific name or synonym
#
# SELECT
# ?protein, ?name
# WHERE
# [?protein rdf:type :Protein] AND
# [?protein :name ?name] AND
# [?protein :encodedBy ?gene] AND
# [?gene :name "CRB"]
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <urn:lsid:uniprot.org:ontology:>
SELECT ?protein ?name
WHERE
{ ?protein rdf:type :Protein ;
:name ?name ;
:encodedBy ?gene .
?gene :name "CRB" .
}
# ==== Ex 2 :Ranges of transmembrane regions
#
# SELECT
# ?protein, ?begin, ?end
# WHERE
# [?protein rdf:type :Protein] AND
# [?protein :annotation ?annotation] AND
# [?annotation rdf:type :Transmembrane_Annotation] AND
# [?annotation :range ?range] AND
# [?range :begin ?begin] AND -- Note: Should use MAYBE...
# [?range :end ?end]
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <urn:lsid:uniprot.org:ontology:>
SELECT ?protein ?begin ?end
WHERE
{ ?protein rdf:type :Protein ;
:annotation ?annotation .
?annotation rdf:type :Transmembrane_Annotation .
# As given
?annotation :range ?range .
?range :begin ?begin .
?range :end ?end .
# Optional
## OPTIONAL
## { ?annotation :range ?range .
## ?range :begin ?begin ;
## :end ?end .
## }
}
# ==== Ex 3 : Proteins with publications by authors with matching names
#
# SELECT
# ?protein, ?author, ?title
# WHERE
# [?protein rdf:type :Protein] AND
# [?protein :modified ?modified] AND
# [?protein :citation ?citation] AND
# [?citation :author ?author] AND
# ?author ~ "bairoch %" AND
# [?citation :title ?title]
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf
PREFIX : <urn:lsid:uniprot.org:ontology:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT
?protein ?author ?title
{
?protein rdf:type :Protein .
?protein :modified ?modified .
?protein :citation ?citation .
?citation :author ?author .
FILTER ( regex(?author, "^bairoch ", "i") ) .
?citation :title ?title
}
# ==== Ex 4 :Number of times a publication by a specific author is cited
#
# COUNT
# ?protein
# WHERE
# [?protein rdf:type :Protein] AND
# [?protein :citation ?citation] AND
# [?citation :author "Bairoch A."]
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf
# No COUNT in SPARQL
PREFIX : <urn:lsid:uniprot.org:ontology:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?protein
WHERE
{
?protein rdf:type :Protein ;
:citation [ :author "Bairoch A." ] .
}
# ==== Ex 5 :Resources that are related to proteins annotated with a specific keyword
#
# SELECT
# ?related
# WHERE
# [?protein rdf:type :Protein] AND
# [?protein :classifiedWith <urn:lsid:uniprot.org:keywords:48>] AND
# [?protein rdfs:seeAlso ?related]
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf,
# "http://www.w3.org/2000/01/rdf-schema#" AS rdfs
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <urn:lsid:uniprot.org:ontology:>
SELECT ?related
WHERE
{ ?protein rdf:type :Protein ;
:classifiedWith <urn:lsid:uniprot.org:keywords:48> ;
rdfs:seeAlso ?related .
}
# ==== Ex 6 : Genes associated with human diseases
#
# SELECT
# ?gene AS "Gene", ?name AS "Name", ?text AS "Disease"
# WHERE
# [?protein rdf:type :Protein] AND
# [?protein :gene ?gene] AND
# [?gene :name ?name] AND
# [?protein :organism taxon:9606] AND
# [?protein :annotation ?annotation] AND
# [?annotation rdf:type :Disease_Annotation] AND
# [?annotation rdfs:comment ?text]
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf,
# "http://www.w3.org/2000/01/rdf-schema#" AS rdfs,
# "urn:lsid:uniprot.org:taxonomy:" AS taxon
PREFIX : <urn:lsid:uniprot.org:ontology:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX taxon: <urn:lsid:uniprot.org:taxonomy:>
# No variable aliases
SELECT ?gene ?name ?text
{
?protein rdf:type :Protein .
?protein :gene ?gene .
?gene :name ?name .
?protein :organism <urn:lsid:uniprot.org:taxonomy:9606> .
?protein :annotation ?annotation .
?annotation rdf:type :Disease_Annotation .
?annotation rdfs:comment ?text .
}
# ==== Ex 7 : Sequences of bacterial proteins
#
# SELECT
# ?protein, ?aa
# WHERE
# [?protein rdf:type :Protein] AND
# [?protein :organism taxon:2] AND
# [?protein :sequence ?s] AND
# [?s rdf:value ?aa]
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf,
# "http://www.w3.org/2000/01/rdf-schema#" AS rdfs,
# "urn:lsid:uniprot.org:taxonomy:" AS taxon
PREFIX : <urn:lsid:uniprot.org:ontology:>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX taxon: <urn:lsid:uniprot.org:taxonomy:>
SELECT ?protein ?aa
{
?protein rdf:type :Protein .
?protein :organism <urn:lsid:uniprot.org:taxonomy:2> .
?protein :sequence ?s .
?s rdf:value ?aa
}
# ==== Ex 8 : Recently modified entries
#
# SELECT
# ?protein, ?date
# WHERE
# [?protein rdf:type :Protein] AND
# [?protein :modified ?date] AND
# ?date > "2004-08"
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <urn:lsid:uniprot.org:ontology:>
SELECT ?protein ?date
WHERE
{ ?protein rdf:type :Protein ;
:modified ?date .
# Not a date!
FILTER ( ?date > "2004-08" )
}
# ==== Ex 9 : Interactions between two specific enzymes
#
# SELECT
# ?interaction, ?p1, ?p2
# WHERE
# [?p1 rdf:type :Protein] AND
# [?p1 :enzyme ec:2.7.7.-] AND
# [?p2 rdf:type :Protein] AND
# [?p2 :enzyme ec:3.1.3.16] AND
# [?interaction rdf:type :Interaction] AND
# [?interaction :participant ?p1] AND
# [?interaction :participant ?p2]
# USING
# "urn:lsid:uniprot.org:ontology:",
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#" AS rdf,
# "http://www.w3.org/2000/01/rdf-schema#" AS rdfs,
# "urn:lsid:uniprot.org:enzymes:" AS ec
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <urn:lsid:uniprot.org:ontology:>
SELECT ?interaction ?p1 ?p2
WHERE
{ ?p1 rdf:type :Protein ;
:enzyme <urn:lsid:uniprot.org:enzymes:2.7.7.-> .
?p2 rdf:type :Protein ;
:enzyme <urn:lsid:uniprot.org:enzymes:3.1.3.16> .
?interaction rdf:type :Interaction ;
:participant ?p1 ;
:participant ?p2 .
}