<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def remap_index_fn(ref_file):
 """minimap2 can build indexes on the fly but will also store commons ones. """

    index_dir = os.path.join(os.path.dirname(ref_file), os.pardir, "minimap2")
    if os.path.exists(index_dir) and os.path.isdir(index_dir):
        return index_dir
    else:
        return os.path.dirname(ref_file)