comparison segmentation.xml @ 7:4a2ac25d1063 draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit f986c51abe33c7f622d429a3c4a79ee24b33c1f3"
author galaxyp
date Thu, 23 Apr 2020 08:09:32 -0400
parents 9f7d1ec01767
children b591450b3d1c
comparison
equal deleted inserted replaced
6:82f6c2f4332d 7:4a2ac25d1063
1 <tool id="cardinal_segmentations" name="MSI segmentation" version="@VERSION@.3"> 1 <tool id="cardinal_segmentations" name="MSI segmentation" version="@VERSION@.0">
2 <description>mass spectrometry imaging spatial clustering</description> 2 <description>mass spectrometry imaging spatial clustering</description>
3 <macros> 3 <macros>
4 <import>macros.xml</import> 4 <import>macros.xml</import>
5 </macros> 5 </macros>
6 <expand macro="requirements"> 6 <expand macro="requirements">
7 <requirement type="package" version="2.3">r-gridextra</requirement> 7 <requirement type="package" version="2.3">r-gridextra</requirement>
8 <requirement type="package" version="0.20_35">r-lattice</requirement> 8 </expand>
9 </expand>
10 <command detect_errors="exit_code"> 9 <command detect_errors="exit_code">
11 <![CDATA[ 10 <![CDATA[
12 11
13 @INPUT_LINKING@ 12 @INPUT_LINKING@
14 cat '${MSI_segmentation}' && 13 cat '${MSI_segmentation}' &&
17 ]]> 16 ]]>
18 </command> 17 </command>
19 <configfiles> 18 <configfiles>
20 <configfile name="MSI_segmentation"><![CDATA[ 19 <configfile name="MSI_segmentation"><![CDATA[
21 20
22
23 ################################# load libraries and read file ################# 21 ################################# load libraries and read file #################
24 22
25 library(Cardinal) 23 library(Cardinal)
26 library(gridExtra) 24 library(gridExtra)
27 library(lattice) 25
28 26 @READING_MSIDATA@
29 27
30 28 msidata = as(msidata, "MSImageSet") ##coercion to MSImageSet
31 @READING_MSIDATA_INRAM@
32
33 29
34 ## remove duplicated coordinates 30 ## remove duplicated coordinates
35 msidata <- msidata[,!duplicated(coord(msidata))] 31 msidata <- msidata[,!duplicated(coord(msidata))]
36 32
37 33
58 54
59 ######################## II) segmentation tools ############################# 55 ######################## II) segmentation tools #############################
60 ############################################################################# 56 #############################################################################
61 #set $color_string = ','.join(['"%s"' % $color.feature_color for $color in $colours]) 57 #set $color_string = ','.join(['"%s"' % $color.feature_color for $color in $colours])
62 colourvector = c($color_string) 58 colourvector = c($color_string)
63
64 ### preparation for images and plots:
65 #if str($image_type) == "standard_image":
66 print("standard image")
67
68 strip_input = FALSE
69 lattice_input = FALSE
70
71 #elif str($image_type) == "lattice_image":
72 print("lattice image")
73
74 strip_input = strip.custom(bg="lightgrey", par.strip.text=list(col="black", cex=.9))
75 lattice_input = TRUE
76
77 #end if
78 59
79 ## set seed to make analysis reproducible 60 ## set seed to make analysis reproducible
80 set.seed($setseed) 61 set.seed($setseed)
81 62
82 #if str( $segm_cond.segmentationtool ) == 'pca': 63 #if str( $segm_cond.segmentationtool ) == 'pca':
103 PC_vector[[PCs]] = c(paste0("PC",PCs))} 84 PC_vector[[PCs]] = c(paste0("PC",PCs))}
104 sd_table = cbind(PC_vector, sd_table) 85 sd_table = cbind(PC_vector, sd_table)
105 colnames(sd_table)[1] = "Principal components" 86 colnames(sd_table)[1] = "Principal components"
106 grid.table(sd_table, rows=NULL) 87 grid.table(sd_table, rows=NULL)
107 ### images in pdf file 88 ### images in pdf file
108 print(image(pca_result, main="PCA image", lattice=lattice_input, strip = strip_input, col=colourvector, ylim=c(maximumy+2, minimumy-2))) 89 print(image(pca_result, main="PCA image", strip = FALSE, col=colourvector, ylim=c(maximumy+2, minimumy-2)))
109 for (PCs in 1:$segm_cond.pca_ncomp){ 90 for (PCs in 1:$segm_cond.pca_ncomp){
110 print(image(pca_result, column = c(paste0("PC",PCs)), lattice=lattice_input,strip = strip_input, superpose = FALSE, main=paste0("PC", PCs), col.regions = risk.colors(100), ylim=c(maximumy+2, minimumy-2)))} 91 print(image(pca_result, column = c(paste0("PC",PCs)),strip = FALSE, superpose = FALSE, main=paste0("PC", PCs), col.regions = risk.colors(100), ylim=c(maximumy+2, minimumy-2)))}
111 ### plots in pdf file 92 ### plots in pdf file
112 print(plot(pca_result, main="PCA plot", lattice=lattice_input, col= colourvector, strip = strip_input)) 93 print(plot(pca_result, main="PCA plot", col= colourvector, strip = FALSE))
113 for (PCs in 1:$segm_cond.pca_ncomp){ 94 for (PCs in 1:$segm_cond.pca_ncomp){
114 print(plot(pca_result, column = c(paste0("PC",PCs)),main=paste0("PC", PCs),strip = FALSE,superpose = FALSE))} 95 print(plot(pca_result, column = c(paste0("PC",PCs)),main=paste0("PC", PCs),strip = FALSE,superpose = FALSE))}
115 96
116 ### values in tabular files 97 ### values in tabular files
117 pcaloadings = formatC(pca_result@resultData\$ncomp\$loadings, format = "e", digits = 6)### loading for each m/z value 98 pcaloadings = formatC(pca_result@resultData\$ncomp\$loadings, format = "e", digits = 6)### loading for each m/z value
147 128
148 ## remove msidata to clean up RAM space 129 ## remove msidata to clean up RAM space
149 rm(msidata) 130 rm(msidata)
150 gc() 131 gc()
151 132
152 print(image(skm, key=TRUE, main="K-means clustering", lattice=lattice_input, strip=strip_input, col= colourvector, layout=c(1,1), ylim=c(maximumy+2, minimumy-2))) 133 print(image(skm, key=TRUE, main="K-means clustering", strip=FALSE, col= colourvector, layout=c(1,1), ylim=c(maximumy+2, minimumy-2)))
153 print(plot(skm, main="K-means plot", lattice=lattice_input, col= colourvector, strip=strip_input, layout=c(1,1))) 134 print(plot(skm, main="K-means plot", col= colourvector, strip=FALSE, layout=c(1,1)))
154 135
155 skm_clusters = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) 136 skm_clusters = data.frame(matrix(NA, nrow = pixelcount, ncol = 0))
156 for (iteration in 1:length(skm@resultData)){ 137 for (iteration in 1:length(skm@resultData)){
157 skm_cluster = ((skm@resultData)[[iteration]]\$cluster) 138 skm_cluster = ((skm@resultData)[[iteration]]\$cluster)
158 skm_clusters = cbind(skm_clusters, skm_cluster) } 139 skm_clusters = cbind(skm_clusters, skm_cluster) }
165 y_coordinates = gsub(" y = ","",y_coords) 146 y_coordinates = gsub(" y = ","",y_coords)
166 pixel_names = paste0("xy_", x_coordinates, "_", y_coordinates) 147 pixel_names = paste0("xy_", x_coordinates, "_", y_coordinates)
167 skm_clusters2 = data.frame(pixel_names, x_coordinates, y_coordinates, skm_clusters) 148 skm_clusters2 = data.frame(pixel_names, x_coordinates, y_coordinates, skm_clusters)
168 colnames(skm_clusters2) = c("pixel names", "x", "y",names(skm@resultData)) 149 colnames(skm_clusters2) = c("pixel names", "x", "y",names(skm@resultData))
169 150
170 skm_toplabels = topLabels(skm, n=$segm_cond.kmeans_toplabels) 151 skm_toplabels = topFeatures(skm, n=$segm_cond.kmeans_toplabels)
171 152
172 write.table(skm_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 153 write.table(skm_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
173 write.table(skm_clusters2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 154 write.table(skm_clusters2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
174 155
175 ## optional output as .RData 156 ## optional output as .RData
186 167
187 ssc = spatialShrunkenCentroids(msidata, r=c($segm_cond.centroids_r), k=c($segm_cond.centroids_k), s=c($segm_cond.centroids_s), method="$segm_cond.centroids_method") 168 ssc = spatialShrunkenCentroids(msidata, r=c($segm_cond.centroids_r), k=c($segm_cond.centroids_k), s=c($segm_cond.centroids_s), method="$segm_cond.centroids_method")
188 ## remove msidata to clean up RAM space 169 ## remove msidata to clean up RAM space
189 rm(msidata) 170 rm(msidata)
190 gc() 171 gc()
191 print(image(ssc, key=TRUE, main="Spatial shrunken centroids", lattice=lattice_input, strip = TRUE, col= colourvector,layout=c(1,1), ylim=c(maximumy+2, minimumy-2))) 172 print(image(ssc, key=TRUE, main="Spatial shrunken centroids", strip = TRUE, col= colourvector,layout=c(1,1), ylim=c(maximumy+2, minimumy-2)))
192 print(plot(ssc, main="Spatial shrunken centroids plot", lattice=lattice_input, col= colourvector, strip = TRUE,layout=c(1,1))) 173 print(plot(ssc, main="Spatial shrunken centroids plot", col= colourvector, strip = TRUE,layout=c(1,1)))
193 print(plot(ssc, mode = "tstatistics",key = TRUE, lattice=lattice_input, layout = c(1,1), main="t-statistics", col=colourvector)) 174 print(plot(ssc, mode = "tstatistics",key = TRUE, layout = c(1,1), main="t-statistics", col=colourvector))
194 175
195 plot(summary(ssc), main = "Number of segments") 176 plot(summary(ssc), main = "Number of segments")
196 177
197 ssc_classes = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) 178 ssc_classes = data.frame(matrix(NA, nrow = pixelcount, ncol = 0))
198 for (iteration in 1:length(ssc@resultData)){ 179 for (iteration in 1:length(ssc@resultData)){
207 y_coordinates = gsub(" y = ","",y_coords) 188 y_coordinates = gsub(" y = ","",y_coords)
208 pixel_names = paste0("xy_", x_coordinates, "_", y_coordinates) 189 pixel_names = paste0("xy_", x_coordinates, "_", y_coordinates)
209 ssc_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, ssc_classes) 190 ssc_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, ssc_classes)
210 colnames(ssc_classes2) = c("pixel names", "x", "y", names(ssc@resultData)) 191 colnames(ssc_classes2) = c("pixel names", "x", "y", names(ssc@resultData))
211 192
212 ssc_toplabels = topLabels(ssc, n=$segm_cond.centroids_toplabels) 193 ssc_toplabels = topFeatures(ssc, n=$segm_cond.centroids_toplabels)
213 194
214 write.table(ssc_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 195 write.table(ssc_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
215 write.table(ssc_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 196 write.table(ssc_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
216 197
217 ## optional output as .RData 198 ## optional output as .RData
311 </param> 292 </param>
312 <param name="centroids_toplabels" type="integer" value="500" 293 <param name="centroids_toplabels" type="integer" value="500"
313 label="Number of toplabels (m/z) which should be written in tabular output"/> 294 label="Number of toplabels (m/z) which should be written in tabular output"/>
314 </when> 295 </when>
315 </conditional> 296 </conditional>
316 <param name="image_type" type="boolean" checked="True" truevalue="standard_image" falsevalue="lattice_image"
317 label="Standard image" help="No: lattice function is used to display image"/>
318 <param name="svg_pixelimage" type="boolean" label="Export first segmentation image as svg"/> 297 <param name="svg_pixelimage" type="boolean" label="Export first segmentation image as svg"/>
319 <repeat name="colours" title="Colours for the plots" min="1" max="50"> 298 <repeat name="colours" title="Colours for the plots" min="1" max="50">
320 <param name="feature_color" type="color" label="Colours" value="#ff00ff" help="Numbers of colours should be the same as number of components"> 299 <param name="feature_color" type="color" label="Colours" value="#ff00ff" help="Numbers of colours should be the same as number of components">
321 <sanitizer> 300 <sanitizer>
322 <valid initial="string.letters,string.digits"> 301 <valid initial="string.letters,string.digits">
341 </outputs> 320 </outputs>
342 <tests> 321 <tests>
343 <test> 322 <test>
344 <expand macro="infile_imzml"/> 323 <expand macro="infile_imzml"/>
345 <param name="segmentationtool" value="pca"/> 324 <param name="segmentationtool" value="pca"/>
346 <param name="image_type" value="lattice_image"/>
347 <repeat name="colours"> 325 <repeat name="colours">
348 <param name="feature_color" value="#ff00ff"/> 326 <param name="feature_color" value="#ff00ff"/>
349 </repeat> 327 </repeat>
350 <repeat name="colours"> 328 <repeat name="colours">
351 <param name="feature_color" value="#0000FF"/> 329 <param name="feature_color" value="#0000FF"/>
352 </repeat> 330 </repeat>
353 <output name="segmentationimages" file="pca_imzml.pdf" compare="sim_size"/> 331 <output name="segmentationimages" file="pca_imzml.pdf" compare="sim_size"/>
354 <output name="mzfeatures"> 332 <output name="mzfeatures">
355 <assert_contents> 333 <assert_contents>
356 <has_text text="300.17" /> 334 <has_text text="300.1667" />
335 <has_text text="300.25" />
357 <has_text text="-4.234458e-04" /> 336 <has_text text="-4.234458e-04" />
358 <has_text text="3.878545e-10" /> 337 <has_text text="3.878545e-10" />
359 <has_n_columns n="3" /> 338 <has_n_columns n="3" />
360 </assert_contents> 339 </assert_contents>
361 </output> 340 </output>
362 <output name="pixeloutput" file="scores_pca.tabular"/> 341 <output name="pixeloutput" file="scores_pca.tabular"/>
363 </test> 342 </test>
364 <test> 343 <test>
365 <expand macro="infile_analyze75"/> 344 <expand macro="infile_imzml"/>
366 <param name="segmentationtool" value="kmeans"/> 345 <param name="segmentationtool" value="kmeans"/>
367 <param name="kmeans_r" value="1:3"/> 346 <param name="kmeans_r" value="1:3"/>
368 <param name="kmeans_k" value="2,3"/> 347 <param name="kmeans_k" value="2,3"/>
369 <param name="kmeans_toplabels" value="20"/> 348 <param name="kmeans_toplabels" value="20"/>
370 <repeat name="colours"> 349 <repeat name="colours">
395 <param name="feature_color" value="#00C957"/> 374 <param name="feature_color" value="#00C957"/>
396 </repeat> 375 </repeat>
397 <repeat name="colours"> 376 <repeat name="colours">
398 <param name="feature_color" value="#B0171F"/> 377 <param name="feature_color" value="#B0171F"/>
399 </repeat> 378 </repeat>
400 <repeat name="colours">
401 <param name="feature_color" value="#FFD700"/>
402 </repeat>
403 <repeat name="colours">
404 <param name="feature_color" value="#848484"/>
405 </repeat>
406 <output name="segmentationimages" file="centroids_rdata.pdf" compare="sim_size"/> 379 <output name="segmentationimages" file="centroids_rdata.pdf" compare="sim_size"/>
407 <output name="mzfeatures" file="toplabels_ssc.tabular"/> 380 <output name="mzfeatures" file="toplabels_ssc.tabular"/>
408 <output name="pixeloutput" file="classes_ssc.tabular"/> 381 <output name="pixeloutput" file="classes_ssc.tabular"/>
409 </test> 382 </test>
383 <test>
384 <param name="infile" value="" ftype="imzml">
385 <composite_data value="preprocessing_results3.imzml"/>
386 <composite_data value="preprocessing_results3.ibd"/>
387 </param>
388 <conditional name="processed_cond">
389 <param name="processed_file" value="processed"/>
390 <param name="accuracy" value="1"/>
391 <param name="units" value="mz"/>
392 </conditional>
393 <param name="segmentationtool" value="centroids"/>
394 <param name="centroids_r" value="1"/>
395 <param name="centroids_k" value="2,3"/>
396 <param name="centroids_s" value="0,3"/>
397 <param name="centroids_toplabels" value="100"/>
398 <repeat name="colours">
399 <param name="feature_color" value="#0000FF"/>
400 </repeat>
401 <repeat name="colours">
402 <param name="feature_color" value="#00C957"/>
403 </repeat>
404 <repeat name="colours">
405 <param name="feature_color" value="#B0171F"/>
406 </repeat>
407 <output name="segmentationimages" file="centroids_proc.pdf" compare="sim_size"/>
408 <output name="mzfeatures" file="toplabels_proc.tabular"/>
409 <output name="pixeloutput" file="classes_proc.tabular"/>
410 </test>
410 </tests> 411 </tests>
411 <help> 412 <help>
412 <![CDATA[ 413 <![CDATA[
413 414
414 @CARDINAL_DESCRIPTION@ 415 @CARDINAL_DESCRIPTION@