SPARQL example query
34: Find the co-occurence count of Topological Domain comment text in UniProtKB entries
SELECT ?comment1 ?comment2 (COUNT(?comment1) AS ?count1) WHERE { ?protein a up:Protein ; up:annotation ?annotation1 , ?annotation2 . ?annotation1 rdf:type up:Topological_Domain_Annotation ; rdfs:comment ?rawComment1 . ?annotation2 rdf:type up:Topological_Domain_Annotation ; rdfs:comment ?rawComment2 . BIND(IF(contains(?rawComment1, ';'), STRBEFORE(?rawComment1,';'), ?rawComment1) AS ?comment1) BIND(IF(contains(?rawComment2, ';'), STRBEFORE(?rawComment2,';'), ?rawComment2) AS ?comment2) FILTER(?annotation1 != ?annotation2) } GROUP BY ?comment1 ?comment2 ORDER BY DESC(COUNT(?comment1))Use34: Find the co-occurence count of Topological Domain comment text in UniProtKB entries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?comment1 ?comment2 (COUNT(?comment1) AS ?count1) WHERE { ?protein a up:Protein ; up:annotation ?annotation1 , ?annotation2 . ?annotation1 rdf:type up:Topological_Domain_Annotation ; rdfs:comment ?rawComment1 . ?annotation2 rdf:type up:Topological_Domain_Annotation ; rdfs:comment ?rawComment2 . BIND(IF(contains(?rawComment1, ';'), STRBEFORE(?rawComment1,';'), ?rawComment1) AS ?comment1) BIND(IF(contains(?rawComment2, ';'), STRBEFORE(?rawComment2,';'), ?rawComment2) AS ?comment2) FILTER(?annotation1 != ?annotation2) } GROUP BY ?comment1 ?comment2 ORDER BY DESC(COUNT(?comment1))Use35: Find the similar proteins for UniProtKB entry P05067 sorted by UniRef cluster identity
SELECT ?similar ?identity FROM <http://sparql.uniprot.org/uniref> FROM <http://sparql.uniprot.org/uniprot> WHERE { BIND (uniprotkb:P05607 AS ?protein) ?cluster up:member ?member ; up:member/up:sequenceFor ?protein; up:identity ?identity . ?member up:sequenceFor ?similar . FILTER(!sameTerm(?similar, ?protein)) } ORDER BY DESC(?identity)Use35: Find the similar proteins for UniProtKB entry P05067 sorted by UniRef cluster identity
PREFIX uniprotkb: <http://purl.uniprot.org/uniprot/> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?similar ?identity FROM <http://sparql.uniprot.org/uniref> FROM <http://sparql.uniprot.org/uniprot> WHERE { BIND (uniprotkb:P05607 AS ?protein) ?cluster up:member ?member ; up:member/up:sequenceFor ?protein; up:identity ?identity . ?member up:sequenceFor ?similar . FILTER(!sameTerm(?similar, ?protein)) } ORDER BY DESC(?identity)Use36: Find the orthologous proteins for UniProtKB entry P05067 using the OrthoDB database
SELECT ?protein ?orthoGroup ?scientificName ?functionComment ?prefferedGeneName ((STRLEN(?value) - ?medianLength) as ?deviationFromMedianLength) WHERE { uniprotkb:P05067 a up:Protein ; up:organism/up:scientificName ?scientificName ; rdfs:seeAlso ?orthoGroup ; up:encodedBy/skos:prefLabel ?prefferedGeneName ; up:sequence/rdf:value ?value . OPTIONAL { ?protein up:annotation ?functionAnnotation . ?functionAnnotation a up:Function_Annotation ; rdfs:comment ?functionComment . } SERVICE<https://sparql.orthodb.org/sparql>{ ?orthoGroup orthodb:ogMedianProteinLength ?medianLength . ?orthoGroup orthodb:hasMember ?xref . ?xref orthodb:xref/orthodb:xrefResource uniprotkb:P05067 . } }Use36: Find the orthologous proteins for UniProtKB entry P05067 using the OrthoDB database
PREFIX orthodb: <http://purl.orthodb.org/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX uniprotkb: <http://purl.uniprot.org/uniprot/> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?protein ?orthoGroup ?scientificName ?functionComment ?prefferedGeneName ((STRLEN(?value) - ?medianLength) as ?deviationFromMedianLength) WHERE { uniprotkb:P05067 a up:Protein ; up:organism/up:scientificName ?scientificName ; rdfs:seeAlso ?orthoGroup ; up:encodedBy/skos:prefLabel ?prefferedGeneName ; up:sequence/rdf:value ?value . OPTIONAL { ?protein up:annotation ?functionAnnotation . ?functionAnnotation a up:Function_Annotation ; rdfs:comment ?functionComment . } SERVICE <https://sparql.orthodb.org/sparql>{ ?orthoGroup orthodb:ogMedianProteinLength ?medianLength . ?orthoGroup orthodb:hasMember ?xref . ?xref orthodb:xref/orthodb:xrefResource uniprotkb:P05067 . } }Use37: Find the human protein which contains an Epitope VSTQ, where T is a phosporylated threonine
SELECT ?protein ?comment ?begin ?end WHERE { ?protein a up:Protein ; up:organism taxon:9606 ; up:sequence ?sequence ; up:annotation ?annotation . ?annotation a up:Modified_Residue_Annotation ; rdfs:comment ?comment ; up:range ?range . ?range faldo:begin [ faldo:position ?begin ; faldo:reference ?sequence ] ; faldo:end [ faldo:position ?end ; faldo:reference ?sequence ] . ?sequence rdf:value ?aaSequence . FILTER (SUBSTR(?aaSequence, ?begin -2 , 4) = "VSTQ") FILTER (CONTAINS(?comment, "Phosphothreonine")) }Use37: Find the human protein which contains an Epitope VSTQ, where T is a phosporylated threonine
PREFIX faldo: <http://biohackathon.org/resource/faldo#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX taxon: <http://purl.uniprot.org/taxonomy/> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?protein ?comment ?begin ?end WHERE { ?protein a up:Protein ; up:organism taxon:9606 ; up:sequence ?sequence ; up:annotation ?annotation . ?annotation a up:Modified_Residue_Annotation ; rdfs:comment ?comment ; up:range ?range . ?range faldo:begin [ faldo:position ?begin ; faldo:reference ?sequence ] ; faldo:end [ faldo:position ?end ; faldo:reference ?sequence ] . ?sequence rdf:value ?aaSequence . FILTER (SUBSTR(?aaSequence, ?begin -2 , 4) = "VSTQ") FILTER (CONTAINS(?comment, "Phosphothreonine")) }Use38: For the human entry P05067 (Amyloid-beta precursor protein) find the gene start ends in WikiData
SELECT ?protein ?begin ?end ?chromosome ?assembly WHERE { { BIND(uniprotkb:P05067 AS ?proteinIRI) BIND (SUBSTR(STR(?proteinIRI), STRLEN(STR(uniprotkb:))+1) AS ?protein) } SERVICE <https://query.wikidata.org/sparql> { ?wp wdt:P352 ?protein ; wdt:P702 ?wg . ?wg p:P644 ?wgss . ?wgss ps:P644 ?begin ; pq:P1057/wdt:P1813 ?chromosome ; pq:P659/rdfs:label ?assembly . ?wg p:P645 ?wgse . ?wgse ps:P645 ?end ; pq:P1057/wdt:P1813 ?chromosome ; pq:P659/rdfs:label ?assembly . FILTER(lang(?assembly) = "en") } }Use38: For the human entry P05067 (Amyloid-beta precursor protein) find the gene start ends in WikiData
PREFIX p: <http://www.wikidata.org/prop/> PREFIX pq: <http://www.wikidata.org/prop/qualifier/> PREFIX ps: <http://www.wikidata.org/prop/statement/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX uniprotkb: <http://purl.uniprot.org/uniprot/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT ?protein ?begin ?end ?chromosome ?assembly WHERE { { BIND(uniprotkb:P05067 AS ?proteinIRI) BIND (SUBSTR(STR(?proteinIRI), STRLEN(STR(uniprotkb:))+1) AS ?protein) } SERVICE <https://query.wikidata.org/sparql> { ?wp wdt:P352 ?protein ; wdt:P702 ?wg . ?wg p:P644 ?wgss . ?wgss ps:P644 ?begin ; pq:P1057/wdt:P1813 ?chromosome ; pq:P659/rdfs:label ?assembly . ?wg p:P645 ?wgse . ?wgse ps:P645 ?end ; pq:P1057/wdt:P1813 ?chromosome ; pq:P659/rdfs:label ?assembly . FILTER(lang(?assembly) = "en") } }Use39: Retrieve entries and Catalytic activities in the reviewed (Swiss-Prot) section that have experimental evidences,
SELECT ?protein ?rhea WHERE { # ECO 269 is experimental evidence BIND (<http://purl.obolibrary.org/obo/ECO_0000269> as ?evidence) GRAPH <http://sparql.uniprot.org/uniprot> { ?protein up:reviewed true ; up:annotation ?a ; up:attribution ?attribution . ?a a up:Catalytic_Activity_Annotation ; up:catalyticActivity ?ca . ?ca up:catalyzedReaction ?rhea . [] rdf:subject ?a ; rdf:predicate up:catalyticActivity ; rdf:object ?ca ; up:attribution ?attribution . ?attribution up:evidence ?evidence . } }Use39: Retrieve entries and Catalytic activities in the reviewed (Swiss-Prot) section that have experimental evidences,
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?protein ?rhea WHERE { # ECO 269 is experimental evidence BIND (<http://purl.obolibrary.org/obo/ECO_0000269> as ?evidence) GRAPH <http://sparql.uniprot.org/uniprot> { ?protein up:reviewed true ; up:annotation ?a ; up:attribution ?attribution . ?a a up:Catalytic_Activity_Annotation ; up:catalyticActivity ?ca . ?ca up:catalyzedReaction ?rhea . [] rdf:subject ?a ; rdf:predicate up:catalyticActivity ; rdf:object ?ca ; up:attribution ?attribution . ?attribution up:evidence ?evidence . } }Use40: Retrieve human enzymes that metabolize sphingolipids and are annotated in ChEMBL
SELECT DISTINCT ?protein ?chemblEntry WHERE { SERVICE <https://sparql.rhea-db.org/sparql> { ?rhea rdfs:subClassOf rh:Reaction ; rh:side/rh:contains/rh:compound/rh:chebi/rdfs:subClassOf+ CHEBI:26739 . } ?ca up:catalyzedReaction ?rhea . ?protein up:annotation/up:catalyticActivity ?ca ; up:organism taxon:9606 ; rdfs:seeAlso ?chemblEntry . ?chemblEntry up:database <http://purl.uniprot.org/database/ChEMBL> . }Use40: Retrieve human enzymes that metabolize sphingolipids and are annotated in ChEMBL
PREFIX CHEBI: <http://purl.obolibrary.org/obo/CHEBI_> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh: <http://rdf.rhea-db.org/> PREFIX taxon: <http://purl.uniprot.org/taxonomy/> PREFIX up: <http://purl.uniprot.org/core/> SELECT DISTINCT ?protein ?chemblEntry WHERE { SERVICE <https://sparql.rhea-db.org/sparql> { ?rhea rdfs:subClassOf rh:Reaction ; rh:side/rh:contains/rh:compound/rh:chebi/rdfs:subClassOf+ CHEBI:26739 . } ?ca up:catalyzedReaction ?rhea . ?protein up:annotation/up:catalyticActivity ?ca ; up:organism taxon:9606 ; rdfs:seeAlso ?chemblEntry . ?chemblEntry up:database <http://purl.uniprot.org/database/ChEMBL> . }Use41: Retrieve entries with sequences that are composed of fragments
SELECT DISTINCT ?protein WHERE { ?protein a up:Protein ; up:sequence ?sequence . MINUS { ?sequence up:fragment [] } }Use41: Retrieve entries with sequences that are composed of fragments
PREFIX up: <http://purl.uniprot.org/core/> SELECT DISTINCT ?protein WHERE { ?protein a up:Protein ; up:sequence ?sequence . MINUS { ?sequence up:fragment [] } }Use42: Connect patents cited in UniProtKB with those in the patent database at EPO via publication number.
SELECT ?citation ?patent ?application ?applicationNo WHERE { ?citation a up:Patent_Citation ; skos:exactMatch ?patent . FILTER(CONTAINS(STR(?patent), 'EP')) BIND(SUBSTR(STR(?patent), 35) AS ?applicationNo) SERVICE<https://data.epo.org/linked-data/query>{ ?application patent:publicationNumber ?applicationNo } }Use42: Connect patents cited in UniProtKB with those in the patent database at EPO via publication number.
PREFIX patent: <http://data.epo.org/linked-data/def/patent/> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?citation ?patent ?application ?applicationNo WHERE { ?citation a up:Patent_Citation ; skos:exactMatch ?patent . FILTER(CONTAINS(STR(?patent), 'EP')) BIND(SUBSTR(STR(?patent), 35) AS ?applicationNo) SERVICE <https://data.epo.org/linked-data/query>{ ?application patent:publicationNumber ?applicationNo } }Use43: Connect patents cited in UniProtKB with those in the patent database at EPO via publication number, whose grant date is more than twenty years in the past.
SELECT ?grantDate ?patent ?application ?applicationNo WHERE { ?citation a up:Patent_Citation ; skos:exactMatch ?patent . BIND(SUBSTR(STR(?patent), 35) AS ?applicationNo) BIND(SUBSTR(STR(?patent), 33, 2) AS ?countryCode) SERVICE<https://data.epo.org/linked-data/query>{ ?publication patent:publicationNumber ?applicationNo ; patent:application ?application . ?application patent:grantDate ?grantDate . } BIND((year(now()) - 20) AS ?thisYearMinusTwenty) BIND(year(?grantDate) AS ?grantYear) FILTER(?grantYear < ?thisYearMinusTwenty) } ORDER BY ?grantYearUse43: Connect patents cited in UniProtKB with those in the patent database at EPO via publication number, whose grant date is more than twenty years in the past.
PREFIX patent: <http://data.epo.org/linked-data/def/patent/> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?grantDate ?patent ?application ?applicationNo WHERE { ?citation a up:Patent_Citation ; skos:exactMatch ?patent . BIND(SUBSTR(STR(?patent), 35) AS ?applicationNo) BIND(SUBSTR(STR(?patent), 33, 2) AS ?countryCode) SERVICE <https://data.epo.org/linked-data/query>{ ?publication patent:publicationNumber ?applicationNo ; patent:application ?application . ?application patent:grantDate ?grantDate . } BIND((year(now()) - 20) AS ?thisYearMinusTwenty) BIND(year(?grantDate) AS ?grantYear) FILTER(?grantYear < ?thisYearMinusTwenty) } ORDER BY ?grantYearUse44: Find the Rhea and Interpro combinations in UniProtKB entries.
SELECT ?interpro ?rhea FROM <http://sparql.uniprot.org/uniprot> WHERE { ?protein up:reviewed true . ?protein up:annotation ?annotation . ?annotation up:catalyticActivity ?rhea . ?protein rdfs:seeAlso ?interpro . ?interpro up:database <http://purl.uniprot.org/database/InterPro> . } ORDER BY ?rheaUse44: Find the Rhea and Interpro combinations in UniProtKB entries.
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?interpro ?rhea FROM <http://sparql.uniprot.org/uniprot> WHERE { ?protein up:reviewed true . ?protein up:annotation ?annotation . ?annotation up:catalyticActivity ?rhea . ?protein rdfs:seeAlso ?interpro . ?interpro up:database <http://purl.uniprot.org/database/InterPro> . } ORDER BY ?rheaUse45: Retrieve drugs that target human enzymes involved in sterol metabolism (federated query with WikiData and Rhea).
SELECT DISTINCT ?protein ?proteinFullName ?wikiChemical ?wikiChemicalLabel ?medicalConditionTreatedLabel WHERE { # ChEBI: retrieve members of the ChEBI class ChEBI:15889 (sterol) # Rhea: retrieve the reactions involving these ChEBI as participants SERVICE <https://sparql.rhea-db.org/sparql> { ?reaction rdfs:subClassOf rh:Reaction ; rh:status rh:Approved ; rh:side ?reactionSide . ?reactionSide rh:contains ?participant . ?participant rh:compound ?compound { ?compound rh:chebi ?chebi . ?chebi (rdfs:subClassOf)+ CHEBI:15889 } UNION { ?compound rh:chebi ?chebi . ?chebi2 rdfs:subClassOf ?chebiRestriction . ?chebiRestriction a owl:Restriction ; owl:onProperty chebihash:has_major_microspecies_at_pH_7_3 ; owl:someValuesFrom ?chebi . ?chebi2 (rdfs:subClassOf)+ CHEBI:15889 } } # UniProt: retrieve the human (taxid:9606) enzymes catalyzing these Rhea reactions ?ca up:catalyzedReaction ?reaction . ?a up:catalyticActivity ?ca . ?proteinIRI up:annotation ?a ; up:organism taxon:9606 ; up:recommendedName ?proteinRecName . ?proteinRecName up:fullName ?proteinFullName . # Find drugs in wikidata that interact with the UniProt Proteins BIND (SUBSTR(STR(?proteinIRI), STRLEN(STR(uniprotkb:))+1) AS ?protein) SERVICE<https://query.wikidata.org/sparql> { ?wp wdt:P352 ?protein . ?wikiChemical wdt:P129 ?wp . # Physically interacts with ?wikiChemical rdfs:label ?wikiChemicalLabel . ?wikiChemical wdt:P2175 ?wmc . # Medical conndition treated ?wmc rdfs:label ?medicalConditionTreatedLabel . FILTER(lang(?medicalConditionTreatedLabel) = 'en') FILTER(lang(?wikiChemicalLabel) = 'en') } }Use45: Retrieve drugs that target human enzymes involved in sterol metabolism (federated query with WikiData and Rhea).
PREFIX CHEBI: <http://purl.obolibrary.org/obo/CHEBI_> PREFIX chebihash: <http://purl.obolibrary.org/obo/chebi#> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rh: <http://rdf.rhea-db.org/> PREFIX taxon: <http://purl.uniprot.org/taxonomy/> PREFIX uniprotkb: <http://purl.uniprot.org/uniprot/> PREFIX up: <http://purl.uniprot.org/core/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT DISTINCT ?protein ?proteinFullName ?wikiChemical ?wikiChemicalLabel ?medicalConditionTreatedLabel WHERE { # ChEBI: retrieve members of the ChEBI class ChEBI:15889 (sterol) # Rhea: retrieve the reactions involving these ChEBI as participants SERVICE <https://sparql.rhea-db.org/sparql> { ?reaction rdfs:subClassOf rh:Reaction ; rh:status rh:Approved ; rh:side ?reactionSide . ?reactionSide rh:contains ?participant . ?participant rh:compound ?compound { ?compound rh:chebi ?chebi . ?chebi (rdfs:subClassOf)+ CHEBI:15889 } UNION { ?compound rh:chebi ?chebi . ?chebi2 rdfs:subClassOf ?chebiRestriction . ?chebiRestriction a owl:Restriction ; owl:onProperty chebihash:has_major_microspecies_at_pH_7_3 ; owl:someValuesFrom ?chebi . ?chebi2 (rdfs:subClassOf)+ CHEBI:15889 } } # UniProt: retrieve the human (taxid:9606) enzymes catalyzing these Rhea reactions ?ca up:catalyzedReaction ?reaction . ?a up:catalyticActivity ?ca . ?proteinIRI up:annotation ?a ; up:organism taxon:9606 ; up:recommendedName ?proteinRecName . ?proteinRecName up:fullName ?proteinFullName . # Find drugs in wikidata that interact with the UniProt Proteins BIND (SUBSTR(STR(?proteinIRI), STRLEN(STR(uniprotkb:))+1) AS ?protein) SERVICE <https://query.wikidata.org/sparql> { ?wp wdt:P352 ?protein . ?wikiChemical wdt:P129 ?wp . # Physically interacts with ?wikiChemical rdfs:label ?wikiChemicalLabel . ?wikiChemical wdt:P2175 ?wmc . # Medical conndition treated ?wmc rdfs:label ?medicalConditionTreatedLabel . FILTER(lang(?medicalConditionTreatedLabel) = 'en') FILTER(lang(?wikiChemicalLabel) = 'en') } }Use46: Retrieve images of 'Anas' (Ducks) from the European Environmental Agency databases (federated query).
SELECT ?taxon ?ncbiTaxid ?eunisTaxon ?eunisName ?image WHERE { GRAPH <http://sparql.uniprot.org/taxonomy> { ?taxon a up:Taxon . # Taxon subclasses are materialized, do not use rdfs:subClassOf+ ?taxon rdfs:subClassOf taxon:8835 . BIND(strafter(str(?taxon), 'onomy/') AS ?ncbiTaxid) } SERVICE <https://semantic.eea.europa.eu/sparql> { ?eunisTaxon a eunisSpecies:SpeciesSynonym ; eunisSpecies:binomialName ?eunisName ; eunisSpecies:sameSpeciesNCBI ?ncbiTaxid ; <http://xmlns.com/foaf/0.1/depiction> ?image . } }Use46: Retrieve images of 'Anas' (Ducks) from the European Environmental Agency databases (federated query).
PREFIX eunisSpecies: <http://eunis.eea.europa.eu/rdf/species-schema.rdf#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX taxon: <http://purl.uniprot.org/taxonomy/> PREFIX up: <http://purl.uniprot.org/core/> SELECT ?taxon ?ncbiTaxid ?eunisTaxon ?eunisName ?image WHERE { GRAPH <http://sparql.uniprot.org/taxonomy> { ?taxon a up:Taxon . # Taxon subclasses are materialized, do not use rdfs:subClassOf+ ?taxon rdfs:subClassOf taxon:8835 . BIND(strafter(str(?taxon), 'onomy/') AS ?ncbiTaxid) } SERVICE <https://semantic.eea.europa.eu/sparql> { ?eunisTaxon a eunisSpecies:SpeciesSynonym ; eunisSpecies:binomialName ?eunisName ; eunisSpecies:sameSpeciesNCBI ?ncbiTaxid ; <http://xmlns.com/foaf/0.1/depiction> ?image . } }Use