new transform to produce Resources for variants and diagnosis
authorTim L <lebot@rpi.edu>
Sun, 06 Feb 2011 23:29:15 -0500
changeset 37 1f34c9bd8fdf
parent 36 1e3b9b02d90e
child 38 c903152963c8
new transform to produce Resources for variants and diagnosis
syntheticPatients/Indivo2Trig.xsl
syntheticPatients/tests/q6.rq
--- a/syntheticPatients/Indivo2Trig.xsl	Wed Feb 02 21:28:17 2011 -0500
+++ b/syntheticPatients/Indivo2Trig.xsl	Sun Feb 06 23:29:15 2011 -0500
@@ -19,6 +19,8 @@
   @prefix cpr: &lt;http://purl.org/cpr/0.75#&gt; .
   @prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
   @prefix ro: &lt;http://www.obofoundry.org/ro/ro.owl#&gt; .
+  @prefix skos: &lt;http://www.w3.org/2004/02/skos/core#&gt; .
+  @prefix dct: &lt;http://purl.org/dc/terms/&gt; .
 {
   &lt;&gt; a cpr:patient-record .
   _:patient cpr:subjectOfDescription &lt;&gt; .
@@ -124,6 +126,7 @@
 <xsl:template match="in:Problem">
   _:patient trans:hasCondition [<xsl:apply-templates mode="problem" select="*"/>
   ] .
+<xsl:apply-templates mode="resources" select="in:name"/>
 </xsl:template>
 
 <xsl:template mode="problem" match="in:dateOnset">
@@ -131,10 +134,18 @@
 </xsl:template>
 
 <xsl:template mode="problem" match="in:name">
-  trans:diagnosedWith "<xsl:value-of select="text()"/>" ;
+   <xsl:variable name="problemL"  select="text()"/>
+   <xsl:variable name="problem"   select="concat(':',lower-case(replace(replace(translate($problemL,' >.:@','_____'),$SQ2,''),$SQ,'')))"/>
+  trans:diagnosedWith <xsl:value-of select="$problem"/> ;
   trans:ICD9 "<xsl:value-of select="@value"/>" ;
 </xsl:template>
 
+<xsl:template mode="resources" match="in:name">
+   <xsl:variable name="problemL"  select="text()"/>
+   <xsl:variable name="problem"   select="concat(':',lower-case(replace(replace(translate($problemL,' >.:@','_____'),$SQ2,''),$SQ,'')))"/>
+   <xsl:value-of select="concat($NL,$problem,' dct:identifier ',$DQ,$problemL,$DQ,' .',$NL)"/>
+</xsl:template>
+
 <xsl:template mode="problem" match="*">
   # unmatched <xsl:value-of select="name()"/>
 </xsl:template>
@@ -147,6 +158,7 @@
     trans:reportedSymptoms "<xsl:value-of select="in:ReportedSymptoms/text()"/>" ;
 <xsl:apply-templates select="in:LabTests/in:Test"/>    
   ] .
+<xsl:apply-templates select="*//in:SNPresult" mode="relate-variants"/>    
 </xsl:template>
 
 <xsl:template match="in:PreliminaryDiagnosis">
@@ -161,14 +173,61 @@
     ] ;
 </xsl:template>
 
+<xsl:template match="in:Test[in:SNPresult]">
+    trans:test [
+        # indivo:dateMeasured <xsl:apply-templates mode="date" select="in:dateMeasured"/> ;
+        a :<xsl:value-of select="replace(replace(in:name/text(),' ','_'),$SQ,'')"/> ;
+        <xsl:apply-templates select="in:result"/><xsl:apply-templates select="in:SNPresult"/>
+    ] ;
+</xsl:template>
+<xsl:variable name="SQ">
+<xsl:text>'</xsl:text>
+</xsl:variable>
+<xsl:variable name="SQ2">
+<xsl:text>’</xsl:text>
+</xsl:variable>
+<xsl:variable name="DQ">
+<xsl:text>"</xsl:text>
+</xsl:variable>
+<xsl:variable name="NL">
+<xsl:text>
+</xsl:text>
+</xsl:variable>
+
 <xsl:template match="in:result">
     # @@not done ;
 </xsl:template>
 
+<!-- Replaced by lebot Jan 2011 
+xsl:template match="in:SNPresult">
+       trans:result [
+           trans:variant_Synonyms "<xsl:value-of select="in:LabTest/in:variant_Synonyms/text()"/>" ;
+       ] ;
+</xsl:template-->
+
 <xsl:template match="in:SNPresult">
-    trans:result [
-        trans:variant_Synonyms "<xsl:value-of select="in:LabTest/in:variant_Synonyms/text()"/>" ;
-    ] ;
+   <xsl:variable name="variant-synonyms" select="tokenize(in:LabTest/in:variant_Synonyms/text(),'[,;]')"/>
+   <xsl:variable name="primary-synonymL"  select="normalize-space($variant-synonyms[1])"/>
+   <xsl:variable name="primary-synonym"   select="concat('variant_',translate($primary-synonymL,'>.:@','____'))"/>
+       trans:result [
+           a :SNPResult ;
+           trans:variant :<xsl:value-of select="$primary-synonym"/> ;
+           trans:present true ;
+       ] ;
+</xsl:template>
+
+<xsl:template match="in:SNPresult" mode="relate-variants">
+   <xsl:variable name="variant-synonyms" select="tokenize(in:LabTest/in:variant_Synonyms/text(),'[,;]')"/>
+   <xsl:variable name="primary-synonymL"  select="normalize-space($variant-synonyms[1])"/>
+   <xsl:variable name="primary-synonym"   select="concat(':variant_',translate($primary-synonymL,'>.:@','____'))"/>
+   <xsl:for-each select="$variant-synonyms">
+      <xsl:if test="position() gt 1">
+         <xsl:variable name="secondary-synonymL"  select="normalize-space(.)"/>
+         <xsl:variable name="secondary-synonym"  select="concat(':variant_',translate($secondary-synonymL,'>.:@','____'))"/>
+         <xsl:value-of select="concat($primary-synonym,  ' skos:relatedMatch ',$secondary-synonym,' .',$NL)"/>
+         <xsl:value-of select="concat($secondary-synonym,' dct:identifier ',$DQ,$secondary-synonymL,$DQ,' .',$NL)"/>
+      </xsl:if>
+   </xsl:for-each>
 </xsl:template>
 
 <!-- Utility templates
@@ -176,4 +235,4 @@
 
 <xsl:template mode="date" match="*">"<xsl:value-of select="text()"/>"<!-- ^^xsd:dateTime --></xsl:template>
 
-</xsl:stylesheet>
\ No newline at end of file
+</xsl:stylesheet>
--- a/syntheticPatients/tests/q6.rq	Wed Feb 02 21:28:17 2011 -0500
+++ b/syntheticPatients/tests/q6.rq	Sun Feb 06 23:29:15 2011 -0500
@@ -1,20 +1,41 @@
 PREFIX trans: <tag:eric@w3.org:2009/tmo/translator#>
 PREFIX foaf: <http://xmlns.com/foaf/0.1/>
 
-SELECT distinct (?name) ?patient ?testname ?apoe4
 
+# Before Tim started doing stuff:
+#WHERE {
+# ?encounter trans:patient ?patient .
+# ?patient foaf:name ?name .
+# ?patient trans:hasCondition ?condition .
+# ?condition trans:diagnosedWith ?diagnosis .
+# FILTER (regex (?diagnosis, "alzheimer", "i"))
+#
+#OPTIONAL {
+# ?encounter trans:test ?test .
+# ?test trans:testName ?testname .
+# ?test trans:result ?result .
+# ?result trans:variant_Synonyms ?apoe4
+# FILTER (regex (?apoe4, "APOE4"))
+#}
+
+SELECT distinct ?patient ?name
 WHERE {
- ?encounter trans:patient ?patient .
- ?patient foaf:name ?name .
- ?patient trans:hasCondition ?condition .
- ?condition trans:diagnosedWith ?diagnosis .
- FILTER (regex (?diagnosis, "alzheimer", "i"))
 
-OPTIONAL {
- ?encounter trans:test ?test .
- ?test trans:testName ?testname .
- ?test trans:result ?result .
- ?result trans:variant_Synonyms ?apoe4
- FILTER (regex (?apoe4, "APOE4"))
+   ?patient 
+      trans:hasCondition [
+         trans:diagnosedWith trans:alzheimers_disease 
+      ]; 
+      foaf:name ?name;
+   .
+
+   OPTIONAL {
+      ?encounter trans:test [
+         a ?testname;
+         trans:result ?result
+      ] . 
+      ?result
+            trans:variant trans:variant_APOE4;
+            trans:present true
+   }
+   FILTER(!bound(?result))
 }
-}