aggmap.utils package

Submodules

aggmap.utils.calculator module

Created on Sat Aug 17 16:54:12 2019

@author: wanxiang.shen@u.nus.edu

@usecase: calculate varies distances

aggmap.utils.calculator.pairwise_distance(npydata, n_cpus=8, method='correlation')[source]
Parameters:
  • method ({'euclidean', 'manhattan', 'canberra', 'chebyshev',) – ‘cosine’, ‘braycurtis’, ‘correlation’, ‘jaccard’, ‘rogerstanimoto’, ‘hamming’, ‘dice’, ‘kulsinski’, ‘sokal_sneath’}

  • npydata (np.array or np.memmap, Note that the default we will calcuate the vector's distances instead of sample's distances, if you wish to calculate distances between samples, you can pass data.T instead of data) –

  • Usage

  • --------------

  • np (>>> import numpy as) –

  • np.random.random_sample(size=(10000 (>>> data =) –

  • 10)

  • pairwise_distance(data) (>>> dist_matrix =) –

  • dist_matrix.shape (>>>) –

  • (10 (>>>) –

  • 10)

aggmap.utils.distances module

aggmap.utils.distances.GenNamedDist(descriptors_dist, fingerprint_dist)[source]
aggmap.utils.distances.bray_curtis(x, y)[source]
aggmap.utils.distances.canberra(x, y)[source]
aggmap.utils.distances.chebyshev(x, y)[source]

Chebyshev or l-infinity distance. ..math:

D(x, y) = \max_i |x_i - y_i|
aggmap.utils.distances.correlation(x, y)[source]
aggmap.utils.distances.cosine(x, y)[source]
aggmap.utils.distances.dice(x, y)[source]
aggmap.utils.distances.euclidean(x, y)[source]

Standard euclidean distance. l2 distance ..math:

D(x, y) = \sqrt{\sum_i (x_i - y_i)^2}
aggmap.utils.distances.hamming(x, y)[source]
aggmap.utils.distances.jaccard(x, y)[source]
aggmap.utils.distances.kulsinski(x, y)[source]
aggmap.utils.distances.manhattan(x, y)[source]

Manhatten, taxicab, or l1 distance. ..math:

D(x, y) = \sum_i |x_i - y_i|
aggmap.utils.distances.rogers_tanimoto(x, y)[source]
aggmap.utils.distances.sokal_sneath(x, y)[source]
aggmap.utils.distances.sqeuclidean(x, y)[source]

Standard euclidean distance. l2 distance ..math:

D(x, y) = \sqrt{\sum_i (x_i - y_i)^2}

aggmap.utils.gen_nwk module

Created on Fri Aug 27 14:06:17 2021

@author: Shen Wanxiang

aggmap.utils.gen_nwk.dfs_to_tree(dfs)[source]
aggmap.utils.gen_nwk.dfs_to_weightless_newick(dfs)[source]
aggmap.utils.gen_nwk.mp2newick(mp, treefile='phenotype_tree', leaf_names=None)[source]
aggmap.utils.gen_nwk.pprint_tree(tree_instance)[source]
aggmap.utils.gen_nwk.tree()[source]
aggmap.utils.gen_nwk.tree_add(t, path)[source]
aggmap.utils.gen_nwk.tree_to_newick(root)[source]

aggmap.utils.logtools module

Created on Sat Aug 17 16:54:12 2019

@author: wanxiang.shen@u.nus.edu

@logtools

class aggmap.utils.logtools.PBarHandler(pbar)[source]

Bases: Handler

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

aggmap.utils.logtools.clip_text(text)[source]
aggmap.utils.logtools.create_print_method(level)[source]
aggmap.utils.logtools.format_exc(error)[source]
aggmap.utils.logtools.get_date()[source]
aggmap.utils.logtools.get_datetime()[source]
aggmap.utils.logtools.log_to_file(path)[source]
aggmap.utils.logtools.pbar(*args, **kwargs)[source]
aggmap.utils.logtools.print_debug(*args, sep=' ', verbose=True)
aggmap.utils.logtools.print_error(*args, sep=' ', verbose=True)
aggmap.utils.logtools.print_exc(error, verbose=True)[source]
aggmap.utils.logtools.print_exc_s(error)[source]
aggmap.utils.logtools.print_info(*args, sep=' ', verbose=True)
aggmap.utils.logtools.print_timedelta(*args, sep=' ')[source]
aggmap.utils.logtools.print_traceback()[source]
aggmap.utils.logtools.print_warn(*args, sep=' ', verbose=True)
aggmap.utils.logtools.reset_handler(handler)[source]
aggmap.utils.logtools.set_level(level)[source]
aggmap.utils.logtools.set_text_length(prefix, suffix)[source]

aggmap.utils.matrixopt module

Created on Sun Aug 25 20:29:36 2019

@author: wanxiang.shen@u.nus.edu

matrix operation

class aggmap.utils.matrixopt.Scatter2Array(fmap_shape=(128, 128))[source]

Bases: object

fit(df, split_channels=True, channel_col='Channels')[source]
Parameters:
  • df (embedding_df, dataframe) –

  • split_channels (bool, if True, will apply split by group) –

  • channel_col (column in df.columns, split to groups by this col) –

transform(vector_1d)[source]

vector_1d: feature values 1d array

class aggmap.utils.matrixopt.Scatter2Grid[source]

Bases: object

fit(df, split_channels=True, channel_col='Channels')[source]
Parameters:
  • df (dataframe with x, y columns) –

  • split_channels (bool, if True, will apply split by group) –

  • channel_col (column in df.columns, split to groups by this col) –

refit_c(df)[source]
Parameters:

df (dataframe with x, y columns) –

transform(vector_1d)[source]

vector_1d: extracted features

aggmap.utils.matrixopt.conv2(array, kernel_size=31, sigma=2, mode='same', fillvalue=0)[source]
aggmap.utils.matrixopt.fspecial_gauss(size=31, sigma=2)[source]

Function to mimic the ‘fspecial’ gaussian MATLAB function size should be odd value

aggmap.utils.matrixopt.smartpadding(array, target_size, mode='constant', constant_values=0)[source]

array: 2d array to be padded target_size: tuple of target array’s shape

aggmap.utils.multiproc module

Created on Wed Nov 21 12:52:49 2018

@author: shenwanxiang

Multi process Run

aggmap.utils.multiproc.ImapUnorder(processor, iterator, max_workers=10, fail_in_file='./filed.lst')[source]

processor: fuction iterator: list or iterator,each element should be a tuple or dict, so that data can be used as ordered

aggmap.utils.multiproc.MultiExecutorRun(func, deal_list, n_cpus=4, tqdm_args={'unit': 'one'})[source]
input:

func: function to do with each element in the deal_list deal_list: list to be done n_cpus: use the number of cpus tqdm_args: args for tqdm

output:

list of the return value for each func

aggmap.utils.multiproc.MultiProcessRun(func, deal_list, n_cpus=None)[source]
input:

func: function to do with each element in the deal_list deal_list: list to be done n_cpus: use the number of cpus

output:

list of the return result for each func

aggmap.utils.multiproc.MultiProcessUnorderedBarRun(func, deal_list, n_cpus=None)[source]
aggmap.utils.multiproc.RunCmd(cmd)[source]
input:

cmd: str

output:

status: int, 0 for success stdout: str stderr: str

aggmap.utils.summary module

Created on Sat Aug 17 16:54:12 2019

@author: wanxiang.shen@u.nus.edu

@usecase: statistic features’ distribution

class aggmap.utils.summary.Summary(n_jobs=1)[source]

Bases: object

fit(data, backend='threading', **kwargs)[source]
Parameters:

data (np.memmap or np.array) –

aggmap.utils.summary.Summary2(data, n_jobs)[source]

aggmap.utils.vismap module

aggmap.utils.vismap.plot_grid(mp, htmlpath='./', htmlname=None, enabled_data_labels=False)[source]

mp: the object of mp htmlpath: the figure path

aggmap.utils.vismap.plot_scatter(mp, htmlpath='./', htmlname=None, radius=2, enabled_data_labels=False)[source]

mp: the object of mp htmlpath: the figure path, not include the prefix of ‘html’ htmlname: the name radius: int, defaut:3, the radius of scatter dot

aggmap.utils.vismap.plot_tree(mp, htmlpath='./', htmlname=None)[source]

Module contents