Skip to content

Instantly share code, notes, and snippets.

@christopher-beckham
Last active August 29, 2015 14:01
Show Gist options
  • Save christopher-beckham/accbf1da3a735e1de896 to your computer and use it in GitHub Desktop.
Save christopher-beckham/accbf1da3a735e1de896 to your computer and use it in GitHub Desktop.
Find consensus of .aln file
from sys import stdin
import sys
N = 10 # number of sequences
body = stdin.read()
body = body.split('\n')
body = body[3:len(body)-2]
final_body = []
for elem in body:
elem = elem.split()
if len(elem) > 1:
final_body.append(elem[1])
split_body = []
for i in range(0, len(final_body), N+1):
split_body.append( final_body[i:i+N] )
print ">consensus_seq"
for body in split_body:
final_seq = []
for i in range(0, len(body[0])):
nucs = []
for j in range(0, len(body)):
nucs.append( body[j][i] )
final_seq.append( max(set(nucs), key=nucs.count) )
print "".join(final_seq).replace('-','')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment