diff data_exporter.xml @ 4:e521b5767819 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit ecdc3a64aa245d80dbc5487b2bf10a85a43adc6d
author galaxyp
date Fri, 22 Mar 2019 08:16:20 -0400
parents d94770c22f13
children 350a84ea795c
line wrap: on
line diff
--- a/data_exporter.xml	Thu Feb 28 09:24:07 2019 -0500
+++ b/data_exporter.xml	Fri Mar 22 08:16:20 2019 -0400
@@ -1,4 +1,4 @@
-<tool id="cardinal_data_exporter" name="MSI data exporter" version="@VERSION@.1">
+<tool id="cardinal_data_exporter" name="MSI data exporter" version="@VERSION@.2">
     <description>
         exports imzML and Analyze7.5 to tabular files
     </description>
@@ -24,8 +24,6 @@
 
 @READING_MSIDATA_INRAM@
 
-## to make sure that processed files work as well: 
-iData(msidata) = iData(msidata)[]
 
     ###################### Intensity matrix output ################################
 
@@ -37,12 +35,11 @@
         pixel_names = gsub(", y = ", "_", names(pixels(msidata)))
         pixel_names = gsub(" = ", "y_", pixel_names)
 
-        spectramatrix = cbind(mz_names,spectra(msidata)[])
-        newmatrix = rbind(c("mz_name", pixel_names), spectramatrix)
+        ##spectramatrix = cbind(mz_names,spectra(msidata))
+        newmatrix = rbind(c("mz_name", pixel_names), cbind(mz_names,spectra(msidata)))
         write.table(newmatrix, file="$intensity_matrix", quote = FALSE, row.names = FALSE, col.names=FALSE, sep = "\t")
         ## free up RAM space in case furhter steps will be run: 
         rm(newmatrix)
-        rm(spectramatrix)
         gc()
 
     #end if
@@ -56,19 +53,22 @@
         mz_names = gsub("/", "", mz_names)
 
         ## mean, median, sd and SEM intensity per file and mz
-        full_sample_mean = apply(spectra(msidata)[],1,mean, na.rm=TRUE)
-        full_sample_median = apply(spectra(msidata)[],1,median, na.rm=TRUE)
-        full_sample_sd = apply(spectra(msidata)[],1,sd, na.rm=TRUE)
+        full_sample_mean = rowMeans(spectra(msidata), na.rm=TRUE)
+        full_sample_median = apply(spectra(msidata),1,median, na.rm=TRUE)
+        full_sample_sd = apply(spectra(msidata),1,sd, na.rm=TRUE)
         full_sample_sem = full_sample_sd/full_sample_mean*100
         ## npeaks and sum of all intensities per spectrum and mz
-        npeaks= sum(spectra(msidata)[]>0, na.rm=TRUE)
-        mzTIC = rowSums(spectra(msidata)[], na.rm=TRUE) ## calculate intensity sum for each m/z
-        peakspermz = rowSums(spectra(msidata)[] > 0, na.rm=TRUE) ## calculate number of intensities > 0 for each m/z (max = number of spectra)
+        npeaks= sum(spectra(msidata)>0, na.rm=TRUE)
+        mzTIC = rowSums(spectra(msidata), na.rm=TRUE) ## calculate intensity sum for each m/z
+        peakspermz = rowSums(spectra(msidata) > 0, na.rm=TRUE) ## calculate number of intensities > 0 for each m/z (max = number of spectra)
 
         ## combine into dataframe, order is the same for all vectors
         mz_df = data.frame(mz_names, mz(msidata), full_sample_mean, full_sample_median, full_sample_sd, full_sample_sem, mzTIC, peakspermz)
         colnames(mz_df) = c("mz_names", "mz", "sample_mean", "sample_median", "sample_sd", "sample_sem", "intensity_sum", "number_peaks")
         write.table(mz_df, file="$feature_output", quote = FALSE, row.names = FALSE, col.names=TRUE, sep = "\t")
+        ## free up RAM space in case furhter steps will be run: 
+        rm(mz_df)
+        gc()
     #end if
 
     ###################### summarized m/z feature output #######################
@@ -101,7 +101,7 @@
             count = 1
             for (subsample in levels(msidata\$annotation)){
                 subsample_pixels = msidata[,msidata\$annotation == subsample]
-                subsample_calc = apply(spectra(subsample_pixels)[],1,mean, na.rm=TRUE)
+                subsample_calc = rowMeans(spectra(subsample_pixels), na.rm=TRUE)
                 sample_matrix = cbind(sample_matrix, subsample_calc)
                 count = count+1}
             sample_matrix_mean = cbind(mz_names,sample_matrix)
@@ -116,7 +116,7 @@
             count = 1
             for (subsample in levels(msidata\$annotation)){
                 subsample_pixels = msidata[,msidata\$annotation == subsample]
-                subsample_calc = apply(spectra(subsample_pixels)[],1,median, na.rm=TRUE)
+                subsample_calc = apply(spectra(subsample_pixels),1,median, na.rm=TRUE)
                 sample_matrix = cbind(sample_matrix, subsample_calc)
                 count = count+1}
             sample_matrix_median = cbind(mz_names,sample_matrix)
@@ -131,7 +131,7 @@
             count = 1
             for (subsample in levels(msidata\$annotation)){
                 subsample_pixels = msidata[,msidata\$annotation == subsample]
-                subsample_calc = apply(spectra(subsample_pixels)[],1,sd, na.rm=TRUE)
+                subsample_calc = apply(spectra(subsample_pixels),1,sd, na.rm=TRUE)
                 sample_matrix = cbind(sample_matrix, subsample_calc)
                 count = count+1}
             sample_matrix_sd = cbind(mz_names,sample_matrix)
@@ -156,19 +156,19 @@
         pixelxyarray=1:length(pixels(msidata))
 
         ## number of pixels per spectrum: every intensity value > 0 counts as peak
-        peaksperpixel = apply(spectra(msidata)[]> 0, 2, sum, na.rm=TRUE)
+        peaksperpixel = colSums(spectra(msidata)>0, na.rm=TRUE)
 
         ## Total ion chromatogram per spectrum
-        TICs = round(apply(spectra(msidata)[],2, sum, na.rm=TRUE), digits = 2)
+        TICs = round(colSums(spectra(msidata), na.rm=TRUE), digits = 2)
 
         ## Median ion intensity per spectrum
-        med_int = round(apply(spectra(msidata)[], 2, median, na.rm=TRUE), digits = 2)
+        med_int = round(apply(spectra(msidata), 2, median, na.rm=TRUE), digits = 2)
 
         ## Maximum ion intensity per spectrum
-        max_int = round(apply(spectra(msidata)[], 2, max, na.rm=TRUE), digits = 2)
+        max_int = round(apply(spectra(msidata), 2, max, na.rm=TRUE), digits = 2)
 
         ## Highest m/z per spectrum
-        highestmz = apply(spectra(msidata)[],2,which.max) 
+        highestmz = apply(spectra(msidata),2,which.max) 
         highestmz_data = mz(msidata)[highestmz]
 
         ## Combine into dataframe; order is the same for all vectors
@@ -197,13 +197,13 @@
 
                 for (mass in 1:length(inputcalibrantmasses)){
                     filtered_data = msidata[mz(msidata) >= inputcalibrantmasses[mass]-plusminusvalues[mass] & mz(msidata) <= inputcalibrantmasses[mass]+plusminusvalues[mass],]
-                    if (nrow(filtered_data) > 1 & sum(spectra(filtered_data)[],na.rm=TRUE) > 0){
+                    if (nrow(filtered_data) > 1 & sum(spectra(filtered_data),na.rm=TRUE) > 0){
                         ## intensity of all m/z > 0
-                          intensity_sum = apply(spectra(filtered_data)[],2,sum, na.rm=TRUE) > 0
+                          intensity_sum = colSums(spectra(filtered_data), na.rm=TRUE) > 0
 
-                    }else if(nrow(filtered_data) == 1 & sum(spectra(filtered_data)[], na.rm=TRUE) > 0){
+                    }else if(nrow(filtered_data) == 1 & sum(spectra(filtered_data), na.rm=TRUE) > 0){
                         ## intensity of only m/z > 0
-                        intensity_sum = spectra(filtered_data)[] > 0 
+                        intensity_sum = spectra(filtered_data) > 0 
                     }else{
                         intensity_sum = rep(FALSE, ncol(filtered_data))}
                     ## for each pixel add sum of intensities > 0 in the given m/z range