sparql-examples

A set of SPARQL examples

View the Project on GitHub Adafede/sparql-examples

wd_omics_search

rq turtle/ttl

Which taxa have children (or themselves) with known chemicals, genes, and proteins? (search)

Use at


PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX hint: <http://www.bigdata.com/queryHints#>
#title: Which taxa have children (or themselves) with known chemicals, genes, and proteins? (search)
SELECT ?taxon ?child (COUNT(DISTINCT ?g) AS ?genome) (COUNT(DISTINCT ?m) AS ?metabolome) (COUNT(DISTINCT ?p) AS ?proteome) WHERE {
    {
        SELECT ?taxon ?child ?thing WHERE {
            VALUES ?taxon {
                wd:Q31856
            }
            ?taxon ^(wdt:P171*) ?child.
            hint:Prior hint:rangeSafe true.
            ?child ^wdt:P703 ?thing.
            hint:Prior hint:rangeSafe true.
        }
    }
    {
        SELECT * WHERE {
            VALUES ?chemical {
                wd:Q113145171
                wd:Q59199015
            }
            VALUES ?gene {
                wd:Q7187
            }
            VALUES ?protein {
                wd:Q8054
            }
            {
                ?thing wdt:P31 ?chemical.
                hint:Prior hint:rangeSafe true.
                BIND(?thing AS ?m)
            }
            UNION
            {
                ?thing wdt:P31 ?protein.
                hint:Prior hint:rangeSafe true.
                BIND(?thing AS ?p)
            }
            UNION
            {
                ?thing wdt:P31 ?gene.
                hint:Prior hint:rangeSafe true.
                BIND(?thing AS ?g)
            }
        }
    }
}
GROUP BY ?taxon ?child
HAVING (((?genome > 0 ) || (?metabolome > 0 )) || (?proteome > 0 ))

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v7("?chemical")
  v5("?child"):::projected 
  v12("?g"):::projected 
  v8("?gene")
  v13("?genome")
  v10("?m"):::projected 
  v13("?metabolome")
  v11("?p"):::projected 
  v9("?protein")
  v13("?proteome")
  v4("?taxon"):::projected 
  v6("?thing")
  c3([http://www.bigdata.com/queryHints#Prior]):::iri 
  c5(["true^^xsd:boolean"]):::literal 
  f0[["((?genome > '0^^xsd:integer' || ?metabolome > '0^^xsd:integer') || ?proteome > '0^^xsd:integer')"]]
  f0 --> v13
  f0 --> v13
  f0 --> v13
  bind1[/VALUES ?taxon/]
  bind1-->v4
  bind10(["wd:Q31856"])
  bind10 --> bind1
  v5 --"wdt:P171"-->  v4
  c3 --http://www.bigdata.com/queryHints#rangeSafe-->  c5
  v6 --"wdt:P703"-->  v5
  c3 --http://www.bigdata.com/queryHints#rangeSafe-->  c5
  bind2[/VALUES ?chemical/]
  bind2-->v7
  bind20(["wd:Q113145171"])
  bind20 --> bind2
  bind21(["wd:Q59199015"])
  bind21 --> bind2
  bind3[/VALUES ?gene/]
  bind3-->v8
  bind30(["wd:Q7187"])
  bind30 --> bind3
  bind4[/VALUES ?protein/]
  bind4-->v9
  bind40(["wd:Q8054"])
  bind40 --> bind4
  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;
      v6 --"wdt:P31"-->  v8
      c3 --http://www.bigdata.com/queryHints#rangeSafe-->  c5
      bind5[/"?thing"/]
      v6 --o bind5
      bind5 --as--o v12
    end
    subgraph union1r[" "]
      style union1r fill:#abf,stroke-dasharray: 3 3;
      v6 --"wdt:P31"-->  v9
      c3 --http://www.bigdata.com/queryHints#rangeSafe-->  c5
      bind6[/"?thing"/]
      v6 --o bind6
      bind6 --as--o v11
    end
    union1r <== or ==> union1l
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v6 --"wdt:P31"-->  v7
    c3 --http://www.bigdata.com/queryHints#rangeSafe-->  c5
    bind7[/"?thing"/]
    v6 --o bind7
    bind7 --as--o v10
  end
  union0r <== or ==> union0l
  end
  bind11[/"count(?g)"/]
  v12 --o bind11
  bind11 --as--o v13
  bind12[/"count(?m)"/]
  v10 --o bind12
  bind12 --as--o v13
  bind13[/"count(?p)"/]
  v11 --o bind13
  bind13 --as--o v13