Mercurial > repos > galaxyp > msi_combine
comparison msi_combine.xml @ 8:c6564ddf0744 draft default tip
planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msi_combine commit e87eea03505ab1ba067e192bbbcdc6197dc4b42e
author | galaxyp |
---|---|
date | Tue, 04 Sep 2018 13:42:57 -0400 |
parents | 19d8eee15959 |
children |
comparison
equal
deleted
inserted
replaced
7:19d8eee15959 | 8:c6564ddf0744 |
---|---|
1 <tool id="mass_spectrometry_imaging_combine" name="MSI combine" version="1.10.0.5"> | 1 <tool id="mass_spectrometry_imaging_combine" name="MSI combine" version="1.10.0.6"> |
2 <description> | 2 <description> |
3 combine several mass spectrometry imaging datasets into one | 3 combine several mass spectrometry imaging datasets into one |
4 </description> | 4 </description> |
5 <requirements> | 5 <requirements> |
6 <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement> | 6 <requirement type="package" version="1.10.0">bioconductor-cardinal</requirement> |
18 ln -s '${infile.extra_files_path}/t2m' infile_${i}.t2m && | 18 ln -s '${infile.extra_files_path}/t2m' infile_${i}.t2m && |
19 #else | 19 #else |
20 ln -s '$infile' infile_${i}.RData && | 20 ln -s '$infile' infile_${i}.RData && |
21 #end if | 21 #end if |
22 #end for | 22 #end for |
23 #for $i, $annotation_file in enumerate($annotation_files): | 23 #if $annotation_cond.annotation_tabular == 'annotation' |
24 ln -s '$annotation_file' annotation_file_${i}.tabular && | 24 #for $i, $annotation_file in enumerate($annotation_cond.annotation_files): |
25 #end for | 25 ln -s '$annotation_file' annotation_file_${i}.tabular && |
26 #end for | |
27 #end if | |
26 | 28 |
27 cat '${msi_combine}' && | 29 cat '${msi_combine}' && |
28 Rscript '${msi_combine}' | 30 Rscript '${msi_combine}' |
29 | 31 |
30 ]]> | 32 ]]> |
38 | 40 |
39 library(Cardinal) | 41 library(Cardinal) |
40 library(ggplot2) | 42 library(ggplot2) |
41 | 43 |
42 ## read tabular file for xy_shift option | 44 ## read tabular file for xy_shift option |
43 | |
44 #if str( $combine_conditional.combine_method ) == 'xy_shifts': | 45 #if str( $combine_conditional.combine_method ) == 'xy_shifts': |
45 input_list = read.delim("$combine_conditional.coordinates_file", header = FALSE, | 46 input_list = read.delim("$combine_conditional.coordinates_file", header = FALSE, |
46 stringsAsFactors = FALSE) | 47 stringsAsFactors = FALSE) |
47 #end if | 48 #end if |
48 | 49 |
49 ## load RData and store with new variable name | 50 ## function to load RData and store with new variable name |
50 | |
51 loadRData <- function(fileName){ | 51 loadRData <- function(fileName){ |
52 #loads an RData file, and returns it | |
53 load(fileName) | 52 load(fileName) |
54 get(ls()[ls() != "fileName"]) | 53 get(ls()[ls() != "fileName"]) |
55 } | 54 } |
56 | 55 |
57 ## preparations for reading files one by one with for loop | 56 ## preparations for reading files one by one with for loop |
58 | |
59 pixel_vector = numeric() | 57 pixel_vector = numeric() |
60 x_shifts = 0 | 58 x_shifts = 0 |
61 y_shifts = 0 | 59 y_shifts = 0 |
62 max_y = numeric() | 60 max_y = numeric() |
63 valid_dataset = logical() | 61 valid_dataset = logical() |
69 | 67 |
70 ############## reading files and changing pixel coordinates ################### | 68 ############## reading files and changing pixel coordinates ################### |
71 | 69 |
72 #for $i, $infile in enumerate($infiles): | 70 #for $i, $infile in enumerate($infiles): |
73 | 71 |
74 ## read MSI data | 72 ## read and manipulate MSI data |
75 | 73 |
76 #if $infile.ext == 'imzml' | 74 #if $infile.ext == 'imzml' |
77 #if str($processed_cond.processed_file) == "processed": | 75 #if str($processed_cond.processed_file) == "processed": |
78 msidata_$i <- readImzML('infile_${i}', mass.accuracy=$processed_cond.accuracy, units.accuracy = "$processed_cond.units") | 76 msidata_$i <- readImzML('infile_${i}', mass.accuracy=$processed_cond.accuracy, units.accuracy = "$processed_cond.units") |
79 #else | 77 #else |
83 msidata_$i <- readAnalyze('infile_${i}') | 81 msidata_$i <- readAnalyze('infile_${i}') |
84 #else | 82 #else |
85 msidata_$i = loadRData('infile_${i}.RData') | 83 msidata_$i = loadRData('infile_${i}.RData') |
86 #end if | 84 #end if |
87 | 85 |
88 | 86 ## remove duplicated coordinates, otherwise combine will fail |
89 ## read annotation data, up to 5 annotations can be used for now | 87 print(paste0(sum(duplicated(coord(msidata_$i))), " duplicated coordinates were removed from input file")) |
90 | 88 msidata_${i} <- msidata_${i}[,!duplicated(coord(msidata_${i}))] |
91 ## read annotation tabular, set first two columns as x and y, merge with coordinates dataframe and order according to pixelorder in msidata | |
92 input_annotation = read.delim("annotation_file_${i}.tabular", header = TRUE, | |
93 stringsAsFactors = FALSE) | |
94 | |
95 if (class(input_annotation[,1]) == "character"){ | |
96 annotation_coordinates = matrix(unlist(strsplit(as.character(input_annotation[,1]), "\\,")), ncol=2, byrow=TRUE) | |
97 annotation_coordinates2 = cbind(as.numeric(substring(annotation_coordinates[,1], 5, last = 1000000L)), as.numeric(substring(annotation_coordinates[,2], 5, last = 1000000L))) | |
98 input_annotation = cbind(annotation_coordinates2, input_annotation[,-1]) | |
99 } | |
100 | |
101 colnames(input_annotation)[1:2] = c("x", "y") | |
102 msidata_coordinates = cbind(coord(msidata_$i)[,1:2], 1:ncol(msidata_$i)) | |
103 colnames(msidata_coordinates)[3] = "pixel_index" | |
104 ## only first 5 annotation columns are kept | |
105 if (ncol(input_annotation) > 7){ | |
106 input_annotation = input_annotation[,1:7]} | |
107 | |
108 annotation_df = merge(msidata_coordinates, input_annotation, by=c("x", "y"), all.x=TRUE) | |
109 annotation_df_8 = cbind(annotation_df, data.frame(matrix(NA,ncol=8-ncol(annotation_df), nrow=ncol(msidata_$i)))) | |
110 annotation_df_8_sorted = annotation_df_8[order(annotation_df_8\$pixel_index),]## orders pixel according to msidata | |
111 | |
112 ## each annotation column is assigned to the pixel in the pData slot of the MSIdata | |
113 msidata_$i\$column1 = annotation_df_8_sorted[,4] | |
114 msidata_$i\$column2 = annotation_df_8_sorted[,5] | |
115 msidata_$i\$column3 = annotation_df_8_sorted[,6] | |
116 msidata_$i\$column4 = annotation_df_8_sorted[,7] | |
117 msidata_$i\$column5 = annotation_df_8_sorted[,8] | |
118 | 89 |
119 ## same name for MSI data files necessary to combine data in one single coordinate system | 90 ## same name for MSI data files necessary to combine data in one single coordinate system |
120 sampleNames(msidata_$i) = "msidata" | 91 sampleNames(msidata_$i) = "msidata" |
92 | |
93 | |
94 ## read and process annotation tabular or automatically use name of infile as annotation | |
95 | |
96 ## set all pixel annotations to NA, necessary in case files were combined before with different annotations | |
97 msidata_$i\$column1 = rep(NA, ncol(msidata_$i)) | |
98 msidata_$i\$column2 = rep(NA, ncol(msidata_$i)) | |
99 msidata_$i\$column3 = rep(NA, ncol(msidata_$i)) | |
100 msidata_$i\$column4 = rep(NA, ncol(msidata_$i)) | |
101 msidata_$i\$column5 = rep(NA, ncol(msidata_$i)) | |
102 msidata_$i\$combined_sample = rep(NA, ncol(msidata_$i)) | |
103 | |
104 #if str($annotation_cond.annotation_tabular) == 'annotation' | |
105 print("annotations") | |
106 | |
107 ## read annotation tabular, set first two columns as x and y, merge with coordinates dataframe and order according to pixelorder in msidata | |
108 input_annotation = read.delim("annotation_file_${i}.tabular", header = $annotation_cond.tabular_header, stringsAsFactors = FALSE) | |
109 | |
110 ## change format x = 1, y = 2 into two columns | |
111 if (class(input_annotation[,1]) == "character"){ | |
112 annotation_names = colnames(input_annotation[2:ncol(input_annotation)]) | |
113 annotation_coordinates = matrix(unlist(strsplit(as.character(input_annotation[,1]), "\\,")), ncol=2, byrow=TRUE) | |
114 annotation_coordinates2 = cbind(as.numeric(substring(annotation_coordinates[,1], 5, last = 1000000L)), as.numeric(substring(annotation_coordinates[,2], 5, last = 1000000L))) | |
115 input_annotation = cbind(annotation_coordinates2, input_annotation[,-1]) | |
116 colnames(input_annotation) = c("x", "y", annotation_names) | |
117 } | |
118 | |
119 colnames(input_annotation)[1:2] = c("x", "y") | |
120 msidata_coordinates = cbind(coord(msidata_$i)[,1:2], 1:ncol(msidata_$i)) | |
121 colnames(msidata_coordinates)[3] = "pixel_index" | |
122 | |
123 ## only first 5 annotation columns are kept | |
124 if (ncol(input_annotation) > 7){ | |
125 input_annotation = input_annotation[,1:7]} | |
126 | |
127 annotation_df = merge(msidata_coordinates, input_annotation, by=c("x", "y"), all.x=TRUE) | |
128 annotation_df_8 = cbind(annotation_df, data.frame(matrix(NA,ncol=8-ncol(annotation_df), nrow=ncol(msidata_$i)))) | |
129 annotation_df_8_sorted = annotation_df_8[order(annotation_df_8\$pixel_index),]## orders pixel according to msidata | |
130 | |
131 ## each annotation column is assigned to the pixel in the pData slot of the MSIdata | |
132 msidata_$i\$column1 = annotation_df_8_sorted[,4] | |
133 msidata_$i\$column2 = annotation_df_8_sorted[,5] | |
134 msidata_$i\$column3 = annotation_df_8_sorted[,6] | |
135 msidata_$i\$column4 = annotation_df_8_sorted[,7] | |
136 msidata_$i\$column5 = annotation_df_8_sorted[,8] | |
137 | |
138 ## extract columnnames from (last) annotation tabular (for QC plot names) | |
139 annotation_colnames = colnames(input_annotation)[-c(1,2)] | |
140 | |
141 #end if | |
142 | |
121 | 143 |
122 ################### preparation xy shifts ########################## | 144 ################### preparation xy shifts ########################## |
123 | 145 |
124 #if str( $combine_conditional.combine_method ) == 'xy_shifts': | 146 #if str( $combine_conditional.combine_method ) == 'xy_shifts': |
125 | 147 |
133 colnames(pixelcoords_$i)[3] = "file_number" | 155 colnames(pixelcoords_$i)[3] = "file_number" |
134 | 156 |
135 ################### preparation automatic combination ########################## | 157 ################### preparation automatic combination ########################## |
136 | 158 |
137 #elif str( $combine_conditional.combine_method ) == 'automatic_combine': | 159 #elif str( $combine_conditional.combine_method ) == 'automatic_combine': |
160 | |
161 ## use name of Galaxy inputfile as combined sample annotation | |
138 names_vector = character() | 162 names_vector = character() |
139 #set escaped_element_identifier = re.sub('[^\w\-\s\[/]]', '_', str($infile.element_identifier)) ## use name of inputfile from Galaxy | 163 #set escaped_element_identifier = re.sub('[^\w\-\s\[/]]', '_', str($infile.element_identifier)) |
140 if (sum(spectra(msidata_$i)[],na.rm=TRUE)>0) ## use only valid files | 164 if (sum(spectra(msidata_$i)[],na.rm=TRUE)>0) ## use only valid files |
141 { | 165 { |
142 if (is.null(levels(msidata_$i\$combined_sample))) | 166 if (is.null(levels(msidata_$i\$combined_sample))) |
143 { | 167 { |
144 names_vector = append(names_vector, rep(paste($i+1, "$escaped_element_identifier", sep="_"),ncol(msidata_$i))) | 168 names_vector = append(names_vector, rep(paste($i+1, "$escaped_element_identifier", sep="_"),ncol(msidata_$i))) |
168 valid_dataset = append(valid_dataset, | 192 valid_dataset = append(valid_dataset, |
169 (ncol(msidata_$i)>0 & nrow(msidata_$i)>0 & sum(spectra(msidata_$i)[], na.rm=TRUE)>0)) | 193 (ncol(msidata_$i)>0 & nrow(msidata_$i)>0 & sum(spectra(msidata_$i)[], na.rm=TRUE)>0)) |
170 | 194 |
171 #end for | 195 #end for |
172 | 196 |
173 ## extract columnnames from (last) annotation tabular (for QC plot names) | |
174 annotation_colnames = colnames(input_annotation)[-c(1,2)] | |
175 | 197 |
176 ###################### automatic combination ################################### | 198 ###################### automatic combination ################################### |
177 ################################################################################ | 199 ################################################################################ |
178 | 200 |
179 #if str( $combine_conditional.combine_method ) == 'automatic_combine': | 201 #if str( $combine_conditional.combine_method ) == 'automatic_combine': |
210 ## save as (.RData) | 232 ## save as (.RData) |
211 | 233 |
212 msidata = msidata_combined | 234 msidata = msidata_combined |
213 save(msidata, file="$msidata_combined") | 235 save(msidata, file="$msidata_combined") |
214 | 236 |
215 | |
216 ################################## xy shifts ################################### | 237 ################################## xy shifts ################################### |
217 ################################################################################ | 238 ################################################################################ |
218 | 239 |
219 #elif str( $combine_conditional.combine_method ) == 'xy_shifts': | 240 #elif str( $combine_conditional.combine_method ) == 'xy_shifts': |
220 print("xy_shifts") | 241 print("xy_shifts") |
221 | 242 |
222 ## find duplicated coordinates | 243 ## in case user made mistake with xy shifts: find duplicated coordinates |
223 all_coordinates = do.call(rbind, list(#echo ','.join($pixelcoords)#)) | 244 all_coordinates = do.call(rbind, list(#echo ','.join($pixelcoords)#)) |
224 duplicated_coordinates= duplicated(all_coordinates[,1:2])| duplicated(all_coordinates[,1:2], fromLast=TRUE) | 245 duplicated_coordinates= duplicated(all_coordinates[,1:2])| duplicated(all_coordinates[,1:2], fromLast=TRUE) |
225 print(paste0("Number of removed duplicated coordinates: ", sum(duplicated_coordinates)/2)) | 246 print(paste0("Number of removed duplicated coordinates after combination: ", sum(duplicated_coordinates)/2)) |
226 unique_coordinates = all_coordinates[!duplicated_coordinates,] | 247 unique_coordinates = all_coordinates[!duplicated_coordinates,] |
227 | 248 |
228 ## remove duplicated coordinates | 249 ## remove duplicated coordinates |
229 datasetlist = list() | 250 datasetlist = list() |
230 count = 1 | 251 count = 1 |
267 theme(legend.position="bottom",legend.direction="vertical")+ | 288 theme(legend.position="bottom",legend.direction="vertical")+ |
268 guides(fill=guide_legend(ncol=5,byrow=TRUE)) | 289 guides(fill=guide_legend(ncol=5,byrow=TRUE)) |
269 coord_labels = aggregate(cbind(x,y)~sample_name, data=position_df, mean) | 290 coord_labels = aggregate(cbind(x,y)~sample_name, data=position_df, mean) |
270 coord_labels\$file_number = gsub( "_.*$", "", coord_labels\$sample_name) | 291 coord_labels\$file_number = gsub( "_.*$", "", coord_labels\$sample_name) |
271 for(file_count in 1:nrow(coord_labels)) | 292 for(file_count in 1:nrow(coord_labels)) |
272 {combine_plot = combine_plot + annotate("text",x=coord_labels[file_count,"x"], | 293 {combine_plot = combine_plot + annotate("text",x=coord_labels[file_count,"x"], |
273 y=coord_labels[file_count,"y"],label=toString(coord_labels[file_count,4]))} | 294 y=coord_labels[file_count,"y"],label=toString(coord_labels[file_count,4]))} |
274 print(combine_plot) | 295 print(combine_plot) |
275 | 296 |
276 | 297 #if str($annotation_cond.annotation_tabular) == 'annotation' |
277 ## annotation plots | 298 |
278 | 299 ## annotation plots |
279 ## plot 1 | 300 |
280 | 301 ## plot 1 |
281 column1_df = cbind(coord(msidata), msidata\$column1) | 302 |
282 colnames(column1_df)[3] = "column1" | 303 column1_df = cbind(coord(msidata), msidata\$column1) |
283 | 304 colnames(column1_df)[3] = "column1" |
284 if (sum(is.na(column1_df[3])) < nrow(column1_df)){ | 305 |
285 column1_plot = ggplot(column1_df, aes(x=x, y=y, fill=column1))+ | 306 if (sum(is.na(column1_df[3])) < nrow(column1_df)){ |
286 geom_tile() + | 307 column1_plot = ggplot(column1_df, aes(x=x, y=y, fill=column1))+ |
287 coord_fixed()+ | 308 geom_tile() + |
288 ggtitle(paste0(annotation_colnames[1]))+ | 309 coord_fixed()+ |
289 theme_bw()+ | 310 ggtitle(paste0(annotation_colnames[1]))+ |
290 theme(text=element_text(family="ArialMT", face="bold", size=15))+ | 311 theme_bw()+ |
291 theme(legend.position="bottom",legend.direction="vertical")+ | 312 theme(text=element_text(family="ArialMT", face="bold", size=15))+ |
292 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[1])) | 313 theme(legend.position="bottom",legend.direction="vertical")+ |
293 print(column1_plot)} | 314 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[1])) |
294 ##rename columnname for output tabular file | 315 print(column1_plot)} |
295 colnames(column1_df)[3] = annotation_colnames[1] | 316 ##rename columnname for output tabular file |
296 | 317 colnames(column1_df)[3] = annotation_colnames[1] |
297 ## plot 2 | 318 |
298 column2_df = cbind(coord(msidata), msidata\$column2) | 319 ## plot 2 |
299 colnames(column2_df)[3] = "column2" | 320 column2_df = cbind(coord(msidata), msidata\$column2) |
300 | 321 colnames(column2_df)[3] = "column2" |
301 if (sum(is.na(column2_df[3])) < nrow(column2_df)){ | 322 |
302 column2_plot = ggplot(column2_df, aes(x=x, y=y, fill=column2))+ | 323 if (sum(is.na(column2_df[3])) < nrow(column2_df)){ |
303 geom_tile() + | 324 column2_plot = ggplot(column2_df, aes(x=x, y=y, fill=column2))+ |
304 coord_fixed()+ | 325 geom_tile() + |
305 ggtitle(paste0(annotation_colnames[2]))+ | 326 coord_fixed()+ |
306 theme_bw()+ | 327 ggtitle(paste0(annotation_colnames[2]))+ |
307 theme(text=element_text(family="ArialMT", face="bold", size=15))+ | 328 theme_bw()+ |
308 theme(legend.position="bottom",legend.direction="vertical")+ | 329 theme(text=element_text(family="ArialMT", face="bold", size=15))+ |
309 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[2])) | 330 theme(legend.position="bottom",legend.direction="vertical")+ |
310 print(column2_plot)} | 331 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[2])) |
311 ##rename columnname for output tabular file | 332 print(column2_plot)} |
312 colnames(column2_df)[3] = annotation_colnames[2] | 333 ##rename columnname for output tabular file |
313 | 334 colnames(column2_df)[3] = annotation_colnames[2] |
314 ## plot 3 | 335 |
315 column3_df = cbind(coord(msidata), msidata\$column3) | 336 ## plot 3 |
316 colnames(column3_df)[3] = "column3" | 337 column3_df = cbind(coord(msidata), msidata\$column3) |
317 if (sum(is.na(column3_df[3])) < nrow(column3_df)){ | 338 colnames(column3_df)[3] = "column3" |
318 column3_plot = ggplot(column3_df, aes(x=x, y=y, fill=column3))+ | 339 if (sum(is.na(column3_df[3])) < nrow(column3_df)){ |
319 geom_tile() + | 340 column3_plot = ggplot(column3_df, aes(x=x, y=y, fill=column3))+ |
320 coord_fixed()+ | 341 geom_tile() + |
321 ggtitle(paste0(annotation_colnames[3]))+ | 342 coord_fixed()+ |
322 theme_bw()+ | 343 ggtitle(paste0(annotation_colnames[3]))+ |
323 theme(text=element_text(family="ArialMT", face="bold", size=15))+ | 344 theme_bw()+ |
324 theme(legend.position="bottom",legend.direction="vertical")+ | 345 theme(text=element_text(family="ArialMT", face="bold", size=15))+ |
325 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[3])) | 346 theme(legend.position="bottom",legend.direction="vertical")+ |
326 print(column3_plot)} | 347 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[3])) |
327 ##rename columnname for output tabular file | 348 print(column3_plot)} |
328 colnames(column3_df)[3] = annotation_colnames[3] | 349 ##rename columnname for output tabular file |
329 | 350 colnames(column3_df)[3] = annotation_colnames[3] |
330 ## plot 4 | 351 |
331 column4_df = cbind(coord(msidata), msidata\$column4) | 352 ## plot 4 |
332 colnames(column4_df)[3] = "column4" | 353 column4_df = cbind(coord(msidata), msidata\$column4) |
333 | 354 colnames(column4_df)[3] = "column4" |
334 if (sum(is.na(column4_df[3])) < nrow(column4_df)){ | 355 |
335 column4_plot = ggplot(column4_df, aes(x=x, y=y, fill=column4))+ | 356 if (sum(is.na(column4_df[3])) < nrow(column4_df)){ |
336 geom_tile() + | 357 column4_plot = ggplot(column4_df, aes(x=x, y=y, fill=column4))+ |
337 coord_fixed()+ | 358 geom_tile() + |
338 ggtitle(paste0(annotation_colnames[4]))+ | 359 coord_fixed()+ |
339 theme_bw()+ | 360 ggtitle(paste0(annotation_colnames[4]))+ |
340 theme(text=element_text(family="ArialMT", face="bold", size=15))+ | 361 theme_bw()+ |
341 theme(legend.position="bottom",legend.direction="vertical")+ | 362 theme(text=element_text(family="ArialMT", face="bold", size=15))+ |
342 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[4])) | 363 theme(legend.position="bottom",legend.direction="vertical")+ |
343 print(column4_plot)} | 364 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[4])) |
344 ##rename columnname for output tabular file | 365 print(column4_plot)} |
345 colnames(column4_df)[3] = annotation_colnames[4] | 366 ##rename columnname for output tabular file |
346 | 367 colnames(column4_df)[3] = annotation_colnames[4] |
347 ## plot5 | 368 |
348 | 369 ## plot5 |
349 column5_df = cbind(coord(msidata), msidata\$column5) | 370 |
350 colnames(column5_df)[3] = "column5" | 371 column5_df = cbind(coord(msidata), msidata\$column5) |
351 if (sum(is.na(column5_df[3])) < nrow(column5_df)){ | 372 colnames(column5_df)[3] = "column5" |
352 column5_plot = ggplot(column5_df, aes(x=x, y=y, fill=column5))+ | 373 if (sum(is.na(column5_df[3])) < nrow(column5_df)){ |
353 geom_tile() + | 374 column5_plot = ggplot(column5_df, aes(x=x, y=y, fill=column5))+ |
354 coord_fixed()+ | 375 geom_tile() + |
355 ggtitle(paste0(annotation_colnames[5]))+ | 376 coord_fixed()+ |
356 theme_bw()+ | 377 ggtitle(paste0(annotation_colnames[5]))+ |
357 theme(text=element_text(family="ArialMT", face="bold", size=15))+ | 378 theme_bw()+ |
358 theme(legend.position="bottom",legend.direction="vertical")+ | 379 theme(text=element_text(family="ArialMT", face="bold", size=15))+ |
359 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[5])) | 380 theme(legend.position="bottom",legend.direction="vertical")+ |
360 print(column5_plot)} | 381 guides(fill=guide_legend(ncol=5,byrow=TRUE, title=annotation_colnames[5])) |
361 ##rename columnname for output tabular file | 382 print(column5_plot)} |
362 colnames(column5_df)[3] = annotation_colnames[5] | 383 ##rename columnname for output tabular file |
384 colnames(column5_df)[3] = annotation_colnames[5] | |
385 | |
386 #end if | |
363 | 387 |
364 dev.off() | 388 dev.off() |
365 | 389 |
366 ##################### annotation tabular output ################################ | 390 ##################### annotation tabular output ################################ |
367 | 391 |
368 if (length(features(msidata))> 0 & length(pixels(msidata)) > 0){ | 392 if (length(features(msidata))> 0 & length(pixels(msidata)) > 0){ |
369 annotation_df_list = list(position_df, column1_df, column2_df, column3_df, column4_df, column5_df) | 393 |
370 combined_annotations = Reduce(function(...) merge(..., by=c("x", "y"), all=TRUE), annotation_df_list) | 394 #if str($annotation_cond.annotation_tabular) == 'no_annotation': |
371 write.table(combined_annotations, file="$annotation_output", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") | 395 write.table(position_df, file="$pixel_annotations", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") |
396 | |
397 #else | |
398 annotation_df_list = list(position_df, column1_df, column2_df, column3_df, column4_df, column5_df) | |
399 combined_annotations = Reduce(function(...) merge(..., by=c("x", "y"), all=TRUE), annotation_df_list) | |
400 write.table(combined_annotations, file="$pixel_annotations", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t") | |
401 | |
402 #end if | |
403 | |
372 }else{ | 404 }else{ |
373 print("No annotation tabular output because file has no features or pixels left") | 405 print("No annotation tabular output because file has no features or pixels left") |
374 } | 406 } |
375 | 407 |
376 ####################### optional matrix output ################################# | 408 ####################### optional matrix output ################################# |
378 #if $output_matrix: | 410 #if $output_matrix: |
379 | 411 |
380 if (length(features(msidata))> 0 & length(pixels(msidata)) > 0){ | 412 if (length(features(msidata))> 0 & length(pixels(msidata)) > 0){ |
381 spectramatrix = spectra(msidata)[] | 413 spectramatrix = spectra(msidata)[] |
382 spectramatrix = cbind(mz(msidata),spectramatrix) | 414 spectramatrix = cbind(mz(msidata),spectramatrix) |
383 newmatrix = rbind(c("mz | spectra", names(pixels(msidata))), spectramatrix) | 415 newmatrix = rbind(c("mz", names(pixels(msidata))), spectramatrix) |
384 write.table(newmatrix, file="$matrixasoutput", quote = FALSE, row.names = FALSE, col.names=FALSE, sep = "\t") | 416 write.table(newmatrix, file="$intensity_matrix", quote = FALSE, row.names = FALSE, col.names=FALSE, sep = "\t") |
385 }else{ | 417 }else{ |
386 print("No intensity matrix output because file has no features or pixels left") | 418 print("No intensity matrix output because file has no features or pixels left") |
387 } | 419 } |
388 | 420 |
389 #end if | 421 #end if |
406 <option value="mz" >mz</option> | 438 <option value="mz" >mz</option> |
407 <option value="ppm" selected="True" >ppm</option> | 439 <option value="ppm" selected="True" >ppm</option> |
408 </param> | 440 </param> |
409 </when> | 441 </when> |
410 </conditional> | 442 </conditional> |
411 <param name="annotation_files" type="data" multiple="true" format="tabular" | 443 <conditional name="annotation_cond"> |
412 label="Pixel annotations as tabular files, same number and order of files as input files" | 444 <param name="annotation_tabular" type="select" label="Optional annotation of pixels with tabular files"> |
413 help="Coordinates in column 1 in format x = 1, y = 1 or first column x values, second column y values. Up to 5 columns with pixel annotations"/> | 445 <option value="no_annotation" selected="True">no annotation</option> |
446 <option value="annotation">pixel annotations</option> | |
447 </param> | |
448 <when value="no_annotation"/> | |
449 <when value="annotation"> | |
450 <param name="annotation_files" type="data" multiple="true" format="tabular" | |
451 label="Pixel annotations tabular files" | |
452 help="Same number and order of files as input files. Coordinates in column 1 in format x = 1, y = 1 or first column x values, second column y values. Up to 5 columns with pixel annotations"/> | |
453 <param name="tabular_header" type="boolean" label="Tabular files contain a header line" truevalue="TRUE" falsevalue="FALSE"/> | |
454 </when> | |
455 </conditional> | |
414 <conditional name="combine_conditional"> | 456 <conditional name="combine_conditional"> |
415 <param name="combine_method" type="select" label="Select the way you want to combine multiple files" help="More detailed help can be found in the help section at the bottom"> | 457 <param name="combine_method" type="select" label="Way of combining multiple files"> |
416 <option value="automatic_combine" selected="True" >automatic combination</option> | 458 <option value="automatic_combine" selected="True" >automatic combination</option> |
417 <option value="xy_shifts">shift xy coordinates with a tabular file</option> | 459 <option value="xy_shifts">shift xy coordinates with a tabular file</option> |
418 </param> | 460 </param> |
419 <when value="automatic_combine"/> | 461 <when value="automatic_combine"/> |
420 <when value="xy_shifts"> | 462 <when value="xy_shifts"> |
427 </conditional> | 469 </conditional> |
428 <param name="output_matrix" type="boolean" display="radio" label="Intensity matrix output"/> | 470 <param name="output_matrix" type="boolean" display="radio" label="Intensity matrix output"/> |
429 </inputs> | 471 </inputs> |
430 <outputs> | 472 <outputs> |
431 <data format="rdata" name="msidata_combined" label="MSI_data_combined"/> | 473 <data format="rdata" name="msidata_combined" label="MSI_data_combined"/> |
432 <data format="pdf" name="combining_qc" from_work_dir="Combined_qc.pdf" label = "Combined_QC"/> | 474 <data format="pdf" name="QC_overview" from_work_dir="Combined_qc.pdf" label = "Combined_QC"/> |
433 <data format="tabular" name="annotation_output" label="Annotation_tabular"/> | 475 <data format="tabular" name="pixel_annotations" label="Combined_pixel_annotations"/> |
434 <data format="tabular" name="matrixasoutput" label="Combined_matrix"> | 476 <data format="tabular" name="intensity_matrix" label="Combined_matrix"> |
435 <filter>output_matrix</filter> | 477 <filter>output_matrix</filter> |
436 </data> | 478 </data> |
437 </outputs> | 479 </outputs> |
438 <tests> | 480 <tests> |
439 <test expect_num_outputs="4"> | 481 <test expect_num_outputs="4"> |
440 <param name="infiles" value="msidata_1.RData,msidata_2.RData,msidata_3.RData" ftype="rdata"/> | 482 <param name="infiles" value="msidata_1.RData,msidata_2.RData,msidata_3.RData" ftype="rdata"/> |
441 <param name="annotation_files" value="annotations_file1.tabular,annotations_file2.tabular,annotations_file3.tabular" ftype="tabular"/> | 483 <conditional name="annotation_cond"> |
484 <param name="annotation_tabular" value="annotation"/> | |
485 <param name="annotation_files" value="annotations_file1.tabular,annotations_file2.tabular,annotations_file3.tabular" ftype="tabular"/> | |
486 <param name="tabular_header" value="TRUE"/> | |
487 </conditional> | |
442 <param name="combine_method" value="xy_shifts"/> | 488 <param name="combine_method" value="xy_shifts"/> |
443 <param name="coordinates_file" ftype="tabular" value="xy_coordinates.tabular"/> | 489 <param name="coordinates_file" ftype="tabular" value="xy_coordinates.tabular"/> |
444 <param name="column_x" value="1"/> | 490 <param name="column_x" value="1"/> |
445 <param name="column_y" value="2"/> | 491 <param name="column_y" value="2"/> |
446 <param name="column_names" value="3"/> | 492 <param name="column_names" value="3"/> |
447 <param name="output_matrix" value="True"/> | 493 <param name="output_matrix" value="True"/> |
448 <output name="matrixasoutput" file="123_combined_matrix.tabular"/> | 494 <output name="intensity_matrix" file="123_combined_matrix.tabular"/> |
449 <output name="annotation_output" file="123_annotation_output.tabular"/> | 495 <output name="pixel_annotations" file="123_annotation_output.tabular"/> |
450 <output name="msidata_combined" file="123_combined.RData" compare="sim_size" /> | 496 <output name="msidata_combined" file="123_combined.RData" compare="sim_size" /> |
451 <output name="combining_qc" file="123_combined_QC.pdf" compare="sim_size" delta="2000"/> | 497 <output name="QC_overview" file="123_combined_QC.pdf" compare="sim_size" delta="2000"/> |
452 </test> | 498 </test> |
453 <test expect_num_outputs="4"> | 499 <test expect_num_outputs="4"> |
454 <param name="infiles" value="msidata_1.RData,msidata_2.RData" ftype="rdata"/> | 500 <param name="infiles" value="msidata_1.RData,msidata_2.RData" ftype="rdata"/> |
455 <param name="annotation_files" value="annotations_file1.tabular,annotations_file2.tabular" ftype="tabular"/> | 501 <conditional name="annotation_cond"> |
502 <param name="annotation_tabular" value="annotation"/> | |
503 <param name="annotation_files" value="annotations_file1.tabular,annotations_file2.tabular" ftype="tabular"/> | |
504 <param name="tabular_header" value="TRUE"/> | |
505 </conditional> | |
456 <param name="combine_method" value="automatic_combine"/> | 506 <param name="combine_method" value="automatic_combine"/> |
457 <param name="output_matrix" value="True"/> | 507 <param name="output_matrix" value="True"/> |
458 <output name="matrixasoutput" file="12_combined_matrix.tabular"/> | 508 <output name="intensity_matrix" file="12_combined_matrix.tabular"/> |
459 <output name="annotation_output" file="12_annotation_output.tabular"/> | 509 <output name="pixel_annotations" file="12_annotation_output.tabular"/> |
460 <output name="msidata_combined" file="12_combined.RData" compare="sim_size" /> | 510 <output name="msidata_combined" file="12_combined.RData" compare="sim_size" /> |
461 <output name="combining_qc" file="12_combined_QC.pdf" compare="sim_size" delta="2000"/> | 511 <output name="QC_overview" file="12_combined_QC.pdf" compare="sim_size" delta="2000"/> |
462 </test> | 512 </test> |
463 <test expect_num_outputs="3"> | 513 <test expect_num_outputs="3"> |
464 <param name="infiles" value="msidata_1.RData,123_combined.RData" ftype="rdata"/> | 514 <param name="infiles" value="msidata_1.RData,123_combined.RData" ftype="rdata"/> |
465 <param name="annotation_files" value="annotations_file1.tabular,123_annotation.tabular" ftype="tabular"/> | 515 <conditional name="annotation_cond"> |
516 <param name="annotation_tabular" value="annotation"/> | |
517 <param name="annotation_files" value="annotations_file1.tabular,123_annotation.tabular" ftype="tabular"/> | |
518 <param name="tabular_header" value="TRUE"/> | |
519 </conditional> | |
466 <param name="combine_method" value="automatic_combine"/> | 520 <param name="combine_method" value="automatic_combine"/> |
467 <param name="output_matrix" value="False"/> | 521 <param name="output_matrix" value="False"/> |
468 <output name="annotation_output" file="112_annotation_output.tabular"/> | 522 <output name="pixel_annotations" file="112_annotation_output.tabular"/> |
469 <output name="msidata_combined" file="112_auto_combined.RData" compare="sim_size" /> | 523 <output name="msidata_combined" file="112_auto_combined.RData" compare="sim_size" /> |
470 <output name="combining_qc" file="112_auto_combined_QC.pdf" compare="sim_size" delta="2000"/> | 524 <output name="QC_overview" file="112_auto_combined_QC.pdf" compare="sim_size" delta="2000"/> |
525 </test> | |
526 <test expect_num_outputs="3"> | |
527 <param name="infiles" value="msidata_2.RData,123_combined.RData" ftype="rdata"/> | |
528 <conditional name="annotation_cond"> | |
529 <param name="annotation_tabular" value="no_annotation"/> | |
530 </conditional> | |
531 <param name="combine_method" value="automatic_combine"/> | |
532 <param name="output_matrix" value="False"/> | |
533 <output name="pixel_annotations" file="2123_annotation_output.tabular"/> | |
534 <output name="msidata_combined" file="2123_auto_combined.RData" compare="sim_size" /> | |
535 <output name="QC_overview" file="2123_auto_combined_QC.pdf" compare="sim_size" delta="2000"/> | |
471 </test> | 536 </test> |
472 </tests> | 537 </tests> |
473 <help> | 538 <help> |
474 <![CDATA[ | 539 <![CDATA[ |
475 | 540 |