Mercurial > repos > galaxyp > cardinal_spectra_plots
comparison spectra_plots.xml @ 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 |
comparison
equal
deleted
inserted
replaced
13:c5aa9fca18c6 | 14:1693b2126f30 |
---|---|
1 <tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.2"> | 1 <tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.3"> |
2 <description> | 2 <description> |
3 mass spectrometry imaging mass spectra plots | 3 mass spectrometry imaging mass spectra plots |
4 </description> | 4 </description> |
5 <macros> | 5 <macros> |
6 <import>macros.xml</import> | 6 <import>macros.xml</import> |
69 #if str($pixel_conditional.single_or_overlaid.plot_type) == 'overlaid_plots': | 69 #if str($pixel_conditional.single_or_overlaid.plot_type) == 'overlaid_plots': |
70 | 70 |
71 spectra_input = spectra_tabular[,c($pixel_conditional.column_pixel_x, $pixel_conditional.column_pixel_y, $pixel_conditional.single_or_overlaid.column_pixel_annotation)] | 71 spectra_input = spectra_tabular[,c($pixel_conditional.column_pixel_x, $pixel_conditional.column_pixel_y, $pixel_conditional.single_or_overlaid.column_pixel_annotation)] |
72 colnames(spectra_input) = c("x", "y", "annotation") | 72 colnames(spectra_input) = c("x", "y", "annotation") |
73 spectra_input\$annotation = as.character(spectra_input\$annotation) | 73 spectra_input\$annotation = as.character(spectra_input\$annotation) |
74 | 74 |
75 msidata_coordinates = data.frame(coord(msidata)\$x, coord(msidata)\$y) | 75 ## keeping only spectra with annotations |
76 colnames(msidata_coordinates) = c("x", "y") | 76 input_pixels = paste(spectra_input[,1], spectra_input[,2], sep="_") |
77 merged_annotation = merge(msidata_coordinates, spectra_input, by=c("x", "y")) | 77 dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_") |
78 pixelsofinterest = dataset_pixels %in% input_pixels | |
79 msidata = msidata[,pixelsofinterest] | |
80 | |
81 msidata_coordinates = data.frame(coord(msidata)\$x, coord(msidata)\$y, c(1:ncol(msidata))) | |
82 colnames(msidata_coordinates) = c("x", "y", "pixel_index") | |
83 merged_annotation = merge(msidata_coordinates, spectra_input, by=c("x", "y"), all.x=TRUE) | |
78 merged_annotation[is.na(merged_annotation)] = "NA" | 84 merged_annotation[is.na(merged_annotation)] = "NA" |
79 | 85 merged_annotation = merged_annotation[order(merged_annotation\$pixel_index),] |
80 merged_annotation = merged_annotation[order(merged_annotation\$annotation),] | 86 msidata\$annotation = factor(merged_annotation[,4], levels = unique(as.character(merged_annotation[,4]))) ## keep the right order |
81 msidata\$annotation = factor(merged_annotation\$annotation) | 87 |
82 | 88 print(msidata\$annotation) |
83 | 89 print(merged_annotation) |
90 | |
84 ## overview plot over annotated samples | 91 ## overview plot over annotated samples |
85 number_combined = length(levels(msidata\$annotation)) | 92 number_combined = length(levels(msidata\$annotation)) |
86 | 93 |
87 ## the more annotation groups a file has the smaller will be the legend | 94 ## the more annotation groups a file has the smaller will be the legend |
88 if (number_combined<20){ | 95 if (number_combined<20){ |
103 #set $color_string = ','.join(['"%s"' % $color.annotation_color for $color in $pixel_conditional.single_or_overlaid.colour_conditional.colours]) | 110 #set $color_string = ','.join(['"%s"' % $color.annotation_color for $color in $pixel_conditional.single_or_overlaid.colour_conditional.colours]) |
104 colourvector = c($color_string) | 111 colourvector = c($color_string) |
105 | 112 |
106 #elif str($pixel_conditional.single_or_overlaid.colour_conditional.colour_type) == "colourpalette" | 113 #elif str($pixel_conditional.single_or_overlaid.colour_conditional.colour_type) == "colourpalette" |
107 | 114 |
108 number_levels = (length(levels(msidata\$annotation))) | 115 number_levels = (length(levels(msidata\$annotation))) |
109 | 116 |
110 colourvector = noquote($pixel_conditional.single_or_overlaid.colour_conditional.palettes)(number_levels) | 117 colourvector = noquote($pixel_conditional.single_or_overlaid.colour_conditional.palettes)(number_levels) |
111 | 118 |
112 #end if | 119 #end if |
113 | 120 |
114 position_df = merged_annotation | 121 position_df = data.frame(coord(msidata)\$x, coord(msidata)\$y, as.factor(msidata\$annotation)) |
115 colnames(position_df) = c("x", "y", "sample_name") | 122 colnames(position_df) = c("x", "y", "sample_name") |
116 | 123 print(position_df) |
117 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+ | 124 combine_plot = ggplot(position_df, aes(x=x, y=y, fill=sample_name))+ |
118 geom_tile(height = 1, width=1)+ | 125 geom_tile(height = 1, width=1)+ |
119 coord_fixed()+ | 126 coord_fixed()+ |
120 ggtitle("Spatial orientation of annotations")+ | 127 ggtitle("Spatial orientation of annotations")+ |
121 theme_bw()+ | 128 theme_bw()+ |
124 theme(legend.position="bottom",legend.direction="vertical")+ | 131 theme(legend.position="bottom",legend.direction="vertical")+ |
125 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 10))+ | 132 theme(legend.key.size = unit(0.2, "line"), legend.text = element_text(size = 10))+ |
126 guides(fill=guide_legend(ncol=4,byrow=TRUE))+ | 133 guides(fill=guide_legend(ncol=4,byrow=TRUE))+ |
127 scale_discrete_manual(aesthetics = c("colour", "fill"), values = colourvector) | 134 scale_discrete_manual(aesthetics = c("colour", "fill"), values = colourvector) |
128 | 135 |
129 | |
130 coord_labels = aggregate(cbind(x,y)~sample_name, data=position_df, mean, na.rm=TRUE, na.action="na.pass") | 136 coord_labels = aggregate(cbind(x,y)~sample_name, data=position_df, mean, na.rm=TRUE, na.action="na.pass") |
131 coord_labels\$file_number = 1:length(unique(position_df\$sample_name)) | 137 coord_labels\$file_number = 1:nrow(coord_labels) |
132 | 138 |
133 for(file_count in 1:nrow(coord_labels)) | 139 for(file_count in 1:nrow(coord_labels)) |
134 {combine_plot = combine_plot + annotate("text",x=coord_labels[file_count,"x"], | 140 {combine_plot = combine_plot + annotate("text",x=coord_labels[file_count,"x"], |
135 y=coord_labels[file_count,"y"],label=toString(coord_labels[file_count,4])) | 141 y=coord_labels[file_count,"y"],label=toString(coord_labels[file_count,4])) |
136 } | 142 } |
147 print(plot(msidata, run="infile", pixel.groups=msidata\$annotation, key=key_legend,superpose=TRUE, strip=FALSE, grid=$grid_variable, col = colourvector), main="Average spectrum per group") | 153 print(plot(msidata, run="infile", pixel.groups=msidata\$annotation, key=key_legend,superpose=TRUE, strip=FALSE, grid=$grid_variable, col = colourvector), main="Average spectrum per group") |
148 #end if | 154 #end if |
149 | 155 |
150 pixeldf = data.frame(table(msidata\$annotation)) | 156 pixeldf = data.frame(table(msidata\$annotation)) |
151 colnames(pixeldf) = c("sample name", "number of pixels") | 157 colnames(pixeldf) = c("sample name", "number of pixels") |
152 | |
153 | 158 |
154 ##################### II) Sample: plot zoom-in mass spectrum ########## | 159 ##################### II) Sample: plot zoom-in mass spectrum ########## |
155 | 160 |
156 #if str($mz_range.mz_range_options) == "manual_mz": | 161 #if str($mz_range.mz_range_options) == "manual_mz": |
157 | 162 |
177 return(features(msidata, mz=max(mz(msidata)))) | 182 return(features(msidata, mz=max(mz(msidata)))) |
178 } | 183 } |
179 ) | 184 ) |
180 | 185 |
181 ## plot single tabular mz, average per annotation, manual zoom | 186 ## plot single tabular mz, average per annotation, manual zoom |
182 | |
183 print(plot(msidata[minmasspixel:maxmasspixel,], run="infile", strip=FALSE, col = colourvector, | 187 print(plot(msidata[minmasspixel:maxmasspixel,], run="infile", strip=FALSE, col = colourvector, |
184 xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$annotation, grid = $grid_variable, | 188 xlim= c($token.xlimmin,$token.xlimmax),pixel.groups=msidata\$annotation, grid = $grid_variable, |
185 key=key_legend, superpose=TRUE, main="Average spectrum per group")) | 189 key=key_legend, superpose=TRUE, main="Average spectrum per group")) |
186 #end for | 190 #end for |
187 | 191 |