<p>There are certainly software libraries for working with HMMs. For a general-purpose implementation in C++, take a look at the <a href="http://docs.seqan.de/seqan/2.1.1/group_HmmAlgorithms.html" rel="noreferrer">SeqAn HMM algorithms</a>.</p>

<p>For your purposes, i.e. “computing … the most likely hidden sequence given the sequence of observed states”, you’d invoke <code>viterbiAlgorithm</code> with your observed sequence and the HMM graph.</p>

<p>More fundamentally I think that most existing, mature implementations are probably found in the domain of signal processing, which has been using them longer than biology, and where most of the underlying theory was developed.</p>

CC BY-SA 3.0
2017-06-02T10:59:48.487Z
2017-06-02T10:59:48.487Z
Konrad Rudolph
<p>If I remember correctly Ewan Birney's Dynamite (a <a href="https://en.wikipedia.org/wiki/Compiler-compiler" rel="nofollow noreferrer">compiler-compiler</a>) as presented at <a href="https://pdfs.semanticscholar.org/2345/f68bb0b2f079f9f201034da462d69a7817b1.pdf" rel="nofollow noreferrer">ISMB 1997</a> had this functionality, there is also some code here on GitHub <a href="https://github.com/birney/wise3" rel="nofollow noreferrer">https://github.com/birney/wise3</a> which at least mentions Dynamite.  Suspect Ewan is too busy these days to work on this, although he has tweeted about blowing dust of his old Dynamite, sorry Dynamite code: <a href="https://twitter.com/ewanbirney/status/788121636973142016" rel="nofollow noreferrer">https://twitter.com/ewanbirney/status/788121636973142016</a></p>

CC BY-SA 3.0
2017-06-04T13:31:13.200Z
2017-06-04T13:37:40.803Z
2017-06-04T13:37:40.803Z
Matt Bashton
<p>I would also recommend to take a look at <a href="https://pomegranate.readthedocs.io/en/latest/" rel="noreferrer">pomegranate</a>, a nice Python package for probabilistic graphical models. It includes solvers for HMMs and much more. Under the hood it uses Cythonised code, so it's also quite fast.</p>

CC BY-SA 3.0
2017-06-02T13:16:00.703Z
2017-06-02T13:16:00.703Z
Lucas van Dijk
<p>Hidden Markov models (HMMs) are used extensively in bioinformatics, and have been adapted for gene prediction, protein family classification, and a variety of other problems. Indeed, <a href="http://www.cambridge.org/gb/academic/subjects/life-sciences/genomics-bioinformatics-and-systems-biology/biological-sequence-analysis-probabilistic-models-proteins-and-nucleic-acids" rel="noreferrer">the treatise by Durbin, Eddy and colleagues</a> is one of the defining volumes in this field.</p>

<p>Although the details of each of these different applications of HMMs differ, the core mathematical model remains unchanged, and there are efficient algorithms for computing the probability of the observed sequence given the model, or (perhaps more useful) the most likely hidden sequence given the sequence of observed states.</p>

<p>Accordingly, it seems plausible that there could be a generic software library for solving HMMs. As far as I can tell that's not the case, and most bioinformaticians end up writing HMMs from scratch. Perhaps there's a good reason for this? (Aside from the obvious fact that it's already difficult, nigh impossible, to get funding to build and provide long-term support for open source science software. Academic pressures incentivize building a new tool that you can publish a paper on much more than building on and extending existing tools.)</p>

<p>Do any generic HMM solver libraries exist? If so, would this be tempting enough for bioinformaticians to use rather than writing their own from scratch?</p>

CC BY-SA 3.0
2017-06-02T10:56:09.667Z
You make it sound like “writing HMMs from scratch” is a huge endeavour. ;-) That said, of course having existing implementations of the relevant algorithms makes sense.
Konrad Rudolph
<hidden-markov-models><sequence-analysis>
Generic HMM solvers in bioinformatics?
# Generic HMM solvers in bioinformatics?

(Asked by: username_0 on 2017-06-02)

Hidden Markov models (HMMs) are used extensively in bioinformatics, and have been adapted for gene prediction, protein family classification, and a variety of other problems. Indeed, [the treatise by Durbin, Eddy and colleagues](http://www.cambridge.org/gb/academic/subjects/life-sciences/genomics-bioinformatics-and-systems-biology/biological-sequence-analysis-probabilistic-models-proteins-and-nucleic-acids) is one of the defining volumes in this field.

Although the details of each of these different applications of HMMs differ, the core mathematical model remains unchanged, and there are efficient algorithms for computing the probability of the observed sequence given the model, or (perhaps more useful) the most likely hidden sequence given the sequence of observed states.

Accordingly, it seems plausible that there could be a generic software library for solving HMMs. As far as I can tell that's not the case, and most bioinformaticians end up writing HMMs from scratch. Perhaps there's a good reason for this? (Aside from the obvious fact that it's already difficult, nigh impossible, to get funding to build and provide long-term support for open source science software. Academic pressures incentivize building a new tool that you can publish a paper on much more than building on and extending existing tools.)

Do any generic HMM solver libraries exist? If so, would this be tempting enough for bioinformaticians to use rather than writing their own from scratch?

**Tags:** hidden-markov-models, sequence-analysis
> **Comments:**
> **username_1**: You make it sound like “writing HMMs from scratch” is a huge endeavour. ;-) That said, of course having existing implementations of the relevant algorithms makes sense.  

---

## 3 answers

### Answer by username_3 on 2017-06-02. Score: 7 | Accepted answer

I would also recommend to take a look at [pomegranate](https://pomegranate.readthedocs.io/en/latest/), a nice Python package for probabilistic graphical models. It includes solvers for HMMs and much more. Under the hood it uses Cythonised code, so it's also quite fast.


---

### Answer by username_1 on 2017-06-02. Score: 5

There are certainly software libraries for working with HMMs. For a general-purpose implementation in C++, take a look at the [SeqAn HMM algorithms](http://docs.seqan.de/seqan/2.1.1/group_HmmAlgorithms.html).

For your purposes, i.e. “computing … the most likely hidden sequence given the sequence of observed states”, you’d invoke `viterbiAlgorithm` with your observed sequence and the HMM graph.

More fundamentally I think that most existing, mature implementations are probably found in the domain of signal processing, which has been using them longer than biology, and where most of the underlying theory was developed.


---

### Answer by username_2 on 2017-06-04. Score: 4

If I remember correctly Ewan Birney's Dynamite (a [compiler-compiler](https://en.wikipedia.org/wiki/Compiler-compiler)) as presented at [ISMB 1997](https://pdfs.semanticscholar.org/2345/f68bb0b2f079f9f201034da462d69a7817b1.pdf) had this functionality, there is also some code here on GitHub <https://github.com/birney/wise3> which at least mentions Dynamite. Suspect Ewan is too busy these days to work on this, although he has tweeted about blowing dust of his old Dynamite, sorry Dynamite code: <https://twitter.com/ewanbirney/status/788121636973142016>


---

