Import information from NCBI SRA into a RDF model.
[htsworkflow.git] / htsworkflow / templates / sra.rdfxml.xsl
1 <?xml version="1.0"?>
2 <xsl:stylesheet version="1.0"
3                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4                 xmlns:xs="http://www.w3.org/2001/XMLSchema#"
5                 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6                 xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
7                 xmlns:submission="http://jumpgate.caltech.edu/wiki/UcscSubmissionOntology#"
8                 xmlns:sra="http://www.ncbi.nlm.nih.gov/sra"
9                 xmlns:sras="http://www.ncbi.nlm.nih.gov/viewvc/v1/trunk/sra/doc/SRA_1-3/SRA.package.xsd#"
10                 xmlns:sraa="http://www.ncbi.nlm.nih.gov/viewvc/v1/trunk/sra/doc/SRA_1-3/SRA.attribute#"
11                 >
12
13 <xsl:output method="xml" indent="yes"/>
14
15 <xsl:template match="/">
16   <rdf:RDF xmlns:ddf="http://encodesubmit.ucsc.edu/pipeline/download_ddf#"
17            xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
18            xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
19            xmlns:submission="http://jumpgate.caltech.edu/wiki/UcscSubmissionOntology#"
20            xmlns:pipeline="http://encodesubmit.ucsc.edu/pipeline/"
21            xmlns:sra="http://www.ncbi.nlm.nih.gov/sra"
22            xmlns:sras="http://www.ncbi.nlm.nih.gov/viewvc/v1/trunk/sra/doc/SRA_1-3/SRA.package.xsd#"
23            xmlns:sraa="http://www.ncbi.nlm.nih.gov/viewvc/v1/trunk/sra/doc/SRA_1-3/SRA.attribute#"
24 >
25     <xsl:apply-templates select="*"/>
26   </rdf:RDF>
27 </xsl:template>
28
29 <xsl:template match="EXPERIMENT_PACKAGE">
30   <xsl:apply-templates select="./EXPERIMENT"/>
31   <!-- xsl:for-each select="./EXPERIMENT/EXPERIMENT_ATTRIBUTES/EXPERIMENT_ATTRIBUTE">
32     <xsl:call-template name="node_detail"/>
33   </xsl:for-each -->
34   <xsl:apply-templates select="./SUBMISSION"/>
35   <xsl:apply-templates select="./STUDY"/>
36   <xsl:apply-templates select="./SAMPLE"/>
37   <!-- xsl:for-each select="./SAMPLE/SAMPLE_ATTRIBUTES/SAMPLE_ATTRIBUTE">
38     <xsl:call-template name="node_detail"/>
39   </xsl:for-each -->
40   <xsl:apply-templates select="./RUN_SET"/>
41 </xsl:template>
42
43 <xsl:template match="EXPERIMENT">
44   <sras:experiment>
45     <xsl:attribute name="rdf:about">http://www.ncbi.nlm.nih.gov/sra/<xsl:value-of select="@accession"/></xsl:attribute>
46     <sras:experiment_alias><xsl:value-of select="@alias"/></sras:experiment_alias>
47     <sras:center_name><xsl:value-of select="@center_name"/></sras:center_name>
48     <xsl:apply-templates select="STUDY_REF"/>
49     <xsl:apply-templates select="DESIGN"/>
50     <xsl:apply-templates select="PLATFORM"/>
51     <xsl:for-each select="./EXPERIMENT_ATTRIBUTES/EXPERIMENT_ATTRIBUTE">
52       <xsl:call-template name="node_simple"/>
53     </xsl:for-each>
54     <sras:submission>
55       <xsl:attribute name="rdf:resource">http://www.ncbi.nlm.nih.gov/sra/<xsl:value-of select="../SUBMISSION/@accession"/></xsl:attribute>
56     </sras:submission>
57   </sras:experiment>
58 </xsl:template>
59
60 <xsl:template match="STUDY_REF">
61   <sras:study>
62     <xsl:attribute name="rdf:resource">http://www.ncbi.nlm.nih.gov/sra/<xsl:value-of select="@accession"/></xsl:attribute>
63   </sras:study>
64 </xsl:template>
65
66 <xsl:template match="DESIGN">
67   <xsl:apply-templates select="SAMPLE_DESCRIPTOR"/>
68   <xsl:apply-templates select="LIBRARY_DESCRIPTOR"/>
69 </xsl:template>
70
71 <xsl:template match="SAMPLE_DESCRIPTOR">
72   <sras:sample>
73     <xsl:attribute name="rdf:resource">http://www.ncbi.nlm.nih.gov/sra/<xsl:value-of select="@accession"/></xsl:attribute>
74   </sras:sample>
75 </xsl:template>
76
77 <xsl:template match="LIBRARY_DESCRIPTOR">
78   <sras:library_name><xsl:value-of select="LIBRARY_NAME"/></sras:library_name>
79   <sras:library_strategy><xsl:value-of select="LIBRARY_STRATEGY"/></sras:library_strategy>
80   <sras:library_source><xsl:value-of select="LIBRARY_SOURCE"/></sras:library_source>
81   <sras:library_selection><xsl:value-of select="LIBRARY_SELECTION"/></sras:library_selection>
82   <sras:library_protocol>
83     <xsl:attribute name="rdf:resource">http:<xsl:value-of select="substring-after(LIBRARY_CONSTRUCTION_PROTOCOL, 'http')"/></xsl:attribute></sras:library_protocol>
84 </xsl:template>
85
86 <xsl:template match="PLATFORM">
87   <sras:instrument_model><xsl:value-of select="ILLUMINA/INSTRUMENT_MODEL"/></sras:instrument_model>
88   <sras:sequence_length rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal"><xsl:value-of select="ILLUMINA/SEQUENCE_LENGTH"/></sras:sequence_length>
89 </xsl:template>
90
91 <!-- xsl:template select="EXPERIMENT" mode="ref" -->
92 <xsl:template name="node_ref">
93   <sras:has_attribute>
94     <xsl:attribute rdf:name="rdf:nodeID"><xsl:value-of select="generate-id(node())"/></xsl:attribute>
95   </sras:has_attribute>
96 </xsl:template>
97
98 <!-- xsl:template name="attribute" mode="nodedetail" -->
99 <xsl:template name="node_detail">
100   <sras:attribute>
101     <xsl:attribute rdf:name="rdf:nodeID"><xsl:value-of select="generate-id(node())"/></xsl:attribute>
102     <sras:attribute_name><xsl:value-of select="TAG"/></sras:attribute_name>
103   </sras:attribute>
104   <sras:attribute>
105     <xsl:attribute rdf:name="rdf:nodeID"><xsl:value-of select="generate-id(node())"/></xsl:attribute>
106     <sras:attribute_value><xsl:value-of select="VALUE"/></sras:attribute_value>
107   </sras:attribute>
108 </xsl:template>
109
110 <!-- try to generate attributes with non blank nodes -->
111 <xsl:template name="node_simple">
112   <xsl:variable name="spacelessTag">
113     <xsl:call-template name="string-replace-all">
114       <xsl:with-param name="text" select="TAG" />
115       <xsl:with-param name="replace" select="' '" />
116       <xsl:with-param name="by" select="'_'" />
117     </xsl:call-template>
118   </xsl:variable>
119   <xsl:element name="sraa:{$spacelessTag}"><xsl:value-of select="VALUE"/></xsl:element>
120 </xsl:template>
121
122 <!-- SUBMISSION TOP LEVEL -->
123 <xsl:template match="SUBMISSION">
124   <sras:submission>
125     <xsl:attribute name="rdf:about">http://www.ncbi.nlm.nih.gov/sra/<xsl:value-of select="@accession"/></xsl:attribute>
126     <sras:alias><xsl:value-of select="@alias"/></sras:alias>
127     <sras:comment><xsl:value-of select="@submission_comment"/></sras:comment>
128     <sras:date rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"><xsl:value-of select="@submission_date"/></sras:date>
129     <sras:lab_name><xsl:value-of select="@lab_name"/></sras:lab_name>
130     <sras:accession><xsl:value-of select="@accession"/></sras:accession>
131   </sras:submission>
132 </xsl:template>
133
134 <xsl:template match="STUDY">
135   <sras:study>
136     <xsl:attribute name="rdf:about">http://www.ncbi.nlm.nih.gov/sra/<xsl:value-of select="@accession"/></xsl:attribute>
137     <sras:study_alias><xsl:value-of select="@alias"/></sras:study_alias>
138     <sras:title><xsl:value-of select="DESCRIPTOR/STUDY_TITLE"/></sras:title>
139     <sras:description><xsl:value-of select="normalize-space(DESCRIPTOR/STUDY_DESCRIPTION)"/></sras:description>
140   </sras:study>
141 </xsl:template>
142
143 <xsl:template match="SAMPLE">
144   <sras:sample>
145     <xsl:attribute name="rdf:about">http://www.ncbi.nlm.nih.gov/sra/<xsl:value-of select="@accession"/></xsl:attribute>
146     <sras:sample_alias><xsl:value-of select="@alias"/></sras:sample_alias>
147     <sras:common_name><xsl:value-of select="SAMPLE_NAME/COMMON_NAME"/></sras:common_name>
148     <sras:description><xsl:value-of select="DESCRIPTION"/></sras:description>
149     <xsl:for-each select="./SAMPLE_ATTRIBUTES/SAMPLE_ATTRIBUTE">
150       <xsl:call-template name="node_simple"/>
151     </xsl:for-each>
152   </sras:sample>
153 </xsl:template>
154 <xsl:template match="RUN_SET">
155 </xsl:template>
156
157 <!-- from http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx -->
158 <xsl:template name="string-replace-all">
159     <xsl:param name="text" />
160     <xsl:param name="replace" />
161     <xsl:param name="by" />
162     <xsl:choose>
163       <xsl:when test="contains($text, $replace)">
164         <xsl:value-of select="substring-before($text,$replace)" />
165         <xsl:value-of select="$by" />
166         <xsl:call-template name="string-replace-all">
167           <xsl:with-param name="text"
168           select="substring-after($text,$replace)" />
169           <xsl:with-param name="replace" select="$replace" />
170           <xsl:with-param name="by" select="$by" />
171         </xsl:call-template>
172       </xsl:when>
173       <xsl:otherwise>
174         <xsl:value-of select="$text" />
175       </xsl:otherwise>
176     </xsl:choose>
177   </xsl:template>
178
179 </xsl:stylesheet>