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

Creating a Scan from m/z & intensity pairs in a DataFrame #10

Closed DarylWM closed 5 years ago

DarylWM commented 5 years ago

Hi @mobiusklein.

I'd like to deconvolute (m/z,intensity) pairs already in a DataFrame. I've looked at the source and it seems I need to create a ScanDataSource. Do you have an example perhaps, or could you offer a suggestion for how to go about it?

Thanks.

mobiusklein commented 5 years ago

All behaviors of Scan objects, including deconvolute are available as separate functions. The one you're looking for is ms_deisotope.deconvolute_peaks. This function takes the peak list representation, and the same range of other parameters as Scan.deconvolute, but its return value is a tuple-like object, where the first value is the deconvoluted peak list and the second value is a list of "priority" targets, which should be empty.

from ms_deisotope import deconvolute_peaks, averagine, scoring
...

peaks = get_peak_mz_int_pairs()

deconvoluted_peaks, _priority_targets = deconvolute_peaks(
         peaks, averagine=averagine.peptide, scorer=scoring.MSDeconVFitter(10.0))

The Scan class is a giant inversion-of-control structure wrapping the disparate shapes that different mass spectrometry data formats produce. That makes them very tricky to build from scratch by a library user, though I should fix that eventually.

For reference, deconvolute_peaks will convert any sequence of "Peak-like" objects into another data structure for compatibility with statically typed methods. The conversion logic is in prepare_peaklist. I tried to handle the most common types of cases, but if your type isn't handled here, please let me know and I'll try to accommodate it, or at least show you what to do to make it compatible.

DarylWM commented 5 years ago

Thanks @mobiusklein, that helped me out.