changeset 12:fbcc2ab88045 draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit c8d3adac445b4e08e2724e22d7201bfc38bbf40f"
author galaxyp
date Sun, 29 Aug 2021 07:11:53 +0000
parents 8abcfbb033a1
children 433013b25386
files classification.xml macros.xml test-data/QC_imzml_shortreport.pdf test-data/preprocessing_results4.ibd test-data/preprocessing_results4.imzml test-data/preprocessing_results4.imzml.txt test-data/preprocessing_results4.pdf 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 16 files changed, 82 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/classification.xml	Fri May 07 09:46:01 2021 +0000
+++ b/classification.xml	Sun Aug 29 07:11:53 2021 +0000
@@ -1,11 +1,11 @@
-<tool id="cardinal_classification" name="MSI classification" version="@VERSION@.1">
+<tool id="cardinal_classification" name="MSI classification" version="@VERSION@.0">
     <description>spatial classification of mass spectrometry imaging data</description>
     <macros>
         <import>macros.xml</import>
     </macros>
     <expand macro="requirements">
         <requirement type="package" version="2.3">r-gridextra</requirement>
-        <requirement type="package" version="3.3.2">r-ggplot2</requirement>
+        <requirement type="package" version="3.3.5">r-ggplot2</requirement>
     </expand>
     <command detect_errors="exit_code">
     <![CDATA[
@@ -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>
--- a/macros.xml	Fri May 07 09:46:01 2021 +0000
+++ b/macros.xml	Sun Aug 29 07:11:53 2021 +0000
@@ -1,5 +1,5 @@
 <macros>
-    <token name="@VERSION@">2.6.0</token>
+    <token name="@VERSION@">2.10.0</token>
 
     <xml name="requirements">
         <requirements>
Binary file test-data/QC_imzml_shortreport.pdf has changed
Binary file test-data/preprocessing_results4.ibd has changed
--- a/test-data/preprocessing_results4.imzml	Fri May 07 09:46:01 2021 +0000
+++ b/test-data/preprocessing_results4.imzml	Sun Aug 29 07:11:53 2021 +0000
@@ -9,8 +9,8 @@
 		<fileContent>
 			<cvParam cvRef="MS" accession="MS:1000579" name="MS1 spectrum" value="" />
 			<cvParam cvRef="MS" accession="MS:1000128" name="profile spectrum" value="" />
-			<cvParam cvRef="IMS" accession="IMS:1000080" name="universally unique identifier" value="48842eaf-40e5-4a3f-831c-2d7a3b7e04b9" />
-			<cvParam cvRef="IMS" accession="IMS:1000091" name="ibd SHA-1" value="2010ba5b7d44695d891cfe3b6674a5699fa610c0" />
+			<cvParam cvRef="IMS" accession="IMS:1000080" name="universally unique identifier" value="04431b64-9f3d-44b4-9e63-81b9e4924aec" />
+			<cvParam cvRef="IMS" accession="IMS:1000091" name="ibd SHA-1" value="38a4fadd32374bdf0e4b2bb7d976f6067d542a29" />
 			<cvParam cvRef="IMS" accession="IMS:1000030" name="continuous" value="" />
 		</fileContent>
 	</fileDescription>
@@ -42,7 +42,7 @@
 		</sample>
 	</sampleList>
 	<softwareList count="1">
-		<software id="Cardinal" version="2.6.0">
+		<software id="Cardinal" version="2.10.0">
 			<cvParam cvRef="MS" accession="MS:1000799" name="custom unreleased software tool" value="" />
 		</software>
 	</softwareList>
--- a/test-data/preprocessing_results4.imzml.txt	Fri May 07 09:46:01 2021 +0000
+++ b/test-data/preprocessing_results4.imzml.txt	Sun Aug 29 07:11:53 2021 +0000
@@ -1,4 +1,4 @@
 imzML file:
 total 84
--rw-rw-r-- 1 meli meli 62696 Oct  5 19:58 ibd
--rw-rw-r-- 1 meli meli 18199 Oct  5 19:58 imzml
+-rw-rw-r-- 1 meli meli 62696 Aug 28 16:41 ibd
+-rw-rw-r-- 1 meli meli 18200 Aug 28 16:41 imzml
Binary file test-data/preprocessing_results4.pdf has changed
Binary file test-data/test1.pdf has changed
Binary file test-data/test2.pdf has changed
Binary file test-data/test3.pdf has changed
Binary file test-data/test4.pdf has changed
Binary file test-data/test5.pdf has changed
Binary file test-data/test6.pdf has changed
Binary file test-data/test6.rdata has changed
Binary file test-data/test7.pdf has changed
Binary file test-data/test7.rdata has changed