import pegasus as pg
import scanpy as sc
import pandas as pd
import matplotlib.colors as clr
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import seaborn as sns
# Set a colormap
colormap = clr.LinearSegmentedColormap.from_list('gene_cmap', ["#e0e0e1", '#4576b8', '#02024a'], N=200)
# Aggregate the matrices
pg.aggregate_matrices(csv_file = "/home/nealpsmith/projects/medoff/cellranger/aggregate_matrix.csv",
what_to_return = "/home/nealpsmith/projects/medoff/data/all_data.h5sc")
all_data = pg.read_input("/home/nealpsmith/projects/medoff/data/all_data.h5sc")
pg.qc_metrics(all_data, percent_mito = 30)
# Plot the percent mito/n genes
# fig, ax = plt.subplots(1)
# x = all_data.obs["n_genes"]
# y = all_data.obs["percent_mito"]
# _ = ax.hexbin(x, y, mincnt=1, xscale = "log")
# _ = ax.set_xticks([10, 100, 1000])
# _ = ax.get_xaxis().set_major_formatter(mpl.ticker.ScalarFormatter())
# _ = ax.axvline(500, color="red")
# _ = ax.axhline(30, color="red")
# _ = plt.xlabel("Number of genes")
# _ = plt.ylabel("percent mitochondrial UMIs")
violin_dat = all_data.obs[["Channel", "percent_mito"]]
violin_dat[["Channel"]] = [n.replace("ANA", "AC") for n in violin_dat["Channel"]]
violin_dat[["Channel"]] = [n.replace("Pre", "Bln") for n in violin_dat["Channel"]]
violin_order = ['500008_AC_Bln',
'500008_AC_Dil',
'500008_AC_Ag',
'500012_AC_Bln',
'500012_AC_Dil',
'500012_AC_Ag',
'500015_AC_Bln',
'500015_AC_Ag',
'500024_AC_Bln',
'500024_AC_Dil',
'500024_AC_Ag',
'500021_AA_Bln',
'500021_AA_Dil',
'500021_AA_Ag',
'500030_AA_Bln',
'500030_AA_Dil',
'500030_AA_Ag',
'500032_AA_Bln',
'500032_AA_Ag',
'500035_AA_Bln',
'500035_AA_Ag']
fig, ax = plt.subplots(1)
sns.violinplot(x = "Channel", y = "percent_mito", color = "grey", data = violin_dat, inner = None, scale = "width",
ax = ax, cut = 0, order = violin_order)
for violin in ax.collections:
violin.set_alpha(0.8)
_ = ax.axhline(y = 30, color = "red", ls = "--")
labs = ax.get_xticklabels()
_ = ax.set_xticklabels(labs, rotation=90)
_ = ax.set_ylabel("% mitochondrial UMIs")
figure = plt.gcf()
figure.set_size_inches(4, 3)
figure.tight_layout()
figure
我已经配置了python环境,我可以在Rstudio中运行这段代码吗
最新发布