Dec-30-2019, 05:46 AM
I am trying to take a string of DNA bases and partition the string into codons followed by replacing each codon one by one with a list of codons while keeping the rest of the sequence untouched.
For instance,
If a DNA sequence is ATG GCC
and the possible codons for replacement are TCC GGG
the possible combinations would be TCC GCC, GGG GCC, ATG TCC and ATG GGG.
So far i've written some code to Splice the DNA sequence into codons
I'm not sure if I can now use Itertools to try to replace each codon with my list or if I need to take an alternative approach?
For instance,
If a DNA sequence is ATG GCC
and the possible codons for replacement are TCC GGG
the possible combinations would be TCC GCC, GGG GCC, ATG TCC and ATG GGG.
So far i've written some code to Splice the DNA sequence into codons
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from itertools import zip_longest def grouper(iterable, n, fillvalue = 'x' ): args = [ iter (iterable)] * n ans = list (zip_longest(fillvalue = fillvalue, * args)) t = len (ans) for i in range (t): ans[i] = "".join(ans[i]) return " " .join(ans) s = "ccggcgaacccgggcaccaccgccacgtacctc" k = 3 Splice = grouper(s, k) print (Splice) |