Mercurial > repos > galaxyp > cardinal_segmentations
comparison segmentation.xml @ 13:199ae8af4d0d draft default tip
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit 91e77c139cb3b7c6d67727dc39140dd79355fa0c
| author | galaxyp |
|---|---|
| date | Thu, 04 Jul 2024 13:22:00 +0000 |
| parents | 46d53f24c81c |
| children |
comparison
equal
deleted
inserted
replaced
| 12:4be836296c07 | 13:199ae8af4d0d |
|---|---|
| 1 <tool id="cardinal_segmentations" name="MSI segmentation" version="@VERSION@.0"> | 1 <tool id="cardinal_segmentations" name="MSI segmentation" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="22.05"> |
| 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> | |
| 8 </expand> | |
| 9 <command detect_errors="exit_code"> | 7 <command detect_errors="exit_code"> |
| 10 <![CDATA[ | 8 <![CDATA[ |
| 11 | 9 |
| 12 @INPUT_LINKING@ | 10 @INPUT_LINKING@ |
| 13 cat '${MSI_segmentation}' && | 11 cat '${MSI_segmentation}' && |
| 20 | 18 |
| 21 ################################# load libraries and read file ################# | 19 ################################# load libraries and read file ################# |
| 22 | 20 |
| 23 library(Cardinal) | 21 library(Cardinal) |
| 24 library(gridExtra) | 22 library(gridExtra) |
| 23 library(ggplot2) | |
| 24 library(scales) | |
| 25 | 25 |
| 26 @READING_MSIDATA@ | 26 @READING_MSIDATA@ |
| 27 | 27 |
| 28 msidata = as(msidata, "MSImageSet") ##coercion to MSImageSet | 28 msidata = as(msidata, "MSImagingExperiment") |
| 29 | 29 |
| 30 ## remove duplicated coordinates | 30 ## remove duplicated coordinates |
| 31 msidata <- msidata[,!duplicated(coord(msidata))] | 31 msidata <- msidata[,!duplicated(coord(msidata))] |
| 32 | 32 |
| 33 | 33 |
| 47 | 47 |
| 48 ############################# I) numbers #################################### | 48 ############################# I) numbers #################################### |
| 49 ############################################################################# | 49 ############################################################################# |
| 50 grid.table(property_df, rows= NULL) | 50 grid.table(property_df, rows= NULL) |
| 51 | 51 |
| 52 if (npeaks > 0 && sum(is.na(spectra(msidata)))==0) | 52 |
| 53 if (npeaks > 0 && NAcount==0) | |
| 53 { | 54 { |
| 54 | 55 |
| 55 ######################## II) segmentation tools ############################# | 56 ######################## II) segmentation tools ############################# |
| 56 ############################################################################# | 57 ############################################################################# |
| 57 #set $color_string = ','.join(['"%s"' % $color.feature_color for $color in $colours]) | 58 |
| 58 colourvector = c($color_string) | 59 #if str( $segm_cond.segmentationtool ) == 'kmeans': |
| 60 number_colors = max(c($segm_cond.kmeans_k)) | |
| 61 | |
| 62 #elif str( $segm_cond.segmentationtool ) == 'centroids': | |
| 63 number_colors = max(c($segm_cond.centroids_k)) | |
| 64 | |
| 65 #end if | |
| 66 | |
| 67 #if str($colour_conditional.colour_type) == "manual_colour" | |
| 68 #set $color_string = ','.join(['"%s"' % $color.annotation_color for $color in $colour_conditional.colours]) | |
| 69 colourvector = c($color_string) | |
| 70 | |
| 71 #elif str($colour_conditional.colour_type) == "colourpalette" | |
| 72 number_levels = (number_colors) | |
| 73 colourvector = noquote($colour_conditional.palettes)(number_levels) | |
| 74 | |
| 75 #end if | |
| 76 | |
| 59 | 77 |
| 60 ## set seed to make analysis reproducible | 78 ## set seed to make analysis reproducible |
| 61 set.seed($setseed) | 79 set.seed($setseed) |
| 62 | 80 |
| 63 #if str( $segm_cond.segmentationtool ) == 'pca': | 81 #if str( $segm_cond.segmentationtool ) == 'kmeans': |
| 64 print('pca') | 82 print('kmeans') |
| 65 ##pca | 83 ##k-means |
| 66 | 84 skm = spatialKMeans(msidata, r=c($segm_cond.kmeans_r), k=c($segm_cond.kmeans_k), method="gaussian") |
| 67 component_vector = character() | |
| 68 for (numberofcomponents in 1:$segm_cond.pca_ncomp) | |
| 69 {component_vector[numberofcomponents]= paste0("PC", numberofcomponents)} | |
| 70 | |
| 71 pca_result = PCA(msidata, ncomp=$segm_cond.pca_ncomp, column = component_vector, superpose = FALSE, | |
| 72 method = "$segm_cond.pca_method", scale = $segm_cond.pca_scale, layout = c(ncomp, 1)) | |
| 73 | 85 |
| 74 ## remove msidata to clean up RAM space | 86 ## remove msidata to clean up RAM space |
| 75 rm(msidata) | 87 rm(msidata) |
| 76 gc() | 88 gc() |
| 77 | 89 |
| 78 ### table in pdf file | 90 k_value = c($segm_cond.kmeans_k) |
| 79 plot(0,type='n',axes=FALSE,ann=FALSE) | 91 r_value = c($segm_cond.kmeans_r) |
| 80 sd_table = as.data.frame(round(pca_result@resultData\$ncomp\$sdev, digits=2)) | 92 |
| 81 colnames(sd_table) = "Standard deviation" | 93 for (k in k_value) { |
| 82 PC_vector = character() | 94 for (r in r_value) { |
| 83 for (PCs in 1:$segm_cond.pca_ncomp){ | 95 print(image(skm, key=TRUE, model = list(k = k, r = r), |
| 84 PC_vector[[PCs]] = c(paste0("PC",PCs))} | 96 main = paste("K-means clustering (r =", r, ", k =", k, ")"), |
| 85 sd_table = cbind(PC_vector, sd_table) | 97 strip = FALSE, col = colourvector, layout = c(1, 1), ylim = c(maximumy+2, minimumy-2))) |
| 86 colnames(sd_table)[1] = "Principal components" | 98 |
| 87 grid.table(sd_table, rows=NULL) | 99 print(plot(skm, model = list(k = k, r = r), key = TRUE, |
| 88 ### images in pdf file | 100 main = paste("K-means plot (r =", r, ", k =", k, ")"), |
| 89 print(image(pca_result, main="PCA image", strip = FALSE, col=colourvector, ylim=c(maximumy+2, minimumy-2))) | 101 strip = FALSE, col = colourvector, layout = c(1, 1))) |
| 90 for (PCs in 1:$segm_cond.pca_ncomp){ | 102 } |
| 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)))} | 103 } |
| 92 ### plots in pdf file | 104 |
| 93 print(plot(pca_result, main="PCA plot", col= colourvector, strip = FALSE)) | 105 skm_clusters = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) |
| 94 for (PCs in 1:$segm_cond.pca_ncomp){ | 106 for (iteration in 1:length(skm@resultData)){ |
| 95 print(plot(pca_result, column = c(paste0("PC",PCs)),main=paste0("PC", PCs),strip = FALSE,superpose = FALSE))} | 107 skm_cluster = ((skm@resultData)[[iteration]]\$cluster) |
| 96 | 108 skm_clusters = cbind(skm_clusters, skm_cluster) } |
| 97 ### values in tabular files | 109 |
| 98 pcaloadings = formatC(pca_result@resultData\$ncomp\$loadings, format = "e", digits = 6)### loading for each m/z value | 110 skm.coordinates = coord(skm) |
| 99 pcaloadings2 = cbind(matrix(unlist(strsplit(rownames(pcaloadings), " = ")), ncol=2, byrow=TRUE)[,2], pcaloadings) | 111 x_coords = skm.coordinates@listData[["x"]] |
| 100 colnames(pcaloadings2) = c("mz", colnames(pcaloadings)) | 112 y_coords = skm.coordinates@listData[["y"]] |
| 101 pcascores = round(pca_result@resultData\$ncomp\$scores, digits=6) ### scores for each pixel | 113 pixel_names = paste0("xy_", x_coords, "_", y_coords) |
| 102 | 114 |
| 103 ## pixel names and coordinates | 115 skm_clusters2 = data.frame(pixel_names, x_coords, y_coords, skm_clusters) |
| 104 ## to remove potential sample names and z dimension, split at comma and take only x and y | 116 r_values = skm@modelData@listData[["r"]] |
| 105 x_coords = unlist(lapply(strsplit(rownames(pcascores), ","), `[[`, 1)) | 117 k_values = skm@modelData@listData[["k"]] |
| 106 y_coords = unlist(lapply(strsplit(rownames(pcascores), ","), `[[`, 2)) | 118 new_names = paste0("r=", r_values, ", k=", k_values) |
| 107 x_coordinates = gsub("x = ","",x_coords) | 119 colnames(skm_clusters2) = c("pixel names", "x", "y", new_names) |
| 108 y_coordinates = gsub(" y = ","",y_coords) | 120 |
| 109 | 121 skm_toplabels = topFeatures(skm, n=$segm_cond.kmeans_toplabels) |
| 110 pixel_names = paste0("xy_", x_coordinates, "_", y_coordinates) | 122 |
| 111 pcascores2 = data.frame(pixel_names, x_coordinates, y_coordinates, pcascores) | 123 write.table(skm_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") |
| 112 colnames(pcascores2) = c("pixel names", "x", "y", colnames(pcascores)) | 124 write.table(skm_clusters2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") |
| 113 write.table(pcaloadings2, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") | |
| 114 write.table(pcascores2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") | |
| 115 | 125 |
| 116 ## optional output as .RData | 126 ## optional output as .RData |
| 117 #if $output_rdata: | 127 #if $output_rdata: |
| 128 | |
| 118 ## save as (.RData) | 129 ## save as (.RData) |
| 119 save(pca, file="$segmentation_rdata") | 130 save(skm, file="$segmentation_rdata") |
| 120 | 131 |
| 121 #end if | 132 #end if |
| 122 | 133 |
| 123 #elif str( $segm_cond.segmentationtool ) == 'kmeans': | 134 #elif str( $segm_cond.segmentationtool ) == 'centroids': |
| 124 print('kmeans') | 135 print('centroids') |
| 125 ##k-means | 136 ##centroids |
| 126 | 137 |
| 127 skm = spatialKMeans(msidata, r=c($segm_cond.kmeans_r), k=c($segm_cond.kmeans_k), method="$segm_cond.kmeans_method") | 138 ssc = spatialShrunkenCentroids(msidata, r=c($segm_cond.centroids_r), k=c($segm_cond.centroids_k), s=c($segm_cond.centroids_s), method="gaussian") |
| 128 | 139 |
| 129 ## remove msidata to clean up RAM space | 140 ## remove msidata to clean up RAM space |
| 130 rm(msidata) | 141 rm(msidata) |
| 131 gc() | 142 gc() |
| 132 | 143 |
| 133 print(image(skm, key=TRUE, main="K-means clustering", strip=FALSE, col= colourvector, layout=c(1,1), ylim=c(maximumy+2, minimumy-2))) | 144 ## new plots and summary table |
| 134 print(plot(skm, main="K-means plot", col= colourvector, strip=FALSE, layout=c(1,1))) | 145 |
| 135 | 146 summary_df = summary(ssc) |
| 136 skm_clusters = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) | 147 summary_df = as.data.frame(summary_df@listData) |
| 137 for (iteration in 1:length(skm@resultData)){ | 148 colnames(summary_df) = c("r", "initial_k", "s", "k", "features_per_k") |
| 138 skm_cluster = ((skm@resultData)[[iteration]]\$cluster) | 149 |
| 139 skm_clusters = cbind(skm_clusters, skm_cluster) } | 150 opar <- par() |
| 140 | 151 par(opar) |
| 141 ## pixel names and coordinates | 152 plot(0,type='n',axes=FALSE,ann=FALSE) |
| 142 ## to remove potential sample names and z dimension, split at comma and take only x and y | 153 title(main="\n Summary for the different parameters\n", adj=0.5) |
| 143 x_coords = unlist(lapply(strsplit(rownames(skm_clusters), ","), `[[`, 1)) | 154 ## 20 rows fits in one page: |
| 144 y_coords = unlist(lapply(strsplit(rownames(skm_clusters), ","), `[[`, 2)) | 155 if (nrow(summary_df)<=20){ |
| 145 x_coordinates = gsub("x = ","",x_coords) | 156 grid.table(summary_df, rows= NULL) |
| 146 y_coordinates = gsub(" y = ","",y_coords) | 157 }else{ |
| 147 pixel_names = paste0("xy_", x_coordinates, "_", y_coordinates) | 158 grid.table(summary_df[1:20,], rows= NULL) |
| 148 skm_clusters2 = data.frame(pixel_names, x_coordinates, y_coordinates, skm_clusters) | 159 mincount = 21 |
| 149 colnames(skm_clusters2) = c("pixel names", "x", "y",names(skm@resultData)) | 160 maxcount = 40 |
| 150 | 161 for (count20 in 1:(ceiling(nrow(summary_df)/20)-1)){ |
| 151 skm_toplabels = topFeatures(skm, n=$segm_cond.kmeans_toplabels) | 162 plot(0,type='n',axes=FALSE,ann=FALSE) |
| 152 | 163 if (maxcount <= nrow(summary_df)){ |
| 153 write.table(skm_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") | 164 grid.table(summary_df[mincount:maxcount,], rows= NULL) |
| 154 write.table(skm_clusters2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") | 165 mincount = mincount+20 |
| 155 | 166 maxcount = maxcount+20 |
| 156 ## optional output as .RData | 167 }else{### stop last page with last sample otherwise NA in table |
| 157 #if $output_rdata: | 168 grid.table(summary_df[mincount:nrow(summary_df),], rows= NULL)} |
| 158 | 169 } |
| 159 ## save as (.RData) | 170 } |
| 160 save(skm, file="$segmentation_rdata") | 171 |
| 161 | 172 ## plot |
| 162 #end if | 173 summary_df\$r <- factor(summary_df\$r) |
| 163 | 174 summary_df\$initial_k <- factor(summary_df\$initial_k) |
| 164 #elif str( $segm_cond.segmentationtool ) == 'centroids': | 175 |
| 165 print('centroids') | 176 cluster_plot = ggplot(summary_df, aes(x = s, y = k, color = initial_k)) + |
| 166 ##centroids | 177 geom_point(size = 3) + ### Add points |
| 167 | 178 geom_line() + |
| 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") | 179 theme_bw() + |
| 169 ## remove msidata to clean up RAM space | 180 facet_wrap(~ paste("r =", r)) + |
| 170 rm(msidata) | 181 labs(title = "Number of segments", y = "predicted number of k", x = "shrinkage parameter (s)") |
| 171 gc() | 182 |
| 172 print(image(ssc, key=TRUE, main="Spatial shrunken centroids", strip = TRUE, col= colourvector,layout=c(1,1), ylim=c(maximumy+2, minimumy-2))) | 183 print(cluster_plot) |
| 173 print(plot(ssc, main="Spatial shrunken centroids plot", col= colourvector, strip = TRUE,layout=c(1,1))) | 184 |
| 174 print(plot(ssc, mode = "tstatistics",key = TRUE, layout = c(1,1), main="t-statistics", col=colourvector)) | 185 s_value = c($segm_cond.centroids_s) |
| 175 | 186 k_value = c($segm_cond.centroids_k) |
| 176 plot(summary(ssc), main = "Number of segments") | 187 r_value = c($segm_cond.centroids_r) |
| 188 | |
| 189 to_remove = subset(summary_df, features_per_k == 0) | |
| 190 s_to_remove = unique(c(to_remove\$s)) | |
| 191 s_value = s_value[!s_value %in% s_to_remove] | |
| 192 | |
| 193 for (s in s_value) { | |
| 194 for (k in k_value) { | |
| 195 for (r in r_value) { | |
| 196 print(image(ssc, model = list(s = s, k = k, r = r), key = TRUE, values = "class", | |
| 197 main = paste("Spatial shrunken centroids (s =", s, ", k =", k, ", r =", r, ")"), | |
| 198 strip = FALSE, col = colourvector, layout = c(1, 1), ylim = c(maximumy+2, minimumy-2))) | |
| 199 | |
| 200 print(image(ssc, model = list(s = s, k = k, r = r), key = TRUE, values = "probability", | |
| 201 main = paste("Class Probability (s =", s, ", k =", k, ", r =", r, ")"), | |
| 202 strip = FALSE, col = colourvector, layout = c(1, 1), ylim = c(maximumy+2, minimumy-2))) | |
| 203 | |
| 204 print(plot(ssc, model = list(s = s, k = k, r = r), key = TRUE, | |
| 205 main = paste("Spatial shrunken centroids features (s =", s, ", k =", k, ", r =", r, ")"), | |
| 206 col = colourvector, strip = TRUE, layout = c(1, 1))) | |
| 207 | |
| 208 print(plot(ssc, model = list(s = s, k = k, r = r), values = "statistic", key = TRUE, | |
| 209 layout = c(1, 1), | |
| 210 main = paste("t-statistics (s =", s, ", k =", k, ", r =", r, ")"), | |
| 211 col = colourvector)) | |
| 212 } | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 | |
| 217 new_s_value = s_to_remove | |
| 218 | |
| 219 for (s in new_s_value) { | |
| 220 for (k in k_value) { | |
| 221 for (r in r_value) { | |
| 222 print(image(ssc, model = list(s = s, k = k, r = r), key = TRUE, values = "class", | |
| 223 main = paste("Spatial shrunken centroids (s =", s, ", k =", k, ", r =", r, ")"), | |
| 224 strip = FALSE, col = colourvector, layout = c(1, 1), ylim = c(maximumy+2, minimumy-2))) | |
| 225 | |
| 226 print(image(ssc, model = list(s = s, k = k, r = r), key = TRUE, values = "probability", | |
| 227 main = paste("Class Probability (s =", s, ", k =", k, ", r =", r, ")"), | |
| 228 strip = FALSE, col = colourvector, layout = c(1, 1), ylim = c(maximumy+2, minimumy-2))) | |
| 229 | |
| 230 print(plot(ssc, model = list(s = s, k = k, r = r), key = TRUE, | |
| 231 main = paste("Spatial shrunken centroids features (s =", s, ", k =", k, ", r =", r, ")"), | |
| 232 col = colourvector, strip = TRUE, layout = c(1, 1))) | |
| 233 | |
| 234 plot(0, 0, type = "n", xlab = "", ylab = "", xlim = c(0, 10), ylim = c(0, 10), xaxt = "n", yaxt = "n") | |
| 235 ## Add the text to the plot | |
| 236 text(5, 5, "t-statistics plot can not be drawn.\nS (shrinkage parameter) is too small to result\n in meaningful segmentation.", | |
| 237 cex = 1.5, adj = c(0.5, 0.5)) | |
| 238 | |
| 239 } | |
| 240 } | |
| 241 } | |
| 177 | 242 |
| 178 ssc_classes = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) | 243 ssc_classes = data.frame(matrix(NA, nrow = pixelcount, ncol = 0)) |
| 179 for (iteration in 1:length(ssc@resultData)){ | 244 for (iteration in 1:length(ssc@resultData@listData)){ |
| 180 ssc_class = ((ssc@resultData)[[iteration]]\$classes) | 245 ssc_class = ((ssc@resultData@listData)[[iteration]]\$class) |
| 181 ssc_classes = cbind(ssc_classes, ssc_class) } | 246 ssc_classes = cbind(ssc_classes, ssc_class) } |
| 182 | 247 |
| 183 ## pixel names and coordinates | 248 ## coordinates and topFeatures of results |
| 184 ## to remove potential sample names and z dimension, split at comma and take only x and y | 249 s_values = ssc@modelData@listData[["s"]] |
| 185 x_coords = unlist(lapply(strsplit(rownames(ssc_classes), ","), `[[`, 1)) | 250 r_values = ssc@modelData@listData[["r"]] |
| 186 y_coords = unlist(lapply(strsplit(rownames(ssc_classes), ","), `[[`, 2)) | 251 k_values = ssc@modelData@listData[["k"]] |
| 187 x_coordinates = gsub("x = ","",x_coords) | 252 new_names = paste0("r=", r_values, ", s=", s_values, ", k=", k_values) |
| 188 y_coordinates = gsub(" y = ","",y_coords) | 253 |
| 189 pixel_names = paste0("xy_", x_coordinates, "_", y_coordinates) | 254 ssc.coordinates = coord(ssc) |
| 190 ssc_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, ssc_classes) | 255 x_coords = ssc.coordinates@listData[["x"]] |
| 191 colnames(ssc_classes2) = c("pixel names", "x", "y", names(ssc@resultData)) | 256 y_coords = ssc.coordinates@listData[["y"]] |
| 257 pixel_names = paste0("xy_", x_coords, "_", y_coords) | |
| 258 | |
| 259 ssc_classes2 = data.frame(pixel_names, x_coords, y_coords, ssc_classes) | |
| 260 colnames(ssc_classes2) = c("pixel names", "x", "y", new_names) | |
| 192 | 261 |
| 193 ssc_toplabels = topFeatures(ssc, n=$segm_cond.centroids_toplabels) | 262 ssc_toplabels = topFeatures(ssc, n=$segm_cond.centroids_toplabels) |
| 194 | 263 |
| 195 write.table(ssc_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") | 264 write.table(ssc_toplabels, file="$mzfeatures", 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") | 265 write.table(ssc_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") |
| 266 | |
| 197 | 267 |
| 198 ## optional output as .RData | 268 ## optional output as .RData |
| 199 #if $output_rdata: | 269 #if $output_rdata: |
| 200 | 270 |
| 201 ## save as (.RData) | 271 ## save as (.RData) |
| 209 | 279 |
| 210 ## optional svg output with original coordinates | 280 ## optional svg output with original coordinates |
| 211 #if $svg_pixelimage: | 281 #if $svg_pixelimage: |
| 212 print("svg image") | 282 print("svg image") |
| 213 ## reverse y axis for svg output = correct order and nice svg image | 283 ## reverse y axis for svg output = correct order and nice svg image |
| 214 | |
| 215 | 284 |
| 216 svg(file="svg_pixel_output.svg", width=maximumx, height=maximumy) | 285 svg(file="svg_pixel_output.svg", width=maximumx, height=maximumy) |
| 217 par(mar=c(0,0,0,0)) | 286 par(mar=c(0,0,0,0)) |
| 218 #if str( $segm_cond.segmentationtool ) == 'pca': | 287 #if str( $segm_cond.segmentationtool ) == 'pca': |
| 219 coord(pca_result)\$y <- max(coord(pca_result)\$y) - coord(pca_result)\$y + 1 | 288 coord(pca_result)\$y <- max(coord(pca_result)\$y) - coord(pca_result)\$y + 1 |
| 228 dev.off() | 297 dev.off() |
| 229 #end if | 298 #end if |
| 230 | 299 |
| 231 | 300 |
| 232 }else{ | 301 }else{ |
| 302 plot.new() | |
| 303 text(0.5, 0.5, "Inputfile has no intensities > 0 \n or contains NA values.", cex = 1.5) | |
| 233 print("Inputfile has no intensities > 0") | 304 print("Inputfile has no intensities > 0") |
| 234 dev.off() | 305 dev.off() |
| 235 } | 306 } |
| 236 | 307 |
| 237 ]]></configfile> | 308 ]]></configfile> |
| 238 </configfiles> | 309 </configfiles> |
| 239 <inputs> | 310 <inputs> |
| 240 <expand macro="reading_msidata"/> | 311 <expand macro="reading_msidata"/> |
| 241 <conditional name="segm_cond"> | 312 <conditional name="segm_cond"> |
| 242 <param name="segmentationtool" type="select" label="Select the tool for spatial clustering"> | 313 <param name="segmentationtool" type="select" label="Select the tool for spatial clustering"> |
| 243 <option value="pca" selected="True">pca</option> | |
| 244 <option value="kmeans">k-means</option> | 314 <option value="kmeans">k-means</option> |
| 245 <option value="centroids">spatial shrunken centroids</option> | 315 <option value="centroids">spatial shrunken centroids</option> |
| 246 </param> | 316 </param> |
| 247 <when value="pca"> | |
| 248 <param name="pca_ncomp" type="integer" value="2" | |
| 249 label="The number of principal components to calculate"/> | |
| 250 <param name="pca_method" type="select" | |
| 251 label="The function used to calculate the singular value decomposition"> | |
| 252 <option value="irlba" selected="True">irlba</option> | |
| 253 <option value="svd">svd</option> | |
| 254 </param> | |
| 255 <param name="pca_scale" type="boolean" truevalue="TRUE" falsevalue="FALSE" label="Scaling of data before analysis"/> | |
| 256 </when> | |
| 257 <when value="kmeans"> | 317 <when value="kmeans"> |
| 258 <param name="kmeans_r" type="text" value="2" | 318 <param name="kmeans_r" type="text" value="2" |
| 259 label="The spatial neighborhood radius of nearby pixels to consider (r)" help="Multiple values are allowed (e.g. 1,2,3 or 2:5)"> | 319 label="The spatial neighborhood radius of nearby pixels to consider (r)" help="Multiple values are allowed (e.g. 1,2,3 or 2:5)"> |
| 260 <expand macro="sanitizer_multiple_digits"/> | 320 <expand macro="sanitizer_multiple_digits"/> |
| 261 </param> | 321 </param> |
| 262 <param name="kmeans_k" type="text" value="3" | 322 <param name="kmeans_k" type="text" value="3" |
| 263 label="The number of clusters (k)" help="Multiple values are allowed (e.g. 1,2,3 or 2:5)"> | 323 label="The number of clusters (k)" help="Multiple values are allowed (e.g. 1,2,3 or 2:5)"> |
| 264 <expand macro="sanitizer_multiple_digits"/> | 324 <expand macro="sanitizer_multiple_digits"/> |
| 265 </param> | 325 </param> |
| 266 <param name="kmeans_method" type="select" display="radio" | 326 <param name="kmeans_toplabels" type="integer" value="500" |
| 267 label="The method to use to calculate the spatial smoothing kernels for the embedding. The 'gaussian' method refers to spatially-aware (SA) clustering, and 'adaptive' refers to spatially-aware structurally-adaptive (SASA) clustering"> | |
| 268 <option value="gaussian">gaussian</option> | |
| 269 <option value="adaptive" selected="True">adaptive</option> | |
| 270 </param> | |
| 271 <param name="kmeans_toplabels" type="integer" value="500" | |
| 272 label="Number of toplabels (m/z) which should be written in tabular output"/> | 327 label="Number of toplabels (m/z) which should be written in tabular output"/> |
| 273 </when> | 328 </when> |
| 274 | 329 |
| 275 <when value="centroids"> | 330 <when value="centroids"> |
| 276 <param name="centroids_r" type="text" value="2" | 331 <param name="centroids_r" type="text" value="2" |
| 284 <param name="centroids_s" type="text" value="2" | 339 <param name="centroids_s" type="text" value="2" |
| 285 label="The sparsity thresholding parameter by which to shrink the t-statistics (s)" | 340 label="The sparsity thresholding parameter by which to shrink the t-statistics (s)" |
| 286 help="As s increases, fewer m/z features (m/z values) will be used in the spatial segmentation, and only the informative m/z features will be retained. Multiple values are allowed (e.g. 1,2,3 or 2:5)"> | 341 help="As s increases, fewer m/z features (m/z values) will be used in the spatial segmentation, and only the informative m/z features will be retained. Multiple values are allowed (e.g. 1,2,3 or 2:5)"> |
| 287 <expand macro="sanitizer_multiple_digits"/> | 342 <expand macro="sanitizer_multiple_digits"/> |
| 288 </param> | 343 </param> |
| 289 <param name="centroids_method" type="select" display="radio" label="The method to use to calculate the spatial smoothing kernels for the embedding. The 'gaussian' method refers to spatially-aware (SA) weights, and 'adaptive' refers to spatially-aware structurally-adaptive (SASA) weights"> | 344 |
| 290 <option value="gaussian">gaussian</option> | |
| 291 <option value="adaptive" selected="True">adaptive</option> | |
| 292 </param> | |
| 293 <param name="centroids_toplabels" type="integer" value="500" | 345 <param name="centroids_toplabels" type="integer" value="500" |
| 294 label="Number of toplabels (m/z) which should be written in tabular output"/> | 346 label="Number of toplabels (m/z) which should be written in tabular output"/> |
| 295 </when> | 347 </when> |
| 296 </conditional> | 348 </conditional> |
| 297 <param name="svg_pixelimage" type="boolean" label="Export first segmentation image as svg"/> | 349 <param name="svg_pixelimage" type="boolean" label="Export first segmentation image as svg"/> |
| 298 <repeat name="colours" title="Colours for the plots" min="1" max="50"> | 350 |
| 299 <param name="feature_color" type="color" label="Colours" value="#ff00ff" help="Numbers of colours should be the same as number of components"> | 351 <conditional name="colour_conditional"> |
| 300 <sanitizer> | 352 <param name="colour_type" type="select" label="Choose a colour scheme"> |
| 301 <valid initial="string.letters,string.digits"> | 353 <option value="colourpalette" selected="True" >Colour palette</option> |
| 302 <add value="#" /> | 354 <option value="manual_colour">Manual selection</option> |
| 303 </valid> | 355 </param> |
| 304 </sanitizer> | 356 <when value="manual_colour"> |
| 357 <repeat name="colours" title="Colours for the plots" min="1" max="50"> | |
| 358 <param name="annotation_color" type="color" label="Colours" value="#ff00ff" help="Numbers of colours should be the same as number of components"> | |
| 359 <sanitizer> | |
| 360 <valid initial="string.letters,string.digits"> | |
| 361 <add value="#" /> | |
| 362 </valid> | |
| 363 </sanitizer> | |
| 364 </param> | |
| 365 </repeat> | |
| 366 </when> | |
| 367 <when value="colourpalette"> | |
| 368 <param name="palettes" type="select" display="radio" label="Select a colourpalette"> | |
| 369 <option value="hue_pal()" selected="True">hue</option> | |
| 370 <option value="rainbow">rainbow</option> | |
| 371 <option value="heat.colors">heat colors</option> | |
| 372 <option value="terrain.colors">terrain colors</option> | |
| 373 <option value="topo.colors">topo colors</option> | |
| 374 <option value="cm.colors">cm colors</option> | |
| 305 </param> | 375 </param> |
| 306 </repeat> | 376 </when> |
| 307 <param name="output_rdata" type="boolean" label="Results as .RData output"/> | 377 </conditional> |
| 308 <param name="setseed" type="integer" value="1" label="set seed" help="Use same value to reproduce previous results"/> | 378 <param name="output_rdata" type="boolean" label="Results as .RData output"/> |
| 379 <param name="setseed" type="integer" value="1" label="set seed" help="Use same value to reproduce previous results"/> | |
| 309 </inputs> | 380 </inputs> |
| 310 <outputs> | 381 <outputs> |
| 311 <data format="pdf" name="segmentationimages" from_work_dir="segmentationpdf.pdf" label = "${tool.name} on ${on_string}: results"/> | 382 <data format="pdf" name="segmentationimages" from_work_dir="segmentationpdf.pdf" label = "${tool.name} on ${on_string}: results"/> |
| 312 <data format="tabular" name="mzfeatures" label="${tool.name} on ${on_string}: features"/> | 383 <data format="tabular" name="mzfeatures" label="${tool.name} on ${on_string}: features"/> |
| 313 <data format="tabular" name="pixeloutput" label="${tool.name} on ${on_string}: pixels"/> | 384 <data format="tabular" name="pixeloutput" label="${tool.name} on ${on_string}: pixels"/> |
| 317 <data format="svg" name="svg_output" from_work_dir="svg_pixel_output.svg" label="${tool.name} on ${on_string}: image.svg"> | 388 <data format="svg" name="svg_output" from_work_dir="svg_pixel_output.svg" label="${tool.name} on ${on_string}: image.svg"> |
| 318 <filter>svg_pixelimage</filter> | 389 <filter>svg_pixelimage</filter> |
| 319 </data> | 390 </data> |
| 320 </outputs> | 391 </outputs> |
| 321 <tests> | 392 <tests> |
| 322 <test> | 393 <test expect_num_outputs="4"> |
| 323 <expand macro="infile_imzml"/> | |
| 324 <param name="segmentationtool" value="pca"/> | |
| 325 <repeat name="colours"> | |
| 326 <param name="feature_color" value="#ff00ff"/> | |
| 327 </repeat> | |
| 328 <repeat name="colours"> | |
| 329 <param name="feature_color" value="#0000FF"/> | |
| 330 </repeat> | |
| 331 <output name="segmentationimages" file="pca_imzml.pdf" compare="sim_size"/> | |
| 332 <output name="mzfeatures"> | |
| 333 <assert_contents> | |
| 334 <has_text text="300.1667" /> | |
| 335 <has_text text="300.25" /> | |
| 336 <has_text text="-4.234458e-04" /> | |
| 337 <has_text text="3.878545e-10" /> | |
| 338 <has_n_columns n="3" /> | |
| 339 </assert_contents> | |
| 340 </output> | |
| 341 <output name="pixeloutput" file="scores_pca.tabular"/> | |
| 342 </test> | |
| 343 <test> | |
| 344 <expand macro="infile_imzml"/> | 394 <expand macro="infile_imzml"/> |
| 345 <param name="segmentationtool" value="kmeans"/> | 395 <param name="segmentationtool" value="kmeans"/> |
| 346 <param name="kmeans_r" value="1:3"/> | 396 <param name="kmeans_r" value="1:3"/> |
| 347 <param name="kmeans_k" value="2,3"/> | 397 <param name="kmeans_k" value="2,3"/> |
| 348 <param name="kmeans_toplabels" value="20"/> | 398 <param name="kmeans_toplabels" value="20"/> |
| 359 <output name="segmentationimages" file="kmeans_analyze.pdf" compare="sim_size"/> | 409 <output name="segmentationimages" file="kmeans_analyze.pdf" compare="sim_size"/> |
| 360 <output name="mzfeatures" file="toplabels_skm.tabular"/> | 410 <output name="mzfeatures" file="toplabels_skm.tabular"/> |
| 361 <output name="pixeloutput" file="cluster_skm.tabular"/> | 411 <output name="pixeloutput" file="cluster_skm.tabular"/> |
| 362 <output name="segmentation_rdata" file="cluster_skm.RData" compare="sim_size"/> | 412 <output name="segmentation_rdata" file="cluster_skm.RData" compare="sim_size"/> |
| 363 </test> | 413 </test> |
| 364 <test> | 414 <test expect_num_outputs="3"> |
| 365 <param name="infile" value="preprocessed.RData" ftype="rdata"/> | 415 <param name="infile" value="preprocessed.RData" ftype="rdata"/> |
| 366 <param name="segmentationtool" value="centroids"/> | 416 <param name="segmentationtool" value="centroids"/> |
| 367 <param name="centroids_r" value="1,2"/> | 417 <param name="centroids_r" value="1,2"/> |
| 368 <param name="centroids_k" value="3"/> | 418 <param name="centroids_k" value="3"/> |
| 369 <param name="centroids_toplabels" value="50"/> | 419 <param name="centroids_toplabels" value="50"/> |
| 378 </repeat> | 428 </repeat> |
| 379 <output name="segmentationimages" file="centroids_rdata.pdf" compare="sim_size"/> | 429 <output name="segmentationimages" file="centroids_rdata.pdf" compare="sim_size"/> |
| 380 <output name="mzfeatures" file="toplabels_ssc.tabular"/> | 430 <output name="mzfeatures" file="toplabels_ssc.tabular"/> |
| 381 <output name="pixeloutput" file="classes_ssc.tabular"/> | 431 <output name="pixeloutput" file="classes_ssc.tabular"/> |
| 382 </test> | 432 </test> |
| 383 <test> | 433 <test expect_num_outputs="3"> |
| 384 <expand macro="processed_infile_imzml"/> | 434 <expand macro="processed_infile_imzml"/> |
| 385 <conditional name="processed_cond"> | 435 <conditional name="processed_cond"> |
| 386 <param name="processed_file" value="processed"/> | 436 <param name="processed_file" value="processed"/> |
| 387 <param name="accuracy" value="200"/> | 437 <param name="accuracy" value="200"/> |
| 388 <param name="units" value="ppm"/> | 438 <param name="units" value="ppm"/> |
| 399 <param name="feature_color" value="#00C957"/> | 449 <param name="feature_color" value="#00C957"/> |
| 400 </repeat> | 450 </repeat> |
| 401 <repeat name="colours"> | 451 <repeat name="colours"> |
| 402 <param name="feature_color" value="#B0171F"/> | 452 <param name="feature_color" value="#B0171F"/> |
| 403 </repeat> | 453 </repeat> |
| 404 <output name="segmentationimages" file="centroids_proc.pdf" compare="sim_size"/> | 454 <output name="segmentationimages" ftype="pdf"> |
| 455 <assert_contents> | |
| 456 <has_size value="1206464" delta="100"/> | |
| 457 </assert_contents> | |
| 458 </output> | |
| 405 <output name="pixeloutput" file="classes_proc.tabular"/> | 459 <output name="pixeloutput" file="classes_proc.tabular"/> |
| 406 <output name="mzfeatures"> | 460 <output name="mzfeatures"> |
| 407 <assert_contents> | 461 <assert_contents> |
| 408 <has_text text="100.642" /> | 462 <has_text text="177.926436700994"/> |
| 409 <has_text text="101.816297645089" /> | 463 <has_text text="192.976841249583"/> |
| 410 <has_text text="1.34687866193417" /> | 464 <has_text text="0.818218808031712"/> |
| 411 <has_text text="6.43855724908388" /> | 465 <has_text text="0.469980133537009"/> |
| 412 <has_n_columns n="9" /> | 466 <has_n_columns n="7"/> |
| 413 <has_n_lines n="101" /> | 467 <has_n_lines n="101"/> |
| 414 </assert_contents> | 468 </assert_contents> |
| 415 </output> | 469 </output> |
| 416 </test> | 470 </test> |
| 417 </tests> | 471 </tests> |
| 418 <help> | 472 <help> |
