sneumann / mzR

This is the git repository matching the Bioconductor package mzR: parser for netCDF, mzXML, mzData and mzML files (mass spectrometry data)
40 stars 26 forks source link

To subset the file #272

Closed ghost closed 2 years ago

ghost commented 2 years ago

Is it possible to extract a file within an rt range, then apply copyWriteMSData() to create a subset file? The subset file will then be processed with xcms package.

ghost commented 2 years ago

Here are my codes:

group_A_list<- list.files(path =dest.filepath, pattern = ".mzXML", full.name = T) %>%
  lapply(openMSfile)

df1_120_headerinfo <- header(group_A_list[[1]])%>%
  filter(retentionTime >0 & retentionTime < 120)

df1_120_peaksinfo <- peaks(group_A_list[[1]])[1:119]

newfile <- tempfile()

copyWriteMSData(object = df1_120_peaksinfo, file = newfile, original_file = group_A_list[[1]], header = df1_120)

The error message is:

Error in file.exists(original_file) : invalid 'file' argument
lgatto commented 2 years ago

I suggest you use the Spectra package for that - you can easily and sagely subset the object and then write it back to mzML.

ghost commented 2 years ago

I fixed it. My problem is that the group_A_list is a list of pwiz files, original_file() in copyWriteMSData only takes the file name.

Therefore, I did this:

group_A_list<- list.files(path =dest.filepath, pattern = ".mzXML", full.name = T)

group_A_list_pwiz<- list.files(path =dest.filepath, pattern = ".mzXML", full.name = T) %>%
  lapply(openMSfile)

newfile <- tempfile()

copyWriteMSData(object = df1_120_peaksinfo, file = newfile, original_file = group_A_list[[1]], header = df1_120)

I subset the object. Yahoo!

peaks() works as fine as spectra() does.