KeyError: '> R ' in Google Python Colab

I copied the following code from a data visualization tutorial in Python, but it doesn't perform properly, warning KeyError as seen in the title. Can anyone help me? Is there something wrong there?

entrada = open("/bacteria.fasta").read()
saida = open("/bacteria.html", "w")

cont = {}

for i in ['A', 'T', 'C', 'G']:
    for j in ['A', 'T', 'C', 'G']:
        cont[i+j] = 0

entrada = entrada.replace("\n", "")

for k in range(len(entrada)-1):
    cont[entrada[k]+entrada[k+1]] += 1

# html

i = 1
for k in cont:
    transparencia = cont[k]/max(cont.values())
    saida.write("<div style='width:100px; border:1px solid #111; height:100px; float:left; background-color:rgba(0,0,255,"+str(transparencia)+"')></div>")

saida.close()

The log says the following:

KeyError                                  Traceback (most recent call last)
<ipython-input-9-e27a0dec51b4> in <module>()
     13 
     14 for k in range(len(entrada)-1):
---> 15         cont[entrada[k]+entrada[k+1]] += 1
     16 
     17 # html

KeyError: '>R'
Author: lina dias, 2020-03-19

1 answers

I recently conducted the same study,and managed to solve the same problem by opening the file " bacteria.fasta " with Sublime Text software and delete the first two lines that do not have information regarding the genetic code. After saving, the error did not appear again.

Att.

 2
Author: Rafael Pereira Carniato, 2020-03-25 00:07:07