glasgowcompbio / vimms

A programmable and modular LC/MS simulator in Python
MIT License
19 stars 6 forks source link

One test fixture doesn't produce MS2 scans #64

Closed sdrogers closed 4 years ago

sdrogers commented 4 years ago

fragscan_dataset_spectra produced empty MS2 scans. Chemical objects don't have any children. Problem is this method: https://github.com/sdrogers/vimms/blob/be48bd5c9f4db9f63cc7bd7f0b42bba7d1e339db/vimms/Chemicals.py#L378-L389 Should it be returning an empty list on line 383?

At the moment, I've removed it from all tests.

joewandy commented 4 years ago

Should it be returning an empty list on line 383?

It shouldn't. It's an old unfinished code that Vinny and I forgot to complete.

sdrogers commented 4 years ago

What does it need for completion?

joewandy commented 4 years ago

We need to test the block of codes below that return to see if they actually work.

I remember we were in a hurry doing something else at that time, so we just returned an empty kids (line 383) as a hack to make this run -- instead of returning the kids that are properly initialised (line 384-389).

sdrogers commented 4 years ago

What should they do? I know they should make a spectrum, but in what way? Pull an intact spectrum from the dataset?

joewandy commented 4 years ago

I think we wanted to sample ms2 spectrum from the dataset and adjust the relative intensities of ms2 peaks in that spectrum, so it's proportional to the parent ms1 peak?

Add comments below, based on looking at the codes:

 def _get_children_spectra(self, parent): 
     # this should hopefully sample an intact ms2 spectrum from the dataset?
     spectra = self.peak_sampler.get_ms2_spectra()[0] 
     kids = [] 

    # turn ms2 spectrum intensities into relative intensities
     intensity_props = self._get_msn_proportions(None, None, spectra.intensities) 

    # randomly sample one `parent_mass_prop`
    # this is the proportion of all fragment intensities in a spectra over the parent intensity
    # returns number between 0 and 1
     parent_mass_prop = self.peak_sampler.get_parent_intensity_proportion() 

    # create ms2 peaks having the right intensities??
     for i in range(len(spectra.mzs)): 
         kid = MSN(spectra.mzs[i], spectra.ms_level, intensity_props[i], parent_mass_prop, None, parent) 
         kids.append(kid) 
     return kids 
sdrogers commented 4 years ago

ok, so it:

  1. grabs a spectrum
  2. normalises the spectrum (so max is 1: https://github.com/sdrogers/vimms/blob/ec4d0da06a03b6cf6e77409381739e5ac398afcc/vimms/Chemicals.py#L442-L444)
  3. Get an intensity proportion from the peak sampler...how much of the parent intensity becomes fragments
  4. create the MS2 peaks with the correct intensities

It looks good to me, I'll try uncommenting and see what happens 👍

joewandy commented 4 years ago

it would be good if we have another file to test the chemical generation process (it's getting quite complex now, and will be more complex in the future). Maybe can create one test_chemicals.py next to test_controllers.py?

sdrogers commented 4 years ago

yes, please do so - separate issue though