-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathba10b.py
31 lines (24 loc) · 893 Bytes
/
ba10b.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @File : ba10b.py
# @Date : 18-10-29
# @Author : luyang([email protected])
import numpy as np
def main():
file = 'input/rosalind_ba10b.txt'
with open(file) as f:
lines = f.readlines()
observation_sequence = lines[0].strip()
observation = lines[2].strip().split('\t')
hidden_sequence = lines[4].strip()
hiddens = lines[6].strip().split('\t')
start_probability = 1
probability = start_probability
emission_matrix = np.zeros([len(hiddens), len(observation)])
for i in range(len(hiddens)):
emission_matrix[i:, ] = lines[i + 9].strip().split('\t')[1:]
for i in range(len(observation_sequence)):
probability *= emission_matrix[hiddens.index(hidden_sequence[i]), observation.index(observation_sequence[i])]
print(probability)
if __name__ == "__main__":
main()