Skip to main content
Topic: m/z sort assumption violated! Argh!! (Read 3848 times) previous topic - next topic

m/z sort assumption violated! Argh!!

Don't panic!
You have probably received a message like the one below
Detecting mass traces at 5 ppm ...
 % finished: 0 Error in .local(object, ...) :
  m/z sort assumption violated !

This error means that one of the scans in your data has the m/z (vector) out of order. CentWave performs a lot of checks on the data to make sure everything is ok. Don't worry though this can be fixed. You can either use openMS FileFilter (-sort_peaks option) or xcms. If it's a single file try this code
Code: [Select]
xr<-xcmsRaw("YourFile", profstep=0)
write.mzdata(xr, file="NewFixedFile.mzData")

However, you will probably find that you have a lot of files that are like this so you want to automate the code. The code below will test every file in the current directory and directories below.

If you could help the developer by telling us what instrument this happened on by filling out the poll. Thank you.

Code: [Select]
## Notes: This program will check the m/z vector for a single file for sort violation
## If a sort violation is found the m/z vector is reorganised along with the Intensity
## vector. Finally a new CDF file is made which is fixed.
## !!!NB!!! : Parallel version does not report progress

checkAllcdfs<-function(Ftype="mzXML", nSlaves=1){
AllCDFs<-list.files(recursive=TRUE, pattern=Ftype,, full.names=TRUE)
if(nSlaves >1){
cl <- makeCluster(nSlaves, type = "SOCK")
clusterEvalQ(cl, library(xcms))
unlist(clusterApply(cl, AllCDFs, checkCDFfile))
} else{
sapply(AllCDFs, checkCDFfile)

checkCDFfile<-function(file, type=".mzXML"){
cat(paste("Loading File:", file, sep=""))
xr<-xcmsRaw(file, profstep=0)
for(i in 1:length(xr@scanindex)){
scan<-getScan(xr, scan=i)
if(is.unsorted(scan[,"mz"]) == TRUE){
cat(" x ")
newfile<-sub(type, "-Fixed.mzdata", file,
write.mzdata(xr, newfile)
file.copy(file, sub(type, ".OLD", file,
if(i == length(xr@scanindex)){
cat(" O ")
H. Paul Benton
Scripps Research Institute
If you have an error with XCMS Online please send me the JOBID and submit an error via the XCMS Online contact page