多说无益,直接上代码(其实就是懒的说)
import random
import numpy as np
S = ['A','G','C','T']
def createStr(n):
str = []
for i in range(30):
str.append(S[random.randint(0,3)])
return str
def calScore(str):
score =[]
for i in range(len(str)):
if str[i] in ('G','C'):
score.append(4)
else:
score.append(2)
return score
def divide(score,eTm,low,high):
div_point=[]
div_score=[]
i=j=0
total_len = len(score)
piece_s = 0
while j < total_len:
piece_s += score[j]
if j-i+1 < low: #长度不足下限
continue
else:
if j-i+1 == high: #长度达到上限
i = j+1
j = i
div_point.append(j) #添加分割点
div_score.append(piece_s)
pieces_s = 0
else: #长度在范围内
if piece_s >= eTm: #温度达到或超过期望值
i = j+1
j = i
div_point.append(j) #添加分割点
div_score.append(piece_s)
piece_s = 0
j += 1
return div_point,div_score
def std(div_score):
a = np.array(div_score)
mean = np.mean(a)
return np.sum((a-mean)**2)/len(a)
str = createStr(10)
score = calScore(str)