esmrank 0.1.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.
esmrank-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
esmrank-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,292 @@
1
+ Metadata-Version: 2.4
2
+ Name: esmrank
3
+ Version: 0.1.0
4
+ Summary: A learn-to-rank approach for protein variant effect prediction
5
+ Author: Riccardo Arnese, Gennaro Gambardella
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/gambalab/ESMRank
8
+ Project-URL: Issues, https://github.com/gambalab/ESMRank/issues
9
+ Keywords: protein,variant effect prediction,learning to rank,protein language model,bioinformatics
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: numpy>=2.0
22
+ Requires-Dist: pandas>=2.2
23
+ Requires-Dist: scikit-learn>=1.5
24
+ Requires-Dist: scipy>=1.13
25
+ Requires-Dist: tqdm>=4.66
26
+ Requires-Dist: xgboost<3,>=2.1
27
+ Requires-Dist: edlib>=1.3.9
28
+ Requires-Dist: pyhmmer<0.12,>=0.11
29
+ Requires-Dist: biopython>=1.85
30
+ Requires-Dist: transformers<5,>=4.57
31
+ Requires-Dist: torch>=2.1
32
+ Requires-Dist: accelerate>=0.26.0
33
+ Requires-Dist: matplotlib
34
+ Requires-Dist: pyarrow
35
+ Provides-Extra: test
36
+ Requires-Dist: pytest; extra == "test"
37
+ Dynamic: license-file
38
+
39
+ # ESMRank
40
+ **A learn-to-rank approach for protein variant effect prediction**
41
+
42
+ ESMRank is a pipeline for ranking protein variants according to their predicted functional impact.
43
+ The method frames variant effect prediction as a **learning-to-rank problem**, leveraging protein language models and sequence-derived features to prioritize mutations based on fitness, activity, or stability.
44
+
45
+ ---
46
+
47
+ ## Installation
48
+
49
+ ### Requirements
50
+ - Python **3.10+**
51
+ - Linux / macOS
52
+ - A CUDA GPU (the ESM-2 feature step needs one)
53
+
54
+ ### Install with pip
55
+
56
+ Install a `torch` build that matches your CUDA setup first (see https://pytorch.org), then:
57
+
58
+ ```bash
59
+ pip install git+https://github.com/gambalab/ESMRank.git
60
+ ```
61
+
62
+ This provides the `esmrank` command (and `python -m esmrank`).
63
+
64
+ ### Download the pretrained models
65
+
66
+ The package does not bundle the models (~830 MB, hosted on Zenodo: https://zenodo.org/records/18773439). Fetch them once with:
67
+
68
+ ```bash
69
+ esmrank download-models
70
+ ```
71
+
72
+ They are stored in `~/.cache/esmrank/model` (or `--dest DIR`). If the installation fails the downloaded archive is kept, so re-running does not download it again; an archive you already have can be used with `esmrank download-models --archive ESMRank.tar.gz`. At run time the model directory is looked up in this order: `--model-dir`, `$ESMRANK_MODEL_DIR`, `./model`, then the cache directory above.
73
+
74
+ ### Install from source (development)
75
+
76
+ ```bash
77
+ git clone https://github.com/gambalab/ESMRank.git
78
+ cd ESMRank
79
+ python -m venv ESMRank_venv && source ESMRank_venv/bin/activate
80
+ pip install -e ".[test]"
81
+ esmrank download-models
82
+ pytest
83
+ ```
84
+
85
+ `requirements.txt` still lists the exact versions the pipeline was developed against; `pyproject.toml` declares compatible ranges.
86
+
87
+ ---
88
+
89
+ ## Usage
90
+
91
+ ### From Python
92
+
93
+ ```python
94
+ import pandas as pd
95
+ import esmrank
96
+
97
+ # make sure the pretrained files are available (downloads them only if missing)
98
+ model_dir = esmrank.ensure_models()
99
+
100
+ # a protein sequence instead of a FASTA file
101
+ seq = "MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQKDWQPEVKLDLDTASSQLADDVYEVVLRVTVTASLG"
102
+ df = esmrank.rank_variants(seq, sub=True) # all missense variants
103
+ df = esmrank.rank_variants(sequence=seq, alanines=True) # explicit form, any length
104
+
105
+ # a DataFrame instead of a CSV file (columns hgvsp, seq_wt, seq_mu; extra columns are kept)
106
+ variants = pd.DataFrame({"hgvsp": ["p.Q12V"], "seq_wt": [seq], "seq_mu": [seq[:11] + "V" + seq[12:]]})
107
+ df = esmrank.rank_variants(variants)
108
+
109
+ # files work as well
110
+ df = esmrank.rank_variants("protein.fasta", sub=True, model_dir=model_dir)
111
+ df = esmrank.rank_variants("variants.csv", csv=True)
112
+
113
+ # download the models first if they are not there yet
114
+ df = esmrank.rank_variants(seq, alanines=True, auto_download=True)
115
+ ```
116
+
117
+ `rank_variants` returns a DataFrame with columns `ids` and `prediction`.
118
+
119
+ How the input is interpreted:
120
+
121
+ | You pass | Treated as |
122
+ |----------|------------|
123
+ | a `pandas.DataFrame` | table of variants (same as CSV mode); `sub` / `indel` / `alanines` do not apply |
124
+ | a string that is an existing file | FASTA file, or CSV file with `csv=True` |
125
+ | a string starting with `>` | text of a single-record FASTA |
126
+ | an all-uppercase string of at least 10 letters that is not an existing file | protein sequence |
127
+ | `sequence="..."` | protein sequence, explicitly (any length, any case) |
128
+
129
+ A sequence needs at least one of `sub`, `indel`, `alanines`, and may only contain the 20 standard amino acids. Any other string that is not a file raises `FileNotFoundError`, so a mistyped file name is never read as a sequence (use `sequence=` for short ones). Results are still written to `<outdir>/<name>/`: `name` defaults to the file name, the FASTA header, or a short hash of the sequence / DataFrame, and can be set with `name="..."`. The command line only accepts files.
130
+
131
+ | Function | What it does |
132
+ |----------|--------------|
133
+ | `esmrank.ensure_models(model_dir=None)` | Returns the model directory; downloads the files only if they are missing (into `model_dir`, `$ESMRANK_MODEL_DIR`, or `~/.cache/esmrank/model`) |
134
+ | `esmrank.download_models(dest=None, force=False, verify=True)` | Always downloads (unless already present and not `force`) |
135
+ | `esmrank.find_model_dir(explicit=None)` | Locates existing model files, raises `FileNotFoundError` if none |
136
+ | `esmrank.rank_variants(data, ...)` | Runs the pipeline and returns the predictions as a DataFrame |
137
+ | `esmrank.run_pipeline(data, ...)` | Runs the pipeline and returns the output directory (also has `profile.tsv` / `profile.png`) |
138
+
139
+ `rank_variants` and `run_pipeline` take the same options as the CLI: `csv`, `sub`, `indel`, `alanines`, `outdir`, `model_dir`, `esm_model`, `batch_size`, `gpu_ids`, plus `sequence`, `name` and `auto_download`. On the command line the equivalent of `auto_download` is `esmrank run --download ...`.
140
+
141
+ ### From command line
142
+
143
+ ```bash
144
+ esmrank run --input INPUT [-csv] [-sub] [-indel] [-alanines]
145
+ [--outdir DIR] [--model-dir DIR] [--download] [--gpus 0,1] [--batch-size N] [--esm-model NAME]
146
+ ```
147
+
148
+ Results are written to `<outdir>/<input file name>/` (default `output/<name>/`): `predictions.csv`, plus `profile.tsv` and `profile.png` in `-sub` / `-alanines` mode.
149
+
150
+ ---
151
+
152
+ ## Input modes
153
+
154
+ ESMRank supports **two input modes**: CSV mode and FASTA mode.
155
+
156
+ From the command line the input is always a file. From Python the input can also be given in memory: a **pandas DataFrame** instead of the CSV file, and a **protein sequence string** instead of the FASTA file (see [From Python](#from-python) for all the details).
157
+
158
+ ---
159
+
160
+ ### CSV mode
161
+
162
+ In CSV mode, the input must be a CSV file (or, from Python, a pandas DataFrame) containing **three mandatory columns**:
163
+
164
+ | Column name | Description |
165
+ |------------|-------------|
166
+ | `hgvsp` | Variant identifier |
167
+ | `seq_wt` | Wild-type protein sequence |
168
+ | `seq_mu` | Mutant protein sequence |
169
+
170
+ Example:
171
+ ```csv
172
+ hgvsp,seq_wt,seq_mu
173
+ p.A123V,MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQ...,MSEQNNTEMTFQIQRIYTKDISFEVPNAPHVFQ...
174
+ ```
175
+
176
+ To run in CSV mode:
177
+ ```bash
178
+ esmrank run --input variants.csv -csv
179
+ ```
180
+
181
+ From Python you can pass a DataFrame directly, without writing a CSV (extra columns are kept):
182
+ ```python
183
+ import pandas as pd
184
+ import esmrank
185
+
186
+ variants = pd.read_csv("variants.csv") # or any DataFrame with the three columns above
187
+ df = esmrank.rank_variants(variants) # DataFrame with columns `ids` and `prediction`
188
+ ```
189
+
190
+ ---
191
+
192
+ ### FASTA mode
193
+
194
+ In FASTA mode, the input must be a **single wild-type protein sequence** in FASTA format (or, from Python, the sequence itself as a string).
195
+
196
+ The pipeline will automatically generate variants based on the selected mutation types:
197
+
198
+ - `-sub` : generate all possible **missense substitutions**
199
+ - `-indel` : generate all possible **insertions and deletions**
200
+ - `-alanines`: mutually exclusive to sub and indel, generate only alanines substitutions for each aminoacid
201
+
202
+ Example FASTA:
203
+ ```fasta
204
+ >protein_X
205
+ MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQ...
206
+ ```
207
+
208
+ Example execution:
209
+
210
+ generating all missenses variants:
211
+
212
+ ```bash
213
+ esmrank run --input protein.fasta -sub
214
+ ```
215
+ generating all single single indel
216
+
217
+ ```bash
218
+ esmrank run --input protein.fasta -indel
219
+ ```
220
+ generating all missenses and single indel
221
+
222
+ ```bash
223
+ esmrank run --input protein.fasta -sub -indel
224
+ ```
225
+ generate alanine scanning ( alanines substitution only )
226
+
227
+ ```bash
228
+ esmrank run --input protein.fasta -alanines
229
+ ```
230
+
231
+ From Python you can pass the sequence as a string instead of a FASTA file; the same `sub`, `indel` and `alanines` options apply:
232
+ ```python
233
+ import esmrank
234
+
235
+ seq = "MSEQNNTEMTFQIQRIYTKDISFEAPNAPHVFQKDWQPEVKLDLDTASSQLADDVYEVVLRVTVTASLG"
236
+ df = esmrank.rank_variants(seq, sub=True) # all missense variants
237
+ df = esmrank.rank_variants(sequence=seq, alanines=True) # alanine scanning
238
+ ```
239
+
240
+ ---
241
+
242
+ ## Command-line arguments
243
+
244
+ | Argument | Description |
245
+ |--------|-------------|
246
+ | `-h` | Show help message |
247
+ | `--input`, `-i` | Path to input file (CSV or FASTA) |
248
+ | `-csv` | Enable CSV input mode (default: FASTA mode) |
249
+ | `-sub` | Generate all possible missense substitutions |
250
+ | `-indel` | Generate all possible insertions and deletions |
251
+ | `-alanines` | Generate alanine substitutions for each position |
252
+ | `--outdir` | Output root directory (default: `output`) |
253
+ | `--model-dir` | Directory with the pretrained model files |
254
+ | `--download` | Download the model files first if they are not already present |
255
+ | `--gpus` | Comma-separated CUDA device ids (default: all) |
256
+ | `--batch-size` | Worker batch size for the ESM step (default: 128) |
257
+ | `--esm-model` | ESM-2 checkpoint name (default: `esm2_t33_650M_UR50D`) |
258
+
259
+ The command line only accepts files. Sequence strings and DataFrames are available from Python, see [From Python](#from-python).
260
+
261
+ The environment variables `ESM_GPU_IDS`, `ESM_WORKER_BATCH_SIZE`, `ESM_MODEL_NAME` and `ESM_CHECKPOINT_DIR` are still honoured.
262
+
263
+ ---
264
+
265
+ ## Notes
266
+
267
+ - CSV and FASTA modes are **mutually exclusive**.
268
+ - In FASTA mode, at least one of `-sub`, `-indel` or `-alanines` must be specified.
269
+ - Runtime and memory usage scale with protein length and number of generated variants.
270
+
271
+ ---
272
+
273
+ ## License
274
+
275
+ - **Source code**: Apache License 2.0, see [`LICENSE`](LICENSE).
276
+ - **Pretrained model parameters** (downloaded with `esmrank download-models`): ESMRank Model Parameters Non-Commercial Research License, see [`LICENSE_WEIGHTS.md`](LICENSE_WEIGHTS.md). They may be used for non-commercial research and educational purposes only; commercial use requires written permission from the authors.
277
+ - Third-party resources (Pfam-A HMMs, ESM-2 weights) keep their own licenses.
278
+
279
+ ---
280
+
281
+ ## Citation
282
+
283
+ If you use ESMRank in your research, please cite:
284
+
285
+ ```bibtex
286
+ @article{esmrank,
287
+ title={ESMRank reveals a transferable axis of protein mutational constraint from overlapping variant effect assays},
288
+ author={Riccardo Arnese, Gennaro Gambardella},
289
+ journal={TBD},
290
+ year={TBD}
291
+ }
292
+ ```