diff spectra_plots.xml @ 2:3642ed221eb2 draft

planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/cardinal commit f127be2141cf22e269c85282d226eb16fe14a9c1
author galaxyp
date Fri, 15 Feb 2019 10:23:28 -0500
parents 1d9931768896
children 58c4aef16eb0
line wrap: on
line diff
--- a/spectra_plots.xml	Thu Oct 25 07:30:24 2018 -0400
+++ b/spectra_plots.xml	Fri Feb 15 10:23:28 2019 -0500
@@ -1,4 +1,4 @@
-<tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.1">
+<tool id="cardinal_spectra_plots" name="MSI plot spectra" version="@VERSION@.2">
     <description>
         mass spectrometry imaging mass spectra plots
     </description>
@@ -27,6 +27,7 @@
 library(ggplot2)
 library(scales)
 
+
 @READING_MSIDATA@
 
 @DATA_PROPERTIES@
@@ -52,15 +53,17 @@
 
 ## set NA to 0 otherwise plot function will not work
 
-    ##spectra(msidata)[is.na(spectra(msidata)[])] = 0 ## in case of NA values they will be set to zero
+    #if str($processed_cond.processed_file) == "processed":
+        ##processed file needs to be converted into matrix to be able to replace NAs
+        iData(msidata) <- iData(msidata)[]
+        spectra(msidata)[][is.na(spectra(msidata)[])] = 0
+    #else
+        spectra(msidata)[is.na(spectra(msidata))] = 0
+    #end if
 
-    spectra_df = spectra(msidata)[]
-    spectra_df[is.na(spectra_df)] = 0
-    print(paste0("Number of NA which were converted into 0:",sum(is.na(spectra_df))))
-    spectra(msidata) = spectra_df
+## run only if mz and pixels are > 0
 
-
-if (npeaks > 0){
+if (ncol(msidata)>0 & nrow(msidata) >0){
 
     pixeldf = data.frame(matrix(ncol = 2, nrow=0))
 
@@ -73,13 +76,21 @@
         #for $chosenpixel in $pixel_conditional.repeatpixel: 
 
             pixelname = paste0("x = ", $chosenpixel.inputx,", ", "y = ", $chosenpixel.inputy)
-            pixelisvalid = as.character(pixelname %in% names(pixels(msidata)))
+
+
+
+        input_pixels = paste($chosenpixel.inputx, $chosenpixel.inputy, sep="_")
+        dataset_pixels = paste(coord(msidata)\$x, coord(msidata)\$y, sep="_")
+
+        pixelisvalid = as.character(input_pixels %in% dataset_pixels)
+
+
+
             pixeldf = rbind(pixeldf, cbind(pixelname, pixelisvalid))
 
             ############################# II) control image ####################
 
                 if (pixelisvalid == "TRUE"){
-                    print(pixelisvalid)
 
                     image(msidata, mz=$chosenpixel.inputmz, ylim = c(maximumy+(0.2*maximumy),minimumy-1),
                     colorkey=FALSE, plusminus = $chosenpixel.plusminusinDalton,
@@ -188,16 +199,13 @@
                         key_legend = TRUE
                     }else{key_legend = FALSE}
 
-            spectra(msidata)[is.na(spectra(msidata)[])] = 0 ## in case of NA values they will be set to zero
             plot(msidata, pixel=1:ncol(msidata), pixel.groups=msidata\$annotation, key=key_legend, col=hue_pal()(length(levels(msidata\$annotation))),superpose=TRUE)
         }else{
-            spectra(msidata)[is.na(spectra(msidata)[])] = 0 ## in case of NA values they will be set to zero
             plot(msidata, pixel=1:ncol(msidata), key=TRUE)}
 
         ##################### II) Sample: plot zoom-in mass spectrum ##########
 
         #if $pixel_conditional.zoomed_sample:
-            iData(msidata) <- iData(msidata)[] ## getting back data on disk 
             #for $token in $pixel_conditional.zoomed_sample:
                 print("zoomed sample pixels")
 
@@ -317,7 +325,7 @@
         </conditional>
     </inputs>
     <outputs>
-        <data format="pdf" name="plots" from_work_dir="mzplots.pdf" label="${tool.name} on ${on_string}"/>
+        <data format="pdf" name="plots" from_work_dir="mzplots.pdf" label="${tool.name} on ${on_string}:results"/>
     </outputs>
     <tests>
         <test>