Hi, Davide
That is how I usually remove matrix peaks:
After some preprocessing steps (peakPicking - peakAligning - peakFiltering - normalization) I use spatial shrunken centroid function to find area without slice:
file_ssc_5 <- spatialShrunkenCentroids(file, r = 2, k = 5, s = 1)
Than I make a dataframe, where each column is a cluster and each row is m/z
df_file_ssc_5 <- data.frame(file_ssc_5@resultData@listData[[1]][["centers"]])
Than we can compare mean intestines of each m/z in clusters of interest: for example I see that matrix is in 1, 2 and 3 clusters
df_file_ssc_5$Matrix <- rowMeans(df_file_ssc_5[, c(1, 2, 3)])
than I compare mean "matrix" intensity with other clusters:
df_file_ssc_5_mz <- df_file_ssc_5[df_file_ssc_5$Matrix<df_file_ssc_5$X4 | df_file_ssc_5$Matrix<df_file_ssc_5$X5,]
df_file_ssc_5_sample_mz <- df_file_ssc_5_mz$mz
Than I find indexes of obtained m/z and subset initial file:
file_No_Matrix_MZ <- file[which(file@featureData@mz %in% df_file_ssc_5_sample_mz), ]
I'm not sure, it's the best way, but it works for me
Hope, it will help
best,
Marina