Skip to content

Commit

Permalink
Catch zero-counts in codon frequency reporting
Browse files Browse the repository at this point in the history
If no codons counted, skip amino acid consensus summary.

Use dummy value of 0.000001 minimum freq for amino acids not observed in
sample, for cases where sample too small to pick up all amino acids at
least once.
  • Loading branch information
kbseah committed Jan 27, 2022
1 parent c70d9e6 commit 0319f9c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions porc_cod_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,15 @@ def ok_cod(acod):
codcons = {}
for cod in all_hist:
thres50 = sum([all_hist[cod][aa] for aa in all_hist[cod]])/2
candidate = [aa for aa in all_hist[cod] if all_hist[cod][aa] >= thres50]
if len(candidate) >= 1:
# concatenate if there is a 50-50 tie (unlikely except for singleton counts)
codcons[cod] = '_'.join(candidate)
if thres50 == 0: # no codons counted!
codcons[cod] = '-'
else:
codcons[cod] = '?'
candidate = [aa for aa in all_hist[cod] if all_hist[cod][aa] >= thres50]
if len(candidate) >= 1:
# concatenate if there is a 50-50 tie (unlikely except for singleton counts)
codcons[cod] = '_'.join(candidate)
else:
codcons[cod] = '?'

# Summary statistics on codon frequencies in alignments
with open(args.counts, 'w') as fh:
Expand Down Expand Up @@ -359,7 +362,7 @@ def ok_cod(acod):
# matrix for Weblogo plotting
if stop_tot[cod] > args.codon_threshold * mean(list(other_tot.values())):
outlines.append(
"\t".join([str(i)] + [str(float(all_hist[cod][aa])/aa_freq_d[aa]) for aa in aa_list]) + "\n")
"\t".join([str(i)] + [str(float(all_hist[cod][aa])/(aa_freq_d[aa] + 0.00001)) for aa in aa_list]) + "\n")
#outlines.append("%s" % i + "\t" + "\t".join([str(float(all_hist[cod][aa])) for aa in aa_list]) + "\n")
# else append zeroes (column not displayed by Weblogo)
else:
Expand Down

0 comments on commit 0319f9c

Please sign in to comment.