1

I have to create two functions that should allow me to open .genbank files and convert them into a .fasta file and the other way around. What I have for the moment is this:

def Convert(file, file1)
    handle_input=open('file', 'rU')
    handle_output=open('file1', 'w')
        while True:
        s=handle_input.readline()
        t=handle_output.write(s, '.genbank')
    print(t)
Convert('file.fas', 'file.genbank')

It is also probably not correct, but I have no idea what to do.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

1 Answers1

1

You can find a lot of documentation about this on the internet. Take a look here: https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

But to get you started: I assume that the 2 files will not be identical in the future because otherwise you can just copy the file.

I have couple of remarks.

1) Your loop while true will run till the end of time. Change it to something like

for line in handle_input:

2)Close your files when you are done:

handle_input.close() handle_output.close()

3)t=handle_output.write(s, '.genbank') Remove the '.genbank' argument

4) No need to do print(t)

Note: I havent tested this code so I could have made some small mistakes

BramV
  • 66
  • 9