# HG changeset patch # User galaxyp # Date 1524518185 14400 # Node ID a170455feb599e12c122c3dc2b7e15ff97b6cb92 # Parent 91e2a0c9695c8924076a072e9bfab94b19743860 planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/msi_filtering commit 06c2b45d8644b1d7fc01622a5c59dcbf8886d0f1 diff -r 91e2a0c9695c -r a170455feb59 msi_filtering.xml --- a/msi_filtering.xml Wed Feb 28 14:01:53 2018 -0500 +++ b/msi_filtering.xml Mon Apr 23 17:16:25 2018 -0400 @@ -1,4 +1,4 @@ - + tool for filtering mass spectrometry imaging data bioconductor-cardinal @@ -45,7 +45,7 @@ ###################################### inputfile properties in numbers ###################### -#if $outputs.outputs_select == "quality_control" +#if $outputs.outputs_select == "quality_control": ## Number of features (mz) maxfeatures = length(features(msidata)) ## Range mz @@ -76,63 +76,159 @@ ###################################### filtering of pixels ###################### -#if $inputpixels: - input_list = read.delim("$inputpixels", header = FALSE, - na.strings=c("","NA", "#NUM!", "#ZAHL!"), stringsAsFactors = FALSE) - validpixels = input_list[,$pixel_column] %in% names(pixels(msidata)) + +#if str($pixels_cond.pixel_filtering) == "single_column": + print("single column") + + #if $pixels_cond.single_pixels: + input_list = read.delim("$pixels_cond.single_pixels", header = FALSE, stringsAsFactors = FALSE) + numberpixels = length(input_list[,$pixels_cond.pixel_column]) + valid_entries = input_list[,$pixels_cond.pixel_column] %in% names(pixels(msidata)) + validpixels = sum(valid_entries) + + if (validpixels != 0) + { + pixelsofinterest = pixels(msidata)[names(pixels(msidata)) %in% input_list[valid_entries,$pixels_cond.pixel_column]] + msidata = msidata[,pixelsofinterest] + }else{ + validpixels=0 + } + + #else + validpixels=0 + numberpixels = 0 + #end if + +#elif str($pixels_cond.pixel_filtering) == "two_columns": + print("two columns") - if (validpixels != 0) + #if $pixels_cond.two_columns_pixel: + + input_list = read.delim("$pixels_cond.two_columns_pixel", header = FALSE, + stringsAsFactors = FALSE) + numberpixels = length(input_list[,$pixels_cond.pixel_column_x]) + + inputpixel_x = input_list[,$pixels_cond.pixel_column_x] + inputpixel_y = input_list[,$pixels_cond.pixel_column_y] + + inputpixels = cbind(inputpixel_x, inputpixel_y) + colnames(inputpixels) = c("x", "y") + valid_rows = merge(inputpixels, coord(msidata)[,1:2]) + validpixels = nrow(valid_rows) + + if (validpixels != 0) { - pixelsofinterest = pixels(msidata)[names(pixels(msidata)) %in% input_list[validpixels,$pixel_column]] + + pixelvector = character() + + for (pixel in 1:nrow(valid_rows)) + { + pixelvector[pixel] = paste0("x = ", valid_rows[pixel,1],", ", "y = ", valid_rows[pixel,2]) + } + + pixelsofinterest= pixels(msidata)[names(pixels(msidata)) %in% pixelvector] msidata = msidata[,pixelsofinterest] - numberpixels = length(input_list[,$pixel_column]) - }else { - numberpixels = 0 + }else{ + validpixels=0 } + + #else + validpixels=0 + numberpixels = 0 + #end if -#else - input_list = data.frame(0, 0) - validpixels=0 +#elif str($pixels_cond.pixel_filtering) == "pixel_range": + print("pixel range") + + numberpixels = "range" + validpixels = "range" + + if (sum(coord(msidata)\$x <= $pixels_cond.max_x_range & coord(msidata)\$x >= $pixels_cond.min_x_range) > 0) + { + msidata = msidata[, coord(msidata)\$x <= $pixels_cond.max_x_range & coord(msidata)\$x >= $pixels_cond.min_x_range] + } + + if (sum(coord(msidata)\$y <= $pixels_cond.max_y_range & coord(msidata)\$y >= $pixels_cond.min_y_range) > 0) + { + msidata = msidata[, coord(msidata)\$y <= $pixels_cond.max_y_range & coord(msidata)\$y >= $pixels_cond.min_y_range] + } + + + +#elif str($pixels_cond.pixel_filtering) == "none": + print("no pixel filtering") numberpixels = 0 + validpixels = 0 + #end if ###################################### filtering of features ###################### -#if $inputfeatures: - input_features = read.delim("$inputfeatures", header = FALSE, - na.strings=c("","NA", "#NUM!", "#ZAHL!"), stringsAsFactors = FALSE) - validfeatures = input_features[,$feature_column] %in% names(features(msidata)) +#if str($features_cond.features_filtering) == "features_list": + + print("feature list") - if (validfeatures != 0) - { - featuresofinterest = features(msidata)[names(features(msidata)) %in% input_features[validfeatures,$feature_column]] - msidata = msidata[featuresofinterest,] - numberfeatures = length(input_features[,$feature_column]) - } else { - numberfeatures = 0 - } + input_features = read.delim("$inputfeatures", header = FALSE, stringsAsFactors = FALSE) + + startingrow = $features_cond.feature_header+1 + extracted_features = input_features[startingrow:nrow(input_features),$features_cond.feature_column] + numberfeatures = length(extracted_features) -#else - input_features = data.frame(0, 0) + if (grepl("m/z = ", input_features[startingrow,$features_cond.feature_column])==FALSE) + + { print("no m/z = in data") + + if (class(extracted_features) == "numeric") + { + charactervector = rep("m/z = ", numberfeatures) + mz_added = paste0(charactervector, round(extracted_features,digits=2)) + validfeatures = mz_added %in% names(features(msidata)) + featuresofinterest = features(msidata)[names(features(msidata)) %in% mz_added[validfeatures]] + }else{ + validfeatures = 0 + featuresofinterest = features(msidata) + } + }else{ + validfeatures = extracted_features %in% names(features(msidata)) + featuresofinterest = features(msidata)[names(features(msidata)) %in% extracted_features[validfeatures]] + } + + msidata = msidata[featuresofinterest,] + + + +#elif str($features_cond.features_filtering) == "features_range": + + print("feature range") + + numberfeatures = "range" + validfeatures = NA + + if (sum(mz(msidata) >= $features_cond.min_mz & mz(msidata) <= $features_cond.max_mz)> 0) + { + msidata = msidata[mz(msidata) >= $features_cond.min_mz & mz(msidata) <= $features_cond.max_mz,] + } + + +#elif str($features_cond.features_filtering) == "none": + + print("no feature filtering") validfeatures = 0 numberfeatures = 0 #end if - - - # save msidata as Rfile save(msidata, file="$msidata_filtered") ###################################### outputfile properties in numbers ###################### -#if $outputs.outputs_select == "quality_control" +#if $outputs.outputs_select == "quality_control": ## Number of features (mz) maxfeatures2 = length(features(msidata)) @@ -168,8 +264,8 @@ "Intensities > 0", "Median TIC per pixel", "Number of zero TICs", - paste0("# pixels in ", "$inputpixels.display_name"), - paste0("# mz in ", "$inputfeatures.display_name")) + "pixel overview", + "feature overview") before = c(paste0(maxfeatures), paste0(minmz, " - ", maxmz), @@ -190,7 +286,7 @@ paste0(percpeaks2, " %"), paste0(medint2), paste0(NumemptyTIC2), - paste0("valid pixels: ", sum(validpixels)), + paste0("valid pixels: ", validpixels), paste0("valid mz: ", sum(validfeatures))) @@ -200,17 +296,19 @@ ######################################## PDF QC ############################################# - pdf("filtertool_QC.pdf", fonts = "Times", pointsize = 12) plot(0,type='n',axes=FALSE,ann=FALSE) title(main=paste0("Qualitycontrol of filtering tool for file: \n\n", "$infile.display_name")) + grid.table(property_df, rows= NULL) + ### heatmap image as visual pixel control - ### heatmap image as visual pixel control +if (length(features(msidata))> 0 & length(pixels(msidata)) > 0) +{ image(msidata, mz=$outputs.inputmz, plusminus = $outputs.plusminus_dalton, contrast.enhance = "none", @@ -218,11 +316,19 @@ ### control features which are left - par(mfrow = c(2,1)) - plot(featuresinfile, ylab = "m/z in Dalton", xlab = "feature index") - plot(mz(msidata), ylab = "m/z in Dalton", xlab = "feature index") + plot(featuresinfile, rep(1,length(featuresinfile)), yaxt="n", ylab=NA, xlab="m/z values", col="red", ylim=c(0.8, 1.1), main="Distribution of m/z values") + lines(mz(msidata),rep(0.9, length(mz(msidata))), col="green", type="p") + legend("top", horiz=TRUE, + legend = c("before", "filtered"), + fill = c("red", "green")) + + +}else{ + print("file has no features or pixels left") +} + dev.off() #end if @@ -251,32 +357,73 @@ - - - - + help="Upload composite datatype imzML (ibd+imzML) or analyze75 (hdr+img+t2m) or regular upload .RData (Cardinal MSImageSet)"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - + + outputs["outputs_select"] == "quality_control" - + output_matrix @@ -287,27 +434,104 @@ - + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + @@ -320,16 +544,19 @@ - + - + + + - + + @@ -338,13 +565,14 @@ +