Skip to content

Commit

Permalink
added error handler to set to zero corrupted spectra in imzML files
Browse files Browse the repository at this point in the history
  • Loading branch information
prafols committed Mar 11, 2019
1 parent 0d1637f commit a643369
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions R/imzMLreader.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,16 @@ import_imzML <- function(imzML_File, ibd_File = paste(sub("\\.[^.]*$", "", imzM
#Apply re-sampling (only if needed...)
if( ! identical(mzdd, mzAxis))
{
dd <- (approx( x = mzdd, y = dd, xout = mzAxis, ties = "ordered", yleft = 0, yright = 0))$y
dd[which(is.na(dd))] <- 0 #Remove any possible NA
if(length(mzdd) == length(dd))
{
dd <- (approx( x = mzdd, y = dd, xout = mzAxis, ties = "ordered", yleft = 0, yright = 0))$y
dd[which(is.na(dd))] <- 0 #Remove any possible NA
}
else
{
cat(paste0("WARNING: spectra at X = ", xmlRes$run_data$x[i], " Y = ", xmlRes$run_data$y[i], " corrupt!\n" ))
dd <- rep(0, length(mzAxis))
}
}
}
}
Expand Down

0 comments on commit a643369

Please sign in to comment.