-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdna.py
110 lines (91 loc) · 2.78 KB
/
dna.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from random import randint
class DNA():
# this metaclass is here to implement getters
# and setters for these static variables
dna_chain= ""
rna_chain = ""
protein_chain = ""
dna_complement = ""
gc_rate = 0
codon_frequency=0
protein_mass = 0
# generate DNA Sequence from length
@classmethod
def generate_dna(cls,length: int):
ADN = ''
for i in range(0,length):
ADN+='ACGT'[randint(0,3)]
cls.dna_chain = ADN
@classmethod
def translate_to_rna(cls):
cls.rna_chain = cls.dna_chain.replace("T", "U")
@classmethod
def rna_to_prot(cls):
from .rna_to_acid import RNA_to_acido_dic
rna = cls.rna_chain
index = 0
l = []
while index <= len(rna)-1:
if(len(rna[index:index+3]) == 3):
l.append(RNA_to_acido_dic[rna[index:index+3]])
index += 3
prot=''
# print(l)
for ele in l:
prot += ele+' '
cls.protein_chain = prot
@classmethod
def get_dna_complement(cls):
adn = cls.dna_chain
dna_comp=''
conversion_dict = {
'A':'T',
'T':'A',
'C':'G',
'G':'C'
}
for x in adn:
dna_comp += conversion_dict[x]
cls.dna_complement = dna_comp
@classmethod
def taux_gc(cls):
adn = cls.dna_chain
gc= int((adn.count("C")+adn.count("G")) / len(adn) * 100)
cls.gc_rate=gc
@classmethod
def taux_codons(cls):
if cls.rna_chain == "":
cls.translate_to_rna()
from .rna_to_acid import RNA_to_acido_dic
rna = cls.rna_chain
freq = 0
for index in range(0,len(rna),3):
if index+3 < len(rna) and RNA_to_acido_dic[rna[index:index+3]] != "---":
freq= freq+1
cls.codon_frequency = freq
@classmethod
def masse(cls):
from .acid_mass import amino_acid_abr, mass_amino_acid
prot = cls.protein_chain.replace(' ','')
if (len(prot)>0):
index = 0
l = []
while index <= len(prot)-1:
if(len(prot[index:index+3]) == 3):
l.append(amino_acid_abr[prot[index:index+3]])
index += 3
prot_abr = ""
for ele in l:
prot_abr += ele
mass = 0
for x in prot_abr:
mass+=mass_amino_acid[x]
cls.protein_mass = mass
# print(cls.MASSE)
# else:
# cls.show_popup("vous devez creer le Proteine")
# DNA.generate_dna(31)
# DNA.taux_codons()
# DNA.rna_to_prot()
# print(DNA.protein_chain)
# print(DNA.codon_frequency)