├── .gitignore
├── Dockerfile
├── LICENSE
├── README.md
├── data
├── Test_seed1.fasta
├── Test_seed1_aligned.aln
└── per_protein_embeddings.h5.zip
├── docker-compose.yml
├── img
├── fine-tuning.png
├── gpu.png
├── logo_small.gif
├── nb_logo.png
└── protgpt2.png
├── notebooks
├── embeddings.ipynb
├── model_training.ipynb
├── prediction.ipynb
├── prot_design.ipynb
└── seq_analysis.ipynb
├── poetry.lock
├── pyproject.toml
├── ran
├── embeddings.html
├── model_training.html
├── prediction.html
├── prot_design.html
└── seq_analysis.html
├── requirements.txt
├── slides
├── intro_pLM.key
└── intro_pLM.pdf
└── topics.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # poetry
98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99 | # This is especially recommended for binary packages to ensure reproducibility, and is more
100 | # commonly ignored for libraries.
101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102 | #poetry.lock
103 |
104 | # pdm
105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106 | #pdm.lock
107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108 | # in version control.
109 | # https://pdm.fming.dev/#use-with-ide
110 | .pdm.toml
111 |
112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113 | __pypackages__/
114 |
115 | # Celery stuff
116 | celerybeat-schedule
117 | celerybeat.pid
118 |
119 | # SageMath parsed files
120 | *.sage.py
121 |
122 | # Environments
123 | .env
124 | .venv
125 | env/
126 | venv/
127 | ENV/
128 | env.bak/
129 | venv.bak/
130 |
131 | # Spyder project settings
132 | .spyderproject
133 | .spyproject
134 |
135 | # Rope project settings
136 | .ropeproject
137 |
138 | # mkdocs documentation
139 | /site
140 |
141 | # mypy
142 | .mypy_cache/
143 | .dmypy.json
144 | dmypy.json
145 |
146 | # Pyre type checker
147 | .pyre/
148 |
149 | # pytype static type analyzer
150 | .pytype/
151 |
152 | # Cython debug symbols
153 | cython_debug/
154 |
155 | # PyCharm
156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158 | # and can be added to the global gitignore or merged into this file. For a more nuclear
159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160 | #.idea/
161 | .DS_Store
162 | *.ent
163 | notebooks/esm2_t12_35M_UR50D-finetuned-localization/*
164 | *.fasta
165 | *.pdb
166 | *.h5.zip
167 | *.h5
168 | *.fa
169 | *.aln
170 | *.xml
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use the official Python image from the Docker Hub
2 | FROM python:3.11
3 |
4 | # If you have a requirements.txt, copy and install dependencies
5 | COPY requirements.txt .
6 | RUN pip install -r requirements.txt
7 | RUN apt-get update && apt-get install -y wget
8 | # Download and install MUSCLE
9 | RUN wget https://github.com/rcedgar/muscle/releases/download/v5.1/muscle5.1.linux_intel64 -O /usr/local/bin/muscle && \
10 | chmod +x /usr/local/bin/muscle
11 |
12 | # also in case...
13 | RUN pip install --no-cache-dir jupyterlab
14 |
15 | # Set the working directory
16 | WORKDIR /app
17 | #Include app dir
18 | ENV PYTHONPATH=/app
19 |
20 | # expose port
21 | EXPOSE 8888
22 |
23 | # run jupyter
24 | CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root", "--NotebookApp.token=''"]
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Protein Language Modeling Course
2 |
3 | 
4 |
5 | ----
6 |
7 | 1. [Topics](topics.md)
8 | 2. [Course Structure](#course-structure)
9 | 3. [References](#references)
10 | 4. [Resources](#other-resources)
11 |
12 |
13 |
14 | ## Course Structure
15 |
16 | | **Theory** | | Link | Data |Models |
17 | |--------------|-------------------------|------------------------------|-----------------|-----------------|
18 | | | [Topics](topics.md) | [slides](slides/intro_pLM.pdf) | | |
19 | | **Hands-on** | | | | |
20 | | | **Sequence Analysis** | [Seq. Analysis Notebook](notebooks/seq_analysis.ipynb) [](https://colab.research.google.com/github/Multiomics-Analytics-Group/course_protein_language_modeling/blob/main/notebooks/seq_analysis.ipynb) | Exploring protein sequence and structure data | |
21 | | | **Fine-tuning a model** | [Model Training Notebook](notebooks/model_training.ipynb) [](https://colab.research.google.com/github/Multiomics-Analytics-Group/course_protein_language_modeling/blob/main/notebooks/model_training.ipynb) | Taking an existing model and tuning it for other prediction/classification tasks | [Evolutionary Scale Modeling (ESM)](https://github.com/facebookresearch/esm) |
22 | | | **Working with Embeddings** | [Embeddings Notebook](notebooks/embeddings.ipynb) [](https://colab.research.google.com/github/Multiomics-Analytics-Group/course_protein_language_modeling/blob/main/notebooks/embeddings.ipynb) | Accessing Protein representations (embeddings) generated by existing LMs | [ProTrans](https://github.com/agemagician/ProtTrans) |
23 | | | **Predictions** | [pML Predictions Notebook](notebooks/prediction.ipynb) [](https://colab.research.google.com/github/Multiomics-Analytics-Group/course_protein_language_modeling/blob/main/notebooks/prediction.ipynb) | Using embeddings for predicting features or classifying sequences | [ProTrans](https://github.com/agemagician/ProtTrans) |
24 | | | **Protein Design** | [Protein Design Notebook](notebooks/prot_design.ipynb)[](https://colab.research.google.com/github/Multiomics-Analytics-Group/course_protein_language_modeling/blob/main/notebooks/prot_design.ipynb) | *De novo* protein design and engineering using a LLM | [ProtGPT2](https://huggingface.co/nferruz/ProtGPT2), [ESM](https://github.com/facebookresearch/esm) |
25 |
26 | #### Working Locally
27 |
28 | 1. Install [Docker](https://docs.docker.com/engine/install/)
29 | 2. From the root of the repository in the terminal run:
30 | ```
31 | docker compose up --build -d
32 | ```
33 | 3. Open JupyterLab in any browser via `0.0.0.0:8888`
34 |
35 | To stop run: `docker compose stop`
36 | To stop and remove containers: `docker compose down`
37 |
38 |
39 | #### Working VM
40 | 1. Once you have a VM, download docker in it
41 | - (e.g., [apt install](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository) via ssh)
42 | - e.g. in VM shell run below
43 | ```
44 | # Add Docker's official GPG key:
45 | sudo apt-get update
46 | sudo apt-get install ca-certificates curl
47 | sudo install -m 0755 -d /etc/apt/keyrings
48 | sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
49 | sudo chmod a+r /etc/apt/keyrings/docker.asc
50 |
51 | # Add the repository to Apt sources:
52 | echo \
53 | "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
54 | $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
55 | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
56 | sudo apt-get update
57 |
58 | sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
59 | ```
60 | 2. Clone this repo into the VM or to keep things slim you can move only the below needed files onto VM (e.g., via `scp`)
61 | - notebooks and data folders
62 | - Dockerfile, docker-compose.yml
63 | - requirements.txt
64 | 3. Then run `docker compose up --build -d`
65 | - if you encounter permission denied you may need to run the above command with elevated permissions e.g. `sudo docker compose up --build -d`
66 | - Note: for troubleshooting you can use `docker logs ` e.g., `docker logs jupyter`
67 | 4. The URL to the JupyterLab will be: `:8888` e.g. `12.26.38.408:8888`
68 | - Note: may have to expose port 8888 via the VM's network security group
69 | 5. On your local device, open a browser of your choosing. In the address bar input the URL to JupyterLab. And you should be good to go :)
70 | 6. **Remember to stop the VM container once you are done**
71 |
72 |
73 | ## References
74 | ----
75 | 1. [Neural Machine Translation by Jointly Learning to Align and Translate](https://arxiv.org/abs/1409.0473) Dzmitry Bahdanau, Kyunghyun Cho, Yoshua Bengio
76 |
77 | 2. [Attention Is All You Need](https://arxiv.org/abs/1706.03762) Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin
78 |
79 | 3. [MSA Transformer](https://www.biorxiv.org/content/10.1101/2021.02.12.430858v3) Roshan Rao, Jason Liu, Robert Verkuil, Joshua Meier, John F. Canny, Pieter Abbeel, Tom Sercu, Alexander Rives
80 |
81 | 4. [Transformer-based deep learning for predicting protein properties in the life sciences](https://elifesciences.org/articles/82819) Abel Chandra, Laura Tünnermann, Tommy Löfstedt, Regina Gratz
82 |
83 | 5. [BERTology Meets Biology: Interpreting Attention in Protein Language Models](https://arxiv.org/abs/2006.15222) Jesse Vig, Ali Madani, Lav R. Varshney, Caiming Xiong, Richard Socher, Nazneen Fatema Rajani
84 |
85 | 6. [Broadly applicable and accurate protein design by integrating structure prediction networks and diffusion generative models
86 | ](https://www.biorxiv.org/content/10.1101/2022.12.09.519842v2) Joseph L. Watson, David Juergens, Nathaniel R. Bennett, Brian L. Trippe, Jason Yim, Helen E. Eisenach, Woody Ahern, Andrew J. Borst, Robert J. Ragotte, Lukas F. Milles, Basile I. M. Wicky, Nikita Hanikel, Samuel J. Pellock, Alexis Courbet, William Sheffler, Jue Wang, Preetham Venkatesh, Isaac Sappington, Susana Vázquez Torres, Anna Lauko, Valentin De Bortoli, Emile Mathieu, Regina Barzilay, Tommi S. Jaakkola, Frank DiMaio, Minkyung Baek, David Baker
87 |
88 | 7. [Large language models generate functional protein sequences across diverse families](https://www.nature.com/articles/s41587-022-01618-2) Ali Madani, Ben Krause, Eric R. Greene, Subu Subramanian, Benjamin P. Mohr, James M. Holton, Jose Luis Olmos Jr., Caiming Xiong, Zachary Z. Sun, Richard Socher, James S. Fraser & Nikhil Naik
89 |
90 | 8. [Learning functional properties of proteins with language models](https://www.nature.com/articles/s42256-022-00457-9)Serbulent Unsal, Heval Atas, Muammer Albayrak, Kemal Turhan, Aybar C. Acar & Tunca Doğan
91 |
92 | 9. [Learning the protein language: Evolution, structure, and function](https://www.sciencedirect.com/science/article/pii/S2405471221002039) Tristan Bepler, Bonnie Berger
93 |
94 | 10. [The language of proteins: NLP, machine learning & protein sequences](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8050421/) Dan Ofer, Nadav Brandes, Michal Linial
95 |
96 | 11. [Evolutionary-scale prediction of atomic-level protein structure with a language model](https://www.science.org/doi/10.1126/science.ade2574) ZEMING LIN, HALIL AKIN, ROSHAN RAO, BRIAN HIE, ZHONGKAI ZHU, WENTING LU, NIKITA SMETANIN, ROBERT VERKUIL, ORI KABELI, ..., ALEXANDER RIVES
97 |
98 | 12. [Generative power of a protein language model trained on multiple sequence alignments](https://elifesciences.org/articles/79854) Damiano Sgarbossa, Umberto Lupo, Anne-Florence Bitbol
99 |
100 | 13. [How Huge Protein Language Models Could Disrupt Structural Biology](https://towardsdatascience.com/how-huge-protein-language-models-could-disrupt-structural-biology-6b98193f880b)
101 |
102 | 14. [Embeddings from protein language models predict conservation and variant effects](https://link.springer.com/article/10.1007/s00439-021-02411-y) Céline Marquet, Michael Heinzinger, Tobias Olenyi, Christian Dallago, Kyra Erckert, Michael Bernhofer, Dmitrii Nechaev & Burkhard Rost
103 |
104 | 15. [Collectively encoding protein properties enriches protein language models](https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-022-05031-z) Jingmin An & Xiaogang Weng
105 |
106 | 16. [ProGen: Language Modeling for Protein Generation](https://www.biorxiv.org/content/10.1101/2020.03.07.982272v2) Ali Madani, Bryan McCann, Nikhil Naik, Nitish Shirish Keskar, Namrata Anand, Raphael R. Eguchi, Po-Ssu Huang, Richard Socher
107 |
108 | 17. [Transformer protein language models are unsupervised structure learners](https://www.biorxiv.org/content/10.1101/2020.12.15.422761v1) Roshan Rao, Joshua Meier, Tom Sercu, Sergey Ovchinnikov, Alexander Rives
109 |
110 | 18. [Biological structure and function emerge from scaling unsupervised learning to 250 million protein sequences](https://www.pnas.org/doi/full/10.1073/pnas.2016239118) Alexander Rives, Joshua Meier, Tom Sercu and Rob Fergus
111 |
112 | 19. [NetSurfP-3.0: accurate and fast prediction of protein structural features by protein language models and deep learning](https://academic.oup.com/nar/article/50/W1/W510/6596854?) Magnus Haraldson Høie, Erik Nicolas Kiehl, Bent Petersen, Morten Nielsen, Ole Winther, Henrik Nielsen, Jeppe Hallgren, Paolo Marcatili
113 |
114 | 20. [Modeling Protein Using Large-scale Pretrain Language Model](https://arxiv.org/abs/2108.07435) Yijia Xiao, Jiezhong Qiu, Ziang Li, Chang-Yu Hsieh, Jie Tang [github](https://github.com/THUDM/ProteinLM)
115 |
116 | 21. [Deciphering antibody affinity maturation with language models and weakly supervised learning](https://arxiv.org/abs/2112.07782) Jeffrey A. Ruffolo, Jeffrey J. Gray, Jeremias Sulam [github](https://github.com/dohlee/antiberty-pytorch)
117 |
118 | 22. [Protein embeddings improve phage-host interaction prediction](https://www.biorxiv.org/content/10.1101/2023.02.26.530154v1) Mark Edward M. Gonzales, Jennifer C. Ureta, View ORCID ProfileAnish M.S. Shrestha [github](https://github.com/bioinfodlsu/phage-host-prediction)
119 |
120 | 23. [ProteinBERT: a universal deep-learning model of protein sequence and function](https://academic.oup.com/bioinformatics/article/38/8/2102/6502274) Nadav Brandes, Dan Ofer, Yam Peleg, Nadav Rappoport, Michal Linial [github](https://github.com/nadavbra/protein_bert)
121 |
122 | 24. [ProtGPT2 is a deep unsupervised language model for protein design](https://www.nature.com/articles/s41467-022-32007-7) Noelia Ferruz, Steffen Schmidt & Birte Höcker [Hugging Face](https://huggingface.co/nferruz/ProtGPT2?)
123 |
124 | 25. [Protein-Protein Interaction Prediction is Achievable with Large Language Models](https://www.biorxiv.org/content/10.1101/2023.06.07.544109v1.full) Logan Hallee, Jason P. Gleghorn
125 |
126 | 26. [Accurate prediction of virus-host protein-protein interactions via a Siamese neural network using deep protein sequence embeddings](https://www.sciencedirect.com/science/article/pii/S2666389922001568?via%3Dihub) Sumit Madan, Victoria Demina, Marcus Stapf, Oliver Ernst, Holger Fröhlich
127 |
128 | 27. [Structure-informed Language Models Are Protein Designers](https://arxiv.org/abs/2302.01649) Zaixiang Zheng, Yifan Deng, Dongyu Xue, Yi Zhou, Fei YE, Quanquan Gu
129 |
130 | 28. [Graph-BERT and language model-based framework for protein–protein interaction identification](https://www.nature.com/articles/s41598-023-31612-w) Kanchan Jha, Sourav Karmakar & Sriparna Saha
131 |
132 | 29. [Ankh: Optimized Protein Language Model Unlocks General-Purpose Modelling](https://arxiv.org/abs/2301.06568) Ahmed Elnaggar, Hazem Essam, Wafaa Salah-Eldin, Walid Moustafa, Mohamed Elkerdawy, Charlotte Rochereau, Burkhard Rost
133 |
134 | 30. [Contrastive learning in protein language space predicts interactions between drugs and protein targets](https://www.pnas.org/doi/10.1073/pnas.2220778120) Rohit Singh, Samuel Sledzieski, Bryan Bryson, Bonnie Berger
135 |
136 | 31. [De novo design of protein structure and function with RFdiffusion](https://www.nature.com/articles/s41586-023-06415-8) Joseph L. Watson, David Juergens, Nathaniel R. Bennett, Brian L. Trippe, Jason Yim, Helen E. Eisenach, Woody Ahern, Andrew J. Borst, Robert J. Ragotte, Lukas F. Milles, Basile I. M. Wicky, Nikita Hanikel, Samuel J. Pellock, Alexis Courbet, William Sheffler, Jue Wang, Preetham Venkatesh, Isaac Sappington, Susana Vázquez Torres, Anna Lauko, Valentin De Bortoli, Emile Mathieu, Sergey Ovchinnikov, Regina Barzilay, Tommi S. Jaakkola, Frank DiMaio, Minkyung Baek & David Baker
137 |
138 | 32. [Single-sequence protein structure prediction using a language model and deep learning](https://www.nature.com/articles/s41587-022-01432-w) Ratul Chowdhury, Nazim Bouatta, Surojit Biswas, Christina Floristean, Anant Kharkar, Koushik Roy, Charlotte Rochereau, Gustaf Ahdritz, Joanna Zhang, George M. Church, Peter K. Sorger & Mohammed AlQuraishi
139 |
140 | 33. [Before and after AlphaFold2: An overview of protein structure prediction](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10011655/) Letícia M. F. Bertoline, Angélica N. Lima, Jose E. Krieger, and Samantha K. Teixeira
141 |
142 | 34. [Evaluating Protein Transfer Learning with TAPE](https://arxiv.org/abs/1906.08230) Roshan Rao, Nicholas Bhattacharya, Neil Thomas, Yan Duan, Xi Chen, John Canny, Pieter Abbeel, Yun S. Song
143 |
144 | 35. [FLIP: Benchmark tasks in fitness landscape inference for proteins](https://www.biorxiv.org/content/10.1101/2021.11.09.467890v2) Christian Dallago, Jody Mou, Kadina E. Johnston, Bruce J. Wittmann, Nicholas Bhattacharya, Samuel Goldman, Ali Madani, Kevin K. Yang
145 |
146 | 36. [Standards, tooling and benchmarks to probe representation learning on proteins](https://openreview.net/forum?id=adODyN-eeJ8) Joaquin Gomez Sanchez, Sebastian Franz, Michael Heinzinger, Burkhard Rost, Christian Dallago
147 |
148 | 37. [Learning meaningful representations of protein sequences](https://www.nature.com/articles/s41467-022-29443-w) Nicki Skafte Detlefsen, Søren Hauberg & Wouter Boomsma
149 |
150 | 38. [Language modelling for biological sequences – curated datasets and baselines](https://www.biorxiv.org/content/10.1101/2020.03.09.983585v1) Jose Juan Almagro Armenteros, Alexander Rosenberg Johansen, Ole Winther, Henrik Nielsen
151 |
152 | 39. [Language models generalize beyond natural proteins](https://www.biorxiv.org/content/10.1101/2022.12.21.521521v1) Robert Verkuil, Ori Kabeli, Yilun Du, Basile I. M. Wicky, Lukas F. Milles, Justas Dauparas, David Baker, Sergey Ovchinnikov, Tom Sercu, Alexander Rives
153 |
154 | 40. [ChemBERTa: Large-Scale Self-Supervised Pretraining for Molecular Property Prediction](https://arxiv.org/abs/2010.09885) Seyone Chithrananda, Gabriel Grand, Bharath Ramsundar
155 |
156 | 41. [SETH predicts nuances of residue disorder from protein embeddings](https://www.frontiersin.org/articles/10.3389/fbinf.2022.1019597/full) Dagmar Ilzhöfer, Michael Heinzinger, Burkhard Rost
157 |
158 | 42. [Exploiting pretrained biochemical language models for targeted drug design](https://academic.oup.com/bioinformatics/article/38/Supplement_2/ii155/6702010) Gökçe Uludoğan, Elif Ozkirimli, Kutlu O Ulgen, Nilgün Karalı, Arzucan Özgür
159 |
160 |
161 | ## Other Resources
162 | ----
163 | - [Protein Language Workshop](https://github.com/dimiboeckaerts/ProteinLanguageWorkshop)
164 |
165 | - [Awesome protein representation learning](https://github.com/LirongWu/awesome-protein-representation-learning)
166 |
167 | - [Evolutionary Scale Modeling - ESM](https://github.com/facebookresearch/esm)
168 |
169 | - [Huggingface ESM](https://huggingface.co/docs/transformers/model_doc/esm)
170 |
171 | - [Ankh](https://github.com/agemagician/Ankh)
172 |
173 | - [Protein Sequence Embeddings (ProSE)](https://github.com/tbepler/prose)
174 |
175 | - [ProTrans](https://github.com/agemagician/ProtTrans)
176 |
177 | - [ConPlex](https://github.com/samsledje/ConPLex)
178 |
179 | - [Deep Learning with Proteins](https://github.com/huggingface/blog/blob/main/deep-learning-with-proteins.md)
180 |
181 | - [Awesome AI-based for Protein Design](https://github.com/opendilab/awesome-AI-based-protein-design)
182 |
183 | - [Amazon SageMaker Protein Classification](https://github.com/aws-samples/amazon-sagemaker-protein-classification/tree/main)
184 |
185 | - [Huggingface Protein Language Modeling - pytorch](https://github.com/huggingface/notebooks/blob/main/examples/protein_language_modeling.ipynb)
186 |
187 | - [Huggingface Protein Language Modeling - tensorflow](https://github.com/huggingface/notebooks/blob/main/examples/protein_language_modeling-tf.ipynb)
188 |
189 | - [Building a Text Generation Model from Scratch](https://wingedsheep.com/building-a-language-model/)
190 |
191 | - [Training the Transformer Model](https://machinelearningmastery.com/training-the-transformer-model/)
192 |
193 | - [GearNet: Geometry-Aware Relational Graph Neural Network](https://github.com/DeepGraphLearning/GearNet)
194 |
195 | - [UniLanguage](https://github.com/alrojo/UniLanguage)
196 |
197 | - [SETH](https://github.com/DagmarIlz/SETH)
198 |
199 |
200 |
--------------------------------------------------------------------------------
/data/Test_seed1.fasta:
--------------------------------------------------------------------------------
1 | >Test_1
2 | MIQEKDKYVVASVTILESNQILDKGSIQTSGIELNYYMKYQKY
3 | >Test_2
4 | MIQEKDKYVVASVTILESNQLLKEANSSGN
5 | >Test_3
6 | MIQEKDKYVVASVTILESNQNSDVFIDLTNLTVEHKKLLN
7 | >Test_4
8 | MIQEKDKYVVASVTILESNQVFDAMGFGGFLNINRKKFYNDL
9 | >Test_5
10 | MIQEKDKYVVASVTILESNQVFFDSPEIKKLGLVTLKAKYD
11 | >Test_6
12 | MIQEKDKYVVASVTILESNQFGMKRNILYKETKALRAK
13 | >Test_7
14 | MIQEKDKYVVASVTILESNQHGNIQIAQIQIFTNSKEPTVFD
15 | >Test_8
16 | MIQEKDKYVVASVTILESNQWFHENICLAGLWHVGKCKS
17 | >Test_9
18 | MIQEKDKYVVASVTILESNQIYISEYLLIELKEYVLNIISETL
19 | >Test_10
20 | MIQEKDKYVVASVTILESNQSLGQIIQRAIDFSDNNTNLRSIDG
21 | >Test_11
22 | MIQEKDKYVVASVTILESNQCILGSVELAIDVTEQERLSRELEQV
23 | >Test_12
24 | MIQEKDKYVVASVTILESNQVGKAFIENYLRDNKY
25 | >Test_13
26 | MIQEKDKYVVASVTILESNQMGGYVATGHGNFISPVY
27 | >Test_14
28 | MIQEKDKYVVASVTILESNQATVTLRTKATYRNLSRKWTLFG
29 | >Test_15
30 | MIQEKDKYVVASVTILESNQFEGNMIQIYYESTHSPT
31 | >Test_16
32 | MIQEKDKYVVASVTILESNQLLLTYNVTSLTQNQQPWGS
33 | >Test_17
34 | MIQEKDKYVVASVTILESNQKKQKEYKIKRVLKYEGNS
35 | >Test_18
36 | MIQEKDKYVVASVTILESNQIYTFESNKDYMITIALRE
37 | >Test_19
38 | MIQEKDKYVVASVTILESNQALFLLTVMESQLQNEKSGKALNRMRE
39 | >Test_20
40 | MIQEKDKYVVASVTILESNQWTGNIQNYKQTAEAILTD
41 |
--------------------------------------------------------------------------------
/data/Test_seed1_aligned.aln:
--------------------------------------------------------------------------------
1 | >Test_5
2 | MIQEKDKYVVASVTILESNQV-----FFDSPEIKKLGLVTLKAKYD----
3 | >Test_7
4 | MIQEKDKYVVASVTILESNQH---GNIQIAQIQIFTNSKEPTVFD-----
5 | >Test_1
6 | MIQEKDKYVVASVTILESNQI---LDKGSIQTSGIELNYYMKYQKY----
7 | >Test_9
8 | MIQEKDKYVVASVTILESNQIYISEYLLIELKEYVLNIISETL-------
9 | >Test_10
10 | MIQEKDKYVVASVTILESNQS-----LGQIIQRAIDFSDNNTNLRSIDG-
11 | >Test_11
12 | MIQEKDKYVVASVTILESNQC-----ILGSVELAIDVTEQERLSRELEQV
13 | >Test_19
14 | MIQEKDKYVVASVTILESNQA---LFLLTVMESQLQNEKSGKALNRMRE-
15 | >Test_8
16 | MIQEKDKYVVASVTILESNQW-------FHENICLAGLWHVGKCKS----
17 | >Test_3
18 | MIQEKDKYVVASVTILESNQN-----SDVFIDLTNLTVEHKKLLN-----
19 | >Test_14
20 | MIQEKDKYVVASVTILESNQA----TVTLRTKATYRNLSRKWTLFG----
21 | >Test_4
22 | MIQEKDKYVVASVTILESNQVFDAMGFGGFLNINRKKFYNDL--------
23 | >Test_18
24 | MIQEKDKYVVASVTILESNQI-----YTFESNKDYMITIALRE-------
25 | >Test_17
26 | MIQEKDKYVVASVTILESNQK------KQKEYKIKRVLKYEGNS------
27 | >Test_16
28 | MIQEKDKYVVASVTILESNQL-----LLTYNVTSLTQNQQPWGS------
29 | >Test_12
30 | MIQEKDKYVVASVTILESNQV-----GKAFIENYLRDNKY----------
31 | >Test_6
32 | MIQEKDKYVVASVTILESNQF------GMKRNILYKETKALRAK------
33 | >Test_20
34 | MIQEKDKYVVASVTILESNQW------TGNIQNYKQTAEAILTD------
35 | >Test_13
36 | MIQEKDKYVVASVTILESNQM------GGYVATGHGNFISPVY-------
37 | >Test_15
38 | MIQEKDKYVVASVTILESNQF-----EGNMIQIYYESTHSPT--------
39 | >Test_2
40 | MIQEKDKYVVASVTILESNQL-------------LKEANSSGN-------
41 |
--------------------------------------------------------------------------------
/data/per_protein_embeddings.h5.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Multiomics-Analytics-Group/course_protein_language_modeling/37c74ceb67f32c138a7a7e6a6cc2c6baccffcfef/data/per_protein_embeddings.h5.zip
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | services:
2 | jupyter:
3 | container_name: jupyter
4 | build:
5 | context: ${DOCKER_VOLUME_DIRECTORY:-.}
6 | dockerfile: ${DOCKER_VOLUME_DIRECTORY:-.}/Dockerfile
7 | ports:
8 | - "8888:8888"
9 | volumes:
10 | - ${DOCKER_VOLUME_DIRECTORY:-.}/notebooks:/app
11 | - ${DOCKER_VOLUME_DIRECTORY:-.}/data:/app/data
--------------------------------------------------------------------------------
/img/fine-tuning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Multiomics-Analytics-Group/course_protein_language_modeling/37c74ceb67f32c138a7a7e6a6cc2c6baccffcfef/img/fine-tuning.png
--------------------------------------------------------------------------------
/img/gpu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Multiomics-Analytics-Group/course_protein_language_modeling/37c74ceb67f32c138a7a7e6a6cc2c6baccffcfef/img/gpu.png
--------------------------------------------------------------------------------
/img/logo_small.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Multiomics-Analytics-Group/course_protein_language_modeling/37c74ceb67f32c138a7a7e6a6cc2c6baccffcfef/img/logo_small.gif
--------------------------------------------------------------------------------
/img/nb_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Multiomics-Analytics-Group/course_protein_language_modeling/37c74ceb67f32c138a7a7e6a6cc2c6baccffcfef/img/nb_logo.png
--------------------------------------------------------------------------------
/img/protgpt2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Multiomics-Analytics-Group/course_protein_language_modeling/37c74ceb67f32c138a7a7e6a6cc2c6baccffcfef/img/protgpt2.png
--------------------------------------------------------------------------------
/notebooks/embeddings.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "06460c02-2004-436b-aa38-1ae0a7587052",
6 | "metadata": {},
7 | "source": [
8 | "
"
9 | ]
10 | },
11 | {
12 | "cell_type": "markdown",
13 | "id": "8bf874eb-8949-41dd-a33b-0e55ba2954c6",
14 | "metadata": {},
15 | "source": [
16 | "[](https://colab.research.google.com/github/Multiomics-Analytics-Group/course_protein_language_modeling/blob/main/notebooks/embeddings.ipynb)\n",
17 | "\n",
18 | "\n",
19 | "This is a version of the notebook from [SETH](https://github.com/DagmarIlz/SETH) --- [here](https://colab.research.google.com/drive/1vDWh5YI_BPxQg0ku6CxKtSXEJ25u2wSq?usp=sharing)."
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": null,
25 | "id": "cd6f0c8f-d9db-4623-a2ee-483008dc9d74",
26 | "metadata": {},
27 | "outputs": [],
28 | "source": [
29 | "# uncomment the below to install dependencies for colab\n",
30 | "#!pip install \"transformers[torch]\" sentencepiece h5py biopython > /dev/null"
31 | ]
32 | },
33 | {
34 | "cell_type": "markdown",
35 | "id": "4efcc6ce-9843-4541-a6de-6b3a6ba14c45",
36 | "metadata": {},
37 | "source": [
38 | "Important
\n",
39 | "If you are running in Google Colab, change the Notebook settings to use `GPU`.\n",
40 | "\n",
41 | "Just follow **Edit** > **Notebook settings** or **Runtime** > **Change runtime type** and select **GPU** as Hardware accelerator.\n",
42 | "\n",
43 | "\n"
44 | ]
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "id": "75061fa6-eea7-42dc-b057-5da1c56094c0",
49 | "metadata": {
50 | "id": "5c0749e1"
51 | },
52 | "source": [
53 | "# Embedding Protein Sequences\n",
54 | "\n",
55 | "In this notebook, we will use a pre-trained language model, [ProtT5-XL-UniRef50](https://huggingface.co/Rostlab/prot_t5_xl_uniref50), to encode the protein sequences of 5000+ $\\beta$-$lactamase$ TEM-type varients from FASTA file [P62593.fasta](https://github.com/facebookresearch/esm/blob/2b369911bb5b4b0dda914521b9475cad1656b2ac/examples/data/P62593.fasta). This data was subsetted from a deep mutational scan released by [Gray et al. (2018)](https://www.cell.com/cell-systems/pdfExtended/S2405-4712(17)30492-1). \n",
56 | "\n",
57 | "The goal of this notebook is to obtain an embedding (fixed-dimensional vector representation) for each mutated sequence.\n",
58 | "\n",
59 | "Although the embedding won't capture all the information from the original data, good embedding representations allow us to analyze, cluster, or use them as features to train machine learning models. \n",
60 | "\n",
61 | "The embeddings generated in this notebook will then be used in the next exercise (prediction.ipynb) to train a simple varient predictor (i.e., predict the activity of the protein mutation)."
62 | ]
63 | },
64 | {
65 | "cell_type": "markdown",
66 | "id": "38b6f6b9-0778-4435-a515-e9616522c4b3",
67 | "metadata": {},
68 | "source": [
69 | "\n",
70 | "
\n",
71 | "NOTE
\n",
72 | "\n",
73 | " Even when using GPU, embedding the protein sequences takes some time (~25mins) so to begin go ahead and run all cells of this notebook so that the process is started in the background as we review the notebook.\n",
74 | "
\n",
75 | "\n",
76 | " A shortcut to running all cells is going to the \"Runtime\" menu and selecting \"Run all\".\n",
77 | "\n",
78 | "
\n",
79 | "
"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "id": "0e5c4fc2-00ea-4e24-90fa-d96bf3751810",
85 | "metadata": {
86 | "id": "5c0749e1"
87 | },
88 | "source": [
89 | "----\n",
90 | "\n",
91 | "## The Data: P62593 Sequences\n",
92 | "\n",
93 | "To start we will import and explore the dataset: "
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": null,
99 | "id": "e520014b-391d-41b0-ad62-7d51f56511b8",
100 | "metadata": {},
101 | "outputs": [],
102 | "source": [
103 | "# Set up working directories and download files/checkpoints \n",
104 | "!mkdir protT5 # directory for storing checkpoints, results etc\n",
105 | "!mkdir protT5/output # directory for storing your embeddings\n",
106 | "!curl -o P62593.fasta https://dl.fbaipublicfiles.com/fair-esm/examples/P62593.fasta"
107 | ]
108 | },
109 | {
110 | "cell_type": "code",
111 | "execution_count": null,
112 | "id": "bcfc1b48-24d6-4d6f-86aa-9d3048a6d1d0",
113 | "metadata": {},
114 | "outputs": [],
115 | "source": [
116 | "# Import dependencies\n",
117 | "from transformers import T5EncoderModel, T5Tokenizer\n",
118 | "import torch\n",
119 | "import h5py\n",
120 | "import time\n",
121 | "from Bio import SeqIO\n",
122 | "\n",
123 | "# Path variables\n",
124 | "per_protein_path = \"./protT5/output/per_protein_embeddings.h5\" # where to store the embeddings\n",
125 | "seq_path = 'P62593.fasta' # where the fasta file is saved\n",
126 | "\n",
127 | "# check whether GPU is available\n",
128 | "device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')\n",
129 | "print(f\"Using {device}\")"
130 | ]
131 | },
132 | {
133 | "cell_type": "code",
134 | "execution_count": null,
135 | "id": "009ac9f9-b169-4696-abf6-a1c0a3ef8edf",
136 | "metadata": {},
137 | "outputs": [],
138 | "source": [
139 | "def read_fasta(fasta_path:str) -> dict:\n",
140 | " '''\n",
141 | " reads in fasta file and returns a dictionary with primary id/sequence key/value pairs \n",
142 | " '''\n",
143 | " \n",
144 | " # dictionary to append to\n",
145 | " seqs = {}\n",
146 | " \n",
147 | " # read in and parse fasta file\n",
148 | " with open(fasta_path) as handle:\n",
149 | " for record in SeqIO.parse(handle, \"fasta\"):\n",
150 | " # append each varient to the dict\n",
151 | " seqs[record.id] = record.seq\n",
152 | "\n",
153 | " # verbose\n",
154 | " example_id=next(iter(seqs))\n",
155 | " print(f\"Read {len(seqs)} sequences.\")\n",
156 | " print(f\"Example:\\nKey: {example_id}\\nValue: {seqs[example_id]}\")\n",
157 | "\n",
158 | " return seqs"
159 | ]
160 | },
161 | {
162 | "cell_type": "code",
163 | "execution_count": null,
164 | "id": "3aa98336-a298-4f5f-87b6-98718ec5e22f",
165 | "metadata": {},
166 | "outputs": [],
167 | "source": [
168 | "# read in file\n",
169 | "fasta_output = read_fasta(seq_path)"
170 | ]
171 | },
172 | {
173 | "cell_type": "markdown",
174 | "id": "717503ab-a593-4af2-8128-4e64491c3ebc",
175 | "metadata": {},
176 | "source": [
177 | "In the FASTA file there are 5,397 sequences. As we can see in the example above from our fasta dictionary, each entry contains:\n",
178 | "\n",
179 | "- key: `{index}|beta-lactamase_{mutation}|{scaled_varient_effect}`\n",
180 | " > in prediction.ipynb we will be predicting the `scaled_varient_effect` value, which describes the scaled effect of the mutation. \n",
181 | "- value: the mutated $\\beta$-lactamase sequence, where a single residue is mutated (swapped with another amino acid)"
182 | ]
183 | },
184 | {
185 | "cell_type": "markdown",
186 | "id": "ef06a40d-a52f-46bf-bfe7-3b2374eea224",
187 | "metadata": {},
188 | "source": [
189 | "## The Model: ProtT5-XL-UniRef50\n",
190 | "\n",
191 | "ProtT5-XL-UniRef50 is based on the t5-3b model and was pretrained on a large corpus of protein sequences in a self-supervised fashion. This means it was pretrained on the raw protein sequences only, with **no humans-in-the-loop labelling** them in any way (which is why it can use lots of publicly available data) with an automatic process to generate inputs and labels from those protein sequences.\n",
192 | "\n",
193 | "This model only contains the encoder portion of the original ProtT5-XL-UniRef50 model using half precision (float16). As such, this model can efficiently be used to create protein/ amino acid representations. When used for training downstream networks/ feature extraction, these embeddings produced the same performance (established empirically by comparing on several downstream tasks). \n",
194 | "\n",
195 | "In the following cells we will prepare functions that will later assist us when generating the embeddings. "
196 | ]
197 | },
198 | {
199 | "cell_type": "markdown",
200 | "id": "d072fe5a-3d34-475b-b025-abb7f3eef1f8",
201 | "metadata": {},
202 | "source": [
203 | "### `get_T5_model()` Load encoder-part of ProtT5 in half-precision\n",
204 | "\n",
205 | "To start we create a function that will load the model and associated tokenizer. Recall from the previous notebook (model_training.ipynb) where every model on `transformers` comes with an associated `tokenizer` that handles tokenization for it, where tokenization for protein language models involve coverting each amino acid to a single token.\n",
206 | "\n",
207 | "**Recall: Fine-tuning flow chart from the previous notebook**\n",
208 | "\n",
209 | "\n",
210 | "\n",
211 | "This function accomplishes the \"Model Checkpoint Loading\" step. "
212 | ]
213 | },
214 | {
215 | "cell_type": "code",
216 | "execution_count": null,
217 | "id": "ac1c2e47-9131-41f6-b39b-2da11b4afe2f",
218 | "metadata": {},
219 | "outputs": [],
220 | "source": [
221 | "# Load ProtT5 in half-precision (more specifically: the encoder-part of ProtT5-XL-U50) \n",
222 | "def get_T5_model():\n",
223 | " '''\n",
224 | " retrieves the model and tokenizer\n",
225 | " '''\n",
226 | " # specify the encorder-part of the model \n",
227 | " model_checkpoint = 'Rostlab/prot_t5_xl_half_uniref50-enc'\n",
228 | " \n",
229 | " # import the model \n",
230 | " model = T5EncoderModel.from_pretrained(model_checkpoint)\n",
231 | " \n",
232 | " model = model.to(device) # move model to GPU\n",
233 | " model = model.eval() # set model to evaluation model\n",
234 | " \n",
235 | " # import tokenizer\n",
236 | " tokenizer = T5Tokenizer.from_pretrained(model_checkpoint)\n",
237 | "\n",
238 | " return model, tokenizer"
239 | ]
240 | },
241 | {
242 | "cell_type": "markdown",
243 | "id": "4404313f-0c46-4cae-acea-5bfdbe86bd99",
244 | "metadata": {},
245 | "source": [
246 | "Let's use the function:"
247 | ]
248 | },
249 | {
250 | "cell_type": "code",
251 | "execution_count": null,
252 | "id": "5282b4cc-36f4-4c70-93f2-5fb32a67f6b9",
253 | "metadata": {},
254 | "outputs": [],
255 | "source": [
256 | "# loading model\n",
257 | "model, tokenizer = get_T5_model()"
258 | ]
259 | },
260 | {
261 | "cell_type": "markdown",
262 | "id": "6ef88997-d8c8-4c62-b394-1d2c3b005a4f",
263 | "metadata": {},
264 | "source": [
265 | "### `get_embeddings()` Using the model to generate the embeddings\n",
266 | "\n",
267 | "From the flow chart above, the function `get_embeddings()` includes the 'Tokenization' and 'Dataset Creation' steps. Additionally, the model will encode the sequences. "
268 | ]
269 | },
270 | {
271 | "cell_type": "code",
272 | "execution_count": null,
273 | "id": "261698df-2497-4f6d-89ef-1df09736110a",
274 | "metadata": {},
275 | "outputs": [],
276 | "source": [
277 | "def get_embeddings(model, tokenizer, seqs, max_seq_len=1000, max_batch=100):\n",
278 | " '''\n",
279 | " use the encoder to embbed the sequences via batch-processing\n",
280 | " -----\n",
281 | " \n",
282 | " parameters:\n",
283 | " model: from get_T5_model()\n",
284 | " tokenizer: from get_T5_model()\n",
285 | " seqs: the dictionary of sequences generated by read_fasta() \n",
286 | " max_seq_length: the upper sequences length for applying batch-processing\n",
287 | " max_batch: the upper number of sequences per batch\n",
288 | " \n",
289 | " returns:\n",
290 | " results: a dictionary containing the embedding representations of the sequences\n",
291 | " '''\n",
292 | "\n",
293 | " # initialize a dictionary, the embeddings will be accessible from results['protein_embs'] \n",
294 | " results = {\"protein_embs\" : dict()}\n",
295 | "\n",
296 | " # sort sequences according to length (reduces unnecessary padding --> speeds up embedding)\n",
297 | " seq_dict = sorted(seqs.items(), \n",
298 | " # 'key' option is a function that serves as a basis of sort comparison.\n",
299 | " key=lambda kv: len(seqs[kv[0]]), \n",
300 | " # sort by descending order\n",
301 | " reverse=True\n",
302 | " )\n",
303 | " \n",
304 | " # for time tracking\n",
305 | " start = time.time()\n",
306 | " \n",
307 | " # initialize empty list\n",
308 | " batch = list()\n",
309 | " \n",
310 | " # for each item in the dictionary\n",
311 | " for seq_idx, (pdb_id, seq) in enumerate(seq_dict, 1):\n",
312 | " \n",
313 | " # add space between residues\n",
314 | " seq = ' '.join(list(seq))\n",
315 | " \n",
316 | " # length of sequence with spaces\n",
317 | " seq_len = len(seq)\n",
318 | " \n",
319 | " # append to batch list as tuple\n",
320 | " batch.append((pdb_id, seq, seq_len))\n",
321 | "\n",
322 | " # creates n-tuple pairs from each element in batch\n",
323 | " pdb_ids, seqs, seq_lens = zip(*batch)\n",
324 | " \n",
325 | " # empty list\n",
326 | " batch = list()\n",
327 | " \n",
328 | " # Data Preparation and Tokenization:\n",
329 | "\n",
330 | " # add_special_tokens adds extra token at the end of each sequence\n",
331 | " token_encoding = tokenizer.batch_encode_plus(seqs, add_special_tokens=True, padding=\"longest\")\n",
332 | " \n",
333 | " # making the tokenized sequence into a tensor\n",
334 | " input_ids = torch.tensor(token_encoding['input_ids']).to(device)\n",
335 | " \n",
336 | " # now making the mask into a tensor\n",
337 | " attention_mask = torch.tensor(token_encoding['attention_mask']).to(device)\n",
338 | " \n",
339 | " # Generate Embedding:\n",
340 | " \n",
341 | " # using the model to encode the sequence, generating an embedding representation\n",
342 | " try:\n",
343 | " with torch.no_grad():\n",
344 | " embedding_repr = model(input_ids, attention_mask=attention_mask)\n",
345 | " # verbosity for progress tracking\n",
346 | " print(f'Currently, embedding {pdb_id}')\n",
347 | " except RuntimeError:\n",
348 | " print(\"RuntimeError during embedding for {} (L={})\".format(pdb_id, seq_len))\n",
349 | " continue\n",
350 | " \n",
351 | " # Putting together the dataset:\n",
352 | " \n",
353 | " # slice off padding if any \n",
354 | " emb = embedding_repr.last_hidden_state[0,:seq_len]\n",
355 | "\n",
356 | " # average along column\n",
357 | " protein_emb = emb.mean(dim=0)\n",
358 | "\n",
359 | " # save the embedding into results dictionary where the key = the fasta file entry header\n",
360 | " results[\"protein_embs\"][pdb_id] = protein_emb.detach().cpu().numpy().squeeze()\n",
361 | "\n",
362 | " # get time elapsed\n",
363 | " passed_time=time.time()-start\n",
364 | " avg_time = passed_time/len(results[\"protein_embs\"])\n",
365 | " \n",
366 | " # final verbose\n",
367 | " print('\\n############# EMBEDDING STATS #############')\n",
368 | " print('Total number of per-protein embeddings: {}'.format(len(results[\"protein_embs\"])))\n",
369 | " print(\"Time for generating embeddings: {:.1f}[m] ({:.3f}[s/protein])\".format(\n",
370 | " passed_time/60, avg_time ))\n",
371 | " print('\\n############# END #############')\n",
372 | " \n",
373 | " return results"
374 | ]
375 | },
376 | {
377 | "cell_type": "markdown",
378 | "id": "53ccafd2-6032-4e50-be6a-53e98897f922",
379 | "metadata": {},
380 | "source": [
381 | "**NOTE: What are special tokens?** \n",
382 | "\n",
383 | "Special tokens aren't present in the input text, but carry important meaning that we want the model to act on. For exmaple (not spevific to our model): \n",
384 | "- [PAD] Padding token — Added to the end of shorter inputs so that all inputs have the same length. This is because inputs to a neural network model are typically batched and the model operates on entire batches. \n",
385 | "- [UNK] Unknown token — Used to limit the number of distinct tokens. For example, if we want a vocabulary of at most 1000 tokens but the input text has 1200, then the remaining 200 will be converted to [UNK].\n",
386 | " \n",
387 | "You can read more [here](https://medium.com/@alexkubiesa/special-tokens-in-tensorflow-3c7718dcb0ef).\n",
388 | "\n",
389 | "We will move on and use the function to get the embeddings:"
390 | ]
391 | },
392 | {
393 | "cell_type": "code",
394 | "execution_count": null,
395 | "id": "6f4097b1-8da4-4cd7-9be1-4caf817294ab",
396 | "metadata": {},
397 | "outputs": [],
398 | "source": [
399 | "# Compute embeddings\n",
400 | "results = get_embeddings(model, tokenizer, fasta_output)"
401 | ]
402 | },
403 | {
404 | "cell_type": "markdown",
405 | "id": "fc2e3350-2791-4773-99f2-e55113f288ea",
406 | "metadata": {},
407 | "source": [
408 | "### `save_embeddings()` Writing the embeddings to a file\n",
409 | "\n",
410 | "For our final function, we will write the embeddings to a file. We will load this file into prediction.ipynb to train machine learning models. This is also a copy of the embedding file in the reposition in _data/_. "
411 | ]
412 | },
413 | {
414 | "cell_type": "code",
415 | "execution_count": null,
416 | "id": "6986186f-93f3-4efe-9597-3c60ce5059a5",
417 | "metadata": {},
418 | "outputs": [],
419 | "source": [
420 | "def save_embeddings(emb_dict:dict , out_path:str):\n",
421 | " '''\n",
422 | " takes the resulting embeddings from get_embeddings() and saves to a compressed h5 file\n",
423 | " -----\n",
424 | " \n",
425 | " parameters:\n",
426 | " emb_dict (dict): dictionary that is in results['protein_embs'] \n",
427 | " out_path (str): path and filename where the embeddings will be saved\n",
428 | " '''\n",
429 | " \n",
430 | " with h5py.File(str(out_path), \"w\") as hf:\n",
431 | " for sequence_id, embedding in emb_dict.items():\n",
432 | " hf.create_dataset(sequence_id, data=embedding)\n",
433 | " \n",
434 | " return None"
435 | ]
436 | },
437 | {
438 | "cell_type": "code",
439 | "execution_count": null,
440 | "id": "aea3a1d4-0091-4134-9773-0a901f644a12",
441 | "metadata": {},
442 | "outputs": [],
443 | "source": [
444 | "# write embeddings to file\n",
445 | "save_embeddings(results[\"protein_embs\"], per_protein_path)"
446 | ]
447 | }
448 | ],
449 | "metadata": {
450 | "kernelspec": {
451 | "display_name": "Python 3 (ipykernel)",
452 | "language": "python",
453 | "name": "python3"
454 | },
455 | "language_info": {
456 | "codemirror_mode": {
457 | "name": "ipython",
458 | "version": 3
459 | },
460 | "file_extension": ".py",
461 | "mimetype": "text/x-python",
462 | "name": "python",
463 | "nbconvert_exporter": "python",
464 | "pygments_lexer": "ipython3",
465 | "version": "3.10.9"
466 | }
467 | },
468 | "nbformat": 4,
469 | "nbformat_minor": 5
470 | }
471 |
--------------------------------------------------------------------------------
/notebooks/model_training.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "3494f2e1-0e62-4d3d-a161-6cff27727f78",
6 | "metadata": {},
7 | "source": [
8 | "
"
9 | ]
10 | },
11 | {
12 | "cell_type": "markdown",
13 | "id": "d183c1c8-5e35-4eec-9078-caccab5c4708",
14 | "metadata": {},
15 | "source": [
16 | "[](https://colab.research.google.com/github/Multiomics-Analytics-Group/course_protein_language_modeling/blob/main/notebooks/model_training.ipynb)\n",
17 | "\n",
18 | "\n",
19 | "This is a version of the notebook from [Matthew Carrigan](https://huggingface.co/Rocketknight1) --- [here](https://huggingface.co/blog/deep-learning-with-proteins)."
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 1,
25 | "id": "a78e617c-c8a7-4715-88d4-06e31e947c4a",
26 | "metadata": {},
27 | "outputs": [],
28 | "source": [
29 | "# uncomment the below to install dependencies for colab\n",
30 | "#!pip install \"transformers[torch]\" datasets evaluate biopython"
31 | ]
32 | },
33 | {
34 | "attachments": {},
35 | "cell_type": "markdown",
36 | "id": "5a6eb017-b2dc-4dbe-8771-69f1443d89e3",
37 | "metadata": {},
38 | "source": [
39 | "Important
\n",
40 | "If you are running in Google Colab, change the Notebook settings to use `GPU`.\n",
41 | "\n",
42 | "Just follow **Edit** > **Notebook settings** or **Runtime** > **Change runtime type** and select **GPU** as Hardware accelerator.\n",
43 | "\n",
44 | "
\n"
45 | ]
46 | },
47 | {
48 | "cell_type": "markdown",
49 | "id": "85f3e1b8-5517-4016-b7db-f1bb3bb33d31",
50 | "metadata": {
51 | "id": "5c0749e1"
52 | },
53 | "source": [
54 | "# Fine-Tuning Protein Language Models"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "id": "1b38b001-2450-4792-8647-31bae0bca58e",
60 | "metadata": {
61 | "id": "1d81db83"
62 | },
63 | "source": [
64 | "In this notebook, we are going to use transfer learning to fine-tune a large, pre-trained protein language model to predict **Subcellular location** based on protein sequence. \n",
65 | "\n",
66 | "The specific model we are going to use is [ESM](https://github.com/facebookresearch/esm), which is the state-of-the-art protein language model at the time of writing (November 2022) and described in detail in [Lin et al, 2022](https://www.biorxiv.org/content/10.1101/2022.07.20.500902v1).\n",
67 | "\n",
68 | "There are several ESM-2 checkpoints with differing model sizes. **A checkpoint** is an intermediate dump of a model’s entire internal state (weights, learning rate, etc.) so that the framework can resume the training from this point whenever desired. \n",
69 | "\n",
70 | "Larger models will generally have better accuracy, but they require more GPU memory and will take much longer to train. The available ESM-2 checkpoints are:\n",
71 | "\n",
72 | "| Checkpoint name | Num layers | Num parameters |\n",
73 | "|------------------------------|----|----------|\n",
74 | "| `esm2_t48_15B_UR50D` | 48 | 15B |\n",
75 | "| `esm2_t36_3B_UR50D` | 36 | 3B |\n",
76 | "| `esm2_t33_650M_UR50D` | 33 | 650M |\n",
77 | "| `esm2_t30_150M_UR50D` | 30 | 150M |\n",
78 | "| `esm2_t12_35M_UR50D` | 12 | 35M |\n",
79 | "| `esm2_t6_8M_UR50D` | 6 | 8M |\n",
80 | "\n",
81 | "*Note*: larger checkpoints may be very difficult to train without a large cloud GPU like an A100 or H100, and the largest 15B parameter checkpoint will probably be impossible to train on **any** single GPU! Also, note that memory usage for attention during training will scale as `O(batch_size * num_layers * seq_len^2)`, so larger models on long sequences will use quite a lot of memory! We will use the `esm2_t12_35M_UR50D` checkpoint for this notebook, which should train on any Colab instance or modern GPU."
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "execution_count": 2,
87 | "id": "2c447d8c-00ee-4a3b-b924-ccc36e865828",
88 | "metadata": {
89 | "id": "32e605a2"
90 | },
91 | "outputs": [],
92 | "source": [
93 | "model_checkpoint = \"facebook/esm2_t12_35M_UR50D\""
94 | ]
95 | },
96 | {
97 | "attachments": {},
98 | "cell_type": "markdown",
99 | "id": "2cbf0310-6664-4938-80cf-0d6cbe741f2e",
100 | "metadata": {
101 | "id": "a8e6ac19"
102 | },
103 | "source": [
104 | "# Fine-tuning\n",
105 | "\n",
106 | "
"
107 | ]
108 | },
109 | {
110 | "cell_type": "markdown",
111 | "id": "a7f033aa-d819-4e16-86de-feecf3d7b17c",
112 | "metadata": {},
113 | "source": [
114 | "## Subcellular Location"
115 | ]
116 | },
117 | {
118 | "cell_type": "markdown",
119 | "id": "33d88492-5d1e-4f4a-b09d-0f0642f17105",
120 | "metadata": {
121 | "id": "c5bc122f"
122 | },
123 | "source": [
124 | "## Data Collection"
125 | ]
126 | },
127 | {
128 | "cell_type": "markdown",
129 | "id": "57191840-da48-42ae-a5b9-c2eb87d0835f",
130 | "metadata": {
131 | "id": "4c91d394"
132 | },
133 | "source": [
134 | "We will gather data from [UniProt](https://www.uniprot.org/) to create a pair of lists: `sequences` and `labels`. `sequences` will be a list of protein sequences and `labels` will be a list of the category for each sequence (integers)."
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": 3,
140 | "id": "410bc787-ca60-44f5-98e6-1cb23e7e5088",
141 | "metadata": {
142 | "id": "c718ffbc"
143 | },
144 | "outputs": [
145 | {
146 | "name": "stdout",
147 | "output_type": "stream",
148 | "text": [
149 | "https://rest.uniprot.org/uniprotkb/stream?compressed=true&fields=accession%2Csequence%2Ccc_subcellular_location&format=tsv&query=%28%28organism_id%3A9606%29+AND+%28reviewed%3Atrue%29+AND+%28length%3A%5B80+TO+500%5D%29%29\n"
150 | ]
151 | }
152 | ],
153 | "source": [
154 | "import requests\n",
155 | "import urllib.parse\n",
156 | "\n",
157 | "organism = 9606\n",
158 | "fields = \",\".join(['accession', 'sequence', 'cc_subcellular_location'])\n",
159 | "query = f'((organism_id:{organism}) AND (reviewed:true) AND (length:[80 TO 500]))'\n",
160 | "params = {\n",
161 | " 'compressed': 'true', \n",
162 | " 'fields': fields, \n",
163 | " 'format':'tsv', \n",
164 | " 'query':query\n",
165 | "}\n",
166 | "query_url = 'https://rest.uniprot.org/uniprotkb/stream?'\n",
167 | "query_url += urllib.parse.urlencode(params)\n",
168 | "\n",
169 | "# take a look \n",
170 | "print(query_url)"
171 | ]
172 | },
173 | {
174 | "cell_type": "markdown",
175 | "id": "3412dd8d-958c-42da-bc26-0f021c832b7b",
176 | "metadata": {
177 | "id": "3d2edc14"
178 | },
179 | "source": [
180 | "We searched for `(organism_id:9606) AND (reviewed:true) AND (length:[80 TO 500])` on UniProt to get a list of reasonably-sized human proteins, then selected the format to TSV and the columns to `Accession`, `Sequence` and `Subcellular location [CC]`, since those contain the data we care about for this task."
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": 4,
186 | "id": "0bae78eb-e690-4574-b110-16f4f6a8a2e3",
187 | "metadata": {
188 | "id": "dd03ef98"
189 | },
190 | "outputs": [],
191 | "source": [
192 | "uniprot_request = requests.get(query_url)"
193 | ]
194 | },
195 | {
196 | "cell_type": "markdown",
197 | "id": "7494ca5e-f712-4b7b-9445-043942bc78a4",
198 | "metadata": {
199 | "id": "b7217b77"
200 | },
201 | "source": [
202 | "To get this data into Pandas, we use a `BytesIO` object, which Pandas will treat like a file. If you downloaded the data as a file you can skip this bit and just pass the filepath directly to `read_csv`."
203 | ]
204 | },
205 | {
206 | "cell_type": "code",
207 | "execution_count": 5,
208 | "id": "6e2481a9-b84b-420b-8fab-aadddc5160ef",
209 | "metadata": {
210 | "colab": {
211 | "base_uri": "https://localhost:8080/",
212 | "height": 468
213 | },
214 | "id": "f2c05017",
215 | "outputId": "9de817df-8a18-4ac3-b70b-452d8f6aa71a"
216 | },
217 | "outputs": [
218 | {
219 | "data": {
220 | "text/html": [
221 | "\n",
222 | "\n",
235 | "
\n",
236 | " \n",
237 | " \n",
238 | " | \n",
239 | " Entry | \n",
240 | " Sequence | \n",
241 | " Subcellular location [CC] | \n",
242 | "
\n",
243 | " \n",
244 | " \n",
245 | " \n",
246 | " 0 | \n",
247 | " A0A0K2S4Q6 | \n",
248 | " MTQRAGAAMLPSALLLLCVPGCLTVSGPSTVMGAVGESLSVQCRYE... | \n",
249 | " SUBCELLULAR LOCATION: [Isoform 1]: Membrane {E... | \n",
250 | "
\n",
251 | " \n",
252 | " 1 | \n",
253 | " A0AVI4 | \n",
254 | " MDSPEVTFTLAYLVFAVCFVFTPNEFHAAGLTVQNLLSGWLGSEDA... | \n",
255 | " SUBCELLULAR LOCATION: Endoplasmic reticulum me... | \n",
256 | "
\n",
257 | " \n",
258 | " 2 | \n",
259 | " A0JLT2 | \n",
260 | " MENFTALFGAQADPPPPPTALGFGPGKPPPPPPPPAGGGPGTAPPP... | \n",
261 | " SUBCELLULAR LOCATION: Nucleus {ECO:0000305}. | \n",
262 | "
\n",
263 | " \n",
264 | " 3 | \n",
265 | " A0M8Q6 | \n",
266 | " GQPKAAPSVTLFPPSSEELQANKATLVCLVSDFNPGAVTVAWKADG... | \n",
267 | " SUBCELLULAR LOCATION: Secreted {ECO:0000303|Pu... | \n",
268 | "
\n",
269 | " \n",
270 | " 4 | \n",
271 | " A0PJY2 | \n",
272 | " MDSSCHNATTKMLATAPARGNMMSTSKPLAFSIERIMARTPEPKAL... | \n",
273 | " SUBCELLULAR LOCATION: Nucleus {ECO:0000269|Pub... | \n",
274 | "
\n",
275 | " \n",
276 | "
\n",
277 | "
"
278 | ],
279 | "text/plain": [
280 | " Entry Sequence \\\n",
281 | "0 A0A0K2S4Q6 MTQRAGAAMLPSALLLLCVPGCLTVSGPSTVMGAVGESLSVQCRYE... \n",
282 | "1 A0AVI4 MDSPEVTFTLAYLVFAVCFVFTPNEFHAAGLTVQNLLSGWLGSEDA... \n",
283 | "2 A0JLT2 MENFTALFGAQADPPPPPTALGFGPGKPPPPPPPPAGGGPGTAPPP... \n",
284 | "3 A0M8Q6 GQPKAAPSVTLFPPSSEELQANKATLVCLVSDFNPGAVTVAWKADG... \n",
285 | "4 A0PJY2 MDSSCHNATTKMLATAPARGNMMSTSKPLAFSIERIMARTPEPKAL... \n",
286 | "\n",
287 | " Subcellular location [CC] \n",
288 | "0 SUBCELLULAR LOCATION: [Isoform 1]: Membrane {E... \n",
289 | "1 SUBCELLULAR LOCATION: Endoplasmic reticulum me... \n",
290 | "2 SUBCELLULAR LOCATION: Nucleus {ECO:0000305}. \n",
291 | "3 SUBCELLULAR LOCATION: Secreted {ECO:0000303|Pu... \n",
292 | "4 SUBCELLULAR LOCATION: Nucleus {ECO:0000269|Pub... "
293 | ]
294 | },
295 | "execution_count": 5,
296 | "metadata": {},
297 | "output_type": "execute_result"
298 | }
299 | ],
300 | "source": [
301 | "from io import BytesIO\n",
302 | "import pandas as pd\n",
303 | "\n",
304 | "# read in content to dataframe\n",
305 | "bio = BytesIO(uniprot_request.content)\n",
306 | "df = pd.read_csv(bio, compression='gzip', sep='\\t')\n",
307 | "\n",
308 | "# check out first 5 rows of df\n",
309 | "df.head()"
310 | ]
311 | },
312 | {
313 | "cell_type": "code",
314 | "execution_count": 6,
315 | "id": "ad5595c8-f8f1-42c3-aa53-cd332d7d38ac",
316 | "metadata": {},
317 | "outputs": [
318 | {
319 | "name": "stdout",
320 | "output_type": "stream",
321 | "text": [
322 | "\n",
323 | "RangeIndex: 11980 entries, 0 to 11979\n",
324 | "Data columns (total 3 columns):\n",
325 | " # Column Non-Null Count Dtype \n",
326 | "--- ------ -------------- ----- \n",
327 | " 0 Entry 11980 non-null object\n",
328 | " 1 Sequence 11980 non-null object\n",
329 | " 2 Subcellular location [CC] 9840 non-null object\n",
330 | "dtypes: object(3)\n",
331 | "memory usage: 280.9+ KB\n"
332 | ]
333 | }
334 | ],
335 | "source": [
336 | "# learn more about the df via .info() or .shape\n",
337 | "df.info()"
338 | ]
339 | },
340 | {
341 | "cell_type": "markdown",
342 | "id": "650dc9bf-47d7-4faa-98eb-2a40da2e1938",
343 | "metadata": {
344 | "id": "0bcdf34b"
345 | },
346 | "source": [
347 | "Nice! Now we have some proteins and their subcellular locations. Let's start filtering this down. First, let's ditch the columns without subcellular location information."
348 | ]
349 | },
350 | {
351 | "cell_type": "markdown",
352 | "id": "6badb1af-f4b8-46be-91cd-a75cb7a4c527",
353 | "metadata": {},
354 | "source": [
355 | "## Data Preparation"
356 | ]
357 | },
358 | {
359 | "cell_type": "code",
360 | "execution_count": 7,
361 | "id": "a2291e81-9d2b-4411-8305-62a0a058ebfe",
362 | "metadata": {
363 | "id": "31d87663"
364 | },
365 | "outputs": [],
366 | "source": [
367 | "# Drop proteins with missing columns\n",
368 | "df = df.dropna() "
369 | ]
370 | },
371 | {
372 | "cell_type": "code",
373 | "execution_count": 8,
374 | "id": "6d6f5b8b-455a-4c52-a47b-e3fc14467079",
375 | "metadata": {},
376 | "outputs": [
377 | {
378 | "name": "stdout",
379 | "output_type": "stream",
380 | "text": [
381 | "\n",
382 | "Index: 9840 entries, 0 to 11969\n",
383 | "Data columns (total 3 columns):\n",
384 | " # Column Non-Null Count Dtype \n",
385 | "--- ------ -------------- ----- \n",
386 | " 0 Entry 9840 non-null object\n",
387 | " 1 Sequence 9840 non-null object\n",
388 | " 2 Subcellular location [CC] 9840 non-null object\n",
389 | "dtypes: object(3)\n",
390 | "memory usage: 307.5+ KB\n"
391 | ]
392 | }
393 | ],
394 | "source": [
395 | "# check\n",
396 | "df.info()"
397 | ]
398 | },
399 | {
400 | "cell_type": "markdown",
401 | "id": "311e56bd-dabc-4b2e-8f82-7a6da8538bed",
402 | "metadata": {
403 | "id": "10d1af5c"
404 | },
405 | "source": [
406 | "Now we'll make one dataframe of proteins that contain `cytosol` or `cytoplasm` in their subcellular localization column, and a second that mentions the `membrane` or `cell membrane`."
407 | ]
408 | },
409 | {
410 | "cell_type": "code",
411 | "execution_count": 9,
412 | "id": "9f27cb39-8c94-4488-a446-7d0e9a031f23",
413 | "metadata": {
414 | "id": "c831bb16"
415 | },
416 | "outputs": [],
417 | "source": [
418 | "# first creating boolean series\n",
419 | "cytosolic = df['Subcellular location [CC]'].str.contains(\"Cytosol\") | df['Subcellular location [CC]'].str.contains(\"Cytoplasm\")\n",
420 | "membrane = df['Subcellular location [CC]'].str.contains(\"Membrane\") | df['Subcellular location [CC]'].str.contains(\"Cell membrane\")"
421 | ]
422 | },
423 | {
424 | "cell_type": "markdown",
425 | "id": "36c3c8a5-a041-4566-994d-5601edfcc5c4",
426 | "metadata": {},
427 | "source": [
428 | "We ensure that there is no overlap between classes."
429 | ]
430 | },
431 | {
432 | "cell_type": "code",
433 | "execution_count": 10,
434 | "id": "c3c7dec8-3f0e-4464-8997-184d9e580c90",
435 | "metadata": {
436 | "colab": {
437 | "base_uri": "https://localhost:8080/",
438 | "height": 424
439 | },
440 | "id": "f41139a2",
441 | "outputId": "05884511-1ce7-435b-b5f5-16cf91ca973c"
442 | },
443 | "outputs": [
444 | {
445 | "data": {
446 | "text/html": [
447 | "\n",
448 | "\n",
461 | "
\n",
462 | " \n",
463 | " \n",
464 | " | \n",
465 | " Entry | \n",
466 | " Sequence | \n",
467 | " Subcellular location [CC] | \n",
468 | "
\n",
469 | " \n",
470 | " \n",
471 | " \n",
472 | " 9 | \n",
473 | " A1E959 | \n",
474 | " MKIIILLGFLGATLSAPLIPQRLMSASNSNELLLNLNNGQLLPLQL... | \n",
475 | " SUBCELLULAR LOCATION: Secreted {ECO:0000250|Un... | \n",
476 | "
\n",
477 | " \n",
478 | " 14 | \n",
479 | " A1XBS5 | \n",
480 | " MMRRTLENRNAQTKQLQTAVSNVEKHFGELCQIFAAYVRKTARLRD... | \n",
481 | " SUBCELLULAR LOCATION: Cytoplasm {ECO:0000269|P... | \n",
482 | "
\n",
483 | " \n",
484 | " 18 | \n",
485 | " A2RU49 | \n",
486 | " MSSGNYQQSEALSKPTFSEEQASALVESVFGLKVSKVRPLPSYDDQ... | \n",
487 | " SUBCELLULAR LOCATION: Cytoplasm {ECO:0000305}. | \n",
488 | "
\n",
489 | " \n",
490 | " 20 | \n",
491 | " A2RUH7 | \n",
492 | " MEAATAPEVAAGSKLKVKEASPADAEPPQASPGQGAGSPTPQLLPP... | \n",
493 | " SUBCELLULAR LOCATION: Cytoplasm, myofibril, sa... | \n",
494 | "
\n",
495 | " \n",
496 | " 21 | \n",
497 | " A4D126 | \n",
498 | " MEAGPPGSARPAEPGPCLSGQRGADHTASASLQSVAGTEPGRHPQA... | \n",
499 | " SUBCELLULAR LOCATION: Cytoplasm, cytosol {ECO:... | \n",
500 | "
\n",
501 | " \n",
502 | "
\n",
503 | "
"
504 | ],
505 | "text/plain": [
506 | " Entry Sequence \\\n",
507 | "9 A1E959 MKIIILLGFLGATLSAPLIPQRLMSASNSNELLLNLNNGQLLPLQL... \n",
508 | "14 A1XBS5 MMRRTLENRNAQTKQLQTAVSNVEKHFGELCQIFAAYVRKTARLRD... \n",
509 | "18 A2RU49 MSSGNYQQSEALSKPTFSEEQASALVESVFGLKVSKVRPLPSYDDQ... \n",
510 | "20 A2RUH7 MEAATAPEVAAGSKLKVKEASPADAEPPQASPGQGAGSPTPQLLPP... \n",
511 | "21 A4D126 MEAGPPGSARPAEPGPCLSGQRGADHTASASLQSVAGTEPGRHPQA... \n",
512 | "\n",
513 | " Subcellular location [CC] \n",
514 | "9 SUBCELLULAR LOCATION: Secreted {ECO:0000250|Un... \n",
515 | "14 SUBCELLULAR LOCATION: Cytoplasm {ECO:0000269|P... \n",
516 | "18 SUBCELLULAR LOCATION: Cytoplasm {ECO:0000305}. \n",
517 | "20 SUBCELLULAR LOCATION: Cytoplasm, myofibril, sa... \n",
518 | "21 SUBCELLULAR LOCATION: Cytoplasm, cytosol {ECO:... "
519 | ]
520 | },
521 | "execution_count": 10,
522 | "metadata": {},
523 | "output_type": "execute_result"
524 | }
525 | ],
526 | "source": [
527 | "# use above booleans to filter df\n",
528 | "# NOTE: using .copy() when slicing/filtering an existing dataframe \n",
529 | "# prevents the triggering of 'SettingWithCopyWarning' \n",
530 | "cytosolic_df = df[cytosolic & ~membrane].copy()\n",
531 | "\n",
532 | "# check using .head() and/or .tail()\n",
533 | "cytosolic_df.head()"
534 | ]
535 | },
536 | {
537 | "cell_type": "code",
538 | "execution_count": 11,
539 | "id": "97b8ade4-d39e-48a1-ad5a-7908faeb9331",
540 | "metadata": {},
541 | "outputs": [
542 | {
543 | "data": {
544 | "text/html": [
545 | "\n",
546 | "\n",
559 | "
\n",
560 | " \n",
561 | " \n",
562 | " | \n",
563 | " Entry | \n",
564 | " Sequence | \n",
565 | " Subcellular location [CC] | \n",
566 | "
\n",
567 | " \n",
568 | " \n",
569 | " \n",
570 | " 11527 | \n",
571 | " Q8TDY3 | \n",
572 | " MFNPHALDSPAVIFDNGSGFCKAGLSGEFGPRHMVSSIVGHLKFQA... | \n",
573 | " SUBCELLULAR LOCATION: Cytoplasm, cytoskeleton ... | \n",
574 | "
\n",
575 | " \n",
576 | " 11540 | \n",
577 | " Q8WWF8 | \n",
578 | " MAGTARHDREMAIQAKKKLTTATDPIERLRLQCLARGSAGIKGLGR... | \n",
579 | " SUBCELLULAR LOCATION: Cytoplasm {ECO:0000305}. | \n",
580 | "
\n",
581 | " \n",
582 | " 11665 | \n",
583 | " Q9NUJ7 | \n",
584 | " MGGQVSASNSFSRLHCRNANEDWMSALCPRLWDVPLHHLSIPGSHD... | \n",
585 | " SUBCELLULAR LOCATION: Cytoplasm {ECO:0000269|P... | \n",
586 | "
\n",
587 | " \n",
588 | " 11667 | \n",
589 | " Q9NVM6 | \n",
590 | " MAVTKELLQMDLYALLGIEEKAADKEVKKAYRQKALSCHPDKNPDN... | \n",
591 | " SUBCELLULAR LOCATION: Cytoplasm {ECO:0000250|U... | \n",
592 | "
\n",
593 | " \n",
594 | " 11675 | \n",
595 | " Q9P2W6 | \n",
596 | " MGRTWCGMWRRRRPGRRSAVPRWPHLSSQSGVEPPDRWTGTPGWPS... | \n",
597 | " SUBCELLULAR LOCATION: Cytoplasm. | \n",
598 | "
\n",
599 | " \n",
600 | "
\n",
601 | "
"
602 | ],
603 | "text/plain": [
604 | " Entry Sequence \\\n",
605 | "11527 Q8TDY3 MFNPHALDSPAVIFDNGSGFCKAGLSGEFGPRHMVSSIVGHLKFQA... \n",
606 | "11540 Q8WWF8 MAGTARHDREMAIQAKKKLTTATDPIERLRLQCLARGSAGIKGLGR... \n",
607 | "11665 Q9NUJ7 MGGQVSASNSFSRLHCRNANEDWMSALCPRLWDVPLHHLSIPGSHD... \n",
608 | "11667 Q9NVM6 MAVTKELLQMDLYALLGIEEKAADKEVKKAYRQKALSCHPDKNPDN... \n",
609 | "11675 Q9P2W6 MGRTWCGMWRRRRPGRRSAVPRWPHLSSQSGVEPPDRWTGTPGWPS... \n",
610 | "\n",
611 | " Subcellular location [CC] \n",
612 | "11527 SUBCELLULAR LOCATION: Cytoplasm, cytoskeleton ... \n",
613 | "11540 SUBCELLULAR LOCATION: Cytoplasm {ECO:0000305}. \n",
614 | "11665 SUBCELLULAR LOCATION: Cytoplasm {ECO:0000269|P... \n",
615 | "11667 SUBCELLULAR LOCATION: Cytoplasm {ECO:0000250|U... \n",
616 | "11675 SUBCELLULAR LOCATION: Cytoplasm. "
617 | ]
618 | },
619 | "execution_count": 11,
620 | "metadata": {},
621 | "output_type": "execute_result"
622 | }
623 | ],
624 | "source": [
625 | "cytosolic_df.tail()"
626 | ]
627 | },
628 | {
629 | "cell_type": "code",
630 | "execution_count": 12,
631 | "id": "ab5a996f-ca49-4f34-ac85-15b51ef09826",
632 | "metadata": {
633 | "colab": {
634 | "base_uri": "https://localhost:8080/",
635 | "height": 424
636 | },
637 | "id": "be5c420e",
638 | "outputId": "2588389b-05e0-4707-8e93-9995880b2dee"
639 | },
640 | "outputs": [
641 | {
642 | "data": {
643 | "text/html": [
644 | "\n",
645 | "\n",
658 | "
\n",
659 | " \n",
660 | " \n",
661 | " | \n",
662 | " Entry | \n",
663 | " Sequence | \n",
664 | " Subcellular location [CC] | \n",
665 | "
\n",
666 | " \n",
667 | " \n",
668 | " \n",
669 | " 0 | \n",
670 | " A0A0K2S4Q6 | \n",
671 | " MTQRAGAAMLPSALLLLCVPGCLTVSGPSTVMGAVGESLSVQCRYE... | \n",
672 | " SUBCELLULAR LOCATION: [Isoform 1]: Membrane {E... | \n",
673 | "
\n",
674 | " \n",
675 | " 3 | \n",
676 | " A0M8Q6 | \n",
677 | " GQPKAAPSVTLFPPSSEELQANKATLVCLVSDFNPGAVTVAWKADG... | \n",
678 | " SUBCELLULAR LOCATION: Secreted {ECO:0000303|Pu... | \n",
679 | "
\n",
680 | " \n",
681 | " 17 | \n",
682 | " A2RU14 | \n",
683 | " MAGTVLGVGAGVFILALLWVAVLLLCVLLSRASGAARFSVIFLFFG... | \n",
684 | " SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... | \n",
685 | "
\n",
686 | " \n",
687 | " 33 | \n",
688 | " A5X5Y0 | \n",
689 | " MEGSWFHRKRFSFYLLLGFLLQGRGVTFTINCSGFGQHGADPTALN... | \n",
690 | " SUBCELLULAR LOCATION: Postsynaptic cell membra... | \n",
691 | "
\n",
692 | " \n",
693 | " 36 | \n",
694 | " A6ND01 | \n",
695 | " MACWWPLLLELWTVMPTWAGDELLNICMNAKHHKRVPSPEDKLYEE... | \n",
696 | " SUBCELLULAR LOCATION: Cell membrane {ECO:00002... | \n",
697 | "
\n",
698 | " \n",
699 | "
\n",
700 | "
"
701 | ],
702 | "text/plain": [
703 | " Entry Sequence \\\n",
704 | "0 A0A0K2S4Q6 MTQRAGAAMLPSALLLLCVPGCLTVSGPSTVMGAVGESLSVQCRYE... \n",
705 | "3 A0M8Q6 GQPKAAPSVTLFPPSSEELQANKATLVCLVSDFNPGAVTVAWKADG... \n",
706 | "17 A2RU14 MAGTVLGVGAGVFILALLWVAVLLLCVLLSRASGAARFSVIFLFFG... \n",
707 | "33 A5X5Y0 MEGSWFHRKRFSFYLLLGFLLQGRGVTFTINCSGFGQHGADPTALN... \n",
708 | "36 A6ND01 MACWWPLLLELWTVMPTWAGDELLNICMNAKHHKRVPSPEDKLYEE... \n",
709 | "\n",
710 | " Subcellular location [CC] \n",
711 | "0 SUBCELLULAR LOCATION: [Isoform 1]: Membrane {E... \n",
712 | "3 SUBCELLULAR LOCATION: Secreted {ECO:0000303|Pu... \n",
713 | "17 SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... \n",
714 | "33 SUBCELLULAR LOCATION: Postsynaptic cell membra... \n",
715 | "36 SUBCELLULAR LOCATION: Cell membrane {ECO:00002... "
716 | ]
717 | },
718 | "execution_count": 12,
719 | "metadata": {},
720 | "output_type": "execute_result"
721 | }
722 | ],
723 | "source": [
724 | "# use boolean series to filter df\n",
725 | "membrane_df = df[membrane & ~cytosolic].copy()\n",
726 | "\n",
727 | "# check\n",
728 | "membrane_df.head()"
729 | ]
730 | },
731 | {
732 | "cell_type": "code",
733 | "execution_count": 13,
734 | "id": "7a0596b8-6655-4000-a8f6-555b961b84ab",
735 | "metadata": {},
736 | "outputs": [
737 | {
738 | "data": {
739 | "text/html": [
740 | "\n",
741 | "\n",
754 | "
\n",
755 | " \n",
756 | " \n",
757 | " | \n",
758 | " Entry | \n",
759 | " Sequence | \n",
760 | " Subcellular location [CC] | \n",
761 | "
\n",
762 | " \n",
763 | " \n",
764 | " \n",
765 | " 11896 | \n",
766 | " Q86UQ5 | \n",
767 | " MQSDIYHPGHSFPSWVLCWVHSCGHEGHLRETAEIRKTHQNGDLQI... | \n",
768 | " SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... | \n",
769 | "
\n",
770 | " \n",
771 | " 11920 | \n",
772 | " Q8N8V8 | \n",
773 | " MLLKVRRASLKPPATPHQGAFRAGNVIGQLIYLLTWSLFTAWLRPP... | \n",
774 | " SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... | \n",
775 | "
\n",
776 | " \n",
777 | " 11959 | \n",
778 | " Q96N68 | \n",
779 | " MQGQGALKESHIHLPTEQPEASLVLQGQLAESSALGPKGALRPQAQ... | \n",
780 | " SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... | \n",
781 | "
\n",
782 | " \n",
783 | " 11966 | \n",
784 | " Q9H0A3 | \n",
785 | " MMNNTDFLMLNNPWNKLCLVSMDFCFPLDFVSNLFWIFASKFIIVT... | \n",
786 | " SUBCELLULAR LOCATION: Membrane {ECO:0000255}; ... | \n",
787 | "
\n",
788 | " \n",
789 | " 11969 | \n",
790 | " Q9H354 | \n",
791 | " MNKHNLRLVQLASELILIEIIPKLFLSQVTTISHIKREKIPPNHRK... | \n",
792 | " SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... | \n",
793 | "
\n",
794 | " \n",
795 | "
\n",
796 | "
"
797 | ],
798 | "text/plain": [
799 | " Entry Sequence \\\n",
800 | "11896 Q86UQ5 MQSDIYHPGHSFPSWVLCWVHSCGHEGHLRETAEIRKTHQNGDLQI... \n",
801 | "11920 Q8N8V8 MLLKVRRASLKPPATPHQGAFRAGNVIGQLIYLLTWSLFTAWLRPP... \n",
802 | "11959 Q96N68 MQGQGALKESHIHLPTEQPEASLVLQGQLAESSALGPKGALRPQAQ... \n",
803 | "11966 Q9H0A3 MMNNTDFLMLNNPWNKLCLVSMDFCFPLDFVSNLFWIFASKFIIVT... \n",
804 | "11969 Q9H354 MNKHNLRLVQLASELILIEIIPKLFLSQVTTISHIKREKIPPNHRK... \n",
805 | "\n",
806 | " Subcellular location [CC] \n",
807 | "11896 SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... \n",
808 | "11920 SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... \n",
809 | "11959 SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... \n",
810 | "11966 SUBCELLULAR LOCATION: Membrane {ECO:0000255}; ... \n",
811 | "11969 SUBCELLULAR LOCATION: Membrane {ECO:0000305}; ... "
812 | ]
813 | },
814 | "execution_count": 13,
815 | "metadata": {},
816 | "output_type": "execute_result"
817 | }
818 | ],
819 | "source": [
820 | "membrane_df.tail()"
821 | ]
822 | },
823 | {
824 | "cell_type": "markdown",
825 | "id": "9798179a-96ac-42d3-959e-79cd9564a63c",
826 | "metadata": {
827 | "id": "77e8cea6"
828 | },
829 | "source": [
830 | "Now, let's add labels. We use `0` as the label for cytosolic proteins and `1` as the label for membrane proteins."
831 | ]
832 | },
833 | {
834 | "cell_type": "code",
835 | "execution_count": 14,
836 | "id": "4ff5bbdb-6f11-4d9e-995a-2019f1338b73",
837 | "metadata": {},
838 | "outputs": [],
839 | "source": [
840 | "# adding label columns\n",
841 | "cytosolic_df['label'] = 0\n",
842 | "membrane_df['label'] = 1"
843 | ]
844 | },
845 | {
846 | "cell_type": "markdown",
847 | "id": "e430cec6-fb0c-45db-8854-52e9d37014a2",
848 | "metadata": {
849 | "id": "5a4bbda2"
850 | },
851 | "source": [
852 | "Now we will combine the 2 groups to form our initial dataset. Don't worry - the proteins will get shuffled when splitting the data!"
853 | ]
854 | },
855 | {
856 | "cell_type": "code",
857 | "execution_count": 15,
858 | "id": "a589d77f-7c63-4b5c-b584-8a4ca8f3d4cb",
859 | "metadata": {},
860 | "outputs": [
861 | {
862 | "name": "stdout",
863 | "output_type": "stream",
864 | "text": [
865 | "\n",
866 | "Index: 5170 entries, 9 to 11969\n",
867 | "Data columns (total 2 columns):\n",
868 | " # Column Non-Null Count Dtype \n",
869 | "--- ------ -------------- ----- \n",
870 | " 0 Sequence 5170 non-null object\n",
871 | " 1 label 5170 non-null int64 \n",
872 | "dtypes: int64(1), object(1)\n",
873 | "memory usage: 121.2+ KB\n"
874 | ]
875 | }
876 | ],
877 | "source": [
878 | "# combining dataframes and only keeping 'Sequence' and 'label' columns\n",
879 | "df_sequences = pd.concat([cytosolic_df, membrane_df])[['Sequence', 'label']]\n",
880 | "\n",
881 | "# check\n",
882 | "df_sequences.info()"
883 | ]
884 | },
885 | {
886 | "cell_type": "code",
887 | "execution_count": 16,
888 | "id": "2edbec8f-e266-4a47-92b5-5679eba48aa8",
889 | "metadata": {},
890 | "outputs": [
891 | {
892 | "data": {
893 | "text/plain": [
894 | "label\n",
895 | "0 0.509284\n",
896 | "1 0.490716\n",
897 | "Name: proportion, dtype: float64"
898 | ]
899 | },
900 | "execution_count": 16,
901 | "metadata": {},
902 | "output_type": "execute_result"
903 | }
904 | ],
905 | "source": [
906 | "# check class distribution\n",
907 | "df_sequences['label'].value_counts(normalize=True)"
908 | ]
909 | },
910 | {
911 | "cell_type": "markdown",
912 | "id": "79fdd50c-9531-4baa-a9a5-5e8e66521fc0",
913 | "metadata": {},
914 | "source": [
915 | "We can also see that we will be working with a dataset with a balanced number of observations per class. "
916 | ]
917 | },
918 | {
919 | "cell_type": "markdown",
920 | "id": "46d6f5a5-416b-4e74-8f11-ff574ceaf9b6",
921 | "metadata": {
922 | "id": "e0aac39c"
923 | },
924 | "source": [
925 | "### Splitting the data"
926 | ]
927 | },
928 | {
929 | "cell_type": "markdown",
930 | "id": "c2c00e81-f9b2-44af-b798-9b9029c0a5fc",
931 | "metadata": {
932 | "id": "a9099e7c"
933 | },
934 | "source": [
935 | "We need to split the data into train and test sets. We can use sklearn's function for that:"
936 | ]
937 | },
938 | {
939 | "cell_type": "code",
940 | "execution_count": 17,
941 | "id": "99b8a8bb-658c-42ad-a6b4-03cea93e6b13",
942 | "metadata": {
943 | "id": "366147ad"
944 | },
945 | "outputs": [],
946 | "source": [
947 | "from sklearn.model_selection import train_test_split\n",
948 | "\n",
949 | "train_sequences, test_sequences, train_labels, test_labels = train_test_split(\n",
950 | " df_sequences['Sequence'], \n",
951 | " df_sequences['label'],\n",
952 | " test_size=0.2,\n",
953 | " shuffle=True, #default\n",
954 | " stratify=df_sequences['label']\n",
955 | ")"
956 | ]
957 | },
958 | {
959 | "cell_type": "markdown",
960 | "id": "f0fcd94a-31be-4771-9a94-15de903183c2",
961 | "metadata": {},
962 | "source": [
963 | "### Quick EDA of the datasets"
964 | ]
965 | },
966 | {
967 | "cell_type": "code",
968 | "execution_count": 18,
969 | "id": "14faf07e-a4ef-4a24-a31e-2e532afad27f",
970 | "metadata": {},
971 | "outputs": [],
972 | "source": [
973 | "from Bio.SeqUtils.ProtParam import ProteinAnalysis\n",
974 | "\n",
975 | "# recall this function from seq_analysis.ipynb\n",
976 | "# calculates mean amino acid composition for a set of sequences\n",
977 | "def calculate_mean_AA_composition(sequences):\n",
978 | " stats = []\n",
979 | " for sequence in sequences:\n",
980 | " protein_sequence = ProteinAnalysis(sequence)\n",
981 | " st = {k:v/len(sequence) for k,v in protein_sequence.count_amino_acids().items()}\n",
982 | " stats.append(st)\n",
983 | " df = pd.DataFrame.from_dict(stats).transpose()\n",
984 | " df = df.T.mean().reset_index()\n",
985 | " df.columns = ['amino acid', 'mean']\n",
986 | "\n",
987 | " return df"
988 | ]
989 | },
990 | {
991 | "cell_type": "code",
992 | "execution_count": 19,
993 | "id": "f71e6845-85b1-490b-b1fd-420097446346",
994 | "metadata": {},
995 | "outputs": [],
996 | "source": [
997 | "train_df = calculate_mean_AA_composition(train_sequences)\n",
998 | "test_df = calculate_mean_AA_composition(test_sequences)"
999 | ]
1000 | },
1001 | {
1002 | "cell_type": "code",
1003 | "execution_count": 20,
1004 | "id": "8516588d-974d-4974-a142-b55b78cf6e19",
1005 | "metadata": {},
1006 | "outputs": [
1007 | {
1008 | "data": {
1009 | "application/vnd.plotly.v1+json": {
1010 | "config": {
1011 | "plotlyServerURL": "https://plot.ly"
1012 | },
1013 | "data": [
1014 | {
1015 | "alignmentgroup": "True",
1016 | "hovertemplate": "amino acid=%{x}
mean=%{marker.color}",
1017 | "legendgroup": "",
1018 | "marker": {
1019 | "color": [
1020 | 0.014276530857263214,
1021 | 0.02374415775646245,
1022 | 0.02505995966826259,
1023 | 0.025541000480718307,
1024 | 0.0311588126052296,
1025 | 0.03428877300617997,
1026 | 0.04187413465529812,
1027 | 0.04339843667362734,
1028 | 0.043415117293841746,
1029 | 0.04902146015841204,
1030 | 0.052457196707355165,
1031 | 0.05323904688250555,
1032 | 0.05384332962888099,
1033 | 0.056038465489439596,
1034 | 0.06104812530264299,
1035 | 0.06561811577004506,
1036 | 0.06580619532417109,
1037 | 0.0733023743902716,
1038 | 0.07845822449785629,
1039 | 0.10839390317870566
1040 | ],
1041 | "coloraxis": "coloraxis",
1042 | "pattern": {
1043 | "shape": ""
1044 | }
1045 | },
1046 | "name": "",
1047 | "offsetgroup": "",
1048 | "orientation": "v",
1049 | "showlegend": false,
1050 | "textposition": "auto",
1051 | "type": "bar",
1052 | "x": [
1053 | "W",
1054 | "H",
1055 | "C",
1056 | "M",
1057 | "Y",
1058 | "N",
1059 | "Q",
1060 | "D",
1061 | "F",
1062 | "I",
1063 | "K",
1064 | "R",
1065 | "T",
1066 | "P",
1067 | "E",
1068 | "G",
1069 | "V",
1070 | "A",
1071 | "S",
1072 | "L"
1073 | ],
1074 | "xaxis": "x",
1075 | "y": [
1076 | 0.014276530857263214,
1077 | 0.02374415775646245,
1078 | 0.02505995966826259,
1079 | 0.025541000480718307,
1080 | 0.0311588126052296,
1081 | 0.03428877300617997,
1082 | 0.04187413465529812,
1083 | 0.04339843667362734,
1084 | 0.043415117293841746,
1085 | 0.04902146015841204,
1086 | 0.052457196707355165,
1087 | 0.05323904688250555,
1088 | 0.05384332962888099,
1089 | 0.056038465489439596,
1090 | 0.06104812530264299,
1091 | 0.06561811577004506,
1092 | 0.06580619532417109,
1093 | 0.0733023743902716,
1094 | 0.07845822449785629,
1095 | 0.10839390317870566
1096 | ],
1097 | "yaxis": "y"
1098 | }
1099 | ],
1100 | "layout": {
1101 | "barmode": "relative",
1102 | "coloraxis": {
1103 | "colorbar": {
1104 | "title": {
1105 | "text": "mean"
1106 | }
1107 | },
1108 | "colorscale": [
1109 | [
1110 | 0,
1111 | "#0d0887"
1112 | ],
1113 | [
1114 | 0.1111111111111111,
1115 | "#46039f"
1116 | ],
1117 | [
1118 | 0.2222222222222222,
1119 | "#7201a8"
1120 | ],
1121 | [
1122 | 0.3333333333333333,
1123 | "#9c179e"
1124 | ],
1125 | [
1126 | 0.4444444444444444,
1127 | "#bd3786"
1128 | ],
1129 | [
1130 | 0.5555555555555556,
1131 | "#d8576b"
1132 | ],
1133 | [
1134 | 0.6666666666666666,
1135 | "#ed7953"
1136 | ],
1137 | [
1138 | 0.7777777777777778,
1139 | "#fb9f3a"
1140 | ],
1141 | [
1142 | 0.8888888888888888,
1143 | "#fdca26"
1144 | ],
1145 | [
1146 | 1,
1147 | "#f0f921"
1148 | ]
1149 | ]
1150 | },
1151 | "legend": {
1152 | "tracegroupgap": 0
1153 | },
1154 | "margin": {
1155 | "t": 60
1156 | },
1157 | "template": {
1158 | "data": {
1159 | "bar": [
1160 | {
1161 | "error_x": {
1162 | "color": "#2a3f5f"
1163 | },
1164 | "error_y": {
1165 | "color": "#2a3f5f"
1166 | },
1167 | "marker": {
1168 | "line": {
1169 | "color": "#E5ECF6",
1170 | "width": 0.5
1171 | },
1172 | "pattern": {
1173 | "fillmode": "overlay",
1174 | "size": 10,
1175 | "solidity": 0.2
1176 | }
1177 | },
1178 | "type": "bar"
1179 | }
1180 | ],
1181 | "barpolar": [
1182 | {
1183 | "marker": {
1184 | "line": {
1185 | "color": "#E5ECF6",
1186 | "width": 0.5
1187 | },
1188 | "pattern": {
1189 | "fillmode": "overlay",
1190 | "size": 10,
1191 | "solidity": 0.2
1192 | }
1193 | },
1194 | "type": "barpolar"
1195 | }
1196 | ],
1197 | "carpet": [
1198 | {
1199 | "aaxis": {
1200 | "endlinecolor": "#2a3f5f",
1201 | "gridcolor": "white",
1202 | "linecolor": "white",
1203 | "minorgridcolor": "white",
1204 | "startlinecolor": "#2a3f5f"
1205 | },
1206 | "baxis": {
1207 | "endlinecolor": "#2a3f5f",
1208 | "gridcolor": "white",
1209 | "linecolor": "white",
1210 | "minorgridcolor": "white",
1211 | "startlinecolor": "#2a3f5f"
1212 | },
1213 | "type": "carpet"
1214 | }
1215 | ],
1216 | "choropleth": [
1217 | {
1218 | "colorbar": {
1219 | "outlinewidth": 0,
1220 | "ticks": ""
1221 | },
1222 | "type": "choropleth"
1223 | }
1224 | ],
1225 | "contour": [
1226 | {
1227 | "colorbar": {
1228 | "outlinewidth": 0,
1229 | "ticks": ""
1230 | },
1231 | "colorscale": [
1232 | [
1233 | 0,
1234 | "#0d0887"
1235 | ],
1236 | [
1237 | 0.1111111111111111,
1238 | "#46039f"
1239 | ],
1240 | [
1241 | 0.2222222222222222,
1242 | "#7201a8"
1243 | ],
1244 | [
1245 | 0.3333333333333333,
1246 | "#9c179e"
1247 | ],
1248 | [
1249 | 0.4444444444444444,
1250 | "#bd3786"
1251 | ],
1252 | [
1253 | 0.5555555555555556,
1254 | "#d8576b"
1255 | ],
1256 | [
1257 | 0.6666666666666666,
1258 | "#ed7953"
1259 | ],
1260 | [
1261 | 0.7777777777777778,
1262 | "#fb9f3a"
1263 | ],
1264 | [
1265 | 0.8888888888888888,
1266 | "#fdca26"
1267 | ],
1268 | [
1269 | 1,
1270 | "#f0f921"
1271 | ]
1272 | ],
1273 | "type": "contour"
1274 | }
1275 | ],
1276 | "contourcarpet": [
1277 | {
1278 | "colorbar": {
1279 | "outlinewidth": 0,
1280 | "ticks": ""
1281 | },
1282 | "type": "contourcarpet"
1283 | }
1284 | ],
1285 | "heatmap": [
1286 | {
1287 | "colorbar": {
1288 | "outlinewidth": 0,
1289 | "ticks": ""
1290 | },
1291 | "colorscale": [
1292 | [
1293 | 0,
1294 | "#0d0887"
1295 | ],
1296 | [
1297 | 0.1111111111111111,
1298 | "#46039f"
1299 | ],
1300 | [
1301 | 0.2222222222222222,
1302 | "#7201a8"
1303 | ],
1304 | [
1305 | 0.3333333333333333,
1306 | "#9c179e"
1307 | ],
1308 | [
1309 | 0.4444444444444444,
1310 | "#bd3786"
1311 | ],
1312 | [
1313 | 0.5555555555555556,
1314 | "#d8576b"
1315 | ],
1316 | [
1317 | 0.6666666666666666,
1318 | "#ed7953"
1319 | ],
1320 | [
1321 | 0.7777777777777778,
1322 | "#fb9f3a"
1323 | ],
1324 | [
1325 | 0.8888888888888888,
1326 | "#fdca26"
1327 | ],
1328 | [
1329 | 1,
1330 | "#f0f921"
1331 | ]
1332 | ],
1333 | "type": "heatmap"
1334 | }
1335 | ],
1336 | "heatmapgl": [
1337 | {
1338 | "colorbar": {
1339 | "outlinewidth": 0,
1340 | "ticks": ""
1341 | },
1342 | "colorscale": [
1343 | [
1344 | 0,
1345 | "#0d0887"
1346 | ],
1347 | [
1348 | 0.1111111111111111,
1349 | "#46039f"
1350 | ],
1351 | [
1352 | 0.2222222222222222,
1353 | "#7201a8"
1354 | ],
1355 | [
1356 | 0.3333333333333333,
1357 | "#9c179e"
1358 | ],
1359 | [
1360 | 0.4444444444444444,
1361 | "#bd3786"
1362 | ],
1363 | [
1364 | 0.5555555555555556,
1365 | "#d8576b"
1366 | ],
1367 | [
1368 | 0.6666666666666666,
1369 | "#ed7953"
1370 | ],
1371 | [
1372 | 0.7777777777777778,
1373 | "#fb9f3a"
1374 | ],
1375 | [
1376 | 0.8888888888888888,
1377 | "#fdca26"
1378 | ],
1379 | [
1380 | 1,
1381 | "#f0f921"
1382 | ]
1383 | ],
1384 | "type": "heatmapgl"
1385 | }
1386 | ],
1387 | "histogram": [
1388 | {
1389 | "marker": {
1390 | "pattern": {
1391 | "fillmode": "overlay",
1392 | "size": 10,
1393 | "solidity": 0.2
1394 | }
1395 | },
1396 | "type": "histogram"
1397 | }
1398 | ],
1399 | "histogram2d": [
1400 | {
1401 | "colorbar": {
1402 | "outlinewidth": 0,
1403 | "ticks": ""
1404 | },
1405 | "colorscale": [
1406 | [
1407 | 0,
1408 | "#0d0887"
1409 | ],
1410 | [
1411 | 0.1111111111111111,
1412 | "#46039f"
1413 | ],
1414 | [
1415 | 0.2222222222222222,
1416 | "#7201a8"
1417 | ],
1418 | [
1419 | 0.3333333333333333,
1420 | "#9c179e"
1421 | ],
1422 | [
1423 | 0.4444444444444444,
1424 | "#bd3786"
1425 | ],
1426 | [
1427 | 0.5555555555555556,
1428 | "#d8576b"
1429 | ],
1430 | [
1431 | 0.6666666666666666,
1432 | "#ed7953"
1433 | ],
1434 | [
1435 | 0.7777777777777778,
1436 | "#fb9f3a"
1437 | ],
1438 | [
1439 | 0.8888888888888888,
1440 | "#fdca26"
1441 | ],
1442 | [
1443 | 1,
1444 | "#f0f921"
1445 | ]
1446 | ],
1447 | "type": "histogram2d"
1448 | }
1449 | ],
1450 | "histogram2dcontour": [
1451 | {
1452 | "colorbar": {
1453 | "outlinewidth": 0,
1454 | "ticks": ""
1455 | },
1456 | "colorscale": [
1457 | [
1458 | 0,
1459 | "#0d0887"
1460 | ],
1461 | [
1462 | 0.1111111111111111,
1463 | "#46039f"
1464 | ],
1465 | [
1466 | 0.2222222222222222,
1467 | "#7201a8"
1468 | ],
1469 | [
1470 | 0.3333333333333333,
1471 | "#9c179e"
1472 | ],
1473 | [
1474 | 0.4444444444444444,
1475 | "#bd3786"
1476 | ],
1477 | [
1478 | 0.5555555555555556,
1479 | "#d8576b"
1480 | ],
1481 | [
1482 | 0.6666666666666666,
1483 | "#ed7953"
1484 | ],
1485 | [
1486 | 0.7777777777777778,
1487 | "#fb9f3a"
1488 | ],
1489 | [
1490 | 0.8888888888888888,
1491 | "#fdca26"
1492 | ],
1493 | [
1494 | 1,
1495 | "#f0f921"
1496 | ]
1497 | ],
1498 | "type": "histogram2dcontour"
1499 | }
1500 | ],
1501 | "mesh3d": [
1502 | {
1503 | "colorbar": {
1504 | "outlinewidth": 0,
1505 | "ticks": ""
1506 | },
1507 | "type": "mesh3d"
1508 | }
1509 | ],
1510 | "parcoords": [
1511 | {
1512 | "line": {
1513 | "colorbar": {
1514 | "outlinewidth": 0,
1515 | "ticks": ""
1516 | }
1517 | },
1518 | "type": "parcoords"
1519 | }
1520 | ],
1521 | "pie": [
1522 | {
1523 | "automargin": true,
1524 | "type": "pie"
1525 | }
1526 | ],
1527 | "scatter": [
1528 | {
1529 | "fillpattern": {
1530 | "fillmode": "overlay",
1531 | "size": 10,
1532 | "solidity": 0.2
1533 | },
1534 | "type": "scatter"
1535 | }
1536 | ],
1537 | "scatter3d": [
1538 | {
1539 | "line": {
1540 | "colorbar": {
1541 | "outlinewidth": 0,
1542 | "ticks": ""
1543 | }
1544 | },
1545 | "marker": {
1546 | "colorbar": {
1547 | "outlinewidth": 0,
1548 | "ticks": ""
1549 | }
1550 | },
1551 | "type": "scatter3d"
1552 | }
1553 | ],
1554 | "scattercarpet": [
1555 | {
1556 | "marker": {
1557 | "colorbar": {
1558 | "outlinewidth": 0,
1559 | "ticks": ""
1560 | }
1561 | },
1562 | "type": "scattercarpet"
1563 | }
1564 | ],
1565 | "scattergeo": [
1566 | {
1567 | "marker": {
1568 | "colorbar": {
1569 | "outlinewidth": 0,
1570 | "ticks": ""
1571 | }
1572 | },
1573 | "type": "scattergeo"
1574 | }
1575 | ],
1576 | "scattergl": [
1577 | {
1578 | "marker": {
1579 | "colorbar": {
1580 | "outlinewidth": 0,
1581 | "ticks": ""
1582 | }
1583 | },
1584 | "type": "scattergl"
1585 | }
1586 | ],
1587 | "scattermapbox": [
1588 | {
1589 | "marker": {
1590 | "colorbar": {
1591 | "outlinewidth": 0,
1592 | "ticks": ""
1593 | }
1594 | },
1595 | "type": "scattermapbox"
1596 | }
1597 | ],
1598 | "scatterpolar": [
1599 | {
1600 | "marker": {
1601 | "colorbar": {
1602 | "outlinewidth": 0,
1603 | "ticks": ""
1604 | }
1605 | },
1606 | "type": "scatterpolar"
1607 | }
1608 | ],
1609 | "scatterpolargl": [
1610 | {
1611 | "marker": {
1612 | "colorbar": {
1613 | "outlinewidth": 0,
1614 | "ticks": ""
1615 | }
1616 | },
1617 | "type": "scatterpolargl"
1618 | }
1619 | ],
1620 | "scatterternary": [
1621 | {
1622 | "marker": {
1623 | "colorbar": {
1624 | "outlinewidth": 0,
1625 | "ticks": ""
1626 | }
1627 | },
1628 | "type": "scatterternary"
1629 | }
1630 | ],
1631 | "surface": [
1632 | {
1633 | "colorbar": {
1634 | "outlinewidth": 0,
1635 | "ticks": ""
1636 | },
1637 | "colorscale": [
1638 | [
1639 | 0,
1640 | "#0d0887"
1641 | ],
1642 | [
1643 | 0.1111111111111111,
1644 | "#46039f"
1645 | ],
1646 | [
1647 | 0.2222222222222222,
1648 | "#7201a8"
1649 | ],
1650 | [
1651 | 0.3333333333333333,
1652 | "#9c179e"
1653 | ],
1654 | [
1655 | 0.4444444444444444,
1656 | "#bd3786"
1657 | ],
1658 | [
1659 | 0.5555555555555556,
1660 | "#d8576b"
1661 | ],
1662 | [
1663 | 0.6666666666666666,
1664 | "#ed7953"
1665 | ],
1666 | [
1667 | 0.7777777777777778,
1668 | "#fb9f3a"
1669 | ],
1670 | [
1671 | 0.8888888888888888,
1672 | "#fdca26"
1673 | ],
1674 | [
1675 | 1,
1676 | "#f0f921"
1677 | ]
1678 | ],
1679 | "type": "surface"
1680 | }
1681 | ],
1682 | "table": [
1683 | {
1684 | "cells": {
1685 | "fill": {
1686 | "color": "#EBF0F8"
1687 | },
1688 | "line": {
1689 | "color": "white"
1690 | }
1691 | },
1692 | "header": {
1693 | "fill": {
1694 | "color": "#C8D4E3"
1695 | },
1696 | "line": {
1697 | "color": "white"
1698 | }
1699 | },
1700 | "type": "table"
1701 | }
1702 | ]
1703 | },
1704 | "layout": {
1705 | "annotationdefaults": {
1706 | "arrowcolor": "#2a3f5f",
1707 | "arrowhead": 0,
1708 | "arrowwidth": 1
1709 | },
1710 | "autotypenumbers": "strict",
1711 | "coloraxis": {
1712 | "colorbar": {
1713 | "outlinewidth": 0,
1714 | "ticks": ""
1715 | }
1716 | },
1717 | "colorscale": {
1718 | "diverging": [
1719 | [
1720 | 0,
1721 | "#8e0152"
1722 | ],
1723 | [
1724 | 0.1,
1725 | "#c51b7d"
1726 | ],
1727 | [
1728 | 0.2,
1729 | "#de77ae"
1730 | ],
1731 | [
1732 | 0.3,
1733 | "#f1b6da"
1734 | ],
1735 | [
1736 | 0.4,
1737 | "#fde0ef"
1738 | ],
1739 | [
1740 | 0.5,
1741 | "#f7f7f7"
1742 | ],
1743 | [
1744 | 0.6,
1745 | "#e6f5d0"
1746 | ],
1747 | [
1748 | 0.7,
1749 | "#b8e186"
1750 | ],
1751 | [
1752 | 0.8,
1753 | "#7fbc41"
1754 | ],
1755 | [
1756 | 0.9,
1757 | "#4d9221"
1758 | ],
1759 | [
1760 | 1,
1761 | "#276419"
1762 | ]
1763 | ],
1764 | "sequential": [
1765 | [
1766 | 0,
1767 | "#0d0887"
1768 | ],
1769 | [
1770 | 0.1111111111111111,
1771 | "#46039f"
1772 | ],
1773 | [
1774 | 0.2222222222222222,
1775 | "#7201a8"
1776 | ],
1777 | [
1778 | 0.3333333333333333,
1779 | "#9c179e"
1780 | ],
1781 | [
1782 | 0.4444444444444444,
1783 | "#bd3786"
1784 | ],
1785 | [
1786 | 0.5555555555555556,
1787 | "#d8576b"
1788 | ],
1789 | [
1790 | 0.6666666666666666,
1791 | "#ed7953"
1792 | ],
1793 | [
1794 | 0.7777777777777778,
1795 | "#fb9f3a"
1796 | ],
1797 | [
1798 | 0.8888888888888888,
1799 | "#fdca26"
1800 | ],
1801 | [
1802 | 1,
1803 | "#f0f921"
1804 | ]
1805 | ],
1806 | "sequentialminus": [
1807 | [
1808 | 0,
1809 | "#0d0887"
1810 | ],
1811 | [
1812 | 0.1111111111111111,
1813 | "#46039f"
1814 | ],
1815 | [
1816 | 0.2222222222222222,
1817 | "#7201a8"
1818 | ],
1819 | [
1820 | 0.3333333333333333,
1821 | "#9c179e"
1822 | ],
1823 | [
1824 | 0.4444444444444444,
1825 | "#bd3786"
1826 | ],
1827 | [
1828 | 0.5555555555555556,
1829 | "#d8576b"
1830 | ],
1831 | [
1832 | 0.6666666666666666,
1833 | "#ed7953"
1834 | ],
1835 | [
1836 | 0.7777777777777778,
1837 | "#fb9f3a"
1838 | ],
1839 | [
1840 | 0.8888888888888888,
1841 | "#fdca26"
1842 | ],
1843 | [
1844 | 1,
1845 | "#f0f921"
1846 | ]
1847 | ]
1848 | },
1849 | "colorway": [
1850 | "#636efa",
1851 | "#EF553B",
1852 | "#00cc96",
1853 | "#ab63fa",
1854 | "#FFA15A",
1855 | "#19d3f3",
1856 | "#FF6692",
1857 | "#B6E880",
1858 | "#FF97FF",
1859 | "#FECB52"
1860 | ],
1861 | "font": {
1862 | "color": "#2a3f5f"
1863 | },
1864 | "geo": {
1865 | "bgcolor": "white",
1866 | "lakecolor": "white",
1867 | "landcolor": "#E5ECF6",
1868 | "showlakes": true,
1869 | "showland": true,
1870 | "subunitcolor": "white"
1871 | },
1872 | "hoverlabel": {
1873 | "align": "left"
1874 | },
1875 | "hovermode": "closest",
1876 | "mapbox": {
1877 | "style": "light"
1878 | },
1879 | "paper_bgcolor": "white",
1880 | "plot_bgcolor": "#E5ECF6",
1881 | "polar": {
1882 | "angularaxis": {
1883 | "gridcolor": "white",
1884 | "linecolor": "white",
1885 | "ticks": ""
1886 | },
1887 | "bgcolor": "#E5ECF6",
1888 | "radialaxis": {
1889 | "gridcolor": "white",
1890 | "linecolor": "white",
1891 | "ticks": ""
1892 | }
1893 | },
1894 | "scene": {
1895 | "xaxis": {
1896 | "backgroundcolor": "#E5ECF6",
1897 | "gridcolor": "white",
1898 | "gridwidth": 2,
1899 | "linecolor": "white",
1900 | "showbackground": true,
1901 | "ticks": "",
1902 | "zerolinecolor": "white"
1903 | },
1904 | "yaxis": {
1905 | "backgroundcolor": "#E5ECF6",
1906 | "gridcolor": "white",
1907 | "gridwidth": 2,
1908 | "linecolor": "white",
1909 | "showbackground": true,
1910 | "ticks": "",
1911 | "zerolinecolor": "white"
1912 | },
1913 | "zaxis": {
1914 | "backgroundcolor": "#E5ECF6",
1915 | "gridcolor": "white",
1916 | "gridwidth": 2,
1917 | "linecolor": "white",
1918 | "showbackground": true,
1919 | "ticks": "",
1920 | "zerolinecolor": "white"
1921 | }
1922 | },
1923 | "shapedefaults": {
1924 | "line": {
1925 | "color": "#2a3f5f"
1926 | }
1927 | },
1928 | "ternary": {
1929 | "aaxis": {
1930 | "gridcolor": "white",
1931 | "linecolor": "white",
1932 | "ticks": ""
1933 | },
1934 | "baxis": {
1935 | "gridcolor": "white",
1936 | "linecolor": "white",
1937 | "ticks": ""
1938 | },
1939 | "bgcolor": "#E5ECF6",
1940 | "caxis": {
1941 | "gridcolor": "white",
1942 | "linecolor": "white",
1943 | "ticks": ""
1944 | }
1945 | },
1946 | "title": {
1947 | "x": 0.05
1948 | },
1949 | "xaxis": {
1950 | "automargin": true,
1951 | "gridcolor": "white",
1952 | "linecolor": "white",
1953 | "ticks": "",
1954 | "title": {
1955 | "standoff": 15
1956 | },
1957 | "zerolinecolor": "white",
1958 | "zerolinewidth": 2
1959 | },
1960 | "yaxis": {
1961 | "automargin": true,
1962 | "gridcolor": "white",
1963 | "linecolor": "white",
1964 | "ticks": "",
1965 | "title": {
1966 | "standoff": 15
1967 | },
1968 | "zerolinecolor": "white",
1969 | "zerolinewidth": 2
1970 | }
1971 | }
1972 | },
1973 | "xaxis": {
1974 | "anchor": "y",
1975 | "domain": [
1976 | 0,
1977 | 1
1978 | ],
1979 | "title": {
1980 | "text": "amino acid"
1981 | }
1982 | },
1983 | "yaxis": {
1984 | "anchor": "x",
1985 | "domain": [
1986 | 0,
1987 | 1
1988 | ],
1989 | "title": {
1990 | "text": "mean"
1991 | }
1992 | }
1993 | }
1994 | }
1995 | },
1996 | "metadata": {},
1997 | "output_type": "display_data"
1998 | }
1999 | ],
2000 | "source": [
2001 | "import plotly.express as px\n",
2002 | "import plotly.io as pio\n",
2003 | "#pio.renderers.default = 'colab'\n",
2004 | "\n",
2005 | "fig = px.bar(train_df.sort_values(by='mean'), x='amino acid', y='mean', color='mean')\n",
2006 | "fig.show()"
2007 | ]
2008 | },
2009 | {
2010 | "cell_type": "code",
2011 | "execution_count": 21,
2012 | "id": "1bbe273e-cd36-4847-8123-d59c40c8d2f8",
2013 | "metadata": {},
2014 | "outputs": [
2015 | {
2016 | "data": {
2017 | "application/vnd.plotly.v1+json": {
2018 | "config": {
2019 | "plotlyServerURL": "https://plot.ly"
2020 | },
2021 | "data": [
2022 | {
2023 | "alignmentgroup": "True",
2024 | "hovertemplate": "amino acid=%{x}
mean=%{marker.color}",
2025 | "legendgroup": "",
2026 | "marker": {
2027 | "color": [
2028 | 0.014136117361704979,
2029 | 0.023589131494643693,
2030 | 0.025297232893305557,
2031 | 0.025371494199653944,
2032 | 0.031745002114803175,
2033 | 0.03430800452812807,
2034 | 0.041102400627987666,
2035 | 0.04284639551591461,
2036 | 0.04467896302341708,
2037 | 0.050013510118148724,
2038 | 0.051964618142288796,
2039 | 0.05346029887945661,
2040 | 0.0545606317541359,
2041 | 0.056677643109466436,
2042 | 0.05945287314037615,
2043 | 0.06529701346221778,
2044 | 0.06576621663029467,
2045 | 0.07405508152817654,
2046 | 0.07782976790796636,
2047 | 0.10784760356791326
2048 | ],
2049 | "coloraxis": "coloraxis",
2050 | "pattern": {
2051 | "shape": ""
2052 | }
2053 | },
2054 | "name": "",
2055 | "offsetgroup": "",
2056 | "orientation": "v",
2057 | "showlegend": false,
2058 | "textposition": "auto",
2059 | "type": "bar",
2060 | "x": [
2061 | "W",
2062 | "H",
2063 | "M",
2064 | "C",
2065 | "Y",
2066 | "N",
2067 | "Q",
2068 | "D",
2069 | "F",
2070 | "I",
2071 | "K",
2072 | "R",
2073 | "T",
2074 | "P",
2075 | "E",
2076 | "G",
2077 | "V",
2078 | "A",
2079 | "S",
2080 | "L"
2081 | ],
2082 | "xaxis": "x",
2083 | "y": [
2084 | 0.014136117361704979,
2085 | 0.023589131494643693,
2086 | 0.025297232893305557,
2087 | 0.025371494199653944,
2088 | 0.031745002114803175,
2089 | 0.03430800452812807,
2090 | 0.041102400627987666,
2091 | 0.04284639551591461,
2092 | 0.04467896302341708,
2093 | 0.050013510118148724,
2094 | 0.051964618142288796,
2095 | 0.05346029887945661,
2096 | 0.0545606317541359,
2097 | 0.056677643109466436,
2098 | 0.05945287314037615,
2099 | 0.06529701346221778,
2100 | 0.06576621663029467,
2101 | 0.07405508152817654,
2102 | 0.07782976790796636,
2103 | 0.10784760356791326
2104 | ],
2105 | "yaxis": "y"
2106 | }
2107 | ],
2108 | "layout": {
2109 | "barmode": "relative",
2110 | "coloraxis": {
2111 | "colorbar": {
2112 | "title": {
2113 | "text": "mean"
2114 | }
2115 | },
2116 | "colorscale": [
2117 | [
2118 | 0,
2119 | "#0d0887"
2120 | ],
2121 | [
2122 | 0.1111111111111111,
2123 | "#46039f"
2124 | ],
2125 | [
2126 | 0.2222222222222222,
2127 | "#7201a8"
2128 | ],
2129 | [
2130 | 0.3333333333333333,
2131 | "#9c179e"
2132 | ],
2133 | [
2134 | 0.4444444444444444,
2135 | "#bd3786"
2136 | ],
2137 | [
2138 | 0.5555555555555556,
2139 | "#d8576b"
2140 | ],
2141 | [
2142 | 0.6666666666666666,
2143 | "#ed7953"
2144 | ],
2145 | [
2146 | 0.7777777777777778,
2147 | "#fb9f3a"
2148 | ],
2149 | [
2150 | 0.8888888888888888,
2151 | "#fdca26"
2152 | ],
2153 | [
2154 | 1,
2155 | "#f0f921"
2156 | ]
2157 | ]
2158 | },
2159 | "legend": {
2160 | "tracegroupgap": 0
2161 | },
2162 | "margin": {
2163 | "t": 60
2164 | },
2165 | "template": {
2166 | "data": {
2167 | "bar": [
2168 | {
2169 | "error_x": {
2170 | "color": "#2a3f5f"
2171 | },
2172 | "error_y": {
2173 | "color": "#2a3f5f"
2174 | },
2175 | "marker": {
2176 | "line": {
2177 | "color": "#E5ECF6",
2178 | "width": 0.5
2179 | },
2180 | "pattern": {
2181 | "fillmode": "overlay",
2182 | "size": 10,
2183 | "solidity": 0.2
2184 | }
2185 | },
2186 | "type": "bar"
2187 | }
2188 | ],
2189 | "barpolar": [
2190 | {
2191 | "marker": {
2192 | "line": {
2193 | "color": "#E5ECF6",
2194 | "width": 0.5
2195 | },
2196 | "pattern": {
2197 | "fillmode": "overlay",
2198 | "size": 10,
2199 | "solidity": 0.2
2200 | }
2201 | },
2202 | "type": "barpolar"
2203 | }
2204 | ],
2205 | "carpet": [
2206 | {
2207 | "aaxis": {
2208 | "endlinecolor": "#2a3f5f",
2209 | "gridcolor": "white",
2210 | "linecolor": "white",
2211 | "minorgridcolor": "white",
2212 | "startlinecolor": "#2a3f5f"
2213 | },
2214 | "baxis": {
2215 | "endlinecolor": "#2a3f5f",
2216 | "gridcolor": "white",
2217 | "linecolor": "white",
2218 | "minorgridcolor": "white",
2219 | "startlinecolor": "#2a3f5f"
2220 | },
2221 | "type": "carpet"
2222 | }
2223 | ],
2224 | "choropleth": [
2225 | {
2226 | "colorbar": {
2227 | "outlinewidth": 0,
2228 | "ticks": ""
2229 | },
2230 | "type": "choropleth"
2231 | }
2232 | ],
2233 | "contour": [
2234 | {
2235 | "colorbar": {
2236 | "outlinewidth": 0,
2237 | "ticks": ""
2238 | },
2239 | "colorscale": [
2240 | [
2241 | 0,
2242 | "#0d0887"
2243 | ],
2244 | [
2245 | 0.1111111111111111,
2246 | "#46039f"
2247 | ],
2248 | [
2249 | 0.2222222222222222,
2250 | "#7201a8"
2251 | ],
2252 | [
2253 | 0.3333333333333333,
2254 | "#9c179e"
2255 | ],
2256 | [
2257 | 0.4444444444444444,
2258 | "#bd3786"
2259 | ],
2260 | [
2261 | 0.5555555555555556,
2262 | "#d8576b"
2263 | ],
2264 | [
2265 | 0.6666666666666666,
2266 | "#ed7953"
2267 | ],
2268 | [
2269 | 0.7777777777777778,
2270 | "#fb9f3a"
2271 | ],
2272 | [
2273 | 0.8888888888888888,
2274 | "#fdca26"
2275 | ],
2276 | [
2277 | 1,
2278 | "#f0f921"
2279 | ]
2280 | ],
2281 | "type": "contour"
2282 | }
2283 | ],
2284 | "contourcarpet": [
2285 | {
2286 | "colorbar": {
2287 | "outlinewidth": 0,
2288 | "ticks": ""
2289 | },
2290 | "type": "contourcarpet"
2291 | }
2292 | ],
2293 | "heatmap": [
2294 | {
2295 | "colorbar": {
2296 | "outlinewidth": 0,
2297 | "ticks": ""
2298 | },
2299 | "colorscale": [
2300 | [
2301 | 0,
2302 | "#0d0887"
2303 | ],
2304 | [
2305 | 0.1111111111111111,
2306 | "#46039f"
2307 | ],
2308 | [
2309 | 0.2222222222222222,
2310 | "#7201a8"
2311 | ],
2312 | [
2313 | 0.3333333333333333,
2314 | "#9c179e"
2315 | ],
2316 | [
2317 | 0.4444444444444444,
2318 | "#bd3786"
2319 | ],
2320 | [
2321 | 0.5555555555555556,
2322 | "#d8576b"
2323 | ],
2324 | [
2325 | 0.6666666666666666,
2326 | "#ed7953"
2327 | ],
2328 | [
2329 | 0.7777777777777778,
2330 | "#fb9f3a"
2331 | ],
2332 | [
2333 | 0.8888888888888888,
2334 | "#fdca26"
2335 | ],
2336 | [
2337 | 1,
2338 | "#f0f921"
2339 | ]
2340 | ],
2341 | "type": "heatmap"
2342 | }
2343 | ],
2344 | "heatmapgl": [
2345 | {
2346 | "colorbar": {
2347 | "outlinewidth": 0,
2348 | "ticks": ""
2349 | },
2350 | "colorscale": [
2351 | [
2352 | 0,
2353 | "#0d0887"
2354 | ],
2355 | [
2356 | 0.1111111111111111,
2357 | "#46039f"
2358 | ],
2359 | [
2360 | 0.2222222222222222,
2361 | "#7201a8"
2362 | ],
2363 | [
2364 | 0.3333333333333333,
2365 | "#9c179e"
2366 | ],
2367 | [
2368 | 0.4444444444444444,
2369 | "#bd3786"
2370 | ],
2371 | [
2372 | 0.5555555555555556,
2373 | "#d8576b"
2374 | ],
2375 | [
2376 | 0.6666666666666666,
2377 | "#ed7953"
2378 | ],
2379 | [
2380 | 0.7777777777777778,
2381 | "#fb9f3a"
2382 | ],
2383 | [
2384 | 0.8888888888888888,
2385 | "#fdca26"
2386 | ],
2387 | [
2388 | 1,
2389 | "#f0f921"
2390 | ]
2391 | ],
2392 | "type": "heatmapgl"
2393 | }
2394 | ],
2395 | "histogram": [
2396 | {
2397 | "marker": {
2398 | "pattern": {
2399 | "fillmode": "overlay",
2400 | "size": 10,
2401 | "solidity": 0.2
2402 | }
2403 | },
2404 | "type": "histogram"
2405 | }
2406 | ],
2407 | "histogram2d": [
2408 | {
2409 | "colorbar": {
2410 | "outlinewidth": 0,
2411 | "ticks": ""
2412 | },
2413 | "colorscale": [
2414 | [
2415 | 0,
2416 | "#0d0887"
2417 | ],
2418 | [
2419 | 0.1111111111111111,
2420 | "#46039f"
2421 | ],
2422 | [
2423 | 0.2222222222222222,
2424 | "#7201a8"
2425 | ],
2426 | [
2427 | 0.3333333333333333,
2428 | "#9c179e"
2429 | ],
2430 | [
2431 | 0.4444444444444444,
2432 | "#bd3786"
2433 | ],
2434 | [
2435 | 0.5555555555555556,
2436 | "#d8576b"
2437 | ],
2438 | [
2439 | 0.6666666666666666,
2440 | "#ed7953"
2441 | ],
2442 | [
2443 | 0.7777777777777778,
2444 | "#fb9f3a"
2445 | ],
2446 | [
2447 | 0.8888888888888888,
2448 | "#fdca26"
2449 | ],
2450 | [
2451 | 1,
2452 | "#f0f921"
2453 | ]
2454 | ],
2455 | "type": "histogram2d"
2456 | }
2457 | ],
2458 | "histogram2dcontour": [
2459 | {
2460 | "colorbar": {
2461 | "outlinewidth": 0,
2462 | "ticks": ""
2463 | },
2464 | "colorscale": [
2465 | [
2466 | 0,
2467 | "#0d0887"
2468 | ],
2469 | [
2470 | 0.1111111111111111,
2471 | "#46039f"
2472 | ],
2473 | [
2474 | 0.2222222222222222,
2475 | "#7201a8"
2476 | ],
2477 | [
2478 | 0.3333333333333333,
2479 | "#9c179e"
2480 | ],
2481 | [
2482 | 0.4444444444444444,
2483 | "#bd3786"
2484 | ],
2485 | [
2486 | 0.5555555555555556,
2487 | "#d8576b"
2488 | ],
2489 | [
2490 | 0.6666666666666666,
2491 | "#ed7953"
2492 | ],
2493 | [
2494 | 0.7777777777777778,
2495 | "#fb9f3a"
2496 | ],
2497 | [
2498 | 0.8888888888888888,
2499 | "#fdca26"
2500 | ],
2501 | [
2502 | 1,
2503 | "#f0f921"
2504 | ]
2505 | ],
2506 | "type": "histogram2dcontour"
2507 | }
2508 | ],
2509 | "mesh3d": [
2510 | {
2511 | "colorbar": {
2512 | "outlinewidth": 0,
2513 | "ticks": ""
2514 | },
2515 | "type": "mesh3d"
2516 | }
2517 | ],
2518 | "parcoords": [
2519 | {
2520 | "line": {
2521 | "colorbar": {
2522 | "outlinewidth": 0,
2523 | "ticks": ""
2524 | }
2525 | },
2526 | "type": "parcoords"
2527 | }
2528 | ],
2529 | "pie": [
2530 | {
2531 | "automargin": true,
2532 | "type": "pie"
2533 | }
2534 | ],
2535 | "scatter": [
2536 | {
2537 | "fillpattern": {
2538 | "fillmode": "overlay",
2539 | "size": 10,
2540 | "solidity": 0.2
2541 | },
2542 | "type": "scatter"
2543 | }
2544 | ],
2545 | "scatter3d": [
2546 | {
2547 | "line": {
2548 | "colorbar": {
2549 | "outlinewidth": 0,
2550 | "ticks": ""
2551 | }
2552 | },
2553 | "marker": {
2554 | "colorbar": {
2555 | "outlinewidth": 0,
2556 | "ticks": ""
2557 | }
2558 | },
2559 | "type": "scatter3d"
2560 | }
2561 | ],
2562 | "scattercarpet": [
2563 | {
2564 | "marker": {
2565 | "colorbar": {
2566 | "outlinewidth": 0,
2567 | "ticks": ""
2568 | }
2569 | },
2570 | "type": "scattercarpet"
2571 | }
2572 | ],
2573 | "scattergeo": [
2574 | {
2575 | "marker": {
2576 | "colorbar": {
2577 | "outlinewidth": 0,
2578 | "ticks": ""
2579 | }
2580 | },
2581 | "type": "scattergeo"
2582 | }
2583 | ],
2584 | "scattergl": [
2585 | {
2586 | "marker": {
2587 | "colorbar": {
2588 | "outlinewidth": 0,
2589 | "ticks": ""
2590 | }
2591 | },
2592 | "type": "scattergl"
2593 | }
2594 | ],
2595 | "scattermapbox": [
2596 | {
2597 | "marker": {
2598 | "colorbar": {
2599 | "outlinewidth": 0,
2600 | "ticks": ""
2601 | }
2602 | },
2603 | "type": "scattermapbox"
2604 | }
2605 | ],
2606 | "scatterpolar": [
2607 | {
2608 | "marker": {
2609 | "colorbar": {
2610 | "outlinewidth": 0,
2611 | "ticks": ""
2612 | }
2613 | },
2614 | "type": "scatterpolar"
2615 | }
2616 | ],
2617 | "scatterpolargl": [
2618 | {
2619 | "marker": {
2620 | "colorbar": {
2621 | "outlinewidth": 0,
2622 | "ticks": ""
2623 | }
2624 | },
2625 | "type": "scatterpolargl"
2626 | }
2627 | ],
2628 | "scatterternary": [
2629 | {
2630 | "marker": {
2631 | "colorbar": {
2632 | "outlinewidth": 0,
2633 | "ticks": ""
2634 | }
2635 | },
2636 | "type": "scatterternary"
2637 | }
2638 | ],
2639 | "surface": [
2640 | {
2641 | "colorbar": {
2642 | "outlinewidth": 0,
2643 | "ticks": ""
2644 | },
2645 | "colorscale": [
2646 | [
2647 | 0,
2648 | "#0d0887"
2649 | ],
2650 | [
2651 | 0.1111111111111111,
2652 | "#46039f"
2653 | ],
2654 | [
2655 | 0.2222222222222222,
2656 | "#7201a8"
2657 | ],
2658 | [
2659 | 0.3333333333333333,
2660 | "#9c179e"
2661 | ],
2662 | [
2663 | 0.4444444444444444,
2664 | "#bd3786"
2665 | ],
2666 | [
2667 | 0.5555555555555556,
2668 | "#d8576b"
2669 | ],
2670 | [
2671 | 0.6666666666666666,
2672 | "#ed7953"
2673 | ],
2674 | [
2675 | 0.7777777777777778,
2676 | "#fb9f3a"
2677 | ],
2678 | [
2679 | 0.8888888888888888,
2680 | "#fdca26"
2681 | ],
2682 | [
2683 | 1,
2684 | "#f0f921"
2685 | ]
2686 | ],
2687 | "type": "surface"
2688 | }
2689 | ],
2690 | "table": [
2691 | {
2692 | "cells": {
2693 | "fill": {
2694 | "color": "#EBF0F8"
2695 | },
2696 | "line": {
2697 | "color": "white"
2698 | }
2699 | },
2700 | "header": {
2701 | "fill": {
2702 | "color": "#C8D4E3"
2703 | },
2704 | "line": {
2705 | "color": "white"
2706 | }
2707 | },
2708 | "type": "table"
2709 | }
2710 | ]
2711 | },
2712 | "layout": {
2713 | "annotationdefaults": {
2714 | "arrowcolor": "#2a3f5f",
2715 | "arrowhead": 0,
2716 | "arrowwidth": 1
2717 | },
2718 | "autotypenumbers": "strict",
2719 | "coloraxis": {
2720 | "colorbar": {
2721 | "outlinewidth": 0,
2722 | "ticks": ""
2723 | }
2724 | },
2725 | "colorscale": {
2726 | "diverging": [
2727 | [
2728 | 0,
2729 | "#8e0152"
2730 | ],
2731 | [
2732 | 0.1,
2733 | "#c51b7d"
2734 | ],
2735 | [
2736 | 0.2,
2737 | "#de77ae"
2738 | ],
2739 | [
2740 | 0.3,
2741 | "#f1b6da"
2742 | ],
2743 | [
2744 | 0.4,
2745 | "#fde0ef"
2746 | ],
2747 | [
2748 | 0.5,
2749 | "#f7f7f7"
2750 | ],
2751 | [
2752 | 0.6,
2753 | "#e6f5d0"
2754 | ],
2755 | [
2756 | 0.7,
2757 | "#b8e186"
2758 | ],
2759 | [
2760 | 0.8,
2761 | "#7fbc41"
2762 | ],
2763 | [
2764 | 0.9,
2765 | "#4d9221"
2766 | ],
2767 | [
2768 | 1,
2769 | "#276419"
2770 | ]
2771 | ],
2772 | "sequential": [
2773 | [
2774 | 0,
2775 | "#0d0887"
2776 | ],
2777 | [
2778 | 0.1111111111111111,
2779 | "#46039f"
2780 | ],
2781 | [
2782 | 0.2222222222222222,
2783 | "#7201a8"
2784 | ],
2785 | [
2786 | 0.3333333333333333,
2787 | "#9c179e"
2788 | ],
2789 | [
2790 | 0.4444444444444444,
2791 | "#bd3786"
2792 | ],
2793 | [
2794 | 0.5555555555555556,
2795 | "#d8576b"
2796 | ],
2797 | [
2798 | 0.6666666666666666,
2799 | "#ed7953"
2800 | ],
2801 | [
2802 | 0.7777777777777778,
2803 | "#fb9f3a"
2804 | ],
2805 | [
2806 | 0.8888888888888888,
2807 | "#fdca26"
2808 | ],
2809 | [
2810 | 1,
2811 | "#f0f921"
2812 | ]
2813 | ],
2814 | "sequentialminus": [
2815 | [
2816 | 0,
2817 | "#0d0887"
2818 | ],
2819 | [
2820 | 0.1111111111111111,
2821 | "#46039f"
2822 | ],
2823 | [
2824 | 0.2222222222222222,
2825 | "#7201a8"
2826 | ],
2827 | [
2828 | 0.3333333333333333,
2829 | "#9c179e"
2830 | ],
2831 | [
2832 | 0.4444444444444444,
2833 | "#bd3786"
2834 | ],
2835 | [
2836 | 0.5555555555555556,
2837 | "#d8576b"
2838 | ],
2839 | [
2840 | 0.6666666666666666,
2841 | "#ed7953"
2842 | ],
2843 | [
2844 | 0.7777777777777778,
2845 | "#fb9f3a"
2846 | ],
2847 | [
2848 | 0.8888888888888888,
2849 | "#fdca26"
2850 | ],
2851 | [
2852 | 1,
2853 | "#f0f921"
2854 | ]
2855 | ]
2856 | },
2857 | "colorway": [
2858 | "#636efa",
2859 | "#EF553B",
2860 | "#00cc96",
2861 | "#ab63fa",
2862 | "#FFA15A",
2863 | "#19d3f3",
2864 | "#FF6692",
2865 | "#B6E880",
2866 | "#FF97FF",
2867 | "#FECB52"
2868 | ],
2869 | "font": {
2870 | "color": "#2a3f5f"
2871 | },
2872 | "geo": {
2873 | "bgcolor": "white",
2874 | "lakecolor": "white",
2875 | "landcolor": "#E5ECF6",
2876 | "showlakes": true,
2877 | "showland": true,
2878 | "subunitcolor": "white"
2879 | },
2880 | "hoverlabel": {
2881 | "align": "left"
2882 | },
2883 | "hovermode": "closest",
2884 | "mapbox": {
2885 | "style": "light"
2886 | },
2887 | "paper_bgcolor": "white",
2888 | "plot_bgcolor": "#E5ECF6",
2889 | "polar": {
2890 | "angularaxis": {
2891 | "gridcolor": "white",
2892 | "linecolor": "white",
2893 | "ticks": ""
2894 | },
2895 | "bgcolor": "#E5ECF6",
2896 | "radialaxis": {
2897 | "gridcolor": "white",
2898 | "linecolor": "white",
2899 | "ticks": ""
2900 | }
2901 | },
2902 | "scene": {
2903 | "xaxis": {
2904 | "backgroundcolor": "#E5ECF6",
2905 | "gridcolor": "white",
2906 | "gridwidth": 2,
2907 | "linecolor": "white",
2908 | "showbackground": true,
2909 | "ticks": "",
2910 | "zerolinecolor": "white"
2911 | },
2912 | "yaxis": {
2913 | "backgroundcolor": "#E5ECF6",
2914 | "gridcolor": "white",
2915 | "gridwidth": 2,
2916 | "linecolor": "white",
2917 | "showbackground": true,
2918 | "ticks": "",
2919 | "zerolinecolor": "white"
2920 | },
2921 | "zaxis": {
2922 | "backgroundcolor": "#E5ECF6",
2923 | "gridcolor": "white",
2924 | "gridwidth": 2,
2925 | "linecolor": "white",
2926 | "showbackground": true,
2927 | "ticks": "",
2928 | "zerolinecolor": "white"
2929 | }
2930 | },
2931 | "shapedefaults": {
2932 | "line": {
2933 | "color": "#2a3f5f"
2934 | }
2935 | },
2936 | "ternary": {
2937 | "aaxis": {
2938 | "gridcolor": "white",
2939 | "linecolor": "white",
2940 | "ticks": ""
2941 | },
2942 | "baxis": {
2943 | "gridcolor": "white",
2944 | "linecolor": "white",
2945 | "ticks": ""
2946 | },
2947 | "bgcolor": "#E5ECF6",
2948 | "caxis": {
2949 | "gridcolor": "white",
2950 | "linecolor": "white",
2951 | "ticks": ""
2952 | }
2953 | },
2954 | "title": {
2955 | "x": 0.05
2956 | },
2957 | "xaxis": {
2958 | "automargin": true,
2959 | "gridcolor": "white",
2960 | "linecolor": "white",
2961 | "ticks": "",
2962 | "title": {
2963 | "standoff": 15
2964 | },
2965 | "zerolinecolor": "white",
2966 | "zerolinewidth": 2
2967 | },
2968 | "yaxis": {
2969 | "automargin": true,
2970 | "gridcolor": "white",
2971 | "linecolor": "white",
2972 | "ticks": "",
2973 | "title": {
2974 | "standoff": 15
2975 | },
2976 | "zerolinecolor": "white",
2977 | "zerolinewidth": 2
2978 | }
2979 | }
2980 | },
2981 | "xaxis": {
2982 | "anchor": "y",
2983 | "domain": [
2984 | 0,
2985 | 1
2986 | ],
2987 | "title": {
2988 | "text": "amino acid"
2989 | }
2990 | },
2991 | "yaxis": {
2992 | "anchor": "x",
2993 | "domain": [
2994 | 0,
2995 | 1
2996 | ],
2997 | "title": {
2998 | "text": "mean"
2999 | }
3000 | }
3001 | }
3002 | }
3003 | },
3004 | "metadata": {},
3005 | "output_type": "display_data"
3006 | }
3007 | ],
3008 | "source": [
3009 | "fig = px.bar(test_df.sort_values('mean'), x='amino acid', y='mean', color='mean')\n",
3010 | "fig.show()"
3011 | ]
3012 | },
3013 | {
3014 | "cell_type": "markdown",
3015 | "id": "504bc7e9-d8a2-4edf-83a0-58b94c0eddda",
3016 | "metadata": {
3017 | "id": "7d29b4ed"
3018 | },
3019 | "source": [
3020 | "## Tokenisation"
3021 | ]
3022 | },
3023 | {
3024 | "cell_type": "markdown",
3025 | "id": "ad4ea3fe-1a7d-41f6-b214-4ef3a3c1fea5",
3026 | "metadata": {
3027 | "id": "c02baaf7"
3028 | },
3029 | "source": [
3030 | "All inputs to neural nets must be numerical. The process of converting strings into numerical indices suitable for a neural net is called **tokenization**. For natural language this can be quite complex, as usually the network's vocabulary will not contain every possible word, which means the tokenizer must handle splitting rarer words into pieces, as well as all the complexities of capitalization and unicode characters and so on.\n",
3031 | "\n",
3032 | "With proteins, however, things are very easy. In protein language models, each amino acid is converted to a single token. Every model on `transformers` comes with an associated `tokenizer` that handles tokenization for it, and protein language models are no different. Let's get our tokenizer!"
3033 | ]
3034 | },
3035 | {
3036 | "cell_type": "code",
3037 | "execution_count": 22,
3038 | "id": "245c56d6-f03b-4306-80f5-0678b051a822",
3039 | "metadata": {
3040 | "colab": {
3041 | "base_uri": "https://localhost:8080/",
3042 | "height": 113,
3043 | "referenced_widgets": [
3044 | "48ea66931f1e4eec9c02d44766897106",
3045 | "799fbc24f6d745a89716caaf7e2db87a",
3046 | "62f8ae11792145bea1b1d7afd1497415",
3047 | "e151623066004c969cb6258f70adcde9",
3048 | "994d3df7154e403fb1e29185bb73d714",
3049 | "b6cf9d5576c14031a9fc901bf1c83284",
3050 | "0d4c7cec0152401e9faa3145bef7cbb0",
3051 | "69d9d37fdee24c7cacac2c4a88df0273",
3052 | "8ecac32695454023a98d889893340a4d",
3053 | "008851fc6aec47e6b9294343f281d4ef",
3054 | "881d61da2cc64f0aba9cd11d99d18044",
3055 | "f6e1a4cbf15249628dae2f4c2a51f8cf",
3056 | "d74c66158e8343988e937573a5254c4c",
3057 | "db52d20520bf44798ce76323e4324b80",
3058 | "ef065a30ea9246dfb9b7e4ac96b58ca9",
3059 | "591e3f5003b2422e8aa55ab750226195",
3060 | "7b51332c344a4d73a13327d0448f499f",
3061 | "ef8c06dbfc70495d9d38ffbbf83aeb8d",
3062 | "df6b40fa9fb84c788b860bd3a8ec814e",
3063 | "ea16a9e174e74dcb98b9a5b5229725b5",
3064 | "4a15581db7dd4f8cbf1bd92493ff9587",
3065 | "6e5a3b7598cb466fb327ff99f8c2331c",
3066 | "1769f6420fb845c9935c0cecc4f14189",
3067 | "04b87e010c234a518bf102462b65c758",
3068 | "6d486f76da1e422e83943af3143bc567",
3069 | "fc4e48d289104bfea7348a3e8f74bf13",
3070 | "c41e121a002b4235b6f9dc35ea0bd5f0",
3071 | "64e999c2e40041f7beb5baf4c3a8fefb",
3072 | "5f5a22e1a2c043bf9cb02816628c1f49",
3073 | "3aa54d54e9da433c91b35983e50795ab",
3074 | "635d2a69bb9648e68fc161d2927da091",
3075 | "ddbb89e848a343f29b28d38ea7aa0e39",
3076 | "68fd265ae06542299ea9a1ec664537b5"
3077 | ]
3078 | },
3079 | "id": "ddbe2b2d",
3080 | "outputId": "41950c4a-22fc-4018-838c-fbbcbc421482"
3081 | },
3082 | "outputs": [],
3083 | "source": [
3084 | "from transformers import AutoTokenizer\n",
3085 | "tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)"
3086 | ]
3087 | },
3088 | {
3089 | "cell_type": "markdown",
3090 | "id": "776e3399-4c54-48c7-ad0e-71ee5fb57e9c",
3091 | "metadata": {
3092 | "id": "9d16be37"
3093 | },
3094 | "source": [
3095 | "Let's try a single sequence to see what the outputs from our tokenizer look like:"
3096 | ]
3097 | },
3098 | {
3099 | "cell_type": "code",
3100 | "execution_count": 23,
3101 | "id": "dc349a74-8b06-40a5-9889-65b144ef763d",
3102 | "metadata": {
3103 | "colab": {
3104 | "base_uri": "https://localhost:8080/"
3105 | },
3106 | "id": "687386af",
3107 | "outputId": "a55bc023-b94b-4ef3-fb34-cac712bdf9cf"
3108 | },
3109 | "outputs": [
3110 | {
3111 | "data": {
3112 | "text/plain": [
3113 | "{'input_ids': [0, 20, 11, 16, 10, 5, 6, 5, 5, 20, 4, 14, 8, 5, 4, 4, 4, 4, 23, 7, 14, 6, 23, 4, 11, 7, 8, 6, 14, 8, 11, 7, 20, 6, 5, 7, 6, 9, 8, 4, 8, 7, 16, 23, 10, 19, 9, 9, 15, 19, 15, 11, 18, 17, 15, 19, 22, 23, 10, 16, 14, 23, 4, 14, 12, 22, 21, 9, 20, 7, 9, 11, 6, 6, 8, 9, 6, 7, 7, 10, 8, 13, 16, 7, 12, 12, 11, 13, 21, 14, 6, 13, 4, 11, 18, 11, 7, 11, 4, 9, 17, 4, 11, 5, 13, 13, 5, 6, 15, 19, 10, 23, 6, 12, 5, 11, 12, 4, 16, 9, 13, 6, 4, 8, 6, 18, 4, 14, 13, 14, 18, 18, 16, 7, 16, 7, 4, 7, 8, 8, 5, 8, 8, 11, 9, 17, 8, 7, 15, 11, 14, 5, 8, 14, 11, 10, 14, 8, 16, 23, 16, 6, 8, 4, 14, 8, 8, 11, 23, 18, 4, 4, 4, 14, 4, 4, 15, 7, 14, 4, 4, 4, 8, 12, 4, 6, 5, 12, 4, 22, 7, 17, 10, 14, 22, 10, 11, 14, 22, 11, 9, 8, 2], 'attention_mask': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}"
3114 | ]
3115 | },
3116 | "execution_count": 23,
3117 | "metadata": {},
3118 | "output_type": "execute_result"
3119 | }
3120 | ],
3121 | "source": [
3122 | "tokenizer(train_sequences.to_list()[0])"
3123 | ]
3124 | },
3125 | {
3126 | "cell_type": "markdown",
3127 | "id": "00830f7d-ddc6-4fcb-a7b9-d4193c3d2f6d",
3128 | "metadata": {
3129 | "id": "9a719808"
3130 | },
3131 | "source": [
3132 | "This looks good! We can see that our sequence has been converted into `input_ids`, which is the tokenized sequence, and an `attention_mask`. The attention mask handles the case when we have sequences of variable length - in those cases, the shorter sequences are padded with blank \"padding\" tokens, and the attention mask is padded with 0s to indicate that those tokens should be ignored by the model.\n",
3133 | "\n",
3134 | "So now, let's tokenize our whole dataset. Note that we don't need to do anything with the labels, as they're already in the format we need."
3135 | ]
3136 | },
3137 | {
3138 | "cell_type": "code",
3139 | "execution_count": 24,
3140 | "id": "3781e8d3-8f07-469e-a651-147a02f1cba8",
3141 | "metadata": {
3142 | "id": "56e26ddf"
3143 | },
3144 | "outputs": [],
3145 | "source": [
3146 | "# tokenize train and test sequences, which need to be list of str\n",
3147 | "train_tokenized = tokenizer(train_sequences.tolist())\n",
3148 | "test_tokenized = tokenizer(test_sequences.tolist())"
3149 | ]
3150 | },
3151 | {
3152 | "cell_type": "markdown",
3153 | "id": "d8646c13-b638-4b49-928c-23a1caa4e5a1",
3154 | "metadata": {
3155 | "id": "df3681d1"
3156 | },
3157 | "source": [
3158 | "## Training Dataset creation"
3159 | ]
3160 | },
3161 | {
3162 | "cell_type": "markdown",
3163 | "id": "2ec84852-18b3-43db-a953-397997cf7d7b",
3164 | "metadata": {
3165 | "id": "85089e49"
3166 | },
3167 | "source": [
3168 | "Now we want to turn this data into a dataset that PyTorch can load samples from. We can use the HuggingFace `Dataset` class for this, although if you prefer you can also use `torch.utils.data.Dataset`, at the cost of some more boilerplate code ([Datasets](https://pytorch.org/tutorials/beginner/basics/data_tutorial.html))."
3169 | ]
3170 | },
3171 | {
3172 | "cell_type": "code",
3173 | "execution_count": 25,
3174 | "id": "c6b1fde6-00c6-4930-b2d4-2b21038dc725",
3175 | "metadata": {
3176 | "colab": {
3177 | "base_uri": "https://localhost:8080/"
3178 | },
3179 | "id": "fb79ba6c",
3180 | "outputId": "5c355205-9071-4994-bd63-af320efc97bb"
3181 | },
3182 | "outputs": [
3183 | {
3184 | "data": {
3185 | "text/plain": [
3186 | "Dataset({\n",
3187 | " features: ['input_ids', 'attention_mask'],\n",
3188 | " num_rows: 4136\n",
3189 | "})"
3190 | ]
3191 | },
3192 | "execution_count": 25,
3193 | "metadata": {},
3194 | "output_type": "execute_result"
3195 | }
3196 | ],
3197 | "source": [
3198 | "from datasets import Dataset\n",
3199 | "\n",
3200 | "train_dataset = Dataset.from_dict(train_tokenized)\n",
3201 | "test_dataset = Dataset.from_dict(test_tokenized)\n",
3202 | "\n",
3203 | "# check\n",
3204 | "train_dataset"
3205 | ]
3206 | },
3207 | {
3208 | "cell_type": "markdown",
3209 | "id": "b8e2a6c0-efbf-4b9f-ac11-2bafc6777ff5",
3210 | "metadata": {
3211 | "id": "9e809e47"
3212 | },
3213 | "source": [
3214 | "This looks good, but we're missing our labels! Let's add those on as an extra column to the datasets."
3215 | ]
3216 | },
3217 | {
3218 | "cell_type": "code",
3219 | "execution_count": 26,
3220 | "id": "3697fdbb-e43b-4d48-b481-4e3e90ee97f4",
3221 | "metadata": {
3222 | "colab": {
3223 | "base_uri": "https://localhost:8080/"
3224 | },
3225 | "id": "090acc0d",
3226 | "outputId": "a14a5583-d946-47f1-d0a6-b31514d7325e"
3227 | },
3228 | "outputs": [
3229 | {
3230 | "data": {
3231 | "text/plain": [
3232 | "Dataset({\n",
3233 | " features: ['input_ids', 'attention_mask', 'labels'],\n",
3234 | " num_rows: 4136\n",
3235 | "})"
3236 | ]
3237 | },
3238 | "execution_count": 26,
3239 | "metadata": {},
3240 | "output_type": "execute_result"
3241 | }
3242 | ],
3243 | "source": [
3244 | "train_dataset = train_dataset.add_column(\"labels\", train_labels)\n",
3245 | "test_dataset = test_dataset.add_column(\"labels\", test_labels)\n",
3246 | "\n",
3247 | "# check\n",
3248 | "train_dataset"
3249 | ]
3250 | },
3251 | {
3252 | "cell_type": "markdown",
3253 | "id": "e6d38664-d28d-4e70-97c7-e055fe4ed90f",
3254 | "metadata": {},
3255 | "source": [
3256 | "We will split the training set further to use a subset of the data to evaluate the model during fine-tuning (i.e., validation dataset)."
3257 | ]
3258 | },
3259 | {
3260 | "cell_type": "code",
3261 | "execution_count": 27,
3262 | "id": "841ffd19-2bef-436e-8b26-f5a75ff6ec36",
3263 | "metadata": {},
3264 | "outputs": [
3265 | {
3266 | "data": {
3267 | "text/plain": [
3268 | "DatasetDict({\n",
3269 | " train: Dataset({\n",
3270 | " features: ['input_ids', 'attention_mask', 'labels'],\n",
3271 | " num_rows: 3308\n",
3272 | " })\n",
3273 | " test: Dataset({\n",
3274 | " features: ['input_ids', 'attention_mask', 'labels'],\n",
3275 | " num_rows: 828\n",
3276 | " })\n",
3277 | "})"
3278 | ]
3279 | },
3280 | "execution_count": 27,
3281 | "metadata": {},
3282 | "output_type": "execute_result"
3283 | }
3284 | ],
3285 | "source": [
3286 | "train_val_dataset = train_dataset.train_test_split(test_size=0.2)\n",
3287 | "\n",
3288 | "# check\n",
3289 | "train_val_dataset"
3290 | ]
3291 | },
3292 | {
3293 | "cell_type": "markdown",
3294 | "id": "815741ed-b125-4661-825f-6f126272fdde",
3295 | "metadata": {
3296 | "id": "ced9aaa8"
3297 | },
3298 | "source": [
3299 | "Looks good! We're ready for training."
3300 | ]
3301 | },
3302 | {
3303 | "cell_type": "markdown",
3304 | "id": "dda2901c-0d02-473e-baa6-d3bdcaa9dd42",
3305 | "metadata": {
3306 | "id": "af074a5c"
3307 | },
3308 | "source": [
3309 | "## Model loading"
3310 | ]
3311 | },
3312 | {
3313 | "cell_type": "markdown",
3314 | "id": "e2bd5289-8d5a-4977-b49e-d8deeb072795",
3315 | "metadata": {
3316 | "id": "ccab5d70"
3317 | },
3318 | "source": [
3319 | "Next, we want to load our model. Make sure to use exactly the same model as you used when loading the tokenizer, or your model might not understand the tokenization scheme you're using!"
3320 | ]
3321 | },
3322 | {
3323 | "cell_type": "code",
3324 | "execution_count": 28,
3325 | "id": "8cf7b3c8-a150-4552-8e2e-8913563ad214",
3326 | "metadata": {
3327 | "colab": {
3328 | "base_uri": "https://localhost:8080/",
3329 | "height": 570,
3330 | "referenced_widgets": [
3331 | "cd93caa975e74791aba3ede7889c058c",
3332 | "8f7654f0423b48668a983802e6a6aa44",
3333 | "8b9f0a93dcfa4ce08f831355bc82c861",
3334 | "4385c61c3462447c9f6d5a53298fb237",
3335 | "55213ae044de4d9582bcae84c8da9ef6",
3336 | "7908d984799d4d65a398c03346e26729",
3337 | "03618d81301b47ba83336698ffa9c2b7",
3338 | "b003ddf9b40946d690681825979f8205",
3339 | "56e04648858b4965ad94e32c3b26a2f6",
3340 | "cae4138fb556439a994edefcce4e6bd3",
3341 | "e0a77469998a47bd9f39a28403c5ec6c",
3342 | "901a5c1ebca34d899b203035d23c0f46",
3343 | "ce7b83f8fa9649d7b11cce43001198bb",
3344 | "8ede690fe0874410b347a48c276915e7",
3345 | "91c00e196504498a9e5c2d4391b4c0f7",
3346 | "f177f5bd5dfa4765b6eb6bd8ae091348",
3347 | "ec71fad4a3cd4815aff289e25ef70de2",
3348 | "9949f236e90b45c2ba921ce479e54920",
3349 | "b0d02c8c223346b5bf9ab6c7569b9eff",
3350 | "20764cdac47445c09985f2204024d7f6",
3351 | "71f7ff0a7df84d0898dbf14ac3808165",
3352 | "406d2f83ccad49ec9cb114f78d8514a9",
3353 | "8a5fbf0a1e6042f3b1d3900a1d854c2a",
3354 | "8e94130dc4a64b56a156d1bff4c90131",
3355 | "e6c6841a50474f7daef5b1ec9a0f1b79",
3356 | "37329fa50e0a4f3fbb2f863fc9150a40",
3357 | "039c8434f6564960a846b49998e6dc98",
3358 | "8697aee2b4fe469eb8b2acf4c93934cc",
3359 | "ecdf7a23e3be42b1a98d6206221a005d",
3360 | "641ba6628d1c43138343987f6a102a7c",
3361 | "8e3718c5e1e846bca36cacc19f481d7b",
3362 | "30fedea993de40e5962816ded086afa7",
3363 | "a2b96cc7bf62480f8c08e49a79c54e91",
3364 | "d906e65029ec46cca5d4c8736c790535",
3365 | "6360234a90c44caa8d9bbf7b6833fc9f",
3366 | "57893132e5be4b2baca0db3dadd46999",
3367 | "eafbb78481fb41f8a9792eb5e8a00043",
3368 | "fd88fadcbd9e449f9ba6938013d58f7c",
3369 | "290af5dfc2b3470b94e07a96d982c6b1",
3370 | "0384b6458894415a95142dd26902e47f",
3371 | "4434eef7462e44b8a77ebfa30b15de19",
3372 | "262dfa94f2404e3caf3c3bb81215eedf",
3373 | "9a5a74ef3a294b2cbaeb3a2968bffef9",
3374 | "c0b5bfdf1f6247dfb4e967c750fdd16d",
3375 | "ee83891aacff4186a2e5b1c015d5aa48",
3376 | "b9da13013ccb471fb46066fd37216ec1",
3377 | "cb854268a04c4857b8f641575150257a",
3378 | "f066f129604e47bb975acd5f2fb380f9",
3379 | "46a7dc72b34c4a80b4df01d7e2130412",
3380 | "0b3b862d04c14d61af5b08ad2c00895b",
3381 | "affc17d525b245a9a7df95f3ed5ecce5",
3382 | "16f52a411b3c4f10b986d85de862e34b",
3383 | "3f8103fe9c5e49449c0e39f4f1603f02",
3384 | "fb46882705784e1fb516ce156fa8f86e",
3385 | "0c0c429e800041bfa1530080d7b26400",
3386 | "f8bf3aebff25499fae5de8d82704fb6f",
3387 | "9ea7802e962e4647acf36aa0a42a86d2",
3388 | "28b1f101ef3749819f86b69349ce6c24",
3389 | "dcf594b86fce4062b0e624e6b7d996aa",
3390 | "7cb1942781ba4a6e9619d2cfca17dd5b",
3391 | "d6ba55fbcc20433a84a79478acd4f1ff",
3392 | "2d4f570d845540f8bbcce3a40d0026a7",
3393 | "ef7cbb1b37f84c208897c447ed6612da",
3394 | "559694d417154050b2712a6441e56f7d",
3395 | "758e1a01f3bd4c79a6833560c22e03f9",
3396 | "dfe14fbaae0e484f9bec2dd4bcb414ca",
3397 | "e4ca5fcd11964869901ed46cdfb4479a",
3398 | "82583bb78f6c446a9b374db27a1c262e",
3399 | "79c8f3195f0f4e3fb07c045cef8504de",
3400 | "7890cb3c089148bf9f63d9d45fc7b41f",
3401 | "95e819c3b93d443595704b14a6aceebc",
3402 | "7d2248b1c05644db9cc3b44e31a46cc1",
3403 | "73d0ece7c54d4e339d2d5bac0855aa58",
3404 | "89a06e969be9432d9294f9c7ff9b8675",
3405 | "6efb8d2b82c54e828de047e2c2b29efd",
3406 | "44b959e9df0b438799d99d57f6e313a6",
3407 | "4c6a54049338417e811f39d9ea54b33f"
3408 | ]
3409 | },
3410 | "id": "fc164b49",
3411 | "outputId": "032629cb-2e91-478d-fd25-c6a179b3f26b"
3412 | },
3413 | "outputs": [
3414 | {
3415 | "data": {
3416 | "application/vnd.jupyter.widget-view+json": {
3417 | "model_id": "db65f495f247487f87b1bd5c147d6073",
3418 | "version_major": 2,
3419 | "version_minor": 0
3420 | },
3421 | "text/plain": [
3422 | "config.json: 0%| | 0.00/778 [00:00, ?B/s]"
3423 | ]
3424 | },
3425 | "metadata": {},
3426 | "output_type": "display_data"
3427 | },
3428 | {
3429 | "data": {
3430 | "application/vnd.jupyter.widget-view+json": {
3431 | "model_id": "88cd72b03e8c4fa49a386b7c38ad4668",
3432 | "version_major": 2,
3433 | "version_minor": 0
3434 | },
3435 | "text/plain": [
3436 | "model.safetensors: 0%| | 0.00/136M [00:00, ?B/s]"
3437 | ]
3438 | },
3439 | "metadata": {},
3440 | "output_type": "display_data"
3441 | },
3442 | {
3443 | "name": "stderr",
3444 | "output_type": "stream",
3445 | "text": [
3446 | "Some weights of EsmForSequenceClassification were not initialized from the model checkpoint at facebook/esm2_t12_35M_UR50D and are newly initialized: ['classifier.dense.bias', 'classifier.dense.weight', 'classifier.out_proj.bias', 'classifier.out_proj.weight']\n",
3447 | "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
3448 | ]
3449 | }
3450 | ],
3451 | "source": [
3452 | "from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer\n",
3453 | "\n",
3454 | "# the number of classes \n",
3455 | "num_labels = train_labels.nunique() #2 \n",
3456 | "\n",
3457 | "# instantiate the model\n",
3458 | "model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint, num_labels=num_labels)"
3459 | ]
3460 | },
3461 | {
3462 | "cell_type": "markdown",
3463 | "id": "3d0ed91f-87ef-49f6-90b0-fea5ba491afb",
3464 | "metadata": {
3465 | "id": "49dcba23"
3466 | },
3467 | "source": [
3468 | "These warnings are telling us that the model is discarding some weights that it used for language modelling (the `lm_head`) and adding some weights for sequence classification (the `classifier`). This is exactly what we expect when we want to fine-tune a language model on a sequence classification task!\n",
3469 | "\n",
3470 | "Next, we initialize our `TrainingArguments`. These control the various training hyperparameters, and will be passed to our `Trainer`."
3471 | ]
3472 | },
3473 | {
3474 | "cell_type": "code",
3475 | "execution_count": 29,
3476 | "id": "5c8b6f44-ec76-486e-b5d7-f861d1b254e2",
3477 | "metadata": {
3478 | "id": "775cb3e7"
3479 | },
3480 | "outputs": [
3481 | {
3482 | "name": "stderr",
3483 | "output_type": "stream",
3484 | "text": [
3485 | "/Users/anglup/GitHub/course_PLM/.venv/lib/python3.11/site-packages/transformers/training_args.py:1575: FutureWarning:\n",
3486 | "\n",
3487 | "`evaluation_strategy` is deprecated and will be removed in version 4.46 of 🤗 Transformers. Use `eval_strategy` instead\n",
3488 | "\n"
3489 | ]
3490 | }
3491 | ],
3492 | "source": [
3493 | "model_name = model_checkpoint.split(\"/\")[-1]\n",
3494 | "batch_size = 8\n",
3495 | "\n",
3496 | "args = TrainingArguments(\n",
3497 | " f\"{model_name}-finetuned-localization\",\n",
3498 | " evaluation_strategy = \"epoch\", #evaluate at end of every epoch\n",
3499 | " save_strategy = \"epoch\",\n",
3500 | " learning_rate=2e-5,\n",
3501 | " per_device_train_batch_size=batch_size,\n",
3502 | " per_device_eval_batch_size=batch_size,\n",
3503 | " num_train_epochs=3,\n",
3504 | " weight_decay=0.01,\n",
3505 | " load_best_model_at_end=True,\n",
3506 | " metric_for_best_model=\"accuracy\",\n",
3507 | " push_to_hub=False,\n",
3508 | " optim=\"adamw_torch\",\n",
3509 | " report_to=\"none\"\n",
3510 | ")"
3511 | ]
3512 | },
3513 | {
3514 | "cell_type": "markdown",
3515 | "id": "a8b9149a-0c08-4c73-b5e8-5af49109ae13",
3516 | "metadata": {
3517 | "id": "bc95d099"
3518 | },
3519 | "source": [
3520 | "Next, we define the metric we will use to evaluate our models and write a `compute_metrics` function. We can load this from the `evaluate` library."
3521 | ]
3522 | },
3523 | {
3524 | "cell_type": "code",
3525 | "execution_count": 30,
3526 | "id": "05dbfcc1-3175-4693-9b2f-a5f266c4bff7",
3527 | "metadata": {
3528 | "id": "471cef9f"
3529 | },
3530 | "outputs": [
3531 | {
3532 | "data": {
3533 | "application/vnd.jupyter.widget-view+json": {
3534 | "model_id": "6dc00b0c25534b1a9f1aa0be9630f76d",
3535 | "version_major": 2,
3536 | "version_minor": 0
3537 | },
3538 | "text/plain": [
3539 | "Downloading builder script: 0%| | 0.00/4.20k [00:00, ?B/s]"
3540 | ]
3541 | },
3542 | "metadata": {},
3543 | "output_type": "display_data"
3544 | }
3545 | ],
3546 | "source": [
3547 | "from evaluate import load\n",
3548 | "import numpy as np\n",
3549 | "\n",
3550 | "# we will compute the model accuracy\n",
3551 | "metric = load(\"accuracy\")\n",
3552 | "\n",
3553 | "# build evaluation function to be used during model training\n",
3554 | "def compute_metrics(eval_pred):\n",
3555 | " predictions, labels = eval_pred\n",
3556 | " predictions = np.argmax(predictions, axis=1)\n",
3557 | " return metric.compute(predictions=predictions, references=labels)"
3558 | ]
3559 | },
3560 | {
3561 | "cell_type": "markdown",
3562 | "id": "3104367a-5c18-4d95-9950-39d1cdc85345",
3563 | "metadata": {
3564 | "id": "709dcf25"
3565 | },
3566 | "source": [
3567 | "## Training\n",
3568 | "\n",
3569 | "And at last we're ready to initialize our `Trainer`:"
3570 | ]
3571 | },
3572 | {
3573 | "cell_type": "code",
3574 | "execution_count": 31,
3575 | "id": "4a7e0744-bac2-42db-9236-58b5e772587e",
3576 | "metadata": {
3577 | "id": "e212b751"
3578 | },
3579 | "outputs": [
3580 | {
3581 | "name": "stderr",
3582 | "output_type": "stream",
3583 | "text": [
3584 | "/var/folders/3d/vpv9_sk51c584kypm0w04hmh0000gp/T/ipykernel_22522/2543515990.py:1: FutureWarning:\n",
3585 | "\n",
3586 | "`tokenizer` is deprecated and will be removed in version 5.0.0 for `Trainer.__init__`. Use `processing_class` instead.\n",
3587 | "\n"
3588 | ]
3589 | }
3590 | ],
3591 | "source": [
3592 | "trainer = Trainer(\n",
3593 | " model,\n",
3594 | " args,\n",
3595 | " train_dataset=train_val_dataset['train'],\n",
3596 | " eval_dataset=train_val_dataset['test'],\n",
3597 | " tokenizer=tokenizer,\n",
3598 | " compute_metrics=compute_metrics,\n",
3599 | ")"
3600 | ]
3601 | },
3602 | {
3603 | "cell_type": "markdown",
3604 | "id": "3700b0cd-99db-46f5-a39b-aba46c1ce145",
3605 | "metadata": {
3606 | "id": "32924d0d"
3607 | },
3608 | "source": [
3609 | "You might wonder why we pass along the `tokenizer` when we already preprocessed our data. This is because we will use it one last time to make all the samples we gather the same length by applying padding, which requires knowing the model's preferences regarding padding (to the left or right? with which token?). The `tokenizer` has a pad method that will do all of this right for us, and the `Trainer` will use it. You can customize this part by defining and passing your own `data_collator` which will receive samples like the dictionaries seen above and will need to return a dictionary of tensors."
3610 | ]
3611 | },
3612 | {
3613 | "cell_type": "markdown",
3614 | "id": "8b9bd8fe-42ff-4f3b-a0ed-f0f401a68fbd",
3615 | "metadata": {
3616 | "id": "72f7a24c"
3617 | },
3618 | "source": [
3619 | "We can now finetune our model by just calling the `train` method:"
3620 | ]
3621 | },
3622 | {
3623 | "cell_type": "code",
3624 | "execution_count": 32,
3625 | "id": "10e341ad-9594-49bb-a2f3-fec4e68ea799",
3626 | "metadata": {
3627 | "id": "9c3cf6da",
3628 | "scrolled": true
3629 | },
3630 | "outputs": [
3631 | {
3632 | "data": {
3633 | "application/vnd.jupyter.widget-view+json": {
3634 | "model_id": "004d94a51568426ab4cc7fd0c5e883be",
3635 | "version_major": 2,
3636 | "version_minor": 0
3637 | },
3638 | "text/plain": [
3639 | " 0%| | 0/1242 [00:00, ?it/s]"
3640 | ]
3641 | },
3642 | "metadata": {},
3643 | "output_type": "display_data"
3644 | },
3645 | {
3646 | "data": {
3647 | "application/vnd.jupyter.widget-view+json": {
3648 | "model_id": "e644f6f8a6294f04bfe22fec015769b4",
3649 | "version_major": 2,
3650 | "version_minor": 0
3651 | },
3652 | "text/plain": [
3653 | " 0%| | 0/104 [00:00, ?it/s]"
3654 | ]
3655 | },
3656 | "metadata": {},
3657 | "output_type": "display_data"
3658 | },
3659 | {
3660 | "name": "stdout",
3661 | "output_type": "stream",
3662 | "text": [
3663 | "{'eval_loss': 0.17506983876228333, 'eval_accuracy': 0.9492753623188406, 'eval_runtime': 50.2208, 'eval_samples_per_second': 16.487, 'eval_steps_per_second': 2.071, 'epoch': 1.0}\n",
3664 | "{'loss': 0.2387, 'grad_norm': 22.21633529663086, 'learning_rate': 1.1948470209339775e-05, 'epoch': 1.21}\n"
3665 | ]
3666 | },
3667 | {
3668 | "data": {
3669 | "application/vnd.jupyter.widget-view+json": {
3670 | "model_id": "11ce918e0a714ce1b0aaa39e22e698d9",
3671 | "version_major": 2,
3672 | "version_minor": 0
3673 | },
3674 | "text/plain": [
3675 | " 0%| | 0/104 [00:00, ?it/s]"
3676 | ]
3677 | },
3678 | "metadata": {},
3679 | "output_type": "display_data"
3680 | },
3681 | {
3682 | "name": "stdout",
3683 | "output_type": "stream",
3684 | "text": [
3685 | "{'eval_loss': 0.1711239218711853, 'eval_accuracy': 0.9528985507246377, 'eval_runtime': 47.6384, 'eval_samples_per_second': 17.381, 'eval_steps_per_second': 2.183, 'epoch': 2.0}\n",
3686 | "{'loss': 0.1297, 'grad_norm': 2.55241322517395, 'learning_rate': 3.89694041867955e-06, 'epoch': 2.42}\n"
3687 | ]
3688 | },
3689 | {
3690 | "data": {
3691 | "application/vnd.jupyter.widget-view+json": {
3692 | "model_id": "968affa71026400c815a8713fbe0fe1c",
3693 | "version_major": 2,
3694 | "version_minor": 0
3695 | },
3696 | "text/plain": [
3697 | " 0%| | 0/104 [00:00, ?it/s]"
3698 | ]
3699 | },
3700 | "metadata": {},
3701 | "output_type": "display_data"
3702 | },
3703 | {
3704 | "name": "stdout",
3705 | "output_type": "stream",
3706 | "text": [
3707 | "{'eval_loss': 0.1626405566930771, 'eval_accuracy': 0.9541062801932367, 'eval_runtime': 46.6456, 'eval_samples_per_second': 17.751, 'eval_steps_per_second': 2.23, 'epoch': 3.0}\n",
3708 | "{'train_runtime': 1943.4779, 'train_samples_per_second': 5.106, 'train_steps_per_second': 0.639, 'train_loss': 0.16977286684340326, 'epoch': 3.0}\n"
3709 | ]
3710 | },
3711 | {
3712 | "data": {
3713 | "text/plain": [
3714 | "TrainOutput(global_step=1242, training_loss=0.16977286684340326, metrics={'train_runtime': 1943.4779, 'train_samples_per_second': 5.106, 'train_steps_per_second': 0.639, 'total_flos': 892203812094672.0, 'train_loss': 0.16977286684340326, 'epoch': 3.0})"
3715 | ]
3716 | },
3717 | "execution_count": 32,
3718 | "metadata": {},
3719 | "output_type": "execute_result"
3720 | }
3721 | ],
3722 | "source": [
3723 | "trainer.train()"
3724 | ]
3725 | },
3726 | {
3727 | "cell_type": "markdown",
3728 | "id": "eec662d9-ec7f-4313-b365-3299060dc09e",
3729 | "metadata": {
3730 | "id": "dfec59f4"
3731 | },
3732 | "source": [
3733 | "Nice! After three epochs we have a model accuracy of ~94%. \n",
3734 | "\n",
3735 | "## Evaluation\n",
3736 | "\n",
3737 | "We will take a look at how our final fine-tuned model performs when predicting the subcellular location of protein sequences the model has not seen before (i.e., test set)."
3738 | ]
3739 | },
3740 | {
3741 | "cell_type": "code",
3742 | "execution_count": 33,
3743 | "id": "f90c93f7-aa89-4b2f-8233-d8b1e73199dc",
3744 | "metadata": {},
3745 | "outputs": [
3746 | {
3747 | "data": {
3748 | "application/vnd.jupyter.widget-view+json": {
3749 | "model_id": "dfaf9cae4f634a4099780f34dfcf4c4f",
3750 | "version_major": 2,
3751 | "version_minor": 0
3752 | },
3753 | "text/plain": [
3754 | " 0%| | 0/130 [00:00, ?it/s]"
3755 | ]
3756 | },
3757 | "metadata": {},
3758 | "output_type": "display_data"
3759 | }
3760 | ],
3761 | "source": [
3762 | "# taking a look at model outputs\n",
3763 | "output = trainer.predict(test_dataset)"
3764 | ]
3765 | },
3766 | {
3767 | "cell_type": "code",
3768 | "execution_count": 34,
3769 | "id": "4ad25398-619b-44ea-9a07-d0f4cc4ad998",
3770 | "metadata": {},
3771 | "outputs": [],
3772 | "source": [
3773 | "# from logits to classifications\n",
3774 | "from scipy.special import softmax\n",
3775 | "\n",
3776 | "# from logits to class probabilities\n",
3777 | "y_proba = softmax(output.predictions, axis=-1)\n",
3778 | "\n",
3779 | "# from probabilities to classifications\n",
3780 | "y_pred = np.argmax(y_proba, axis=-1)"
3781 | ]
3782 | },
3783 | {
3784 | "cell_type": "code",
3785 | "execution_count": 35,
3786 | "id": "004775ce-f71e-4122-800e-cb63c6438eb5",
3787 | "metadata": {},
3788 | "outputs": [
3789 | {
3790 | "name": "stdout",
3791 | "output_type": "stream",
3792 | "text": [
3793 | " precision recall f1-score support\n",
3794 | "\n",
3795 | " 0 0.94 0.95 0.95 527\n",
3796 | " 1 0.95 0.94 0.94 507\n",
3797 | "\n",
3798 | " accuracy 0.94 1034\n",
3799 | " macro avg 0.94 0.94 0.94 1034\n",
3800 | "weighted avg 0.94 0.94 0.94 1034\n",
3801 | "\n"
3802 | ]
3803 | }
3804 | ],
3805 | "source": [
3806 | "from sklearn.metrics import classification_report\n",
3807 | "\n",
3808 | "print(classification_report(y_true=test_labels, y_pred=y_pred))"
3809 | ]
3810 | },
3811 | {
3812 | "cell_type": "markdown",
3813 | "id": "102e2ed8-4fb6-40e6-87c3-ce2ed526934c",
3814 | "metadata": {},
3815 | "source": [
3816 | "Our goal was to classify the subcellular location of given proteins. Our final fine-tuned model achieved 95% on the test set. Note that we didn't do a lot of work to filter the training data or tune hyperparameters for this experiment, and also that we used one of the smallest ESM-2 models. With a larger starting model and more effort to ensure that the training data categories were cleanly separable, accuracy could almost certainly go a lot higher!"
3817 | ]
3818 | }
3819 | ],
3820 | "metadata": {
3821 | "kernelspec": {
3822 | "display_name": ".venv",
3823 | "language": "python",
3824 | "name": "python3"
3825 | },
3826 | "language_info": {
3827 | "codemirror_mode": {
3828 | "name": "ipython",
3829 | "version": 3
3830 | },
3831 | "file_extension": ".py",
3832 | "mimetype": "text/x-python",
3833 | "name": "python",
3834 | "nbconvert_exporter": "python",
3835 | "pygments_lexer": "ipython3",
3836 | "version": "3.11.0"
3837 | }
3838 | },
3839 | "nbformat": 4,
3840 | "nbformat_minor": 5
3841 | }
3842 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.poetry]
2 | name = "course-protein-language-modeling"
3 | version = "0.1.0"
4 | description = ""
5 | authors = ["Your Name "]
6 | readme = "README.md"
7 |
8 | [tool.poetry.dependencies]
9 | python = "^3.11"
10 | transformers = {extras = ["torch"], version = "^4.47.1"}
11 | datasets = "^3.2.0"
12 | evaluate = "^0.4.3"
13 | biopython = "^1.84"
14 | py3dmol = "^2.4.2"
15 | pymsaviz = "^0.5.0"
16 | ipykernel = "^6.29.5"
17 | plotly = "^5.24.1"
18 | nbformat = "^5.10.4"
19 | jupyter = "^1.1.1"
20 | ipywidgets = "^8.1.5"
21 | pandas = "^2.2.3"
22 | scikit-learn = "^1.6.0"
23 | sentencepiece = "^0.2.0"
24 | h5py = "^3.12.1"
25 |
26 |
27 | [build-system]
28 | requires = ["poetry-core"]
29 | build-backend = "poetry.core.masonry.api"
30 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | accelerate==1.2.1 ; python_version >= "3.11" and python_version < "4.0"
2 | aiohappyeyeballs==2.4.4 ; python_version >= "3.11" and python_version < "4.0"
3 | aiohttp==3.11.11 ; python_version >= "3.11" and python_version < "4.0"
4 | aiosignal==1.3.2 ; python_version >= "3.11" and python_version < "4.0"
5 | anyio==4.8.0 ; python_version >= "3.11" and python_version < "4.0"
6 | appnope==0.1.4 ; python_version >= "3.11" and python_version < "4.0" and platform_system == "Darwin"
7 | argon2-cffi-bindings==21.2.0 ; python_version >= "3.11" and python_version < "4.0"
8 | argon2-cffi==23.1.0 ; python_version >= "3.11" and python_version < "4.0"
9 | arrow==1.3.0 ; python_version >= "3.11" and python_version < "4.0"
10 | asttokens==3.0.0 ; python_version >= "3.11" and python_version < "4.0"
11 | async-lru==2.0.4 ; python_version >= "3.11" and python_version < "4.0"
12 | attrs==24.3.0 ; python_version >= "3.11" and python_version < "4.0"
13 | babel==2.16.0 ; python_version >= "3.11" and python_version < "4.0"
14 | beautifulsoup4==4.12.3 ; python_version >= "3.11" and python_version < "4.0"
15 | biopython==1.84 ; python_version >= "3.11" and python_version < "4.0"
16 | bleach[css]==6.2.0 ; python_version >= "3.11" and python_version < "4.0"
17 | certifi==2024.12.14 ; python_version >= "3.11" and python_version < "4.0"
18 | cffi==1.17.1 ; python_version >= "3.11" and python_version < "4.0"
19 | charset-normalizer==3.4.1 ; python_version >= "3.11" and python_version < "4.0"
20 | colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0" and (platform_system == "Windows" or sys_platform == "win32")
21 | comm==0.2.2 ; python_version >= "3.11" and python_version < "4.0"
22 | contourpy==1.3.1 ; python_version >= "3.11" and python_version < "4.0"
23 | cycler==0.12.1 ; python_version >= "3.11" and python_version < "4.0"
24 | datasets==3.2.0 ; python_version >= "3.11" and python_version < "4.0"
25 | debugpy==1.8.11 ; python_version >= "3.11" and python_version < "4.0"
26 | decorator==5.1.1 ; python_version >= "3.11" and python_version < "4.0"
27 | defusedxml==0.7.1 ; python_version >= "3.11" and python_version < "4.0"
28 | dill==0.3.8 ; python_version >= "3.11" and python_version < "4.0"
29 | evaluate==0.4.3 ; python_version >= "3.11" and python_version < "4.0"
30 | executing==2.1.0 ; python_version >= "3.11" and python_version < "4.0"
31 | fastjsonschema==2.21.1 ; python_version >= "3.11" and python_version < "4.0"
32 | filelock==3.16.1 ; python_version >= "3.11" and python_version < "4.0"
33 | fonttools==4.55.3 ; python_version >= "3.11" and python_version < "4.0"
34 | fqdn==1.5.1 ; python_version >= "3.11" and python_version < "4"
35 | frozenlist==1.5.0 ; python_version >= "3.11" and python_version < "4.0"
36 | fsspec==2024.9.0 ; python_version >= "3.11" and python_version < "4.0"
37 | fsspec[http]==2024.9.0 ; python_version >= "3.11" and python_version < "4.0"
38 | h11==0.14.0 ; python_version >= "3.11" and python_version < "4.0"
39 | h5py==3.12.1 ; python_version >= "3.11" and python_version < "4.0"
40 | httpcore==1.0.7 ; python_version >= "3.11" and python_version < "4.0"
41 | httpx==0.28.1 ; python_version >= "3.11" and python_version < "4.0"
42 | huggingface-hub==0.27.1 ; python_version >= "3.11" and python_version < "4.0"
43 | idna==3.10 ; python_version >= "3.11" and python_version < "4.0"
44 | ipykernel==6.29.5 ; python_version >= "3.11" and python_version < "4.0"
45 | ipython==8.31.0 ; python_version >= "3.11" and python_version < "4.0"
46 | ipywidgets==8.1.5 ; python_version >= "3.11" and python_version < "4.0"
47 | isoduration==20.11.0 ; python_version >= "3.11" and python_version < "4.0"
48 | jedi==0.19.2 ; python_version >= "3.11" and python_version < "4.0"
49 | jinja2==3.1.5 ; python_version >= "3.11" and python_version < "4.0"
50 | joblib==1.4.2 ; python_version >= "3.11" and python_version < "4.0"
51 | json5==0.10.0 ; python_version >= "3.11" and python_version < "4.0"
52 | jsonpointer==3.0.0 ; python_version >= "3.11" and python_version < "4.0"
53 | jsonschema-specifications==2024.10.1 ; python_version >= "3.11" and python_version < "4.0"
54 | jsonschema==4.23.0 ; python_version >= "3.11" and python_version < "4.0"
55 | jsonschema[format-nongpl]==4.23.0 ; python_version >= "3.11" and python_version < "4.0"
56 | jupyter-client==8.6.3 ; python_version >= "3.11" and python_version < "4.0"
57 | jupyter-console==6.6.3 ; python_version >= "3.11" and python_version < "4.0"
58 | jupyter-core==5.7.2 ; python_version >= "3.11" and python_version < "4.0"
59 | jupyter-events==0.11.0 ; python_version >= "3.11" and python_version < "4.0"
60 | jupyter-lsp==2.2.5 ; python_version >= "3.11" and python_version < "4.0"
61 | jupyter-server-terminals==0.5.3 ; python_version >= "3.11" and python_version < "4.0"
62 | jupyter-server==2.15.0 ; python_version >= "3.11" and python_version < "4.0"
63 | jupyter==1.1.1 ; python_version >= "3.11" and python_version < "4.0"
64 | jupyterlab-pygments==0.3.0 ; python_version >= "3.11" and python_version < "4.0"
65 | jupyterlab-server==2.27.3 ; python_version >= "3.11" and python_version < "4.0"
66 | jupyterlab-widgets==3.0.13 ; python_version >= "3.11" and python_version < "4.0"
67 | jupyterlab==4.3.4 ; python_version >= "3.11" and python_version < "4.0"
68 | kiwisolver==1.4.8 ; python_version >= "3.11" and python_version < "4.0"
69 | markupsafe==3.0.2 ; python_version >= "3.11" and python_version < "4.0"
70 | matplotlib-inline==0.1.7 ; python_version >= "3.11" and python_version < "4.0"
71 | matplotlib==3.10.0 ; python_version >= "3.11" and python_version < "4.0"
72 | mistune==3.1.0 ; python_version >= "3.11" and python_version < "4.0"
73 | mpmath==1.3.0 ; python_version >= "3.11" and python_version < "4.0"
74 | multidict==6.1.0 ; python_version >= "3.11" and python_version < "4.0"
75 | multiprocess==0.70.16 ; python_version >= "3.11" and python_version < "4.0"
76 | nbclient==0.10.2 ; python_version >= "3.11" and python_version < "4.0"
77 | nbconvert==7.16.5 ; python_version >= "3.11" and python_version < "4.0"
78 | nbformat==5.10.4 ; python_version >= "3.11" and python_version < "4.0"
79 | nest-asyncio==1.6.0 ; python_version >= "3.11" and python_version < "4.0"
80 | networkx==3.4.2 ; python_version >= "3.11" and python_version < "4.0"
81 | notebook-shim==0.2.4 ; python_version >= "3.11" and python_version < "4.0"
82 | notebook==7.3.2 ; python_version >= "3.11" and python_version < "4.0"
83 | numpy==2.2.1 ; python_version >= "3.11" and python_version < "4.0"
84 | nvidia-cublas-cu12==12.4.5.8 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
85 | nvidia-cuda-cupti-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
86 | nvidia-cuda-nvrtc-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
87 | nvidia-cuda-runtime-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
88 | nvidia-cudnn-cu12==9.1.0.70 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
89 | nvidia-cufft-cu12==11.2.1.3 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
90 | nvidia-curand-cu12==10.3.5.147 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
91 | nvidia-cusolver-cu12==11.6.1.9 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
92 | nvidia-cusparse-cu12==12.3.1.170 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
93 | nvidia-nccl-cu12==2.21.5 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
94 | nvidia-nvjitlink-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
95 | nvidia-nvtx-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.11" and python_version < "4.0"
96 | overrides==7.7.0 ; python_version >= "3.11" and python_version < "4.0"
97 | packaging==24.2 ; python_version >= "3.11" and python_version < "4.0"
98 | pandas==2.2.3 ; python_version >= "3.11" and python_version < "4.0"
99 | pandocfilters==1.5.1 ; python_version >= "3.11" and python_version < "4.0"
100 | parso==0.8.4 ; python_version >= "3.11" and python_version < "4.0"
101 | pexpect==4.9.0 ; python_version >= "3.11" and python_version < "4.0" and (sys_platform != "win32" and sys_platform != "emscripten")
102 | pillow==11.1.0 ; python_version >= "3.11" and python_version < "4.0"
103 | platformdirs==4.3.6 ; python_version >= "3.11" and python_version < "4.0"
104 | plotly==5.24.1 ; python_version >= "3.11" and python_version < "4.0"
105 | prometheus-client==0.21.1 ; python_version >= "3.11" and python_version < "4.0"
106 | prompt-toolkit==3.0.48 ; python_version >= "3.11" and python_version < "4.0"
107 | propcache==0.2.1 ; python_version >= "3.11" and python_version < "4.0"
108 | psutil==6.1.1 ; python_version >= "3.11" and python_version < "4.0"
109 | ptyprocess==0.7.0 ; python_version >= "3.11" and python_version < "4.0" and (sys_platform != "win32" and sys_platform != "emscripten" or os_name != "nt")
110 | pure-eval==0.2.3 ; python_version >= "3.11" and python_version < "4.0"
111 | py3dmol==2.4.2 ; python_version >= "3.11" and python_version < "4.0"
112 | pyarrow==18.1.0 ; python_version >= "3.11" and python_version < "4.0"
113 | pycparser==2.22 ; python_version >= "3.11" and python_version < "4.0"
114 | pygments==2.19.1 ; python_version >= "3.11" and python_version < "4.0"
115 | pymsaviz==0.5.0 ; python_version >= "3.11" and python_version < "4.0"
116 | pyparsing==3.2.1 ; python_version >= "3.11" and python_version < "4.0"
117 | python-dateutil==2.9.0.post0 ; python_version >= "3.11" and python_version < "4.0"
118 | python-json-logger==3.2.1 ; python_version >= "3.11" and python_version < "4.0"
119 | pytz==2024.2 ; python_version >= "3.11" and python_version < "4.0"
120 | pywin32==308 ; sys_platform == "win32" and platform_python_implementation != "PyPy" and python_version >= "3.11" and python_version < "4.0"
121 | pywinpty==2.0.14 ; python_version >= "3.11" and python_version < "4.0" and os_name == "nt"
122 | pyyaml==6.0.2 ; python_version >= "3.11" and python_version < "4.0"
123 | pyzmq==26.2.0 ; python_version >= "3.11" and python_version < "4.0"
124 | referencing==0.35.1 ; python_version >= "3.11" and python_version < "4.0"
125 | regex==2024.11.6 ; python_version >= "3.11" and python_version < "4.0"
126 | requests==2.32.3 ; python_version >= "3.11" and python_version < "4.0"
127 | rfc3339-validator==0.1.4 ; python_version >= "3.11" and python_version < "4.0"
128 | rfc3986-validator==0.1.1 ; python_version >= "3.11" and python_version < "4.0"
129 | rpds-py==0.22.3 ; python_version >= "3.11" and python_version < "4.0"
130 | safetensors==0.5.1 ; python_version >= "3.11" and python_version < "4.0"
131 | scikit-learn==1.6.0 ; python_version >= "3.11" and python_version < "4.0"
132 | scipy==1.15.0 ; python_version >= "3.11" and python_version < "4.0"
133 | send2trash==1.8.3 ; python_version >= "3.11" and python_version < "4.0"
134 | sentencepiece==0.2.0 ; python_version >= "3.11" and python_version < "4.0"
135 | setuptools==75.7.0 ; python_version >= "3.11" and python_version < "4.0"
136 | six==1.17.0 ; python_version >= "3.11" and python_version < "4.0"
137 | sniffio==1.3.1 ; python_version >= "3.11" and python_version < "4.0"
138 | soupsieve==2.6 ; python_version >= "3.11" and python_version < "4.0"
139 | stack-data==0.6.3 ; python_version >= "3.11" and python_version < "4.0"
140 | sympy==1.13.1 ; python_version >= "3.11" and python_version < "4.0"
141 | tenacity==9.0.0 ; python_version >= "3.11" and python_version < "4.0"
142 | terminado==0.18.1 ; python_version >= "3.11" and python_version < "4.0"
143 | threadpoolctl==3.5.0 ; python_version >= "3.11" and python_version < "4.0"
144 | tinycss2==1.4.0 ; python_version >= "3.11" and python_version < "4.0"
145 | tokenizers==0.21.0 ; python_version >= "3.11" and python_version < "4.0"
146 | torch==2.5.1 ; python_version >= "3.11" and python_version < "4.0"
147 | tornado==6.4.2 ; python_version >= "3.11" and python_version < "4.0"
148 | tqdm==4.67.1 ; python_version >= "3.11" and python_version < "4.0"
149 | traitlets==5.14.3 ; python_version >= "3.11" and python_version < "4.0"
150 | transformers[torch]==4.47.1 ; python_version >= "3.11" and python_version < "4.0"
151 | triton==3.1.0 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.13" and python_version >= "3.11"
152 | types-python-dateutil==2.9.0.20241206 ; python_version >= "3.11" and python_version < "4.0"
153 | typing-extensions==4.12.2 ; python_version >= "3.11" and python_version < "4.0"
154 | tzdata==2024.2 ; python_version >= "3.11" and python_version < "4.0"
155 | uri-template==1.3.0 ; python_version >= "3.11" and python_version < "4.0"
156 | urllib3==2.3.0 ; python_version >= "3.11" and python_version < "4.0"
157 | wcwidth==0.2.13 ; python_version >= "3.11" and python_version < "4.0"
158 | webcolors==24.11.1 ; python_version >= "3.11" and python_version < "4.0"
159 | webencodings==0.5.1 ; python_version >= "3.11" and python_version < "4.0"
160 | websocket-client==1.8.0 ; python_version >= "3.11" and python_version < "4.0"
161 | widgetsnbextension==4.0.13 ; python_version >= "3.11" and python_version < "4.0"
162 | xxhash==3.5.0 ; python_version >= "3.11" and python_version < "4.0"
163 | yarl==1.18.3 ; python_version >= "3.11" and python_version < "4.0"
164 |
--------------------------------------------------------------------------------
/slides/intro_pLM.key:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Multiomics-Analytics-Group/course_protein_language_modeling/37c74ceb67f32c138a7a7e6a6cc2c6baccffcfef/slides/intro_pLM.key
--------------------------------------------------------------------------------
/slides/intro_pLM.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Multiomics-Analytics-Group/course_protein_language_modeling/37c74ceb67f32c138a7a7e6a6cc2c6baccffcfef/slides/intro_pLM.pdf
--------------------------------------------------------------------------------
/topics.md:
--------------------------------------------------------------------------------
1 | # Protein Language Modeling Course
2 |
3 |
4 | ## Topics
5 | ----
6 | **1. Proteins**
7 |
8 | What are they and why are they important.
9 |
10 | **2. The Language of Proteins: Sequences**
11 |
12 | Analyzing the amino acid sequence of a protein, including aligning sequences, identifying patterns, and utilizing databases and resources to gain insights into protein function and evolution.
13 |
14 | **3. Protein Structure**
15 |
16 | Predicting the three-dimensional structure of a protein using computational methods, including homology modeling, comparative modeling, and de novo structure prediction.
17 |
18 | **4. Protein-Protein Interactions**
19 |
20 | Exploring how proteins interact with each other, including computational techniques for predicting and analyzing protein-protein interactions, as well as docking algorithms for simulating their binding.
21 |
22 | **5. Protein Engineering and Design**
23 |
24 | Modifying proteins to enhance their properties or design new ones, using methods like directed evolution and rational design, often guided by computational modeling and simulation.
25 |
26 | **6. Protein Function Prediction and Annotation**
27 |
28 | Inferring the function of a protein based on its sequence or structure, utilizing computational methods to predict and annotate protein functions, including predicting protein-protein interactions.
29 |
30 | **7. Data Resources**
31 |
32 | A description of resources that contain relevant protein data that can be used in ML models.
33 |
34 | **8. Machine Learning and Deep Learning for Protein Language Modeling**
35 |
36 | Leveraging machine learning and deep learning algorithms to model and analyze protein sequences and structures, enabling tasks such as sequence generation, structure prediction, and function annotation.
37 |
38 | **9. Applications of Protein Language Models**
39 |
40 | Exploring real-world applications of protein language modeling, including refining and improving protein structures, predicting protein-protein interactions, facilitating drug discovery, and aiding protein engineering and design.
41 |
42 | **10. Limitations**
43 |
44 | Addressing the limitations associated with protein language modeling, potential biases or shortcomings of computational methods.
45 |
--------------------------------------------------------------------------------