sparql-examples

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

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

neXtProt/NXQ_00269

Proteins with associated cancer pathways in WikiPathways (via Disease Ontology classification)

Use at

PREFIX : <http://nextprot.org/rdf/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?entry (str(?gen) as ?gene) ?pathwayname WHERE {
 SERVICE <https://sparql.wikipathways.org/sparql> {
 {?geneProduct a wp:Protein}
 union
 {?geneProduct a wp:GeneProduct}
 ?geneProduct rdfs:label ?genraw .
 bind (concat( ""^^xsd:string, ?genraw) as ?gen).
 filter(!regex(?gen,"[ a-z-]")). # ensures official gene names for subsequent neXtprot matching
 ?geneProduct dcterms:isPartOf ?pathway .
 ?pathway a wp:Pathway .
 ?pathway wp:organism ?organism .
 filter(contains(str(?organism),"9606")) # Human proteins
 ?pathway dcterms:title ?pathwayname .
 ?pathway wp:ontologyTag <http://purl.obolibrary.org/obo/DOID_162> . # Parent id for all cancers
 }
 ?entry a :Entry .
 ?entry :gene / :recommendedName / rdfs:label ?gen .
}
order by ?pathwayname
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v7("?entry"):::projected 
  v6("?gen"):::projected 
  v8("?gene")
  v4("?geneProduct")
  v5("?genraw")
  v2("?organism")
  v6("?pathway")
  v1("?pathwayname"):::projected 
  a1((" "))
  a2((" "))
  c5(["wp:Protein"]):::iri 
  c9(["wp:Pathway"]):::iri 
  c6(["wp:GeneProduct"]):::iri 
  c14([":Entry"]):::iri 
  c13([http://purl.obolibrary.org/obo/DOID_162]):::iri 
  subgraph s1["https://sparql.wikipathways.org/sparql"]
    style s1 stroke-width:4px;
    f0[["contains(str(?organism),'9606')"]]
    f0 --> v2
    f1[["not regex(?gen,'#91; a-z-#93;')"]]
    f1 --> v6
    subgraph union0[" Union "]
    subgraph union0l[" "]
      style union0l fill:#abf,stroke-dasharray: 3 3;
      v4 --"a"-->  c6
    end
    subgraph union0r[" "]
      style union0r fill:#abf,stroke-dasharray: 3 3;
      v4 --"a"-->  c5
    end
    union0r <== or ==> union0l
    end
    v4 --"rdfs:label"-->  v5
    bind2[/"concat('',?genraw)"/]
    v5 --o bind2
    bind2 --as--o v6
    v4 --"dcterms:isPartOf"-->  v6
    v6 --"a"-->  c9
    v6 --"wp:organism"-->  v2
    v6 --"dcterms:title"-->  v1
    v6 --"wp:ontologyTag"-->  c13
  end
  v7 --"a"-->  c14
  v7 --":gene"-->  a1
  a1 --":recommendedName"-->  a2
  a2 --"rdfs:label"-->  v6
  bind3[/"str(?gen)"/]
  v6 --o bind3
  bind3 --as--o v8