comparison spacexr_cside.xml @ 0:2b1797b4cbb1 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/spacexr commit c6f85f5bd2c9dee114640a4e4007852c060e10ca
author iuc
date Tue, 28 Jan 2025 09:44:07 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2b1797b4cbb1
1 <tool id="spacexr_cside" name="CSIDE" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
2 <description>Cell type-specific differential expression with C-SIDE</description>
3 <macros>
4 <import>macros.xml</import>
5 </macros>
6 <expand macro="edam"/>
7 <expand macro="requirements">
8 <requirement type="package" version="3.5.1">r-ggplot2</requirement>
9 </expand>
10 <command detect_errors="exit_code"><![CDATA[
11 export GALAXY_SLOTS=2 &&
12 mkdir -p 'inputs' 'results' 'logs' 'figures' &&
13 ln -s '$rctd' 'inputs/rctd.rds' &&
14 #if $type.de_type == 'point_density':
15 ln -s '$barcodes' 'inputs/barcodes.tabular' &&
16 #end if
17 #if $type.de_type == 'custom':
18 ln -s '$barcodes' 'inputs/barcodes.tabular' &&
19 #end if
20 touch 'results/cside_script.R' &&
21 cat '$cside_script' > 'results/cside_script.R' &&
22 Rscript 'results/cside_script.R'
23 ]]></command>
24 <configfiles>
25 <configfile name="cside_script"><![CDATA[
26 #if $type.cell_types != '':
27 #set $cell_types_list = ['"' + str(x.strip()) + '"' for x in str($type.cell_types).split(',')]
28 #set $cell_types = ','.join($cell_types_list)
29 #end if
30 #if str($type.cell_types_present) != '':
31 #set $cell_types_present_list = ['"' + str(x.strip()) + '"' for x in str($type.cell_types_present).split(',')]
32 #set $cell_types_present = ','.join($cell_types_present_list)
33 #end if
34 # cside script
35 # This file is used to specify the parameters for the cside from spacexr package
36
37 # Load the spacexr library
38 library('spacexr')
39 library('Matrix')
40 library('doParallel')
41
42 # load RCTD object
43 myRCTD <- readRDS('inputs/rctd.rds')
44
45 # set max cores
46 cores = Sys.getenv("GALAXY_SLOTS", unset= NA)
47 if (is.na(cores) || !nzchar(cores)) {
48 cores = 1
49 }
50 myRCTD@config[["max_cores"]] <- as.numeric(cores)
51 print(paste("Using", cores, "cores"))
52
53 # CSIDE
54 #if str($type.de_type) == 'non_parametric':
55 myRCTD <- run.CSIDE.nonparam(myRCTD,
56 df = $type.df,
57 barcodes = NULL, # use all barcodes
58 CSIDE_COMMON_RUN
59 )
60
61 #else if str($type.de_type) == 'point_density':
62 barcodes <- read.delim('inputs/barcodes.tabular', header = FALSE, sep = '\t', check.names = FALSE)
63 barcodes <- barcodes[,1]
64 pathogen_coords <- myRCTD@spatialRNA@coords[barcodes,]
65 barcodes <- colnames(myRCTD@spatialRNA@counts)
66 explanatory.variable <- exvar.point.density(myRCTD,
67 barcodes,
68 pathogen_coords,
69 radius = $type.radius
70 )
71 CSIDE_SINGLE_RUN
72
73
74 #else if str($type.de_type) == 'cell2cell':
75 barcodes <- colnames(myRCTD@spatialRNA@counts)
76 explanatory.variable <- exvar.celltocell.interactions(myRCTD,
77 barcodes,
78 '$type.cell_type',
79 radius = $type.radius
80 )
81 CSIDE_SINGLE_RUN
82
83
84 #else if str($type.de_type) == 'XY':
85 #if str($type.xy) == 'X':
86 explanatory.variable <- as.integer(myRCTD@spatialRNA@coords[['x']] > $type.lim)
87 names(explanatory.variable) <- rownames(myRCTD@spatialRNA@coords)
88
89 #else
90 explanatory.variable <- as.integer(myRCTD@spatialRNA@coords[['y']] > $type.lim)
91 names(explanatory.variable) <- rownames(myRCTD@spatialRNA@coords)
92 #end if
93 CSIDE_SINGLE_RUN
94
95 #else:
96 barcodes_df <- read.delim('inputs/barcodes.tabular', header = FALSE, sep = '\t', check.names = FALSE)
97 region_list <- list()
98 for (i in 1:ncol(barcodes_df)) {
99 region <- barcodes_df[, i]
100 region <- region[region != "" & !is.na(region)]
101 region_list[[i]] <- region
102 }
103
104 myRCTD <- run.CSIDE.regions(myRCTD,
105 region_list,
106 log_fc_thresh = $type.log_FC_thresh,
107 CSIDE_COMMON_RUN
108 )
109 #end if
110
111
112 # save the results
113
114 # save significant genes in each cell type
115 cell_types <- names(myRCTD@de_results[["sig_gene_list"]])
116 for (cell_type in cell_types) {
117 df <- myRCTD@de_results[["sig_gene_list"]][[cell_type]]
118 assign(cell_type, df)
119 write.table(df, file = paste0("results/", cell_type, "_sig.tabular"), sep = "\t", quote = FALSE)
120 }
121 # save all genes in each cell type
122 cell_types <- names(myRCTD@de_results[["all_gene_list"]])
123 for (cell_type in cell_types) {
124 df <- myRCTD@de_results[["all_gene_list"]][[cell_type]]
125 assign(cell_type, df)
126 write.table(df, file = paste0("results/", cell_type, ".tabular"), sep = "\t", quote = FALSE)
127 }
128
129 #if 'plots' in $output_selector:
130 # create plots
131 library('ggplot2')
132 make_all_de_plots(myRCTD, "figures")
133 #end if
134
135 #if 'rds' in $output_selector:
136 # save rds file
137 saveRDS(myRCTD, file = 'results/cside_results.rds')
138 #end if
139 ]]></configfile>
140 </configfiles>
141 <inputs>
142 <param name="rctd" type="data" format="rds" label="RCTD object" help="annotated RCTD object"/>
143 <conditional name="type">
144 <param name="de_type" type="select" label="Type of covariates for explaining differential expression with C-SIDE">
145 <option value="non_parametric">Smooth spatial pattern (non-non_parametric)</option>
146 <option value="point_density">Proximity to pathology</option>
147 <option value="cell2cell">Cell-to-cell interaction</option>
148 <option value="XY">define X or Y axis</option>
149 <option value="custom">Custom spatial locations</option>
150 </param>
151 <when value="non_parametric">
152 <param argument="df" type="integer" min="0" value="15" label="Degrees of freedom" help="The degrees of freedom, or number of basis functions to be used in the model."/>
153 <expand macro="cside_common_input"/>
154 </when>
155 <when value="point_density">
156 <expand macro="barcodes_input" label="One-column list of spatial barcodes" help="Only barcodes in first column will be used."/>
157 <expand macro="radius"/>
158 <expand macro="cside_single_input"/>
159 </when>
160 <when value="cell2cell">
161 <param name="cell_type" type="text" optional="false" label="Cell type for which to compute density">
162 <expand macro="sanitizer"/>
163 </param>
164 <expand macro="radius"/>
165 <expand macro="cside_single_input"/>
166 </when>
167 <when value="XY">
168 <param name="lim" type="integer" value="" optional="false" label="Axis" help="The number on X or Y axis to discriminate two spatial regions"/>
169 <param name="xy" type="boolean" truevalue="X" falsevalue="Y" checked="true" label="Is the number on X axis?"/>
170 <expand macro="cside_single_input"/>
171 </when>
172 <when value="custom">
173 <expand macro="barcodes_input" label="Tabular list of spatial barcodes" help="At least 3 regions should be specified"/>
174 <expand macro="cside_common_input"/>
175 <param argument="log_FC_thresh" type="float" min="0" value="0.4" label="logFC cutoff for differential expression"/>
176 </when>
177 </conditional>
178 <expand macro="output">
179 <option value="plots">DEG plots</option>
180 <option value="log">log File</option>
181 </expand>
182 </inputs>
183 <outputs>
184 <collection name="de_results" type="list" label="${tool.name} on ${on_string}: DE Results">
185 <discover_datasets pattern="(?P&lt;name&gt;.+)\.tabular$" format="tabular" directory="results"/>
186 </collection>
187 <collection name="de_plots" type="list" label="${tool.name} on ${on_string}: DE plots">
188 <discover_datasets pattern="(?P&lt;name&gt;.+)\.pdf$" format="pdf" directory="figures/de_plots"/>
189 <filter>output['output_selector'] and 'plots' in output['output_selector']</filter>
190 </collection>
191 <collection name="de_plots_quant" type="list" label="${tool.name} on ${on_string}: DE plots (quant)">
192 <discover_datasets pattern="(?P&lt;name&gt;.+)\.pdf$" format="pdf" directory="figures/de_plots_quant"/>
193 <filter>output['output_selector'] and 'plots' in output['output_selector']</filter>
194 </collection>
195 <collection name="de_plots_two_regions" type="list" label="${tool.name} on ${on_string}: DE plots (two regions)">
196 <discover_datasets pattern="(?P&lt;name&gt;.+)\.pdf$" format="pdf" directory="figures/de_plots_two_regions"/>
197 <filter>output['output_selector'] and 'plots' in output['output_selector']</filter>
198 </collection>
199 <data name="out_rds" format="rds" from_work_dir="results/cside_results.rds" label="${tool.name} on ${on_string}: RDS file">
200 <filter>output['output_selector'] and 'rds' in output['output_selector']</filter>
201 </data>
202 <data name="out_rscript" format="txt" from_work_dir="results/cside_script.R" label="${tool.name} on ${on_string}: RScript">
203 <filter>output['output_selector'] and 'rscript' in output['output_selector']</filter>
204 </data>
205 <data name="out_log" format="txt" from_work_dir="logs/de_log.txt" label="${tool.name} on ${on_string}: Log">
206 <filter>output['output_selector'] and 'log' in output['output_selector']</filter>
207 </data>
208 </outputs>
209 <tests>
210 <!-- test non_parametric -->
211 <test expect_num_outputs="2">
212 <param name="rctd" location="https://zenodo.org/records/14642119/files/myRCTD_merfish.rds"/>
213 <param name="de_type" value="non_parametric"/>
214 <param name="cell_types" value="Astrocytes"/>
215 <param name="cell_type_threshold" value="10"/>
216 <param name="gene_threshold" value="0.001"/>
217 <param name="fdr" value="0.25"/>
218 <param name="output_selector" value="rscript" />
219 <output_collection name="de_results" type="list">
220 <element name="Astrocytes" ftype="tabular">
221 <assert_contents>
222 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val"/>
223 <has_text_matching expression="Gad1.*3.8390[0-9].*-3.6943[0-9].*0.9623[0-9].*6.*TRUE.*0.0017[0-9]"/>
224 </assert_contents>
225 </element>
226 <element name="Astrocytes_sig" ftype="tabular">
227 <assert_contents>
228 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val"/>
229 <has_text_matching expression="Glra3.*3.9271[0-9].*-7.2991[0-9].*1.8586[0-9].*8.*TRUE.*0.0012[0-9]"/>
230 </assert_contents>
231 </element>
232 </output_collection>
233 <output name="out_rscript">
234 <assert_contents>
235 <has_text_matching expression="run.CSIDE.nonparam"/>
236 </assert_contents>
237 </output>
238 </test>
239 <!-- test fig and rds -->
240 <test expect_num_outputs="7">
241 <param name="rctd" location="https://zenodo.org/records/14642119/files/myRCTD_merfish.rds"/>
242 <param name="de_type" value="non_parametric"/>
243 <param name="cell_types" value="Astrocytes"/>
244 <param name="cell_type_threshold" value="10"/>
245 <param name="gene_threshold" value="0.001"/>
246 <param name="fdr" value="0.25"/>
247 <param name="output_selector" value="rds,rscript,plots,log" />
248 <output_collection name="de_results" type="list">
249 <element name="Astrocytes" ftype="tabular">
250 <assert_contents>
251 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val"/>
252 <has_text_matching expression="Gad1.*3.8390[0-9].*-3.6943[0-9].*0.9623[0-9].*6.*TRUE.*0.0017[0-9]"/>
253 </assert_contents>
254 </element>
255 <element name="Astrocytes_sig" ftype="tabular">
256 <assert_contents>
257 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val"/>
258 <has_text_matching expression="Glra3.*3.9271[0-9].*-7.2991[0-9].*1.8586[0-9].*8.*TRUE.*0.0012[0-9]"/>
259 </assert_contents>
260 </element>
261 </output_collection>
262 <output_collection name="de_plots" type="list">
263 <element name="de_genes_Astrocytes" location="https://zenodo.org/records/14642119/files/de_genes_Astrocytes.pdf" ftype="pdf" compare="sim_size"/>
264 </output_collection>
265 <output_collection name="de_plots_quant" type="list">
266 <element name="de_genes_Astrocytes" location="https://zenodo.org/records/14642119/files/de_genes_Astrocytes_quant.pdf" ftype="pdf" compare="sim_size"/>
267 </output_collection>
268 <output_collection name="de_plots_two_regions" type="list">
269 <element name="de_genes_Astrocytes" location="https://zenodo.org/records/14642119/files/de_genes_Astrocytes_two_regions" ftype="pdf" compare="sim_size"/>
270 </output_collection>
271 <output name="out_rds" location="https://zenodo.org/records/14642119/files/cside.rds" ftype="rds" compare="sim_size"/>
272 <output name="out_rscript">
273 <assert_contents>
274 <has_text_matching expression="run.CSIDE.nonparam"/>
275 </assert_contents>
276 </output>
277 <output name="out_log">
278 <assert_contents>
279 <has_text_matching expression="Testing sample: 1 gene Rnd3"/>
280 </assert_contents>
281 </output>
282 </test>
283 <!-- test point_density -->
284 <test expect_num_outputs="3">
285 <param name="rctd" location="https://zenodo.org/records/14642119/files/myRCTD_merfish.rds"/>
286 <param name="de_type" value="point_density"/>
287 <param name="barcodes" location="https://zenodo.org/records/14642119/files/barcode.tabular"/>
288 <param name="cell_types" value="Astrocytes"/>
289 <param name="cell_type_threshold" value="10"/>
290 <param name="gene_threshold" value="0.001"/>
291 <param name="fdr" value="0.25"/>
292 <param name="output_selector" value="rscript,log" />
293 <output_collection name="de_results" type="list">
294 <element name="Astrocytes" ftype="tabular">
295 <assert_contents>
296 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val.*mean_0.*mean_1.*sd_0.*sd_1"/>
297 <has_text_matching expression="Gad1.*0.0155[0-9].*0.0088[0-9].*0.5666[0-9].*2.*TRUE.*0.9876[0-9].*-4.9869[0-9].*-4.9781[0-9].*0.2504[0-9].*0.5083[0-9]"/>
298 </assert_contents>
299 </element>
300 <element name="Astrocytes_sig" ftype="tabular">
301 <assert_contents>
302 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val.*mean_0.*mean_1.*sd_0.*sd_1"/>
303 </assert_contents>
304 </element>
305 </output_collection>
306 <output name="out_rscript">
307 <assert_contents>
308 <has_text_matching expression="exvar.point.density"/>
309 </assert_contents>
310 </output>
311 <output name="out_log">
312 <assert_contents>
313 <has_text_matching expression="Testing sample: 2 gene Gad1"/>
314 </assert_contents>
315 </output>
316 </test>
317 <!-- test cell2cell -->
318 <test expect_num_outputs="3">
319 <param name="rctd" location="https://zenodo.org/records/14642119/files/myRCTD_merfish.rds"/>
320 <param name="de_type" value="cell2cell"/>
321 <param name="cell_type" value="Excitatory"/>
322 <param name="cell_types" value="Astrocytes"/>
323 <param name="cell_type_threshold" value="10"/>
324 <param name="gene_threshold" value="0.001"/>
325 <param name="fdr" value="0.25"/>
326 <param name="output_selector" value="rscript,log" />
327 <output_collection name="de_results" type="list">
328 <element name="Astrocytes" ftype="tabular">
329 <assert_contents>
330 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val.*mean_0.*mean_1.*sd_0.*sd_1"/>
331 <has_text_matching expression="Gad1.*1.2142[0-9].*-0.9565[0-9].*0.7877[0-9].*2.*TRUE.*0.2246[0-9].*-4.6413[0-9].*-5.5978[0-9].*0.3508[0-9].*0.7053[0-9]"/>
332 </assert_contents>
333 </element>
334 <element name="Astrocytes_sig" ftype="tabular">
335 <assert_contents>
336 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val.*mean_0.*mean_1.*sd_0.*sd_1"/>
337 <has_text_matching expression="Pgr.*3.6958[0-9].*2.4095[0-9].*0.6519[0-9].*2.*TRUE.*0.0002[0-9].*-7.2097[0-9].*-4.8002[0-9].*0.3666[0-9].*0.5390[0-9]"/>
338 </assert_contents>
339 </element>
340 </output_collection>
341 <output name="out_rscript">
342 <assert_contents>
343 <has_text_matching expression="exvar.celltocell.interactions"/>
344 </assert_contents>
345 </output>
346 <output name="out_log">
347 <assert_contents>
348 <has_text_matching expression="Testing sample: 1 gene Rnd3"/>
349 </assert_contents>
350 </output>
351 </test>
352 <!-- test XY -->
353 <test expect_num_outputs="3">
354 <param name="rctd" location="https://zenodo.org/records/14642119/files/myRCTD_merfish.rds"/>
355 <param name="de_type" value="XY"/>
356 <param name="lim" value="2000"/>
357 <param name="xy" value="X"/>
358 <param name="cell_types" value="Astrocytes"/>
359 <param name="cell_type_threshold" value="10"/>
360 <param name="gene_threshold" value="0.001"/>
361 <param name="fdr" value="0.25"/>
362 <param name="output_selector" value="rscript,log" />
363 <output_collection name="de_results" type="list">
364 <element name="Astrocytes" ftype="tabular">
365 <assert_contents>
366 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val.*mean_0.*mean_1.*sd_0.*sd_1"/>
367 <has_text_matching expression="Gad1.*0.7420[0-9].*-0.3333[0-9].*0.4492[0-9].*2.*TRUE.*0.4580[0-9].*-4.7997[0-9].*-5.1331[0-9].*0.3343[0-9].*0.3000[0-9]"/>
368 </assert_contents>
369 </element>
370 <element name="Astrocytes_sig" ftype="tabular">
371 <assert_contents>
372 <has_text_matching expression="Z_score.*log_fc.*se.*paramindex_best.*conv.*p_val.*mean_0.*mean_1.*sd_0.*sd_1"/>
373 </assert_contents>
374 </element>
375 </output_collection>
376 <output name="out_rscript">
377 <assert_contents>
378 <has_text_matching expression="explanatory\.variable &lt;- as\.integer\(myRCTD@spatialRNA@coords\[\['x'\]\] &gt; 2000\)"/>
379 </assert_contents>
380 </output>
381 <output name="out_log">
382 <assert_contents>
383 <has_text_matching expression="Testing sample: 1 gene Rnd3"/>
384 </assert_contents>
385 </output>
386 </test>
387 <!-- test custom -->
388 <test expect_num_outputs="3">
389 <param name="rctd" location="https://zenodo.org/records/14642119/files/myRCTD_merfish.rds"/>
390 <param name="de_type" value="custom"/>
391 <param name="barcodes" location="https://zenodo.org/records/14642119/files/barcodes.tabular"/>
392 <param name="cell_types" value="Inhibitory"/>
393 <param name="cell_type_threshold" value="10"/>
394 <param name="gene_threshold" value="0.001"/>
395 <param name="cell_type_threshold" value="10"/>
396 <param name="fdr" value="0.25"/>
397 <param name="output_selector" value="rscript,log" />
398 <output_collection name="de_results" type="list">
399 <element name="Inhibitory" ftype="tabular">
400 <assert_contents>
401 <has_text_matching expression="sd_lfc.*paramindex1_best.*paramindex2_best.*sd_best.*p_val_best.*log_fc_best.*mean_1.*mean_2.*mean_3.*sd_1.*sd_2.*sd_3"/>
402 <has_text_matching expression="Rnd3.*0.0576[0-9].*1.*3.*0.3116[0-9].*1.*0.1091[0-9].*-5.1913[0-9].*-5.1046[0-9].*-5.0822[0-9].*0.1963[0-9]"/>
403 </assert_contents>
404 </element>
405 <element name="Inhibitory_sig" ftype="tabular">
406 <assert_contents>
407 <has_text_matching expression=""/>
408 </assert_contents>
409 </element>
410 </output_collection>
411 <output name="out_rscript">
412 <assert_contents>
413 <has_text_matching expression="read\.delim\('inputs/barcodes\.tabular'"/>
414 </assert_contents>
415 </output>
416 <output name="out_log">
417 <assert_contents>
418 <has_text_matching expression="Testing sample: 1 gene Rnd3"/>
419 </assert_contents>
420 </output>
421 </test>
422 </tests>
423 <help><![CDATA[
424
425 Cell type-Specific Inference of Differential Expression, or CSIDE, is part of the spacexr R package for learning cell type-specific differential expression from spatial transcriptomics data.
426
427 C-SIDE can detect differential expression (DE) along one or multiple user-defined axes, termed explanatory variables.
428
429 The user should first run RCTD on the data to annotated cell types. and use RCTD object rds file as input.
430
431 The explanatory variable (i.e. covariate) is used for predicting differential expression in CSIDE. In general one should set the explanatory variable to biologically relevant predictors of gene expression such as spatial position.
432
433 The explanatory variable can be defined in several ways:
434
435 * Smooth spatial pattern (non-parametric): This method uses a smooth spatial pattern to explain the differential expression.
436 * Proximity to pathology: This method uses the proximity to pathology (specific spatial locations) to explain the differential expression.
437 * Cell-to-cell interaction: This method uses the cell-to-cell interaction to explain the differential expression. The user should specify the cell type for which to compute density and the radius for the cell-to-cell interaction.
438 * Define X or Y axis: This method uses the X or Y axis to explain the differential expression. The user should specify the axis and the number on the axis to discriminate two spatial regions.
439 * Custom spatial locations: This method uses custom spatial locations to explain the differential expression. The user should specify at least 3 regions containing at least 2 spatial barcodes.
440 ]]></help>
441 <expand macro="citations" />
442 </tool>