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

Processing ms2 scans #7

Closed DarylWM closed 5 years ago

DarylWM commented 5 years ago

Thanks for sharing this code. I'd like to use it to deconvolve and deisotope my ms2 spectra, but I'm having trouble working out how to do that when it's not accompanied by an ms1 scan.

My MGF follows:

BEGIN IONS PEPMASS=1247.602054 6018645 TITLE=RawFile: HeLa_20KInt Index: 1 precursor: 26579 Charge: 2 FeatureIntensity: 6018645 Feature#: 2 RtApex: 1085.76696854 RTINSECONDS=1085.76696854 INSTRUMENT=ESI-QUAD-TOF CHARGE=2+ SCANS=1085 1036.442 8882 1037.446 5433 675.343 2306 1038.448 2278 892.392 2049 448.212 1783 979.423 1645 835.367 1472 676.34 1379 333.185 1363 561.295 1339 1036.415 1261 893.392 1220 980.425 1152 1019.423 873 1149.517 769 602.331 680 893.381 667 1018.426 655 789.43 641 892.381 605 1019.414 602 562.3 584 981.428 548 448.219 542 1037.403 528 836.378 502 894.391 500 1039.452 497 575.27 469 503.263 439 509.724 427 449.22 421 566.762 401 1150.543 350 788.429 349 658.315 343 575.767 329 518.725 317 566.255 297 1149.487 283 589.243 266 244.164 249 893.409 246 1020.431 226 801.382 209 362.11 184 511.177 168 836.361 168 837.387 132 1004.499 131 442.161 125 1001.412 111 1001.4 88 END IONS

To process it, I tried: reader = ms_deisotope.MSFileLoader(datafile('feature-2-precursor-26579.mgf')) bunch = next(reader)

And bunch is: Scan(u'RawFile: HeLa_20KInt Index: 1 precursor: 26579 Charge: 2 FeatureIntensity: 6018645 Feature#: 2 RtApex: 1085.76696854', index=0, time=18.0961, ms_level=2, PrecursorInformation(mz=1247.6021/0.0000, intensity=6018645.0000/0.0000, charge=2/0.0, scan_id=None))

I was expecting the product ions to be in the Scan object. What am I missing?

mobiusklein commented 5 years ago

The datafile function from the unit tests is a helper function to get the absolute path to one of the included example data files used by those tests. In your own code, you'd just write

reader = ms_deisotope.MSFileLoader("path/to/your/file")

For a reader whose iteration mode is "single" like MGF, or an mzML without MS1 scans, iterating over the reader yields Scan objects. If the mode were "grouped", it would yield ScanBunch objects.

To access the raw signal in a Scan object, you would use scan.arrays, which returns an object with an mz array and an intensity array. The entries in these arrays reflect whatever data was stored in the file. To convert those into centroids, call scan.pick_peaks(), which populates scan.peak_set. These are the centroids produced by either fitting peak models on profile data, or by just converting each point in a pre-centroided scan into a peak object.

Once you've picked the peaks of a scan, you deconvolute them using the Scan.deconvolute method, whose signature is the same as deconvolute_peaks. If you were dealing with peptide product ions, you would invoke it like so:

scan.deconvolute(scorer=ms_deisotope.MSDeconvFitter(10), averagine=ms_deisotope.peptide, truncate_after=0.8)

This populates the scan's deconvoluted_peak_set attribute, which will contain the deconvoluted peaks.

From end-to-end:

reader = ms_deisotope.MSFileLoader('feature-2-precursor-26579.mgf')
scan = next(reader)
scan.pick_peaks().deconvolute(
    scorer=ms_deisotope.MSDeconvFitter(10), averagine=ms_deisotope.peptide,
    truncate_after=0.8)
print(scan.deconvoluted_peak_set)

Were you looking at examples using ScanProcessor?

DarylWM commented 5 years ago

Thanks, that clears it up for me.