#
# example SPARQL query 110
#

@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_110 a sh:SPARQLExecutable ;
    sh:prefixes _:sparql_examples_prefixes ;
    rdfs:comment """STR (short tandem repeat) profile of a chosen cell line"""@en ; 
    schema:keywords "STR" , "short tandem repeat profile" , "source" ; 
    schema:target <https://sparql.cellosaurus.org/sparql> ; 
    sh:select """
PREFIX cello: <https://purl.expasy.org/cellosaurus/rdf/ontology/>
PREFIX cvcl: <https://purl.expasy.org/cellosaurus/rdf/cvcl/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?cl ?cl_name ?marker ?detected ?repeat_num ?conflicting (group_concat(distinct ?source; separator=' ') as ?sources)
where {
  values ?cl { cvcl:CVCL_0025 }
  ?cl cello:recommendedName ?cl_name .
  ?cl cello:hasShortTandemRepeatProfile / cello:includesObservation ?obs .
  ?obs rdfs:label ?obs_name .
  ?obs cello:conflicting ?conflict .
  ?obs cello:hasTarget ?trg .
  optional { ?trg rdfs:label ?trg_label . }
  optional { ?trg cello:markerId ?trg_id . }
  bind(coalesce(?trg_label, ?trg_id) as ?marker)
  optional { ?obs cello:detectedTarget ?dt . }
  optional { ?obs cello:detectedAllele / cello:repeatNumber ?allele . }
  optional {
    ?obs cello:hasSource ?s .
  	optional { ?s cello:originatesFrom / a ?st }.
   	optional { ?s cello:originatesFrom / cello:internalId ?id }   	# src origin is a xref or a publi
    optional { ?s cello:originatesFrom / skos:prefLabel ?org }      # src origin is an organization
    optional { ?s rdfs:label ?lb }                                  # src origin not specified
  }
  bind (coalesce(?id, ?org, ?lb, '-') as ?source)
  bind (coalesce(?st, '-') as ?source_type)
  bind (if(bound(?dt), if(?dt=1, 'yes', 'no'), 'n/a') as ?detected)
  bind (if(bound(?allele), concat('n=',?allele), 'n/a') as ?repeat_num)
  bind (if(?conflict, 'yes', 'no') as ?conflicting)
}
group by ?cl ?cl_name ?obs_name ?marker ?detected ?repeat_num ?conflicting
order by ?cl ?cl_name ?obs_name ?marker ?detected ?repeat_num ?conflicting
limit 500
    """
    .

