{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f15641e6", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:57:35.430169Z", "iopub.status.busy": "2025-03-25T05:57:35.430065Z", "iopub.status.idle": "2025-03-25T05:57:35.594064Z", "shell.execute_reply": "2025-03-25T05:57:35.593708Z" } }, "outputs": [], "source": [ "import sys\n", "import os\n", "sys.path.append(os.path.abspath(os.path.join(os.getcwd(), '../..')))\n", "\n", "# Path Configuration\n", "from tools.preprocess import *\n", "\n", "# Processing context\n", "trait = \"Obstructive_sleep_apnea\"\n", "cohort = \"GSE75097\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Obstructive_sleep_apnea\"\n", "in_cohort_dir = \"../../input/GEO/Obstructive_sleep_apnea/GSE75097\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Obstructive_sleep_apnea/GSE75097.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Obstructive_sleep_apnea/gene_data/GSE75097.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Obstructive_sleep_apnea/clinical_data/GSE75097.csv\"\n", "json_path = \"../../output/preprocess/Obstructive_sleep_apnea/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "a0f6187b", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "c06cb83a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:57:35.595505Z", "iopub.status.busy": "2025-03-25T05:57:35.595356Z", "iopub.status.idle": "2025-03-25T05:57:35.680183Z", "shell.execute_reply": "2025-03-25T05:57:35.679799Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Microarray gene expression profiles of peripheral blood mononuclear cells (PBMC) in patients with obstructive sleep apnea and primary snoring\"\n", "!Series_summary\t\"Therefore, we extended our investigation into OSA patients with long-term continuous positive airway pressure (CPAP) treatment, hypertension, or excessive daytime sleepiness (EDS) by analyzing whole-genome gene expression profiles of PBMC in three comparisons: (1) treatment-naïve moderate to very severe OSA patients versus subjects with primary snoring; (2) moderate to very severe OSA patients with hypertension or EDS versus those without hypertension or EDS, respectively; (3) treatment-naïve very severe OSA patients versus those receiving at least one year of adequate CPAP treatment.\"\n", "!Series_overall_design\t\"We analyzed whole-genome gene expression profiles of peripheral blood mononuclear cells from 48 patients with sleep-disordered breathing stratified into four groups: primary snoring (PS), moderate to severe OSA (MSO), very severe OSA (VSO), and very severe OSA patients with long-term continuous positive airway pressure (CPAP) treatment (VSOC).\"\n", "Sample Characteristics Dictionary:\n", "{0: ['cell type: PBMC'], 1: ['apnea hyponea index: 22.7', 'apnea hyponea index: 32.6', 'apnea hyponea index: 56.5', 'apnea hyponea index: 46.9', 'apnea hyponea index: 31.1', 'apnea hyponea index: 4.5', 'apnea hyponea index: 26.7', 'apnea hyponea index: 56.4', 'apnea hyponea index: 22.6', 'apnea hyponea index: 33.4', 'apnea hyponea index: 98.6', 'apnea hyponea index: 73.5', 'apnea hyponea index: 63.3', 'apnea hyponea index: 44.1', 'apnea hyponea index: 50.2', 'apnea hyponea index: 43.8', 'apnea hyponea index: 63.4', 'apnea hyponea index: 79.2', 'apnea hyponea index: 42.1', 'apnea hyponea index: 24.3', 'apnea hyponea index: 2.4', 'apnea hyponea index: 59.9', 'apnea hyponea index: 73.2', 'apnea hyponea index: 64.9', 'apnea hyponea index: 33.2', 'apnea hyponea index: 45.6', 'apnea hyponea index: 4.3', 'apnea hyponea index: 85.1', 'apnea hyponea index: 28.4', 'apnea hyponea index: 86.5'], 2: ['Sex: male', 'Sex: female'], 3: ['age: 54', 'age: 31', 'age: 44', 'age: 60', 'age: 21', 'age: 50', 'age: 52', 'age: 58', 'age: 42', 'age: 34', 'age: 37', 'age: 59', 'age: 27', 'age: 57', 'age: 68', 'age: 53', 'age: 36', 'age: 38', 'age: 43', 'age: 46', 'age: 49', 'age: 61', 'age: 45', 'age: 35', 'age: 47'], 4: ['hypertension: 1', 'hypertension: 0'], 5: ['eds: 0', 'eds: 1']}\n" ] } ], "source": [ "from tools.preprocess import *\n", "# 1. Identify the paths to the SOFT file and the matrix file\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. Read the matrix file to obtain background information and sample characteristics data\n", "background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']\n", "clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']\n", "background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)\n", "\n", "# 3. Obtain the sample characteristics dictionary from the clinical dataframe\n", "sample_characteristics_dict = get_unique_values_by_row(clinical_data)\n", "\n", "# 4. Explicitly print out all the background information and the sample characteristics dictionary\n", "print(\"Background Information:\")\n", "print(background_info)\n", "print(\"Sample Characteristics Dictionary:\")\n", "print(sample_characteristics_dict)\n" ] }, { "cell_type": "markdown", "id": "7cf06e6f", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "bd1090cf", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:57:35.681581Z", "iopub.status.busy": "2025-03-25T05:57:35.681469Z", "iopub.status.idle": "2025-03-25T05:57:35.691101Z", "shell.execute_reply": "2025-03-25T05:57:35.690781Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of extracted clinical features:\n", "{'values': [nan, nan, nan]}\n", "Clinical data saved to ../../output/preprocess/Obstructive_sleep_apnea/clinical_data/GSE75097.csv\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Looking at the series title and summary, this dataset contains microarray gene expression profiles\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Determine rows for each clinical feature\n", "# From the sample characteristics dictionary, we can identify:\n", "# Row 1: apnea hypopnea index (AHI) - this is a key clinical measure for OSA severity\n", "trait_row = 1 # AHI values indicate OSA severity\n", "age_row = 3 # Age information is available\n", "gender_row = 2 # Gender information is available\n", "\n", "# 2.2 Data Type Conversion Functions\n", "def convert_trait(value):\n", " \"\"\"\n", " Convert apnea hypopnea index (AHI) to a binary trait: OSA or not\n", " AHI < 5 is considered normal/primary snoring\n", " AHI ≥ 5 is considered OSA\n", " \"\"\"\n", " if value is None:\n", " return None\n", " # Extract the value after the colon\n", " parts = str(value).split(': ')\n", " if len(parts) != 2:\n", " return None\n", " \n", " try:\n", " ahi = float(parts[1].strip())\n", " # AHI < 5 is considered normal/primary snoring (0)\n", " # AHI ≥ 5 is considered OSA (1)\n", " return 1 if ahi >= 5 else 0\n", " except:\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age string to a numeric value.\"\"\"\n", " if value is None:\n", " return None\n", " # Extract the value after the colon\n", " parts = str(value).split(': ')\n", " if len(parts) != 2:\n", " return None\n", " \n", " try:\n", " age = int(parts[1].strip())\n", " return age\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender string to binary (0 for female, 1 for male).\"\"\"\n", " if value is None:\n", " return None\n", " # Extract the value after the colon\n", " parts = str(value).split(': ')\n", " if len(parts) != 2:\n", " return None\n", " \n", " gender = parts[1].strip().lower()\n", " if gender == 'male':\n", " return 1\n", " elif gender == 'female':\n", " return 0\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata - Initial filtering on usability\n", "is_trait_available = trait_row is not None\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available\n", ")\n", "\n", "# 4. Clinical Feature Extraction\n", "if trait_row is not None:\n", " # For the geo_select_clinical_features function, we need to create a proper DataFrame\n", " # that's structured with row indices corresponding to the rows in the sample characteristics\n", "\n", " # Define the sample characteristics from the previous step\n", " sample_chars = {\n", " 0: ['cell type: PBMC'], \n", " 1: ['apnea hyponea index: 22.7', 'apnea hyponea index: 32.6', 'apnea hyponea index: 56.5', \n", " 'apnea hyponea index: 46.9', 'apnea hyponea index: 31.1', 'apnea hyponea index: 4.5', \n", " 'apnea hyponea index: 26.7', 'apnea hyponea index: 56.4', 'apnea hyponea index: 22.6', \n", " 'apnea hyponea index: 33.4', 'apnea hyponea index: 98.6', 'apnea hyponea index: 73.5', \n", " 'apnea hyponea index: 63.3', 'apnea hyponea index: 44.1', 'apnea hyponea index: 50.2', \n", " 'apnea hyponea index: 43.8', 'apnea hyponea index: 63.4', 'apnea hyponea index: 79.2', \n", " 'apnea hyponea index: 42.1', 'apnea hyponea index: 24.3', 'apnea hyponea index: 2.4', \n", " 'apnea hyponea index: 59.9', 'apnea hyponea index: 73.2', 'apnea hyponea index: 64.9', \n", " 'apnea hyponea index: 33.2', 'apnea hyponea index: 45.6', 'apnea hyponea index: 4.3', \n", " 'apnea hyponea index: 85.1', 'apnea hyponea index: 28.4', 'apnea hyponea index: 86.5'], \n", " 2: ['Sex: male', 'Sex: female'], \n", " 3: ['age: 54', 'age: 31', 'age: 44', 'age: 60', 'age: 21', 'age: 50', 'age: 52', \n", " 'age: 58', 'age: 42', 'age: 34', 'age: 37', 'age: 59', 'age: 27', 'age: 57', \n", " 'age: 68', 'age: 53', 'age: 36', 'age: 38', 'age: 43', 'age: 46', 'age: 49', \n", " 'age: 61', 'age: 45', 'age: 35', 'age: 47'], \n", " 4: ['hypertension: 1', 'hypertension: 0'], \n", " 5: ['eds: 0', 'eds: 1']\n", " }\n", " \n", " # Create a DataFrame that's compatible with geo_select_clinical_features\n", " # The function likely expects a DataFrame with row indices matching the sample characteristics\n", " clinical_data = pd.DataFrame(index=range(max(sample_chars.keys()) + 1))\n", " \n", " # Add an empty column to make it a proper DataFrame\n", " clinical_data['values'] = [sample_chars.get(i, []) for i in range(len(clinical_data))]\n", " \n", " # Extract clinical features using the library function\n", " selected_clinical_df = geo_select_clinical_features(\n", " clinical_df=clinical_data,\n", " trait=trait,\n", " trait_row=trait_row,\n", " convert_trait=convert_trait,\n", " age_row=age_row,\n", " convert_age=convert_age,\n", " gender_row=gender_row,\n", " convert_gender=convert_gender\n", " )\n", " \n", " # Preview the extracted clinical features\n", " preview = preview_df(selected_clinical_df)\n", " print(\"Preview of extracted clinical features:\")\n", " print(preview)\n", " \n", " # Save the processed clinical data\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " selected_clinical_df.to_csv(out_clinical_data_file)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "c735ec17", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "13227880", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:57:35.692150Z", "iopub.status.busy": "2025-03-25T05:57:35.692043Z", "iopub.status.idle": "2025-03-25T05:57:35.817859Z", "shell.execute_reply": "2025-03-25T05:57:35.817488Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "First 20 gene/probe identifiers:\n", "Index(['7A5', 'A1BG', 'A1CF', 'A26C3', 'A2BP1', 'A2LD1', 'A2M', 'A2ML1',\n", " 'A3GALT2', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS', 'AACS', 'AACSL', 'AADAC',\n", " 'AADACL1', 'AADACL2', 'AADACL3', 'AADACL4'],\n", " dtype='object', name='ID')\n", "\n", "Gene data dimensions: 34677 genes × 48 samples\n" ] } ], "source": [ "# 1. Re-identify the SOFT and matrix files to ensure we have the correct paths\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. Extract the gene expression data from the matrix file\n", "gene_data = get_genetic_data(matrix_file)\n", "\n", "# 3. Print the first 20 row IDs (gene or probe identifiers)\n", "print(\"\\nFirst 20 gene/probe identifiers:\")\n", "print(gene_data.index[:20])\n", "\n", "# 4. Print the dimensions of the gene expression data\n", "print(f\"\\nGene data dimensions: {gene_data.shape[0]} genes × {gene_data.shape[1]} samples\")\n", "\n", "# Note: we keep is_gene_available as True since we successfully extracted gene expression data\n", "is_gene_available = True\n" ] }, { "cell_type": "markdown", "id": "9a729f99", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "e0f1a86a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:57:35.819175Z", "iopub.status.busy": "2025-03-25T05:57:35.819052Z", "iopub.status.idle": "2025-03-25T05:57:35.821089Z", "shell.execute_reply": "2025-03-25T05:57:35.820769Z" } }, "outputs": [], "source": [ "# The identifiers appear to be a mix of gene symbols (like A1BG, A2M) and some less standard identifiers.\n", "# Most of them look like recognized gene symbols, with a few exceptions.\n", "# Given that most seem to be proper gene symbols, we can consider this as not requiring mapping.\n", "\n", "requires_gene_mapping = False\n" ] }, { "cell_type": "markdown", "id": "857ad693", "metadata": {}, "source": [ "### Step 5: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 6, "id": "a32719b1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:57:35.822237Z", "iopub.status.busy": "2025-03-25T05:57:35.822129Z", "iopub.status.idle": "2025-03-25T05:57:46.102311Z", "shell.execute_reply": "2025-03-25T05:57:46.101573Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalizing gene symbols...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape after normalization: (20741, 48)\n", "First 5 normalized gene symbols: ['A1BG', 'A1BG-AS1', 'A1CF', 'A2M', 'A2ML1']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Obstructive_sleep_apnea/gene_data/GSE75097.csv\n", "Preview of clinical data:\n", "{'GSM1942590': [1.0, 54.0, 1.0], 'GSM1942591': [1.0, 31.0, 1.0], 'GSM1942592': [1.0, 44.0, 1.0], 'GSM1942593': [1.0, 60.0, 1.0], 'GSM1942594': [1.0, 21.0, 1.0], 'GSM1942595': [0.0, 50.0, 1.0], 'GSM1942596': [1.0, 52.0, 0.0], 'GSM1942597': [1.0, 58.0, 1.0], 'GSM1942598': [1.0, 42.0, 0.0], 'GSM1942599': [1.0, 34.0, 1.0], 'GSM1942600': [1.0, 58.0, 1.0], 'GSM1942601': [1.0, 37.0, 1.0], 'GSM1942602': [1.0, 60.0, 0.0], 'GSM1942603': [1.0, 59.0, 1.0], 'GSM1942604': [1.0, 27.0, 1.0], 'GSM1942605': [1.0, 57.0, 1.0], 'GSM1942606': [1.0, 68.0, 1.0], 'GSM1942607': [1.0, 53.0, 1.0], 'GSM1942608': [1.0, 58.0, 1.0], 'GSM1942609': [1.0, 52.0, 0.0], 'GSM1942610': [0.0, 36.0, 1.0], 'GSM1942611': [1.0, 38.0, 1.0], 'GSM1942612': [1.0, 50.0, 1.0], 'GSM1942613': [1.0, 44.0, 1.0], 'GSM1942614': [1.0, 58.0, 1.0], 'GSM1942615': [1.0, 54.0, 1.0], 'GSM1942616': [0.0, 43.0, 1.0], 'GSM1942617': [1.0, 59.0, 0.0], 'GSM1942618': [1.0, 44.0, 1.0], 'GSM1942619': [1.0, 46.0, 1.0], 'GSM1942620': [1.0, 36.0, 1.0], 'GSM1942621': [1.0, 59.0, 0.0], 'GSM1942622': [1.0, 49.0, 1.0], 'GSM1942623': [1.0, 59.0, 1.0], 'GSM1942624': [0.0, 68.0, 1.0], 'GSM1942625': [1.0, 61.0, 1.0], 'GSM1942626': [1.0, 38.0, 1.0], 'GSM1942627': [1.0, 45.0, 0.0], 'GSM1942628': [1.0, 35.0, 1.0], 'GSM1942629': [1.0, 57.0, 0.0], 'GSM1942630': [1.0, 42.0, 1.0], 'GSM1942631': [1.0, 44.0, 1.0], 'GSM1942632': [1.0, 47.0, 1.0], 'GSM1942633': [0.0, 50.0, 0.0], 'GSM1942634': [1.0, 54.0, 1.0], 'GSM1942635': [1.0, 50.0, 1.0], 'GSM1942636': [1.0, 47.0, 1.0], 'GSM1942637': [1.0, 38.0, 1.0]}\n", "Clinical data saved to ../../output/preprocess/Obstructive_sleep_apnea/clinical_data/GSE75097.csv\n", "Linked data shape: (48, 20744)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Data shape after handling missing values: (48, 20744)\n", "For the feature 'Obstructive_sleep_apnea', the least common label is '0.0' with 5 occurrences. This represents 10.42% of the dataset.\n", "The distribution of the feature 'Obstructive_sleep_apnea' in this dataset is fine.\n", "\n", "Quartiles for 'Age':\n", " 25%: 42.0\n", " 50% (Median): 50.0\n", " 75%: 58.0\n", "Min: 21.0\n", "Max: 68.0\n", "The distribution of the feature 'Age' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '0.0' with 9 occurrences. This represents 18.75% of the dataset.\n", "The distribution of the feature 'Gender' in this dataset is fine.\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data saved to ../../output/preprocess/Obstructive_sleep_apnea/GSE75097.csv\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "print(\"Normalizing gene symbols...\")\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Gene data shape after normalization: {normalized_gene_data.shape}\")\n", "print(f\"First 5 normalized gene symbols: {normalized_gene_data.index[:5].tolist()}\")\n", "\n", "# Save the normalized gene data\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "normalized_gene_data.to_csv(out_gene_data_file)\n", "print(f\"Normalized gene data saved to {out_gene_data_file}\")\n", "\n", "# 2. Re-extract clinical data using the correct row indices and conversion functions from step 2\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# Get background information and clinical data\n", "background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']\n", "clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']\n", "background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)\n", "\n", "# Use the correct values and functions identified in step 2\n", "trait_row = 1 # apnea hypopnea index\n", "age_row = 3 # age information\n", "gender_row = 2 # gender information\n", "\n", "def convert_trait(value):\n", " \"\"\"\n", " Convert apnea hypopnea index (AHI) to a binary trait: OSA or not\n", " AHI < 5 is considered normal/primary snoring\n", " AHI ≥ 5 is considered OSA\n", " \"\"\"\n", " if value is None:\n", " return None\n", " # Extract the value after the colon\n", " parts = str(value).split(': ')\n", " if len(parts) != 2:\n", " return None\n", " \n", " try:\n", " ahi = float(parts[1].strip())\n", " # AHI < 5 is considered normal/primary snoring (0)\n", " # AHI ≥ 5 is considered OSA (1)\n", " return 1 if ahi >= 5 else 0\n", " except:\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age string to a numeric value.\"\"\"\n", " if value is None:\n", " return None\n", " # Extract the value after the colon\n", " parts = str(value).split(': ')\n", " if len(parts) != 2:\n", " return None\n", " \n", " try:\n", " age = int(parts[1].strip())\n", " return age\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender string to binary (0 for female, 1 for male).\"\"\"\n", " if value is None:\n", " return None\n", " # Extract the value after the colon\n", " parts = str(value).split(': ')\n", " if len(parts) != 2:\n", " return None\n", " \n", " gender = parts[1].strip().lower()\n", " if gender == 'male':\n", " return 1\n", " elif gender == 'female':\n", " return 0\n", " else:\n", " return None\n", "\n", "# Extract clinical features with correct row indices and conversion functions\n", "selected_clinical_df = geo_select_clinical_features(\n", " clinical_df=clinical_data,\n", " trait=trait,\n", " trait_row=trait_row,\n", " convert_trait=convert_trait,\n", " age_row=age_row,\n", " convert_age=convert_age,\n", " gender_row=gender_row,\n", " convert_gender=convert_gender\n", ")\n", "\n", "# Debug: Show preview of clinical data\n", "print(\"Preview of clinical data:\")\n", "print(preview_df(selected_clinical_df))\n", "\n", "# Save clinical data\n", "os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", "selected_clinical_df.to_csv(out_clinical_data_file)\n", "print(f\"Clinical data saved to {out_clinical_data_file}\")\n", "\n", "# 3. Link clinical and genetic data\n", "linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)\n", "print(f\"Linked data shape: {linked_data.shape}\")\n", "\n", "# 4. Handle missing values\n", "linked_data = handle_missing_values(linked_data, trait_col=trait)\n", "print(f\"Data shape after handling missing values: {linked_data.shape}\")\n", "\n", "# 5. Determine if trait and demographic features are biased\n", "is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)\n", "\n", "# 6. Conduct final quality validation\n", "is_trait_available = True # We confirmed trait data is available in step 2\n", "is_usable = validate_and_save_cohort_info(\n", " is_final=True,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=True,\n", " is_trait_available=is_trait_available,\n", " is_biased=is_biased,\n", " df=linked_data,\n", " note=\"Dataset contains gene expression profiles from patients with obstructive sleep apnea and primary snoring.\"\n", ")\n", "\n", "# 7. Save linked data if usable\n", "if is_usable:\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " linked_data.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(\"Dataset deemed not usable for trait association studies, linked data not saved.\")" ] } ], "metadata": { "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.16" } }, "nbformat": 4, "nbformat_minor": 5 }