pymzml / pymzML

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

Averaging spectra #98

Closed CAWarmerdam closed 5 years ago

CAWarmerdam commented 6 years ago

I am very new to pymzml and I would like to average all spectra from a file within a given time range to analyse this further. On the (outdated?) docs (http://pymzml.github.io/usage.html#advanced-usage) is an example that shows how to average the spectra, but this doesn't seem to work.

Initializing an empty spectrum as done in the example throws an error: t += spec / spec['total ion current'] File "pymzml\spec.py", line 516, in __add__ self.set_peaks(self._reprofile_Peaks(), 'reprofiled') File "pymzml\spec.py", line 1139, in _reprofile_Peaks for mz, i in self.peaks('centroided'): File "pymzml\spec.py", line 994, in peaks mz_params = self._get_encoding_parameters('m/z array') File "pymzml\spec.py", line 199, in _get_encoding_parameters array_type_accession = self.calling_instance.OT[array_type]['id'] AttributeError: 'NoneType' object has no attribute 'OT'

And adapting the code so no empty new instance is made halts advancements in the program without any erros. first_spec = None for n, spec in enumerate(self.ms_run): if first_spec is None: first_spec = spec / spec['total ion current'] else: first_spec += spec / spec['total ion current']

What is currently the correct procedure for creating the average spectrum?

JB-MS commented 6 years ago

Hi, sorry for the late reply. I haven't used this feature for some time, so I would have to look into that .

Which version of pymzML are you using?

Cheers, Johannes

CAWarmerdam commented 6 years ago

Hi Johannes,

Thanks. It’s fine. I however have managed to reach my objectives regarding this subject with another method. I still think it would be usefull to resolve this issue.

The version of pymzML is 2.0.3

The code below is shown on the documentation for calculating the average spectrum, this throws an error as written in my first post:

t = pymzml.spec.Spectrum()
for s in msrun:
    if s['ms level'] == 1:
    t += s / s['total ion current']

This second code snippet is my adaptation that does seem to halt progress of the program

first_spec = None
for n, spec in enumerate(self.ms_run):
    if first_spec is None:
        first_spec = spec / spec['total ion current']
    else:
        first_spec += spec / spec['total ion current']

Thanks for your help, Robert Warmerdam

fu commented 6 years ago

Hi Robert,

yes, spec averaging did not make it into the newest pymzML version although we at Cellzome have developed an advanced version of it, which, however, needs some more evaluation. I hope we can bring back that feature in v 2.1 .Sorry about that :( I guess we should at least update the docu for v2.0 and remove that script for the time being.

Cheers

.c

MKoesters commented 5 years ago

Hope that Issue is finally resolved, at least your examples are working as expected at my machine. Feel free to repopen this Issue if your problem is not resolved and its still needed