pymzml / pymzML

pymzML - an interface between Python and mzML Mass spectrometry Files
https://pymzml.readthedocs.io/en/latest/
MIT License
158 stars 91 forks source link

How to get isolation window information? #327

Open rxnataliezhang opened 1 year ago

rxnataliezhang commented 1 year ago

Do you have any features about getting isolation window information (upper bound and lower bound)? I didn't find any clue about this in the documentation.

MKoesters commented 1 year ago

Hi @rxnataliezhang,

You can get the scan window for an MS1 spectrum by:

ms1_spec["scan window lower limit"]

If you want to know the isolation offset for precursor selection you can get it by:

ms2_spec['isolation window lower offset']

In general, if you know the name of an attribute in the mzml you can just access it like this, it should work with any attribute. However, it might be a good idea for the next release to include this info in the selected_precursors attribute of a spectrum.

Best, Manuel

MKoesters commented 1 year ago

Hi,

Did this solve your issue or you need furher support? If there is no problem, I'll close this issue in about a week :)

Best, Manuel

rxnataliezhang commented 1 year ago

Hi Manuel,

Sorry that I turned to other busy work and forgot to reply.

Not quite. I ran the following code as you suggested and this returns None.

run = pymzml.run.Reader(mzml_file)

for n,spectrum in enumerate(run):
    if spectrum.ms_level == 2:
        print(spectrum["isolation window lower offset"])
StSchulze commented 1 year ago

I can confirm that it doesn't work with spectrum["isolation window lower offset"], so it seems like the name of the xml element is not parsed correctly in this case.

However, it works using the accession number ("MS:1000828" for lower offset, "MS:1000829" for upper offset). So, try the following:

run = pymzml.run.Reader(mzml_file)

for n,spectrum in enumerate(run):
    if spectrum.ms_level == 2:
        print(spectrum["MS:1000828"])

I hope that helps, but let us know if it still doesn't work.

rxnataliezhang commented 1 year ago

@StSchulze Yes, this works. Thank you!

fu commented 9 months ago

It seems "isolation window lower offset" is just the wrong name, maybe?. What name has MS:1000828 in the current obo?