@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:37 a sh:SPARQLExecutable,
        sh:SPARQLSelectExecutable ;
    rdfs:label "Lipids with the same components, positions"@en ;
    rdfs:comment """Returns the list of isomeric subspecies that contain the same fatty acid component(s) at the same position(s) as a user-defined lipid.
The user supplies a lipid ID, from which we first retrieve the fatty acids and their positions, after which we search for other lipids with the same combination of fatty acids at the same positions.
This query could be useful in the website (classification tab): for a given lipid, provide a list of the other lipids with the same “tail”
e.g. for PA(16:0/18:1(9Z)) => hexadecanoate@sn1 AND (9Z)-octadecenoate@sn2 => PC(16:0/18:1(9Z)), PE(16:0/18:1(9Z)), PG(16:0/18:1(9Z)), PI(16:0/18:1(9Z)), PIP[3](16:0/18:1(9Z)), PIP[4](16:0/18:1(9Z)), PIP[5](16:0/18:1(9Z)), PI2P[3,4](16:0/18:1(9Z)), PI2P[4,5](16:0/18:1(9Z)), PI2P[3,5](16:0/18:1(9Z)), PI3P[3,4,5](16:0/18:1(9Z)), PS(16:0/18:1(9Z))…
Output should include the corresponding SwissLipids ID(s) and name(s)."""@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#>

# Example 37
SELECT ?startId ?startName ?tail1 ?tailName1 ?tail2 ?tailName2 ?id ?name
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 .

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

