Skip to content

Instantly share code, notes, and snippets.

View grst's full-sized avatar

Gregor Sturm grst

  • Boehringer Ingelheim
  • Biberach, DE
  • 10:02 (UTC +02:00)
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@grst
grst / squidpy_get_bbox.py
Created August 2, 2023 13:31
Get bounding box for squidpy spatial plot to be equivalent to the scanpy.pl.spatial
def get_bbox(adata, library_id, *, library_key="sample", img_key="hires", margin=50):
adata = adata[adata.obs[library_key] == library_id, :]
coords = adata.obsm["spatial"]
scale_factor = adata.uns["spatial"][library_id]["scalefactors"][f"tissue_{img_key}_scalef"]
return tuple(
np.array(
[
np.min(coords[:, 0]) - margin,
np.min(coords[:, 1]) - margin,
np.max(coords[:, 0]) + margin,
@grst
grst / pl.py
Created September 6, 2023 14:37
from functools import partial
import math
from typing import Literal
from datashader.mpl_ext import dsshow, alpha_colormap
import datashader as ds
from joblib import parallel_backend
from mpl_toolkits.axes_grid1 import ImageGrid
import matplotlib.pyplot as plt
import pandas as pd
import scanpy as sc