cisformer 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ cisformer_config/
2
+ dist/
3
+ logs/
4
+ output/
5
+ preprocessed_dataset/
6
+ save/
7
+ cisformer/resource/gene_surround_enhancers_250kbp_idx.pkl
8
+ cisformer/resource/gene_surround_enhancers_250kbp.pkl
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2025 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,175 @@
1
+ Metadata-Version: 2.4
2
+ Name: cisformer
3
+ Version: 1.0.0
4
+ Summary: Cisformer command-line tools
5
+ Project-URL: Homepage, https://github.com/wanglabtongji/Cisformer
6
+ Project-URL: Issues, https://github.com/qihang-zou/Cisformer/issues
7
+ Author-email: Chenfei Wang <08chenfeiwang@tongji.edu.cn>
8
+ License-Expression: MIT
9
+ License-File: LICENCE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+
15
+ # Translation of Single-Cell Data Across Modalities with **Cisformer**
16
+ ![logo](figs/logo.png)
17
+
18
+ ## About
19
+ **Cisformer** is a novel cross-modal deep learning model based on the Transformer architecture. It enables **bidirectional prediction and association between cis-regulatory elements and genes** at the single-cell level, with high efficiency and accuracy.
20
+
21
+ To meet real-world application needs and improve model performance:
22
+ - For the RNA2ATAC task, a trained Cisformer can generate high-quality scATAC-seq data from scRNA-seq inputs.
23
+ - For the ATAC2RNA task, the model can generate pseudo-scRNA-seq data and construct a highly accurate cis-regulatory interaction matrix between cis-elements and genes.
24
+
25
+ ## Documentation
26
+ For detailed usage and examples, see the [official documentation]().
27
+ If you encounter any issues, feel free to open an [issue](https://github.com/qihang-zou/Cisformer/issues).
28
+
29
+ ## Environment Setup
30
+
31
+ ### Miniconda3
32
+ We recommend using [Miniconda3](https://www.anaconda.com/docs/getting-started/miniconda/main) or [Anaconda](https://www.anaconda.com/) as the environment manager. Make sure `conda` is installed.
33
+
34
+ ### Creating the Cisformer Environment
35
+ To get started, copy `requirement.sh` to your local server and run:
36
+ ```bash
37
+ conda create -n cisformer python=3.10
38
+ conda activate cisformer
39
+ bash ./requirement.sh
40
+ ```
41
+ Alternatively, you can install dependencies manually:
42
+ ```bash
43
+ conda create -n cisformer python=3.10
44
+ conda activate cisformer
45
+ conda install numpy=1.23
46
+ conda install pytorch=2.2.1 torchvision=0.17.1 torchaudio=2.2.1 pytorch-cuda=12.1 -c pytorch -c nvidia
47
+ conda install -c conda-forge accelerate==0.22.0
48
+ conda install -c conda-forge scanpy python-igraph leidenalg
49
+ pip install ninja
50
+ pip install flash-attn --no-build-isolation
51
+ pip install torcheval
52
+ conda install tensorboard
53
+ conda install pybedtools
54
+ ```
55
+
56
+ ## Install from PyPI
57
+ ```bash
58
+ pip install cisformer
59
+ ```
60
+
61
+ ---
62
+
63
+ # Quick Start
64
+
65
+ ## Generate Default Config Files
66
+ ```bash
67
+ cisformer generate_default_config
68
+ ```
69
+ This command will create a folder named `cisformer_config` in the current directory, containing the following config files:
70
+ - `accelerate_config.yaml`
71
+ - `atac2rna_config.yaml`
72
+ - `rna2atac_config.yaml`
73
+
74
+ Cisformer uses [Hugging Face Accelerate](https://huggingface.co/docs/accelerate/index) for distributed training. You may need to modify `cisformer_config/accelerate_config.yaml` based on your server setup. See [Accelerate launch docs](https://huggingface.co/docs/accelerate/basic_tutorials/launch) for more information.
75
+
76
+ ## RNA ➝ ATAC
77
+
78
+ ### 1. Configure Parameters (Optional)
79
+ Edit the RNA2ATAC configuration file:
80
+ - `cisformer_config/rna2atac_config.yaml`
81
+ Refer to the [documentation]() for parameter explanations.
82
+
83
+ ### 2. Data Preprocessing
84
+ Cisformer requires raw scRNA-seq and scATAC-seq data in [Scanpy `.h5ad` format](https://scanpy.readthedocs.io/en/stable/tutorials/index.html).
85
+
86
+ To preprocess:
87
+ ```bash
88
+ cisformer data_preprocess -r test_data/rna.h5ad -a test_data/atac.h5ad -s preprocessed_dataset
89
+ ```
90
+ - `-r`: path to RNA `.h5ad` file
91
+ - `-a`: path to ATAC `.h5ad` file
92
+ - `-s`: output directory
93
+
94
+ See the [documentation]() for additional options and output file details.
95
+
96
+ ### 3. Model Training
97
+ ```bash
98
+ cisformer rna2atac_train -t preprocessed_dataset/cisformer_rna2atac_train_dataset -v preprocessed_dataset/cisformer_rna2atac_val_dataset -n rna2atac_test
99
+ ```
100
+ - `-t`: path to training dataset
101
+ - `-v`: path to validation dataset
102
+ - `-n`: project name
103
+
104
+ A `save` directory will be created (or can be customized using `-s`). Inside, you'll find a folder like `2025-05-12_rna2atac_test`, which contains the trained models. Typically, the model from the last epoch performs best.
105
+
106
+ Refer to the [documentation]() for more options and output explanations.
107
+
108
+ ### 4. Prediction
109
+ ```bash
110
+ cisformer rna2atac_predict -r preprocessed_dataset/test_rna.h5ad -m save/2025-05-12_rna2atac_test/epoch34/pytorch_model.bin
111
+ ```
112
+ - `-r`: RNA `.h5ad` file for prediction
113
+ - `-m`: trained model checkpoint
114
+
115
+ The predicted ATAC matrix will be saved to `output/cisformer_predicted_atac.h5ad` by default.
116
+ See the [documentation]() for more.
117
+
118
+ ---
119
+
120
+ ## ATAC ➝ RNA
121
+
122
+ ### 1. Configure Parameters (Optional)
123
+ Edit the ATAC2RNA configuration file:
124
+ - `cisformer_config/atac2rna_config.yaml`
125
+
126
+ See the [documentation]() for details.
127
+
128
+ ### 2. Data Preprocessing
129
+ ```bash
130
+ cisformer data_preprocess -r test_data/rna.h5ad -a test_data/atac.h5ad -s preprocessed_dataset --atac2rna
131
+ ```
132
+ - `--atac2rna` flag indicates this is for the ATAC2RNA direction
133
+ Other arguments are the same as in RNA2ATAC.
134
+
135
+ ### 3. Model Training
136
+ ```bash
137
+ cisformer atac2rna_train -d preprocessed_dataset/cisformer_atac2rna_train_dataset -n atac2rna_test
138
+ ```
139
+ - `-d`: path to ATAC2RNA training dataset
140
+ - `-n`: project name
141
+
142
+ A `save` directory will be created (or customized with `-s`). The folder `2025-05-12_atac2rna_test` will contain the trained model, with the final epoch model usually performing best.
143
+
144
+ ### 4. Prediction (Optional)
145
+ ```bash
146
+ cisformer atac2rna_predict -d preprocessed_dataset/cisformer_atac2rna_test_dataset/atac2rna_0.pt -m save/2025-05-12_atac2rna_test/epoch30/pytorch_model.bin
147
+ ```
148
+ - `-d`: path to test dataset `.pt` file
149
+ - `-m`: trained model checkpoint
150
+
151
+ Output will be saved to `output/cisformer_predicted_rna.h5ad`.
152
+
153
+ ### 5. Link cis-regulators and Genes
154
+ ```bash
155
+ cisformer atac2rna_link -d preprocessed_dataset/cisformer_atac2rna_test_dataset/atac2rna_0.pt -m save/2025-05-12_atac2rna_test/epoch30/pytorch_model.bin -c test_data/celltype_info.tsv
156
+ ```
157
+ - `-d`: test `.pt` file (must be accompanied by `cell_info.tsv` in the same folder)
158
+ - `-m`: trained model
159
+ - `-c`: TSV file mapping each cell barcode to a cell type (no header)
160
+
161
+ Example of `celltype_info.tsv`:
162
+ ```
163
+ GTACCGGGTATACTGG-1 CD14 Mono
164
+ ACTGAATGTCACCAAA-1 cDC2
165
+ AACCTTGCAAACTGTT-1 CD14 Mono
166
+ ...
167
+ ```
168
+
169
+ The output folder `output/cisformer_link` will contain `.h5ad` files linking cis-regulators to genes for each cell type.
170
+
171
+ ---
172
+
173
+ ## Acknowledgements
174
+ - [flash-attention2](https://github.com/Dao-AILab/flash-attention)
175
+ - [Hugging Face](https://huggingface.co/)
@@ -0,0 +1,161 @@
1
+ # Translation of Single-Cell Data Across Modalities with **Cisformer**
2
+ ![logo](figs/logo.png)
3
+
4
+ ## About
5
+ **Cisformer** is a novel cross-modal deep learning model based on the Transformer architecture. It enables **bidirectional prediction and association between cis-regulatory elements and genes** at the single-cell level, with high efficiency and accuracy.
6
+
7
+ To meet real-world application needs and improve model performance:
8
+ - For the RNA2ATAC task, a trained Cisformer can generate high-quality scATAC-seq data from scRNA-seq inputs.
9
+ - For the ATAC2RNA task, the model can generate pseudo-scRNA-seq data and construct a highly accurate cis-regulatory interaction matrix between cis-elements and genes.
10
+
11
+ ## Documentation
12
+ For detailed usage and examples, see the [official documentation]().
13
+ If you encounter any issues, feel free to open an [issue](https://github.com/qihang-zou/Cisformer/issues).
14
+
15
+ ## Environment Setup
16
+
17
+ ### Miniconda3
18
+ We recommend using [Miniconda3](https://www.anaconda.com/docs/getting-started/miniconda/main) or [Anaconda](https://www.anaconda.com/) as the environment manager. Make sure `conda` is installed.
19
+
20
+ ### Creating the Cisformer Environment
21
+ To get started, copy `requirement.sh` to your local server and run:
22
+ ```bash
23
+ conda create -n cisformer python=3.10
24
+ conda activate cisformer
25
+ bash ./requirement.sh
26
+ ```
27
+ Alternatively, you can install dependencies manually:
28
+ ```bash
29
+ conda create -n cisformer python=3.10
30
+ conda activate cisformer
31
+ conda install numpy=1.23
32
+ conda install pytorch=2.2.1 torchvision=0.17.1 torchaudio=2.2.1 pytorch-cuda=12.1 -c pytorch -c nvidia
33
+ conda install -c conda-forge accelerate==0.22.0
34
+ conda install -c conda-forge scanpy python-igraph leidenalg
35
+ pip install ninja
36
+ pip install flash-attn --no-build-isolation
37
+ pip install torcheval
38
+ conda install tensorboard
39
+ conda install pybedtools
40
+ ```
41
+
42
+ ## Install from PyPI
43
+ ```bash
44
+ pip install cisformer
45
+ ```
46
+
47
+ ---
48
+
49
+ # Quick Start
50
+
51
+ ## Generate Default Config Files
52
+ ```bash
53
+ cisformer generate_default_config
54
+ ```
55
+ This command will create a folder named `cisformer_config` in the current directory, containing the following config files:
56
+ - `accelerate_config.yaml`
57
+ - `atac2rna_config.yaml`
58
+ - `rna2atac_config.yaml`
59
+
60
+ Cisformer uses [Hugging Face Accelerate](https://huggingface.co/docs/accelerate/index) for distributed training. You may need to modify `cisformer_config/accelerate_config.yaml` based on your server setup. See [Accelerate launch docs](https://huggingface.co/docs/accelerate/basic_tutorials/launch) for more information.
61
+
62
+ ## RNA ➝ ATAC
63
+
64
+ ### 1. Configure Parameters (Optional)
65
+ Edit the RNA2ATAC configuration file:
66
+ - `cisformer_config/rna2atac_config.yaml`
67
+ Refer to the [documentation]() for parameter explanations.
68
+
69
+ ### 2. Data Preprocessing
70
+ Cisformer requires raw scRNA-seq and scATAC-seq data in [Scanpy `.h5ad` format](https://scanpy.readthedocs.io/en/stable/tutorials/index.html).
71
+
72
+ To preprocess:
73
+ ```bash
74
+ cisformer data_preprocess -r test_data/rna.h5ad -a test_data/atac.h5ad -s preprocessed_dataset
75
+ ```
76
+ - `-r`: path to RNA `.h5ad` file
77
+ - `-a`: path to ATAC `.h5ad` file
78
+ - `-s`: output directory
79
+
80
+ See the [documentation]() for additional options and output file details.
81
+
82
+ ### 3. Model Training
83
+ ```bash
84
+ cisformer rna2atac_train -t preprocessed_dataset/cisformer_rna2atac_train_dataset -v preprocessed_dataset/cisformer_rna2atac_val_dataset -n rna2atac_test
85
+ ```
86
+ - `-t`: path to training dataset
87
+ - `-v`: path to validation dataset
88
+ - `-n`: project name
89
+
90
+ A `save` directory will be created (or can be customized using `-s`). Inside, you'll find a folder like `2025-05-12_rna2atac_test`, which contains the trained models. Typically, the model from the last epoch performs best.
91
+
92
+ Refer to the [documentation]() for more options and output explanations.
93
+
94
+ ### 4. Prediction
95
+ ```bash
96
+ cisformer rna2atac_predict -r preprocessed_dataset/test_rna.h5ad -m save/2025-05-12_rna2atac_test/epoch34/pytorch_model.bin
97
+ ```
98
+ - `-r`: RNA `.h5ad` file for prediction
99
+ - `-m`: trained model checkpoint
100
+
101
+ The predicted ATAC matrix will be saved to `output/cisformer_predicted_atac.h5ad` by default.
102
+ See the [documentation]() for more.
103
+
104
+ ---
105
+
106
+ ## ATAC ➝ RNA
107
+
108
+ ### 1. Configure Parameters (Optional)
109
+ Edit the ATAC2RNA configuration file:
110
+ - `cisformer_config/atac2rna_config.yaml`
111
+
112
+ See the [documentation]() for details.
113
+
114
+ ### 2. Data Preprocessing
115
+ ```bash
116
+ cisformer data_preprocess -r test_data/rna.h5ad -a test_data/atac.h5ad -s preprocessed_dataset --atac2rna
117
+ ```
118
+ - `--atac2rna` flag indicates this is for the ATAC2RNA direction
119
+ Other arguments are the same as in RNA2ATAC.
120
+
121
+ ### 3. Model Training
122
+ ```bash
123
+ cisformer atac2rna_train -d preprocessed_dataset/cisformer_atac2rna_train_dataset -n atac2rna_test
124
+ ```
125
+ - `-d`: path to ATAC2RNA training dataset
126
+ - `-n`: project name
127
+
128
+ A `save` directory will be created (or customized with `-s`). The folder `2025-05-12_atac2rna_test` will contain the trained model, with the final epoch model usually performing best.
129
+
130
+ ### 4. Prediction (Optional)
131
+ ```bash
132
+ cisformer atac2rna_predict -d preprocessed_dataset/cisformer_atac2rna_test_dataset/atac2rna_0.pt -m save/2025-05-12_atac2rna_test/epoch30/pytorch_model.bin
133
+ ```
134
+ - `-d`: path to test dataset `.pt` file
135
+ - `-m`: trained model checkpoint
136
+
137
+ Output will be saved to `output/cisformer_predicted_rna.h5ad`.
138
+
139
+ ### 5. Link cis-regulators and Genes
140
+ ```bash
141
+ cisformer atac2rna_link -d preprocessed_dataset/cisformer_atac2rna_test_dataset/atac2rna_0.pt -m save/2025-05-12_atac2rna_test/epoch30/pytorch_model.bin -c test_data/celltype_info.tsv
142
+ ```
143
+ - `-d`: test `.pt` file (must be accompanied by `cell_info.tsv` in the same folder)
144
+ - `-m`: trained model
145
+ - `-c`: TSV file mapping each cell barcode to a cell type (no header)
146
+
147
+ Example of `celltype_info.tsv`:
148
+ ```
149
+ GTACCGGGTATACTGG-1 CD14 Mono
150
+ ACTGAATGTCACCAAA-1 cDC2
151
+ AACCTTGCAAACTGTT-1 CD14 Mono
152
+ ...
153
+ ```
154
+
155
+ The output folder `output/cisformer_link` will contain `.h5ad` files linking cis-regulators to genes for each cell type.
156
+
157
+ ---
158
+
159
+ ## Acknowledgements
160
+ - [flash-attention2](https://github.com/Dao-AILab/flash-attention)
161
+ - [Hugging Face](https://huggingface.co/)