mobiusklein / ms_deisotope

A library for deisotoping and charge state deconvolution of complex mass spectra
https://mobiusklein.github.io/ms_deisotope
Apache License 2.0
33 stars 14 forks source link

Error in MzMLSerializer #5

Closed infusini closed 5 years ago

infusini commented 5 years ago

Hi @mobiusklein

in the mzML writer example in the link

import ms_deisotope
from ms_deisotope.test.common import datafile
from ms_deisotope.output.mzml import MzMLSerializer

reader = ms_deisotope.MSFileLoader(datafile("small.mzML"))
with open("small.deconvoluted.mzML", 'wb') as fh:
    writer = MzMLSerializer(fh, n_spectra=len(reader))

    writer.copy_metadata_from(reader)
    for bunch in reader:
        bunch.precursor.pick_peaks()
        bunch.precursor.deconvolute()
        for product in bunch.products:
            product.pick_peaks()
            product.deconvolute()
        writer.save(bunch)

    writer.complete()
    writer.format()

I get this error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-488-fc7db1835dfd> in <module>()
      6 with open("/home/ubuntu/playground/XIC_HelaEcoli_11_1_decon.mzML", 'wb') as fh:
      7 
----> 8     writer = MzMLSerializer(fh, n_spectra=len(reader))
      9 
     10     writer.copy_metadata_from(reader)

/opt/anaconda3/lib/python3.6/site-packages/ms_deisotope-0.0.6-py3.6-linux-x86_64.egg/ms_deisotope/output/mzml.py in __init__(self, handle, n_spectra, compression, deconvoluted, sample_name, build_extra_index, data_encoding)
    197         if data_encoding is None:
    198             data_encoding = {
--> 199                 writer.MZ_ARRAY: np.float64,
    200                 writer.INTENSITY_ARRAY: np.float32,
    201                 writer.CHARGE_ARRAY: np.int32,

AttributeError: 'NoneType' object has no attribute 'MZ_ARRAY'

The same happens with my own file.

Cheers,

Giuseppe

mobiusklein commented 5 years ago

You need to install psims for this module to work. It appears I removed the more informative error message, but didn't update the requirements.txt. You can install psims fron https://github.com/mobiusklein/psims, or using pip. I've just published psims v0.1.19 to PyPI.

On Mon, Sep 17, 2018 at 3:38 AM Giuseppe Infusini notifications@github.com wrote:

Hi @mobiusklein https://github.com/mobiusklein

in the mzML writer example in the link https://mobiusklein.github.io/ms_deisotope/docs/_build/html/output/mzml.html#writing-mzml

import ms_deisotopefrom ms_deisotope.test.common import datafilefrom ms_deisotope.output.mzml import MzMLSerializer

reader = ms_deisotope.MSFileLoader(datafile("small.mzML"))with open("small.deconvoluted.mzML", 'wb') as fh: writer = MzMLSerializer(fh, n_spectra=len(reader))

writer.copy_metadata_from(reader)
for bunch in reader:
    bunch.precursor.pick_peaks()
    bunch.precursor.deconvolute()
    for product in bunch.products:
        product.pick_peaks()
        product.deconvolute()
    writer.save(bunch)

writer.complete()
writer.format()

I get this error


AttributeError Traceback (most recent call last)

in () 6 with open("/home/ubuntu/playground/XIC_HelaEcoli_11_1_decon.mzML", 'wb') as fh: 7 ----> 8 writer = MzMLSerializer(fh, n_spectra=len(reader)) 9 10 writer.copy_metadata_from(reader) /opt/anaconda3/lib/python3.6/site-packages/ms_deisotope-0.0.6-py3.6-linux-x86_64.egg/ms_deisotope/output/mzml.py in __init__(self, handle, n_spectra, compression, deconvoluted, sample_name, build_extra_index, data_encoding) 197 if data_encoding is None: 198 data_encoding = { --> 199 writer.MZ_ARRAY: np.float64, 200 writer.INTENSITY_ARRAY: np.float32, 201 writer.CHARGE_ARRAY: np.int32, AttributeError: 'NoneType' object has no attribute 'MZ_ARRAY' The same happens with my own file. Cheers, Giuseppe — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub , or mute the thread .
infusini commented 5 years ago

Worked, thanks.

But I have a question, my intent is to write an mzML with deconvoluted MS2, but unaltered MS1. the snippet of code works well, but only I keep this line bunch.precursor.deconvolute()

Is there any reason for it? Will the resulting mzML have deconvoluted MS1 spectra as well as MS2?

mobiusklein commented 5 years ago

The implementation currently assumes that if you set deconvoluted=True in the initialization code that both MS1 and MSn scans will be deconvoluted and it will write the deconvoluted_peak_set out for both types of scans, otherwise it will try peak_set or arrays. I can refactor it to be more granular.

On Mon, Sep 17, 2018 at 6:50 AM Giuseppe Infusini notifications@github.com wrote:

Worked, thanks.

But I have a question, my intent is to write an mzML with deconvoluted MS2, but unaltered MS1. the snippet of code works well, but only I keep this line bunch.precursor.deconvolute()

Is there any reason for it? Will the resulting mzML have deconvoluted MS1 spectra as well as MS2?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mobiusklein/ms_deisotope/issues/5#issuecomment-421965951, or mute the thread https://github.com/notifications/unsubscribe-auth/ABXCefKS7EixAxHecwc2uYyuXT1-HuTxks5ub356gaJpZM4WrZYK .

mobiusklein commented 5 years ago

I've added a save_scan method which will write a single scan to the file, with an optional deconvoluted argument which will tell the writer whether you want to write the deconvoluted peaks or the centroided peaks.

mobiusklein commented 5 years ago

Are there any remaining problems to work out for this issue, or can it be closed?