@prefix ex: <https://kg.earthmetabolome.org/metrin/api/.well-known/examples/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

ex:004 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "For features from Melochia umbellata in positive ionization mode with SIRIUS annotations, get the ones for which a feature in negative ionization mode with the same retention time (± 3 sec) has the same SIRIUS annotation (2D InChIKey)."@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX emi: <https://w3id.org/emi#>
PREFIX sosa: <http://www.w3.org/ns/sosa/>

SELECT DISTINCT ?feature ?feature_opp ?ik2d ?rt ?rt_opp
WHERE {
    VALUES ?rt_tol {
        "0.05"^^xsd:decimal # RT tolerance (minute)
    }
    ?sample a emi:ExtractSample ;
        sosa:isSampleOf* ?organe .
    ?organe emi:inTaxon ?taxon .
    ?taxon rdfs:label "melochia umbellata" .
    ?sample sosa:isFeatureOfInterestOf ?lcms .
    ?lcms a emi:LCMSAnalysisPos ;
        sosa:hasResult ?feature_list .
    ?feature_list emi:hasLCMSFeature ?feature .
    ?feature emi:hasRetentionTime ?rt ;
        emi:hasAnnotation ?sirius .
    ?sirius a emi:StructuralAnnotation ;
        prov:wasGeneratedBy ?activity .
    ?activity prov:wasAssociatedWith <https://bio.informatik.uni-jena.de/software/sirius> .
    ?sirius emi:hasChemicalStructure ?ik2d .
    ?sample sosa:isFeatureOfInterestOf ?lcms_opp .
    ?lcms_opp a emi:LCMSAnalysisNeg ;
        sosa:hasResult ?feature_list_opp .
    ?feature_list_opp emi:hasLCMSFeature ?feature_opp .
    ?feature_opp emi:hasRetentionTime ?rt_opp ;
        emi:hasAnnotation ?sirius_opp .
    ?sirius_opp a emi:StructuralAnnotation ;
    #    prov:wasGeneratedBy ?activity_opp ;
        emi:hasChemicalStructure ?ik2d .
    #?activity_opp prov:wasAssociatedWith <https://bio.informatik.uni-jena.de/software/sirius> .
    FILTER(((?rt - ?rt_tol) < ?rt_opp) && ((?rt + ?rt_tol) > ?rt_opp))
}""" ;
    schema:target <https://kg.earthmetabolome.org/metrin/api/> .

