def gRNA_rank_stimulus(xx, s2, prefix=""):
# Difference between unstimulated/stimulated
fig, axis = plt.subplots(1, 3, sharex=False, sharey=True, figsize=(12, 3))
axis = axis.flatten()
for i, screen in enumerate(s2.columns[::-1]):
x = s1.join(s2) # .fillna(0)
x = x.iloc[np.random.permutation(len(x))]
if ("TCR" in screen) or ("Jurkat" in screen):
x = x.ix[x.index[~x.index.str.contains("Wnt")]]
if prefix.startswith("mid_screen-"):
b = x["gDNA_Jurkat"]
else:
b = x["plasmid_pool_TCR"]
elif ("WNT" in screen) or ("HEK" in screen):
x = x.ix[x.index[~x.index.str.contains("Tcr")]]
if prefix.startswith("mid_screen-"):
if "_4_" in prefix:
b = x["gDNA_HEKclone4"]
else:
b = x["gDNA_HEKclone6"]
else:
b = x["plasmid_pool_WNT"]
fc = np.log2(1 + x[screen]) - np.log2(1 + b)
fc.name = screen
if i == 0:
xx = pd.DataFrame(fc)
else:
xx = xx.join(fc, how="outer")
screens = s2.columns[::-1]
for i in range(0, len(s2.columns), 2):
fc = (xx[screens[i + 1]] - xx[screens[i]]).dropna()
fc.name = screens[i + 1]
if i == 0:
axis[i].set_ylabel("gRNA fold-change (stimulated / unstimulated)")
xxx = pd.DataFrame(fc)
else:
xxx = xxx.join(fc, how="outer")
colors = pd.DataFrame()
colors[sns.color_palette("colorblind")[0]] = fc.index.str.contains("Wnt")
colors[sns.color_palette("colorblind")[1]] = fc.index.str.contains("CTRL")
colors[sns.color_palette("colorblind")[2]] = fc.index.str.contains("Tcr")
colors[sns.color_palette("colorblind")[3]] = fc.index.str.contains("Ess")
colors = colors.apply(lambda j: j[j].index.tolist()[0], axis=1).tolist()
axis[i].scatter(fc.rank(ascending=False, method="first"), fc, color=colors, alpha=0.5)
axis[i].axhline(y=0, color='black', linestyle='--', lw=0.5)
axis[i].set_title(re.sub("_stimulated", "", screens[i + 1]))
axis[i].set_xlabel("gRNA rank (stimulated / unstimulated)")
sns.despine(fig)
fig.savefig(os.path.join(results_dir, "gRNA_counts.norm.{}.rank.diff_condition.svg".format(prefix)), bbox_inches="tight")
xxx.columns = xxx.columns.str.extract("(.*)_stimulated")
xxx.to_csv(os.path.join(results_dir, "gRNA_counts.norm.{}.rank.diff_condition.csv".format(prefix)), index=True)
评论列表
文章目录