code: def collapse_to_consensus(seqrecords, strict=False, do_iron=True):
      level = 0
      name = seqrecords[0].id
      if hasattr(seqrecords, '_records'):
          if hasattr(seqrecords, 'level'):
              level = seqrecords.level
          if hasattr(seqrecords, 'name'):
              name = seqrecords.name
          seqrecords = seqrecords._records
      consensus = seqrecords.pop(0)
      cons_length = len(consensus)
      for i, s in enumerate(seqrecords):
          if len(s) != cons_length:
              raise ValueError(
              "Sequence
              % (i+2, len(s), cons_length))
      if '.' in str(consensus.seq):
          if '-' in str(consensus.seq):
              if strict:
                  raise ValueError("Consensus contains '-' gap characters")
              logging.warn("Consensus sequence contains both '.' and '-' gap "
                           "characters -- is it really the consensus?")
              aligned_cols = [(c not in '.-') for c in str(consensus.seq)]
          else:
              aligned_cols = [c != '.' for c in str(consensus.seq)]
      else:
          aligned_cols = [c != '-' for c in str(consensus.seq)]
      consensus.seq = replace_asterisks(consensus.seq, 'consensus')
      block = consensus2block(consensus, level=level, name=name)
      qlen = block['query_length']
      for index, rec in zip(xrange(2, len(seqrecords)+2), seqrecords):
          new_mol_seq = []
          is_beginning = True
          for aligned_col, char in zip(aligned_cols,
                                       replace_asterisks(rec.seq, index)):
              if aligned_col:
                  is_beginning = False
                  if char in '-.':
                      new_mol_seq.append('-')
                  else:
                      new_mol_seq.append(char.upper())
              else:
                  if char not in '-.' and not is_beginning:
                      new_mol_seq.append(char.lower())
          rec.seq = ''.join(new_mol_seq)
          if do_iron:
              rec.seq = iron(rec.seq)
          block['sequences'].append(seqrecord2sequence(rec, qlen, index))
      return block