Figure 1: Overview of the CellSexID workflow and validation approach.
CellSexID: Sex-Based Computational Tracking of Cellular Origins in Chimeric Models
Read the paper on bioRxiv
CellSexID predicts biological sex from single-cell RNA-seq data using machine learning approaches with automatic feature selection capabilities.
- Sample demultiplexing: Identify sex for mixed-sex samples without prior knowledge
- Quality control: Verify reported sex labels in published datasets
- Organ transplantation studies: Track donor vs recipient cells by sex
- Cross-tissue analysis: Apply models trained on one tissue to predict sex in another
- Species translation: Adapt human-trained models for mouse studies
- Machine learning models (Logistic Regression, SVM, XGBoost, Random Forest)
- Automatic gene discovery with cross-validation feature selection
- Predefined sex marker genes for human and mouse
- Cross-dataset validation and batch effect handling
- Command-line interface and Python API
# Install from GitHub
pip install git+https://github.com/mcgilldinglab/CellSexID.git
# Or clone and install locally
git clone https://github.com/mcgilldinglab/CellSexID.git
cd CellSexID
pip install .# Clone repository
git clone https://github.com/mcgilldinglab/CellSexID.git
cd CellSexID
# Create clean environment
conda create -n cellsexid python=3.9
conda activate cellsexid
# Install dependencies and package
pip install -e .git clone https://github.com/mcgilldinglab/CellSexID.git
cd CellSexID
pip install -r requirements.txtTraining data: Extract preprocessed_training_data.h5ad.zip - ready to use immediately
Test datasets: Extract data.zip for additional validation datasets
# Mouse data with predefined markers
cellsexid --species mouse --train train.h5ad --test test.h5ad --output predictions.csv
# Human data with predefined markers
cellsexid --species human --train train.h5ad --test test.h5ad --output predictions.csv
# Custom marker discovery
cellsexid --species mouse --marker_train discovery.h5ad train.h5ad --test test.h5ad --output predictions.csvfrom cellsexid import SexPredictionTool
# Initialize and train
tool = SexPredictionTool(species='mouse', use_predefined_genes=True)
tool.fit(train_data='train.h5ad')
# Make predictions
predictions, cell_names = tool.predict(test_data='test.h5ad')
tool.save_predictions(predictions, cell_names, 'predictions.csv')cellsexid --help# Mouse with predefined markers
cellsexid --species mouse --train train.h5ad --test test.h5ad --output results.csv
# Human with predefined markers
cellsexid --species human --train train.h5ad --test test.h5ad --output results.csv
# Custom genes
cellsexid --species mouse --train train.h5ad --test test.h5ad --output results.csv \
--custom_genes "Xist,Ddx3y,Kdm5d,Eif2s3y"# Discover markers + train + test (3 separate files)
cellsexid --species human --marker_train marker.h5ad train.h5ad --test test.h5ad --output results.csv
# Same data for marker discovery and training (most common)
cellsexid --species mouse --marker_train train.h5ad train.h5ad --test test.h5ad --output results.csv# Choose different model
cellsexid --species mouse --train train.h5ad --test test.h5ad --output results.csv --model XGB
# Custom sex column name
cellsexid --species human --train train.h5ad --test test.h5ad --output results.csv --sex_column gender
# Generate distribution plot
cellsexid --species mouse --train train.h5ad --test test.h5ad --output results.csv --plot distribution.png
# Feature selection parameters for marker discovery
cellsexid --species mouse --marker_train train.h5ad train.h5ad --test test.h5ad --output results.csv \
--top_k 15 --min_models 2
# Verbose output
cellsexid --species mouse --train train.h5ad --test test.h5ad --output results.csv --verboseCellSexID accepts .h5ad files (AnnData format) with:
adata.X # Expression matrix (cells × genes)
adata.obs["sex"] # Sex labels: "Male"/"Female" or "M"/"F" or 0/1
adata.var_names # Gene symbolsData should be preprocessed (filtered, normalized, log-transformed). See tutorials for preprocessing examples.
Comprehensive Python script demonstrating all features of the SexPredictionTool API, including:
- Example 1: Basic usage with predefined gene markers (2-dataset workflow)
- Example 2: Using custom gene markers (2-dataset workflow)
- Example 3: Automatic feature selection (3-dataset workflow)
- Example 4: Model comparison across all available algorithms
- Example 5: Human species analysis with custom sex column names
- Example 6: CLI command simulation and programmatic usage
Run the tutorial:
# Run all examples
python run_prediction.py
# Run specific example
python run_prediction.py --example 1
# Customize data paths
python run_prediction.py --train_data your_train.h5ad --test_data your_test.h5adDemonstrates sex prediction for mouse and human single-cell datasets, covering data preprocessing, model training with multiple algorithms, and cross-validation evaluation.
Cross-tissue validation by training models on one tissue type and testing on another, addressing tissue-specific expression variations.
Cross-tissue sex prediction using mouse single-cell data, demonstrating model transfer capabilities across different tissue types.
The SexPredictionTool class provides the main interface for sex prediction:
__init__(species, use_predefined_genes, custom_genes, sex_column): Initialize the toolfit(train_data, model_name): Train model with predefined/custom genespredict(test_data): Make sex predictionsdiscover_markers(marker_data, top_k, min_models): Automatic feature selectionfit_with_discovered_markers(train_data, model_name): Train with discovered markerssave_predictions(predictions, cell_names, output_file): Save resultsplot_prediction_distribution(predictions, plot_file): Generate visualization
'LR': Logistic Regression'SVM': Support Vector Machine'XGB': XGBoost Classifier'RF': Random Forest (default)
'mouse': Mouse-specific gene markers'human': Human-specific gene markers
See API.md for detailed documentation of all classes, methods, and parameters.
cell_id,predicted_sex
CELL001,Female
CELL002,Male
CELL003,Femalefeature_selection_results/
├── LogisticRegression_feature_importances.csv
├── SVC_feature_importances.csv
├── XGBClassifier_feature_importances.csv
├── RandomForestClassifier_feature_importances.csv
└── selected_genes_majority_vote.csv
Visual representations of prediction distributions saved as PNG files when using the --plot option or plot_prediction_distribution() method.
@article{tai2024cellsexid,
title={CellSexID: A Tool for Predicting Sex from Single-Cell RNA-Seq Data},
author={Tai, Huilin and Li, Qian and Wang, Jingtao and Tan, Jiahui and Lang, Ryann and Petrof, Basil J and Ding, Jun},
journal={bioRxiv},
year={2024},
publisher={Cold Spring Harbor Laboratory}
}MIT License - see LICENSE file for details.
- Issues: GitHub Issues
- API Tutorial: See
run_prediction.pyfor comprehensive Python API examples - Contact: huilin.tai@mail.mcgill.ca