In [1]:
import scanpy as sc, anndata as ad, numpy as np, pandas as pd
from scipy import sparse
from anndata import AnnData
import warnings
import socket
from matplotlib import pylab
import random
import sys
import yaml
import numbers
import os
import plotly.express as px
import matplotlib.pyplot as plt
import scvelo as scv
import rpy2
import rpy2.robjects as ro
import seaborn as sns

warnings.filterwarnings('ignore')
In [2]:
%matplotlib inline
In [3]:
sc.settings.verbosity = 3         # verbosity: errors (0), warnings (1), info (2), hints (3)
sc.logging.print_header()
sc.settings.set_figure_params(dpi=100, facecolor='white')
pylab.rcParams['figure.figsize'] = (10, 10)
scanpy==1.8.0 anndata==0.8.0 umap==0.4.6 numpy==1.22.2 scipy==1.6.2 pandas==1.2.3 scikit-learn==0.24.1 statsmodels==0.13.5 python-igraph==0.9.1 louvain==0.7.0 leidenalg==0.8.3

Configure paths¶

In [4]:
outdir = "../data/output"

with open("../data/resources/iPSC_lines_map.yaml", 'r') as f:
    iPSC_lines_map = yaml.load(f, Loader=yaml.FullLoader)["lines"]
colorsmap = dict(zip([i["newName"] for i in iPSC_lines_map.values()],[i["color"] for i in iPSC_lines_map.values()]))


figDir = "./figures"
if not os.path.exists(figDir):
   # Create a new directory because it does not exist
   os.makedirs(figDir)
    

Namesmap = dict(zip([i["oldName"] for i in iPSC_lines_map.values()],[i["newName"] for i in iPSC_lines_map.values()]))

Import anndata_all¶

In [5]:
adata = sc.read_h5ad(outdir+"/adatas/ClusterAnnotated_Base_filt.h5ad")
In [6]:
aggregatedCallsDict = {
"D50Up" : "../data/Sample_S20272_157/aggregatedCall/aggregatedCall.tsv",
"D50Down" : "../data/Sample_S20273_158/aggregatedCall/aggregatedCall.tsv",
"D100Up1" : "../data//Sample_S20812_258/aggregatedCall/aggregatedCall.tsv",
"D100Up2" : "../data/Sample_S20813_259/aggregatedCall/aggregatedCall.tsv",
"D250Down" : "../data/Sample_S20814_260/aggregatedCall/aggregatedCall.tsv",
"D100Down" : "../data/Sample_S31807_MET6/aggregatedCall/aggregatedCall.tsv",
"D300Up" : "../data/Sample_S33846_C_GEX/aggregatedCall/aggregatedCall.tsv"
}
In [7]:
aggregatedCallsDFDict = {}
for ds in list(aggregatedCallsDict.keys()):
    aggregatedCallsDFDict[ds] = pd.read_csv(aggregatedCallsDict[ds], sep = "\t")
    aggregatedCallsDFDict[ds]["dataset"] = ds
In [8]:
AllAggregated=pd.concat(list(aggregatedCallsDFDict.values())).replace(Namesmap, inplace=False, regex=True)

AllAggregatedgrouped = AllAggregated.groupby(["dataset","Consensus"], as_index=False).size()
AllAggregatedgrouped.loc[:,"paradigm"] = "upstream"
AllAggregatedgrouped.loc[AllAggregatedgrouped["dataset"].isin(["D100Down","D250Down","D50Down"]),"paradigm"] = "downstream"
AllAggregatedgrouped.loc[:,"stage"] = "mid"
AllAggregatedgrouped.loc[AllAggregatedgrouped["dataset"].isin(["D50Down","D50Up"]),"stage"] = "early"
AllAggregatedgrouped.loc[AllAggregatedgrouped["dataset"].isin(["D250Down","D300Up"]),"stage"] = "late"
AllAggregatedgrouped.rename(columns={"Consensus":"ID","size":"nCells"}, inplace=True)
AllAggregatedgrouped.head()
Out[8]:
dataset ID nCells paradigm stage
0 D100Down CTL02A 3993 downstream mid
1 D100Down CTL04E 4589 downstream mid
2 D100Down CTL08A 1046 downstream mid
3 D100Down LowQuality 2849 downstream mid
4 D100Down doublet 1540 downstream mid
In [9]:
for ds in list(AllAggregatedgrouped.dataset.unique()):
    sns.set_style("whitegrid")
    print(ds)
    
    localDF = AllAggregatedgrouped[AllAggregatedgrouped["dataset"] == ds]
    localDF["ID"] = localDF["ID"].astype("category")
    #localDF["ID"] = localDF["ID"].cat.set_categories([iPSC_lines_map[k]["newName"] for k in list(iPSC_lines_map.keys()) if iPSC_lines_map[k]["newName"] in localDF["ID"].tolist()], ordered = True)

    #LocalColor = 
    plt.figure(figsize=(10, 6))
    fig = sns.barplot(x="ID", y="nCells",linewidth=1,edgecolor=".2", data=localDF, palette=colorsmap)
    sns.despine(left=True, bottom=True)
    fig.bar_label(fig.containers[0],fontsize=20)


    #plt.savefig(figDir+"/"+nb_fname+"."+ds+".svg")
    plt.xlabel('ID', size=20)
    plt.ylabel('Number of cells', size=20)


    plt.savefig(figDir+"/"+ds+".svg")
    plt.show()
    fig.clear
D100Down
D100Up1
D100Up2
D250Down
D300Up
D50Down
D50Up
In [ ]: