schemarecomb.libraries.MutationRateCache¶
- class schemarecomb.libraries.MutationRateCache(bp_to_group_bp)¶
Caches calculated mutation rates for future mutation calculations.
For certain breakpoints, shifting it by one residue will not change the average mutation rate of otherwise identical libraries. Therefore, we can cache every rate that is calculated, such that we can use it for future libraries that are known to differ only in these redundant breakpoints. This is necessary because the average mutation rate calculation takes a significant amount of time and is otherwise difficult to speed up.
You can treat this class as a dictionary with keys of breakpoint position tuples and values of mutation_rates. The breakpoint positions will be automatically converted to breakpoint grouping index. For example, suppose otherwise identical libraries with breakpoints at positions 2 or 3 are known to have the same mutation rate. Then:
>>> from schemarecomb.libraries import MutationRateCache >>> bp_to_group = {1: 1, 2: 2, 3: 2, 4: 3} # 2 and 3 in the same group >>> mr_cache = MutationRateCache(bp_to_group) >>> mr_cache[(1, 2, 4)] = 23.4 # avg mutation rate of lib (1, 2, 4) >>> # We know the (1, 3, 4) avg mutation rate without calculation. >>> assert mr_cache[(1, 3, 4)] == 23.4
- Parameters
bp_to_group_bp (
dict[int,int]) – Mapping from breakpoint position to the index of group of redundant breakpoints that contain it.