I have created a function that will be part of a small working script with files but I can not get some characters that I am identifying in this function. By the error messages of the shell I deduce that it is a matter of variables that are not being correctly identified. This is what I have at the moment:
import os
os.chdir() #direccion del directorio de ficheros
def numero_bases(fichero):
A = 0
T = 0
C = 0
G = 0
with open(fichero) as f:
lineas = f.readlines()
for l in lineas:
if not l.startswith('>'): #esto lo he puesto para que no lea en lineas que empiezan por ('>') que son el encabezado de los registros del fichero, pero no estoy seguro si es la mejor forma para ello.
for base in l:
if base == 'A':
A += 1
elif base == 'T':
T += 1
elif base == 'G':
G += 1
elif base == 'C':
C += 1
return A,T,C,G
while True:
fichero = input('Introduzca nombre del fichero FASTA(q para salir):\n')
if fichero == 'q':
break
print(numero_bases(fichero), A, T,C,G)
What I am getting is an error that the variables A, T, C, G do not exist, but sometimes I get, after modifying the site of the variables, a result of 0, that is to say that it is not counting .
Any idea what could be wrong?