import hisepy
import os
import pandas as pd
import scanpy as sc
def read_adata_uuid(h5ad_uuid):
h5ad_path = '/home/jupyter/cache/{u}'.format(u = h5ad_uuid)
if not os.path.isdir(h5ad_path):
hise_res = hisepy.reader.cache_files([h5ad_uuid])
h5ad_filename = os.listdir(h5ad_path)[0]
h5ad_file = '{p}/{f}'.format(p = h5ad_path, f = h5ad_filename)
adata = sc.read_h5ad(h5ad_file)
return adata
def read_parquet_uuid(pq_uuid):
pq_path = '/home/jupyter/cache/{u}'.format(u = pq_uuid)
if not os.path.isdir(pq_path):
hise_res = hisepy.reader.cache_files([pq_uuid])
pq_filename = os.listdir(pq_path)[0]
pq_file = '{p}/{f}'.format(p = pq_path, f = pq_filename)
df = pd.read_parquet(pq_file)
return df
cell_class = 't-cells'
h5ad_uuid = 'd6ebc576-34ea-4394-a569-e35e16f20253'
adata = read_adata_uuid(h5ad_uuid)
anno_uuid = '75cb6602-0179-4128-9171-83c269a2b340'
anno = read_parquet_uuid(anno_uuid)
anno.head()
barcodes | AIFI_L1 | AIFI_L2 | AIFI_L3 | |
---|---|---|---|---|
0 | cf71f47048b611ea8957bafe6d70929e | T cell | MAIT | CD8 MAIT |
1 | cf71f54248b611ea8957bafe6d70929e | T cell | Naive CD4 T cell | Core naive CD4 T cell |
2 | cf71fb7848b611ea8957bafe6d70929e | T cell | Memory CD4 T cell | CM CD4 T cell |
3 | cf7216a848b611ea8957bafe6d70929e | T cell | Memory CD4 T cell | GZMB- CD27+ EM CD4 T cell |
4 | cf72178448b611ea8957bafe6d70929e | T cell | Naive CD4 T cell | SOX4+ naive CD4 T cell |
obs = adata.obs
obs = obs.reset_index(drop = True)
obs = obs.merge(anno, on = 'barcodes', how = 'left')
obs = obs.set_index('barcodes', drop = False)
adata.obs = obs
exclude_terms = [
'Contamination', 'contamination',
'Doublet', 'doublet',
'Mito', 'mito'
]
all_types = adata.obs['AIFI_L3'].unique().tolist()
exclude_types = []
for cell_type in all_types:
for term in exclude_terms:
if term in cell_type:
exclude_types.append(cell_type)
exclude_types
['Contamination', 'Naive CD8 T cell Platelet Doublets', 'C5_C12_Contamination', 'Proliferating Cells+Monocytes Doublets', 'CD4 naive Platelet Doublets', 'CD4 naive CD16 Monocytes Doublets']
keep_types = []
for cell_type in all_types:
if not cell_type in exclude_types:
keep_types.append(cell_type)
adata = adata[adata.obs['AIFI_L3'].isin(keep_types)]
adata.shape
(1157700, 1487)
l2_markers = [
'CD3E', 'CD4', 'CD8A', 'TRAC', 'TRDC',
'LEF1', 'TCF7', 'CCR7', 'SELL', 'ITGB1',
'FAS', 'CD27', 'CD28', 'FOXP3', 'RTKN2',
'IKZF2', 'ZNF683', 'NKG7', 'KLRC2', 'KLRF1',
'KLRB1', 'KLRD1', 'GZMA', 'GZMK', 'GZMB',
'PRF1', 'GNLY', 'IFI44L', 'IRF7', 'MKI67',
'TRDV1', 'TRDV2', 'TRDV3', 'MME', 'SOX4'
]
Set L2 category order
category_order = [
'Naive CD4 T cell',
'Naive CD8 T cell',
'DN T cell',
'Memory CD4 T cell',
'Treg',
'Proliferating T cell',
'MAIT',
'CD8aa',
'Memory CD8 T cell',
'gdT'
]
adata.obs['AIFI_L2'] = (
adata.obs['AIFI_L2']
.cat
.set_categories(category_order, ordered=True)
)
/tmp/ipykernel_4263/4156893413.py:14: ImplicitModificationWarning: Trying to modify attribute `.obs` of view, initializing view as actual. adata.obs['AIFI_L2'] = (
sc.pl.dotplot(
adata,
groupby = 'AIFI_L2',
var_names = l2_markers,
log = True
)
/opt/conda/lib/python3.10/site-packages/scanpy/plotting/_dotplot.py:168: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning. obs_bool.groupby(level=0).sum() / obs_bool.groupby(level=0).count() /opt/conda/lib/python3.10/site-packages/scanpy/plotting/_dotplot.py:178: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning. dot_color_df = self.obs_tidy.groupby(level=0).mean() /opt/conda/lib/python3.10/site-packages/scanpy/plotting/_dotplot.py:747: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap', 'norm' will be ignored dot_ax.scatter(x, y, **kwds)
l3_markers = [
'CD27', 'CD28', 'KLRF1', 'KLRB1', 'KLRD1',
'KLRC1', 'KLRC2', 'GZMA', 'GZMB', 'GZMK',
'GZMH', 'PRF1', 'CCL5', 'GNLY', 'GATA3',
'TBX21', 'EOMES', 'LEF1', 'TCF7', 'IKZF2',
'SOX4', 'IFI44L'
]
Set L3 category order
category_order = [
'Naive CD4 Treg',
'Core naive CD8 T cell',
'SOX4+ naive CD8 T cell',
'Core naive CD4 T cell',
'SOX4+ naive CD4 T cell',
'CM CD4 T cell',
'GZMB- CD27- EM CD4 T cell',
'ISG+ memory CD4 T cell',
'ISG+ memory CD8 T cell',
'ISG+ naive CD4 T cell',
'ISG+ naive CD8 T cell',
'Proliferating T cell',
'DN T cell',
'KLRB1+ memory CD8 Treg',
'GZMK+ memory CD4 Treg',
'KLRB1+ memory CD4 Treg',
'Memory CD4 Treg',
'Memory CD8 Treg',
'KLRF1- GZMB+ CD27- EM CD8 T cell',
'KLRF1- GZMB+ CD27- memory CD4 T cell',
'KLRF1- effector Vd1 gdT',
'KLRF1+ GZMB+ CD27- EM CD8 T cell',
'KLRF1+ effector Vd1 gdT',
'GZMK+ CD27+ EM CD8 T cell',
'GZMB+ Vd2 gdT',
'GZMK+ Vd2 gdT',
'CD8aa',
'Naive Vd1 gdT',
'SOX4+ Vd1 gdT',
'ISG+ MAIT',
'CD4 MAIT',
'CD8 MAIT',
'GZMB- CD27+ EM CD4 T cell',
'CM CD8 T cell',
'GZMK- CD27+ EM CD8 T cell'
]
adata.obs['AIFI_L3'] = (
adata.obs['AIFI_L3']
.cat
.set_categories(category_order, ordered=True)
)
sc.pl.dotplot(
adata,
groupby = 'AIFI_L3',
var_names = l3_markers,
log = True
)
/opt/conda/lib/python3.10/site-packages/scanpy/plotting/_dotplot.py:168: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning. obs_bool.groupby(level=0).sum() / obs_bool.groupby(level=0).count() /opt/conda/lib/python3.10/site-packages/scanpy/plotting/_dotplot.py:178: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning. dot_color_df = self.obs_tidy.groupby(level=0).mean() /opt/conda/lib/python3.10/site-packages/scanpy/plotting/_dotplot.py:747: UserWarning: No data for colormapping provided via 'c'. Parameters 'cmap', 'norm' will be ignored dot_ax.scatter(x, y, **kwds)
import session_info
session_info.show()
----- anndata 0.10.3 hisepy 0.3.0 pandas 2.1.4 scanpy 1.9.6 session_info 1.0.0 -----
PIL 10.0.1 anyio NA arrow 1.3.0 asttokens NA attr 23.2.0 attrs 23.2.0 babel 2.14.0 beatrix_jupyterlab NA brotli NA cachetools 5.3.1 certifi 2024.02.02 cffi 1.16.0 charset_normalizer 3.3.2 cloudpickle 2.2.1 colorama 0.4.6 comm 0.1.4 cryptography 41.0.7 cycler 0.10.0 cython_runtime NA dateutil 2.8.2 db_dtypes 1.1.1 debugpy 1.8.0 decorator 5.1.1 defusedxml 0.7.1 deprecated 1.2.14 exceptiongroup 1.2.0 executing 2.0.1 fastjsonschema NA fqdn NA google NA greenlet 2.0.2 grpc 1.58.0 grpc_status NA h5py 3.10.0 idna 3.6 igraph 0.10.8 importlib_metadata NA ipykernel 6.28.0 ipython_genutils 0.2.0 ipywidgets 8.1.1 isoduration NA jedi 0.19.1 jinja2 3.1.2 joblib 1.3.2 json5 NA jsonpointer 2.4 jsonschema 4.20.0 jsonschema_specifications NA jupyter_events 0.9.0 jupyter_server 2.12.1 jupyterlab_server 2.25.2 jwt 2.8.0 kiwisolver 1.4.5 leidenalg 0.10.1 llvmlite 0.41.0 lz4 4.3.2 markupsafe 2.1.3 matplotlib 3.8.0 matplotlib_inline 0.1.6 mpl_toolkits NA mpmath 1.3.0 natsort 8.4.0 nbformat 5.9.2 numba 0.58.0 numpy 1.24.0 opentelemetry NA overrides NA packaging 23.2 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 pkg_resources NA platformdirs 4.1.0 plotly 5.18.0 prettytable 3.9.0 prometheus_client NA prompt_toolkit 3.0.42 proto NA psutil NA ptyprocess 0.7.0 pure_eval 0.2.2 pyarrow 13.0.0 pydev_ipython NA pydevconsole NA pydevd 2.9.5 pydevd_file_utils NA pydevd_plugins NA pydevd_tracing NA pygments 2.17.2 pynvml NA pyparsing 3.1.1 pyreadr 0.5.0 pythonjsonlogger NA pytz 2023.3.post1 referencing NA requests 2.31.0 rfc3339_validator 0.1.4 rfc3986_validator 0.1.1 rpds NA scipy 1.11.4 send2trash NA shapely 1.8.5.post1 six 1.16.0 sklearn 1.3.2 sniffio 1.3.0 socks 1.7.1 sql NA sqlalchemy 2.0.21 sqlparse 0.4.4 stack_data 0.6.2 sympy 1.12 termcolor NA texttable 1.7.0 threadpoolctl 3.2.0 torch 2.1.2+cu121 torchgen NA tornado 6.3.3 tqdm 4.66.1 traitlets 5.9.0 typing_extensions NA uri_template NA urllib3 1.26.18 wcwidth 0.2.12 webcolors 1.13 websocket 1.7.0 wrapt 1.15.0 xarray 2023.12.0 yaml 6.0.1 zipp NA zmq 25.1.2 zoneinfo NA
----- IPython 8.19.0 jupyter_client 8.6.0 jupyter_core 5.6.1 jupyterlab 4.1.2 notebook 6.5.4 ----- Python 3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:36:39) [GCC 12.3.0] Linux-5.15.0-1052-gcp-x86_64-with-glibc2.31 ----- Session information updated at 2024-03-07 21:46