-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathba10a.py
More file actions
28 lines (22 loc) · 802 Bytes
/
ba10a.py
File metadata and controls
28 lines (22 loc) · 802 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @File : ba10a.py
# @Date : 18-10-29
# @Author : luyang(luyang@novogene.com)
import numpy as np
def main():
file = 'input/rosalind_ba10a.txt'
with open(file) as f:
lines = f.readlines()
hidden_sequence = lines[0].strip()
hiddens = lines[2].strip().split('\t')
start_probability = 0.5
probability = start_probability
transition_matrix = np.zeros([len(hiddens), len(hiddens)])
for i in range(len(hiddens)):
transition_matrix[i:, ] = lines[i + 5].strip().split('\t')[1:]
for i in range(0, len(hidden_sequence) - 1):
probability *= transition_matrix[hiddens.index(hidden_sequence[i]), hiddens.index(hidden_sequence[i + 1])]
print(probability)
if __name__ == "__main__":
main()