1. 程式人生 > >用python獲取複雜度的P值

用python獲取複雜度的P值

#coding:utf-8
import os
import matplotlib.pyplot as plt
plt.switch_backend('agg')

path = os.getcwd()
f_fasta = open(path+'/fac_cpx.txt','r')
list_data = []
for line in f_fasta.readlines():
	line = line.strip('\n')
	list_data.append(line)
f_fasta.close()

#print(len(list_data))
List_Num = []
for i in range(len(list_data)):
	a_seq = list_data[i]
	A_seq = a_seq.split(',')
	A_seq = list(map(int,A_seq))
	List_Num.append(A_seq)

list_box_1_5 = []
for j in range(5):
	list_box = []
	for i in range(len(List_Num)):
		list_box.append(List_Num[i][j])
	list_box_1_5.append(list_box)

#list_box_1_5 includes 5 types ,and each has 4226

#LCSD = [16,66,91,93,92]
LCSD = [16,49,70,78,81]
#a = [[1,1,3,4,5],[6,1,1,1,5],[3,2,7,8,9]]
def P_value(a):
    P = []
    for j in range(len(LCSD)):
        a_1 =[]
        for i in range(len(a[j])):
            if LCSD[j] >= a[j][i]:
                a_1.append(a[j][i])
        p = round(len(a_1)/len(a[j]),3)
        P.append(p)
    return P


P = P_value(list_box_1_5)
print(P)