def remove_empty_cols(records):
    """Remove all-gap columns from aligned SeqRecords."""
    # In case it's a generator, turn it into a list
    records = list(records)
    seqstrs = [str(rec.seq) for rec in records]
    clean_cols = [col
                  for col in zip(*seqstrs)
                  if not all(c == '-' for c in col)]
    clean_seqs = [''.join(row)
                  for row in zip(*clean_cols)]
    for rec, clean_seq in zip(records, clean_seqs):
        yield SeqRecord(Seq(clean_seq, rec.seq.alphabet), id=rec.id,
                        name=rec.name, description=rec.description,
                        dbxrefs=rec.dbxrefs, features=rec.features,
                        annotations=rec.annotations,
                        letter_annotations=rec.letter_annotations)
def remove_empty_cols ( records ) : records = list ( records ) seqstrs = [ str ( rec . seq ) for rec in records ] clean_cols = [ col for col in zip ( * seqstrs ) if not all ( c == '-' for c in col ) ] clean_seqs = [ '' . join ( row ) for row in zip ( * clean_cols ) ] for rec , clean_seq in zip ( records , clean_seqs ) : yield SeqRecord ( Seq ( clean_seq , rec . seq . alphabet ) , id = rec . id , name = rec . name , description = rec . description , dbxrefs = rec . dbxrefs , features = rec . features , annotations = rec . annotations , letter_annotations = rec . letter_annotations )
Remove all-gap columns from aligned SeqRecords.