So I’m working on a problem where I have to find various string repeats after encountering an initial string, say we take ACTGAC so the data file has sequences that look like:
AAACTGACACCATCGATCAGAACCTGA
So in that string once we find ACTGAC then I need to analyze the next 10 characters for the string repeats which go by some rules. I have the rules coded but can anyone show me how once I find the string that I need, I can make a substring for the next ten characters to analyze. I know that str.partition function can do that once I find the string, and then the [1:10] can get the next ten characters.
Thanks!
You almost have it already (but note that indexes start counting from zero in Python).
The
partitionmethod will split a string intohead, separator, tail, based on the first occurence ofseparator.So you just need to take a slice of the first ten characters of the
tail:Python allows you to leave out the start-index in slices (in defaults to zero – the start of the string), and also the end-index (it defaults to the length of the string).
Note that you could also do the whole operation in one line, like this: