Ciao Giuseppe, per trovare la posizione di un oggetto in una sequenza (lista, stringa o altro) puoi usare il metodo '.index' delle liste:
dna_seq = 'ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT' target = 'GAATTCT' target_position = dna_seq.index(target) + 1 print('lunghezza pre-target: %d, post-target %d' % (target_position, len(dna_seq)-target_position)) Se vuoi iterare sulla sequenza per farci altro fai bene a usare 'enumerate', ma invece di costruirti la stringa di comparazione di volta in volta puoi prelevarla dalla stringa originale ad ogni ciclo: for position, gene in enumerate(dna_seq): if dna_seq[position:position+len(target)] == target: position += 1 # Aggiungiamo 1 perchè enumerate è 0-based print('lunghezza pre-target: %d, post-target %d' % (position, len(dna_seq)-position)) Federico 2017-11-26 10:42 GMT+01:00 Giuseppe Costanzi <giuseppecosta...@gmail.com>: > ciao carlo, > > si, interessante ma vorrei iterare la sequenza mano a mano, > > stavo pensando a qualcosa tipo > > next(iterator, default) > > grazie comunque > > > > On Sun, Nov 26, 2017 at 10:30 AM, Carlo Miron <mi...@python.it> wrote: > > On Sun, Nov 26, 2017 at 10:20 AM, Giuseppe Costanzi > > <giuseppecosta...@gmail.com> wrote: > > > >> ho una sequenza del tipo > >> ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT > >> scorrendola devo trovare una sequenza target GAATTC > >> ACTGATCGATTACGTATAGTA "GAATTC" TATCATACATATATATCGATGCGTTCAT > >> quindi dividere la sequenza da G, la prima lettera della sequenza > target, > >> e calcolarmi la lunghezza dei due frammenti risultanti > >> ACTGATCGATTACGTATAGTAG > >> e di questa > >> GAATTCTATCATACATATATATCGATGCGTTCAT > > > > qualcosa tipo > > > >>>> seq = "ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT" > >>>> target = "GAATTCT" > >>>> first, second = seq.split(target, 1) > >>>> first += target[1] > >>>> second = target[1:] + second > >>>> len(first), len(second) > > (22, 33) > > > > ? > > ㎝ > > > > -- > > |:**THE 🍺-WARE LICENSE** *(Revision ㊷)*: > > | <miron@🐍.it> wrote this mail. As long as you retain this > > | notice you can do whatever you want with this stuff. > > | If we meet some day, and you think this stuff is worth it, > > | you can buy me a 🍺 in return. —㎝ > > _______________________________________________ > > Python mailing list > > Python@lists.python.it > > https://lists.python.it/mailman/listinfo/python > _______________________________________________ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python >
_______________________________________________ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python