forked from Shivi91/Rosalind-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
041_PDST.py
35 lines (27 loc) · 840 Bytes
/
041_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
35
#!/usr/bin/env python
'''
A solution to a ROSALIND bioinformatics problem.
Problem Title: Creating a Distance Matrix
Rosalind ID: PDST
Rosalind #: 041
URL: http://rosalind.info/problems/PDST/
'''
from numpy import zeros
from scripts import ReadFASTA
dna_list = [fasta[1] for fasta in ReadFASTA('data/rosalind_pdst.txt')]
# All seqences have the same length.
dna_len = len(dna_list[0])
M = zeros((len(dna_list),len(dna_list)))
for i in range(len(dna_list)):
for j in range(len(dna_list)):
if i < j:
for k in range(dna_len):
if dna_list[i][k] != dna_list[j][k]:
M[i][j] += 1.0/dna_len
elif i > j:
M[i][j] = M[j][i]
print M
with open('output/041_PDST.txt', 'w') as output_data:
output_data.write(' '.join(map(str,M[0])))
for row in range(1, len(dna_list)):
output_data.write('\n'+(' '.join(map(str,M[row]))))