levitsky / pyteomics

Pyteomics is a collection of lightweight and handy tools for Python that help to handle various sorts of proteomics data. Pyteomics provides a growing set of modules to facilitate the most common tasks in proteomics data analysis.
http://pyteomics.readthedocs.io
Apache License 2.0
105 stars 34 forks source link

[Question] How to get instrument information from mzML #79

Closed jspaezp closed 1 year ago

jspaezp commented 1 year ago

Hello!

I am using the mzml object to read an indexed mzml file and I was wondering whether there is a way to get that information using the python API (which I would be having a hard time finding within the documentation).

Within the actual mzml file it can be found in L20 like this ...

<referenceableParamGroupList count="1">
  <referenceableParamGroup id="CommonInstrumentParams">
    <cvParam cvRef="MS" accession="MS:1002877" name="Q Exactive HF-X" value=""/>
    <cvParam cvRef="MS" accession="MS:1000529" name="instrument serial number" value="Exactive Series slot #6133"/>
  </referenceableParamGroup>
</referenceableParamGroupList>

Thanks for the help beforehand! Kindest wishes, Sebastian

levitsky commented 1 year ago

Hi Sebastian,

You can use the iterfind method to get this information. Example with one of my files:

>>> f = mzml.MzML(...)

>>> next(f.iterfind('referenceableParamGroup[@id="CommonInstrumentParams"]'))
{'id': 'CommonInstrumentParams',
 'Orbitrap Fusion': '',
 'instrument serial number': 'FSN20211'}

Note 1: You can actually just use 'referenceableParamGroup', but this shows how XPath syntax works. Note 2: The file pointer must be still at the beginning of the file for this to work. If you have already read some spectra, you can call f.reset() to go back to the beginning. But after that, iterating over spectra will start from the beginning, as well.

You can also use auxiliary.cvquery() on this dict so that you get instrument name as a value with a predictable key:

>>> aux.cvquery(next(f.iterfind('referenceableParamGroup[@id="CommonInstrumentParams"]')))
{'MS:1002416': 'Orbitrap Fusion', 'MS:1000529': 'FSN20211'}

Best regards, Lev

jspaezp commented 1 year ago

Thank you so much!