def miRNA_count_dynamic(name, project):

    metadata = {"name": name}

    miRNA_count_code = '''
rule miRNA_count_%(name)s:
    """
    miRNA_count_dynamic

    miRNA_count rule count how many reads are mapped on each feature in a BAM file.
    This vould be done for mapping on miRNA (hairpin and mature from miRBase), but also on transcriptome (cDNA file)

    Required input:
        __miRNA_count__input: bam file

    Required output:
        __miRNA_count__output: tabulated file
    """


    input:
        __miRNA_count_%(name)s__input
    output:
        __miRNA_count_%(name)s__output
    log:
        __miRNA_count_%(name)s__log
    shell:
        """
        samtools view {input} | gawk -v FS="\t" '!/^@/{{print $3}}' | sort | uniq -c | gawk '{{print $2 "\t" $1 }}' | sed '1d' > {output}
        """

    '''

    from sequana.snaketools import build_dynamic_rule
    return build_dynamic_rule(miRNA_count_code % metadata, project.pipeline_dir)