comparison segmentation_tool.xml @ 8:4a62874c21a3 draft default tip

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msi_segmentation commit 5feaf3d0e0da8cef1241fecc1f4d6f81324594e6
author galaxyp
date Wed, 22 Aug 2018 13:44:28 -0400
parents adfef12c7e31
children
comparison
equal deleted inserted replaced
7:adfef12c7e31 8:4a62874c21a3
1 <tool id="mass_spectrometry_imaging_segmentations" name="MSI segmentation" version="1.10.0.3"> 1 <tool id="mass_spectrometry_imaging_segmentations" name="MSI segmentation" version="1.10.0.4">
2 <description>mass spectrometry imaging spatial clustering</description> 2 <description>mass spectrometry imaging spatial clustering</description>
3 <requirements> 3 <requirements>
4 <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement> 4 <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement>
5 <requirement type="package" version="2.2.1">r-gridextra</requirement> 5 <requirement type="package" version="2.2.1">r-gridextra</requirement>
6 <requirement type="package" version="0.20-35">r-lattice</requirement> 6 <requirement type="package" version="0.20-35">r-lattice</requirement>
43 msidata <- readImzML('infile') 43 msidata <- readImzML('infile')
44 #end if 44 #end if
45 #elif $infile.ext == 'analyze75' 45 #elif $infile.ext == 'analyze75'
46 msidata = readAnalyze('infile') 46 msidata = readAnalyze('infile')
47 #else 47 #else
48 load('infile.RData') 48 loadRData <- function(fileName){
49 load(fileName)
50 get(ls()[ls() != "fileName"])
51 }
52 msidata = loadRData('infile.RData')
49 #end if 53 #end if
50 54
51 55
52 ## create full matrix to make processed imzML files compatible with segmentation 56 ## create full matrix to make processed imzML files compatible with segmentation
53 iData(msidata) <- iData(msidata)[] 57 iData(msidata) <- iData(msidata)[]
184 strip_input = strip.custom(bg="lightgrey", par.strip.text=list(col="black", cex=.9)) 188 strip_input = strip.custom(bg="lightgrey", par.strip.text=list(col="black", cex=.9))
185 lattice_input = TRUE 189 lattice_input = TRUE
186 190
187 #end if 191 #end if
188 192
193 ## set seed to make analysis reproducible
194 set.seed($setseed)
189 195
190 #if str( $segm_cond.segmentationtool ) == 'pca': 196 #if str( $segm_cond.segmentationtool ) == 'pca':
191 print('pca') 197 print('pca')
192 ##pca 198 ##pca
193 199
196 {component_vector[numberofcomponents]= paste0("PC", numberofcomponents)} 202 {component_vector[numberofcomponents]= paste0("PC", numberofcomponents)}
197 pca_result = PCA(msidata, ncomp=$segm_cond.pca_ncomp, column = component_vector, superpose = FALSE, 203 pca_result = PCA(msidata, ncomp=$segm_cond.pca_ncomp, column = component_vector, superpose = FALSE,
198 method = "$segm_cond.pca_method", scale = $segm_cond.pca_scale, layout = c(ncomp, 1)) 204 method = "$segm_cond.pca_method", scale = $segm_cond.pca_scale, layout = c(ncomp, 1))
199 205
200 ### images in pdf file 206 ### images in pdf file
201 print(image(pca_result, main="PCA image", lattice=lattice_input, strip = strip_input, col=colourvector)) 207 print(image(pca_result, main="PCA image", lattice=lattice_input, strip = strip_input, col=colourvector, ylim=c(maximumy+2, minimumy-2)))
202 for (PCs in 1:$segm_cond.pca_ncomp){ 208 for (PCs in 1:$segm_cond.pca_ncomp){
203 print(image(pca_result, column = c(paste0("PC",PCs)), lattice=lattice_input, superpose = FALSE, col.regions = risk.colors(100)))} 209 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)))}
204 ### plots in pdf file 210 ### plots in pdf file
205 print(plot(pca_result, main="PCA plot", lattice=lattice_input, col= colourvector, strip = strip_input)) 211 print(plot(pca_result, main="PCA plot", lattice=lattice_input, col= colourvector, strip = strip_input))
206 for (PCs in 1:$segm_cond.pca_ncomp){ 212 for (PCs in 1:$segm_cond.pca_ncomp){
207 print(plot(pca_result, column = c(paste0("PC",PCs)),superpose = FALSE))} 213 print(plot(pca_result, column = c(paste0("PC",PCs)),superpose = FALSE))}
208 214
209 ### values in tabular files 215 ### values in tabular files
210 pcaloadings = (pca_result@resultData\$ncomp\$loadings) ### loading for each m/z value 216 pcaloadings = (pca_result@resultData\$ncomp\$loadings) ### loading for each m/z value
217 pcaloadings2 = cbind(rownames(pcaloadings), pcaloadings)
218 colnames(pcaloadings2) = c("mz", colnames(pcaloadings))
211 pcascores = (pca_result@resultData\$ncomp\$scores) ### scores for each pixel 219 pcascores = (pca_result@resultData\$ncomp\$scores) ### scores for each pixel
212 220 pcascores2 = cbind(rownames(pcascores), pcascores)
213 write.table(pcaloadings, file="$mzfeatures", quote = FALSE, row.names = TRUE, col.names=NA, sep = "\t") 221 colnames(pcascores2) = c("pixel names", colnames(pcascores))
214 write.table(pcascores, file="$pixeloutput", quote = FALSE, row.names = TRUE, col.names=NA, sep = "\t") 222
223 write.table(pcaloadings2, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
224 write.table(pcascores2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
215 225
216 ## optional output as .RData 226 ## optional output as .RData
217 #if $output_rdata: 227 #if $output_rdata:
218 ## save as (.RData) 228 ## save as (.RData)
219 save(pca, file="$segmentation_rdata") 229 save(pca, file="$segmentation_rdata")
223 #elif str( $segm_cond.segmentationtool ) == 'kmeans': 233 #elif str( $segm_cond.segmentationtool ) == 'kmeans':
224 print('kmeans') 234 print('kmeans')
225 ##k-means 235 ##k-means
226 236
227 skm = spatialKMeans(msidata, r=c($segm_cond.kmeans_r), k=c($segm_cond.kmeans_k), method="$segm_cond.kmeans_method") 237 skm = spatialKMeans(msidata, r=c($segm_cond.kmeans_r), k=c($segm_cond.kmeans_k), method="$segm_cond.kmeans_method")
228 print(image(skm, key=TRUE, main="K-means clustering", lattice=lattice_input, strip=strip_input, col= colourvector, layout=c(1,1))) 238 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)))
229 239
230 print(plot(skm, main="K-means plot", lattice=lattice_input, col= colourvector, strip=strip_input, layout=c($segm_cond.kmeans_layout))) 240 print(plot(skm, main="K-means plot", lattice=lattice_input, col= colourvector, strip=strip_input, layout=c($segm_cond.kmeans_layout)))
231 241
232 skm_clusters = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) 242 skm_clusters = data.frame(matrix(NA, nrow = pixelcount, ncol = 0))
233 for (iteration in 1:length(skm@resultData)){ 243 for (iteration in 1:length(skm@resultData)){
234 skm_cluster = ((skm@resultData)[[iteration]]\$cluster) 244 skm_cluster = ((skm@resultData)[[iteration]]\$cluster)
235 skm_clusters = cbind(skm_clusters, skm_cluster) } 245 skm_clusters = cbind(skm_clusters, skm_cluster) }
236 colnames(skm_clusters) = names((skm@resultData)) 246 skm_clusters2 = cbind(rownames(skm_clusters), skm_clusters)
247 colnames(skm_clusters2) = c("pixel names", names(skm@resultData))
237 248
238 skm_toplabels = topLabels(skm, n=$segm_cond.kmeans_toplabels) 249 skm_toplabels = topLabels(skm, n=$segm_cond.kmeans_toplabels)
239 250
240 write.table(skm_toplabels, file="$mzfeatures", quote = FALSE, row.names = TRUE, col.names=NA, sep = "\t") 251 write.table(skm_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
241 write.table(skm_clusters, file="$pixeloutput", quote = FALSE, row.names = TRUE, col.names=NA, sep = "\t") 252 write.table(skm_clusters2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
242 253
243 ## optional output as .RData 254 ## optional output as .RData
244 #if $output_rdata: 255 #if $output_rdata:
245 256
246 ## save as (.RData) 257 ## save as (.RData)
251 #elif str( $segm_cond.segmentationtool ) == 'centroids': 262 #elif str( $segm_cond.segmentationtool ) == 'centroids':
252 print('centroids') 263 print('centroids')
253 ##centroids 264 ##centroids
254 265
255 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") 266 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")
256 print(image(ssc, key=TRUE, main="Spatial shrunken centroids", lattice=lattice_input, strip = strip_input, col= colourvector,layout=c(1,1))) 267 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)))
257 print(plot(ssc, main="Spatial shrunken centroids plot", lattice=lattice_input, col= colourvector, strip = strip_input,layout=c($segm_cond.centroids_layout))) 268 print(plot(ssc, main="Spatial shrunken centroids plot", lattice=lattice_input, col= colourvector, strip = strip_input,layout=c($segm_cond.centroids_layout)))
258 print(plot(ssc, mode = "tstatistics",key = TRUE, lattice=lattice_input, layout = c($segm_cond.centroids_layout), main="t-statistics", col=colourvector)) 269 print(plot(ssc, mode = "tstatistics",key = TRUE, lattice=lattice_input, layout = c($segm_cond.centroids_layout), main="t-statistics", col=colourvector))
259 plot(summary(ssc), main = "Number of segments") 270 plot(summary(ssc), main = "Number of segments")
260 271
261 ssc_classes = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) 272 ssc_classes = data.frame(matrix(NA, nrow = pixelcount, ncol = 0))
262 for (iteration in 1:length(ssc@resultData)){ 273 for (iteration in 1:length(ssc@resultData)){
263 ssc_class = ((ssc@resultData)[[iteration]]\$classes) 274 ssc_class = ((ssc@resultData)[[iteration]]\$classes)
264 ssc_classes = cbind(ssc_classes, ssc_class) } 275 ssc_classes = cbind(ssc_classes, ssc_class) }
265 colnames(ssc_classes) = names((ssc@resultData)) 276 ssc_classes2 = cbind(rownames(ssc_classes), ssc_classes)
277 colnames(ssc_classes2) = c("pixel names", names(ssc@resultData))
266 278
267 ssc_toplabels = topLabels(ssc, n=$segm_cond.centroids_toplabels) 279 ssc_toplabels = topLabels(ssc, n=$segm_cond.centroids_toplabels)
268 280
269 write.table(ssc_toplabels, file="$mzfeatures", quote = FALSE, row.names = TRUE, col.names=NA, sep = "\t") 281 write.table(ssc_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
270 write.table(ssc_classes, file="$pixeloutput", quote = FALSE, row.names = TRUE, col.names=NA, sep = "\t") 282 write.table(ssc_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
271 283
272 ## optional output as .RData 284 ## optional output as .RData
273 #if $output_rdata: 285 #if $output_rdata:
274 286
275 ## save as (.RData) 287 ## save as (.RData)
377 </valid> 389 </valid>
378 </sanitizer> 390 </sanitizer>
379 </param> 391 </param>
380 </repeat> 392 </repeat>
381 <param name="output_rdata" type="boolean" display="radio" label="Results as .RData output"/> 393 <param name="output_rdata" type="boolean" display="radio" label="Results as .RData output"/>
394 <param name="setseed" type="integer" value="1" label="set seed" help="use same value to reproduce previous results"/>
382 </inputs> 395 </inputs>
383 <outputs> 396 <outputs>
384 <data format="pdf" name="segmentationimages" from_work_dir="segmentationpdf.pdf" label = "$infile.display_name segmentation"/> 397 <data format="pdf" name="segmentationimages" from_work_dir="segmentationpdf.pdf" label = "$infile.display_name segmentation"/>
385 <data format="tabular" name="mzfeatures" label="$infile.display_name m/z features"/> 398 <data format="tabular" name="mzfeatures" label="$infile.display_name m/z features"/>
386 <data format="tabular" name="pixeloutput" label="$infile.display_name pixels"/> 399 <data format="tabular" name="pixeloutput" label="$infile.display_name pixels"/>