@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix ex: <https://bigcat-um.github.io/sparql-examples/WikiPathways/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix spex: <https://purl.expasy.org/sparql-examples/ontology#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:022 a sh:SPARQLExecutable,
       sh:SPARQLSelectExecutable ;
    rdfs:label "IEM Proteins, Metabolites, Rhea, and Diseases"@en ;
    rdfs:comment "Summarizes IEM community pathways with counts of proteins, metabolites, Rhea reaction annotations, missing Rhea IDs, and linked OMIM disease identifiers per pathway."@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX cur: <http://vocabularies.wikipathways.org/wp#Curation:>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX gpml: <http://vocabularies.wikipathways.org/gpml#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX wp:      <http://vocabularies.wikipathways.org/wp#>
PREFIX rdfs:    <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>

#Variable selection
SELECT DISTINCT (str(?title) as ?pathwayName) ?PWID 
(count(distinct ?geneProduct) AS ?ProteinsInPWs) (count(distinct ?metaboliteNode) AS ?MetabolitesInPWs) 
(count(distinct ?interactionID) AS ?RheaInPWs) (count(distinct ?interactionMissing) AS ?NoRheaInPWs)
(count(distinct ?omim) as ?diseaseIDs)

WHERE {

    ?pathway wp:ontologyTag cur:IEM . 
    ?pathway dcterms:identifier ?PWID. #Obtain the ID
    ?pathway wp:isAbout ?gpmlRDF_ID . #find the corresponding GPML link     
    ?pathway dc:title ?title . #Obtain the title   

    {
    ?geneProduct dcterms:isPartOf ?pathway . #Only those part of PW             
    ?geneProduct a wp:Protein . #Filter for Protein DataNodes    
    } 
    UNION
    { 
    ?metaboliteNode a wp:Metabolite . #Filter for Metabolite DataNodes
    ?metaboliteNode dcterms:isPartOf ?pathway . #Only those part of PW
    }
    UNION 
    { 
    OPTIONAL{?interaction wp:bdbRhea ?interactionID . #Find interactions with a Rhea ID
    ?interaction dcterms:isPartOf ?pathway .} #Only those part of PW
    }
    UNION
    {
    OPTIONAL{?interactionMissing dcterms:isPartOf ?pathway . #Find additional interactions
    ?interactionMissing rdf:type wp:Conversion . #That are of type 'metabolic conversion'
    FILTER NOT EXISTS {?interactionMissing wp:bdbRhea ?interactionID . } #Without a Rhea ID   
    }  
    }
    UNION {
    ?diseaseNode dcterms:isPartOf ?gpmlRDF_ID . #Only check for matching pathways 
    ?diseaseNode rdf:type gpml:Label . #Only include textLabels
    ?diseaseNode gpml:href ?omim . #That have an href attribute  
    FILTER regex(?omim, "omim.org", "i") #Only keep hrefs if they contain 'omim.org'
    }
      
} GROUP BY ?pathway ?title ?PWID
ORDER BY ASC(?pathway)""" ;
    schema:target <https://sparql.wikipathways.org/sparql> ;
    schema:keywords "communities", "inborn errors of metabolism", "metabolism" ;
    dcterms:source <https://github.com/wikipathways/SPARQLQueries/blob/f9de718ebdcca57dadb773d47fa4e342cf386857/B.%20Communities/Inborn%20Errors%20of%20Metabolism/countProteinsMetabolitesRheaDiseases.rq> ;
    dcterms:modified "2026-11-10"^^xsd:date ;
    dcterms:license <https://www.gnu.org/licenses/gpl-3.0.html> .
