code: def calculate_tetra_zscore(filename):
      counts = (collections.defaultdict(int), collections.defaultdict(int),
                collections.defaultdict(int), collections.defaultdict(int))
      for rec in SeqIO.parse(filename, 'fasta'):
          for seq in [str(rec.seq).upper(),
                      str(rec.seq.reverse_complement()).upper()]:
              for base in ('G', 'C', 'T', 'A'):
                  counts[0][base] += seq.count(base)
              for i in range(len(seq[:-4])):
                  din, tri, tetra = seq[i:i+2], seq[i:i+3], seq[i:i+4]
                  counts[1][str(din)] += 1
                  counts[2][str(tri)] += 1
                  counts[3][str(tetra)] += 1
              counts[2][str(seq[-4:-1])] += 1
              counts[2][str(seq[-3:])] += 1
              counts[1][str(seq[-4:-2])] += 1
              counts[1][str(seq[-3:-1])] += 1
              counts[1][str(seq[-2:])] += 1
      tetra_exp = {}
      for tet in [tetn for tetn in counts[3] if tetra_clean(tetn)]:
          tetra_exp[tet] = 1. * counts[2][tet[:3]] * counts[2][tet[1:]] / \
                           counts[1][tet[1:3]]
      tetra_sd = {}
      tetra_z = {}
      for tet, exp in list(tetra_exp.items()):
          den = counts[1][tet[1:3]]
          tetra_sd[tet] = math.sqrt(exp * (den - counts[2][tet[:3]]) *
                                    (den - counts[2][tet[1:]]) / (den * den))
          try:
              tetra_z[tet] = (counts[3][tet] - exp)/tetra_sd[tet]
          except ZeroDivisionError:
              tetra_z[tet] = 1 / (counts[1][tet[1:3]] * counts[1][tet[1:3]])
      return tetra_z