Skip to content Skip to sidebar Skip to footer

Python: Multiple Consensus Sequences

starting from a list of dna sequences, I must have in return all the possible consensus (the resulting sequence with the highest nucleotide frequency in each position) sequences.

Solution 1:

I'm sure there are better ways but this is a simple one:

bestseqs = [[]]
for i in range(n):
    d = {N:profile[N][i] for N in ['T','G','C','A']}
    m = max(d.values())
    l = [N for N in ['T','G','C','A'] if d[N] == m]
    bestseqs = [ s+[N] for N in l for s in bestseqs ]

for s in bestseqs:
    print(''.join(s))

# output:
ATGGAACT
ATGCAACT

Post a Comment for "Python: Multiple Consensus Sequences"