Skip to content

Instantly share code, notes, and snippets.

#sample_dims - spatial dimensions
#samples_hierarchical_errosion - samples from poisson mean
mu = samples_hierarchical_errosion[f'lm_er_{s}'].mean(axis=0) # [tensor dims locations x genes]
k = iss_data[s] # [observed values locations x genes]
u = stats.uniform.rvs(size=mu.shape[0]*mu.shape[1]).reshape(mu.shape)
ppois = u * stats.poisson.cdf(k, mu) + (1-u) * stats.poisson.cdf(k-1, mu) # qusntiles of observations given estimated poisson mean
qnorm = stats.norm.ppf(ppois) * mask[s].reshape(-1,1) #assuming pseudo normal distribution of quantiles
plt.imshow(qnorm[:,g].reshape(*sample_dims[s]).T[::-1, :], vmin=-3, vmax=3) # plot per gene
def kernel(X1, X2, l=1.0, eta=1.0):
'''
Isotropic squared exponential kernel. Computes
a covariance matrix from points in X1 and X2.
Args:
X1: Array of m points (m x d).
X2: Array of n points (n x d).
Returns:
@tulerpetontidae
tulerpetontidae / plot_density_marginals.py
Last active March 12, 2023 20:48
Density scatter plot with marginals
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as st
import matplotlib.ticker as plticker
rng = np.random.default_rng(42)
def generate_dist(mu=[0, 0], sigma1=1, sigma2=2, rho=0.5, n_points=250):
"""
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
groups = ['citizenship', 'race', 'sex', 'institute', 'religion', 'occupation', 'first names', 'eye color']
# List of grouped people, e.g. [1 - iranian, 1 - italian, 4 - russians]
number_of_people = [[1, 1, 4], [1, 5], [1, 5], [1, 1, 4], [6], [1, 1, 4], [2, 1, 1, 1, 1], [2,2,2]]
# Total number of people
n_people = 6
@tulerpetontidae
tulerpetontidae / visium_region_outline.py
Created June 4, 2024 08:20
function to plot outline over a region in visium data
# install alpha_shapes from https://github.com/panosz/alpha_shapes
# adata.obsm['region_inside'] contains a (n_visium_spots, k_regions) binary array,
# where 1 indicates visium spot beplonging to a given regions
# adata.obsm['spatial'] contains position of each of n_visium_spots
from alpha_shapes import Alpha_Shaper, plot_alpha_shape
from tqdm import tqdm
def plot_visium_region_outline(adata):
alpha_scaling=1