sparql-examples

A set of SPARQL examples that are used in different SIB resources

View the Project on GitHub sib-swiss/sparql-examples

127_uniprot_human_reviewed_to_chebi

rq turtle/ttl

UniProt entries use ChEBI in the following annotations: Ligands, Cofactors and Enzymatic Activity. This query shows how these can all be retrieved in one go, to make a UniProt to ChEBI mapping. The example query is made smaller by retrieving only human entries in Swiss-Prot.

Use at

PREFIX uniprotkb: <http://purl.uniprot.org/uniprot/>
PREFIX taxon: <http://purl.uniprot.org/taxonomy/>
PREFIX rh: <http://rdf.rhea-db.org/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX CHEBI: <http://purl.obolibrary.org/obo/CHEBI_>
PREFIX up: <http://purl.uniprot.org/core/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT
	(SUBSTR(STR(?protein), STRLEN(STR(uniprotkb:))+1) AS ?proteinAc)
	(GROUP_CONCAT(DISTINCT ?chebiId; separator=',') AS ?chebis)
WHERE {
	?protein up:reviewed true ;
	up:organism taxon:9606 .
	{
		?protein up:annotation ?ligandAnnotation .
		?ligandAnnotation up:ligand/rdfs:subClassOf ?chebi
	} UNION {
		?protein up:annotation ?cofactorAnnotation .
		?cofactorAnnotation up:cofactor ?chebi .
	} UNION {
		?protein up:annotation ?catalyticActivityAnnotation .
		?catalyticActivityAnnotation a up:Catalytic_Activity_Annotation ;
			up:catalyticActivity ?catalyticActivity .
		?catalyticActivity up:catalyzedReaction ?rhea .
		?rhea rh:side/rh:contains/rh:compound ?compound .
		?compound (rh:chebi|(rh:reactivePart/rh:chebi)|rh:underlyingChebi) ?chebi .
	}
	GRAPH <http://sparql.uniprot.org/chebi> {
		?chebi a owl:Class .
	}
	BIND((CONCAT("chebi:",SUBSTR(STR(?chebi), STRLEN(STR(CHEBI:))+1))) AS ?chebiId)
} GROUP BY ?protein
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?catalyticActivity")
  v5("?catalyticActivityAnnotation")
  v3("?chebi")
  v9("?chebiId"):::projected 
  v11("?chebis")
  v4("?cofactorAnnotation")
  v8("?compound")
  v2("?ligandAnnotation")
  v1("?protein"):::projected 
  v10("?proteinAc")
  v7("?rhea")
  a1((" "))
  a2((" "))
  a3((" "))
  a4((" "))
  c19(["owl:Class"]):::iri 
  c4(["taxon:9606"]):::iri 
  c2(["true^^xsd:boolean"]):::literal 
  c10(["up:Catalytic_Activity_Annotation"]):::iri 
  v1 --"up:reviewed"-->  c2
  v1 --"up:organism"-->  c4
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    subgraph union1[" Union "]
    subgraph union1l[" "]
      style union1l fill:#abf,stroke-dasharray: 3 3;
      v1 --"up:annotation"-->  v5
      v5 --"a"-->  c10
      v5 --"up:catalyticActivity"-->  v6
      v6 --"up:catalyzedReaction"-->  v7
      v7 --"rh:side"-->  a2
      a2 --"rh:contains"-->  a3
      a3 --"rh:compound"-->  v8
      subgraph union2[" Union "]
      subgraph union2l[" "]
        style union2l fill:#abf,stroke-dasharray: 3 3;
        subgraph union3[" Union "]
        subgraph union3l[" "]
          style union3l fill:#abf,stroke-dasharray: 3 3;
          v8 --"rh:underlyingChebi"-->  v3
        end
        subgraph union3r[" "]
          style union3r fill:#abf,stroke-dasharray: 3 3;
          v8 --"rh:reactivePart"-->  a4
          a4 --"rh:chebi"-->  v3
        end
        union3r <== or ==> union3l
        end
      end
      subgraph union2r[" "]
        style union2r fill:#abf,stroke-dasharray: 3 3;
        v8 --"rh:chebi"-->  v3
      end
      union2r <== or ==> union2l
      end
    end
    subgraph union1r[" "]
      style union1r fill:#abf,stroke-dasharray: 3 3;
      v1 --"up:annotation"-->  v4
      v4 --"up:cofactor"-->  v3
    end
    union1r <== or ==> union1l
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v1 --"up:annotation"-->  v2
    v2 --"up:ligand"-->  a1
    a1 --"rdfs:subClassOf"-->  v3
  end
  union0r <== or ==> union0l
  end
  v3 --"a"-->  c19
  bind0[/"concat('chebi:',substring(str(?chebi),string-length(str('CHEBI:')) + '+1^^xsd:integer'))"/]
  v3 --o bind0
  bind0 --as--o v9
  bind2[/"substring(str(?protein),string-length(str('uniprotkb:')) + '+1^^xsd:integer')"/]
  v1 --o bind2
  bind2 --as--o v10
  bind3[/"?chebiId"/]
  v9 --o bind3
  bind3 --as--o v11