viterbi.hmm: Computes the Viterbi path for a hidden markov model

View source: R/tools.R

viterbi.hmmR Documentation

Computes the Viterbi path for a hidden markov model

Description

Estimates the most likely path for a hidden Markov Chain using the maximum likelihood Viterbi algorithm. The code assumes 3 states (normal, deletion and duplication). It is also setup for the first and last exons to be at position 0 (i.e. normal).

Usage

viterbi.hmm(transitions, loglikelihood, positions, expected.CNV.length)

Arguments

transitions

Transition matrix

loglikelihood

numeric matrix containing the loglikelihood of the data under the possible states

positions

Positions of the exons

expected.CNV.length

Expected length of CNV calls, which impacts the transition matrix between CNV states.

Details

Standard forward-backward Viterbi algorithm using a precomputed matrix of likelihoods.

Value

A list with the two slots 'Viterbi.path' and 'calls'.

Examples

transitions <- matrix(data = 1/3, ncol = 3, nrow = 3)
loglikelihood <- matrix(c(rep(c(0, -10, -10), 3),
                          rep(c(-10, -10, 0), 3),
                          rep(c(-10, 0, -10), 4)), nrow = 3)
## note the final 0 state, enforced by the code
viterbi.hmm(transitions, t(loglikelihood), positions = 1:10, expected.CNV.length = 1)

## Now we cannot transition out of 0 and should have no call
transitions <- matrix(c(1, 0, 0, 0, 1, 0, 0, 0, 1), ncol = 3)

## we can check that no call is made
viterbi.hmm(transitions, t(loglikelihood), positions = 1:10, expected.CNV.length = 1)

ExomeDepth documentation built on Nov. 3, 2022, 5:05 p.m.