comparison combine.xml @ 1:65245dc812c3 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit d2f311f7fff24e54c565127c40414de708e31b3c
author galaxyp
date Thu, 25 Oct 2018 07:31:08 -0400
parents 93be1d20b5c3
children 129cddd02600
comparison
equal deleted inserted replaced
0:93be1d20b5c3 1:65245dc812c3
1 <tool id="cardinal_combine" name="MSI combine" version="@VERSION@.0"> 1 <tool id="cardinal_combine" name="MSI combine" version="@VERSION@.1">
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 <macros> 5 <macros>
6 <import>macros.xml</import> 6 <import>macros.xml</import>
7 </macros> 7 </macros>
8 <expand macro="requirements"> 8 <expand macro="requirements">
9 <requirement type="package" version="3.0.0">r-ggplot2</requirement> 9 <requirement type="package" version="3.0">r-ggplot2</requirement>
10 </expand> 10 </expand>
11 <command detect_errors="exit_code"> 11 <command detect_errors="exit_code">
12 <![CDATA[ 12 <![CDATA[
13 #for $i, $infile in enumerate($infiles): 13 #for $i, $infile in enumerate($infiles):
14 #if $infile.ext == 'imzml' 14 #if $infile.ext == 'imzml'
27 ln -s '$annotation_file' annotation_file_${i}.tabular && 27 ln -s '$annotation_file' annotation_file_${i}.tabular &&
28 #end for 28 #end for
29 #end if 29 #end if
30 30
31 cat '${msi_combine}' && 31 cat '${msi_combine}' &&
32 Rscript '${msi_combine}' 32 Rscript '${msi_combine}' &&
33 #if $imzml_output:
34 mkdir $outfile_imzml.files_path &&
35 ls -l &&
36 mv ./out.imzML "${os.path.join($outfile_imzml.files_path, 'imzml')}" | true &&
37 mv ./out.ibd "${os.path.join($outfile_imzml.files_path, 'ibd')}" | true &&
38 #end if
39 echo "imzML file:" > $outfile_imzml &&
40 ls -l "$outfile_imzml.files_path" >> $outfile_imzml
33 41
34 ]]> 42 ]]>
35 </command> 43 </command>
36 <configfiles> 44 <configfiles>
37 <configfile name="msi_combine"><![CDATA[ 45 <configfile name="msi_combine"><![CDATA[
73 81
74 ## read and manipulate MSI data 82 ## read and manipulate MSI data
75 83
76 #if $infile.ext == 'imzml' 84 #if $infile.ext == 'imzml'
77 #if str($processed_cond.processed_file) == "processed": 85 #if str($processed_cond.processed_file) == "processed":
78 msidata_$i <- readImzML('infile_${i}', mass.accuracy=$processed_cond.accuracy, units.accuracy = "$processed_cond.units") 86 msidata_$i <- readImzML('infile_${i}', mass.accuracy=$processed_cond.accuracy, units.accuracy = "$processed_cond.units", attach.only=TRUE)
79 centroided(msidata) = $centroids 87 centroided(msidata_$i) = $centroids
80 #else 88 #else
81 msidata_$i <- readImzML('infile_${i}') 89 msidata_$i <- readImzML('infile_${i}', attach.only=TRUE)
82 centroided(msidata) = $centroids 90 centroided(msidata_$i) = $centroids
83 #end if 91 #end if
84 #elif $infile.ext == 'analyze75' 92 #elif $infile.ext == 'analyze75'
85 msidata_$i <- readAnalyze('infile_${i}') 93 msidata_$i <- readAnalyze('infile_${i}', attach.only=TRUE)
86 centroided(msidata) = $centroids 94 centroided(msidata_$i) = $centroids
87 #else 95 #else
88 msidata_$i = loadRData('infile_${i}.RData') 96 msidata_$i = loadRData('infile_${i}.RData')
89 #end if 97 #end if
90 98
91 ## remove duplicated coordinates, otherwise combine will fail 99 ## remove duplicated coordinates, otherwise combine will fail
104 msidata_$i\$column3 = rep(NA, ncol(msidata_$i)) 112 msidata_$i\$column3 = rep(NA, ncol(msidata_$i))
105 msidata_$i\$column4 = rep(NA, ncol(msidata_$i)) 113 msidata_$i\$column4 = rep(NA, ncol(msidata_$i))
106 msidata_$i\$column5 = rep(NA, ncol(msidata_$i)) 114 msidata_$i\$column5 = rep(NA, ncol(msidata_$i))
107 msidata_$i\$combined_sample = rep(NA, ncol(msidata_$i)) 115 msidata_$i\$combined_sample = rep(NA, ncol(msidata_$i))
108 116
117
109 #if str($annotation_cond.annotation_tabular) == 'annotation' 118 #if str($annotation_cond.annotation_tabular) == 'annotation'
110 print("annotations") 119 print("annotations")
111 120
112 ## read annotation tabular, set first two columns as x and y, merge with coordinates dataframe and order according to pixelorder in msidata 121 ## read annotation tabular, set first two columns as x and y, merge with coordinates dataframe and order according to pixelorder in msidata
113 input_annotation = read.delim("annotation_file_${i}.tabular", header = $annotation_cond.tabular_header, stringsAsFactors = FALSE) 122 input_annotation = read.delim("annotation_file_${i}.tabular", header = $annotation_cond.tabular_header, stringsAsFactors = FALSE)
129 msidata_$i\$column2 = annotation_df_8_sorted[,5] 138 msidata_$i\$column2 = annotation_df_8_sorted[,5]
130 msidata_$i\$column3 = annotation_df_8_sorted[,6] 139 msidata_$i\$column3 = annotation_df_8_sorted[,6]
131 msidata_$i\$column4 = annotation_df_8_sorted[,7] 140 msidata_$i\$column4 = annotation_df_8_sorted[,7]
132 msidata_$i\$column5 = annotation_df_8_sorted[,8] 141 msidata_$i\$column5 = annotation_df_8_sorted[,8]
133 142
143
134 ## extract columnnames from (last) annotation tabular (for QC plot names) 144 ## extract columnnames from (last) annotation tabular (for QC plot names)
135 annotation_colnames = colnames(input_annotation)[-c(1,2)] 145 annotation_colnames = colnames(input_annotation)[-c(1,2)]
136 146
137 #end if 147 #end if
138 148
140 ################### preparation xy shifts ########################## 150 ################### preparation xy shifts ##########################
141 151
142 #if str( $combine_conditional.combine_method ) == 'xy_shifts': 152 #if str( $combine_conditional.combine_method ) == 'xy_shifts':
143 153
144 ## shift coordinates according to input tabular file and store file names 154 ## shift coordinates according to input tabular file and store file names
145 coord(msidata_$i)\$x = coord(msidata_$i)\$x + input_list[$i+1,$combine_conditional.column_x] ## shifts x coordinates according to tabular file 155 coord(msidata_$i)\$x = as.integer(coord(msidata_$i)\$x + input_list[$i+1,$combine_conditional.column_x]) ## shifts x coordinates according to tabular file
146 coord(msidata_$i)\$y = coord(msidata_$i)\$y + input_list[$i+1,$combine_conditional.column_y] ## shifts y coordinates according to tabular file 156 coord(msidata_$i)\$y = as.integer(coord(msidata_$i)\$y + input_list[$i+1,$combine_conditional.column_y]) ## shifts y coordinates according to tabular file
147 pixel_vector = append(pixel_vector, rep(paste($i+1, input_list[$i+1,$combine_conditional.column_names], sep="_"),times=ncol(msidata_$i))) ## stores file name for each pixel 157 pixel_vector = append(pixel_vector, rep(paste($i+1, input_list[$i+1,$combine_conditional.column_names], sep="_"),times=ncol(msidata_$i))) ## stores file name for each pixel
148 msidata_$i\$combined_sample = rep(paste($i+1, input_list[$i+1,$combine_conditional.column_names], sep="_"),times=ncol(msidata_$i)) 158 msidata_$i\$combined_sample = rep(paste($i+1, input_list[$i+1,$combine_conditional.column_names], sep="_"),times=ncol(msidata_$i))
149 pixelcoords_$i = cbind(coord(msidata_$i)[,1:2], rep($i+1,ncol(msidata_$i))) 159 pixelcoords_$i = cbind(coord(msidata_$i)[,1:2], rep($i+1,ncol(msidata_$i)))
150 #silent $pixelcoords.append('pixelcoords_'+str($i)) 160 #silent $pixelcoords.append('pixelcoords_'+str($i))
151 colnames(pixelcoords_$i)[3] = "file_number" 161 colnames(pixelcoords_$i)[3] = "file_number"
165 msidata_$i\$combined_sample = as.factor(names_vector) 175 msidata_$i\$combined_sample = as.factor(names_vector)
166 } 176 }
167 } 177 }
168 178
169 ## Number of input files define grid which is row-wise filled with files 179 ## Number of input files define grid which is row-wise filled with files
170 180 coord(msidata_$i)\$x = as.integer(coord(msidata_$i)\$x - (min(coord(msidata_$i)\$x-1)) + x_shifts)
171 coord(msidata_$i)\$x = coord(msidata_$i)\$x - (min(coord(msidata_$i)\$x-1)) + x_shifts 181 coord(msidata_$i)\$y = as.integer(coord(msidata_$i)\$y - (min(coord(msidata_$i)\$y-1)) + y_shifts)
172 coord(msidata_$i)\$y = coord(msidata_$i)\$y - (min(coord(msidata_$i)\$y-1)) + y_shifts
173 x_shifts = max(coord(msidata_$i)\$x) + 5 182 x_shifts = max(coord(msidata_$i)\$x) + 5
174 max_y = append(max_y, max(coord(msidata_$i)\$y)) 183 max_y = append(max_y, max(coord(msidata_$i)\$y))
175 all_files = $num_infiles 184 all_files = $num_infiles
176 new_row = ($i+1)/ceiling(sqrt(all_files)) 185 new_row = ($i+1)/ceiling(sqrt(all_files))
177 new_row%%1==0 186 new_row%%1==0
207 ## create dataframe with x,y,sample_name and show all pixels in PDF as QC 216 ## create dataframe with x,y,sample_name and show all pixels in PDF as QC
208 position_df = cbind(coord(msidata_combined)[,1:2], msidata_combined\$combined_sample) 217 position_df = cbind(coord(msidata_combined)[,1:2], msidata_combined\$combined_sample)
209 colnames(position_df)[3] = "sample_name" 218 colnames(position_df)[3] = "sample_name"
210 219
211 ## save as (.RData) 220 ## save as (.RData)
212
213 msidata = msidata_combined 221 msidata = msidata_combined
214 save(msidata, file="$msidata_combined") 222 save(msidata, file="$msidata_combined")
223
224 ## save msidata as imzML file
225 #if $imzml_output:
226 writeImzML(msidata, "out")
227 #end if
228
215 229
216 ################################## xy shifts ################################### 230 ################################## xy shifts ###################################
217 ################################################################################ 231 ################################################################################
218 232
219 #elif str( $combine_conditional.combine_method ) == 'xy_shifts': 233 #elif str( $combine_conditional.combine_method ) == 'xy_shifts':
239 253
240 ## save as (.RData) 254 ## save as (.RData)
241 255
242 msidata = msidata_combined 256 msidata = msidata_combined
243 save(msidata, file="$msidata_combined") 257 save(msidata, file="$msidata_combined")
258
259 ## save msidata as imzML file
260 writeImzML(msidata, "out")
244 261
245 ## create x,y,sample_name dataframe for QC pdf 262 ## create x,y,sample_name dataframe for QC pdf
246 263
247 position_df = cbind(coord(msidata), msidata\$combined_sample) 264 position_df = cbind(coord(msidata), msidata\$combined_sample)
248 colnames(position_df)[3] = "sample_name" 265 colnames(position_df)[3] = "sample_name"
386 #end if 403 #end if
387 404
388 }else{ 405 }else{
389 print("No annotation tabular output because file has no features or pixels left") 406 print("No annotation tabular output because file has no features or pixels left")
390 } 407 }
408
409
391 410
392 411
393 ]]></configfile> 412 ]]></configfile>
394 </configfiles> 413 </configfiles>
395 <inputs> 414 <inputs>
437 <param name="column_y" data_ref="coordinates_file" label="Column with values for shift in y direction" type="data_column"/> 456 <param name="column_y" data_ref="coordinates_file" label="Column with values for shift in y direction" type="data_column"/>
438 <param name="column_names" data_ref="coordinates_file" label="Column with dataset names" type="data_column"/> 457 <param name="column_names" data_ref="coordinates_file" label="Column with dataset names" type="data_column"/>
439 <param name="xy_header" type="boolean" label="Tabular files contain a header line" truevalue="TRUE" falsevalue="FALSE"/> 458 <param name="xy_header" type="boolean" label="Tabular files contain a header line" truevalue="TRUE" falsevalue="FALSE"/>
440 </when> 459 </when>
441 </conditional> 460 </conditional>
461 <param name="imzml_output" type="boolean" label="Output of imzML file" truevalue="TRUE" falsevalue="FALSE"/>
442 </inputs> 462 </inputs>
443 <outputs> 463 <outputs>
444 <data format="rdata" name="msidata_combined" label="${tool.name} on ${on_string}"/> 464 <data format="rdata" name="msidata_combined" label="${tool.name} on ${on_string}"/>
445 <data format="pdf" name="QC_overview" from_work_dir="Combined_qc.pdf" label = "${tool.name} on ${on_string}: QC"/> 465 <data format="pdf" name="QC_overview" from_work_dir="Combined_qc.pdf" label = "${tool.name} on ${on_string}: QC"/>
446 <data format="tabular" name="pixel_annotations" label="${tool.name} on ${on_string}: annotations"/> 466 <data format="tabular" name="pixel_annotations" label="${tool.name} on ${on_string}: annotations"/>
467 <data format="imzml" name="outfile_imzml" label="${tool.name} on ${on_string} : imzML">
468 <filter>imzml_output</filter>
469 </data>
447 </outputs> 470 </outputs>
448 <tests> 471 <tests>
449 <test> 472 <test>
450 <param name="infiles" value="msidata_1.RData,msidata_2.RData,msidata_3.RData" ftype="rdata"/> 473 <param name="infiles" value="msidata_1.RData,msidata_2.RData,msidata_3.RData" ftype="rdata"/>
451 <conditional name="annotation_cond"> 474 <conditional name="annotation_cond">
541 564
542 565
543 566
544 **Output** 567 **Output**
545 568
546 - single imzML file containing all valid input files 569 -
570 - MSI data as .RData output (can be read with the Cardinal package in R)
571 - optional: MSI data as imzML file
547 - pdf that shows the pixel positions and annotations of the combined files 572 - pdf that shows the pixel positions and annotations of the combined files
548 - Tabular file with pixel annotations (x,y,column with input file names and up to five annotation columns) 573 - Tabular file with pixel annotations (x,y,column with input file names and up to five annotation columns)
549 574
550 575
551 ]]> 576 ]]>