This code is developed for: Improved CRISPR/Cas9 Off-target Prediction with DNABERT and Epigenetic Features
- This version of the code includes updates and improvements made during the journal revision process.
- Python interpreter == 3.10.13
- numpy == 2.0.2
- pandas == 2.2.3
- scikit-learn == 1.6.1
- torch == 2.5.1
- transformers == 4.48.3
- Paper Title: Generating, modeling and evaluating a large-scale set of CRISPR/Cas9 off-target sites with bulges
- GitHub link: GRU-Emb
- Reimplementation code: ./src/models/gru_embed_2024.py
- Paper Title: Interpretable CRISPR/Cas9 off-target activities with mismatches and indels prediction using BERT
- GitHub link: CRISPR-BERT
- Reimplementation code: ./src/models/crispr_bert_2024.py
- Paper Title: Prediction of CRISPR-Cas9 off-target activities with mismatches and indels based on hybrid neural network
- GitHub link: CRISPR-HW
- Reimplementation code: ./src/models/crispr_hw_2023.py
- Paper Title: CRISPR-DIPOFF: an interpretable deep learning approach for CRISPR Cas-9 off-target prediction
- GitHub link: CRISPR-DIPOFF
- Reimplementation code: ./src/models/crispr_dipoff_2025.py
- Paper Title: Predicting CRISPR-Cas9 off-target effects in human primary cells using bidirectional LSTM with BERT embedding
- GitHub link: CrisprBERT
- Reimplementation code: ./src/models/crispr_bert_2025.py
The following operations need to be performed as part of the prerequisites:
-
Download the Dataset
- Download the dataset from Yaish et al.'s GitHub repository. The file can be downloaded from this link.
- Extract the downloaded file.
- Set the path to the dataset in the
config.yamlfile. - For the Schmid-Burgk 2020 TTISS dataset, download the raw sequence data from SRA (accession: PRJNA602092).Then, process the data according to the steps outlined in
/data_processing/Schmid-Burgk_2020/implement.md. This involves downloading FASTQ files, preprocessing, mapping to the reference genome, identifying off-target candidates with SWOffinder, and counting double-strand breaks.
-
Download Pretrained DNABERT Files
- Download the pretrained DNABERT files from HuggingFace. The DNABERT model is available at this link.
- Set the path to the saved DNABERT files in the
config.yamlfile.
-
Download CRISPR-BERT Configuration Files
- Download the CRISPR-BERT model configuration files from this link.
- Set the path to the saved configuration files in the
config.yamlfile.
-
Set Other File Paths
- Set the paths to other necessary files in
config.yamlas required.
- Set the paths to other necessary files in
To fine-tune DNABERT for the mismatch prediction task, run the following command:
python3 src/models/pair_finetuning_dnabert.py --pretrainTo preprocess the data for the models, run the following command:
python3 src/run_preprocess.py --model <model_name> --dataset <dataset_name>To train and test the model for the off-target effect prediction task, use the following command as an example:
python3 src/run_model.py --model DNABERT --dataset_in_cellula Lazzarotto_2020_GUIDE_seq --dataset_in_vitro Lazzarotto_2020_CHANGE_seq --fold 0 --iter 0 --train --exe_type transfer--model,-m: Specifies the deep learning model. Options areDNABERT,DNABERT-No-Pretrained,GRU-Embed,CRISPR-BERT,CRISPR-HW,CRISPR-DIPOFF,CrisprBERT.--dataset_in_cellula,-dsc: Specifies the in cellula dataset.--dataset_in_vitro,-dsv: Specifies the in vitro dataset.--foldf,-f: An integer from 0 to 13. This corresponds to the fold number for 10-fold cross-validation. Default is 0.-iter,-i: An integer. Changing this value will change the random seed used in the code, useful for running multiple experiments. Default is 0.--train: Include this flag to train the model.--test: Include this flag to test the model.--with_epigenetic,-epi: Include this flag to use epigenetic features.--using_epi_data,-uepi: Specifies the epigenetic data to use (e.g., atac,h3k27ac,h3k4me3).--exe_type,-exe: Specifies the execution type (scratch or transfer).
To display the results from multiple models, use the following command as an example:
python3 src/run_result.py --models GRU-Embed,CRISPR-BERT,CRISPR-HW,CRISPR-DIPOFF,CrisprBERT,DNABERT --dataset Lazzarotto_2020_GUIDE_seq --folds 0,1,2,3,4,5,6,7,8,9,10,11,12,13 --iters 0,1,2,3,4 --exe_type transfer --include_epi_transferKai Kimata
kkaibioinformatics(at-mark)gmail_domain
October 17 2025
本コードは以下の論文向けに実装: Improved CRISPR/Cas9 Off-target Prediction with DNABERT and Epigenetic Features
- Python interpreter == 3.10.13
- numpy == 2.0.2
- pandas == 2.2.3
- scikit-learn == 1.6.1
- torch == 2.5.1
- transformers == 4.48.3
- 論文タイトル: Generating, modeling and evaluating a large-scale set of CRISPR/Cas9 off-target sites with bulges
- GitHubリンク: GRU-Emb
- 再実装コード:
./src/models/gru_embed_2024.py
- 論文タイトル: Interpretable CRISPR/Cas9 off-target activities with mismatches and indels prediction using BERT
- GitHubリンク: CRISPR-BERT
- 再実装コード:
./src/models/crispr_bert_2024.py
- 論文タイトル: Prediction of CRISPR-Cas9 off-target activities with mismatches and indels based on hybrid neural network
- GitHubリンク: CRISPR-HW
- 再実装コード:
./src/models/crispr_hw_2023.py
- 論文タイトル: CRISPR-DIPOFF: an interpretable deep learning approach for CRISPR Cas-9 off-target prediction
- GitHubリンク: CRISPR-DIPOFF
- 再実装コード:
./src/models/crispr_dipoff_2025.py
- 論文タイトル: Predicting CRISPR-Cas9 off-target effects in human primary cells using bidirectional LSTM with BERT embedding
- GitHubリンク: CrisprBERT
- 再実装コード:
./src/models/crispr_bert_2025.py
前準備として以下の操作を実行:
-
データセットのダウンロード
- Yaish et al.のGitHubリポジトリからデータセットをダウンロードする。ファイルは本リンクからダウンロード可能。
- ダウンロードしたファイルを解凍する。
- データセットのパスを
config.yamlファイルに設定する。 Schmid-Burgk 2020 TTISSデータセットについては、SRA(アクセッション: PRJNA602092)から生シーケンスデータをダウンロードする。その後、/data_processing/Schmid-Burgk_2020/implement.mdに記載されている手順に従ってデータを処理する。これには、FASTQファイルのダウンロード、前処理、リファレンスゲノムへのマッピング、SWOffinderによるオフターゲット候補の同定、二本鎖切断のカウントが含まれる。
-
事前学習済みDNABERTファイルのダウンロード
- HuggingFaceから事前学習済みDNABERTファイルをダウンロードする。DNABERTモデルは本リンクで公開。
- 保存したDNABERTファイルのパスを
config.yamlファイルに設定する。
-
CRISPR-BERT設定ファイルのダウンロード
- CRISPR-BERTモデルの設定ファイルを本リンクからダウンロード。
- 保存した設定ファイルのパスを
config.yamlファイルに設定する。
-
その他のファイルパスの設定
- 必要なファイルのパスを
config.yamlファイルに設定。
- 必要なファイルのパスを
DNABERTをミスマッチ予測タスク用にファインチューニング。:
python3 script/dnabert_pair_ft.py --pretrainTo preprocess the data for the models, run the following command:
python3 src/run_preprocess.py --model <model_name> --dataset <dataset_name>オフターゲット効果予測タスクのモデルを訓練およびテスト。コマンド実行例:
python3 src/run_model.py --model DNABERT --dataset_in_cellula Lazzarotto_2020_GUIDE_seq --dataset_in_vitro Lazzarotto_2020_CHANGE_seq --fold 0 --iter 0 --train --exe_type transfer--model,-m: 深層学習モデルを指定する。選択肢は、DNABERT,DNABERT-No-Pretrained,GRU-Embed,CRISPR-BERT,CRISPR-HW,CRISPR-DIPOFF,CrisprBERT。--dataset_in_cellula,-dsc: in cellulaデータセットを指定する。--dataset_in_vitro,-dsv: in vitroデータセットを指定する。--foldf,-f: 0から13の整数。交差検証の交差数に対応する。デフォルトは0。-iter,-i: 整数。この値を変更すると、コード内のランダムシードが変更される。複数回の実験を実施したい場合に使用する。デフォルトは0。--train: このフラグを含めると、モデルの訓練が実行される。--test: このフラグを含めると、モデルのテストが実行される。--with_epigenetic,-epi: エピジェネティックな特徴を使用する場合に、このフラグを含める。--using_epi_data,-uepi: 使用するエピジェネティックデータを指定する (例: atac,h3k27ac,h3k4me3)。--exe_type,-exe: 実行タイプを指定する (scratch または transfer)。
複数のモデルの結果を表示する。コマンド実行例:
python3 src/run_result.py --models GRU-Embed,CRISPR-BERT,CRISPR-HW,CRISPR-DIPOFF,CrisprBERT,DNABERT --dataset Lazzarotto_2020_GUIDE_seq --folds 0,1,2,3,4,5,6,7,8,9,10,11,12,13 --iters 0,1,2,3,4 --exe_type transfer --include_epi_transfer