Skip to content

DMCB-GIST/scRobust

Repository files navigation

scRobust

The robust self-supervised learning strategy to tackle the inherent sparsity of single-cell RNA-seq data

Datasets

https://zenodo.org/records/10602754

Weights

https://zenodo.org/records/10608134 https://zenodo.org/records/12741301

Tutorial

with Python >= 2.1.2, sklearn, scipy, scanpy

from scRobust import *

cuda_condition = torch.cuda.is_available()
device = torch.device("cuda:1" if cuda_condition else "cpu")
scRo = scRobust(device)
adata_path = './data/Processed_Filtered_Segerstolpe_HumanPancreas_data.h5ad'
scRo.read_adata(adata_path)
gene_vocab, tokenizer = scRo.set_vocab()

scRo.set_encoder(hidden = 64*8, n_layers = 1, attn_heads= 8)

## pre_train scRobust
scRo.set_pretraining_model(hidden = 64*8, att_dropout = 0.3)
scRo.train_SSL(epoch = 1000, lr = 0.00005, batch_size = 128, n_ge = 250, save_path = './weights/')

## load weight
weight_path = './weights/Segerstolpe_CL_GE_BERT_Hid_512_Att_8_nGenes_200_ly_1_bt_128_encoder.pt'
scRo.load_encoder_weight(weight_path)

## get cell embeddings
cell_embeddings = scRo.get_cell_embeddings(n_ge = 1000, batch_size = 64)
scRobust_adata = scRo.get_cell_adata(cell_embeddings, umap = False, tsne = True, leiden = True, n_comps = 50, n_neighbors=10, n_pcs=50)

scRobust_adata.obs['label'] = scRo.adata.obs['label']
sc.pl.tsne(scRobust_adata, color='label')
sc.pl.tsne(scRobust_adata, color=['leiden'])


## cell type annotation with pathway vectors

alpha_genes = 'VGF;SYT5;GADD45G;CITED2;FEV;C2CD4B;LOXL4;TBC1D30;C2CD4A;PTP4A3;STC2;LBH;KCNMA1;HERC5;FAP;KCNK17;GLS;RGS4;CRYBA2;APOH;MUC13'
beta_genes = 'DLK1;SYT13;GSN;PRKACB;TGFBR3;SCN1B;SUSD4;PCSK1;NPTX2;EDN3;THBD;CADM1;MEG3;PLCXD3;WSCD2;SIX3;IL17RB;SLC16A9;PDX1;HADH;PRSS23;KCNMA1;KLHDC8A;BMP5;ADRA2A;NEFM;TSPAN1;S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1,FILIP1L,FOS,FOSB,FSTL1,GEM,GGT5,GLUL,GPC6,GPX3,GSN,H19,HGF,HLA-DRB1,HSPB1,IER3,IFITM2,IFITM3,IGFBP3,IGFBP4,IGFBP5,IGFBP7,IL1RL1,INMT,ITGA8,ITGA9,ITGB1,ITGB5,ITM2C,JUNB,KAZN,KLF4,LAMB1,LAMC1,LAMC3,LGALS1,LGALS3BP,LMNA,LRP1,LTBP4,LUM,MAFF,MAP1B,MARCKS,MASP1,MATN2,MFAP4,MGP,MITF,MKNK2,MMP19,MMP2,MT1M,MXRA7,MYADM,MYC,MYH10,MYL9,MYLK,NEXN,NFIA,NFIX,NR2F1,NR2F2,OLFML3,PALLD,PCDH9,PCOLCE,PDGFRA,PHLDA1,PLCXD3,PRELP,CAVIN3,PROS1,PRSS23,PTGDS,PTN,CAVIN1,QSOX1,RBMS3,RBP1,RBPMS,RGS16,RGS2,RGS4,RN7SK,RND3,RRAS,SERPINE1,SERPINF1,SFRP1,SLC38A2,SLIT3,SOCS3,SOD3,SPARC,SRPX,SSPN,SYNPO2,TCEAL4,TCF4,THBS1,THBS2,THY1,TIMP1,TIMP2,TIMP3,TIPARP,TMEM204,TNS1,TPM4,TSC22D1,TSC22D2,VCL,VIM,ZFP36,ZFP36L1'


pathways = ['alpha','beta','delta','gamma','ductal','epsilon','acinar','endothelial','PSC','mast']
target_pathways = [alpha_genes, beta_genes, delta_genes, gamma_genes, ductal_genes, epsilon_genes, acinar_genes,
                  endothelial, psc_genes, mast]

pathway_dict = {}
for i in range(len(target_pathways)):
    pathway = target_pathways[i]
    try:
        pathway.index(';')
        pathway = pathway.split(';')
    except:
        pathway = pathway.split(',')

    pathway_dict[pathways[i]] = pathway

dot_df, pred_y = scRo.cell_type_annotation_with_pathway(pathway_dict)

result_df = pd.concat([scRo.adata.obs['label'],pd.DataFrame(pred_y,columns = ['pred']),dot_df],axis=1)
result_df = result_df[scRo.adata.obs['label'].isin(list(pathway_dict.keys()))]

acc = np.average(result_df['pred'] == result_df['label'])
f1 = f1_score(result_df['label'], result_df['pred'], average='macro')


## analyze HbA1C
clinical_labels = pd.read_csv('./data/Segerstolpe_HumanPancreas_clinical.csv')
sample_ids = clinical_labels['Characteristics [individual]']
sample_ids.index = sample_ids.index.astype(str)

HbA1c_arr = []
count = 0
for i in clinical_labels['Characteristics [clinical information]']:
    try:
        HbA1c_arr.append(float((i[6:9])))
    except:
        HbA1c_arr.append(5.5)
    count +=1
    
HbA1c_arr = np.array(HbA1c_arr)

labels = scRobust_adata.obs['label']
target_cell_type = ['alpha','beta','gamma','delta']

cell_types  = labels[(HbA1c_arr>0) * (labels.isin(target_cell_type))]
HbA1c  = HbA1c_arr[(HbA1c_arr>0) * (labels.isin(target_cell_type))]
s_ids  = sample_ids[(HbA1c_arr>0) *(labels.isin(target_cell_type))]

adata_df = pd.DataFrame(data = cell_embeddings[labels.isin(target_cell_type)],
                               index = labels.index[labels.isin(target_cell_type)])

sc_adata = sc.AnnData(adata_df)   

sc_adata.obs['HbA1c'] = HbA1c 
sc_adata.obs['cell_types'] = cell_types.tolist()
sc_adata.obs['sample_ids'] = s_ids.tolist()

sc.pp.pca(sc_adata, n_comps=50)
sc.pp.neighbors(sc_adata, n_neighbors=10, n_pcs=50)

sc.tl.tsne(sc_adata)
sc.tl.leiden(sc_adata)

sc.pl.tsne(sc_adata, color='HbA1c')    
sc.pl.tsne(sc_adata, color='cell_types')    
sc.pl.tsne(sc_adata, color='sample_ids')   

## Downstream task
indices = ~scRo.adata.obs['label'].isin(['co-expression','unclassified endocrine']).values
scRo.adata = scRo.adata[indices]

n_classes = len(scRo.adata.obs['label'].cat.categories)
scRo.set_downstream_model(hidden = 64*8, n_clssses = n_classes, att_dropout = 0.3)

val_auc, val_loss, val_f1, val_acc, \
        test_auc, test_loss, test_f1, test_acc = scRo.train_DS(epoch = 20, lr = 5e-5, batch_size = 64, n_ge = 800)
cell_embeddings_cell_types

Large scRobust with 8 layers and large vocaburary with 42,160 tokens

from scRobust import *
import scanpy as sc
import pandas as pd
import numpy as np

cuda_condition = torch.cuda.is_available()
device = torch.device("cuda:3" if cuda_condition else "cpu")

scRo = scRobust(device)

vocab_path = './vocab/whole_human_vocab.csv'
adata_path = './data/Processed_Filtered_Segerstolpe_HumanPancreas_data.h5ad'

scRo.load_vocab(vocab_path)

## For the larger version, normalize_total -> log1p step is needed. 
## Processed_Filtered_Segerstolpe_HumanPancreas_data.h5ad has already been pre-processed.
scRo.read_adata(adata_path,normalize_total = False, log1p = False) 

## Pre-processing for being sure. Therefore, it's not necessary.
scRo.adata.X = np.expm1(scRo.adata.X)
sc.pp.normalize_total(scRo.adata, target_sum=1e4)
sc.pp.log1p(scRo.adata)

d = 64; attn_heads = 8; hidden = d*attn_heads; n_layers = 8; n_ge = 400;
scRo.set_encoder(hidden = 64*8, n_layers = n_layers, attn_heads= 8)
scRo.set_pretraining_model(hidden = 64*8, att_dropout = 0.3)

save_path = './weights/test_w_weight_ly8_bt_128'
weight_path = './weights/Whole_Human_BERT_Hid_512_Att_8_nGenes_200_ly_8_bt_256.pt'
scRo.load_model_weight(weight_path)

## can do fine-tuning
train_cl_loss, train_ge_loss, test_cl_loss, test_ge_loss = scRo.train_SSL(epoch = 100, lr = 0.0001, batch_size = 128, 
                                                                              n_ge = n_ge, save_path = save_path, simple = True)

## get cell embeddings
cell_embeddings = scRo.get_cell_embeddings(n_ge = 1000, batch_size = 128, use_HUGs = False, use_HVGs = True, simple = True)
scRobust_adata = scRo.get_cell_adata(cell_embeddings, umap = False, tsne = True, leiden = True, 
                                         n_comps = 50, n_neighbors=10, n_pcs=50)

Overview

Figure1-8

Results

Main_results-8

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages