Rename prodigal output files

    Rename output files from prodigal according to the following naming
    scheme: >contigX_chunkY__geneZ

    Chunk numbering starts at 0 and gene identification is taken from prodigal.

    Parameters
    ----------
    prot_in : file, str or pathlib.Path
        The input protein file in FASTA format to be renamed.
    prot_out : file, str or pathlib.Path
        The output protein file to be renamed into.
    chunk_size : int, optional
        The size of the chunks (in bp) used in the pipeline. Default is 1000.

def rename_proteins(prot_in, prot_out=None, chunk_size=DEFAULT_CHUNK_SIZE):
    """Rename prodigal output files

    Rename output files from prodigal according to the following naming
    scheme: >contigX_chunkY__geneZ

    Chunk numbering starts at 0 and gene identification is taken from prodigal.

    Parameters
    ----------
    prot_in : file, str or pathlib.Path
        The input protein file in FASTA format to be renamed.
    prot_out : file, str or pathlib.Path
        The output protein file to be renamed into.
    chunk_size : int, optional
        The size of the chunks (in bp) used in the pipeline. Default is 1000.
    """

    if prot_out is None:
        prot_out = "{}_renamed.fa".format(prot_in.split(".")[0])

    with open(prot_out, "w") as prot_out_handle:

        for record in SeqIO.parse(prot_in, "fasta"):
            header = record.description
            name, pos_start, _, _, _ = header.split("#")

            chunk_start = int(pos_start) // chunk_size

            name_split = name.split("_")
            contig_name = "_".join(name_split[:-1])
            gene_id = name_split[-1]

            new_record_id = "{}_{}__gene{}".format(
                contig_name, chunk_start, gene_id
            )

            prot_out_handle.write(">{}\n".format(new_record_id))
            prot_out_handle.write("{}\n".format(str(record.seq)))