Cellosaurus SPARQL service

The SPARQL service (or SPARQL endpoint) is the web service that accepts SPARQL queries over HTTP and returns results from the RDF dataset. It acts as the gateway allowing clients to query and retrieve structured data stored in RDF format using the SPARQL protocol and query language.

This service can be accessed programmatically and also provides a basic web form for manually submitting queries. For a more user-friendly experience, the SPARQL Editor offers enhanced features tailored to human users.

There are many ways to connect to and query the SPARQL service programmatically, here are a few examples with a basic query which retrieves the IRI and name of 10 cancer cell lines from Cellosaurus:

Access to SPARQL endpoint using curl in a bash script

1. Copy the following content to a file, e.g. to file test.sh

#!/bin/bash

ENDPOINT="https://sparql.cellosaurus.org/sparql"
QUERY='select * where { ?cl a cello:CancerCellLine ; cello:recommendedName ?name } limit 10'

curl -X POST \
  -H "Content-Type: application/sparql-query" \
  -H "Accept: application/sparql-results+json" \
  --data "$QUERY" \
  "$ENDPOINT"
      

2. Make it executable and run it

chmod +x test.sh
./test.sh

Access to SPARQL endpoint using Python

There are several Python libraries providing interfaces between SPARQL and Python, e.g. sparqlwrapper.

1. Install the library in your Python environment

pip install sparqlwrapper

See also: https://sparqlwrapper.readthedocs.io/en/latest/main.html

2. Create a file, e.g. test.py and copy the follwing code into it

from SPARQLWrapper import SPARQLWrapper, JSON

endpoint = SPARQLWrapper("https://sparql.cellosaurus.org/sparql")

endpoint.setQuery("select * where { ?cl a cello:CancerCellLine ; cello:recommendedName ?name } limit 10")
endpoint.setReturnFormat(JSON)

response = endpoint.queryAndConvert()
for row in response["results"]["bindings"]:
    print(row)
      
3. Run it
python test.py