Python
Python
Ejercicios:
“PYTHON”
ESTUDIANTES:
CUSCO – PERÚ
2020
1
1.
2.
3.
2
4.
5.
6.
3
7.
8.
2. Print(complemento inverso,("ATCGCGAT")
3. Print(totalduplest ("ATATATATACG")
5. print(puedeser("GAT"))
6. print(counter("AUGATATATATA"))
7. Print (impresion("ttccgatcaatg","tjs"))
4
8. print(Busqueda("aagctaaatgctaatcgtacaagc",4))
Proy 1.
class Myseq:
def __len__(self):
return len(self.seq)
def __str__(self):
return self.seq
def sacarSecuenciaBiotipo(self):
return self.seq_type
def muestraInfoSecuencia(self):
print("Secuencia: "+self.seq+" biotype "+self.seq_type)
def validar(self):
alp = self.alfabeto()
res = True
i=0
while i < len(self.seq) and res:
if self.seq[i] not in alp:
res = False
else:
i+=1
return res
5
def transcripcion(self):
if(self.seq_type == "ADN"):
return Myseq(self.seq.replace("T","U"),"ARN")
else:
return None
def reverse_comp(self):
if(self.seq_type != "ADN"):
return None
comp = ""
for c in self.seq:
if(c == 'A'):
comp="T"+comp
elif(c == "T"):
comp="A"+comp
elif(c == "G"):
comp="C"+comp
elif(c == "C"):
comp="G"+comp
def traducirCodon(cod,a):
if a in tc:
return tc[a]
else:
return None
6
return None
seq_aa=""
for pos in range(iniPos, len(self.seq)-2,3):
cod = self.seq[pos:pos+3]
a = str(self.translate_codon(cod))
seq_aa=seq_aa+a
return Myseq(seq_aa, "PROTEIN")
class ADN(Myseq):
def __init__ (self, seq, seq_type = "ADN"):
self.seq = seq.upper()
self.seq_type = seq_type
class ARN(Myseq):
def __init__ (self, seq, seq_type = "ARN"):
self.seq = seq.upper()
self.seq_type = seq_type
class Proteina(Myseq):
def __init__ (self, seq, seq_type = "PROTEIN"):
self.seq = seq.upper()
self.seq_type = seq_type
secuenciaA =
ADN("ATGTGATAAGAATAGAATGCTGAATAAATAGAATGACAT")
secuenciaB = ARN("MKVVLSVQERSVVSLL","PROTEIN")
print(secuenciaA.validar(),secuenciaB.validar())
print(secuenciaA)
7
Proy 2.
import random
def genADN():
DNA=['A','C','G','T']
tamaADN=len(DNA)
print(tamaADN)
for num in range(2):
ADN=random.choices(DNA,k=50)
print("Primer ADN: ",ADN)
mutati=input("Desea Ingresar mutaciones?: ")
if mutati=="1":
mutaciones =int(input("Ingrese la cantidad de mutaciones: "))
for i in range(mutaciones):
nucleotidos=input("Ingrese el nucleotido: ")
ADN.append(nucleotidos)
print("El nuevo ADN es:",ADN)
elif mutati=="0":
boolremo=input("Desea remover un compuesto?: ")
if boolremo=="1":
remover=int(input("Ingrese la cantidad a remover: "))
for i in range(remover):
nucleoremove=input("Ingrese el nucleotido: ")
ADN.remove(nucleoremove)
print("El nuevo ADN es:",ADN)
elif boolremo=="0":
replacesADN=input("Desea reemplazar algun compuesto: ")
if replacesADN=="1":
reemplace=int(input("Ingrese la cantidad a remover: "))
for i in range(reemplace):
valorre=input("Ingrese que compuesto reemplazar: ")
nucleoreplace=input("Ingrese el nucleotido: ")
for n,i in enumerate(ADN):
if i==valorre:
ADN[n]= nucleoreplace
else:
print("Valor no encontrado")
print("El nuevo ADN es:",ADN)
elif replacesADN=="0":
8
print("El ADN es: ",ADN)
print(genADN())