How to SPARQL — a step-by-step tutorial
You don't need to know anything about SPARQL or RDF for this page. Every step adds one small idea. Each query below is live: press Run (or Ctrl+Enter inside the box) and the answer appears underneath. You can change the query and run it again — you can't break anything.
Before we start: the data is made of little sentences
SABIO's data is stored as millions of tiny three-part sentences: something → has some property → some value. For example:
organisms/5 is a Organism organisms/5 has the name "Homo sapiens" kinlaw-entry/23815 was measured in organisms/5
The first part is always a thing, written as a web address (organism 5, entry 23815). The value at the end is either plain text or a number, or another thing — that's how entries are connected to their organism, enzyme, publication and so on.
A query is a sentence with blanks. You write the sentence, leave a blank where
you don't know the answer, and SPARQL fills in every possible answer. A blank is a word
starting with ?, like ?name.
Step 1 · Peek at five sentences
The simplest query there is: a sentence that is only blanks.
What's going on
WHERE { … }holds the sentence you're looking for.?thing ?property ?value— three blanks, so every sentence matches.SELECT *means "show me all the blanks".LIMIT 5means "five answers are enough". There are millions of sentences, so always keep aLIMITwhile you explore.
You'll probably see sentences about unit 0 ("no unit"). It just happens to come first; without more detail in the sentence, SPARQL returns whatever it finds first.
Step 2 · Everything about one thing
Now fill in the first part and keep the other two blank: "tell me everything about organism 5".
What's going on
- A thing's full address goes in
< >. It's also the address of its page on the SABIO-RK website. - The answer lists organism 5's properties: what it is (
type→ Organism), its name (label), other names (altLabel), the same organism in the NCBI taxonomy (exactMatch) and how many entries use it. - Here we
SELECTjust the two blanks we care about, instead of*.
Step 3 · List all organisms
Two sentences at once: "?organism is an organism" and "?organism has the name ?name".
What's going on
PREFIXlines are abbreviations:sabio:Organismis short for<https://sparql.sabiork.h-its.org/vocab#Organism>. Just copy them to the top of every query.ais short for "is a".rdfs:labelis the name. Every SABIO thing has one.- Each sentence ends with a dot
. - Both sentences use the same blank
?organism, so they must be about the same organism. That's how you connect sentences.
Step 4 · Find something by its name
Usually you know the name, not the address. Put the name in quotes and leave the thing blank:
What's going on
- Text in quotes must match exactly, including upper and lower case.
"homo sapiens"finds nothing. - The answer is the address
organisms/5we used in step 2.
Step 5 · Search for part of a name
Don't know the exact name? Keep the name blank and add a FILTER: a
condition every answer has to pass.
What's going on
LCASE(?name)turns the name into lower case, so the search ignores upper/lower case.CONTAINS(…, "coli")keeps only names that contain "coli".
Step 6 · Sort the answers
Which organisms have the most entries? Every organism carries its entry count, so we sort by it.
What's going on
- A semicolon
;means "same thing again". These three lines are the same as writing?organismat the start of each one. It just saves typing. ORDER BY DESC(?entries)sorts from biggest to smallest. WithoutDESCit sorts smallest first.
Step 7 · Follow a link from one thing to another
This is where it gets useful. An entry points to its organism and its enzyme, and the enzyme has a name. We follow that chain: Homo sapiens → its entries → their enzyme → the enzyme's name.
What's going on
- Read it top to bottom, like a path: find the organism, then entries measured in it, then each entry's enzyme, then that enzyme's name.
- Each blank links two sentences:
?organismlinks lines 1 and 2,?entrylines 2 and 3,?enzymelines 3 and 4. - Every
?entryis the address of an entry's page.
Step 8 · Count
Same chain as step 7, but instead of listing entries we count them per enzyme: "which enzymes have the most human entries?"
What's going on
GROUP BY ?enzymeNameputs all answers with the same enzyme name in one pile.(COUNT(?entry) AS ?entries)counts each pile and calls the number?entries.
Step 9 · Get the measured values
The last step: the actual numbers. An entry has parameters (Km, kcat, Ki, …), and each parameter has a type, a value, a unit and usually a compound. Here: Km values of alcohol dehydrogenase (EC 1.1.1.1) in Homo sapiens, per substrate.
What's going on
- Nothing new — just more sentences chained together. The empty lines are only there to make it easier to read.
- Values are converted to standard units, which is why Km shows up in M (molar).
sabio:ecNumber "1.1.1.1"finds the enzyme by its EC number instead of its name.
That's it
With these nine steps you can already answer most questions: describe the sentence you're looking for, leave blanks for what you want to know, and connect things through shared blanks. A few things to remember:
- Keep a
LIMITwhile exploring. - Names in quotes must match exactly; use
FILTER(CONTAINS(LCASE(…), "…"))when you're not sure. - If a query returns nothing, remove sentences from the bottom until it does — then you've found the one that doesn't match.
Ready for more? The query editor has a list of explained example queries on the left, from simple to advanced.