From c70d9e6497c3f03ad6cd0f66d771f08596425620 Mon Sep 17 00:00:00 2001 From: Kwee Boon Brandon Seah Date: Fri, 21 Jan 2022 09:39:01 +0100 Subject: [PATCH] Fix bug zero counts when codon not observed --- porc_cod_usage.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/porc_cod_usage.py b/porc_cod_usage.py index 77491e1..d87cf9e 100755 --- a/porc_cod_usage.py +++ b/porc_cod_usage.py @@ -324,13 +324,17 @@ def ok_cod(acod): fh.write("\t".join([ # header line 'codon','std_aa','put_aa','cod_count','cod_frac','cons_pos']) + '\n') for cod in codon_d: + cons_col = 0 + if cod in cod_d or cod in acod_d: + # in case the codon was not observed at all (possible for true stops) + cons_col = len(dict(cod_d, **acod_d)[cod]) # number of conserved columns in HMMer alignment used for AA prediction ll = [str(i) for i in [ cod, # codon sequence codon_d[cod], # amino acid in the standard genetic code (for reference) codcons[cod], # 50% consensus guess for this AA cod_count_d[cod], # counts of this codon in HMMer alignments (round(100*float(cod_count_d[cod])/cod_tot, 4)), # as percentage of total codon counts - len(dict(cod_d, **acod_d)[cod]) # number of conserved columns in HMMer alignment used for AA prediction + cons_col # number of conserved columns in HMMer alignment used for AA prediction ]] fh.write("\t".join(ll) + '\n')