I’m trying to find a specific sequence in a list containing dna code (letters already converted to numbers E.g. A=1,T=4).
E.g.:
dna = [1,4,3,2,3,2,1,2,3,2,4,2,1,2,2,2,2,4,1,3,4]
Look at the first 3 items (1,4,3) and check if the items are 2,2,4. if True, then get the position (in this 0,1,2 would be False). Else look at the next 3 items 2,3,2 and repeat. Do this for all positions in dna []
My approach was a for i in range loop which should give me the position dna[15,16,17] but it won’t...
A,G,C,U = 1,2,3,4
dna = []
for _ in range(200): #just generated random 200 numbers as example dna
code = random.randrange(1,5,1)
dna.append(code)
l = int(len(dna)/3) #splits search into 3
for i in range(l):
k = i*3
if dna[k] == 2:
if dna[k+1] == 2:
if dna[k+2] == 4:
m += 1
print('GGU at:', dna[i], dna[i+1], dna[k+2], 'found:', m)
I have tried so many different ideas from similar questions on SOF but most don’t care for the order of the Numbers... sometimes the pseudo position would be the item 2,2,4, sometimes it wouldn’t find any matches. All help would be appreciated!