I was wondering, if I had a string that was read from a text file, what would be the most efficient way of splitting it into groups of 5 characters? For example:
I have a text file called dna.txt, and its contents are:
>human
ACCGTGAAAAACGTGAGTATA
>mouse
ACCAAAAGTGTAT
I then have a Python script that will store the 2nd and 4th lines of the text file.
import linecache
f = open("dna.txt")
sequence_1 = linecache.getline('dna.txt', 2)
sequence_2 = linecache.getline('dna.txt', 4)
f.close()
The goal is for the program to print out:
>human
ACCGT
GAAAA
ACGTG
AGTAT
A
>mouse
ACCAA
AAGTG
TAT
Like I said before, I've been trying to come up with an efficient way of breaking the 2 strings, but with no luck. Help would be much appreciated, thanks!