@prefix ex:<https://purl.expasy.org/sparql-examples/neXtProt/> .
@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#> .

ex:NXQ_00249 a sh:SPARQLExecutable, sh:SPARQLSelectExecutable ;
  sh:prefixes _:sparql_examples_prefixes ;
  rdfs:comment '''GO_MF terms associated with proteins binding estradiol and/or similar molecules (substructure search with SMILES)'''@en ;
  schema:keywords "GO", "federated query", "function", "interaction", "snorql-only" ;
  schema:target <https://sparql.nextprot.org/sparql> ;
  sh:select '''PREFIX : <http://nextprot.org/rdf/>
PREFIX cv: <http://nextprot.org/rdf/terminology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

PREFIX sachem: <http://bioinfo.uochb.cas.cz/rdf/v1.0/sachem#>
PREFIX idsm: <https://idsm.elixir-czech.cz/sparql/endpoint/>
PREFIX chembl: <http://rdf.ebi.ac.uk/terms/chembl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT distinct ?gomf ?gomflab (count(distinct ?entry) as ?ecnt) WHERE
{
  {
    SELECT ?compound ?UNIPROT WHERE {
      SERVICE <https://www.ebi.ac.uk/rdf/services/sparql/> {
        SERVICE idsm:chembl {
          ?compound sachem:substructureSearch [
              sachem:query "CC12CCC3C(C1CCC2O)CCC4=C3C=CC(=C4)O"] . # smiles chain for estradiol
        }

        ?ACTIVITY rdf:type chembl:Activity;
          chembl:hasMolecule ?compound;
          chembl:hasAssay ?ASSAY.
        ?ASSAY chembl:hasTarget ?TARGET.
        ?TARGET chembl:hasTargetComponent ?COMPONENT.
        ?TARGET chembl:taxonomy <http://identifiers.org/taxonomy/9606> . # human protein target
        ?COMPONENT chembl:targetCmptXref ?UNIPROT.
        ?UNIPROT rdf:type chembl:UniprotRef.
      }
    }
  }

  ?entry skos:exactMatch ?UNIPROT.
  ?entry :isoform ?iso.
  ?iso :goMolecularFunction / :term ?gomf .
  ?gomf rdfs:label ?gomflab .
} group by ?gomf ?gomflab having(count (distinct ?entry) > 4)
order by desc(?ecnt)''' ;
  spex:federatesWith <https://www.ebi.ac.uk/rdf/services/sparql/> , <https://idsm.elixir-czech.cz/sparql/endpoint/chembl>.
