comparison classification.xml @ 2:cbc7e53518ce 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:18:51 -0500
parents 6a03b201bc12
children 585ef27873c9
comparison
equal deleted inserted replaced
1:6a03b201bc12 2:cbc7e53518ce
1 <tool id="cardinal_classification" name="MSI classification" version="@VERSION@.1"> 1 <tool id="cardinal_classification" name="MSI classification" version="@VERSION@.2">
2 <description>spatial classification of mass spectrometry imaging data</description> 2 <description>spatial classification of mass spectrometry imaging data</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">
26 library(Cardinal) 26 library(Cardinal)
27 library(gridExtra) 27 library(gridExtra)
28 library(lattice) 28 library(lattice)
29 library(ggplot2) 29 library(ggplot2)
30 30
31 @READING_MSIDATA@ 31 @READING_MSIDATA_INRAM@
32 32
33 ## create full matrix to make processed imzML files compatible with classification 33 ## to make sure that processed files work as well:
34 iData(msidata) <- iData(msidata)[] 34 iData(msidata) = iData(msidata)[]
35 35
36 @DATA_PROPERTIES@ 36 @DATA_PROPERTIES_INRAM@
37
37 38
38 ######################################## PDF ################################### 39 ######################################## PDF ###################################
39 ################################################################################ 40 ################################################################################
40 ################################################################################ 41 ################################################################################
41 42
58 59
59 ## table with values 60 ## table with values
60 grid.table(property_df, rows= NULL) 61 grid.table(property_df, rows= NULL)
61 62
62 63
63 if (npeaks > 0 && sum(is.na(spectra(msidata)))==0){ 64 if (npeaks > 0 && sum(is.na(spectra(msidata)[]))==0){
64 65
65 opar <- par() 66 opar <- par()
66 67
67 ######################## II) Training ############################# 68 ######################## II) Training #############################
68 ############################################################################# 69 #############################################################################
138 components = c($type_cond.method_cond.analysis_cond.plscv_comp) 139 components = c($type_cond.method_cond.analysis_cond.plscv_comp)
139 number_groups = length(levels(y_vector)) 140 number_groups = length(levels(y_vector))
140 141
141 ## PLS-cvApply: 142 ## PLS-cvApply:
142 msidata.cv.pls <- cvApply(msidata, .y = y_vector, .fold = fold_vector, .fun = "PLS", ncomp = components) 143 msidata.cv.pls <- cvApply(msidata, .y = y_vector, .fold = fold_vector, .fun = "PLS", ncomp = components)
144
145 ## remove msidata to clean up RAM space
146 rm(msidata)
147 gc()
143 148
144 ## create table with summary 149 ## create table with summary
145 count = 1 150 count = 1
146 summary_plscv = list() 151 summary_plscv = list()
147 accuracy_vector = numeric() 152 accuracy_vector = numeric()
229 pixel_names = gsub(", y = ", "_", names(pixels(msidata))) 234 pixel_names = gsub(", y = ", "_", names(pixels(msidata)))
230 pixel_names = gsub(" = ", "y_", pixel_names) 235 pixel_names = gsub(" = ", "y_", pixel_names)
231 x_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,2] 236 x_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,2]
232 y_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,3] 237 y_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,3]
233 238
239 ## remove msidata to clean up RAM space
240 rm(msidata)
241 gc()
234 pls_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, pls_classes) 242 pls_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, pls_classes)
235 colnames(pls_classes2) = c("pixel names", "x", "y","predicted condition") 243 colnames(pls_classes2) = c("pixel names", "x", "y","predicted condition")
236 pls_toplabels = topLabels(msidata.pls, n=$type_cond.method_cond.analysis_cond.pls_toplabels) 244 pls_toplabels = topLabels(msidata.pls, n=$type_cond.method_cond.analysis_cond.pls_toplabels)
245 pls_toplabels[,4:6] <-round(pls_toplabels[,4:6],6)
237 write.table(pls_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 246 write.table(pls_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
238 write.table(pls_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 247 write.table(pls_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
239 248
240 ## image with predicted classes 249 ## image with predicted classes
241 prediction_df = cbind(coord(msidata.pls)[,1:2], pls_classes) 250 prediction_df = cbind(coord(msidata.pls)[,1:2], pls_classes)
272 components = c($type_cond.method_cond.opls_analysis_cond.opls_cvcomp) 281 components = c($type_cond.method_cond.opls_analysis_cond.opls_cvcomp)
273 number_groups = length(levels(y_vector)) 282 number_groups = length(levels(y_vector))
274 283
275 ## OPLS-cvApply: 284 ## OPLS-cvApply:
276 msidata.cv.opls <- cvApply(msidata, .y = y_vector, .fold = fold_vector, .fun = "OPLS", ncomp = components, keep.Xnew = $type_cond.method_cond.opls_analysis_cond.xnew_cv) 285 msidata.cv.opls <- cvApply(msidata, .y = y_vector, .fold = fold_vector, .fun = "OPLS", ncomp = components, keep.Xnew = $type_cond.method_cond.opls_analysis_cond.xnew_cv)
286
287 ## remove msidata to clean up RAM space
288 rm(msidata)
289 gc()
277 290
278 ## create table with summary 291 ## create table with summary
279 count = 1 292 count = 1
280 summary_oplscv = list() 293 summary_oplscv = list()
281 accuracy_vector = numeric() 294 accuracy_vector = numeric()
367 x_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,2] 380 x_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,2]
368 y_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,3] 381 y_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,3]
369 opls_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, opls_classes) 382 opls_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, opls_classes)
370 colnames(opls_classes2) = c("pixel names", "x", "y","predicted condition") 383 colnames(opls_classes2) = c("pixel names", "x", "y","predicted condition")
371 384
385 ## remove msidata to clean up RAM space
386 rm(msidata)
387 gc()
388
372 opls_toplabels = topLabels(msidata.opls, n=$type_cond.method_cond.opls_analysis_cond.opls_toplabels) 389 opls_toplabels = topLabels(msidata.opls, n=$type_cond.method_cond.opls_analysis_cond.opls_toplabels)
390 opls_toplabels[,4:6] <-round(opls_toplabels[,4:6],6)
373 write.table(opls_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 391 write.table(opls_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
374 write.table(opls_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 392 write.table(opls_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
375 393
376 ## image with predicted classes 394 ## image with predicted classes
377 prediction_df = cbind(coord(msidata.opls)[,1:2], opls_classes) 395 prediction_df = cbind(coord(msidata.opls)[,1:2], opls_classes)
407 ## set variables for components and number of response groups 425 ## set variables for components and number of response groups
408 number_groups = length(levels(y_vector)) 426 number_groups = length(levels(y_vector))
409 427
410 ## SSC-cvApply: 428 ## SSC-cvApply:
411 msidata.cv.ssc <- cvApply(msidata, .y = y_vector,.fold = fold_vector,.fun = "spatialShrunkenCentroids", r = c($type_cond.method_cond.ssc_r), s = c($type_cond.method_cond.ssc_s), method = "$type_cond.method_cond.ssc_kernel_method") 429 msidata.cv.ssc <- cvApply(msidata, .y = y_vector,.fold = fold_vector,.fun = "spatialShrunkenCentroids", r = c($type_cond.method_cond.ssc_r), s = c($type_cond.method_cond.ssc_s), method = "$type_cond.method_cond.ssc_kernel_method")
430
431 ## remove msidata to clean up RAM space
432 rm(msidata)
433 gc()
412 434
413 ## create table with summary 435 ## create table with summary
414 count = 1 436 count = 1
415 summary_ssccv = list() 437 summary_ssccv = list()
416 accuracy_vector = numeric() 438 accuracy_vector = numeric()
500 ssc_classes = data.frame(msidata.ssc\$classes[[1]]) 522 ssc_classes = data.frame(msidata.ssc\$classes[[1]])
501 pixel_names = gsub(", y = ", "_", names(pixels(msidata))) 523 pixel_names = gsub(", y = ", "_", names(pixels(msidata)))
502 pixel_names = gsub(" = ", "y_", pixel_names) 524 pixel_names = gsub(" = ", "y_", pixel_names)
503 x_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,2] 525 x_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,2]
504 y_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,3] 526 y_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,3]
527
528 ## remove msidata to clean up RAM space
529 rm(msidata)
530 gc()
531
505 ssc_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, ssc_classes) 532 ssc_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, ssc_classes)
506 colnames(ssc_classes2) = c("pixel names", "x", "y","predicted condition") 533 colnames(ssc_classes2) = c("pixel names", "x", "y","predicted condition")
507 ssc_toplabels = topLabels(msidata.ssc, n=$type_cond.method_cond.ssc_analysis_cond.ssc_toplabels) 534 ssc_toplabels = topLabels(msidata.ssc, n=$type_cond.method_cond.ssc_analysis_cond.ssc_toplabels)
535 ssc_toplabels[,6:9] <-round(ssc_toplabels[,6:9],6)
508 write.table(ssc_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 536 write.table(ssc_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
509 write.table(ssc_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 537 write.table(ssc_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
510 538
511 ## image with predicted classes 539 ## image with predicted classes
512 prediction_df = cbind(coord(msidata.ssc)[,1:2], ssc_classes) 540 prediction_df = cbind(coord(msidata.ssc)[,1:2], ssc_classes)
569 x_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,2] 597 x_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,2]
570 y_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,3] 598 y_coordinates = matrix(unlist(strsplit(pixel_names, "_")), ncol=3, byrow=TRUE)[,3]
571 predicted_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, predicted_classes) 599 predicted_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, predicted_classes)
572 colnames(predicted_classes2) = c("pixel names", "x", "y","predicted condition") 600 colnames(predicted_classes2) = c("pixel names", "x", "y","predicted condition")
573 predicted_toplabels = topLabels(prediction, n=$type_cond.predicted_toplabels) 601 predicted_toplabels = topLabels(prediction, n=$type_cond.predicted_toplabels)
602 if (colnames(predicted_toplabels)[4] == "coefficients"){
603 predicted_toplabels[,4:6] <-round(predicted_toplabels[,4:6],5)
604
605 }else{
606 predicted_toplabels[,6:9] <-round(predicted_toplabels[,6:9],5)}
574 write.table(predicted_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 607 write.table(predicted_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
575 write.table(predicted_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") 608 write.table(predicted_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
576 609
577 ## image with predicted classes 610 ## image with predicted classes
578 611
743 </when> 776 </when>
744 </conditional> 777 </conditional>
745 <param name="output_rdata" type="boolean" label="Results as .RData output" help="Can be used to generate a classification prediction on new data"/> 778 <param name="output_rdata" type="boolean" label="Results as .RData output" help="Can be used to generate a classification prediction on new data"/>
746 </inputs> 779 </inputs>
747 <outputs> 780 <outputs>
748 <data format="pdf" name="classification_images" from_work_dir="classificationpdf.pdf" label = "${tool.name} on ${on_string}"/> 781 <data format="pdf" name="classification_images" from_work_dir="classificationpdf.pdf" label = "${tool.name} on ${on_string}: results"/>
749 <data format="tabular" name="mzfeatures" label="${tool.name} on ${on_string}: features"/> 782 <data format="tabular" name="mzfeatures" label="${tool.name} on ${on_string}: features"/>
750 <data format="tabular" name="pixeloutput" label="${tool.name} on ${on_string}: pixels"/> 783 <data format="tabular" name="pixeloutput" label="${tool.name} on ${on_string}: pixels"/>
751 <data format="rdata" name="classification_rdata" label="${tool.name} on ${on_string}: results.RData"> 784 <data format="rdata" name="classification_rdata" label="${tool.name} on ${on_string}: results.RData">
752 <filter>output_rdata</filter> 785 <filter>output_rdata</filter>
753 </data> 786 </data>