@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:008 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:comment "Which features in the positive ionization mode have the most fragments and neutral losses in common with the feature identified as mzspec:MSV000087728:VGF143_H08_features_ms2_pos.mgf:scan:707"@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX emi: <https://w3id.org/emi#>
PREFIX sosa: <http://www.w3.org/ns/sosa/>

SELECT ?feature ?massive_doi (SAMPLE(?rt) AS ?retention_time) (SAMPLE(?pm) AS ?parent_mass) (COUNT(?peakloss) AS ?count)
WHERE {
    ?lcms a emi:LCMSAnalysisPos ;
        emi:hasMassiveDOI ?massive_doi ;
        sosa:hasResult ?feature_list .
    #FILTER(regex(str(?massive_doi), "MSV000087728")) # MassIVE id filter
    ?feature_list emi:hasLCMSFeature ?feature .
    ?feature a emi:LCMSFeature ;
        emi:hasSpec2VecDoc ?doc ;
        emi:hasParentMass ?pm ;
        emi:hasRetentionTime ?rt .
    ?doc emi:hasSpec2VecLoss|emi:hasSpec2VecPeak ?peakloss .

    {
        SELECT ?peakloss WHERE {
            ?feature a emi:LCMSFeature ;
                emi:hasUSI "mzspec:MSV000087728:VGF143_H08_features_ms2_pos.mgf:scan:707" ;
                emi:hasSpec2VecDoc ?doc .
            ?doc emi:hasSpec2VecLoss|emi:hasSpec2VecPeak ?peakloss .
        }
    }
} GROUP BY ?feature ?massive_doi ORDER BY DESC(?count)""" ;
    schema:target <https://kg.earthmetabolome.org/metrin/api/> .

