very interesting Jerven, thanks ! I need to learn more about the SPARQL grammar.
Is there a public SPARQL end point where I query if a particular organism is a plant, animal, or virus? The input I have is an taxonomy identifer, e.g. http://bio2rdf.org/taxonomy:9606, and I want to get the superclass, classification, or so, that tells me this falls in the Animal kingdom.
Technically, this is done by using a reasoning engine, e.g. as outlined in this question. But want to mash up things, and leave a public server in control of updating the end point content, and use federated SPARQL instead of caching the data myself.
The kind of SPARQL I like to fire is:
SELECT * WHERE {
tax:9606 foo:isA ?kingdom .
?kingdom rdf:type bar:Kingdom .
}
3 answers
Of course there is no animal kingdom in the NCBI/UniProt taxonomy so I replaced that with metazoa. But the uniprot beta sparql endpoint can be used like this.
PREFIX up:<http://purl.uniprot.org/core/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX taxon:<http://purl.uniprot.org/taxonomy/>
SELECT ?input ?kingdom ?name
FROM <http://purl.uniprot.org/taxonomy/>
WHERE
{
?kingdom a up:Taxon .
?kingdom up:scientificName ?name.
{ ?kingdom up:rank up:Kingdom } UNION {?kingdom up:rank up:Superkingdom}
BIND (taxon:9606 AS ?input)
?input rdfs:subClassOf+ ?kingdom .
}
This query will tell you exactly the corresponding kingdom and super kingdoms that your ncbi tax id corresponds to.
or this
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX taxon:<http://purl.uniprot.org/taxonomy/>
SELECT ?input ?isPlant ?isMetazoa ?isVirus
FROM <http://purl.uniprot.org/taxonomy/>
WHERE
{
BIND(taxon:9606 AS ?input)
{
?input rdfs:subClassOf+ taxon:33090 . #viridiplanae
BIND(true AS ?isPlant)
} UNION {
?input rdfs:subClassOf+ taxon:33208 . #metazoa
BIND(true AS ?isMetazoal)
} UNION {
?input rdfs:subClassOf+ taxon:10239 . #viruses
BIND(true AS ?isVirus)
}
}
Once we adapt to the latest sparql1.1 draft you can ask for a multiple of tax ids in one go. This won't work before January 2013 at the earliest so until then you need to use the other method.
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX taxon:<http://purl.uniprot.org/taxonomy/>
SELECT ?input ?isPlant ?isMamal ?isVirus
FROM <http://purl.uniprot.org/taxonomy/>
WHERE
{
VALUES ?input {(taxon:9606) (taxon:8333)} #etc...
{
?input rdfs:subClassOf+ taxon:33090 . #viridiplanae
BIND(true AS ?isPlant)
} UNION {
?input rdfs:subClassOf+ taxon:40674 . #mamalia
BIND(true AS ?isMamal)
} UNION {
?input rdfs:subClassOf+ taxon:10239 . #viruses
BIND(true AS ?isVirus)
}
}
The use of "rdfs:subClassOf+" is really interesting...
I think that something has changed in UniProt regarding the use of rdfs:subClassOf+, because it doesn't work now. If I use rdfs:subClassOf? (or without ?) it works fine and I can get an organism lineage like this. Here's the error I get when using rdfs:subClassOf+:
Exceeded 1000000000 bytes in transitive temp memory. use t_distinct, t_max or more T_MAX_memory options to limit the search or increase the pool
Jerven could you update the answer? Same in this answer: A: Order by subclass SPARQL
recursively, Using http://beta.sparql.uniprot.org/ and the property rdfs:subClassOf
SELECT ?p ?o
FROM <http://purl.uniprot.org/taxonomy/>
WHERE
{
<http://purl.uniprot.org/taxonomy/9606> ?p ?o .
}
result: http://beta.sparql.uniprot.org/sparql?query=SELECT++%3Fp+%3Fo+%0D%0AFROM+%3Chttp....
http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://purl.uniprot.org/core/Taxon
http://www.w3.org/2000/01/rdf-schema#subClassOf,http://purl.uniprot.org/taxonomy/9605
http://purl.uniprot.org/core/mnemonic,"HUMAN"
http://purl.uniprot.org/core/commonName,"Human"
http://purl.uniprot.org/core/rank,http://purl.uniprot.org/core/Species
http://purl.uniprot.org/core/complete,"true"
http://purl.uniprot.org/core/otherName,"man"
http://purl.uniprot.org/core/otherName,"Homo sapiens Linnaeus, 1758"
http://purl.uniprot.org/core/scientificName,"Homo sapiens"
then with 9605:
http://www.w3.org/1999/02/22-rdf-syntax-ns#type,http://purl.uniprot.org/core/Taxon
http://www.w3.org/2000/01/rdf-schema#subClassOf,http://purl.uniprot.org/taxonomy/207598
http://purl.uniprot.org/core/rank,http://purl.uniprot.org/core/Genus
http://purl.uniprot.org/core/otherName,"Homo Linnaeus, 1758"
http://purl.uniprot.org/core/partOfLineage,"true"
http://purl.uniprot.org/core/scientificName,"Homo"
http://www.w3.org/2004/02/skos/core#narrowerTransitive,http://purl.uniprot.org/taxonomy/9606
then with 207598
etc...
Yes, so what we need is a reasoning SPARQL end point. Doing things iteratively will not work.
that sounds familiar :-) http://stackoverflow.com/questions/1458674
Or see my answer and use SPARQL path queries
I am surprised that that is not in the RDF you already have. According NCBI taxonomy (the underlying database) 9606 is human and thus a primate (which it shows). http://www.ncbi.nlm.nih.gov/taxonomy?term=9606 Since the taxonomy is a tree it should simply know that we are not plants and it is the right source for that. So the RDF for the taxonomy itself should be improved to reflect the tree structure if that is not already in there.
Log in to answer this question.
Your link to "this question" is not correct (links to viruses at uniprot.org instead)
Fixed. Thanx for letting me know.