Skip to content

Instantly share code, notes, and snippets.

@jvsoest
Last active January 7, 2022 10:59
Show Gist options
  • Save jvsoest/98dee25cb2aadf2780ec9ef21235e82b to your computer and use it in GitHub Desktop.
Save jvsoest/98dee25cb2aadf2780ec9ef21235e82b to your computer and use it in GitHub Desktop.
SPARQL right-censored to binary
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
prefix ncit: <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#>
prefix snomedct: <http://purl.bioontology.org/ontology/SNOMEDCT/>
prefix roo: <http://www.cancerdata.org/roo/>
INSERT {
GRAPH <http://inferred-manually.local/> {
?patient roo:survival_5_years ?survival_5y.
}
}
where {
?patient rdf:type snomedct:116154003;
roo:P100028 [
roo:P100042 ?vital_status_value
];
roo:P100008 [
roo:P100311 [
rdf:type snomedct:445320007;
roo:P100042 ?vital_status_days;
];
].
# Determine the time interval to make binary
BIND( xsd:boolean(IF(?vital_status_days > 1825, "true", "false")) AS ?gt_5y).
# Make the outcome (survival) binary
BIND( xsd:boolean(IF(?vital_status_value = xsd:integer("0"), "true", "false")) AS ?survived).
# In the case when survival is less than time interval, AND survival true we need to make this unknown.
# In all other situations we can make the bind (hence testing the exemption case and the negation to make the bind in the end)
OPTIONAL {
FILTER ( !( (?gt_5y = xsd:boolean("false")) && (?survived = xsd:boolean("true")) ) )
BIND( xsd:boolean(IF(?survived && ?gt_5y, "true", "false")) AS ?survival_5y).
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment