MixALime

Parameters estimation

Fitting model to data

To control for various errors and biases in count data, model parameters ought to be fitted to the data with the fit command. MIXALIME uses Maximum Local Pseudo-Likelihood (MLPL). The approach can be effectively described as fitting conditional distributions (namely, the reference allele read count conditioned on the alternative allele read count and vice-versa, hence "pseudo" in MLPL) to the subset of allelic read counts formed by a sliding window. This results in a multitude of parameter estimates for each allelic read count/for each window, hence "local" in MLPL. This approach helps to model possible non-linearities in the data. The method comes with extra hyperparameters relating to the sliding window that can be kept at the default values for most datasets. For details, see the Window subsection.

What can't be avoided even in the most basic case is providing a name of the model:

> mixalime fit MyProject DistName

Possible values of DistName are explained below. After a successful fit run, a *.fit file should appear in the current working directory.

Models

Briefly, if we denote reference allele read counts as $x$ and alternative allele read counts as $y$, MIXALIME models them as $$x \,~\, F(θ_x, y),\: y \,~\, F(θ_y, x),$$ where $F$ is some distribution and θs are parameter vectors to be estimated. The composition of θ varies for different distributions, but regardless of choice it always contains line parameters $b, μ$ that control mapping biases. In MIXALIME, we assume that the mean number of counts $r$ for one allele is linearly dependent on the mean number of counts of the other allele, e.g. for $y$: $$r(b, μ, x) = b x + μ.$$ There are 3 distributions available in MixALime:

Please refer to the arXiv preprint for details.

BetaNB has an extra "concentration" parameter $κ$ - the lower the $κ$, the higher the variance of the model.

Roughly speaking, the selection of the model depends on the overdispersion observed in the dataset under study, with NB being best suitable for datasets with low variance (e.g. ChIP-seq), whereas BetaNB works well for very noisy overdispersed datasets (e.g. RNA-seq). Sometimes the negative binomial model is not applicable at all and fits the data horribly, e.g.:

Note that BetaNB will always provide fits at least as good as NB as it contains negative binomial as an extreme case with an infinite $κ$ value, but in general BetaNB often results in an overly conservative scoring. In some cases it is possible to get the best of both worlds by penalizing low values of $κ$.

Regularized BetaNB

We can impose a Laplace prior on the reciprocal of $κ$: $${1}/{κ} \,~\,Laplace(0, t).$$ This will encourage higher values of $κ$ at the cost of goodness of fit. The degree of this encouragement is moderated by a weight $t$: $$t = α n s,$$ where $s$ is the allelic read count at which the current sliding window is centered (this way, $κ$ is guaranteed to gradually increase at farther windows), $n$ is the number of observations in the current sliding window and $α$ is a hyperparameter. The $α$ can be set with the argument --regul-alpha <float>, with a generally reasonable value being the default value of $1.0$. $s$ or $n$ can be omitted from the weight if necessary with options --no-regul-slice and --no-regul-n respectively.

Regularization can be enabled with the --regul argument.

Polyploidy and CNVs

For non-diploid organisms or when information on CNVs is available, a user can supply this information at the create step. Then, read counts will be modeled by a mixture of 2 distributions from the same family, but with different success probabilities $$p_1 = {BAD}/{BAD+1},\:p_2 = {1}/{BAD+1}.$$ The model will be fitted to data with different BADs separately. This also introduces an extra mixture parameter $w$ to be estimated. See below that accounting for various BADs can be crucial:

Using a non-mixture model will result in tons of false positives as the right tail of the distribution arising from high copy number regions is not fitted by the model.

Window

First we rehearse the reasoning behind the "locality" in the MLPL approach: in particular cases, including pooled datasets, the reference bias modeled by a single parameter (or a single line equation) does not adequately reflect the observed read counts at high-coverage SNVs. This happens both due to non-linearity not taken into account, as well as because the high-coverage SNVs occur at a systematically lower frequency, hence granting them lower weight in the parameter estimation procedure. For complex data, instead of fitting a single model to the whole dataset, it is more reliable to fit multiple models with a sliding window scanning a range of counts supporting the preselected allele. E.g. when estimating the parameter for scoring reference alleles, the subsets are chosen in a sliding window with respect to the alternative allele counts: the window is expanded in both directions until the number of observations in the window reaches a predefined value --window-size (10000, the default value, is usually enough in practice). See an abstract example below for a visual explanation:

The parameters of the sliding window that are of most interest are:

Name Description Default value
--window-size <int> Window will be expanded until it contains at least this many observations 10000
--min-slices <int> Window will be expanded at least this many times 3
--stop-slice-n <int> As long as the number of observations at the central slice of a sliding window is greater than this value, the process will continue towards later slices (larger n-s). Parameter estimates will be extrapolated beyond the final window 10

Inspecting the quality of fit

It's better not to trust MixALime output blindly, but inspect the quality of fit beforehand. To facilitate this task, a user can plot parameter estimates, PMFs at various slices and GoF-indices. All plots can be drawn with a single command:

> mixalime plot all MyProject folder_for_figures

Then, folder_for_figures should contain a folder for each BAD present in the data with figures. Possibly interesting arguments for the plot all command are:

Name Description Default value
--max-count <int> Plots will be drawn up to this allelic read count 60
--slices <list[int]> PMF will be drawn for each slice at an allelic read count in the list. 5, 10, 20, 30, 40
--fmt <str> Figures format (e.g. "png", "pdf", "svg", etc) png
--dpi <int> Resolution of raster figures, in dots per inch 200
r.png Estimates of r(b, μ) (calculated from estimates of b, μ)
r.png
Estimates of $r(b, μ)$
(calculated from estimates of $b, μ$)
k.png Estimates of κ^{-1} (Applicable only for BetaNB)
k.png
Estimates of $κ^{-1}$
(Applicable only for BetaNB)
w.png Estimates of w (Applicable only for BAD > 1)
w.png
Estimates of $w$
(Applicable only for $BAD > 1$)
gof.png Goodness-of-Fit indices (the lower, the better the fit)
gof.png
Goodness-of-Fit indices
(the lower, the better the fit)

There is also n.png, but it is not a fit statistic, but a data statistic, depicting how many observations there are per slice:

n.png
n.png

It might be helpful when considering changing sliding window hyperparameters.

Furthermore, there is a bunch of "slice-plots" with PMFs for each slice specified in --slices parameter, e.g.:

slices_5.png
slices_5.png
slices_20.png
slices_20.png

So, how do we interpret those figures?

First, you should keep an eye out for poor fits: either the allelic read counts were improperly generated, or SNPs were mixed with somatic mutations, or the data has intrinsic overdispersion requiring a different model (e.g. NB versus BetaNB).

Next, there can be discontinuities and crazy discrepancies between "ref" and "alt" in parameter estimates. For example,

We should always expect "ref" and "alt" lines to have similar tangents.
We should always expect "ref" and "alt" lines to have similar tangents.
There is a single outlier at 9 for "alt".
There is a single outlier at 9 for "alt".

Whenever something like this happens, it means either that there is a problem with data or (more likely) the MixALime optimizer failed to converge. As for the latter, meddling with parameters might help, e.g. consider changing window hyperparameters such as increasing the minimal number of slices or the window size per se.

If there is a problem, exporting parameter estimates and likelihood statistics in a tabular form for a more nuanced inspection might be helpful:

> mixalime export all MyProject folderName

It is most convenient to export figures and tables to the same folder.

Standard errors of estimates

A user can supply --std option to the fit command to obtain standard errors of the parameter estimates. This will take a toll on the time needed to fit the model to the data and standard errors are usually not of interest, so this option is turned off by default. If fit was run with it, subsequent runs of plot will respect it automatically by filling an area of $1.5$ standard deviations around parameter estimates, e.g.:

r.png
r.png
k.png
k.png

Fixing parameters

A user can set selected parameters of the model distribution to predefined values via the --fix-params <str>. The option accepts a string of type "param_name_1=val1;param_name_2=val2", where param_name is the name of a parameter and val is its numeric value. A practical example is "w=1;mu=0;b=1", which is the so-called "conservative scoring" useful in scenarios when the data is scarce and the model fits are not reliable.

Other options

There are some options/parameters of the fit command left uncovered, yet still useful:

Name Description Default value
--max-count <int> Observations with the maximal number of counts (be it ref or alt) at an allele greater than this will be omitted for fit None
--max-cover <int> Observations with the total coverage (ref + alt) greater than this will be omitted for fit None
--left <int> Left truncation boundary. If None, then it will be inferred from the previous create step None
--small-dataset-n <int> If a total number of SNV records for a particular BAD is below this value, this subdataset is considered small 10000
--small-dataset-strategy <str> If "conservative", then for small datasets a conservative fit will be used (no parameters are estimated). If "fixed_r", then only $r$ is constrained as in conservative mode. If "none", then MIXALIME will still attempt to fit the model to the sub-dataset conservative
--n-jobs <int> Number of processes/jobs to be run in parallel. The best and maximal number of jobs is 2 * (number of BADs). If "-1", then the maximal number of parallel jobs will be utilized -1
--adjust-line Attempts to alter the estimates of b,μ with very little (if any) decrease in the GoF so that they are closer to those at the previous sliding window. Might make the parameter estimates a bit more stable across the different slices Disabled
On this page