title: BioPython consensus sequence with gaps coded as 'N' and polymorphisms as ambiguities
body: <p>I am trying to write code to get a consensus sequence for each of the 100+ files of individual fasta alignments in a folder. To start I just wanted to get the consensus for one sequence (then I will use a for loop to process all), but I am having trouble with the alphabet of the consensus.  My test fasta alignment is:</p>
  
  <pre><code>&gt;seq1
  ACGTACGATCGTTACTCCTA
  &gt;seq2
  ACGTACGA---TTACTCGTA
  </code></pre>
  
  <p>and what I want the consensus to look like is:</p>
  
  <pre><code>ACGTACGANNNTTACTCSTA
  </code></pre>
  
  <p>I would like any column that contains a gap to be represented by 'N' and any column without 100% identical nucleotides to be represented by ambiguity codes.</p>
  
  <p>My code that doesn't work is:</p>
  
  <pre><code>from Bio import AlignIO
  from Bio.Align import AlignInfo
  from Bio.Alphabet import IUPAC, Gapped
  alphabet = Gapped(IUPAC.ambiguous_dna)
  
  alignment = AlignIO.read(open("fasta_align_for_consensus.fa"), "fasta")
  summary_align = AlignInfo.SummaryInfo(alignment)
  consensus = summary_align.gap_consensus(threshold = 1.0, ambiguous = 'N', consensus_alpha  \
  = alphabet, require_multiple = 2)
  </code></pre>
  
  <p>The object 'ambiguous' only takes a string and places an 'N' in any place in the consensus where there is a polymorphism in the alignment, which I can't seem to work around.  Any suggestion on how to correct this would be greatly appreciated.
  Thanks!</p>