Compute the percent identity of a an alignment column.

  Define PID as the frequency of the most frequent nucleotide in the column.

  :param col:         an alignment column; a dictionary where keys are seq.
                      names and values are the nucleotide in the column for
                      that sequence.
  :param ignore_gaps: if True, do not count gaps towards the total number of
                      sequences in the column (i.e. the denominator of the
                      fraction).
  :raise ValueError: if the column contains only gaps.

def pid(col, ignore_gaps=False):
  """
  Compute the percent identity of a an alignment column.

  Define PID as the frequency of the most frequent nucleotide in the column.

  :param col:         an alignment column; a dictionary where keys are seq.
                      names and values are the nucleotide in the column for
                      that sequence.
  :param ignore_gaps: if True, do not count gaps towards the total number of
                      sequences in the column (i.e. the denominator of the
                      fraction).
  :raise ValueError: if the column contains only gaps.
  """
  hist = {}
  total = 0
  found_non_gap = False
  for v in col.values():
    if v == sequence.GAP_CHAR:
      if ignore_gaps:
        continue
      else:
        total += 1
    else:
      found_non_gap = True
      if v not in hist:
        hist[v] = 0
      hist[v] += 1
      total += 1
  if not found_non_gap:
    raise ValueError("Cannot determine PID of column with only gaps")
  return max(hist.values()) / float(total)