smoother.simulation.gp ====================== .. py:module:: smoother.simulation.gp .. autoapi-nested-parse:: Simulate spatial patterns from 2D Gaussian process. Some functions adapted from the cell2location paper: Kleshchevnikov, Vitalii, et al. "Cell2location maps fine-grained cell types in spatial transcriptomics." Nature biotechnology 40.5 (2022): 661-671. https://www.nature.com/articles/s41587-021-01139-4# Functions --------- .. autoapisummary:: smoother.simulation.gp.kernel smoother.simulation.gp.generate_grid smoother.simulation.gp.random_gp smoother.simulation.gp.plot_spatial smoother.simulation.gp.sample_gp smoother.simulation.gp.conc_cir smoother.simulation.gp.sample_circ smoother.simulation.gp.sample_hist smoother.simulation.gp.get_abundances smoother.simulation.gp.get_abundances_circ smoother.simulation.gp.get_abundances_hist Module Contents --------------- .. py:function:: kernel(X1, X2, band_width=1.0, eta=1.0) Isotropic squared exponential kernel. Computes a covariance matrix from points in X1 and X2. :param X1: Array of m points (m x d). :param X2: Array of n points (n x d). :param band_width: Bandwidth of the Gaussian kernel. :returns: Covariance matrix (m x n). .. py:function:: generate_grid(grid_size=[50, 50]) Generating a grid containing n_spots for each spot, return the x1 and x2 pos .. py:function:: random_gp(coords, x1=1, x2=1, n_patterns=3, eta_true=5, l1_true=[8, 10, 15], l2_true=[8, 10, 15]) Generating random 2D gaussian based on an isotropic squared exponential kernel. :param coords: spatial coordinates for each spot (n_spots x 2). :type coords: 2D array :param x1: x-coordinates of the grid (x_size x 1). :type x1: 1D array :param x2: y-coordinates of the grid (y_size x 1). :type x2: 1D array .. py:function:: plot_spatial(values, grid_size=[50, 50], nrows=5, names=['cell type'], vmin=0, vmax=1, cmap='magma') Plot the input spatial value in 2D .. py:function:: sample_gp(locations, x1, x2, n_zones, band_width, eta=1.5) Sample abundances with 2D GP .. py:function:: conc_cir(x1, x2, mu_r=0, sd=0.1) Sample concentric circlar patterns .. py:function:: sample_circ(locations, x1, x2, n_circ, r_circ, sd_circ, band_width, eta=0.5) Sample abundances with GP based on a prior concentric circlar pattern .. py:function:: sample_hist(locations, x1, x2, n_hist, hist_abundances, band_width, eta) Sample abundances with GP based on a prior histological pattern .. py:function:: get_abundances(locations, x1, x2, n_regional_zones, n_ubiquitous_zones, band_width, n_experiments, n_locations, plot_abundances=True, eta_rg=1.5, eta_ub=0.3) Get the abundances matrix as presented in the cell2location notebook :param locations: # location coordinates for 1 experiment :param x1: # location coordinates for 1 experiment :param x2: # location coordinates for 1 experiment :param n_regional_zones: number of regional zones :param n_ubiquitous_zones: number of ubiquitous zones :param band_width: parameters used to calculate the 2D-gaussian kernel :param eta_rg: parameters used to calculate the 2D-gaussian kernel :param eta_ub: parameters used to calculate the 2D-gaussian kernel :param n_experiments: number of experiments required :param n_locations: number of locations[n_row, n_col] per experiment :param plot_abundances: whether to plot the abundance patterns of each zone in the first experiment :returns: (np.prod(n_locations) * n_exp) x (n_regional_zones + n_ubiquitous_zones) :rtype: abundances_df .. py:function:: get_abundances_circ(locations, x1, x2, n_regional_zones, n_ubiquitous_zones, r_circ, sd_circ, band_width, n_experiments, n_locations, plot_abundances=True, eta=0.3) Get the abundances matrix using donut patterns :param locations: # location coordinates for 1 experiment :param x1: # location coordinates for 1 experiment :param x2: # location coordinates for 1 experiment :param n_regional_zones: number of regional zones :param n_ubiquitous_zones: number of ubiquitous zones :param r_circ: the mean and std of a gaussian distribution used to sample circular ring patterns :param sd_circ: the mean and std of a gaussian distribution used to sample circular ring patterns :param band_width: parameters used to calculate the 2D-gaussian kernel :param eta: parameters used to calculate the 2D-gaussian kernel :param n_experiments: number of experiments required :param n_locations: number of locations[n_row, n_col] per experiment :param plot_abundances: whether to plot the abundance patterns of each zone in the first experiment :returns: (np.prod(n_locations) * n_exp) x (n_regional_zones + n_ubiquitous_zones) :rtype: abundances_df .. py:function:: get_abundances_hist(locations, x1, x2, n_regional_zones, n_ubiquitous_zones, hist_abundances, band_width, n_experiments, n_locations, plot_abundances=True, eta=0.3) Get the abundances matrix using histological patterns :param locations: # location coordinates for 1 experiment :param x1: # location coordinates for 1 experiment :param x2: # location coordinates for 1 experiment :param n_regional_zones: number of regional zones :param n_ubiquitous_zones: number of ubiquitous zones :param hist_abundances: membership matrix from fuzzy-c-means clustering, np.prod(n_locations) x n_regional_zones :param band_width: parameters used to calculate the 2D-gaussian kernel :param eta: parameters used to calculate the 2D-gaussian kernel :param n_experiments: number of experiments required :param n_locations: number of locations[n_row, n_col] per experiment :param plot_abundances: whether to plot the abundance patterns of each zone in the first experiment :returns: (np.prod(n_locations) * n_exp) x (n_regional_zones + n_ubiquitous_zones) :rtype: abundances_df