{"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,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# 📋Table of Contents\n* [Train Data Exploration](#train)\n* [Validation Data Exploration](#valid)\n* [Examples](#examples)","metadata":{}},{"cell_type":"code","source":"# packages\n\n# standard\nimport numpy as np\nimport pandas as pd\nimport time\n\n# plots\nimport matplotlib.pyplot as plt\nimport plotly.express as px\nimport seaborn as sns\n\n# warning handling\nimport warnings\nwarnings.filterwarnings('ignore', category=FutureWarning)\nwarnings.filterwarnings('ignore', category=RuntimeWarning)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:54:03.492808Z","iopub.execute_input":"2025-03-22T09:54:03.493213Z","iopub.status.idle":"2025-03-22T09:54:03.499354Z","shell.execute_reply.started":"2025-03-22T09:54:03.493175Z","shell.execute_reply":"2025-03-22T09:54:03.498128Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# configs\npd.set_option('display.max_columns', 100)\npd.set_option('display.max_rows', 150)\n\ndefault_color_1 = 'darkblue'\ndefault_color_2 = 'darkgreen'\ndefault_color_3 = 'darkred'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:54:17.409799Z","iopub.execute_input":"2025-03-22T09:54:17.410234Z","iopub.status.idle":"2025-03-22T09:54:17.415150Z","shell.execute_reply.started":"2025-03-22T09:54:17.410189Z","shell.execute_reply":"2025-03-22T09:54:17.413905Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# show files\n!ls -l '../input/stanford-rna-3d-folding'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:54:20.939242Z","iopub.execute_input":"2025-03-22T09:54:20.939581Z","iopub.status.idle":"2025-03-22T09:54:21.077598Z","shell.execute_reply.started":"2025-03-22T09:54:20.939546Z","shell.execute_reply":"2025-03-22T09:54:21.076239Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# load train and validation data\ndf_train = pd.read_csv('../input/stanford-rna-3d-folding/train_labels.csv')\ndf_valid = pd.read_csv('../input/stanford-rna-3d-folding/validation_labels.csv')\n\ndf_train_seq = pd.read_csv('../input/stanford-rna-3d-folding/train_sequences.csv')\ndf_valid_seq = pd.read_csv('../input/stanford-rna-3d-folding/validation_sequences.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:54:23.863166Z","iopub.execute_input":"2025-03-22T09:54:23.863545Z","iopub.status.idle":"2025-03-22T09:54:24.291951Z","shell.execute_reply.started":"2025-03-22T09:54:23.863517Z","shell.execute_reply":"2025-03-22T09:54:24.290839Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id='train'></a>\n# Train Data Exploration","metadata":{}},{"cell_type":"code","source":"# first glance\ndf_train.head(12)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:54:32.882878Z","iopub.execute_input":"2025-03-22T09:54:32.883320Z","iopub.status.idle":"2025-03-22T09:54:32.914950Z","shell.execute_reply.started":"2025-03-22T09:54:32.883289Z","shell.execute_reply":"2025-03-22T09:54:32.913682Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# aux function for id extraction\ndef extract_seq_id(s):\n    split = s.split('_')\n    n = len(split)\n    if n==3:\n        result = split[0] + '_' + split[1]\n    else:\n        result = split[0]\n    return result","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:00.372296Z","iopub.execute_input":"2025-03-22T09:55:00.372740Z","iopub.status.idle":"2025-03-22T09:55:00.379446Z","shell.execute_reply.started":"2025-03-22T09:55:00.372701Z","shell.execute_reply":"2025-03-22T09:55:00.378208Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# add sequence id removing the numbers at the end of the id\ndf_train['id_seq'] = df_train.ID.apply(extract_seq_id)\ndf_valid['id_seq'] = df_valid.ID.apply(extract_seq_id)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:01.440194Z","iopub.execute_input":"2025-03-22T09:55:01.440545Z","iopub.status.idle":"2025-03-22T09:55:01.543510Z","shell.execute_reply.started":"2025-03-22T09:55:01.440518Z","shell.execute_reply":"2025-03-22T09:55:01.542409Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# structure of data frame\ndf_train.info(verbose=True, show_counts=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:03.192900Z","iopub.execute_input":"2025-03-22T09:55:03.193296Z","iopub.status.idle":"2025-03-22T09:55:03.249289Z","shell.execute_reply.started":"2025-03-22T09:55:03.193255Z","shell.execute_reply":"2025-03-22T09:55:03.248171Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# show stats\ndf_train.describe(include='all').transpose()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:04.976621Z","iopub.execute_input":"2025-03-22T09:55:04.976994Z","iopub.status.idle":"2025-03-22T09:55:05.262168Z","shell.execute_reply.started":"2025-03-22T09:55:04.976964Z","shell.execute_reply":"2025-03-22T09:55:05.261123Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# stats for \"resname\"\ndf_train.resname.value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:15.853647Z","iopub.execute_input":"2025-03-22T09:55:15.853995Z","iopub.status.idle":"2025-03-22T09:55:15.869511Z","shell.execute_reply.started":"2025-03-22T09:55:15.853967Z","shell.execute_reply":"2025-03-22T09:55:15.868252Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### Let's quickly have a look on the data with the non-GCAU names:","metadata":{}},{"cell_type":"code","source":"df_train[df_train.resname=='-']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:18.096351Z","iopub.execute_input":"2025-03-22T09:55:18.096710Z","iopub.status.idle":"2025-03-22T09:55:18.123992Z","shell.execute_reply.started":"2025-03-22T09:55:18.096681Z","shell.execute_reply":"2025-03-22T09:55:18.122826Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train[df_train.resname=='X']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:22.041352Z","iopub.execute_input":"2025-03-22T09:55:22.041723Z","iopub.status.idle":"2025-03-22T09:55:22.066343Z","shell.execute_reply.started":"2025-03-22T09:55:22.041694Z","shell.execute_reply":"2025-03-22T09:55:22.065153Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# stats for \"resid\" - show top 25\ndf_train.resid.value_counts()[0:25]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:25.669807Z","iopub.execute_input":"2025-03-22T09:55:25.670188Z","iopub.status.idle":"2025-03-22T09:55:25.682340Z","shell.execute_reply.started":"2025-03-22T09:55:25.670157Z","shell.execute_reply":"2025-03-22T09:55:25.681192Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# plot as histogram\ndf_train.resid.plot(kind='hist', bins=100, color=default_color_1)\nplt.title('resid counts')\nplt.grid()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:29.324883Z","iopub.execute_input":"2025-03-22T09:55:29.325291Z","iopub.status.idle":"2025-03-22T09:55:29.816705Z","shell.execute_reply.started":"2025-03-22T09:55:29.325260Z","shell.execute_reply":"2025-03-22T09:55:29.815614Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# stats for sequence is - show top 25\ndf_train.id_seq.value_counts()[0:25]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:32.429514Z","iopub.execute_input":"2025-03-22T09:55:32.429901Z","iopub.status.idle":"2025-03-22T09:55:32.449461Z","shell.execute_reply.started":"2025-03-22T09:55:32.429872Z","shell.execute_reply":"2025-03-22T09:55:32.448353Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# visualize coordinates\nsns.pairplot(data=df_train[['x_1', 'y_1', 'z_1']],\n             diag_kws = {'color' : default_color_1},\n             plot_kws = {'s' : 1, \n                         'alpha' : 0.25,\n                         'color' : default_color_1})\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:37.060585Z","iopub.execute_input":"2025-03-22T09:55:37.060942Z","iopub.status.idle":"2025-03-22T09:55:40.853323Z","shell.execute_reply.started":"2025-03-22T09:55:37.060916Z","shell.execute_reply":"2025-03-22T09:55:40.852206Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# sequence table\ndf_train_seq.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:45.501610Z","iopub.execute_input":"2025-03-22T09:55:45.501967Z","iopub.status.idle":"2025-03-22T09:55:45.513086Z","shell.execute_reply.started":"2025-03-22T09:55:45.501940Z","shell.execute_reply":"2025-03-22T09:55:45.512024Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id='valid'></a>\n# Validation Data Exploration","metadata":{}},{"cell_type":"code","source":"# first glance\ndf_valid.head(12)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:56.163572Z","iopub.execute_input":"2025-03-22T09:55:56.163920Z","iopub.status.idle":"2025-03-22T09:55:56.342195Z","shell.execute_reply.started":"2025-03-22T09:55:56.163893Z","shell.execute_reply":"2025-03-22T09:55:56.340920Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# replace extreme values that encode missings by NaN\ndf_valid.replace(to_replace=-1E18, value=np.nan, inplace=True);","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:55:58.356833Z","iopub.execute_input":"2025-03-22T09:55:58.357265Z","iopub.status.idle":"2025-03-22T09:55:58.364833Z","shell.execute_reply.started":"2025-03-22T09:55:58.357234Z","shell.execute_reply":"2025-03-22T09:55:58.363599Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# structure of data frame\ndf_valid.info(verbose=True, show_counts=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:56:24.955015Z","iopub.execute_input":"2025-03-22T09:56:24.955427Z","iopub.status.idle":"2025-03-22T09:56:24.970606Z","shell.execute_reply.started":"2025-03-22T09:56:24.955396Z","shell.execute_reply":"2025-03-22T09:56:24.969334Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# show stats\ndf_valid.describe(include='all').transpose()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:56:29.113667Z","iopub.execute_input":"2025-03-22T09:56:29.114033Z","iopub.status.idle":"2025-03-22T09:56:29.344326Z","shell.execute_reply.started":"2025-03-22T09:56:29.114005Z","shell.execute_reply":"2025-03-22T09:56:29.343249Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# visualize first coordinates\nsns.pairplot(data = df_valid[['x_1', 'y_1', 'z_1']],\n             diag_kws = {'color' : default_color_1},\n             plot_kws = {'s' : 5, \n                         'alpha' : 0.5,\n                         'color' : default_color_1})\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:56:34.384166Z","iopub.execute_input":"2025-03-22T09:56:34.384542Z","iopub.status.idle":"2025-03-22T09:56:36.611732Z","shell.execute_reply.started":"2025-03-22T09:56:34.384515Z","shell.execute_reply":"2025-03-22T09:56:36.610521Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# visualize coordinates - plot the resname via color encoding\nsns.pairplot(data=df_valid[['x_1', 'y_1', 'z_1', 'resname']],\n             hue = 'resname',\n             diag_kws = {'color' : default_color_1},\n             plot_kws = {'s' : 5, \n                         'alpha' : 0.5,\n                         'color' : default_color_1})\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:56:39.041400Z","iopub.execute_input":"2025-03-22T09:56:39.041781Z","iopub.status.idle":"2025-03-22T09:56:42.994431Z","shell.execute_reply.started":"2025-03-22T09:56:39.041751Z","shell.execute_reply":"2025-03-22T09:56:42.993206Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# visualize second coordinates\nsns.pairplot(data = df_valid[['x_2', 'y_2', 'z_2']],\n             diag_kws = {'color' : default_color_1},\n             plot_kws = {'s' : 5, \n                         'alpha' : 0.5,\n                         'color' : default_color_1})\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:56:52.232971Z","iopub.execute_input":"2025-03-22T09:56:52.233415Z","iopub.status.idle":"2025-03-22T09:56:54.522346Z","shell.execute_reply.started":"2025-03-22T09:56:52.233383Z","shell.execute_reply":"2025-03-22T09:56:54.521196Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# visualize third coordinates\nsns.pairplot(data = df_valid[['x_3', 'y_3', 'z_3']],\n             diag_kws = {'color' : default_color_1},\n             plot_kws = {'s' : 5, \n                         'alpha' : 0.5,\n                         'color' : default_color_1})\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:56:54.970294Z","iopub.execute_input":"2025-03-22T09:56:54.970636Z","iopub.status.idle":"2025-03-22T09:56:57.588792Z","shell.execute_reply.started":"2025-03-22T09:56:54.970610Z","shell.execute_reply":"2025-03-22T09:56:57.587356Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# sequence table\ndf_valid_seq.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:56:59.302894Z","iopub.execute_input":"2025-03-22T09:56:59.303316Z","iopub.status.idle":"2025-03-22T09:56:59.315034Z","shell.execute_reply.started":"2025-03-22T09:56:59.303282Z","shell.execute_reply":"2025-03-22T09:56:59.313913Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"<a id='examples'></a>\n# Examples","metadata":{}},{"cell_type":"code","source":"# function for 3d plotting\ndef create_plots(i_df, i_title, i_varx='x_1', i_vary='y_1', i_varz='z_1'):\n    \n    # 1st plot colored by resname\n    sns.pairplot(data=i_df[[i_varx, i_vary, i_varz, 'resname']],\n                 hue = 'resname',\n                 diag_kws = {'color' : default_color_1},\n                 plot_kws = {'s' : 25, \n                             'alpha' : 1,\n                             'color' : default_color_1}).fig.suptitle(i_title, y=1.05)\n    plt.show()\n\n    # 2nd plot colored by resid\n    sns.pairplot(data=i_df[[i_varx, i_vary, i_varz, 'resid']],\n                 hue = 'resid',             \n                 diag_kws = {'color' : default_color_1},\n                 plot_kws = {'s' : 25, \n                             'alpha' : 1,\n                             'color' : default_color_1})\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:57:01.850878Z","iopub.execute_input":"2025-03-22T09:57:01.851271Z","iopub.status.idle":"2025-03-22T09:57:01.858048Z","shell.execute_reply.started":"2025-03-22T09:57:01.851241Z","shell.execute_reply":"2025-03-22T09:57:01.856882Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## From Training Data","metadata":{}},{"cell_type":"code","source":"# pick an example\nmy_id = '1SCL_A'\ndf_ex = df_train[df_train.id_seq == my_id].copy()\ndf_ex","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:57:04.429731Z","iopub.execute_input":"2025-03-22T09:57:04.430080Z","iopub.status.idle":"2025-03-22T09:57:04.460562Z","shell.execute_reply.started":"2025-03-22T09:57:04.430052Z","shell.execute_reply":"2025-03-22T09:57:04.459376Z"},"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# corresponding sequence / description\ndf_temp = df_train_seq[df_train_seq.target_id==my_id].reset_index(drop=True)\nmy_desc = df_temp.description[0]\nprint(my_desc)\nmy_seq = df_temp.sequence[0]\nprint(my_seq)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:57:07.557612Z","iopub.execute_input":"2025-03-22T09:57:07.557939Z","iopub.status.idle":"2025-03-22T09:57:07.565367Z","shell.execute_reply.started":"2025-03-22T09:57:07.557914Z","shell.execute_reply":"2025-03-22T09:57:07.564017Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"create_plots(df_ex, i_title = my_id + ' - ' + my_seq)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:57:09.598326Z","iopub.execute_input":"2025-03-22T09:57:09.598684Z","iopub.status.idle":"2025-03-22T09:57:16.335846Z","shell.execute_reply.started":"2025-03-22T09:57:09.598658Z","shell.execute_reply":"2025-03-22T09:57:16.334563Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# another - very complex - example\nmy_id = '4V6X_A5'\ndf_ex = df_train[df_train.id_seq == my_id].copy()\ndf_ex","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:57:16.337508Z","iopub.execute_input":"2025-03-22T09:57:16.337822Z","iopub.status.idle":"2025-03-22T09:57:16.366440Z","shell.execute_reply.started":"2025-03-22T09:57:16.337796Z","shell.execute_reply":"2025-03-22T09:57:16.365292Z"},"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# corresponding sequence / description\ndf_temp = df_train_seq[df_train_seq.target_id==my_id].reset_index(drop=True)\nmy_desc = df_temp.description[0]\nprint(my_desc)\nmy_seq = df_temp.sequence[0]\nprint(my_seq)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:57:16.580151Z","iopub.execute_input":"2025-03-22T09:57:16.580554Z","iopub.status.idle":"2025-03-22T09:57:16.588541Z","shell.execute_reply.started":"2025-03-22T09:57:16.580524Z","shell.execute_reply":"2025-03-22T09:57:16.587188Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"create_plots(df_ex, i_title = my_id)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:57:19.186341Z","iopub.execute_input":"2025-03-22T09:57:19.186701Z","iopub.status.idle":"2025-03-22T09:57:35.349371Z","shell.execute_reply.started":"2025-03-22T09:57:19.186671Z","shell.execute_reply":"2025-03-22T09:57:35.348183Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### This is indeed very complex. Let's try an interactive visualization also:","metadata":{}},{"cell_type":"code","source":"# interactive 3d plot using plotly\ndf_ex['size4plot'] = 1 # artificial column to allow size scaling\nfig = px.scatter_3d(df_ex,\n                    x='x_1', y='y_1', z='z_1',\n                    color='resname',\n                    size='size4plot',\n                    size_max=8,\n                    hover_data=['id_seq', 'resid'],\n                    opacity=0.5)\nfig.update_layout(title=my_id)\nfig.show(renderer='iframe')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:57:35.350827Z","iopub.execute_input":"2025-03-22T09:57:35.351199Z","iopub.status.idle":"2025-03-22T09:57:37.879598Z","shell.execute_reply.started":"2025-03-22T09:57:35.351167Z","shell.execute_reply":"2025-03-22T09:57:37.878337Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## From Validation Data","metadata":{}},{"cell_type":"code","source":"# sequences in validation data\ndf_valid.id_seq.value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:58:06.862249Z","iopub.execute_input":"2025-03-22T09:58:06.862639Z","iopub.status.idle":"2025-03-22T09:58:06.871434Z","shell.execute_reply.started":"2025-03-22T09:58:06.862610Z","shell.execute_reply":"2025-03-22T09:58:06.870296Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# pick an example from the validation set with more than one structure\nmy_id = 'R1156'\ndf_ex = df_valid[df_valid.id_seq == my_id]\ndf_ex","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:58:07.685931Z","iopub.execute_input":"2025-03-22T09:58:07.686334Z","iopub.status.idle":"2025-03-22T09:58:08.097448Z","shell.execute_reply.started":"2025-03-22T09:58:07.686304Z","shell.execute_reply":"2025-03-22T09:58:08.095852Z"},"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# corresponding sequence / description\ndf_temp = df_valid_seq[df_valid_seq.target_id==my_id].reset_index(drop=True)\nmy_desc = df_temp.description[0]\nprint(my_desc)\nmy_seq = df_temp.sequence[0]\nprint(my_seq)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:58:16.380528Z","iopub.execute_input":"2025-03-22T09:58:16.380903Z","iopub.status.idle":"2025-03-22T09:58:16.389084Z","shell.execute_reply.started":"2025-03-22T09:58:16.380875Z","shell.execute_reply":"2025-03-22T09:58:16.387884Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# visualize first structure\ncreate_plots(df_ex, my_id + ' - Structure 1', 'x_1', 'y_1', 'z_1')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:58:18.235321Z","iopub.execute_input":"2025-03-22T09:58:18.235673Z","iopub.status.idle":"2025-03-22T09:58:25.233706Z","shell.execute_reply.started":"2025-03-22T09:58:18.235646Z","shell.execute_reply":"2025-03-22T09:58:25.232421Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# visualize second structure\ncreate_plots(df_ex, my_id + ' - Structure 2', 'x_2', 'y_2', 'z_2')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:58:25.235382Z","iopub.execute_input":"2025-03-22T09:58:25.235796Z","iopub.status.idle":"2025-03-22T09:58:32.140346Z","shell.execute_reply.started":"2025-03-22T09:58:25.235755Z","shell.execute_reply":"2025-03-22T09:58:32.139216Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# visualize third structure\ncreate_plots(df_ex, my_id + ' - Structure 3', 'x_3', 'y_3', 'z_3')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:58:32.142241Z","iopub.execute_input":"2025-03-22T09:58:32.142542Z","iopub.status.idle":"2025-03-22T09:58:39.215784Z","shell.execute_reply.started":"2025-03-22T09:58:32.142517Z","shell.execute_reply":"2025-03-22T09:58:39.214488Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# interactive 3d plot using plotly\ndf_ex_temp = df_ex.copy()\ndf_ex_temp['size4plot'] = 1 # artificial column to allow size scaling\nfig = px.scatter_3d(df_ex_temp,\n                    x='x_1', y='y_1', z='z_1',\n                    color='resname',\n                    size='size4plot',\n                    size_max=8,\n                    hover_data=['id_seq', 'resid'],\n                    opacity=0.5)\nfig.update_layout(title=my_id)\nfig.show(renderer='iframe')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:59:20.529428Z","iopub.execute_input":"2025-03-22T09:59:20.529788Z","iopub.status.idle":"2025-03-22T09:59:20.647956Z","shell.execute_reply.started":"2025-03-22T09:59:20.529760Z","shell.execute_reply":"2025-03-22T09:59:20.647051Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Compare structures for same sequence","metadata":{}},{"cell_type":"code","source":"# function for comparing two versions\ndef compare_structures(i_df, i_index_1, i_index_2):\n\n    # copy first structure coordinates in temporary data frame\n    df_A = df_ex[['id_seq', 'resname']].copy()\n    df_A['x'] = df_ex['x_' + str(i_index_1)]\n    df_A['y'] = df_ex['y_' + str(i_index_1)]\n    df_A['z'] = df_ex['z_' + str(i_index_1)]\n    df_A['Structure'] = 'Structure ' + str(i_index_1)\n\n    # copy second structure coordinates in temporary data frame\n    df_B = df_ex[['id_seq', 'resname']].copy()\n    df_B['x'] = df_ex['x_' + str(i_index_2)]\n    df_B['y'] = df_ex['y_' + str(i_index_2)]\n    df_B['z'] = df_ex['z_' + str(i_index_2)]\n    df_B['Structure'] = 'Structure ' + str(i_index_2)\n\n    # concatenate the two data frames\n    df_compare = pd.concat([df_A,df_B])\n\n    # visualize comparison using newly introduced Structure variable\n    sns.pairplot(data = df_compare[['x', 'y', 'z', 'Structure']],\n                 hue = 'Structure',\n                 plot_kws = {'s' : 10, \n                             'alpha' : 1})\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:59:33.836489Z","iopub.execute_input":"2025-03-22T09:59:33.836827Z","iopub.status.idle":"2025-03-22T09:59:33.844497Z","shell.execute_reply.started":"2025-03-22T09:59:33.836797Z","shell.execute_reply":"2025-03-22T09:59:33.843168Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"compare_structures(df_ex, 1, 2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:59:36.848168Z","iopub.execute_input":"2025-03-22T09:59:36.848538Z","iopub.status.idle":"2025-03-22T09:59:39.850149Z","shell.execute_reply.started":"2025-03-22T09:59:36.848509Z","shell.execute_reply":"2025-03-22T09:59:39.849029Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"compare_structures(df_ex, 2, 3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-22T09:59:39.851762Z","iopub.execute_input":"2025-03-22T09:59:39.852186Z","iopub.status.idle":"2025-03-22T09:59:43.092485Z","shell.execute_reply.started":"2025-03-22T09:59:39.852147Z","shell.execute_reply":"2025-03-22T09:59:43.091277Z"}},"outputs":[],"execution_count":null}]}