@prefix ex: <https://sparql.swisslipids.org/.well-known/sparql-examples/> .
@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#> .

ex:36 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:label "Published lipids by fatty acid component and position"@en ;
    rdfs:comment """Returns the list of isomeric subspecies containing a specific combination of fatty acids at defined positions, but only those isomeric subspecies that are associated with a publication.
If the user supplies a single fatty acid and position (e.g. hexadecanoate at sn1), find all lipids with that fatty acid at that position, irrespective of whether or not there are other fatty acids at positions (here sn2, sn3). 
could generalize this query to allow logical combinations of fatty acids (e.g. hexadecanoate at sn1 AND (9Z)-octadecenoate at sn2, hexadecanoate at sn1 AND NOT (9Z)-octadecenoate at sn2, etc)
Output should include the corresponding SwissLipids ID(s) and name(s) and PMIDs."""@en ;
    sh:prefixes _:sparql_examples_prefixes ;
    sh:select """PREFIX SWISSLIPID: <https://swisslipids.org/rdf/SLM_>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>


SELECT ?startId ?startName ?tail1 ?tailName1 ?tail2 ?tailName2 ?id ?name ?pubmed
WHERE {
  VALUES ?startId { SWISSLIPID:000121946 }
  ?startId rdfs:label ?startName .
  # tail components
  ?startId SWISSLIPID:hasPart ?tail1 .
  ?startId SWISSLIPID:hasPart ?tail2 .
  FILTER(!sameTerm(?tail1, ?tail2))
  ?tail1 rdfs:label ?tailName1 .
  ?tail2 rdfs:label ?tailName2 .

  # Retrieve lipids with similar tails
  ?id SWISSLIPID:hasPart ?tail1 , ?tail2 .
  
  # Restrict to isomeric subspecies with PubMed citation(s)
  ?id SWISSLIPID:rank SWISSLIPID:Isomeric_Subspecies .
  ?id SWISSLIPID:citation ?pubmed .

  # Retrieve name
  ?id rdfs:label ?name .
}
ORDER BY ?id ?tail1 ?tail2""" ;
    schema:target <https://sparql.swisslipids.org/sparql/> .

