Created
June 15, 2021 01:04
-
-
Save dwinter/d1630b8f182e03db595da4ec2501a722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def base_consensus(alignment, base_index): | |
""" """ | |
# get the bases at this position, store in case we want to come back | |
# and assign the first one as th winner | |
#n_seqs = len(alignment) | |
bases = [r[base_index].upper() for r in alignment] | |
base_c = Counter(bases) | |
max_count = max(base_c.values()) | |
most_common_base = [b for b in base_c.items() if b[1] == max_count] | |
if len(most_common_base) == 1: | |
return(most_common_base[0][0]) | |
tied_bases = [base for base,count in most_common_base] | |
#this is where the logic of choosing the best base goes | |
return(tied_bases[0]) | |
def make_consensus(alignment): | |
new_string = "" | |
for base_index in range(alignment.get_alignment_length()): | |
new_string += base_consensus(alignment, base_index) | |
return("".join(new_string)) | |
#alignment = AlignIO.read("coi_ali.fna", "fasta") | |
#make_consensus(alignment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment