def collapse_to_consensus(seqrecords, strict=False, do_iron=True):
    """Opposite of realign_seqs.

    Input sequences should all be the same length.

    The first record must be the consensus.
    """
    level = 0
    name = seqrecords[0].id
    # If this is a CMA alignment, extract additional info:
    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 #%d has length %d, consensus is %d"
            % (i+2, len(s), cons_length))

    if '.' in str(consensus.seq):
        # Strict -- error if there's a '-'
        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:
        # A little more ambiguous...
        aligned_cols = [c != '-' for c in str(consensus.seq)]

    consensus.seq = replace_asterisks(consensus.seq, 'consensus')
    # Start a block with the consensus sequence
    block = consensus2block(consensus, level=level, name=name)
    qlen = block['query_length']

    # Collapse & add remaining sequences to the block
    for index, rec in zip(xrange(2, len(seqrecords)+2), seqrecords):
        # Collapse rec.seq down to aligned size
        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 '-.':
                    # deletion
                    new_mol_seq.append('-')
                else:
                    # aligned character
                    new_mol_seq.append(char.upper())
            else:
                # it's an insert or nothing
                # (also, skip any left-side inserts)
                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