{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"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\nplt.style.use('fivethirtyeight')\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"papermill":{"duration":1.743264,"end_time":"2023-10-12T12:08:37.376713","exception":false,"start_time":"2023-10-12T12:08:35.633449","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T07:24:39.199154Z","iopub.execute_input":"2023-10-25T07:24:39.199574Z","iopub.status.idle":"2023-10-25T07:24:41.436440Z","shell.execute_reply.started":"2023-10-25T07:24:39.199541Z","shell.execute_reply":"2023-10-25T07:24:41.435002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/stanford-ribonanza-rna-folding/train_data.csv')\ndf.head()","metadata":{"papermill":{"duration":62.914345,"end_time":"2023-10-12T12:09:40.295658","exception":false,"start_time":"2023-10-12T12:08:37.381313","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T07:24:45.042753Z","iopub.execute_input":"2023-10-25T07:24:45.043352Z","iopub.status.idle":"2023-10-25T07:26:35.709115Z","shell.execute_reply.started":"2023-10-25T07:24:45.043313Z","shell.execute_reply":"2023-10-25T07:26:35.707865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe().style.background_gradient(cmap='summer')","metadata":{"papermill":{"duration":20.357122,"end_time":"2023-10-12T12:10:00.657626","exception":false,"start_time":"2023-10-12T12:09:40.300504","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T07:29:38.165099Z","iopub.execute_input":"2023-10-25T07:29:38.165553Z","iopub.status.idle":"2023-10-25T07:30:09.665179Z","shell.execute_reply.started":"2023-10-25T07:29:38.165518Z","shell.execute_reply":"2023-10-25T07:30:09.664033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_counts = df['sequence'].apply(lambda x: pd.Series(list(x)).value_counts()).sum()\nbase_counts.plot(kind='bar')\nplt.xlabel('Base', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Count', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.title('Base Composition', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\n\n# Save the plot\nplt.savefig('Base Composition.png')\n\n# Show the plot\nplt.show()","metadata":{"papermill":{"duration":586.113689,"end_time":"2023-10-12T12:19:46.779434","exception":false,"start_time":"2023-10-12T12:10:00.665745","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T07:30:18.681502Z","iopub.execute_input":"2023-10-25T07:30:18.682142Z","iopub.status.idle":"2023-10-25T07:47:59.963762Z","shell.execute_reply.started":"2023-10-25T07:30:18.682098Z","shell.execute_reply":"2023-10-25T07:47:59.962425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sequence_lengths = df['sequence'].apply(len)\nsns.histplot(sequence_lengths, kde=True)\nplt.xlabel('Sequence Length', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Frequency', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.title('Sequence Length Distribution', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\n\n# Save the plot\nplt.savefig('Sequence Length Distribution.png')\n\n# Show the plot\nplt.show()","metadata":{"papermill":{"duration":6.987648,"end_time":"2023-10-12T12:19:53.775271","exception":false,"start_time":"2023-10-12T12:19:46.787623","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:47:14.797662Z","iopub.execute_input":"2023-10-25T08:47:14.798611Z","iopub.status.idle":"2023-10-25T08:47:26.285690Z","shell.execute_reply.started":"2023-10-25T08:47:14.798505Z","shell.execute_reply":"2023-10-25T08:47:26.283822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"experiment_type_counts = df['experiment_type'].value_counts()\nplt.pie(experiment_type_counts, labels=experiment_type_counts.index, autopct='%1.1f%%')\nplt.title('Experiment Type Distribution', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\n\n# Save the plot\nplt.savefig('Experiment Type Distribution.png')\n\n# Show the plot\nplt.show()","metadata":{"papermill":{"duration":0.197533,"end_time":"2023-10-12T12:19:53.984528","exception":false,"start_time":"2023-10-12T12:19:53.786995","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:47:32.525769Z","iopub.execute_input":"2023-10-25T08:47:32.526608Z","iopub.status.idle":"2023-10-25T08:47:33.062389Z","shell.execute_reply.started":"2023-10-25T08:47:32.526563Z","shell.execute_reply":"2023-10-25T08:47:33.060436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(df['signal_to_noise'], df['reads'])\nplt.xlabel('Signal to Noise', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Reads', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.title('Signal to Noise vs Reads', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\n\n# Save the plot\nplt.savefig('Signal to Noise vs Reads.png')\n\n# Show the plot\nplt.show()","metadata":{"papermill":{"duration":6.898392,"end_time":"2023-10-12T12:20:00.898070","exception":false,"start_time":"2023-10-12T12:19:53.999678","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:47:39.264966Z","iopub.execute_input":"2023-10-25T08:47:39.265510Z","iopub.status.idle":"2023-10-25T08:47:49.170576Z","shell.execute_reply.started":"2023-10-25T08:47:39.265468Z","shell.execute_reply":"2023-10-25T08:47:49.168950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Select only the first 50 reactivity columns\nreactivity_columns = [col for col in df.columns if col.startswith('reactivity')][:50]\nreactivity_data = df[reactivity_columns]\n\n# Convert the reactivity data to a numpy array\nreactivity_array = reactivity_data.values\n\n# Create a heatmap\nplt.figure(figsize=(10, 8))\nsns.heatmap(reactivity_array, cmap='viridis', cbar=True, xticklabels=20, yticklabels=False)\nplt.xlabel('Position', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Sample', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.title('Reactivity Heatmap (First 50 Columns)', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\n\n# Save the plot\nplt.savefig('Reactivity Heatmap (First 50 Columns).png')\n\n# Show the plot\nplt.show()","metadata":{"papermill":{"duration":93.639239,"end_time":"2023-10-12T12:21:34.546533","exception":false,"start_time":"2023-10-12T12:20:00.907294","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:48:06.511624Z","iopub.execute_input":"2023-10-25T08:48:06.512205Z","iopub.status.idle":"2023-10-25T08:50:49.006184Z","shell.execute_reply.started":"2023-10-25T08:48:06.512147Z","shell.execute_reply":"2023-10-25T08:50:49.004285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_reactivity = reactivity_data.mean(axis=0)\nstd_reactivity = reactivity_data.std(axis=0)\n\nx = np.arange(len(mean_reactivity))\nplt.errorbar(x, mean_reactivity, yerr=std_reactivity, fmt='o')\nplt.xlabel('Position', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Mean Reactivity', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.title('Reactivity with Error Bars', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\n\n# Save the plot\nplt.savefig('Reactivity with Error Bars.png')\n\n# Show the plot\nplt.show()\n","metadata":{"papermill":{"duration":1.117792,"end_time":"2023-10-12T12:21:35.674461","exception":false,"start_time":"2023-10-12T12:21:34.556669","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:53:13.752379Z","iopub.execute_input":"2023-10-25T08:53:13.753449Z","iopub.status.idle":"2023-10-25T08:53:16.250978Z","shell.execute_reply.started":"2023-10-25T08:53:13.753368Z","shell.execute_reply":"2023-10-25T08:53:16.249204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mean_reactivity = reactivity_data.mean(axis=0)\nstd_reactivity = reactivity_data.std(axis=0)\n\nx = np.arange(len(mean_reactivity))\nplt.errorbar(x, mean_reactivity, yerr=std_reactivity, fmt='o')\nplt.xlabel('Position', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Mean Reactivity', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.title('Reactivity with Error Bars', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\n\n# Save the plot\nplt.savefig('Reactivity with Error Bars.png')\n\n# Show the plot\nplt.show()","metadata":{"papermill":{"duration":1.045416,"end_time":"2023-10-12T12:21:36.735881","exception":false,"start_time":"2023-10-12T12:21:35.690465","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:53:22.572235Z","iopub.execute_input":"2023-10-25T08:53:22.572911Z","iopub.status.idle":"2023-10-25T08:53:25.078813Z","shell.execute_reply.started":"2023-10-25T08:53:22.572856Z","shell.execute_reply":"2023-10-25T08:53:25.077463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def sensitivity(true_positives, false_negatives):\n    return true_positives / (true_positives + false_negatives)\n\ntrue_positives = 100  \nfalse_negatives = 20  \n\nprint(f\"True Positives: {true_positives}\")\nprint(f\"False Negatives: {false_negatives}\")\n\nsensitivity_score = sensitivity(true_positives, false_negatives)\nprint(f\"Sensitivity: {sensitivity_score}\")","metadata":{"papermill":{"duration":0.020583,"end_time":"2023-10-12T12:21:36.766861","exception":false,"start_time":"2023-10-12T12:21:36.746278","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:53:31.653906Z","iopub.execute_input":"2023-10-25T08:53:31.654375Z","iopub.status.idle":"2023-10-25T08:53:31.665502Z","shell.execute_reply.started":"2023-10-25T08:53:31.654339Z","shell.execute_reply":"2023-10-25T08:53:31.663816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def ppv(true_positives, false_positives):\n    return true_positives / (true_positives + false_positives)\n\ntrue_positives = 100  \nfalse_positives = 30  \n\nppv_score = ppv(true_positives, false_positives)\nprint(f\"Positive Predictive Value (PPV): {ppv_score}\")","metadata":{"papermill":{"duration":0.020373,"end_time":"2023-10-12T12:21:36.798464","exception":false,"start_time":"2023-10-12T12:21:36.778091","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:53:38.419761Z","iopub.execute_input":"2023-10-25T08:53:38.424038Z","iopub.status.idle":"2023-10-25T08:53:38.433530Z","shell.execute_reply.started":"2023-10-25T08:53:38.423975Z","shell.execute_reply":"2023-10-25T08:53:38.432190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def mcc(true_positives, true_negatives, false_positives, false_negatives):\n    numerator = (true_positives * true_negatives) - (false_positives * false_negatives)\n    denominator = ((true_positives + false_positives) * (true_positives + false_negatives) * \n                   (true_negatives + false_positives) * (true_negatives + false_negatives)) ** 0.5\n    return numerator / denominator if denominator != 0 else 0\n\n\ntrue_positives = 100  \ntrue_negatives = 50   \nfalse_positives = 30  \nfalse_negatives = 20  \n\nmcc_score = mcc(true_positives, true_negatives, false_positives, false_negatives)\nprint(f\"Matthews Correlation Coefficient (MCC): {mcc_score}\")\n","metadata":{"papermill":{"duration":0.019583,"end_time":"2023-10-12T12:21:36.828919","exception":false,"start_time":"2023-10-12T12:21:36.809336","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:53:45.871045Z","iopub.execute_input":"2023-10-25T08:53:45.871545Z","iopub.status.idle":"2023-10-25T08:53:45.881982Z","shell.execute_reply.started":"2023-10-25T08:53:45.871505Z","shell.execute_reply":"2023-10-25T08:53:45.879886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def f_measure(true_positives, false_positives, false_negatives):\n    precision = ppv(true_positives, false_positives)\n    recall = sensitivity(true_positives, false_negatives)\n    return 2 * (precision * recall) / (precision + recall) if (precision + recall) != 0 else 0\n\ntrue_positives = 100  \nfalse_positives = 30  \nfalse_negatives = 20  \n\nf_measure_score = f_measure(true_positives, false_positives, false_negatives)\nprint(f\"F-measure (F1 Score): {f_measure_score}\")","metadata":{"papermill":{"duration":0.017739,"end_time":"2023-10-12T12:21:36.857207","exception":false,"start_time":"2023-10-12T12:21:36.839468","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:53:51.679342Z","iopub.execute_input":"2023-10-25T08:53:51.679845Z","iopub.status.idle":"2023-10-25T08:53:51.691399Z","shell.execute_reply.started":"2023-10-25T08:53:51.679799Z","shell.execute_reply":"2023-10-25T08:53:51.689898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%capture\n%pip install arnie","metadata":{"papermill":{"duration":9.061231,"end_time":"2023-10-12T12:21:45.930123","exception":false,"start_time":"2023-10-12T12:21:36.868892","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:55:46.852994Z","iopub.execute_input":"2023-10-25T08:55:46.853592Z","iopub.status.idle":"2023-10-25T08:56:02.556776Z","shell.execute_reply.started":"2023-10-25T08:55:46.853548Z","shell.execute_reply":"2023-10-25T08:56:02.554797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%capture\n%pip install draw_rna","metadata":{"papermill":{"duration":7.72196,"end_time":"2023-10-12T12:21:53.662914","exception":false,"start_time":"2023-10-12T12:21:45.940954","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:56:11.581934Z","iopub.execute_input":"2023-10-25T08:56:11.582433Z","iopub.status.idle":"2023-10-25T08:56:27.724860Z","shell.execute_reply.started":"2023-10-25T08:56:11.582396Z","shell.execute_reply":"2023-10-25T08:56:27.723139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# install eternafold\n!conda config --set auto_update_conda false\n!conda install -c bioconda eternafold --yes","metadata":{"papermill":{"duration":86.118243,"end_time":"2023-10-12T12:23:19.791486","exception":false,"start_time":"2023-10-12T12:21:53.673243","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T08:56:31.649113Z","iopub.execute_input":"2023-10-25T08:56:31.649847Z","iopub.status.idle":"2023-10-25T08:59:37.211714Z","shell.execute_reply.started":"2023-10-25T08:56:31.649792Z","shell.execute_reply":"2023-10-25T08:59:37.209893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":{"papermill":{"duration":0.033407,"end_time":"2023-10-12T12:23:19.849326","exception":false,"start_time":"2023-10-12T12:23:19.815919","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:00:33.099490Z","iopub.execute_input":"2023-10-25T09:00:33.099996Z","iopub.status.idle":"2023-10-25T09:00:33.111785Z","shell.execute_reply.started":"2023-10-25T09:00:33.099957Z","shell.execute_reply":"2023-10-25T09:00:33.110246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#  df is your DataFrame\nsequences = df['sequence'].tolist()\nsequences","metadata":{"papermill":{"duration":0.127951,"end_time":"2023-10-12T12:23:20.001943","exception":false,"start_time":"2023-10-12T12:23:19.873992","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:00:41.907020Z","iopub.execute_input":"2023-10-25T09:00:41.907504Z","iopub.status.idle":"2023-10-25T09:00:42.831030Z","shell.execute_reply.started":"2023-10-25T09:00:41.907465Z","shell.execute_reply":"2023-10-25T09:00:42.829653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from arnie.mfe import mfe\nsequence =\"GGGAACGACUCGAGUAGAGUCGAAAACGUACGUGGAGACACGUACGACGAGACUUCGGUCUCGAAUAGCUCGAACCGGUGCCGAGCGCGCACGAGGCGUCGGUGGUCGGCGAGCCCACGGACGCAAAAACUCGUGCGUAAAUAAAUAGCAUUGGAAGUGACGUCGACCGUUCGCGGUCGACGUCACAAAAGAAACAACAACAACAAC\"\nstructure = mfe(sequence,package=\"eternafold\")\nprint(structure)","metadata":{"papermill":{"duration":0.137602,"end_time":"2023-10-12T12:23:20.165891","exception":false,"start_time":"2023-10-12T12:23:20.028289","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:01:01.315193Z","iopub.execute_input":"2023-10-25T09:01:01.316727Z","iopub.status.idle":"2023-10-25T09:01:01.504670Z","shell.execute_reply.started":"2023-10-25T09:01:01.316672Z","shell.execute_reply":"2023-10-25T09:01:01.503262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from draw_rna.ipynb_draw import draw_struct\ndraw_struct(sequence, structure)","metadata":{"papermill":{"duration":1.784867,"end_time":"2023-10-12T12:23:21.976886","exception":false,"start_time":"2023-10-12T12:23:20.192019","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:01:11.530758Z","iopub.execute_input":"2023-10-25T09:01:11.531653Z","iopub.status.idle":"2023-10-25T09:01:15.317562Z","shell.execute_reply.started":"2023-10-25T09:01:11.531606Z","shell.execute_reply":"2023-10-25T09:01:15.316178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from arnie.mfe import mfe\nsequence = \"GGGAACGACTCGAGTAGAGTCGAAAAATAAGAGTGATTGGCGTCCGTACGTACCCTTTCTACTCTCAAACTCTTGTTAGTTTAAATCTAATCTAAACTTTATAAACGGCACTTCCTGTGTGTCCATGCCCGTGGGCTTGGTCTTGTCATAGTGCTGACATTTGTGGTTCCTTGGTTTTTGTTCTCTGCCAGTGACGTGTCCATTCGGCGCCAGCAGCCCACCCATAGGTTGCATAATGGCAAAGATGGGCAAATACGGTCTCGGCTTCAAATGGGCCCCAGAATTTCCATGGATGCTTCCGAACGCATCGGAGAAGTTGGGTAGCCCTGAGAGGTCAGAGGAGGATGGGTTTTGCCCCTCTGCTGCGCAAGAACCAAAAACTAAAGGAAAAACTTTGATTAATCACGTGAGGGTGGGGATCCTGTTCGCAGGATCCAAAAGAAACAACAACAACAAC\"\nstructure = mfe(sequence,package=\"eternafold\")\nprint(structure)","metadata":{"papermill":{"duration":0.891489,"end_time":"2023-10-12T12:23:22.895761","exception":false,"start_time":"2023-10-12T12:23:22.004272","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:01:25.343736Z","iopub.execute_input":"2023-10-25T09:01:25.344247Z","iopub.status.idle":"2023-10-25T09:01:26.578837Z","shell.execute_reply.started":"2023-10-25T09:01:25.344202Z","shell.execute_reply":"2023-10-25T09:01:26.577202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from draw_rna.ipynb_draw import draw_struct\ndraw_struct(sequence, structure)","metadata":{"papermill":{"duration":4.135818,"end_time":"2023-10-12T12:23:27.062461","exception":false,"start_time":"2023-10-12T12:23:22.926643","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:01:34.332368Z","iopub.execute_input":"2023-10-25T09:01:34.332825Z","iopub.status.idle":"2023-10-25T09:01:42.575675Z","shell.execute_reply.started":"2023-10-25T09:01:34.332790Z","shell.execute_reply":"2023-10-25T09:01:42.573791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from arnie.bpps import bpps\nbpps(sequence,package=\"eternafold\")","metadata":{"papermill":{"duration":0.898296,"end_time":"2023-10-12T12:23:27.991629","exception":false,"start_time":"2023-10-12T12:23:27.093333","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:01:52.356442Z","iopub.execute_input":"2023-10-25T09:01:52.356877Z","iopub.status.idle":"2023-10-25T09:01:53.650879Z","shell.execute_reply.started":"2023-10-25T09:01:52.356842Z","shell.execute_reply":"2023-10-25T09:01:53.649433Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Example of saving BPPs to a CSV file\nimport pandas as pd\n\nbpps_data = bpps(sequence, package=\"eternafold\")\nbpps_df = pd.DataFrame(bpps_data)\nbpps_df.to_csv('bpps_data.csv')","metadata":{"papermill":{"duration":0.996218,"end_time":"2023-10-12T12:23:29.018696","exception":false,"start_time":"2023-10-12T12:23:28.022478","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:02:00.214618Z","iopub.execute_input":"2023-10-25T09:02:00.215502Z","iopub.status.idle":"2023-10-25T09:02:01.706614Z","shell.execute_reply.started":"2023-10-25T09:02:00.215456Z","shell.execute_reply":"2023-10-25T09:02:01.705152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"\nThis script calculates base pair probabilities (BPPs) for a given RNA sequence.\n\"\"\"\n\nfrom arnie.bpps import bpps\n\ndef calculate_bpps(sequence):\n    \"\"\"\n    Calculate BPPs for a given RNA sequence.\n    \n    Args:\n        sequence (str): The RNA sequence.\n        \n    Returns:\n        dict: A dictionary containing BPPs.\n    \"\"\"\n    return bpps(sequence, package=\"eternafold\")\n\n# Usage\nbpps_data = calculate_bpps(sequence)\n\nbpps_data\n","metadata":{"papermill":{"duration":0.876674,"end_time":"2023-10-12T12:23:29.926387","exception":false,"start_time":"2023-10-12T12:23:29.049713","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:02:08.827897Z","iopub.execute_input":"2023-10-25T09:02:08.828348Z","iopub.status.idle":"2023-10-25T09:02:10.130423Z","shell.execute_reply.started":"2023-10-25T09:02:08.828310Z","shell.execute_reply":"2023-10-25T09:02:10.128856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Drop columns with NaN values (if any)\nbpps_df_cleaned = bpps_df.dropna(axis=1, how='any')\n\n# Calculate Mean BPPs for Each Position\nmean_bpps = bpps_df_cleaned.mean()\n\n# Plot Mean BPPs\nplt.figure(figsize=(10, 6))\nplt.plot(mean_bpps)\nplt.title('Mean Base Pair Probabilities', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\nplt.xlabel('Position', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Mean BPP', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.savefig('Mean Base Pair Probabilities.png')\nplt.show()\n\n# Calculate Total BPP for Each Sequence\ntotal_bpps = bpps_df_cleaned.sum(axis=1)\n\n# 4. Plot Total BPP Distribution\nplt.figure(figsize=(10, 6))\nplt.hist(total_bpps, bins=30, color='skyblue', edgecolor='black')\nplt.title('Total Base Pair Probabilities Distribution', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\nplt.xlabel('Total BPP', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Frequency', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.savefig('Total Base Pair Probabilities Distribution.png')\nplt.show()\n\n\n# Visualize BPPs Heatmap for a Few Sequences\nsample_sequences = bpps_df.sample(n=5, random_state=42)\n\nplt.figure(figsize=(10, 6))\nplt.imshow(sample_sequences.values, cmap='viridis', aspect='auto')\nplt.colorbar(label='BPP')\nplt.title('Base Pair Probabilities Heatmap', fontsize = 14, fontweight = 'bold', color = 'darkgreen')\nplt.xlabel('Position', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.ylabel('Sample Sequence', fontsize = 12, fontweight = 'bold', color = 'darkblue')\nplt.savefig('Base Pair Probabilities Heatmap.png')\nplt.show()","metadata":{"papermill":{"duration":1.009723,"end_time":"2023-10-12T12:23:30.968319","exception":false,"start_time":"2023-10-12T12:23:29.958596","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:02:18.045747Z","iopub.execute_input":"2023-10-25T09:02:18.046335Z","iopub.status.idle":"2023-10-25T09:02:20.091738Z","shell.execute_reply.started":"2023-10-25T09:02:18.046290Z","shell.execute_reply":"2023-10-25T09:02:20.090271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.graph_objects as go\n\n# Define the performance measures\nlabels = ['Sensitivity', 'Positive Predictive Value (PPV)', 'Matthews Correlation Coefficient (MCC)', 'F-measure (F1 Score)']\nscores = [sensitivity_score, ppv_score, mcc_score, f_measure_score]\n\n# Create a horizontal bar plot\nfig = go.Figure(data=[go.Bar(\n    y=labels,\n    x=scores,\n    orientation='h',\n    marker=dict(color=['blue', 'green', 'red', 'purple'])\n)])\n\nfig.update_layout(\n    title='Performance Measures',\n    xaxis_title='Score',\n    yaxis_title='Metric',\n    yaxis=dict(autorange='reversed')\n)\n\nfig.show()","metadata":{"papermill":{"duration":0.387414,"end_time":"2023-10-12T12:23:31.389485","exception":false,"start_time":"2023-10-12T12:23:31.002071","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:02:29.849406Z","iopub.execute_input":"2023-10-25T09:02:29.850321Z","iopub.status.idle":"2023-10-25T09:02:30.679320Z","shell.execute_reply.started":"2023-10-25T09:02:29.850271Z","shell.execute_reply":"2023-10-25T09:02:30.678049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_data = pd.read_csv('/kaggle/input/stanford-ribonanza-rna-folding/sample_submission.csv')\nsubmission_data.head()","metadata":{"papermill":{"duration":66.17221,"end_time":"2023-10-12T12:24:37.596833","exception":false,"start_time":"2023-10-12T12:23:31.424623","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:02:41.788893Z","iopub.execute_input":"2023-10-25T09:02:41.790613Z","iopub.status.idle":"2023-10-25T09:04:36.001644Z","shell.execute_reply.started":"2023-10-25T09:02:41.790562Z","shell.execute_reply":"2023-10-25T09:04:36.000283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.DataFrame(submission_data)\n\n# Save the DataFrame to a CSV file\nsubmission_df.to_csv('submission.csv', index=False)","metadata":{"papermill":{"duration":237.081897,"end_time":"2023-10-12T12:28:34.720269","exception":false,"start_time":"2023-10-12T12:24:37.638372","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:05:37.600294Z","iopub.execute_input":"2023-10-25T09:05:37.600761Z","iopub.status.idle":"2023-10-25T09:17:34.079586Z","shell.execute_reply.started":"2023-10-25T09:05:37.600725Z","shell.execute_reply":"2023-10-25T09:17:34.077737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df","metadata":{"papermill":{"duration":0.051788,"end_time":"2023-10-12T12:28:34.808299","exception":false,"start_time":"2023-10-12T12:28:34.756511","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-10-25T09:37:14.699814Z","iopub.execute_input":"2023-10-25T09:37:14.700579Z","iopub.status.idle":"2023-10-25T09:37:14.744576Z","shell.execute_reply.started":"2023-10-25T09:37:14.700523Z","shell.execute_reply":"2023-10-25T09:37:14.742647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.032629,"end_time":"2023-10-12T12:28:34.874557","exception":false,"start_time":"2023-10-12T12:28:34.841928","status":"completed"},"tags":[]},"execution_count":null,"outputs":[]}]}