scFoundation

repository·main·Indexed 19 days ago

https://github.com/biomap-research/scfoundation

A large-scale foundation model for single-cell transcriptomics with 100M parameters. It provides high-dimensional gene and cell embeddings for downstream biological tasks, including cell type annotation, clustering, and drug sensitivity prediction via the DeepCDR model. The repository includes tools for inference, model finetuning, and reproduction notebooks for ablation studies and evaluation.

Tokens
15.4K
Snippets
45
Records
74
Agent score
65%

What's inside scFoundation

  1. Train the DeepCDR model

    main

    You can train the CDR (Cell-Drug Response) prediction model using the run_DeepCDR.py script. The project provides two training modes: a baseline model using gene expression data directly, and an embedding based model that utilizes scFoundation embeddings.

    Before running, ensure you create log and checkpoint directories to capture output and save model weights. The scFoundation embeddings for gene expression data are located at DeepCDR/data/50M-0.1B-res_embedding.npy.

    # Setup directories
    mkdir log
    mkdir checkpoint
    cd ./prog/
    
    ## baseline model
    CUDA_VISIBLE_DEVICES=0 python run_DeepCDR.py -use_gexp > ../log/Base_rep1.log 2>&1
    
    ## embedding based model
    CUDA_VISIBLE_DEVICES=0 python run_DeepCDR.py --ckpt_name 50M-0.1B-res -use_gexp > ../log/50M-0.1B-res_rep1.log 2>&1
  2. Reproduce gene embeddings results

    main

    To reproduce the gene embeddings results, use the notebook plot_geneemb.ipynb. Note that you must have an environment with pyscenic installed to run the reproduction steps successfully.

    # Refer to plot_geneemb.ipynb for reproducing the gene embeddings' results.
    # A environment with pyscenic is needed.
  3. Obtain cell embeddings from scFoundation

    main

    Cell embeddings for downstream tasks can be obtained in two ways:

    1. Pre-computed Embeddings: Use the .npy files provided in this repository for specific datasets.
    2. On-demand Generation: Use the provided API and model code to generate embeddings directly from scFoundation for your own data.

    Pre-computed Embedding Files:

    • Baron dataset: baron_human_samp_19264_fromsaver_50M-0.1B-res_tgthighres5_embedding.npy
    • PBMC68K dataset: Download via Dropbox
  4. Convert gene symbols to match scFoundation index

    main

    scFoundation requires gene symbols to match the specific index provided in OS_scRNA_gene_index.19264.tsv. If your data uses different symbols, use the main_gene_selection function from get_embedding.py to align your data.

    X_df should represent your single-cell data with cells in rows and genes in columns.

    # X_df represents your single cell data with cells in rows and genes in columns
    gene_list_df = pd.read_csv('../OS_scRNA_gene_index.19264.tsv', header=0, delimiter='\t')
    gene_list = list(gene_list_df['gene_name'])
    X_df, to_fill_columns, var = main_gene_selection(X_df, gene_list)
  5. Perform Read Depth Enhancement

    main

    To enhance cell read depth for clustering using scFoundation, use the scripts provided in the enhancement folder. The implementation is demonstrated by running the run.sh bash script within that directory. Detailed documentation is available in enhancement/README.md.

    # Located in the enhancement folder
    run.sh