clodius/cli/aggregate.py
def _multivec(
    filepath,
    output_file,
    assembly,
    tile_size,
    chromsizes_filename,
    starting_resolution,
    method,
    row_infos_filename=None,
):
    """
    Aggregate a multivec file.

    This is a file containing nxn data that is aggregated along only one axis.
    This data should be in an HDF5 file where each dataset is named for a
    chromosome and contains a 'resolutions' group containing values for the
    base level resolution.

    Example: f['chr1']['reslutions']['1000'] = [[1,2,3],[4,5,6]]

    The resulting data will be organized by resolution and chromosome.

    Example: f_out['chr1']['resolutions']['5000']=[[1000,2000,3000],[4000,5000,6000]]

    Aggregation is currently done by summing adjacent values.
    """
    f_in = h5py.File(filepath, "r")

    if output_file is None:
        output_file = op.splitext(filepath)[0] + ".multires.mv5"

    (chrom_info, chrom_names, chrom_sizes) = cch.load_chromsizes(
        chromsizes_filename, assembly
    )

    # TODO: "method" is not defined, so this would not work?
    if method == "maxtotal":  # noqa: F821
        pass
    if method == "logsumexp":  # noqa: F821

        def agg(x):
            a = x.T.reshape((x.shape[1], -1, 2))
            return sm.logsumexp(a, axis=2).T

    else:

        def agg(x):
            return x.T.reshape((x.shape[1], -1, 2)).sum(axis=2).T

    print("agg:", agg)
    if row_infos_filename is not None:
        with open(row_infos_filename, "r") as fr:
            row_infos = [l.strip().encode("utf8") for l in fr]
    else:
        row_infos = None
    print("row_infos:", row_infos)

    cmv.create_multivec_multires(
        f_in,
        chromsizes=zip(chrom_names, chrom_sizes),
        agg=lambda x: np.nansum(x.T.reshape((x.shape[1], -1, 2)), axis=2).T,
        starting_resolution=starting_resolution,
        tile_size=tile_size,
        output_file=output_file,
        row_infos=row_infos,
    )

    Aggregate a multivec file.

    This is a file containing nxn data that is aggregated along only one axis.
    This data should be in an HDF5 file where each dataset is named for a
    chromosome and contains a 'resolutions' group containing values for the
    base level resolution.

    Example: f['chr1']['reslutions']['1000'] = [[1,2,3],[4,5,6]]

    The resulting data will be organized by resolution and chromosome.

    Example: f_out['chr1']['resolutions']['5000']=[[1000,2000,3000],[4000,5000,6000]]

    Aggregation is currently done by summing adjacent values.
    
Aggregate a multivec file.
This is a file containing nxn data that is aggregated along only one axis.
This data should be in an HDF5 file where each dataset is named for a
chromosome and contains a 'resolutions' group containing values for the
base level resolution.



The resulting data will be organized by resolution and chromosome.



Aggregation is currently done by summing adjacent values.
Aggregate a multivec file . This is a file containing nxn data that is aggregated along only one axis . This data should be in an HDF5 file where each dataset is named for a chromosome and contains a ' resolutions ' group containing values for the base level resolution . The resulting data will be organized by resolution and chromosome . Aggregation is currently done by summing adjacent values .
def _multivec(
    filepath,
    output_file,
    assembly,
    tile_size,
    chromsizes_filename,
    starting_resolution,
    method,
    row_infos_filename=None,
):
    f_in = h5py.File(filepath, "r")
    if output_file is None:
        output_file = op.splitext(filepath)[0] + ".multires.mv5"
    (chrom_info, chrom_names, chrom_sizes) = cch.load_chromsizes(
        chromsizes_filename, assembly
    )
    if method == "maxtotal":  
        pass
    if method == "logsumexp":  
        def agg(x):
            a = x.T.reshape((x.shape[1], -1, 2))
            return sm.logsumexp(a, axis=2).T
    else:
        def agg(x):
            return x.T.reshape((x.shape[1], -1, 2)).sum(axis=2).T
    print("agg:", agg)
    if row_infos_filename is not None:
        with open(row_infos_filename, "r") as fr:
            row_infos = [l.strip().encode("utf8") for l in fr]
    else:
        row_infos = None
    print("row_infos:", row_infos)
    cmv.create_multivec_multires(
        f_in,
        chromsizes=zip(chrom_names, chrom_sizes),
        agg=lambda x: np.nansum(x.T.reshape((x.shape[1], -1, 2)), axis=2).T,
        starting_resolution=starting_resolution,
        tile_size=tile_size,
        output_file=output_file,
        row_infos=row_infos,
    )
def _multivec ( filepath , output_file , assembly , tile_size , chromsizes_filename , starting_resolution , method , row_infos_filename = None , ) : f_in = h5py . File ( filepath , "r" ) if output_file is None : output_file = op . splitext ( filepath ) [ 0 ] + ".multires.mv5" ( chrom_info , chrom_names , chrom_sizes ) = cch . load_chromsizes ( chromsizes_filename , assembly ) if method == "maxtotal" : pass if method == "logsumexp" : def agg ( x ) : a = x . T . reshape ( ( x . shape [ 1 ] , - 1 , 2 ) ) return sm . logsumexp ( a , axis = 2 ) . T else : def agg ( x ) : return x . T . reshape ( ( x . shape [ 1 ] , - 1 , 2 ) ) . sum ( axis = 2 ) . T print ( "agg:" , agg ) if row_infos_filename is not None : with open ( row_infos_filename , "r" ) as fr : row_infos = [ l . strip ( ) . encode ( "utf8" ) for l in fr ] else : row_infos = None print ( "row_infos:" , row_infos ) cmv . create_multivec_multires ( f_in , chromsizes = zip ( chrom_names , chrom_sizes ) , agg = lambda x : np . nansum ( x . T . reshape ( ( x . shape [ 1 ] , - 1 , 2 ) ) , axis = 2 ) . T , starting_resolution = starting_resolution , tile_size = tile_size , output_file = output_file , row_infos = row_infos , )
Aggregate a multivec file.
Aggregate a multivec file .
"""
    Aggregate a multivec file.

    This is a file containing nxn data that is aggregated along only one axis.
    This data should be in an HDF5 file where each dataset is named for a
    chromosome and contains a 'resolutions' group containing values for the
    base level resolution.

    Example: f['chr1']['reslutions']['1000'] = [[1,2,3],[4,5,6]]

    The resulting data will be organized by resolution and chromosome.

    Example: f_out['chr1']['resolutions']['5000']=[[1000,2000,3000],[4000,5000,6000]]

    Aggregation is currently done by summing adjacent values.
    """ # TODO: "method" is not defined, so this would not work? # noqa: F821 # noqa: F821
filepath
output_file
assembly
tile_size
chromsizes_filename
starting_resolution
method
row_infos_filename