






pip install sainsc
###conda install bioconda::sainsc
from pathlib import Path
import numpy as np
import pandas as pd
from sainsc.io import read_StereoSeq
####加载数据
embryo = read_StereoSeq(stereo_seq_file)
embryo.calculate_total_mRNA()
_ = embryo.plot_genecount(im_kwargs={"vmax": 5})
embryo.counts.crop((5_000, 33_000), (9_000, None))
embryo.calculate_total_mRNA()
_ = embryo.plot_genecount(im_kwargs={"vmax": 5})
from PIL import Image
# export total mRNA as png
u8 = np.uint8
Image.fromarray(
np.clip(embryo.total_mRNA, np.iinfo(u8).min, np.iinfo(u8).max).astype(u8)
).save("embryo_counts.png")
import matplotlib.pyplot as plt
from sainsc.datasets import fetch_embryo_mask
# avoid the DecompressionBombError
Image.MAX_IMAGE_PIXELS = None
mask_file = fetch_embryo_mask()
embryo_mask = np.array(Image.open(mask_file), dtype=bool)
_ = plt.imshow(embryo_mask.T, origin="lower")
embryo.counts.filter_mask(embryo_mask)
embryo.counts.filter_genes_by_count(1)
embryo.calculate_total_mRNA()
_ = embryo.plot_genecount(im_kwargs={"vmax": 5})
###核密度
embryo.gaussian_kernel(4, unit="um")
embryo.calculate_total_mRNA_KDE()
_ = embryo.plot_KDE()
embryo.filter_background(0.9)
_ = embryo.plot_KDE(remove_background=True)
####Cell-type assignment
from sainsc.datasets import fetch_embryo_signatures
signatures = fetch_embryo_signatures()
signatures.iloc[:, :4].head()
embryo.assign_celltype(signatures)
import colorcet as cc
import seaborn as sns
cmap = dict(
zip(embryo.celltypes, sns.color_palette(cc.glasbey, n_colors=len(embryo.celltypes)))
)
_ = embryo.plot_celltype_map(cmap=cmap)
_ = embryo.plot_celltype_map(
crop=((2_000, 6_000), (10_500, 15_000)),
cmap=cmap,
scalebar_kwargs={"location": "upper left"},
)
_ = embryo.plot_assignment_score()
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。