示例#1
0
from python.util import getHammingDistance, readDNAs
from python.matrix import Matrix

__author__ = 'ekarpov'


def p_distance(s, t):
    return getHammingDistance(s, t) / len(s)


data = readDNAs()
matrix = Matrix(len(data), default=float(0), format="%.5f")

for i in range(len(data)):
    for j in range(len(data)):
        distance = p_distance(data[i][1], data[j][1])
        matrix[i, j] = distance

print(matrix)
示例#2
0
from python import util

__author__ = 'ekarpov'

data = util.readDNAs()
s1 = data[0][1]
s2 = data[1][1]

trans = 0
trav = 0
for i in range(len(s1)):
    if s1[i] != s2[i]:
        if s1[i] == 'A' and s2[i] == 'G' or s1[i] == 'G' and s2[i] == 'A':
            trans += 1
        elif s1[i] == 'C' and s2[i] == 'T' or s1[i] == 'T' and s2[i] == 'C':
            trans += 1
        else:
            trav += 1

print(trans / trav)