# HG changeset patch # User galaxyp # Date 1624260958 0 # Node ID f28ad96b76dcbe7dd131938b43ed716ec30d2f7a # Parent ece627528a78ca292e96c84df3a8756e4f53613c "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit d0dc9303d449c63a6ffe8fbfe195951d5db9cb89-dirty" diff -r ece627528a78 -r f28ad96b76dc classification.xml --- a/classification.xml Fri May 07 10:10:35 2021 +0000 +++ b/classification.xml Mon Jun 21 07:35:58 2021 +0000 @@ -1,4 +1,4 @@ - + spatial classification of mass spectrometry imaging data macros.xml @@ -92,6 +92,18 @@ merged_response = merged_response[order(merged_response\$pixel_index),] conditions = as.factor(merged_response[,4]) y_vector = conditions + + ## colours selection: + + #if str($colour_conditional.colour_type) == "manual_colour" + #set $color_string = ','.join(['"%s"' % $color.annotation_color for $color in $colour_conditional.colours]) + colourvector = c($color_string) + + #elif str($colour_conditional.colour_type) == "colourpalette" + number_levels = (length(levels(conditions))) + colourvector = noquote($colour_conditional.palettes)(number_levels) + + #end if ## plot of y vector @@ -107,7 +119,8 @@ panel.grid.minor = element_blank())+ theme(text=element_text(family="ArialMT", face="bold", size=15))+ theme(legend.position="bottom",legend.direction="vertical")+ - guides(fill=guide_legend(ncol=4,byrow=TRUE)) + guides(fill=guide_legend(ncol=4,byrow=TRUE))+ + scale_discrete_manual(aesthetics = c("colour", "fill"), values = colourvector) coord_labels = aggregate(cbind(x,y)~conditions, data=position_df, mean, na.rm=TRUE, na.action="na.pass") coord_labels\$file_number = gsub( "_.*$", "", coord_labels\$conditions) print(y_plot) @@ -183,7 +196,7 @@ ## one image for each sample/fold, 4 images per page minimumy = min(coord(msidata.cv.pls)[,2]) maximumy = max(coord(msidata.cv.pls)[,2]) - image(msidata.cv.pls, model = list(ncomp = ncomp_max),ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy),layout = c(1, 1)) + image(msidata.cv.pls, model = list(ncomp = ncomp_max),ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy),layout = c(1, 1), col=colourvector) ## print table with summary in pdf par(opar) @@ -240,7 +253,7 @@ ### pls analysis and coefficients plot msidata.pls <- PLS(msidata, y = y_vector, ncomp = component, scale=$type_cond.method_cond.analysis_cond.pls_scale) - plot(msidata.pls, main="PLS coefficients per m/z") + plot(msidata.pls, main="PLS coefficients per m/z", col=colourvector) ### summary table of PLS summary_table = summary(msidata.pls)\$accuracy[[paste0("ncomp = ",component)]] @@ -292,7 +305,8 @@ panel.grid.minor = element_blank())+ theme(text=element_text(family="ArialMT", face="bold", size=15))+ theme(legend.position="bottom",legend.direction="vertical")+ - guides(fill=guide_legend(ncol=4,byrow=TRUE)) + guides(fill=guide_legend(ncol=4,byrow=TRUE))+ + scale_discrete_manual(aesthetics = c("colour", "fill"), values = colourvector) coord_labels = aggregate(cbind(x,y)~predicted_classes, data=prediction_df, mean, na.rm=TRUE, na.action="na.pass") coord_labels\$file_number = gsub( "_.*$", "", coord_labels\$predicted_classes) print(prediction_plot) @@ -351,7 +365,7 @@ ## one image for each sample/fold, 4 images per page minimumy = min(coord(msidata.cv.opls)[,2]) maximumy = max(coord(msidata.cv.opls)[,2]) - image(msidata.cv.opls, model = list(ncomp = ncomp_max),ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy),layout = c(1, 1)) + image(msidata.cv.opls, model = list(ncomp = ncomp_max),ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy),layout = c(1, 1), col=colourvector) ## print table with summary in pdf par(opar) @@ -409,7 +423,7 @@ ### opls analysis and coefficients plot msidata.opls <- PLS(msidata, y = y_vector, ncomp = component, scale=$type_cond.method_cond.opls_analysis_cond.opls_scale) ## to reduce msidata: keep.Xnew = $type_cond.method_cond.opls_analysis_cond.xnew - plot(msidata.opls, main="OPLS coefficients per m/z") + plot(msidata.opls, main="OPLS coefficients per m/z", col=colourvector) ### summary table of OPLS @@ -463,7 +477,8 @@ panel.grid.minor = element_blank())+ theme(text=element_text(family="ArialMT", face="bold", size=15))+ theme(legend.position="bottom",legend.direction="vertical")+ - guides(fill=guide_legend(ncol=4,byrow=TRUE)) + guides(fill=guide_legend(ncol=4,byrow=TRUE))+ + scale_discrete_manual(aesthetics = c("colour", "fill"), values = colourvector) coord_labels = aggregate(cbind(x,y)~predicted_classes, data=prediction_df, mean, na.rm=TRUE, na.action="na.pass") coord_labels\$file_number = gsub( "_.*$", "", coord_labels\$predicted_classes) print(prediction_plot) @@ -522,7 +537,7 @@ s_value = as.numeric(substring(unlist(strsplit(best_params, ","))[3], 5)) ## remove space minimumy = min(coord(msidata.cv.ssc)[,2]) maximumy = max(coord(msidata.cv.ssc)[,2]) - image(msidata.cv.ssc, model = list( r = r_value, s = s_value ), ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy),layout=c(1,1)) + image(msidata.cv.ssc, model = list( r = r_value, s = s_value ), ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy),layout=c(1,1), col=colourvector) #if $type_cond.method_cond.ssc_analysis_cond.write_best_params: write.table(r_value, file="$best_r", quote = FALSE, row.names = FALSE, col.names=FALSE, sep = "\t") @@ -567,9 +582,7 @@ msidata.ssc <- spatialShrunkenCentroids(msidata, y = y_vector, r = c($type_cond.method_cond.ssc_r), s = c($type_cond.method_cond.ssc_s), method = "$type_cond.method_cond.ssc_kernel_method") plot(msidata.ssc, mode = "tstatistics", model = list("r" = c($type_cond.method_cond.ssc_r), "s" = c($type_cond.method_cond.ssc_s)), - col=hue_pal()(length(levels(msidata.ssc\$classes[[1]]))), lwd=2) - - + col=colourvector, lwd=2) ### summary table SSC ##############summary_table = summary(msidata.ssc) @@ -629,10 +642,10 @@ write.table(ssc_toplabels, file="$mzfeatures", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") write.table(ssc_classes2, file="$pixeloutput", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") - image(msidata.ssc, model=list(r = c($type_cond.method_cond.ssc_r), s = c($type_cond.method_cond.ssc_s)), - col=hue_pal()(length(levels(msidata.ssc\$classes[[1]]))), mode="classes", layout=c(1,1), main="Class Prediction") - image(msidata.ssc, model=list(r = c($type_cond.method_cond.ssc_r), s = c($type_cond.method_cond.ssc_s)), - col=hue_pal()(length(levels(msidata.ssc\$classes[[1]]))), mode="probabilities", layout=c(1,1), main="Class probabilities") + image(msidata.ssc, model=list(r = c($type_cond.method_cond.ssc_r), s = c($type_cond.method_cond.ssc_s)), ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy), + col=colourvector, mode="classes", layout=c(1,1), main="Class Prediction") + image(msidata.ssc, model=list(r = c($type_cond.method_cond.ssc_r), s = c($type_cond.method_cond.ssc_s)), ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy), + col=colourvector, mode="probabilities", layout=c(1,1), main="Class probabilities") ## image with right and wrong classes: @@ -692,6 +705,9 @@ new_y_vector = as.factor(merged_response[,4]) prediction = predict(training_data,msidata, newy = new_y_vector) + ##numbers of levels for colour selection + number_levels = length(levels(new_y_vector)) + ## Summary table prediction summary_table = summary(prediction)\$accuracy[[names(prediction@resultData)]] summary_table2 = round(as.numeric(summary_table), digits=2) @@ -704,7 +720,19 @@ #else prediction = predict(training_data,msidata) + number_levels = length(levels(training_data\$y[[1]])) #end if + + ## colours selection: + + #if str($colour_conditional.colour_type) == "manual_colour" + #set $color_string = ','.join(['"%s"' % $color.annotation_color for $color in $colour_conditional.colours]) + colourvector = c($color_string) + + #elif str($colour_conditional.colour_type) == "colourpalette" + colourvector = noquote($colour_conditional.palettes)(number_levels) + + #end if ## m/z and pixel information output predicted_classes = data.frame(prediction\$classes[[1]]) @@ -730,8 +758,8 @@ predicted_classes2 = data.frame(pixel_names, x_coordinates, y_coordinates, predicted_classes, predicted_probabilities) colnames(predicted_classes2) = c("pixel names", "x", "y","predicted condition", levels(prediction\$classes[[1]])) ## also image modes are specific to SSC - image(prediction, mode="classes", layout=c(1,1), main="Class", col=hue_pal()(length(unique(prediction\$classes[[1]])))) - image(prediction, mode="probabilities", layout=c(1,1), main="Class probabilities", col=hue_pal()(length(unique(prediction\$classes[[1]])))) + image(prediction, mode="classes", layout=c(1,1), main="Class", ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy), col=colourvector) + image(prediction, mode="probabilities", layout=c(1,1), main="Class probabilities",ylim= c(maximumy+0.2*maximumy,minimumy-0.2*minimumy), col=colourvector) #else @@ -746,7 +774,8 @@ panel.grid.minor = element_blank())+ theme(text=element_text(family="ArialMT", face="bold", size=15))+ theme(legend.position="bottom", legend.direction="vertical")+ - guides(fill=guide_legend(ncol=4, byrow=TRUE)) + guides(fill=guide_legend(ncol=4, byrow=TRUE))+ + scale_discrete_manual(aesthetics = c("colour", "fill"), values = colourvector) coord_labels = aggregate(cbind(x,y)~predicted_classes, data=prediction_df, mean, na.rm=TRUE, na.action="na.pass") coord_labels\$file_number = gsub( "_.*ยง", "", coord_labels\$predicted_classes) print(prediction_plot) @@ -924,6 +953,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r ece627528a78 -r f28ad96b76dc test-data/test1.pdf Binary file test-data/test1.pdf has changed diff -r ece627528a78 -r f28ad96b76dc test-data/test2.pdf Binary file test-data/test2.pdf has changed diff -r ece627528a78 -r f28ad96b76dc test-data/test3.pdf Binary file test-data/test3.pdf has changed diff -r ece627528a78 -r f28ad96b76dc test-data/test4.pdf Binary file test-data/test4.pdf has changed diff -r ece627528a78 -r f28ad96b76dc test-data/test5.pdf Binary file test-data/test5.pdf has changed diff -r ece627528a78 -r f28ad96b76dc test-data/test6.pdf Binary file test-data/test6.pdf has changed diff -r ece627528a78 -r f28ad96b76dc test-data/test6.rdata Binary file test-data/test6.rdata has changed diff -r ece627528a78 -r f28ad96b76dc test-data/test7.pdf Binary file test-data/test7.pdf has changed diff -r ece627528a78 -r f28ad96b76dc test-data/test7.rdata Binary file test-data/test7.rdata has changed