rule format_contigs:
    """
    This rule changes contigs name to have sample name and the contig number to
    reduce the description line length. Otherwise, Prokka will not annotate our
    contigs. This rule also removes contigs less long than a threshold.

    Required input:
        - __format_contigs__input: FASTA file with contigs.

    Required output:
        - __format_contigs__output: FASTA file with reformated contigs.

    Required configuration:
        .. code-block:: yaml

            format_contigs:
                threshold: 500 # remove contigs less long than this threshold.
    """
    input:
        contigs = __format_contigs__input
    output:
        contigs = __format_contigs__output
    params:
        threshold = config["format_contigs"]["threshold"]
    run:
        from sequana import FastA

        contigs = FastA(input.contigs)
        contigs.format_contigs_denovo(output_file=output.contigs,
                                      len_min=params.threshold)
