Koetai SPARQL examples

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

View the Project on GitHub Koetai/sparql-examples

link_idr_imaging_studies_to_uniprot_proteins_by_pubmed_citation

rq turtle/ttl

A federated query that links IDR imaging studies to UniProt proteins through their shared publication — for every IDR study annotated with a PubMed ID, it lists the UniProt proteins that cite (or are computationally mapped to) that paper.

Use at

PREFIX ome: <https://ld.openmicroscopy.org/core/>
PREFIX up: <http://purl.uniprot.org/core/>
SELECT ?idrUrl
       (GROUP_CONCAT(DISTINCT STR(?cit);     separator=" ; ") AS ?citations)
       (GROUP_CONCAT(DISTINCT STR(?protein); separator=" ; ") AS ?proteins)
WHERE {
  ?e ome:key "PubMed ID" ; ome:value ?v .
  ?ann ome:mapEntry ?e .
  ?idrSubject ome:hasAnnotation ?ann .
  BIND(CONCAT("https://idr.openmicroscopy.org/webclient/?show=",
              REPLACE(LCASE(STRAFTER(STR(?idrSubject), "openmicroscopy.org/")), "/", "-")) AS ?idrUrl)
  BIND(IRI(CONCAT("http://purl.uniprot.org/citations/", STRBEFORE(?v, " "))) AS ?cit)
  SERVICE <https://sparql.uniprot.org/sparql> {
    ?protein a up:Protein ; (up:citation|up:mappedCitation) ?cit .
  }
}
GROUP BY ?idrUrl
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v3("?ann")
  v6("?cit"):::projected 
  v8("?citations")
  v1("?e")
  v4("?idrSubject")
  v5("?idrUrl"):::projected 
  v7("?protein"):::projected 
  v9("?proteins")
  v2("?v")
  c2(["PubMed ID"]):::literal 
  c8(["up:Protein"]):::iri 
  v1 --https://ld.openmicroscopy.org/core/key-->  c2
  v1 --https://ld.openmicroscopy.org/core/value-->  v2
  v3 --https://ld.openmicroscopy.org/core/mapEntry-->  v1
  v4 --https://ld.openmicroscopy.org/core/hasAnnotation-->  v3
  bind0[/"concat('https://idr.openmicroscopy.org/webclient/?show=',replace(lower-case(substring-after(str(?idrSubject),'openmicroscopy.org/')),'/','-'))"/]
  v4 --o bind0
  bind0 --as--o v5
  bind1[/"concat('http://purl.uniprot.org/citations/',substring-before(?v,' '))"/]
  v2 --o bind1
  bind1 --as--o v6
  subgraph s1["https://sparql.uniprot.org/sparql"]
    style s1 stroke-width:4px;
    v7 --"a"-->  c8
    subgraph union0[" Union "]
    subgraph union0l[" "]
      style union0l fill:#abf,stroke-dasharray: 3 3;
      v7 --"up:mappedCitation"-->  v6
    end
    subgraph union0r[" "]
      style union0r fill:#abf,stroke-dasharray: 3 3;
      v7 --"up:citation"-->  v6
    end
    union0r <== or ==> union0l
    end
  end
  bind4[/"str(?cit)"/]
  v6 --o bind4
  bind4 --as--o v8
  bind5[/"str(?protein)"/]
  v7 --o bind5
  bind5 --as--o v9