forked from weka511/bioinformatics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBA10C.py
More file actions
54 lines (39 loc) · 1.94 KB
/
BA10C.py
File metadata and controls
54 lines (39 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (C) 2019 Greenweaves Software Limited
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# BA10C Implement the Viterbi Algorithm
from hmm import Viterbi
from helpers import create_hmm
if __name__=='__main__':
xs,alphabet,States,Transition,Emission=create_hmm(ext=4)
print ( Viterbi(xs,alphabet,States,Transition,Emission))
print ()
Transition = {
('A','A') : 0.641, ('A','B') : 0.359,
('B','A') : 0.729, ('B','B') : 0.271,
}
Emission = {
('A','x') : 0.117, ('A','y') : 0.691, ('A','z') : 0.192,
('B','x') : 0.097, ('B','y') : 0.42, ('B','z') : 0.483,
}
print (Viterbi('xyxzzxyxyy','xyz','AB',Transition,Emission))
Transition1 = {
('A','A') : 0.634, ('A','B') : 0.366,
('B','A') : 0.387, ('B','B') : 0.613,
}
Emission1 = {
('A','x') : 0.532, ('A','y') : 0.226, ('A','z') : 0.241,
('B','x') : 0.457, ('B','y') : 0.192, ('B','z') : 0.351,
}
print (Viterbi('zxxxxyzzxyxyxyzxzzxzzzyzzxxxzxxyyyzxyxzyxyxyzyyyyzzyyyyzzxzxzyzzzzyxzxxxyxxxxyyzyyzyyyxzzzzyzxyzzyyy',
'xyz','AB',Transition1,Emission1))
# AAAAAAAAAAAAAABBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBAAA
# AAAAAAAAAAAAAABBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBAAA