Issue #26 resolved
Former user created an issue

Hi, Thanks a lot for creating the library. This is actually not an issue, but rather a question on how to use 'mzxml' the mzXML reader.

The following code is from your tutorial (with slight modification):

from pyteomics import mzxml, auxiliary
with'tests/test.mzXML') as reader:

The code works. However, I could not find any other example code to allow me to use the 'mzxml' module. I would like to read a spectrum using the 'get_by_id' method as stated on this page:

If anyone can provide a simple example code I would greatly appreciate it.

Thanks a lot again.

Comments (9)

  1. Lev Levitsky repo owner

    Hello, here is a minimal example showing how to retrieve a scan by its 'num' attribute:

    In [1]: from pyteomics import mzxml
    In [2]: f = mzxml.MzXML('tests/test.mzXML')
    In [3]: f['19']

    This will print the dict corresponding to the <scan> with num='19' (see the test file included in the repository).

    Alternatively, you can do:


    which will give the same result.

    As a second argument to get_by_id, you can specify the attribute name to use for lookup instead of 'num'.

  2. lubwen

    Thanks a lot for the fast reply. When I tried it on my example mzXML, it output the folllowing: {'id': '19', 'offset': '18933'}

    Is this normal?

    What I would like to obtain is the information for scan number '19'. Desired return data in XML is given below:

    <scan num="19" msLevel="1" scanEvent="0" masterIndex="-1" peaksCount="1" ionInjectionTime="100" elapsedScanTime="0.0408431" polarity="+" scanType="Z" filterLine="FTMS + c NSI SIM ms [1025.90-1029.90]" filterLine_analyzer="FTMS" filterLine_activation_type="CID" filterLine_low_m_z="1025.9" filterLine_high_m_z="1029.9" filterLine_activation_energy="-1" retentionTime="PT3.80985S" startMz="1025.9" endMz="1029.9" lowMz="1027.01" highMz="1027.01" basePeakMz="1027.01" basePeakIntensity="1304.58" totIonCurrent="1304.75" > <peaks precision="32" byteOrder="network" contentType="m/z-int" compressionType="none" compressedLen="0" >RIBgQESjEnk=</peaks> <labelData precision="32" byteOrder="network" contentType="m/z-int" compressionType="none" compressedLen="0" numDataPoints="1" >RIBgQEILZIBEoBwO</labelData> </scan>

  3. Lev Levitsky repo owner

    Since it returned something with id='19' rather than num='19', I suspect that you are using the parser which defaults to 'id' as the scan ID key. That would be the case if you are using the latest release version, as opposed to the development version of pyteomics. This issue was discussed on our mailing list, and unfortunately there hasn't been a new release since then.

    If that is the case, you should be able to get the correct result by explicitly specifying 'num' as the ID key:

    f.get_by_id('19', 'num')

    ... or by installing the latest pyteomics version from the repository.

    If neither of those help, please share the example file and we'll look into the problem.

  4. Log in to comment