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

deconvolute_peaks throws error when retention_strategy is specified #11

Closed DarylWM closed 4 years ago

DarylWM commented 5 years ago

Hi @mobiusklein ,

I've been using deconvolute_peaks which has been fine until I tried to specified a retention strategy, as in the following call:

ms2_deconvoluted_peaks, _ = deconvolute_peaks(ms2_peaks_l, averagine=averagine.peptide, charge_range=(1,5), scorer=scoring.MSDeconVFitter(minimum_score=8, mass_error_tolerance=0.1), error_tolerance=4e-5, truncate_after=0.6, retention_strategy=peak_retention_strategy.TopNRetentionStrategy(n_peaks=50, base_peak_coefficient=0.05, max_mass=850.0))

and it throws this error:

ms2_deconvoluted_peaks, _ = deconvolute_peaks(ms2_peaks_l, averagine=averagine.peptide, charge_range=(1,5), scorer=scoring.MSDeconVFitter(minimum_score=8, mass_error_tolerance=0.1), error_tolerance=4e-5, truncate_after=0.6, retention_strategy=peak_retention_strategy.TopNRetentionStrategy(n_peaks=50, base_peak_coefficient=0.05, max_mass=850.0))
  File "/home/ubuntu/anaconda3/envs/py36/lib/python3.6/site-packages/ms_deisotope-0.0.9-py3.6-linux-x86_64.egg/ms_deisotope/deconvolution/api.py", line 155, in deconvolute_peaks
    decon.peaklist, peaklist, charge_range, deconvoluted_peaks)
  File "/home/ubuntu/anaconda3/envs/py36/lib/python3.6/site-packages/ms_deisotope-0.0.9-py3.6-linux-x86_64.egg/ms_deisotope/deconvolution/peak_retention_strategy.py", line 112, in __call__
    return self.retain_peaks(peaklist, original_peaklist, charge_range)
  File "/home/ubuntu/anaconda3/envs/py36/lib/python3.6/site-packages/ms_deisotope-0.0.9-py3.6-linux-x86_64.egg/ms_deisotope/deconvolution/peak_retention_strategy.py", line 174, in retain_peaks
    base_peak = max([peak.intensity for peak in base_peak_sequence])
  File "/home/ubuntu/anaconda3/envs/py36/lib/python3.6/site-packages/ms_deisotope-0.0.9-py3.6-linux-x86_64.egg/ms_deisotope/deconvolution/peak_retention_strategy.py", line 174, in <listcomp>
    base_peak = max([peak.intensity for peak in base_peak_sequence])
AttributeError: 'tuple' object has no attribute 'intensity'

I'm wondering whether this is because I'm using a list of (mz,intensity) tuples and the prepare_peaklist coercion didn't work properly, and when the retention strategy tries to access peak.intensity it's not there?

DarylWM commented 5 years ago

It's happy if ms2_peaks_l is a list of simple_peak.

mobiusklein commented 5 years ago

The peaklist parameter was only being transformed into the expected type once inside the Deconvoluter instance, but was written assuming the type of peaklist was already forced to be an Iterable of FittedPeaks.

I've changed the coercion point to be much earlier in the process in 7ca3980 so this won't be an issue.

The truncation parameter you're using will lose out on the multiply charged peaks smaller than 950 Da. What type of instrument are you using? I've found that truncate_after=0.8 is suitable for most MS2 data. Additionally, because this global truncation parameter is only good for data where the range of isotopic pattern widths is consistently the same, I've implemented a new incremental truncation algorithm which considers all theoretical isotopomers with peaks between truncate_after to truncate_to % of the total theoretical signal:

In [12]: ms_deisotope.peptide.isotopic_cluster(400, charge=2)
Out[12]: TheoreticalIsotopicPattern(400.0000, charge=2, (0.650, 0.277, 0.072))

In [13]: tid = ms_deisotope.peptide.isotopic_cluster(400, charge=2)

In [14]: tid.incremental_truncation(0.8)
Out[14]: 
[TheoreticalIsotopicPattern(400.0000, charge=2, (0.650, 0.277, 0.072)),
 TheoreticalIsotopicPattern(400.0000, charge=2, (0.701, 0.299)),
 TheoreticalIsotopicPattern(400.0000, charge=2, (1.000))]

You can enable this behavior by passing the truncate_to parameter to deconvolute_peaks. I also suggest you try use_quick_charge=True, which will speed up the process markedly. At some point in the future, use_quick_charge will be True by default.

DarylWM commented 5 years ago

Thanks @mobiusklein for your reply and the recent repo pushes. I'm using deconvolute_peaks on data from a Bruker timsTOF Pro for some custom feature detection. I'll give your suggestions a try.

DarylWM commented 5 years ago

Hi @mobiusklein - I'm not seeing how to use the incremental truncation feature. truncate_to doesn't seem to be a parameter on deconvolute_peaks?

mobiusklein commented 5 years ago

Sorry, it's note truncate_to, it's incremental_truncation, I miss-remembered the name.

On Mon, Jun 24, 2019 at 7:19 PM Daryl Wilding-McBride < notifications@github.com> wrote:

Hi @mobiusklein https://github.com/mobiusklein - I'm not seeing how to use the incremental truncation feature. truncate_to doesn't seem to be a parameter on deconvolute_peaks?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mobiusklein/ms_deisotope/issues/11?email_source=notifications&email_token=AAK4E6J3MO3LU26G3RLBSGDP4FJBJA5CNFSM4H226RK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYOP6OI#issuecomment-505216825, or mute the thread https://github.com/notifications/unsubscribe-auth/AAK4E6MVO7LXY4RQVGCNBBLP4FJBJANCNFSM4H226RKQ .

mobiusklein commented 4 years ago

Is this issue resolved?

DarylWM commented 4 years ago

Yes, thank you.