glasgowcompbio / vimms

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

Refactor Scan Sampler to Use Previous Scan Level #273

Open mcbrider5002 opened 8 months ago

mcbrider5002 commented 8 months ago

Currently IndependentMassSpectrometer supports two kinds of arguments to generate scan times. (Example.) The first is a dictionary mapping MS-levels (int) to either static values or a callable (of no arguments). The second is an object supporting a function with the signature sample(current_level, next_level, current_rt). This is intended to be used with a ScanTimeSampler.

A consequence of this is that the simulated mass spec must ask for the scan level of the next scan before it can compute the current RT. However, the TaskFilter used in dynamically adjusting scan times must know the current RT before deciding what the next scan (and its level) will be. For this to work the call to compute the scan time therefore had to be moved and the scan level of the next scan ignored by passing None in this commit.

To resupport this functionality, the code must therefore be changed so that scan samplers use a method sample(previous_level, current_level, current_rt). This preserves the idea that the scan time depends on whether you are switching MS level while not requiring us to "see into the future" and allowing TaskFilter to get the current RT.

Additionally, on initialising an IndependentMassSpectrometer, it could cast an argument, if it is given as dictionary, to a subclass of ScanTimeSampler. DefaultScanTimeSampler requires only minor changes to account for this (i.e. must allow the values in the dictionary to be callables rather than just values). This would allow us to avoid having messy type handling code in the body of IndependentMassSpectrometer while retaining backwards compatibility. (i.e. We just call sample on it regardless of which form the argument was given in.)