def aa_counts(aln, weights=None, gap_chars='<STR_LIT>'):
if weights is None:<EOL><INDENT>counts = Counter()<EOL>for rec in aln:<EOL><INDENT>seq_counts = Counter(str(rec.seq))<EOL>counts.update(seq_counts)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if weights == True:<EOL><INDENT>weights = sequence_weights(aln)<EOL><DEDENT>else:<EOL><INDENT>assert len(weights) == len(aln), (<EOL>"<STR_LIT>"<EOL>% (len(weights), len(aln)))<EOL><DEDENT>counts = defaultdict(float)<EOL>for col in zip(*aln):<EOL><INDENT>for aa, wt in zip(col, weights):<EOL><INDENT>counts[aa] += wt<EOL><DEDENT><DEDENT><DEDENT>for gap_char in gap_chars:<EOL><INDENT>if gap_char in counts:<EOL><INDENT>del counts[gap_char]<EOL><DEDENT><DEDENT>return counts<EOL>
Calculate the amino acid frequencies in a set of SeqRecords.

    Weights for each sequence in the alignment can be given as a list/tuple,
    usually calculated with the sequence_weights function. For convenience, you
    can also pass "weights=True" and the weights will be calculated with
    sequence_weights here.