Skip to content

sparql

Helpers to construct and execute SPARQL queries against the UniProtKB SPARQL endpoint.

build_sparql_generic_by_uniprot_accessions_query(uniprot_accs, select_clause, where_clause, limit=10000, groupby_clause='')

Builds a generic SPARQL query and filters by the given UniProt accessions.

Parameters:

Name Type Description Default
uniprot_accs Iterable[str]

An iterable of UniProt accessions to filter by.

required
select_clause str

The SELECT clause of the SPARQL query, without the "SELECT" keyword.

required
where_clause str

The WHERE clause of the SPARQL query, without the "WHERE" keyword.

required
limit int

The maximum number of results to return. Default is 10,000.

10000
groupby_clause

The GROUP BY clause of the SPARQL query, without the "GROUP BY" keyword.

''

Returns:

Type Description
str

A string containing the complete SPARQL query.

build_sparql_generic_query(select_clause, where_clause, limit=10000, groupby_clause='')

Builds a generic SPARQL query with the given select and where clauses.

Parameters:

Name Type Description Default
select_clause str

The SELECT clause body of the SPARQL query, without the "SELECT" keyword.

required
where_clause str

The WHERE clause body of the SPARQL query, without the "WHERE" keyword.

required
limit int

The maximum number of results to return. Default is 10,000.

10000
groupby_clause

The GROUP BY clause of the SPARQL query, without the "GROUP BY" keyword.

''

Returns:

Type Description
str

A string containing the complete SPARQL query.

Execute a SPARQL query.

Parameters:

Name Type Description Default
sparql_query str

The SPARQL query to execute.

required
timeout int

Timeout for the SPARQL query in seconds. Must be less than 2700 seconds (45 minutes).

required

Returns:

Type Description
list

A list of bindings returned by the SPARQL query.