{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":87793,"databundleVersionId":11228175,"isSourceIdPinned":false,"sourceType":"competition"}],"dockerImageVersionId":30558,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"Published on February 27, 2025. By Prata, Marília (mpwolke)","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n\n#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:45:45.859001Z","iopub.execute_input":"2025-02-27T22:45:45.859331Z","iopub.status.idle":"2025-02-27T22:45:47.114633Z","shell.execute_reply.started":"2025-02-27T22:45:45.859307Z","shell.execute_reply":"2025-02-27T22:45:47.113619Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Even Kaggle team is adding Joy to Competition\n\nI didn't even have to find another image. Job is already done\n\n\n![](https://imgs.xkcd.com/comics/rna.png)","metadata":{}},{"cell_type":"markdown","source":"## Competition Citation\n\n@misc{stanford-rna-3d-folding,\n\n    author = {Shujun He and CASP16 organizers and CASP16 RNA experimentalists and RNA-Puzzles \n    consortium and VFOLD team and Rachael Kretsch and Alissa Hummer and Andrew Favor and Walter Reade and Maggie Demkin and Rhiju Das and others},\n    \n    title = {Stanford RNA 3D Folding},\n    year = {2025},","metadata":{}},{"cell_type":"markdown","source":"### train_sequences file","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/stanford-rna-3d-folding/train_sequences.csv')\ntrain.tail(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:46:06.181421Z","iopub.execute_input":"2025-02-27T22:46:06.182070Z","iopub.status.idle":"2025-02-27T22:46:06.281935Z","shell.execute_reply.started":"2025-02-27T22:46:06.182032Z","shell.execute_reply":"2025-02-27T22:46:06.280765Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### train_labels file","metadata":{}},{"cell_type":"code","source":"train_labels = pd.read_csv('/kaggle/input/stanford-rna-3d-folding/train_labels.csv')\ntrain_labels.tail(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:48:32.173023Z","iopub.execute_input":"2025-02-27T22:48:32.173514Z","iopub.status.idle":"2025-02-27T22:48:32.532025Z","shell.execute_reply.started":"2025-02-27T22:48:32.173477Z","shell.execute_reply":"2025-02-27T22:48:32.530759Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### validation_sequences file","metadata":{}},{"cell_type":"code","source":"val = pd.read_csv('/kaggle/input/stanford-rna-3d-folding/validation_sequences.csv')\nval.tail(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:49:25.297499Z","iopub.execute_input":"2025-02-27T22:49:25.297916Z","iopub.status.idle":"2025-02-27T22:49:25.316339Z","shell.execute_reply.started":"2025-02-27T22:49:25.297885Z","shell.execute_reply":"2025-02-27T22:49:25.315346Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Title's inspiration: Pyrococcus furiosus (\"Rushing Fireball\")\n\nBelow, on train Description entries: Crystal structure of a substrate-bound full H/ACA RNP from **Pyrococcus furiosus**\n\n\"Pyrococcus furiosus (“**rushing fireball**”) was named for the ability of this archaeal coccus to rapidly swim at its optimal growth temperature, around 100°C.\"\n\nhttps://pmc.ncbi.nlm.nih.gov/articles/PMC1595509/#:~:text=Pyrococcus%20furiosus%20(%E2%80%9Crushing%20fireball%E2%80%9D,temperature%2C%20around%20100%C2%B0C.\n\n\"**Pyrococcus furiosus** is a heterotrophic, strictly anaerobic, extremophilic, model species of archaea. It is classified as a hyperthermophile because it thrives best under extremely high temperatures, and is notable for having an optimum growth temperature of 100 °C (a temperature that would destroy most living organisms).\n\n\"P. furiosus belongs to the Pyrococcus genus, most commonly found in extreme environmental conditions of hydrothermal vents. It is one of the few prokaryotic organisms that has enzymes containing tungsten, an element rarely found in biological molecules.\"\n\nhttps://en.wikipedia.org/wiki/Pyrococcus_furiosus","metadata":{}},{"cell_type":"code","source":"train['description'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:50:04.536061Z","iopub.execute_input":"2025-02-27T22:50:04.536584Z","iopub.status.idle":"2025-02-27T22:50:04.564729Z","shell.execute_reply.started":"2025-02-27T22:50:04.536550Z","shell.execute_reply":"2025-02-27T22:50:04.563107Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## all-sequences FASTA-formatted\n\n\"all_sequences - (string) FASTA-formatted sequences of all molecular chains present in the experimentally solved structure. In a few cases this may include multiple copies of the target RNA (look for the word \"Chains\" in the header) and/or partners like other RNAs or proteins or DNA. You don't need to make predictions for all these molecules; if you do, just submit predictions for sequence. Some entries are blank.\"\n\nhttps://www.kaggle.com/competitions/stanford-rna-3d-folding/data?select=train_labels.csv","metadata":{}},{"cell_type":"code","source":"train['all_sequences'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:50:56.589682Z","iopub.execute_input":"2025-02-27T22:50:56.590178Z","iopub.status.idle":"2025-02-27T22:50:56.625972Z","shell.execute_reply.started":"2025-02-27T22:50:56.590146Z","shell.execute_reply":"2025-02-27T22:50:56.624523Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Since I wasn't able to install EternaFold I forked Thomas code from last year.\n\n### Setting up an RNA Science Environment","metadata":{}},{"cell_type":"markdown","source":"The computational biology field has a lot of helpful software packages for interacting with RNA sequences and experimental data. First, let's install `arnie`, a helpful utility library that simplifies interacting with various secondary structure prediction packages.","metadata":{}},{"cell_type":"code","source":"!pip install arnie","metadata":{"execution":{"iopub.status.busy":"2025-02-27T22:38:53.621047Z","iopub.execute_input":"2025-02-27T22:38:53.621404Z","iopub.status.idle":"2025-02-27T22:39:07.463247Z","shell.execute_reply.started":"2025-02-27T22:38:53.621376Z","shell.execute_reply":"2025-02-27T22:39:07.461709Z"},"trusted":true,"collapsed":true,"jupyter":{"outputs_hidden":true},"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Arnie needs at least one secondary structure predictor, so let's install `EternaFold`. [Eternafold](https://www.nature.com/articles/s41592-022-01605-0) is a leading prediction package that was trained using sequences collected via the citizen science game [Eterna](http://eternagame.org). In fact, Eterna players provided many of the sequences in the data for this competition. \n\nhttps://www.kaggle.com/code/brainbowrna/rna-science-computational-environment/notebook","metadata":{}},{"cell_type":"markdown","source":"## Eternafold\n\nOn my Notebook I got:  /bin/bash: line 1: conda: command not found\n\nThat's why I had to copy/edit Thomas code.","metadata":{}},{"cell_type":"code","source":"# Install Eternafold\n!conda config --set auto_update_conda false\n!conda install -c bioconda eternafold --yes","metadata":{"execution":{"iopub.status.busy":"2025-02-27T22:39:20.485339Z","iopub.execute_input":"2025-02-27T22:39:20.485900Z","iopub.status.idle":"2025-02-27T22:41:57.956068Z","shell.execute_reply.started":"2025-02-27T22:39:20.485854Z","shell.execute_reply":"2025-02-27T22:41:57.954659Z"},"trusted":true,"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Ordinarily, the `EternaFold` conda package will automatically set necessary environment variables, but Kaggle's conda install works a little differently. Let's set them manually here using `%env`.","metadata":{"_kg_hide-output":true}},{"cell_type":"code","source":"%env ETERNAFOLD_PATH=/opt/conda/bin/eternafold-bin\n%env ETERNAFOLD_PARAMETERS=/opt/conda/lib/eternafold-lib/parameters/EternaFoldParams.v1","metadata":{"execution":{"iopub.status.busy":"2025-02-27T22:42:24.059915Z","iopub.execute_input":"2025-02-27T22:42:24.060326Z","iopub.status.idle":"2025-02-27T22:42:24.067533Z","shell.execute_reply.started":"2025-02-27T22:42:24.060292Z","shell.execute_reply":"2025-02-27T22:42:24.066321Z"},"trusted":true,"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Now that we have a predictor, we can make structure predictions about a given sequence. For example, let's look at an example Hammerhead ribozyme sequence. We can use arnie's `mfe`, or Minimum Free Energy, function to predict a secondary structure for this RNA sequence. The structure will be represented in \"dot-bracket\" notation, where `.` is an unpaired base and `()` represent two paired bases.","metadata":{}},{"cell_type":"markdown","source":"### Finding Pyrococcus furiosus (aka Rushing fireball) on Description.","metadata":{}},{"cell_type":"code","source":"fireball = train[(train['description']=='Crystal structure of a substrate-bound full H/ACA RNP from Pyrococcus furiosus')].reset_index(drop=True)\nfireball.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:52:27.501374Z","iopub.execute_input":"2025-02-27T22:52:27.501746Z","iopub.status.idle":"2025-02-27T22:52:27.519744Z","shell.execute_reply.started":"2025-02-27T22:52:27.501719Z","shell.execute_reply":"2025-02-27T22:52:27.518677Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### Pyrococcus furiosus (fireball) RNA sequence","metadata":{}},{"cell_type":"code","source":"sequence = fireball[fireball[\"target_id\"] == \"3HAY_E\"][\"sequence\"][0]#.compute()\nsequence","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:52:53.931527Z","iopub.execute_input":"2025-02-27T22:52:53.931936Z","iopub.status.idle":"2025-02-27T22:52:53.940799Z","shell.execute_reply.started":"2025-02-27T22:52:53.931906Z","shell.execute_reply":"2025-02-27T22:52:53.939656Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### mfe: minimum free energy prediction\n\n\"Results for minimum free energy prediction\nThe optimal secondary structure in dot-bracket notation with a minimum free energy of -41.40 kcal/mol is given below.\"\n\n\n1      GGCUGCCUGGGUCCGCCUUGAGUGCCCGGGUGAGAAGCAUGAUCCCGGGUAAUUAUGGCGGACCCACAGAU\n\n1      ..(((..((((((((((.(((.((((((((.............)))))))).))).)))))))))))))..\n\n\nhttp://rna.tbi.univie.ac.at//cgi-bin/RNAWebSuite/RNAfold.cgi?PAGE=3&ID=hSNGgVTlVJ&r=21","metadata":{}},{"cell_type":"code","source":"from arnie.mfe import mfe\nfireball_sequence = \"GGCUGCCUGGGUCCGCCUUGAGUGCCCGGGUGAGAAGCAUGAUCCCGGGUAAUUAUGGCGGACCCACAGAU\"\nstructure = mfe(fireball_sequence,package=\"eternafold\")\nprint(structure)","metadata":{"execution":{"iopub.status.busy":"2025-02-27T22:53:49.597694Z","iopub.execute_input":"2025-02-27T22:53:49.598678Z","iopub.status.idle":"2025-02-27T22:53:49.626710Z","shell.execute_reply.started":"2025-02-27T22:53:49.598644Z","shell.execute_reply":"2025-02-27T22:53:49.625544Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Dot bracket notation can be a little hard to read if you're new to RNA structures. Let's visualize the structure in another way. We're going to install `draw_rna`, a Das Lab tool that let's us plot RNA structures in 2D. `draw_rna` provides a `draw_struct` function that ","metadata":{}},{"cell_type":"code","source":"!pip install draw_rna\n\nfrom draw_rna.ipynb_draw import draw_struct","metadata":{"execution":{"iopub.status.busy":"2025-02-27T22:55:02.261065Z","iopub.execute_input":"2025-02-27T22:55:02.261478Z","iopub.status.idle":"2025-02-27T22:55:12.796690Z","shell.execute_reply.started":"2025-02-27T22:55:02.261445Z","shell.execute_reply":"2025-02-27T22:55:12.795259Z"},"trusted":true,"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Drawing of Fireball MFE structure \n\nResults for thermodynamic ensemble prediction\n\n\"The free energy of the thermodynamic ensemble is -42.03 kcal/mol. The frequency of the MFE structure in the ensemble is 36.07 %. The ensemble diversity is 2.30 .\"\n\nhttp://rna.tbi.univie.ac.at//cgi-bin/RNAWebSuite/RNAfold.cgi?PAGE=3&ID=hSNGgVTlVJ&r=21","metadata":{}},{"cell_type":"code","source":"draw_struct(fireball_sequence, structure)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-02-27T22:55:45.596928Z","iopub.execute_input":"2025-02-27T22:55:45.597336Z","iopub.status.idle":"2025-02-27T22:55:46.494949Z","shell.execute_reply.started":"2025-02-27T22:55:45.597300Z","shell.execute_reply":"2025-02-27T22:55:46.493716Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Arnie provides other functions for structure prediction. We can generate a 'Base Pair Probablility' matrix that predicts the probability of every possible base pairing (e.g, how likely is base 1 to pair with base 2, base 3, base 4...). ","metadata":{}},{"cell_type":"code","source":"from arnie.bpps import bpps\nbpps(sequence,package=\"eternafold\")","metadata":{"execution":{"iopub.status.busy":"2025-02-27T22:56:04.553398Z","iopub.execute_input":"2025-02-27T22:56:04.553874Z","iopub.status.idle":"2025-02-27T22:56:04.587053Z","shell.execute_reply.started":"2025-02-27T22:56:04.553834Z","shell.execute_reply":"2025-02-27T22:56:04.585700Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Flagella of Pyrococcus furiosus (Made for Swimming)\n\nFlagella of Pyrococcus furiosus: Multifunctional Organelles, Made for Swimming, Adhesion to Various Surfaces, and Cell-Cell Contacts\n\nCitation: Näther DJ, Rachel R, Wanner G, Wirth R. Flagella of Pyrococcus furiosus: multifunctional organelles, made for swimming, adhesion to various surfaces, and cell-cell contacts. J Bacteriol. 2006 Oct;188(19):6915-23. doi: 10.1128/JB.00527-06. PMID: 16980494; PMCID: PMC1595509.\n\n\"P. furiosus cells could adhere via their flagella to carbon-coated gold grids used for electron microscopic analyses, to sand grains collected from the original habitat (Porto di Levante, Vulcano, Italy), and to various other surfaces. Therefore, the authors concluded that P. furiosus probably **uses flagella for swimming** but that the cell surface appendages also enable this archaeon to form cable-like cell-cell connections and to adhere to solid surfaces.\"\n\nhttps://pmc.ncbi.nlm.nih.gov/articles/PMC1595509/#:~:text=Pyrococcus%20furiosus%20(%E2%80%9Crushing%20fireball%E2%80%9D,temperature%2C%20around%20100%C2%B0C.\n\n### \"Rushing fireball\" could turn carbon dioxide into biofuel\n\n\"The fireball typically feeds on carbohydrates in the super-heated ocean waters near geothermal vents, but researchers were able to create a version of the organism that feeds off of carbon dioxide at a much lower temperature.\"\n\nhttps://www.cbsnews.com/news/rushing-fireball-could-turn-carbon-dioxide-into-biofuel/","metadata":{}},{"cell_type":"markdown","source":"#Acknowledgements:\n\nThomas https://www.kaggle.com/code/brainbowrna/rna-science-computational-environment/notebook","metadata":{}}]}