Koetai SPARQL examples

Community-curated SPARQL example queries for multiple life-science endpoints.

View the Project on GitHub Koetai/sparql-examples

where_idr_meets_uniprot_linked_through_doi

rq turtle/ttl

This query shouw which URIs in IDR and which URIs in Uniprot are linked through a DOI or Pubmed

Use at

PREFIX ome: <https://ld.openmicroscopy.org/core/>
PREFIX up: <http://purl.uniprot.org/core/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT DISTINCT ?type ?id WHERE {
  {
    { SELECT DISTINCT ?id WHERE {
        ?e ome:key "PubMed ID" ; ome:value ?v .
        BIND(STRBEFORE(?v, " ") AS ?id)
    } }
    BIND("PMID" AS ?type)
    BIND(IRI(CONCAT("http://purl.uniprot.org/citations/", ?id)) AS ?cit)
    SERVICE <https://sparql.uniprot.org/sparql> { ?cit a ?t }
  } UNION {
    { SELECT DISTINCT ?id WHERE {
        ?e2 ome:key "Publication DOI" ; ome:value ?v2 .
        BIND(STRBEFORE(?v2, " ") AS ?id)
    } }
    BIND("DOI" AS ?type)
    BIND(CONCAT("doi:", ?id) AS ?doiLit)
    SERVICE <https://sparql.uniprot.org/sparql> { ?cit2 dcterms:identifier ?doiLit }
  }
}
ORDER BY ?type ?id
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v5("?cit")
  v10("?cit2")
  v9("?doiLit")
  v3("?e")
  v7("?e2")
  v9("?id"):::projected 
  v6("?t")
  v9("?type"):::projected 
  v4("?v")
  v8("?v2")
  c6(["Publication DOI"]):::literal 
  c2(["PubMed ID"]):::literal 
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    v7 --https://ld.openmicroscopy.org/core/key-->  c6
    v7 --https://ld.openmicroscopy.org/core/value-->  v8
    bind0[/"substring-before(?v2,' ')"/]
    v8 --o bind0
    bind0 --as--o v9
    bind1[/"'DOI'"/]
    bind1 --as--o v9
    bind2[/"concat('doi:',?id)"/]
    v9 --o bind2
    bind2 --as--o v9
    subgraph s1["https://sparql.uniprot.org/sparql"]
      style s1 stroke-width:4px;
      v10 --"dcterms:identifier"-->  v9
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v3 --https://ld.openmicroscopy.org/core/key-->  c2
    v3 --https://ld.openmicroscopy.org/core/value-->  v4
    bind3[/"substring-before(?v,' ')"/]
    v4 --o bind3
    bind3 --as--o v9
    bind4[/"'PMID'"/]
    bind4 --as--o v9
    bind5[/"concat('http://purl.uniprot.org/citations/',?id)"/]
    v9 --o bind5
    bind5 --as--o v5
    subgraph s1["https://sparql.uniprot.org/sparql"]
      style s1 stroke-width:4px;
      v5 --"a"-->  v6
    end
  end
  union0r <== or ==> union0l
  end