comparison segmentation.xml @ 2:034885df9b09 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit f127be2141cf22e269c85282d226eb16fe14a9c1
author galaxyp
date Fri, 15 Feb 2019 10:16:36 -0500
parents 98d48f081ad9
children 09b638ceee45
comparison
equal deleted inserted replaced
1:98d48f081ad9 2:034885df9b09
1 <tool id="cardinal_segmentations" name="MSI segmentation" version="@VERSION@.1"> 1 <tool id="cardinal_segmentations" name="MSI segmentation" version="@VERSION@.2">
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">
24 24
25 library(Cardinal) 25 library(Cardinal)
26 library(gridExtra) 26 library(gridExtra)
27 library(lattice) 27 library(lattice)
28 28
29 @READING_MSIDATA@ 29
30 30
31 31 @READING_MSIDATA_INRAM@
32 ## create full matrix to make processed imzML files compatible with segmentation 32
33 iData(msidata) <- iData(msidata)[] 33 ## to make sure that processed files work as well:
34 34 iData(msidata) = iData(msidata)[]
35 @DATA_PROPERTIES@ 35
36 ## count and print number of NAs, all methods are not compatible with NAs
37 print(paste0("Number of NA in dataset: ", sum(is.na(spectra(msidata)[])), " - segmentation does not work with NA values"))
38
39 @DATA_PROPERTIES_INRAM@
40
36 41
37 ######################################## PDF ################################### 42 ######################################## PDF ###################################
38 ################################################################################ 43 ################################################################################
39 ################################################################################ 44 ################################################################################
40 45
47 52
48 ############################# I) numbers #################################### 53 ############################# I) numbers ####################################
49 ############################################################################# 54 #############################################################################
50 grid.table(property_df, rows= NULL) 55 grid.table(property_df, rows= NULL)
51 56
52 if (npeaks > 0) 57 if (npeaks > 0 && sum(is.na(spectra(msidata)[]))==0)
53 { 58 {
54 59
55 ######################## II) segmentation tools ############################# 60 ######################## II) segmentation tools #############################
56 ############################################################################# 61 #############################################################################
57 #set $color_string = ','.join(['"%s"' % $color.feature_color for $color in $colours]) 62 #set $color_string = ','.join(['"%s"' % $color.feature_color for $color in $colours])
79 print('pca') 84 print('pca')
80 ##pca 85 ##pca
81 86
82 component_vector = character() 87 component_vector = character()
83 for (numberofcomponents in 1:$segm_cond.pca_ncomp) 88 for (numberofcomponents in 1:$segm_cond.pca_ncomp)
84 {component_vector[numberofcomponents]= paste0("PC", numberofcomponents)} 89 {component_vector[numberofcomponents]= paste0("PC", numberofcomponents)}
90
85 pca_result = PCA(msidata, ncomp=$segm_cond.pca_ncomp, column = component_vector, superpose = FALSE, 91 pca_result = PCA(msidata, ncomp=$segm_cond.pca_ncomp, column = component_vector, superpose = FALSE,
86 method = "$segm_cond.pca_method", scale = $segm_cond.pca_scale, layout = c(ncomp, 1)) 92 method = "$segm_cond.pca_method", scale = $segm_cond.pca_scale, layout = c(ncomp, 1))
87 93
94 ## remove msidata to clean up RAM space
95 rm(msidata)
96 gc()
97
98 ### table in pdf file
99 plot(0,type='n',axes=FALSE,ann=FALSE)
100 sd_table = as.data.frame(round(pca_result@resultData\$ncomp\$sdev, digits=2))
101 colnames(sd_table) = "Standard deviation"
102 PC_vector = character()
103 for (PCs in 1:$segm_cond.pca_ncomp){
104 PC_vector[[PCs]] = c(paste0("PC",PCs))}
105 sd_table = cbind(PC_vector, sd_table)
106 colnames(sd_table)[1] = "Principal components"
107 grid.table(sd_table, rows=NULL)
88 ### images in pdf file 108 ### images in pdf file
89 print(image(pca_result, main="PCA image", lattice=lattice_input, strip = strip_input, col=colourvector, ylim=c(maximumy+2, minimumy-2))) 109 print(image(pca_result, main="PCA image", lattice=lattice_input, strip = strip_input, col=colourvector, ylim=c(maximumy+2, minimumy-2)))
90 for (PCs in 1:$segm_cond.pca_ncomp){ 110 for (PCs in 1:$segm_cond.pca_ncomp){
91 print(image(pca_result, column = c(paste0("PC",PCs)), lattice=lattice_input, superpose = FALSE, col.regions = risk.colors(100), ylim=c(maximumy+2, minimumy-2)))} 111 print(image(pca_result, column = c(paste0("PC",PCs)), lattice=lattice_input, superpose = FALSE, col.regions = risk.colors(100), ylim=c(maximumy+2, minimumy-2)))}
92 ### plots in pdf file 112 ### plots in pdf file
93 print(plot(pca_result, main="PCA plot", lattice=lattice_input, col= colourvector, strip = strip_input)) 113 print(plot(pca_result, main="PCA plot", lattice=lattice_input, col= colourvector, strip = strip_input))
94 for (PCs in 1:$segm_cond.pca_ncomp){ 114 for (PCs in 1:$segm_cond.pca_ncomp){
95 print(plot(pca_result, column = c(paste0("PC",PCs)),superpose = FALSE))} 115 print(plot(pca_result, column = c(paste0("PC",PCs)),superpose = FALSE))}
96 116
97 ### values in tabular files 117 ### values in tabular files
98 pcaloadings = (pca_result@resultData\$ncomp\$loadings) ### loading for each m/z value 118 pcaloadings = formatC(pca_result@resultData\$ncomp\$loadings, format = "e", digits = 6)### loading for each m/z value
99 pcaloadings2 = cbind(matrix(unlist(strsplit(rownames(pcaloadings), " = ")), ncol=2, byrow=TRUE)[,2], pcaloadings) 119 pcaloadings2 = cbind(matrix(unlist(strsplit(rownames(pcaloadings), " = ")), ncol=2, byrow=TRUE)[,2], pcaloadings)
100 colnames(pcaloadings2) = c("mz", colnames(pcaloadings)) 120 colnames(pcaloadings2) = c("mz", colnames(pcaloadings))
101 pcascores = (pca_result@resultData\$ncomp\$scores) ### scores for each pixel 121 pcascores = round(pca_result@resultData\$ncomp\$scores, digits=6) ### scores for each pixel
102 122
103 ## pixel names and coordinates 123 ## pixel names and coordinates
104 ## to remove potential sample names and z dimension, split at comma and take only x and y 124 ## to remove potential sample names and z dimension, split at comma and take only x and y
105 x_coords = unlist(lapply(strsplit(rownames(pcascores), ","), `[[`, 1)) 125 x_coords = unlist(lapply(strsplit(rownames(pcascores), ","), `[[`, 1))
106 y_coords = unlist(lapply(strsplit(rownames(pcascores), ","), `[[`, 2)) 126 y_coords = unlist(lapply(strsplit(rownames(pcascores), ","), `[[`, 2))
123 #elif str( $segm_cond.segmentationtool ) == 'kmeans': 143 #elif str( $segm_cond.segmentationtool ) == 'kmeans':
124 print('kmeans') 144 print('kmeans')
125 ##k-means 145 ##k-means
126 146
127 skm = spatialKMeans(msidata, r=c($segm_cond.kmeans_r), k=c($segm_cond.kmeans_k), method="$segm_cond.kmeans_method") 147 skm = spatialKMeans(msidata, r=c($segm_cond.kmeans_r), k=c($segm_cond.kmeans_k), method="$segm_cond.kmeans_method")
148
149 ## remove msidata to clean up RAM space
150 rm(msidata)
151 gc()
152
128 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))) 153 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)))
129 154
130 print(plot(skm, main="K-means plot", lattice=lattice_input, col= colourvector, strip=strip_input, layout=c(1,1))) 155 print(plot(skm, main="K-means plot", lattice=lattice_input, col= colourvector, strip=strip_input, layout=c(1,1)))
131 156
132 skm_clusters = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) 157 skm_clusters = data.frame(matrix(NA, nrow = pixelcount, ncol = 0))
160 #elif str( $segm_cond.segmentationtool ) == 'centroids': 185 #elif str( $segm_cond.segmentationtool ) == 'centroids':
161 print('centroids') 186 print('centroids')
162 ##centroids 187 ##centroids
163 188
164 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") 189 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")
190 ## remove msidata to clean up RAM space
191 rm(msidata)
192 gc()
165 print(image(ssc, key=TRUE, main="Spatial shrunken centroids", lattice=lattice_input, strip = strip_input, col= colourvector,layout=c(1,1), ylim=c(maximumy+2, minimumy-2))) 193 print(image(ssc, key=TRUE, main="Spatial shrunken centroids", lattice=lattice_input, strip = strip_input, col= colourvector,layout=c(1,1), ylim=c(maximumy+2, minimumy-2)))
166 print(plot(ssc, main="Spatial shrunken centroids plot", lattice=lattice_input, col= colourvector, strip = strip_input,layout=c(1,1))) 194 print(plot(ssc, main="Spatial shrunken centroids plot", lattice=lattice_input, col= colourvector, strip = strip_input,layout=c(1,1)))
167 print(plot(ssc, mode = "tstatistics",key = TRUE, lattice=lattice_input, layout = c(1,1), main="t-statistics", col=colourvector)) 195 print(plot(ssc, mode = "tstatistics",key = TRUE, lattice=lattice_input, layout = c(1,1), main="t-statistics", col=colourvector))
168 plot(summary(ssc), main = "Number of segments") 196 plot(summary(ssc), main = "Number of segments")
169 197
272 </param> 300 </param>
273 <when value="standard_image"/> 301 <when value="standard_image"/>
274 <when value="lattice_image"/> 302 <when value="lattice_image"/>
275 </conditional> 303 </conditional>
276 <repeat name="colours" title="Colours for the plots" min="1" max="50"> 304 <repeat name="colours" title="Colours for the plots" min="1" max="50">
277 <param name="feature_color" type="color" label="Colours" value="#ff00ff" help="Numbers of columns should be the same as number of components"> 305 <param name="feature_color" type="color" label="Colours" value="#ff00ff" help="Numbers of colours should be the same as number of components">
278 <sanitizer> 306 <sanitizer>
279 <valid initial="string.letters,string.digits"> 307 <valid initial="string.letters,string.digits">
280 <add value="#" /> 308 <add value="#" />
281 </valid> 309 </valid>
282 </sanitizer> 310 </sanitizer>
284 </repeat> 312 </repeat>
285 <param name="output_rdata" type="boolean" label="Results as .RData output"/> 313 <param name="output_rdata" type="boolean" label="Results as .RData output"/>
286 <param name="setseed" type="integer" value="1" label="set seed" help="Use same value to reproduce previous results"/> 314 <param name="setseed" type="integer" value="1" label="set seed" help="Use same value to reproduce previous results"/>
287 </inputs> 315 </inputs>
288 <outputs> 316 <outputs>
289 <data format="pdf" name="segmentationimages" from_work_dir="segmentationpdf.pdf" label = "${tool.name} on ${on_string}"/> 317 <data format="pdf" name="segmentationimages" from_work_dir="segmentationpdf.pdf" label = "${tool.name} on ${on_string}: results"/>
290 <data format="tabular" name="mzfeatures" label="${tool.name} on ${on_string}: features"/> 318 <data format="tabular" name="mzfeatures" label="${tool.name} on ${on_string}: features"/>
291 <data format="tabular" name="pixeloutput" label="${tool.name} on ${on_string}: pixels"/> 319 <data format="tabular" name="pixeloutput" label="${tool.name} on ${on_string}: pixels"/>
292 <data format="rdata" name="segmentation_rdata" label="${tool.name} on ${on_string}: results.RData"> 320 <data format="rdata" name="segmentation_rdata" label="${tool.name} on ${on_string}: results.RData">
293 <filter>output_rdata</filter> 321 <filter>output_rdata</filter>
294 </data> 322 </data>
303 </repeat> 331 </repeat>
304 <repeat name="colours"> 332 <repeat name="colours">
305 <param name="feature_color" value="#0000FF"/> 333 <param name="feature_color" value="#0000FF"/>
306 </repeat> 334 </repeat>
307 <output name="segmentationimages" file="pca_imzml.pdf" compare="sim_size"/> 335 <output name="segmentationimages" file="pca_imzml.pdf" compare="sim_size"/>
308 <output name="mzfeatures" file="loadings_pca.tabular"/> 336 <output name="mzfeatures">
337 <assert_contents>
338 <has_text text="300.17" />
339 <has_text text="-4.234458e-04" />
340 <has_text text="3.878545e-10" />
341 <has_n_columns n="3" />
342 </assert_contents>
343 </output>
309 <output name="pixeloutput" file="scores_pca.tabular"/> 344 <output name="pixeloutput" file="scores_pca.tabular"/>
310 </test> 345 </test>
311 <test> 346 <test>
312 <expand macro="infile_analyze75"/> 347 <expand macro="infile_analyze75"/>
313 <param name="segmentationtool" value="kmeans"/> 348 <param name="segmentationtool" value="kmeans"/>