def documentize_sequence(seqs, tag, nt_seq):
    """This function converts raw nucleotide or amino acid sequences
    into documents that can be encoded with the Keras Tokenizer().
    If a purification tag is supplied, it will be removed from
    the sequence document. """

    # setup 'docs' for use with Tokenizer
    def seq_to_doc(seq):
        # drop initial tag if it is supplied
        if tag:
            if tag not in seq:
                return None
            seq = seq.split(tag)[1]
        # split the sequence at every letter if not a nt_seq
        if not nt_seq:
            return ' '.join([aa for aa in seq])
        # split the sequence every 3 letters if it is a nt_seq
        return ' '.join([seq[i:i + 3]
                         for i in range(0, len(seq), 3)])

    return seqs.apply(seq_to_doc)