#
# example SPARQL query 101
#

@prefix schema: <https://schema.org/> . 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix sh: <http://www.w3.org/ns/shacl#> . 
@prefix cello: <https://purl.expasy.org/cellosaurus/rdf/ontology/> .


cello:Query_101 a sh:SPARQLExecutable ;
    sh:prefixes _:sparql_examples_prefixes ;
    rdfs:comment """Identifiers and names of cell lines"""@en ; 
    schema:keywords "id" , "sy" , "ac" , "accession" , "name" , "primaryAccession" , "secondaryAccession" , "preferredName" , "alternativeName" ; 
    schema:target <https://sparql.cellosaurus.org/sparql> ; 
    sh:select """
PREFIX cello: <https://purl.expasy.org/cellosaurus/rdf/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?cl ?ac ?recommended_name
(group_concat(str(?old_ac); separator= ' ') as ?old_acs) (group_concat(str(?alt_name); separator= ' ') as ?alternative_names)
where {
  ?cl a / rdfs:subClassOf cello:CellLine .
  ?cl cello:primaryAccession ?ac .                       # cell line accession (ac)
  ?cl cello:recommendedName ?recommended_name .          # cell line preferred name (id)
  optional { ?cl cello:secondaryAccession ?old_ac . }    # cell line obsoleted accession(s)
  optional { ?cl cello:alternativeName ?alt_name . }     # cell line alternative name(s) (sy)
  #filter (bound(?old_ac))
}
group by ?cl ?ac ?recommended_name
limit 100
    """
    .

