from pathlib import Path


def _path_to_name(path_str, name_from_part, name_split_on, name_format):
    """Extract a genome name from a URI path."""
    path = Path(path_str)
    component_no = -1 - int(name_from_part)
    component = path.parts[component_no]
    if name_split_on == "":
        split = [component]
    else:
        split = component.split(name_split_on)
    return name_format.format(*split)