Help:WikiPathways SPARQL queries
From WikiPathways
(Difference between revisions)
(→List the species captured in WikiPathways and the number of pathways per species) |
(→Datasource oriented queries) |
||
| Line 61: | Line 61: | ||
[http://sparqlbin.com/#f123c99388d62965e9c96de98c85c71f Sparqlbin] | [http://sparqlbin.com/#f123c99388d62965e9c96de98c85c71f Sparqlbin] | ||
| - | + | == Datasource oriented queries == | |
| - | + | ||
| - | + | ===Get all datasource currently captured in WikiPathways=== | |
| - | + | <pre>SELECT DISTINCT ?datasource | |
WHERE { | WHERE { | ||
?concept dc:source ?datasource | ?concept dc:source ?datasource | ||
} </pre> | } </pre> | ||
| - | + | [http://sparqlbin.com/#7581bb9342849523fc6aec3b9c16758c Execute] | |
| - | + | ||
| - | + | ===Get the number of entries per datasource in WikiPathways=== | |
| - | + | <pre>SELECT DISTINCT ?datasource count(?datasource) as ?numberEntries | |
WHERE { | WHERE { | ||
?concept dc:source ?datasource | ?concept dc:source ?datasource | ||
} | } | ||
ORDER BY DESC(?numberEntries)</pre> | ORDER BY DESC(?numberEntries)</pre> | ||
| - | + | [http://sparqlbin.com/#d30949a809997d9a286cf67886f07ede Execute] | |
| - | + | ||
| - | + | ===Count the identifiers per data source=== | |
| - | + | <pre> | |
SELECT DISTINCT ?datasource ?identifier count(?identifier) AS ?numberEntries | SELECT DISTINCT ?datasource ?identifier count(?identifier) AS ?numberEntries | ||
WHERE { | WHERE { | ||
| Line 86: | Line 86: | ||
} | } | ||
</pre> | </pre> | ||
| - | + | [http://sparqlbin.com/#518227bff329828bfed1a799c6bdb0b5 Execute] | |
| - | + | ||
| - | + | ===Count the identifiers per data source and order them from high to low=== | |
| - | + | <pre> | |
| - | + | ||
SELECT DISTINCT ?datasource ?identifier count(?identifier) AS ?numberEntries | SELECT DISTINCT ?datasource ?identifier count(?identifier) AS ?numberEntries | ||
WHERE { | WHERE { | ||
| Line 98: | Line 97: | ||
ORDER BY DESC(?numberEntries) | ORDER BY DESC(?numberEntries) | ||
</pre> | </pre> | ||
| - | + | [http://sparqlbin.com/#87818e56a8c9de7c1d40ff2340ccfa82 Execute] | |
| - | + | ||
| - | + | ||
| - | + | === Return all Chembl compounds in WikiPathways and the pathways they are in === | |
| - | + | <pre>SELECT DISTINCT ?identifier ?pathway | |
WHERE { | WHERE { | ||
?concept dcterms:isPartOf ?pathway . | ?concept dcterms:isPartOf ?pathway . | ||
| Line 109: | Line 108: | ||
} </pre> | } </pre> | ||
| - | + | [http://sparqlbin.com/#6d0615f7c5da47a7a8ce076cc60ca7a7 Execute] | |
| - | + | ||
| - | + | ||
=== Curators oriented queries === | === Curators oriented queries === | ||
Revision as of 15:37, 24 October 2012
On sparql.wikipathways.org wikipathways content is replicated. Currently this SPARQL endpoint is being developed, with very irregular updates.
Prefixes
Below are example queries. For readability we have omitted the prefixes. We use the following prefixes: (Not complete yet)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX schema: <http://schema.org/>
Example queries
Queries with a * requires a bit more time for results.
Data curation oriented queries
Get the pathway with the erroneous data source "null"
SELECT DISTINCT ?identifier ?pathway ?label
WHERE {
?concept dc:source "null"^^xsd:string .
?concept dc:identifier ?identifier .
?concept dcterms:isPartOf ?pathway .
?concept rdfs:label ?label
}
Pathway oriented queries
Get the species currently in WikiPathways with their respective URI's
SELECT DISTINCT ?organism ?label
WHERE {
?concept wp:organism ?organism .
?organism rdfs:label ?label .
}
List pathways and their species
SELECT DISTINCT ?title ?label
WHERE {
?pathway dc:title ?title .
?pathway wp:organism ?organism .
?organism rdfs:label ?label .
}
List the species captured in WikiPathways and the number of pathways per species
SELECT DISTINCT ?organism ?label count(?pathway) as ?noPathways
WHERE {
?pathway dc:title ?title .
?pathway wp:organism ?organism .
?organism rdfs:label ?label .
}
ORDER BY DESC(?noPathways)
Datasource oriented queries
Get all datasource currently captured in WikiPathways
SELECT DISTINCT ?datasource
WHERE {
?concept dc:source ?datasource
}
Execute
Get the number of entries per datasource in WikiPathways
SELECT DISTINCT ?datasource count(?datasource) as ?numberEntries
WHERE {
?concept dc:source ?datasource
}
ORDER BY DESC(?numberEntries)
Count the identifiers per data source
SELECT DISTINCT ?datasource ?identifier count(?identifier) AS ?numberEntries
WHERE {
?concept dc:source ?datasource .
?concept dc:identifier ?identifier
}
Execute
===Count the identifiers per data source and order them from high to low===
SELECT DISTINCT ?datasource ?identifier count(?identifier) AS ?numberEntries
WHERE {
?concept dc:source ?datasource .
?concept dc:identifier ?identifier
}
ORDER BY DESC(?numberEntries)
Execute
Return all Chembl compounds in WikiPathways and the pathways they are in
SELECT DISTINCT ?identifier ?pathway
WHERE {
?concept dcterms:isPartOf ?pathway .
?concept dc:source "ChEMBL compound"^^xsd:string .
?concept dc:identifier ?identifier .
}
Curators oriented queries
| Extract contributors | SELECT DISTINCT ?contributor
WHERE {
?pathway dc:contributor ?contributor
}
| Execute |
| Extract the amount of pathways edited per contributor | SELECT DISTINCT ?contributor, count(?pathway) as ?pathwaysEdited
WHERE {
?pathway dc:contributor ?contributor
}
ORDER BY DESC(?pathwaysEdited)
| Execute |
| find the pathways a user have edited so far. Change the name in the query | SELECT DISTINCT ?pathway, ?pathwayLabel
WHERE {
?pathway dc:contributor wpuser:Andra .
?pathway dc:contributor ?contributor .
?pathway rdfs:label ?pathwayLabel .
}
| Execute |
Federated queries
Code examples
Java
For java we recommend the Jena Framework.
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
public class javaCodeExample {
public static void main(String[] args) {
String sparqlQueryString = "SELECT * WHERE {?s ?p ?o} LIMIT 10";
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution queryExecution = QueryExecutionFactory.sparqlService("http://sparql.wikipathways.org", query);
ResultSet resultSet = queryExecution.execSelect();
while (resultSet.hasNext()) {
QuerySolution solution = resultSet.next();
System.out.print(solution.get("s"));
System.out.print("\t"+solution.get("p"));
System.out.println("\t"+solution.get("o"));
}
}
}
php
For php we recommend the arc2: Easy RDF and SPARQL for LAMP systems
SPARQL from the command line
For quick and easy querying, we recommend to use curl (Linux and OS X)
curl -F "query=SELECT * WHERE {?s ?p ?o} LIMIT 10" http://sparql.wikipathways.org

