k_seq.model
: kinetics and pool models¶
-
class
k_seq.model.
ModelBase
(**params)¶ Bases:
abc.ABC
base structure for a model A model contains following aspects:
model param estimation: need data, _get_mask, params, seed,
random variable generator, need params, seed, _get_mask
-
abstract
func
(**params)¶ model function: params –> prediction
-
abstract
predict
(**params)¶ Function to predict model output
k_seq.model.count module¶
Model the sequencing process to generate counts
-
k_seq.model.count.
multinomial
(p, N, seed=None)¶ Multinomial distribution for a given probability p and total number of draws
k_seq.model.kinetic module¶
A collection of commonly used kinetic models
Notes
- kinetic models were currently implemented as callable function. It might migrate to Model subclass for
storing parameters, set required parameters, etc
TODO: fix broadcast problem: including broadcast as argument changed the signature for the model function
-
class
k_seq.model.kinetic.
BYOModel
¶ Bases:
object
A collection of BYO kinetic models where some values are fixed:
exp time (t): 90 min BYO degradation factor ($lpha$): 0.479
- models:
reacted_frac(broadcast=False)
amount_first_order(broadcast=False)
composition_first_order(c, p0, k, A)
- Parameters
p0 (1-D list-like) – Amount or composition of sequences in the input pool
c (float or 1-D list-like) – Concentration of substrates, return input pool if negative
k (float or 1-D list-like) – Kinetic coefficient for each sequence in first-order kinetics, with length as number of sequences
A (float or 1-D list-like) – Asymptotic conversion for each sequence in first-order kinetics, with length as number of sequences
return: concentration/composition at the name (time, concentration) point
-
static
amount_first_order
(broadcast=False)¶ Get model for absolute amount of reacted pool, if c is negative, return 0 Notice: broadcast should be False if multiple p0 is used.
- Parameters
broadcast (bool) – if True, apply broadcast for k and A, outer product between A and k are calculated;if False, k and A have to be same length and apply elementwise production. Default False.
- Returns
- p0 (1-D list-like): Amount or composition of sequences in the input pool
c (float or 1-D list-like): Concentration of substrates, return input pool if negative k (float or 1-D list-like): Kinetic coefficient for each sequence in first-order kinetics, with length as number of sequences A (float or 1-D list-like): Asymptotic conversion for each sequence in first-order kinetics, with length as number of sequences
- which returns:
Absolute amount of each sequence in each sample float, 1-D or 2-D np.ndarray with shape (uniq_seq_num, sample_num)
- Return type
a callable with arguments
-
static
composition_first_order
(c, p0, k, A)¶ Function of pool composition w.r.t. BYO concentration (c) if x < 0, output is p0
broadcast is not supported that is k and A should have same length
- Parameters
c (float or 1-D list-like) – Concentration of substrates, return input pool if negative
p0 (1-D list-like) – Amount or composition of sequences in the input pool
k (float or 1-D list-like) – Kinetic coefficient for each sequence in first-order kinetics, with length as number of sequences
A (float or 1-D list-like) – Asymptotic conversion for each sequence in first-order kinetics, with length as number of sequences
- Returns
Pool composition for sequences in each sample float, 1-D or 2-D np.ndarray with shape (len(k), sample_num)
-
static
reacted_frac
(broadcast=False)¶ Get model for Reacted fraction for each seq in a pool :param broadcast: if True, apply broadcast for k and A, outer product between A and k are calculated;if False, k and A have to be same length and apply elementwise production. Default False. :type broadcast: bool
- Returns
- c (float or 1-D list-like): Concentration of substrates, return input pool if negative
k (float or 1-D list-like): Kinetic coefficient for each sequence in first-order kinetics, with length as number of sequences A (float or 1-D list-like): Asymptotic conversion for each sequence in first-order kinetics, with length as number of sequences
- which returns:
Reacted fraction for each sequence in each sample float, 1-D or 2-D np.ndarray with shape (uniq_seq_num, sample_num)
- Return type
a callable with arguments
-
k_seq.model.kinetic.
check_scalar
(value)¶ Check if value is a scalar or is the single value in a vector/matrix/tensor
-
k_seq.model.kinetic.
first_order
(c, k, A, alpha, t, broadcast=False)¶ Base first-order kinetic model, returns reacted fraction of input seqs given parameters
broadcast are available on A, k, c and a full return tensor will have shape (A, k, c) if any of these 3 parameters is scalar, the dimension is automatically squeezed while maintaining the order
Note: for c_i < 0, returns ones as it is input pool
Args: c (float or 1-D list-like): Concentration of substrates, return input pool if negative
k (float or 1-D list-like): Kinetic coefficient for each sequence in first-order kinetics, with length as number of sequences A (float or 1-D list-like): Asymptotic conversion for each sequence in first-order kinetics, with length as number of sequences alpha (float): degradation coefficient for substrates t (float): Reaction time in the experiments broadcast (bool): if True, apply broadcast for k and A, outer product between A and k are calculated;if False, k and A have to be same length and apply elementwise production. Default False.
-
k_seq.model.kinetic.
to_scalar
(value)¶ Try to convert a value to scalar, if possible
k_seq.model.pool module¶
Model for a sequence pool with constituent change from reaction
-
class
k_seq.model.pool.
PoolModel
(count_model, kinetic_model=None, param_table=None, note=None, **params)¶ Bases:
k_seq.model.ModelBase
Model of a kinetic pool,
-
kinetic_model
¶ input initial pool with parameter and return a reacted pool composition
- Type
callable
-
count_model
¶ input pool composition and return a list of counts given total counts or params
- Type
callable
-
kinetic_params
¶ list of parameter names for kinetic model
- Type
list of str
-
count_params
¶ list of parameter names for count model
- Type
list of str
-
note
¶ note for the model
- Type
str
-
__init__
(count_model, kinetic_model=None, param_table=None, note=None, **params)¶ Initialize a pool model with given kinetic models and count_model :param count_model: model for sequencing counts :type count_model: ModelBase or callable :param kinetic_model: model for pool kinetics, no react if not given :type kinetic_model: ModalBase or callable :param **params:
-
func
(**params)¶ Draw counts from given parameters
- Returns
reacted amount if not normalized counts for each sequence
- Return type
output sum from kinetic model
-
predict
(**params)¶ Wrapper over _get_mask, can accept parameters to overwrite current ones if exist
-