{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":87793,"databundleVersionId":11228175,"sourceType":"competition"}],"dockerImageVersionId":30919,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:09.489192Z","iopub.execute_input":"2025-03-13T08:09:09.489556Z","iopub.status.idle":"2025-03-13T08:09:09.496537Z","shell.execute_reply.started":"2025-03-13T08:09:09.489519Z","shell.execute_reply":"2025-03-13T08:09:09.495738Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport tensorflow as tf\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.layers import Input, LSTM, Dense, Bidirectional, Dropout, Masking\nfrom tensorflow.keras.optimizers import Adam\nfrom sklearn.preprocessing import OneHotEncoder\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:09.498360Z","iopub.execute_input":"2025-03-13T08:09:09.498665Z","iopub.status.idle":"2025-03-13T08:09:09.510488Z","shell.execute_reply.started":"2025-03-13T08:09:09.498643Z","shell.execute_reply":"2025-03-13T08:09:09.509717Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Загрузка данных\ntrain_seq = pd.read_csv('/kaggle/input/stanford-rna-3d-folding/train_sequences.csv')\ntrain_labels = pd.read_csv('/kaggle/input/stanford-rna-3d-folding/train_labels.csv')\nvalidation_seq = pd.read_csv('/kaggle/input/stanford-rna-3d-folding/validation_sequences.csv')\nvalidation_labels = pd.read_csv('/kaggle/input/stanford-rna-3d-folding/validation_labels.csv')\ntest_seq = pd.read_csv('/kaggle/input/stanford-rna-3d-folding/test_sequences.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:09.511695Z","iopub.execute_input":"2025-03-13T08:09:09.511945Z","iopub.status.idle":"2025-03-13T08:09:09.742105Z","shell.execute_reply.started":"2025-03-13T08:09:09.511918Z","shell.execute_reply":"2025-03-13T08:09:09.741463Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# EDA (Exploratory Data Analysis)\n#1. Sequence Length Analysis\ntrain_seq['sequence_length'] = train_seq['sequence'].apply(len)\nvalidation_seq['sequence_length'] = validation_seq['sequence'].apply(len)\ntest_seq['sequence_length'] = test_seq['sequence'].apply(len)\n\nplt.figure(figsize=(12, 6))\nsns.histplot(train_seq['sequence_length'], bins=50, kde=True, label='Train')\nplt.title('Distribution of Sequence Lengths')\nplt.xlabel('Sequence Length')\nplt.ylabel('Frequency')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:09.742850Z","iopub.execute_input":"2025-03-13T08:09:09.743077Z","iopub.status.idle":"2025-03-13T08:09:10.023442Z","shell.execute_reply.started":"2025-03-13T08:09:09.743058Z","shell.execute_reply":"2025-03-13T08:09:10.022600Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nsns.histplot(validation_seq['sequence_length'], bins=50, kde=True, label='Validation')\nplt.title('Distribution of Sequence Lengths')\nplt.xlabel('Sequence Length')\nplt.ylabel('Frequency')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:29:00.558659Z","iopub.execute_input":"2025-03-12T13:29:00.558923Z","iopub.status.idle":"2025-03-12T13:29:00.927029Z","shell.execute_reply.started":"2025-03-12T13:29:00.558901Z","shell.execute_reply":"2025-03-12T13:29:00.926012Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nsns.histplot(test_seq['sequence_length'], bins=50, kde=True, label='Test')\nplt.title('Distribution of Sequence Lengths')\nplt.xlabel('Sequence Length')\nplt.ylabel('Frequency')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:29:00.929024Z","iopub.execute_input":"2025-03-12T13:29:00.929353Z","iopub.status.idle":"2025-03-12T13:29:01.297482Z","shell.execute_reply.started":"2025-03-12T13:29:00.929327Z","shell.execute_reply":"2025-03-12T13:29:01.296307Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#2. Analysis of the nucleotide distribution\nnucleotides = ['A', 'C', 'G', 'U']\ntrain_nuc_counts = train_seq['sequence'].apply(lambda x: pd.Series([x.count(nuc) for nuc in nucleotides]))\nvalidation_nuc_counts = validation_seq['sequence'].apply(lambda x: pd.Series([x.count(nuc) for nuc in nucleotides]))\ntest_nuc_counts = test_seq['sequence'].apply(lambda x: pd.Series([x.count(nuc) for nuc in nucleotides]))\n\ntrain_nuc_counts.columns = nucleotides\nvalidation_nuc_counts.columns = nucleotides\ntest_nuc_counts.columns = nucleotides","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:10.024307Z","iopub.execute_input":"2025-03-13T08:09:10.024595Z","iopub.status.idle":"2025-03-13T08:09:10.109843Z","shell.execute_reply.started":"2025-03-13T08:09:10.024565Z","shell.execute_reply":"2025-03-13T08:09:10.109039Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\ntrain_nuc_counts.sum().plot(kind='bar', label='Train')\nplt.title('Nucleotide Distribution')\nplt.xlabel('Nucleotide')\nplt.ylabel('Count')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:29:02.987580Z","iopub.execute_input":"2025-03-12T13:29:02.987903Z","iopub.status.idle":"2025-03-12T13:29:03.300245Z","shell.execute_reply.started":"2025-03-12T13:29:02.987879Z","shell.execute_reply":"2025-03-12T13:29:03.298969Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nvalidation_nuc_counts.sum().plot(kind='bar', label='Validation', alpha=0.7)\nplt.title('Nucleotide Distribution')\nplt.xlabel('Nucleotide')\nplt.ylabel('Count')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:29:03.301849Z","iopub.execute_input":"2025-03-12T13:29:03.302237Z","iopub.status.idle":"2025-03-12T13:29:03.557198Z","shell.execute_reply.started":"2025-03-12T13:29:03.302189Z","shell.execute_reply":"2025-03-12T13:29:03.556013Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\ntest_nuc_counts.sum().plot(kind='bar', label='Test', alpha=0.7)\nplt.title('Nucleotide Distribution')\nplt.xlabel('Nucleotide')\nplt.ylabel('Count')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:29:03.559032Z","iopub.execute_input":"2025-03-12T13:29:03.559341Z","iopub.status.idle":"2025-03-12T13:29:03.809117Z","shell.execute_reply.started":"2025-03-12T13:29:03.559315Z","shell.execute_reply":"2025-03-12T13:29:03.807880Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 3. Timestamp Analysis (temporal_cutoff)\ntrain_seq['temporal_cutoff'] = pd.to_datetime(train_seq['temporal_cutoff'])\nvalidation_seq['temporal_cutoff'] = pd.to_datetime(validation_seq['temporal_cutoff'])\ntest_seq['temporal_cutoff'] = pd.to_datetime(test_seq['temporal_cutoff'])\n\nplt.figure(figsize=(12, 6))\nsns.histplot(train_seq['temporal_cutoff'], bins=50, kde=True, label='Train')\nplt.title('Distribution of Temporal Cutoff Dates')\nplt.xlabel('Temporal Cutoff')\nplt.ylabel('Frequency')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:10.110769Z","iopub.execute_input":"2025-03-13T08:09:10.111064Z","iopub.status.idle":"2025-03-13T08:09:10.634882Z","shell.execute_reply.started":"2025-03-13T08:09:10.111030Z","shell.execute_reply":"2025-03-13T08:09:10.634039Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nsns.histplot(validation_seq['temporal_cutoff'], bins=50, kde=True, label='Validation')\nplt.title('Distribution of Temporal Cutoff Dates')\nplt.xlabel('Temporal Cutoff')\nplt.ylabel('Frequency')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:29:04.267525Z","iopub.execute_input":"2025-03-12T13:29:04.267779Z","iopub.status.idle":"2025-03-12T13:29:04.686090Z","shell.execute_reply.started":"2025-03-12T13:29:04.267758Z","shell.execute_reply":"2025-03-12T13:29:04.685031Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12, 6))\nsns.histplot(test_seq['temporal_cutoff'], bins=50, kde=True, label='Test')\nplt.title('Distribution of Temporal Cutoff Dates')\nplt.xlabel('Temporal Cutoff')\nplt.ylabel('Frequency')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:29:05.778563Z","iopub.execute_input":"2025-03-12T13:29:05.778879Z","iopub.status.idle":"2025-03-12T13:29:06.203842Z","shell.execute_reply.started":"2025-03-12T13:29:05.778856Z","shell.execute_reply":"2025-03-12T13:29:06.202678Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Adding missing characters to categories\nnucleotides = ['A', 'C', 'G', 'U', 'N', '-', 'X']\nmax_len = max(\n    train_seq['sequence'].apply(len).max(),\n    validation_seq['sequence'].apply(len).max(),\n    test_seq['sequence'].apply(len).max()\n)\n# OneHotEncoder with consideration of all characters\nencoder = OneHotEncoder(sparse=False, categories=[nucleotides])\nencoder.fit(np.array(nucleotides).reshape(-1, 1))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:10.636283Z","iopub.execute_input":"2025-03-13T08:09:10.636509Z","iopub.status.idle":"2025-03-13T08:09:10.644669Z","shell.execute_reply.started":"2025-03-13T08:09:10.636489Z","shell.execute_reply":"2025-03-13T08:09:10.643865Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Sequence preprocessing function\ndef preprocess_sequences(seq_list, max_len):\n    encoded = []\n    for seq in seq_list:\n        padded = seq.ljust(max_len, 'N')[:max_len]  # Padding to max_len\n        onehot = encoder.transform(np.array(list(padded)).reshape(-1, 1))\n        encoded.append(onehot)\n    return np.array(encoded)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:11.564050Z","iopub.execute_input":"2025-03-13T08:09:11.564349Z","iopub.status.idle":"2025-03-13T08:09:11.568463Z","shell.execute_reply.started":"2025-03-13T08:09:11.564324Z","shell.execute_reply":"2025-03-13T08:09:11.567630Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_seq['sequence']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:13.568589Z","iopub.execute_input":"2025-03-13T08:09:13.568874Z","iopub.status.idle":"2025-03-13T08:09:13.574876Z","shell.execute_reply.started":"2025-03-13T08:09:13.568848Z","shell.execute_reply":"2025-03-13T08:09:13.574106Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Data conversion\nX_train = preprocess_sequences(train_seq['sequence'], max_len)\nX_val = preprocess_sequences(validation_seq['sequence'], max_len)\nX_test = preprocess_sequences(test_seq['sequence'], max_len)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:13.844164Z","iopub.execute_input":"2025-03-13T08:09:13.844522Z","iopub.status.idle":"2025-03-13T08:09:17.023094Z","shell.execute_reply.started":"2025-03-13T08:09:13.844487Z","shell.execute_reply":"2025-03-13T08:09:17.022390Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Fixed align_labels function\ndef align_labels(sequences_df, labels_df, max_len):\n    aligned = []\n    for target_id in sequences_df['target_id']:\n        # Filtering labels for the current target_id\n        target_labels = labels_df[labels_df['ID'].str.startswith(f\"{target_id}_\")]\n        # Sort by balance number\n        target_labels = target_labels.sort_values('resid')\n        # Replace NaN in coordinates with 0 for Masking\n        target_labels[['x_1', 'y_1', 'z_1']] = target_labels[['x_1', 'y_1', 'z_1']].fillna(-1)\n        # Extracting coordinates\n        coords = target_labels[['x_1', 'y_1', 'z_1']].values\n        # Truncate to max_len\n        if len(coords) > max_len:\n            coords = coords[:max_len]\n        padded_coords = np.zeros((max_len, 3))\n        padded_coords[:len(coords)] = coords\n        aligned.append(padded_coords)\n    return np.array(aligned)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:18.966782Z","iopub.execute_input":"2025-03-13T08:09:18.967109Z","iopub.status.idle":"2025-03-13T08:09:18.972386Z","shell.execute_reply.started":"2025-03-13T08:09:18.967080Z","shell.execute_reply":"2025-03-13T08:09:18.971465Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train = align_labels(train_seq, train_labels, max_len)\ny_val = align_labels(validation_seq, validation_labels, max_len)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:21.928376Z","iopub.execute_input":"2025-03-13T08:09:21.928666Z","iopub.status.idle":"2025-03-13T08:09:47.007859Z","shell.execute_reply.started":"2025-03-13T08:09:21.928645Z","shell.execute_reply":"2025-03-13T08:09:47.007178Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Checking the dimensions\nprint(f\"X_train: {X_train.shape}, y_train: {y_train.shape}\")\nprint(f\"X_val: {X_val.shape}, y_val: {y_val.shape}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:47.008895Z","iopub.execute_input":"2025-03-13T08:09:47.009207Z","iopub.status.idle":"2025-03-13T08:09:47.013943Z","shell.execute_reply.started":"2025-03-13T08:09:47.009161Z","shell.execute_reply":"2025-03-13T08:09:47.013216Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Checking for NaN and infinity in data\nprint(\"NaN in X_train:\", np.isnan(X_train).any())\nprint(\"Infinity in X_train:\", np.isinf(X_train).any())\nprint(\"NaN in y_train:\", np.isnan(y_train).any())\nprint(\"Infinity in y_train:\", np.isinf(y_train).any())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:47.015597Z","iopub.execute_input":"2025-03-13T08:09:47.015803Z","iopub.status.idle":"2025-03-13T08:09:47.214254Z","shell.execute_reply.started":"2025-03-13T08:09:47.015785Z","shell.execute_reply":"2025-03-13T08:09:47.213102Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_val.min(), y_val.max()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:47.215677Z","iopub.execute_input":"2025-03-13T08:09:47.216070Z","iopub.status.idle":"2025-03-13T08:09:47.222227Z","shell.execute_reply.started":"2025-03-13T08:09:47.216028Z","shell.execute_reply":"2025-03-13T08:09:47.221481Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_val.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:47.223256Z","iopub.execute_input":"2025-03-13T08:09:47.223574Z","iopub.status.idle":"2025-03-13T08:09:47.234859Z","shell.execute_reply.started":"2025-03-13T08:09:47.223538Z","shell.execute_reply":"2025-03-13T08:09:47.234198Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"count_below_threshold = np.sum(y_val < -1e+4)\nprint(f\"The number of values is less than -10^10: {count_below_threshold}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:47.235504Z","iopub.execute_input":"2025-03-13T08:09:47.235709Z","iopub.status.idle":"2025-03-13T08:09:47.248110Z","shell.execute_reply.started":"2025-03-13T08:09:47.235689Z","shell.execute_reply":"2025-03-13T08:09:47.247361Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"median_value = np.median(y_val[y_val >= -1e+4])\ny_val[y_val < -1e+4] = -1","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:56.151733Z","iopub.execute_input":"2025-03-13T08:09:56.152046Z","iopub.status.idle":"2025-03-13T08:09:56.158433Z","shell.execute_reply.started":"2025-03-13T08:09:56.152020Z","shell.execute_reply":"2025-03-13T08:09:56.157660Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_val.min(), y_val.max()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:09:58.144779Z","iopub.execute_input":"2025-03-13T08:09:58.145073Z","iopub.status.idle":"2025-03-13T08:09:58.150444Z","shell.execute_reply.started":"2025-03-13T08:09:58.145049Z","shell.execute_reply":"2025-03-13T08:09:58.149681Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"'''\n# Normalization of data\nfrom sklearn.preprocessing import StandardScaler\n\n# Scaling the input data (X)\nscaler_X = StandardScaler()\nX_train_flat = X_train.reshape(-1, X_train.shape[-1])\nX_train_scaled_flat = scaler_X.fit_transform(X_train_flat)\nX_train_scaled = X_train_scaled_flat.reshape(X_train.shape)\n\nX_val_flat = X_val.reshape(-1, X_val.shape[-1])\nX_val_scaled_flat = scaler_X.transform(X_val_flat)\nX_val_scaled = X_val_scaled_flat.reshape(X_val.shape)\n\n# Scaling the output (y)\nscaler_y = StandardScaler()\ny_train_flat = y_train.reshape(-1, y_train.shape[-1])\ny_train_scaled_flat = scaler_y.fit_transform(y_train_flat)\ny_train_scaled = y_train_scaled_flat.reshape(y_train.shape)\n\ny_val_flat = y_val.reshape(-1, y_val.shape[-1])\ny_val_scaled_flat = scaler_y.transform(y_val_flat)\ny_val_scaled = y_val_scaled_flat.reshape(y_val.shape)\n'''","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:29:43.002382Z","iopub.execute_input":"2025-03-12T13:29:43.002746Z","iopub.status.idle":"2025-03-12T13:29:44.224838Z","shell.execute_reply.started":"2025-03-12T13:29:43.002719Z","shell.execute_reply":"2025-03-12T13:29:44.223977Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"np.sum(X_train == -1), np.sum(X_val == -1), np.sum(y_train == -1), np.sum(y_val == -1), ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T08:10:03.464888Z","iopub.execute_input":"2025-03-13T08:10:03.465164Z","iopub.status.idle":"2025-03-13T08:10:03.546968Z","shell.execute_reply.started":"2025-03-13T08:10:03.465144Z","shell.execute_reply":"2025-03-13T08:10:03.546254Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Building a model\ninputs = Input(shape=(max_len, len(nucleotides)))\n\nx = Masking(mask_value=-1)(inputs)\nx = Bidirectional(LSTM(128, return_sequences=True))(x)\nx = Dropout(0.1)(x)\nx = Bidirectional(LSTM(64, return_sequences=True))(x)\noutputs = Dense(3)(x)\n\nmodel = Model(inputs, outputs)\nmodel.compile(optimizer=Adam(0.001), loss='mse')\nmodel.summary()\n\n# Model training\nhistory = model.fit(X_train, y_train,\n                    validation_data=(X_val, y_val),\n                    epochs=50,\n                    batch_size=1,\n                    verbose=1)\n\n# Visualization of learning\nplt.plot(history.history['loss'], label='Train Loss')\nplt.plot(history.history['val_loss'], label='Validation Loss')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-13T09:52:46.893313Z","iopub.execute_input":"2025-03-13T09:52:46.893619Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Prediction generation\npreds = model.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:37:47.412432Z","iopub.execute_input":"2025-03-12T13:37:47.412651Z","iopub.status.idle":"2025-03-12T13:37:47.923118Z","shell.execute_reply.started":"2025-03-12T13:37:47.412632Z","shell.execute_reply":"2025-03-12T13:37:47.922491Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Formation of the submission file\nsubmission_rows = []\nfor i, (_, row) in enumerate(test_seq.iterrows()):\n    seq_len = len(row.sequence)\n    for res_idx in range(seq_len):\n        coords = preds[i][res_idx].tolist()\n        # Duplicate for 5 models\n        all_coords = coords * 5  \n        submission_rows.append([\n            f\"{row.target_id}_{res_idx+1}\",\n            row.sequence[res_idx],\n            res_idx+1,\n            *all_coords\n        ])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:37:47.924152Z","iopub.execute_input":"2025-03-12T13:37:47.924529Z","iopub.status.idle":"2025-03-12T13:37:47.960347Z","shell.execute_reply.started":"2025-03-12T13:37:47.924495Z","shell.execute_reply":"2025-03-12T13:37:47.959590Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Creating a DataFrame\ncolumns = ['ID', 'resname', 'resid'] + [f'{c}_{i+1}' for i in range(5) for c in ['x', 'y', 'z']]\nsubmission = pd.DataFrame(submission_rows, columns=columns)\nsubmission.to_csv('submission.csv', index=False)\nprint(\"Submission file created!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:37:47.961003Z","iopub.execute_input":"2025-03-12T13:37:47.961256Z","iopub.status.idle":"2025-03-12T13:37:48.037603Z","shell.execute_reply.started":"2025-03-12T13:37:47.961224Z","shell.execute_reply":"2025-03-12T13:37:48.036793Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# A list for storing data of each model\nmodels_data = []\n\nfor model_num in range(1, 6):\n    # Selecting columns for the current model\n    cols = ['ID', 'resname', 'resid'] + [f'{c}_{model_num}' for c in ['x', 'y', 'z']]\n    model_data = submission[cols].copy()\n    model_data = submission[cols].copy()\n    # Rename columns for convenience\n    model_data.columns = ['ID', 'resname', 'resid', 'x', 'y', 'z']\n    # Adding a model number\n    model_data['model'] = f'Model {model_num}'\n    models_data.append(model_data)\n# Combining data from all models\nall_models_data = pd.concat(models_data, ignore_index=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:37:48.038393Z","iopub.execute_input":"2025-03-12T13:37:48.038690Z","iopub.status.idle":"2025-03-12T13:37:48.052157Z","shell.execute_reply.started":"2025-03-12T13:37:48.038658Z","shell.execute_reply":"2025-03-12T13:37:48.051379Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import plotly.express as px\nfig = px.scatter_3d(all_models_data,\n                    x='x',\n                    y='y',\n                    z='z',\n                    color='z',\n                    color_continuous_scale='rainbow',\n                    title='3D Distribution of Predicted Points',\n                    labels={'x': 'X Coordinate', 'y': 'Y Coordinate', 'z': 'Z Coordinate'},\n                    opacity=0.7,\n                    hover_name='ID',\n                    hover_data=['resname', 'resid'])\n\nfig.update_layout(scene=dict(xaxis_title='X', yaxis_title='Y',zaxis_title='Z',),\n                  margin=dict(l=0, r=0, b=0, t=30),\n                  legend=dict(title='Model', x=0.8, y=0.9))\n\nfig.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T13:40:49.156160Z","iopub.execute_input":"2025-03-12T13:40:49.156493Z","iopub.status.idle":"2025-03-12T13:40:49.308406Z","shell.execute_reply.started":"2025-03-12T13:40:49.156459Z","shell.execute_reply":"2025-03-12T13:40:49.307316Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}