Mercurial > repos > galaxyp > cardinal_classification
changeset 15:f28ad96b76dc draft
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit d0dc9303d449c63a6ffe8fbfe195951d5db9cb89-dirty"
author | galaxyp |
---|---|
date | Mon, 21 Jun 2021 07:35:58 +0000 |
parents | ece627528a78 |
children | eddc2ae2db80 |
files | classification.xml test-data/test1.pdf test-data/test2.pdf test-data/test3.pdf test-data/test4.pdf test-data/test5.pdf test-data/test6.pdf test-data/test6.rdata test-data/test7.pdf test-data/test7.rdata |
diffstat | 10 files changed, 75 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ -<tool id="cardinal_classification" name="MSI classification" version="@VERSION@.1"> +<tool id="cardinal_classification" name="MSI classification" version="@VERSION@.2"> <description>spatial classification of mass spectrometry imaging data</description> <macros> <import>macros.xml</import> @@ -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 @@ </conditional> </when> </conditional> + <conditional name="colour_conditional"> + <param name="colour_type" type="select" label="Choose a colour scheme"> + <option value="colourpalette" selected="True" >Colour palette</option> + <option value="manual_colour">Manual selection</option> + </param> + <when value="manual_colour"> + <repeat name="colours" title="Colours for the plots" min="1" max="50"> + <param name="annotation_color" type="color" label="Colours" value="#ff00ff" help="Numbers of colours should be the same as number of components"> + <sanitizer> + <valid initial="string.letters,string.digits"> + <add value="#" /> + </valid> + </sanitizer> + </param> + </repeat> + </when> + <when value="colourpalette"> + <param name="palettes" type="select" display="radio" label="Select a colourpalette"> + <option value="hue_pal()" selected="True">hue</option> + <option value="rainbow">rainbow</option> + <option value="heat.colors">heat colors</option> + <option value="terrain.colors">terrain colors</option> + <option value="topo.colors">topo colors</option> + <option value="cm.colors">cm colors</option> + </param> + </when> + </conditional> <param name="output_rdata" type="boolean" label="Results as .RData output" help="Can be used to generate a classification prediction on new data"/> </inputs> <outputs>