title: Faster way of calculating the percentage of identical sites in alignment using biopython
body: <p>I developed the following code to calculate the number of identical sites in an alignment. Unfortunately the code is slow, and I have to iterate it over hundreds of files, it takes close to 12 hours to process more than 1000 alignments, meaning that something ten times faster would be appropriate. Any help would be appreciated:</p>
  
  <pre><code>import os
  from Bio import SeqIO
  from Bio.Seq import Seq
  from Bio import AlignIO
  from Bio.SeqRecord import SeqRecord
  from Bio.Alphabet import generic_dna
  from Bio.Align import MultipleSeqAlignment
  import time
  
  a = SeqRecord(Seq("CCAAGCTGAATCAGCTGGCGGAGTCACTGAAACTGGAGCACCAGTTCCTAAGAGTTCCTTTCGAGCACTACAAGAAGACGATTCGCGCGAACCACCGCAT", generic_dna), id="Alpha")
  b = SeqRecord(Seq("CGAAGCTGACTCAGTGGGCGGAGTCACTGAAACTGGAGCACCAGTTCCTCAGAGTCCCCTTCGAGCACTACAAGAAGACAATTCGTGCGAACCACCGCAT", generic_dna), id="Beta")
  c = SeqRecord(Seq("CGAAGCTGACTCAGTTGGCAGAATCACTGAAACTGGAGCACCAGTTCCTCAGAGTCCCCTTCGAGCACTACAAGAAGACGATTCGTGCGAACCACCGCAT", generic_dna), id="Gamma")
  d = SeqRecord(Seq("CGAAGCTGACTCAGTTGGCAGAGTCACTGAAACTGGAGCACCAGTTCCTCAGAGTCCCCTTCGAGCACTACAAGAAGACGATTCGTGCGAACCACCGCAT", generic_dna), id="Delta")
  e = SeqRecord(Seq("CGAAGCTGACTCAGTTGGCGGAGTCACTGAAACTGGAGCACCAGTTCCTCAGAGTCCCCTTCGAGCACTACAAGAAGACGATTCGTGCGAACCACCGCAT", generic_dna), id="Epsilon")
  
  align = MultipleSeqAlignment([a, b, c], annotations={"tool": "demo"})
  
  start_time = time.time()
  if len(align) != 1:
      for n in range(0,len(align[0])):
          n=0
          i=0
          while n&lt;len(align[0]):    #part that needs to be faster
              column = align[:,n]
              if (column == len(column) * column[0]) == True:
                  i=i+1
              n=n+1
  
      match = float(i)
      length = float(n)
      global_identity = 100*(float(match/length))
      print(global_identity)
  
  print("--- %s seconds ---" % (time.time() - start_time))
  </code></pre>