Bonjour, j'ai un programme a faire qui consiste a generer des sequence aleatoirement, les substituer de maniere aleatoire aussi et calculer la distance de jukes cantor. NOtre consigne est d'importer que random et utiliser randint , et math. Mais j'ai un petit soucis, je n'arrive pas à avoir les bonne valeur dans la liste data[1], je ne sais pas pourquoi il me dit que seq n'a pas de longueur...
pourriez vous m'aider :
#exo1
def alphabet(name):
if name=="nucleic":
alpha="acgt"
return alpha
if name=="protein":
alpha="ARNDBCEQZGHILKMFPSTWYV"
return alpha
if name=="iupac_nucleic":
alpha="ACGTRYSWKMBDHVN"
return alpha
if name=="iupac_protein":
alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
return alpha
#print (alphabet("nucleic"))
#exo2
def randseq(num, alphabet):
randseq=""
for i in range(num):
ind=random.randint(0, len(alphabet)-1)
randseq=randseq+alphabet[ind]
return randseq
#anuc=alphabet("nucleic")
#test=randseq(20,anuc)
#print (test,len(test))
#exo3
def hamming(seq1,seq2):
d=0
for i in range(0,len(seq1)):
if seq1[i]!=seq2[i]:
d=d+1
return d
#hamming("acgtacgt","aggtacga")
#exo4
def mutate(seq,num_subs):
seqmut=list(seq)
for i in range(num_subs):
ahboni=random.randint(0,(len(seq)-1))
seqmut[ahboni]=randseq(1,alphabet('nucleic'))
return hamming(seq,seqmut)
#h=mutate("acgtacg",5)
#print (h)
def experiments(le,su,nb):
v=[]
for i in range(nb):
seq=randseq(le,alphabet("nucleic"))
v.append(mutate(seq,su))
return v
#results=experiments(1000,1000,10)
#print (results)
#STAT
#1.5
def mean(data):
somme=0.0
moyenne=0.0
for i in list(data):
somme=somme+data[i]
moyenne=somme/len(data)
return moyenne
#1.6
def variance(data):
k = 0
for x in data:
k=k+ 1
if k == 1:
M = x
S = 0
else:
Mnext = M + (x - M) / k
S = S + (x - M)*(x - Mnext)
M = Mnext
return (S/(k-1))
#1.7
def std(data):
return math.sqrt(variance)
#1.8
def distanceJC69(mean,L):
d=(-3/4)*math.log(abs(1.0-((mean/L)*(4/3))))
return d
#v =[109,107,99,105,109]
#print (mean(v))
#L =700
#d = distanceJC69(mean,L)
#print(d)
#1.9
def generate(le,nb,xx):
seq1000nt=randseq(1000,alphabet('nucleic'))
listham=[]
listjuke=[]
listfinal=[]
for i in xx:
nb=i
seq_mutated=mutate(seq1000nt,nb)
hamming_distances=hamming(seq_mutated,seq1000nt)
juke=distanceJC69(nb,L)
listham.append(hamming_distances)
listjuke.append(juke)
listfinal.append(listham)
listfinal.append(listjuke)
return listfinal
v=[]
L =1000
R =10
x =list(range(100,10000,200))
data = generate(L,R,x)
import matplotlib.pyplot as plt
xx=[0]*len(x)
yy=[0]*len(x)
for i in range(len(x)):
xx[i]=x[i]
yy[i]=data[1][i]
plt.plot(xx,yy)
xxx=[0]*len(x)
yyy=[0]*len(x)
for i in range(len(x)):
xxx[i]=x[i]
yyy[i]=data[0][i]
plt.plot(xxx,yyy)
plt.show()