I'm currently developing the small and the large database functions separately and I wonder why in the large one it does not keep track of the STR repetitions. Here is my code from both functions:
def slist(data, seq):
seqlen = len(str(seq))
# AGATC, AATG, TATC
runlist = [0, 0, 0]
maxlist = [0, 0, 0]
tempmax = [0, 0, 0]
# Iterate throught substrings of length 4
i = 0
j = 4
# Position variable
while j < seqlen:
# Assign the temporary maxes
tempmax[0] = runlist[0]
tempmax[1] = runlist[1]
tempmax[2] = runlist[2]
# Check the substrings
if seq[i:j + 1] == "AGATC":
runlist[0] += 1
runlist[1] = 0
runlist[2] = 0
i += 5
j += 5
elif seq[i:j] == "AATG":
runlist[1] += 1
runlist[0] = 0
runlist[2] = 0
i += 4
j += 4
elif seq[i:j] == "TATC":
runlist[2] += 1
runlist[0] = 0
runlist[1] = 0
i += 4
j += 4
else:
i += 1
j += 1
# Check the maxes
if tempmax[0] < runlist[0]:
maxlist[0] = runlist[0]
if tempmax[1] < runlist[1]:
maxlist[1] = runlist[1]
if tempmax[2] < runlist[2]:
maxlist[2] = runlist[2]
return maxlist
What this code actually does is keeping track of the STR repetitions while moving two cursors that create substrings, and updating each time the max number of repetitions if necessary.
Here is the large function:
def largelist(data, seq): # PROBLEMAS EN EL COMPUTO TOTAL
seqlen = len(str(seq))
# AGATC, TTTTTTCT, AATG, TCTAG, GATA, TATC, GAAA, TCTG
runlist = [0, 0, 0, 0, 0, 0, 0, 0]
maxlist = [0, 0, 0, 0, 0, 0, 0, 0]
tempmax = [0, 0, 0, 0, 0, 0, 0, 0]
# Iterate throught substrings of length 4
i = 0
j = 0
while j < seqlen:
# Assign the temporary maxes
tempmax[0] = runlist[0]
tempmax[1] = runlist[1]
tempmax[2] = runlist[2]
tempmax[3] = runlist[3]
tempmax[4] = runlist[4]
tempmax[5] = runlist[5]
tempmax[6] = runlist[6]
tempmax[7] = runlist[7]
s = seq[i: j + 4]
# Check the substrings
if seq[i:j+5] == "AGATC":
runlist[0] += 1
runlist[1] = 0
runlist[2] = 0
runlist[3] = 0
runlist[4] = 0
runlist[5] = 0
runlist[6] = 0
runlist[7] = 0
i += 5
j += 5
elif seq[i:j+8] == "TTTTTTCT":
runlist[1] += 1
runlist[0] = 0
runlist[2] = 0
runlist[3] = 0
runlist[4] = 0
runlist[5] = 0
runlist[6] = 0
runlist[7] = 0
i += 8
j += 8
elif seq[i:j+4] == "AATG":
runlist[2] += 1
runlist[0] = 0
runlist[1] = 0
runlist[3] = 0
runlist[4] = 0
runlist[5] = 0
runlist[6] = 0
runlist[7] = 0
i += 4
j += 4
elif seq[i:j+5] == "TCTAG":
runlist[3] += 1
runlist[0] = 0
runlist[1] = 0
runlist[2] = 0
runlist[4] = 0
runlist[5] = 0
runlist[6] = 0
runlist[7] = 0
i += 5
j += 5
elif seq[i:j+4] == "GATA":
runlist[4] += 1
runlist[0] = 0
runlist[1] = 0
runlist[2] = 0
runlist[3] = 0
runlist[5] = 0
runlist[6] = 0
runlist[7] = 0
i += 4
j += 4
elif seq[i:j+4] == "TATC":
runlist[5] += 1
runlist[0] = 0
runlist[1] = 0
runlist[2] = 0
runlist[3] = 0
runlist[4] = 0
runlist[6] = 0
runlist[7] = 0
i += 4
j += 4
elif seq[i:j+4] == "GAAA":
runlist[6] += 1
runlist[0] = 0
runlist[1] = 0
runlist[2] = 0
runlist[3] = 0
runlist[4] = 0
runlist[5] = 0
runlist[7] = 0
i += 4
j += 4
elif seq[i:j+4] == "TCTG":
runlist[7] += 1
runlist[0] = 0
runlist[1] = 0
runlist[2] = 0
runlist[3] = 0
runlist[4] = 0
runlist[5] = 0
runlist[6] = 0
i += 4
j += 4
else:
i += 1
j += 1
# Check the maxes
if tempmax[0] < runlist[0]:
maxlist[0] = runlist[0]
if tempmax[1] < runlist[1]:
maxlist[1] = runlist[1]
if tempmax[2] < runlist[2]:
maxlist[2] = runlist[2]
if tempmax[3] < runlist[3]:
maxlist[3] = runlist[3]
if tempmax[4] < runlist[4]:
maxlist[4] = runlist[4]
if tempmax[5] < runlist[5]:
maxlist[5] = runlist[5]
if tempmax[6] < runlist[6]:
maxlist[6] = runlist[6]
if tempmax[7] < runlist[7]:
maxlist[7] = runlist[7]
return maxlist
It was intended to be the same idea but I don't know what happens as it only returns very little values:
python dna.py databases/large.csv sequences/8.txt
[0, 0, 1, 1, 1, 1, 1, 3]
When it had to be much larger, as Ginny's sequence does not match with this one.
Thanks!
DRY code
Don't Repeat Yourself