@fransua Thank you so much!!!
and i have a one question!!
if i will add some options, how i can do?
ex)
if CAT repeat < 4 times ---- boy
if CAT repeat > 4 times ---- gilr
if CAT repeat > 5 times ---- blue eye gilr
if CAT repeat > 6 times ---- black eye gilr
if CAT repeat > 7 times ---- brown eye gilr
(ALSO, JUST EXAMPLE!!!!)
Regular expressions would be ideal for dealing with this.
import re
patt='(CAT)+'
string='asdsaCATCATCATsdaCATasa'
p=re.compile(patt)
replen=[sp.end()-sp.start() for sp in p.finditer(string)]
print max(replen)/(len(patt)-3)
I think the question is, "was CAT repeated 4 times in a row?". That would be useful for counting tandem repeats. Using that definition, Aleksandr's code which reports 4 for "CATGGGGGCATCATCAT" wouldn't give the correct answer. Here's quick and dirty code to get the maximum number of consecutive repeats for a string:
s="AGTCATCATGTGTAAGCGTAG*CATCATCATCATCATCATCATCATCATCAT*CCGTGAGTCAGAGA"
search = "CAT"
N = len(s)
n = len(search)
x = 0
reps = 0
last=(-1*n)-1
maxreps=0
while x > -1:
x = s.find( search, x)
print x
if x>-1:
if x==last+n:
reps += 1
if reps>maxreps:
maxreps=reps
else:
reps=1
maxreps=1
last = x
x=x+n
print maxreps # returns 10
print maxreps>4 # returns True
Is there any particular reason why you want to use Python for this? If you're dealing with Repeats, RepeatMasker is the way to go. It will detect short tandem repeats like the one you have, and tell you just how many instances of the repeated element are found.
Phython? No such language, so far as I know :)
@Takeo, welcome to Biostars.org