@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:035 a sh:SPARQLExecutable,
       sh:SPARQLSelectExecutable ;
    rdfs:label "Molecular Similarity Reactions via Rhea and IDSM"@en ;
    rdfs:comment "Finds structurally similar compounds for reaction sources and targets in a pathway by querying the IDSM structure search service for molecular similarity. May be slower due to external endpoint dependency."@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX ebi: <http://ebi.rdf.ac.uk/dataset/>
PREFIX sachem: <http://bioinfo.uochb.cas.cz/rdf/v1.0/sachem#>
PREFIX idsm: <https://idsm.elixir-czech.cz/sparql/endpoint/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX wp: <http://vocabularies.wikipathways.org/wp#>
PREFIX sso: <http://semanticscience.org/resource/>
PREFIX rh:<http://rdf.rhea-db.org/>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:     <http://www.w3.org/2001/XMLSchema#>

SELECT distinct ?chebioSrc ?similarSrc ?chebioTgt ?similarTgt ?reaction WHERE {
  ?interaction dcterms:isPartOf ?pathway ; a wp:Conversion ;
      wp:source ?source ;
      wp:target ?target .
    ?source wp:bdbChEBI ?chebiSrc .
    ?target wp:bdbChEBI ?chebiTgt .
    ?pathway dcterms:identifier "WP4225".
    BIND(iri(concat("http://purl.obolibrary.org/obo/CHEBI_", substr(str(?chebiSrc),37))) AS ?chebioSrc)
    BIND(iri(concat("http://purl.obolibrary.org/obo/CHEBI_", substr(str(?chebiTgt),37))) AS ?chebioTgt)


#IDSM
SERVICE <https://idsm.elixir-czech.cz/sparql/endpoint/chebi> {
  
   ?chebioSrc ^sso:is-attribute-of / sso:has-value ?molfileSrc .
 ?chebioTgt ^sso:is-attribute-of / sso:has-value ?molfileTgt .
  [ sachem:compound ?similarSrc; sachem:score ?scoreSrc ]
    sachem:similaritySearch [
      sachem:query ?molfileSrc ;
#     sachem:cutoff "0.98"^^xsd:double
    ].
  [ sachem:compound ?similarTgt; sachem:score ?scoreTgt ]
    sachem:similaritySearch [
      sachem:query ?molfileTgt ;
#      sachem:cutoff "0.98"^^xsd:double
    ].
  }
  
#   SERVICE <https://sparql.rhea-db.org/sparql> {
#    ?reaction rh:side / rh:contains / rh:compound / rh:chebi ?similarSrc , ?similarTgt .
#    ?reaction rdfs:subClassOf rh:Reaction .
#  }  
  
 }""" ;
    schema:target <https://sparql.wikipathways.org/sparql> ;
    schema:keywords "collaborations", "Rhea", "IDSM", "reaction" ;
    spex:federatesWith <https://idsm.elixir-czech.cz/sparql/endpoint/chebi> ;
    dcterms:source <https://github.com/wikipathways/SPARQLQueries/blob/2f50cac7505b9a201527cde7ad60e510508180a9/C.%20Collaborations/smallMolecules_Rhea_IDSM/molecularSimularity_Reactions.rq> ;
    dcterms:modified "2026-03-08"^^xsd:date ;
    dcterms:license <https://www.gnu.org/licenses/gpl-3.0.html> .
