changeset 14:1693b2126f30 draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit 180894cfabbee2d308be140a0f0b4dba119e88d4-dirty"
author galaxyp
date Wed, 23 Dec 2020 22:28:42 +0000
parents c5aa9fca18c6
children d333733dd571
files spectra_plots.xml test-data/Plot_analyze75.pdf test-data/Plot_analyze75_allpixels.pdf test-data/Plot_imzml.pdf test-data/Plot_picked.pdf test-data/Plot_processed.pdf test-data/Plot_rdata.pdf
diffstat 7 files changed, 23 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/spectra_plots.xml	Sun Nov 29 23:41:23 2020 +0000
+++ b/spectra_plots.xml	Wed Dec 23 22:28:42 2020 +0000
@@ -1,4 +1,4 @@
-<tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.2">
+<tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.3">
     <description>
         mass spectrometry imaging mass spectra plots
     </description>
@@ -71,16 +71,23 @@
                 spectra_input = spectra_tabular[,c($pixel_conditional.column_pixel_x, $pixel_conditional.column_pixel_y, $pixel_conditional.single_or_overlaid.column_pixel_annotation)]
                 colnames(spectra_input) = c("x", "y", "annotation")
                 spectra_input\$annotation = as.character(spectra_input\$annotation)
+                
+                ## keeping only spectra with annotations
+                input_pixels = paste(spectra_input[,1], spectra_input[,2], sep="_")
+                dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_")
+                pixelsofinterest = dataset_pixels %in% input_pixels
+                msidata = msidata[,pixelsofinterest]
 
-                msidata_coordinates = data.frame(coord(msidata)\$x, coord(msidata)\$y)
-                colnames(msidata_coordinates) = c("x", "y")
-                merged_annotation = merge(msidata_coordinates, spectra_input, by=c("x", "y"))
+                msidata_coordinates = data.frame(coord(msidata)\$x, coord(msidata)\$y, c(1:ncol(msidata)))
+                colnames(msidata_coordinates) = c("x", "y", "pixel_index")
+                merged_annotation = merge(msidata_coordinates, spectra_input, by=c("x", "y"), all.x=TRUE)
                 merged_annotation[is.na(merged_annotation)] = "NA"
-
-                merged_annotation = merged_annotation[order(merged_annotation\$annotation),]
-                msidata\$annotation = factor(merged_annotation\$annotation)
-
-
+                merged_annotation = merged_annotation[order(merged_annotation\$pixel_index),]
+                msidata\$annotation = factor(merged_annotation[,4], levels = unique(as.character(merged_annotation[,4]))) ## keep the right order
+                
+print(msidata\$annotation)
+print(merged_annotation)
+                 
                     ## overview plot over annotated samples
                     number_combined = length(levels(msidata\$annotation))
 
@@ -105,15 +112,15 @@
 
                     #elif str($pixel_conditional.single_or_overlaid.colour_conditional.colour_type) == "colourpalette"
 
-                    number_levels = (length(levels(msidata\$annotation)))
-
-        	    colourvector = noquote($pixel_conditional.single_or_overlaid.colour_conditional.palettes)(number_levels)
+                    	number_levels = (length(levels(msidata\$annotation)))
+                    
+        	    	colourvector = noquote($pixel_conditional.single_or_overlaid.colour_conditional.palettes)(number_levels)
 
                     #end if
-
-                    position_df = merged_annotation
+                    
+                    position_df = data.frame(coord(msidata)\$x, coord(msidata)\$y, as.factor(msidata\$annotation))
                     colnames(position_df) = c("x", "y", "sample_name")
-
+print(position_df)
                     combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+
                            geom_tile(height = 1, width=1)+
                            coord_fixed()+
@@ -126,9 +133,8 @@
                            guides(fill=guide_legend(ncol=4,byrow=TRUE))+
                            scale_discrete_manual(aesthetics = c("colour", "fill"), values = colourvector)
 
-
                        coord_labels = aggregate(cbind(x,y)~sample_name, data=position_df, mean, na.rm=TRUE, na.action="na.pass")
-                       coord_labels\$file_number = 1:length(unique(position_df\$sample_name))
+                       coord_labels\$file_number = 1:nrow(coord_labels)
 
                     for(file_count in 1:nrow(coord_labels))
                     	{combine_plot = combine_plot + annotate("text",x=coord_labels[file_count,"x"],
@@ -150,7 +156,6 @@
                     pixeldf = data.frame(table(msidata\$annotation))
                     colnames(pixeldf) = c("sample name", "number of pixels")
 
-
             ##################### II) Sample: plot zoom-in mass spectrum ##########
 
                 #if str($mz_range.mz_range_options) == "manual_mz":
@@ -179,7 +184,6 @@
                     )   
 
                         ## plot single tabular mz, average per annotation, manual zoom
-
                         print(plot(msidata[minmasspixel:maxmasspixel,], run="infile", strip=FALSE, col = colourvector,
                         xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$annotation, grid = $grid_variable,
                         key=key_legend, superpose=TRUE, main="Average spectrum per group"))
Binary file test-data/Plot_analyze75.pdf has changed
Binary file test-data/Plot_analyze75_allpixels.pdf has changed
Binary file test-data/Plot_imzml.pdf has changed
Binary file test-data/Plot_picked.pdf has changed
Binary file test-data/Plot_processed.pdf has changed
Binary file test-data/Plot_rdata.pdf has changed