def build(base_folder, size_pyramid, factor, min_bin_per_contig):
    """Build a pyramid of contact maps

    Build a fragment pyramid for multi-scale analysis
    
    Parameters
    ----------
    base_folder : str or pathlib.Path
        Where to create the hdf5 files containing the matrices.
    size_pyramid : int
        How many levels (contact maps of decreasing resolution) to generate.
    factor : int
        Subsampling factor (binning) from one level to the next.
    min_bin_per_contig : int
        The minimum number of bins per contig below which binning shall not be
        performed.
    """

    fact_sub_sampling = factor
    contig_info = os.path.join(base_folder, "info_contigs.txt")
    fragments_list = os.path.join(base_folder, "fragments_list.txt")
    init_abs_fragments_contacts = os.path.join(
        base_folder, "abs_fragments_contacts_weighted.txt"
    )
    all_pyramid_folder = os.path.join(base_folder, "pyramids")
    pyramid_folder = os.path.join(
        all_pyramid_folder, "pyramid_" + str(size_pyramid) + "_no_thresh"
    )

    if not (os.path.exists(all_pyramid_folder)):
        os.mkdir(all_pyramid_folder)

    if not (os.path.exists(pyramid_folder)):
        os.mkdir(pyramid_folder)

    hdf5_pyramid_file = os.path.join(pyramid_folder, "pyramid.hdf5")
    pyramid_handle = h5py.File(hdf5_pyramid_file)
    level = 0
    pyramid_level_folder = os.path.join(pyramid_folder, "level_" + str(level))
    if not (os.path.exists(pyramid_level_folder)):
        os.mkdir(pyramid_level_folder)

    current_contig_info = os.path.join(
        pyramid_level_folder, str(level) + "_contig_info.txt"
    )
    current_frag_list = os.path.join(
        pyramid_level_folder, str(level) + "_fragments_list.txt"
    )
    current_abs_fragments_contacts = os.path.join(
        pyramid_level_folder, str(level) + "_abs_frag_contacts.txt"
    )
    for level in range(0, size_pyramid):
        pyramid_level_folder = os.path.join(
            pyramid_folder, "level_" + str(level)
        )
        if not (os.path.exists(pyramid_level_folder)):
            os.mkdir(pyramid_level_folder)
        level_pyramid = str(level) + "_"
        if level == 0:
            shutil.copyfile(contig_info, current_contig_info)
            shutil.copyfile(
                init_abs_fragments_contacts, current_abs_fragments_contacts
            )
            nfrags = init_frag_list(fragments_list, current_frag_list)
            new_abs_fragments_contacts_file = current_abs_fragments_contacts
            new_contig_list_file = current_contig_info
            new_fragments_list_file = current_frag_list
            sub_2_super_frag_index_file = os.path.join(
                pyramid_level_folder,
                level_pyramid + "sub_2_super_index_frag.txt",
            )

        else:

            new_contig_list_file = os.path.join(
                pyramid_level_folder, level_pyramid + "contig_info.txt"
            )
            new_fragments_list_file = os.path.join(
                pyramid_level_folder, level_pyramid + "fragments_list.txt"
            )
            new_abs_fragments_contacts_file = os.path.join(
                pyramid_level_folder, level_pyramid + "abs_frag_contacts.txt"
            )
            if (
                os.path.exists(new_contig_list_file)
                and os.path.exists(new_fragments_list_file)
                and os.path.exists(new_abs_fragments_contacts_file)
                and os.path.exists(sub_2_super_frag_index_file)
            ):
                logger.info("level already built...")
                nfrags = file_len(new_fragments_list_file) - 1
            else:
                logger.info("writing new_files..")
                nfrags = subsample_data_set(
                    current_contig_info,
                    current_frag_list,
                    fact_sub_sampling,
                    current_abs_fragments_contacts,
                    new_abs_fragments_contacts_file,
                    min_bin_per_contig,
                    new_contig_list_file,
                    new_fragments_list_file,
                    sub_2_super_frag_index_file,
                )

        try:
            status = pyramid_handle.attrs[str(level)] == "done"
        except KeyError:
            pyramid_handle.attrs[str(level)] = "pending"
            status = False
        if not (status):
            logger.info("Start filling the pyramid")
            fill_sparse_pyramid_level(
                pyramid_handle, level, new_abs_fragments_contacts_file, nfrags
            )
            pyramid_handle.attrs[str(level)] = "done"
        current_frag_list = new_fragments_list_file
        current_contig_info = new_contig_list_file
        current_abs_fragments_contacts = new_abs_fragments_contacts_file
        sub_2_super_frag_index_file = os.path.join(
            pyramid_level_folder, level_pyramid + "sub_2_super_index_frag.txt"
        )
    logger.info("pyramid built.")
    pyramid_handle.close()
Build a pyramid of contact maps

    Build a fragment pyramid for multi-scale analysis
    
    Parameters
    ----------
    base_folder : str or pathlib.Path
        Where to create the hdf5 files containing the matrices.
    size_pyramid : int
        How many levels (contact maps of decreasing resolution) to generate.
    factor : int
        Subsampling factor (binning) from one level to the next.
    min_bin_per_contig : int
        The minimum number of bins per contig below which binning shall not be
        performed.