-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdst.py
34 lines (27 loc) · 854 Bytes
/
pdst.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
32
33
34
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @File : pdst.py
# @Date : 18-10-29
# @Author : luyang(luyang@novogene.com)
import numpy as np
from hamm import hamm
from module.readfasta import readfasta
def main():
file = 'input/rosalind_pdst.txt'
fasta_seq_dict = readfasta(file)
seq = [''] * len(fasta_seq_dict)
i = 0
for keys in fasta_seq_dict.keys():
seq[i] = str(fasta_seq_dict[keys])
i = i + 1
dist_matrix = np.zeros([len(seq), len(seq)])
for i in range(len(seq)):
for j in range(i + 1, len(seq)):
dist_matrix[i, j] = hamm(seq[i], seq[j]) / len(seq[i])
dist_matrix[j, i] = dist_matrix[i, j]
for i in range(len(seq)):
for j in range(len(seq)):
print(dist_matrix[i, j], end=' ')
print('')
if __name__ == "__main__":
main()