sgibb / MALDIquant

Quantitative Analysis of Mass Spectrometry Data
https://strimmerlab.github.io/software/maldiquant/
60 stars 25 forks source link

MALDIquant With WATERS DESI Data #63

Closed umara-Nissar closed 4 years ago

umara-Nissar commented 4 years ago

@sgibb Greetings. I have been trying to use MALDIquant with waters data for a while now. I have converted the raw files to imzML format. The script is working well with one data file but when I try to use it for multiple files it giving errors at different steps depending on how I upload the files in the script. I tried to use combined file generated by imzML converter but the file generated is treated as single data file rather than multiple sample file. I tried to load like this file.path(Directory,"F1(29)N19-11-19 Analyte 1.imzML")

spectra1 <- importImzMl(file.path(Directory,"F1(29)N19-11-19 Analyte 1.imzML"),verbose=FALSE)

file.path(Directory,"F1(29)T19-11-19 Analyte 1.imzML")

spectra2 <- importImzMl(file.path(Directory,"F1(29)T19-11-19 Analyte 1.imzML"),verbose=FALSE) ##########################################################################

Spectra <- list(sample1=spectra1, sample2=spectra2)

setClass("Spectra",slots = c(sample1="list",sample2="list" @@))

I tried this as well Spectra <- createMassSpectrum(mass=1:2, intensity=1:2, metaData=list(name="Spectra1"))

is(Spectra)

setClass("Spectra",slots = c(sample1="list",sample2="list" ),contains="numeric") Spectra <- list(sample1=spectra1, sample2=spectra2)

I am new to R , if you could please help me with this.

sgibb commented 4 years ago

Did you tried

library("MADLIquantForeign")
spectra <- importImzMl(Directory)

importImzMl is looking for all .imzML files recursively.

umara-Nissar commented 4 years ago

Dear @sgibb thank you for replying. I load the library first everytime I work on MALDIquant and it does load the files. when I process the files individually it does that as well but but when i load multiple files( files of different samples) like this 1 It doesnot process them as separate files. I load the files as suggested but in my case the problem comes when i try to upload multiple files (files of different samples). How can I upload multiple files? As with the fiedler data there is the folder that is to be uploaded which has all the files. I tried to upload folder with all my sample files but it is not working as well. I tried few options as mentioned in ist comment but they do not work. also it gives this error maldiquant Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘mass’ for signature ‘"list"’. If you could please help me with this.

sgibb commented 4 years ago

import* (as importImzMl) always returns a list of spectra (even if there is just one spectrum, then it is a list of length 1). You have to use the [[ operator (as for every generic list in R) to access the individual spectrum:

library("MADLIquantForeign")
spectra <- importImzMl(Directory)
mass(spectra[[1]])
plot(spectra[[1]])

There is no need to combine individual files manually because import* (and importImzMl) supports recursive reading of all files in a directory and also include and exclude patterns. You could even list the filenames manually:

## list files manually
spectra <- importImzMl(c("file1.imzMl", "file2.imzMl")) 
## use patterns
spectra <- importImzMl(".", pattern = "file[0-9]\\.imzMl")

But if you really want to combine the spectra on your own its:

spectra1 <- importImzMl("file1.imzMl")
spectra2 <- importImzMl("file2.imzMl")
spectra <- c(spectra1, spectra2)
## get the mz values of the first spectrum
mass(spectra[[1]])

Feel free to reopen the issue if it doesn't explain your problem.

umara-Nissar commented 4 years ago

@sgibb Thank you for making it clear. I tried the functions as suggested but I get this error Errormsg

sgibb commented 4 years ago

Could you attach the file? (I would need both the .imzMl and the corresponding .ibd)

umara-Nissar commented 4 years ago

I've shared an item with you:

UmaraDataFiles https://drive.google.com/drive/folders/1-3Ik7cHpCoVZ4hgqnYWhKvMyQgrHHQzG?usp=sharing&ts=5e428e17

It's not an attachment – it's stored online. To open this item, just click
the link above.

Please find the attached data files

Regards Umara

umara-Nissar commented 4 years ago

I could not attach the files in this mail due to size limitation. I shared with you the google drive link via my gmail account.

Apologies for the inconvenience

Best Regards, Umara


From: Sebastian Gibb notifications@github.com Sent: Tuesday, February 11, 2020 12:41:36 PM To: sgibb/MALDIquant Cc: Rafiqi, Umara Nissar (PATHOLOGY); State change Subject: Re: [sgibb/MALDIquant] MALDIquant With WATERS DESI Data (#63)

Could you attach the file? (I would need both the .imzMl and the corresponding .ibd)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/sgibb/MALDIquant/issues/63?email_source=notifications&email_token=AN6PNLCQJO7R6DUMFFPQVLTRCJ6GBA5CNFSM4KGQKHE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELL6DTY#issuecomment-584573391, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN6PNLBUXT3KWEMPZ7JWA2LRCJ6GBANCNFSM4KGQKHEQ.

sgibb commented 4 years ago

Unfortunately your files are incorrect (I guess it is not your fault).

imzML files could store data in two formats: continuous or processed. Your .imzML files claim to be continuous but the .idb files are in fact processed. That's why MALDIquantForeign can import the first but not the second spectrum of a file. You may ask WATERS to fix their converter.

Please have a look at https://ms-imaging.org/wp/imzml/data-structure/ for the details:

In order to insure efficient storage, two different formats of the binary data are defined: continuous and processed. Continuous type means that each spectrum of an image has the same m/z values. As a result the m/z array is only saved once directly behind the UUID of the file and the intensity arrays of the spectra are following. At the processed type every spectrum has its own m/z array. So it is necessary to save both – the m/z array and the corresponding intensity array – per spectrum.

image

A quick fix for you would be to fix the imzML files by replacing line 10:

      <cvParam cvRef="IMS" accession="IMS:1000030" name="continuous" value=""/>

with

      <cvParam cvRef="IMS" accession="IMS:1000031" name="processed" value=""/>

A solution in R would be:

library("MALDIquant")
library("MALDIquantForeign")

repairImzMlFiles <- function(d) {
    files <- list.files(
        d, pattern = "*\\.imzML$", recursive = TRUE, full.names = TRUE
    )
    for (f in files) {
        lns <- sub(
            'accession=\"IMS:1000030\" name=\"continuous\"',
            'accession=\"IMS:1000031\" name=\"processed\"',
            readLines(f)
        )
        writeLines(lns, f)
    }
}

repairImzMlFiles(".")
spectra <- importImzMl(".")

par(mfrow = c(2, 1))
plot(spectra[[1]])
plot(spectra[[2]])
umara-Nissar commented 4 years ago

Thank You so much for your help . I will go through all the details and follow the procedure as mentioned. I may get back to you if I face any difficulty again. I am attaching the file of how I convert the raw file into imzML format. If you could please see whether I am doing it right or not. WatersFileConversion.pptx Thank You again. Kindest Regards Umara

sgibb commented 4 years ago

Sry, but I never used msconvert myself.

umara-Nissar commented 4 years ago

No problem. Thank you again for your help. Kindest Regards Umara


From: Sebastian Gibb notifications@github.com Sent: Tuesday, February 11, 2020 3:16:20 PM To: sgibb/MALDIquant Cc: Rafiqi, Umara Nissar (PATHOLOGY); State change Subject: Re: [sgibb/MALDIquant] MALDIquant With WATERS DESI Data (#63)

Sry, but I never used msconvert myself.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/sgibb/MALDIquant/issues/63?email_source=notifications&email_token=AN6PNLDVEDMKL7EUFBC5PZLRCKQKJA5CNFSM4KGQKHE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELMLXIA#issuecomment-584629152, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN6PNLHIMT6RZ6XMXO4JV4DRCKQKJANCNFSM4KGQKHEQ.