Build Training Cell Corpus from Cellxgene Census
- This documentation describes the procedure for building the pre-training cell corpus from the cellxgene census.
- Please note that this script is designed to run on a cluster with the SLURM workload manager for parallelization.
- You may need to modify the scripts to run on your own system.
- Internet access is required for querying the cellxgene census dataset.
- The scripts referred to in this document are located in the
/data/cellxgenedirectory.
General Workflow for Cell Corpus Construction
The general workflow is:
- (Optional) Configure the query list and query conditions.
- Build the cell index files based on query
- Download the dataset in
h5adchunks - Transform the
h5adintoscb(single-cell bank for high-performance IO)
(Optional) Configure the Query List and Query Conditions
- If you wish to customize your pre-training dataset, you may modify the
data_config.pyfile andquery_list.txtfile. - In the
data_config.pyfile,MAJOR_TISSUE_LISTrefers to the general organ system defined in the cellxgene census; it defines the resolution we used to store the cells.VERSIONrefers to the version of the cellxgene census; we used the version2023-05-08for our experiments. You may change it to the latest/LTS version. Check out the cellxgene census release plan for more information.- As we only use normal cells for pre-training, we filter the dataset by the
DISEASEcolumn in the cellxgene census. - For the
pan-cancermodel, we filter the dataset by theDISEASEcolumn in the cellxgene census. The filtered cancer list is defined in thecancer_list.txtfile. You may modify it according to your own needs.
Build the Cell Index Files Based on Query
- We first query cells from the cellxgene census and filter the cells according to our needs.
INDEX_PATHis the path to the cell index file (to be generated), cell index is the SOMA id (unique index in cellxgene census) for each cell in the cellxgene census.QUERY_PATHis the path to the query file; each line in the query file is a general organ system defined in the cellxgene census.
- Replace them in the following command and run it to generate the cell index file:
INDEX_PATH="path/to/index"
QUERY_PATH="path/to/query"
./build_soma_idx.sh $INDEX_PATH $QUERY_PATH
Download the Dataset in Chunks
- We download the dataset in chunks; each chunk contains a maximum of 200000 cells, and the chunk size can be modified by changing the
MAX_PARTITION_SIZEin thedownload_partition.shfile. - Before running the script, you need to modify the
DATA_PATH,QUERY_PATHandINDEX_PATHin thearray_download_partition.shfile.- Keep the
INDEX_PATHandQUERY_PATHconsistent with the previous step. DATA_PATHis the path to the directory to store the downloaded dataset. The resulting dataset will be stored in theh5adformat.
- Keep the
- Submit it to download the dataset (each compute node will need internet access):
sbatch array_download_partition.sh
Build the scb Files
- We preprocess the dataset and then transform the
h5adintoscb(single-cell bank for high-performance I/O). - Before running the script, you need to modify the
DATA_PATH,OUTPUT_PATH,QUERY_PATH, andVOCAB_PATHin thearray_build_scb.shfile.- Keep the
DATA_PATHandQUERY_PATHconsistent with the previous step. OUTPUT_PATHis the path to store thescbfiles.VOCAB_PATHis the path to the vocabulary file, which is used to map the gene id to token id.
- Keep the
- Then simply submit the job to the cluster by:
sbatch array_build_scb.sh