{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "08854ca3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:02.888642Z", "iopub.status.busy": "2025-03-25T04:29:02.888533Z", "iopub.status.idle": "2025-03-25T04:29:03.056826Z", "shell.execute_reply": "2025-03-25T04:29:03.056384Z" } }, "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 = \"Underweight\"\n", "cohort = \"GSE50982\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Underweight\"\n", "in_cohort_dir = \"../../input/GEO/Underweight/GSE50982\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Underweight/GSE50982.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Underweight/gene_data/GSE50982.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Underweight/clinical_data/GSE50982.csv\"\n", "json_path = \"../../output/preprocess/Underweight/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "362996c0", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "b06114cc", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:03.058327Z", "iopub.status.busy": "2025-03-25T04:29:03.058177Z", "iopub.status.idle": "2025-03-25T04:29:03.197531Z", "shell.execute_reply": "2025-03-25T04:29:03.197073Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Files in the cohort directory:\n", "['GSE50982_family.soft.gz', 'GSE50982_series_matrix.txt.gz']\n", "Identified SOFT files: ['GSE50982_family.soft.gz']\n", "Identified matrix files: ['GSE50982_series_matrix.txt.gz']\n", "\n", "Background Information:\n", "!Series_title\t\"Cavin-3 Dictates the Balance Between ERK and Akt Signaling\"\n", "!Series_summary\t\"Cavin-3 is a tumor suppressor protein of unknown function. Using a combination of in vivo knockout and in vitro gain/loss of function approaches, we show that cavin-3 dictates the balance between ERK and Akt signaling. Loss of cavin-3 increases Akt signaling at the expense of ERK, while gain of cavin-3 increases ERK signaling at the expense Akt. Cavin-3 facilitates signal transduction to ERK by anchoring caveolae, a lipid-raft specialization that contains an ERK activation module, to the membrane skeleton of the plasma membrane. Loss of cavin-3 reduces the number of caveolae, thereby separating this ERK activation module from signaling receptors. Loss of cavin-3 promotes Akt signaling through suppression of EGR1 and PTEN. The in vitro consequences of the loss of cavin-3 include induction of Warburg metabolism (aerobic glycolysis), accelerated cell proliferation and resistance to apoptosis. The in vivo consequences of cavin-3 loss are increased lactate production and cachexia.\"\n", "!Series_overall_design\t\"9 total samples, consisting of 3 cavin-3 siRNA groups (0 days, 3 days and 8 days) one set was untreated, one set was serum starved, one set was serum starved and then treated with EGF for 1 hr.\"\n", "\n", "Sample Characteristics Dictionary:\n", "{0: ['cell line: SV589'], 1: ['knockdown (days): 0', 'knockdown (days): 3', 'knockdown (days): 8', 'knockdown (days): 15'], 2: ['treatment: Serum Starved; no EGF', 'treatment: Serum Starved; 1h EGF', 'treatment: Serum Starved; 3h EGF', 'treatment: no treatment']}\n" ] } ], "source": [ "# 1. Let's first list the directory contents to understand what files are available\n", "import os\n", "\n", "print(\"Files in the cohort directory:\")\n", "files = os.listdir(in_cohort_dir)\n", "print(files)\n", "\n", "# Adapt file identification to handle different naming patterns\n", "soft_files = [f for f in files if 'soft' in f.lower() or '.soft' in f.lower() or '_soft' in f.lower()]\n", "matrix_files = [f for f in files if 'matrix' in f.lower() or '.matrix' in f.lower() or '_matrix' in f.lower()]\n", "\n", "# If no files with these patterns are found, look for alternative file types\n", "if not soft_files:\n", " soft_files = [f for f in files if f.endswith('.txt') or f.endswith('.gz')]\n", "if not matrix_files:\n", " matrix_files = [f for f in files if f.endswith('.txt') or f.endswith('.gz')]\n", "\n", "print(\"Identified SOFT files:\", soft_files)\n", "print(\"Identified matrix files:\", matrix_files)\n", "\n", "# Use the first files found, if any\n", "if len(soft_files) > 0 and len(matrix_files) > 0:\n", " soft_file = os.path.join(in_cohort_dir, soft_files[0])\n", " matrix_file = os.path.join(in_cohort_dir, matrix_files[0])\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(\"\\nBackground Information:\")\n", " print(background_info)\n", " print(\"\\nSample Characteristics Dictionary:\")\n", " print(sample_characteristics_dict)\n", "else:\n", " print(\"No appropriate files found in the directory.\")\n" ] }, { "cell_type": "markdown", "id": "955aa5c8", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "d069df82", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:03.199027Z", "iopub.status.busy": "2025-03-25T04:29:03.198897Z", "iopub.status.idle": "2025-03-25T04:29:03.207294Z", "shell.execute_reply": "2025-03-25T04:29:03.206904Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of clinical features:\n", "{'characteristics': [nan]}\n", "Clinical features saved to: ../../output/preprocess/Underweight/clinical_data/GSE50982.csv\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset appears to be studying gene expression\n", "# changes related to Cavin-3 protein's effect on ERK and Akt signaling pathways\n", "is_gene_available = True\n", "\n", "# 2.1 Data Availability\n", "# For trait (Underweight): \n", "# From the sample characteristics, we can infer underweight status from knockdown days\n", "# Knockdown days information is available in row 1 of the characteristics dictionary\n", "trait_row = 1\n", "\n", "# For age: Age information is not available in this dataset\n", "age_row = None\n", "\n", "# For gender: Gender information is not available in this dataset\n", "gender_row = None\n", "\n", "# 2.2 Data Type Conversion\n", "def convert_trait(value):\n", " \"\"\"\n", " Convert knockdown data to binary underweight status.\n", " \n", " Based on the background information, we can infer that longer \n", " knockdown of Cavin-3 leads to cachexia (wasting syndrome),\n", " which can be considered as an underweight condition.\n", " \n", " 8+ days of knockdown are considered as underweight (1)\n", " 0-3 days of knockdown are considered normal weight (0)\n", " \"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if isinstance(value, str) and ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " try:\n", " knockdown_days = int(value)\n", " # Based on biological inference: longer knockdown leads to cachexia/underweight\n", " if knockdown_days >= 8: # 8 or more days of knockdown\n", " return 1 # Underweight\n", " else: # Less than 8 days of knockdown\n", " return 0 # Normal weight\n", " except (ValueError, TypeError):\n", " return None\n", "\n", "def convert_age(value):\n", " # Age data is not available, but we need this function for the library\n", " return None\n", "\n", "def convert_gender(value):\n", " # Gender data is not available, but we need this function for the library\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Determine trait data availability\n", "is_trait_available = trait_row is not None\n", "\n", "# Conduct initial filtering and save metadata\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", "# Since the clinical data variable was used previously, we'll assume it's already loaded\n", "if trait_row is not None:\n", " try:\n", " # Assuming clinical_data is already available from previous steps\n", " # If not, we need to store this information and continue with metadata\n", " \n", " # Use sample characteristics as clinical data\n", " # Create a DataFrame from the sample characteristics dictionary\n", " characteristics = {0: ['cell line: SV589'], \n", " 1: ['knockdown (days): 0', 'knockdown (days): 3', 'knockdown (days): 8', 'knockdown (days): 15'], \n", " 2: ['treatment: Serum Starved; no EGF', 'treatment: Serum Starved; 1h EGF', \n", " 'treatment: Serum Starved; 3h EGF', 'treatment: no treatment']}\n", " \n", " # Create a clinical data DataFrame with empty samples\n", " # The geo_select_clinical_features function will handle the association between samples and characteristics\n", " clinical_data = pd.DataFrame()\n", " clinical_data['characteristics'] = pd.Series(characteristics)\n", " \n", " # Use the library function to extract clinical features\n", " clinical_features = 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 features\n", " preview = preview_df(clinical_features)\n", " print(\"Preview of clinical features:\")\n", " print(preview)\n", " \n", " # Create the directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " \n", " # Save the clinical features to CSV\n", " clinical_features.to_csv(out_clinical_data_file, index=False)\n", " print(f\"Clinical features saved to: {out_clinical_data_file}\")\n", " \n", " except Exception as e:\n", " print(f\"Error during clinical feature extraction: {e}\")\n", " # If clinical data processing fails, update the metadata\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=False\n", " )\n" ] }, { "cell_type": "markdown", "id": "79faf798", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "7100a73e", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:03.208477Z", "iopub.status.busy": "2025-03-25T04:29:03.208352Z", "iopub.status.idle": "2025-03-25T04:29:03.406064Z", "shell.execute_reply": "2025-03-25T04:29:03.405678Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First 20 gene/probe identifiers:\n", "Index(['ILMN_1343291', 'ILMN_1343295', 'ILMN_1651199', 'ILMN_1651209',\n", " 'ILMN_1651210', 'ILMN_1651221', 'ILMN_1651228', 'ILMN_1651229',\n", " 'ILMN_1651230', 'ILMN_1651232', 'ILMN_1651235', 'ILMN_1651236',\n", " 'ILMN_1651237', 'ILMN_1651238', 'ILMN_1651249', 'ILMN_1651253',\n", " 'ILMN_1651254', 'ILMN_1651259', 'ILMN_1651260', 'ILMN_1651262'],\n", " dtype='object', name='ID')\n", "\n", "Gene expression data shape: (47323, 45)\n" ] } ], "source": [ "# Use the helper function to get the proper file paths\n", "soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# Extract gene expression data\n", "try:\n", " gene_data = get_genetic_data(matrix_file_path)\n", " \n", " # Print the first 20 row IDs (gene or probe identifiers)\n", " print(\"First 20 gene/probe identifiers:\")\n", " print(gene_data.index[:20])\n", " \n", " # Print shape to understand the dataset dimensions\n", " print(f\"\\nGene expression data shape: {gene_data.shape}\")\n", " \n", "except Exception as e:\n", " print(f\"Error extracting gene data: {e}\")\n" ] }, { "cell_type": "markdown", "id": "6da86754", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "6b5c944e", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:03.407689Z", "iopub.status.busy": "2025-03-25T04:29:03.407560Z", "iopub.status.idle": "2025-03-25T04:29:03.409654Z", "shell.execute_reply": "2025-03-25T04:29:03.409388Z" } }, "outputs": [], "source": [ "# Looking at the identifiers, they start with \"ILMN_\" which indicates they are Illumina \n", "# microarray probe IDs, not human gene symbols. These need to be mapped to gene symbols.\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "b6051ac3", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "f3aea0e9", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:03.411157Z", "iopub.status.busy": "2025-03-25T04:29:03.411057Z", "iopub.status.idle": "2025-03-25T04:29:08.143889Z", "shell.execute_reply": "2025-03-25T04:29:08.143516Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['ILMN_1343048', 'ILMN_1343049', 'ILMN_1343050', 'ILMN_1343052', 'ILMN_1343059'], 'Species': [nan, nan, nan, nan, nan], 'Source': [nan, nan, nan, nan, nan], 'Search_Key': [nan, nan, nan, nan, nan], 'Transcript': [nan, nan, nan, nan, nan], 'ILMN_Gene': [nan, nan, nan, nan, nan], 'Source_Reference_ID': [nan, nan, nan, nan, nan], 'RefSeq_ID': [nan, nan, nan, nan, nan], 'Unigene_ID': [nan, nan, nan, nan, nan], 'Entrez_Gene_ID': [nan, nan, nan, nan, nan], 'GI': [nan, nan, nan, nan, nan], 'Accession': [nan, nan, nan, nan, nan], 'Symbol': ['phage_lambda_genome', 'phage_lambda_genome', 'phage_lambda_genome:low', 'phage_lambda_genome:low', 'thrB'], 'Protein_Product': [nan, nan, nan, nan, 'thrB'], 'Probe_Id': [nan, nan, nan, nan, nan], 'Array_Address_Id': [5090180.0, 6510136.0, 7560739.0, 1450438.0, 1240647.0], 'Probe_Type': [nan, nan, nan, nan, nan], 'Probe_Start': [nan, nan, nan, nan, nan], 'SEQUENCE': ['GAATAAAGAACAATCTGCTGATGATCCCTCCGTGGATCTGATTCGTGTAA', 'CCATGTGATACGAGGGCGCGTAGTTTGCATTATCGTTTTTATCGTTTCAA', 'CCGACAGATGTATGTAAGGCCAACGTGCTCAAATCTTCATACAGAAAGAT', 'TCTGTCACTGTCAGGAAAGTGGTAAAACTGCAACTCAATTACTGCAATGC', 'CTTGTGCCTGAGCTGTCAAAAGTAGAGCACGTCGCCGAGATGAAGGGCGC'], 'Chromosome': [nan, nan, nan, nan, nan], 'Probe_Chr_Orientation': [nan, nan, nan, nan, nan], 'Probe_Coordinates': [nan, nan, nan, nan, nan], 'Cytoband': [nan, nan, nan, nan, nan], 'Definition': [nan, nan, nan, nan, nan], 'Ontology_Component': [nan, nan, nan, nan, nan], 'Ontology_Process': [nan, nan, nan, nan, nan], 'Ontology_Function': [nan, nan, nan, nan, nan], 'Synonyms': [nan, nan, nan, nan, nan], 'Obsolete_Probe_Id': [nan, nan, nan, nan, nan], 'GB_ACC': [nan, nan, nan, nan, nan]}\n" ] } ], "source": [ "# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.\n", "try:\n", " # Use the correct variable name from previous steps\n", " gene_annotation = get_gene_annotation(soft_file_path)\n", " \n", " # 2. Preview the gene annotation dataframe\n", " print(\"Gene annotation preview:\")\n", " print(preview_df(gene_annotation))\n", " \n", "except UnicodeDecodeError as e:\n", " print(f\"Unicode decoding error: {e}\")\n", " print(\"Trying alternative approach...\")\n", " \n", " # Read the file with Latin-1 encoding which is more permissive\n", " import gzip\n", " import pandas as pd\n", " \n", " # Manually read the file line by line with error handling\n", " data_lines = []\n", " with gzip.open(soft_file_path, 'rb') as f:\n", " for line in f:\n", " # Skip lines starting with prefixes we want to filter out\n", " line_str = line.decode('latin-1')\n", " if not line_str.startswith('^') and not line_str.startswith('!') and not line_str.startswith('#'):\n", " data_lines.append(line_str)\n", " \n", " # Create dataframe from collected lines\n", " if data_lines:\n", " gene_data_str = '\\n'.join(data_lines)\n", " gene_annotation = pd.read_csv(pd.io.common.StringIO(gene_data_str), sep='\\t', low_memory=False)\n", " print(\"Gene annotation preview (alternative method):\")\n", " print(preview_df(gene_annotation))\n", " else:\n", " print(\"No valid gene annotation data found after filtering.\")\n", " gene_annotation = pd.DataFrame()\n", " \n", "except Exception as e:\n", " print(f\"Error extracting gene annotation data: {e}\")\n", " gene_annotation = pd.DataFrame()\n" ] }, { "cell_type": "markdown", "id": "81243bc6", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "9ee2ee92", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:08.145435Z", "iopub.status.busy": "2025-03-25T04:29:08.145280Z", "iopub.status.idle": "2025-03-25T04:29:08.364230Z", "shell.execute_reply": "2025-03-25T04:29:08.363885Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping dataframe shape: (44837, 2)\n", "Gene mapping preview:\n", "{'ID': ['ILMN_1343048', 'ILMN_1343049', 'ILMN_1343050', 'ILMN_1343052', 'ILMN_1343059'], 'Gene': ['phage_lambda_genome', 'phage_lambda_genome', 'phage_lambda_genome:low', 'phage_lambda_genome:low', 'thrB']}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data shape after mapping: (21464, 45)\n", "First 10 genes after mapping:\n", "Index(['A1BG', 'A1CF', 'A26C3', 'A2BP1', 'A2LD1', 'A2M', 'A2ML1', 'A3GALT2',\n", " 'A4GALT', 'A4GNT'],\n", " dtype='object', name='Gene')\n" ] } ], "source": [ "# 1. Identify columns for gene mapping\n", "# From the gene annotation preview, we can see:\n", "# - 'ID' column contains the Illumina probe IDs (ILMN_*)\n", "# - 'Symbol' column contains gene symbols\n", "\n", "# 2. Get gene mapping dataframe\n", "prob_col = 'ID' # Column containing probe IDs\n", "gene_col = 'Symbol' # Column containing gene symbols\n", "\n", "# Extract mapping between probes and gene symbols\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col)\n", "\n", "print(f\"Gene mapping dataframe shape: {gene_mapping.shape}\")\n", "print(\"Gene mapping preview:\")\n", "print(preview_df(gene_mapping))\n", "\n", "# 3. Apply gene mapping to convert probe-level data to gene-level data\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "print(f\"Gene expression data shape after mapping: {gene_data.shape}\")\n", "print(\"First 10 genes after mapping:\")\n", "print(gene_data.index[:10])\n" ] }, { "cell_type": "markdown", "id": "d05eb44f", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "e1e07315", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:08.365623Z", "iopub.status.busy": "2025-03-25T04:29:08.365512Z", "iopub.status.idle": "2025-03-25T04:29:09.387680Z", "shell.execute_reply": "2025-03-25T04:29:09.387312Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape after normalization: (20259, 45)\n", "First few gene symbols after normalization: ['A1BG', 'A1BG-AS1', 'A1CF', 'A2M', 'A2ML1', 'A3GALT2', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Underweight/gene_data/GSE50982.csv\n", "Clinical features extracted:\n", "{'characteristics': [nan]}\n", "Clinical data saved to ../../output/preprocess/Underweight/clinical_data/GSE50982.csv\n", "Linked data shape: (46, 20260)\n", "Linked data preview:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'Underweight': [nan, nan, nan, nan, nan], 'A1BG': [nan, 230.2868, 238.90699999999998, 234.83589999999998, 236.6119], 'A1BG-AS1': [nan, 115.7004, 136.1917, 133.0038, 128.777], 'A1CF': [nan, 315.4479, 324.1434, 326.9045, 336.3676], 'A2M': [nan, 99.78751, 100.2313, 100.2132, 94.68452], 'A2ML1': [nan, 94.3905, 107.1121, 104.4166, 97.52838], 'A3GALT2': [nan, 220.3246, 225.5058, 214.4992, 204.40794], 'A4GALT': [nan, 160.7064, 240.7132, 220.7152, 163.5258], 'A4GNT': [nan, 116.5021, 121.6363, 121.9945, 123.2215], 'AAA1': [nan, 524.87845, 555.8584, 538.0862, 514.4675199999999], 'AAAS': [nan, 145.673, 176.9964, 180.3475, 153.893], 'AACS': [nan, 184.948, 274.0733, 288.8924, 219.36], 'AACSP1': [nan, 132.3505, 129.8966, 134.7291, 135.2525], 'AADAC': [nan, 106.4089, 108.2836, 112.9999, 106.6635], 'AADACL2': [nan, 108.3963, 108.0997, 107.609, 108.9314], 'AADACL3': [nan, 95.65421, 98.78402, 107.4066, 102.6192], 'AADACL4': [nan, 110.7212, 107.8824, 108.4992, 110.8268], 'AADAT': [nan, 512.40888, 583.2127, 582.4052, 516.9932], 'AAGAB': [nan, 349.9174, 292.4261, 340.3516, 317.6696], 'AAK1': [nan, 342.3372, 351.7932, 355.39459999999997, 365.2031], 'AAMDC': [nan, 889.649, 1002.148, 666.8892, 746.476], 'AAMP': [nan, 469.5453, 519.8195, 598.9376, 450.2833], 'AANAT': [nan, 98.13593, 103.3184, 99.03217, 94.2467], 'AAR2': [nan, 495.175, 959.1937, 892.8412, 670.7365], 'AARS1': [nan, 4173.413, 3365.885, 4954.537, 3712.24], 'AARS2': [nan, 556.6018, 466.1084, 351.149, 416.6475], 'AARSD1': [nan, 369.8486, 415.8535, 382.9841, 371.9335], 'AASDH': [nan, 173.8104, 179.2858, 183.3018, 166.5774], 'AASDHPPT': [nan, 524.0401, 503.7146, 621.1591, 468.01340000000005], 'AASS': [nan, 322.5842, 301.685, 293.09, 285.882], 'AATF': [nan, 382.8282, 689.3082, 671.1091, 461.6306], 'AATK': [nan, 429.9308, 407.6668, 423.9705, 473.8085], 'ABAT': [nan, 322.59796, 324.7708, 325.49490000000003, 338.69464], 'ABCA1': [nan, 419.7055, 394.3596, 573.61, 566.7138], 'ABCA10': [nan, 216.6125, 218.8922, 230.40640000000002, 217.54860000000002], 'ABCA11P': [nan, 130.2364, 148.1417, 148.5568, 131.1519], 'ABCA12': [nan, 190.5211, 220.3612, 213.7988, 195.24574], 'ABCA13': [nan, 89.64138, 99.71778, 102.5062, 93.3756], 'ABCA2': [nan, 227.5504, 250.84609999999998, 253.29200000000003, 214.1873], 'ABCA3': [nan, 116.9167, 103.3804, 107.0835, 106.6392], 'ABCA4': [nan, 108.3506, 106.1427, 104.0383, 104.7054], 'ABCA5': [nan, 347.6143, 357.448, 348.42060000000004, 348.6403], 'ABCA6': [nan, 228.2935, 210.9814, 227.1679, 238.2396], 'ABCA7': [nan, 340.8361, 331.72629, 361.18190000000004, 339.2808], 'ABCA8': [nan, 235.3706, 218.93237, 224.0233, 238.97469999999998], 'ABCA9': [nan, 231.6365, 234.8645, 238.35829999999999, 242.97750000000002], 'ABCB1': [nan, 214.34620999999999, 218.33411, 220.7135, 194.93423], 'ABCB10': [nan, 267.1964, 329.324, 300.553, 219.643], 'ABCB11': [nan, 112.7781, 110.5011, 110.2075, 107.362], 'ABCB4': [nan, 107.8607, 115.9928, 110.6726, 102.3641], 'ABCB5': [nan, 97.09254, 104.6459, 98.30415, 107.2987], 'ABCB6': [nan, 318.4424, 377.1076, 421.1753, 274.6902], 'ABCB7': [nan, 319.4713, 312.2628, 269.6646, 285.9374], 'ABCB8': [nan, 101.9268, 137.0578, 126.8446, 115.1885], 'ABCB9': [nan, 556.2743, 707.1869, 578.3196, 554.1668], 'ABCC1': [nan, 235.3801, 265.7862, 288.1037, 246.5031], 'ABCC10': [nan, 131.017, 180.4761, 164.7777, 139.7267], 'ABCC11': [nan, 313.11400000000003, 323.6827, 336.291, 325.5815], 'ABCC12': [nan, 103.597, 114.589, 105.7631, 98.48702], 'ABCC13': [nan, 329.81113, 330.2206, 338.5534, 333.32858999999996], 'ABCC2': [nan, 103.1481, 103.0011, 109.2575, 104.5444], 'ABCC3': [nan, 644.1514, 635.2381, 835.1937, 539.1425], 'ABCC4': [nan, 582.3976, 604.6408, 730.1749, 563.8209999999999], 'ABCC5': [nan, 1033.2188, 729.6068, 711.5975000000001, 820.5935], 'ABCC6': [nan, 684.1367, 694.0984, 687.2266, 662.94044], 'ABCC6P1': [nan, 121.0109, 114.3046, 114.4033, 120.3217], 'ABCC6P2': [nan, 131.7065, 124.7122, 128.2781, 136.3657], 'ABCC8': [nan, 101.0959, 105.3755, 102.9172, 98.09997], 'ABCC9': [nan, 350.0786, 344.7494, 350.661, 341.62816], 'ABCD1': [nan, 115.0813, 152.7948, 145.0564, 120.2821], 'ABCD2': [nan, 203.74042, 210.0587, 217.2672, 210.4771], 'ABCD3': [nan, 232.5929, 202.3588, 199.778, 209.1678], 'ABCD4': [nan, 442.91020000000003, 459.3675, 460.7019, 436.47220000000004], 'ABCE1': [nan, 1292.4815, 1406.9036, 1656.1565999999998, 1142.7105999999999], 'ABCF1': [nan, 3873.0428, 4251.433, 3713.663, 3946.8032999999996], 'ABCF2': [nan, 577.84487, 816.8512, 921.5354, 655.52708], 'ABCF3': [nan, 127.4533, 184.9173, 202.9042, 141.6591], 'ABCG1': [nan, 701.38182, 677.4702, 685.5823, 674.1858], 'ABCG2': [nan, 104.2387, 109.7404, 107.1732, 105.8924], 'ABCG4': [nan, 120.5573, 117.858, 125.5157, 122.4802], 'ABCG5': [nan, 109.2882, 122.2951, 109.1951, 111.103], 'ABCG8': [nan, 122.5344, 105.6921, 106.5329, 109.8885], 'ABHD1': [nan, 119.9796, 111.2209, 111.3043, 116.9996], 'ABHD10': [nan, 332.4841, 440.0016, 487.187, 302.7687], 'ABHD11': [nan, 387.23675000000003, 456.8969, 462.8415, 437.6243], 'ABHD12': [nan, 1022.9456, 1991.5514, 1452.5354, 1225.8065], 'ABHD12B': [nan, 333.31934, 332.83119999999997, 337.2034, 325.35219], 'ABHD13': [nan, 230.5165, 214.0455, 219.1071, 218.41969999999998], 'ABHD14A': [nan, 278.6214, 662.4188, 506.5457, 325.7369], 'ABHD14B': [nan, 127.674, 174.0505, 205.58, 137.6524], 'ABHD15': [nan, 140.3409, 196.4189, 160.5604, 154.8066], 'ABHD16A': [nan, 299.5092, 474.8322, 471.6591, 366.4594], 'ABHD16B': [nan, 108.9309, 104.9875, 100.9151, 107.2173], 'ABHD17A': [nan, 204.52973, 219.54059999999998, 215.02609999999999, 219.5582], 'ABHD17AP1': [nan, 329.99995, 791.99765, 744.44695, 383.46565], 'ABHD17B': [nan, 598.8478, 623.0894, 623.37224, 583.5376], 'ABHD17C': [nan, 1478.617, 937.0118, 834.1096, 1332.91], 'ABHD18': [nan, 115.6896, 159.9212, 151.6055, 115.0151], 'ABHD2': [nan, 419.47294, 536.4702, 562.351, 460.97199], 'ABHD3': [nan, 353.582, 337.7458, 257.3431, 324.6088], 'ABHD4': [nan, 205.4432, 397.2612, 391.5977, 231.3829], 'ABHD5': [nan, 163.7408, 240.244, 235.0829, 160.2952], 'ABHD6': [nan, 292.0791, 364.2208, 378.8162, 320.2493], 'ABHD8': [nan, 406.9493, 300.5943, 253.1594, 408.7806], 'ABI1': [nan, 361.5074, 442.0346, 411.2797, 324.2314], 'ABI2': [nan, 991.2484000000001, 1331.5599000000002, 1319.2196, 999.3109999999999], 'ABI3': [nan, 146.3644, 130.946, 127.1281, 158.6134], 'ABI3BP': [nan, 1709.936, 689.9605, 743.5436, 1921.737], 'ABITRAM': [nan, 476.67560000000003, 737.6845, 950.2791, 500.481], 'ABL1': [nan, 1316.0667, 1351.5667, 1487.2156, 1280.9906999999998], 'ABL2': [nan, 425.6372, 556.6366, 473.144, 448.83500000000004], 'ABLIM1': [nan, 506.6827, 588.6543, 511.2952, 539.2195], 'ABLIM2': [nan, 108.4397, 108.1899, 113.479, 98.92698], 'ABLIM3': [nan, 176.6559, 167.6975, 215.0746, 171.8779], 'ABO': [nan, 93.35049, 105.7776, 99.23284, 103.5274], 'ABR': [nan, 1757.5258000000001, 1656.5369, 1513.9051, 1658.8393], 'ABRA': [nan, 101.2562, 103.6614, 105.598, 101.9225], 'ABRACL': [nan, 575.9125, 503.9935, 528.4596, 536.0931], 'ABRAXAS1': [nan, 444.5385, 543.9885, 460.6279, 255.5387], 'ABRAXAS2': [nan, 636.4413, 649.8009, 647.3229, 653.584], 'ABT1': [nan, 148.9987, 178.9074, 187.4399, 134.0836], 'ABTB1': [nan, 828.0032, 714.2698, 661.6731, 566.7464], 'ABTB2': [nan, 129.6096, 189.9035, 179.1138, 131.6958], 'ABTB3': [nan, 412.36058, 428.8873, 430.31566, 407.84136], 'ACAA1': [nan, 429.2055, 531.2617, 485.0016, 400.6387], 'ACAA2': [nan, 338.8329, 351.4339, 429.4177, 303.3246], 'ACACA': [nan, 1965.38485, 1993.5666999999999, 2063.9908, 2103.4552], 'ACACB': [nan, 131.7885, 97.0417, 100.2688, 123.3568], 'ACAD10': [nan, 231.2802, 193.2156, 195.3246, 195.9913], 'ACAD11': [nan, 549.1963, 406.8613, 513.8002, 327.1411], 'ACAD8': [nan, 656.5456999999999, 526.0732, 599.9342, 492.96698000000004], 'ACAD9': [nan, 1073.146, 1024.98, 1057.631, 960.203], 'ACADL': [nan, 104.8941, 106.7675, 103.2119, 106.1786], 'ACADM': [nan, 2113.0459, 1655.7381, 2013.4765000000002, 1831.7092], 'ACADS': [nan, 113.9017, 147.8257, 147.6393, 124.4594], 'ACADSB': [nan, 108.7392, 111.7307, 104.3271, 114.4124], 'ACADVL': [nan, 4217.2352, 5186.006, 4229.47, 3075.7749], 'ACAN': [nan, 94.47627, 103.124, 102.9031, 97.04763], 'ACAP1': [nan, 99.18796, 108.5885, 108.978, 105.4119], 'ACAP2': [nan, 472.78475000000003, 536.9282, 593.05135, 498.33439999999996], 'ACAP3': [nan, 105.5425, 122.0169, 118.8936, 109.5795], 'ACAT1': [nan, 1418.808, 2128.048, 2178.747, 1383.199], 'ACAT2': [nan, 5829.6573, 8009.3558, 9235.7839, 6269.3725], 'ACBD3': [nan, 792.5147, 707.7646, 821.9006, 651.4725], 'ACBD4': [nan, 116.9483, 114.2127, 130.7945, 116.3462], 'ACBD5': [nan, 335.84406, 386.9613, 384.7501, 347.3528], 'ACBD6': [nan, 294.0847, 447.3738, 438.7133, 323.8403], 'ACBD7': [nan, 275.0889, 256.9566, 239.14589999999998, 275.5903], 'ACCS': [nan, 135.77474999999998, 136.2971, 141.3605, 122.34215], 'ACCSL': [nan, 206.98340000000002, 231.2138, 212.174, 206.1576], 'ACD': [nan, 356.7945, 759.4478, 820.5231, 417.5334], 'ACE': [nan, 310.15061000000003, 325.44849999999997, 332.6893, 314.25441], 'ACE2': [nan, 104.7992, 112.2823, 113.9982, 114.378], 'ACER1': [nan, 200.34784000000002, 216.2197, 216.1014, 213.6288], 'ACER2': [nan, 245.13639999999998, 277.02250000000004, 278.9181, 235.05599999999998], 'ACER3': [nan, 379.30460000000005, 595.69875, 577.10325, 469.28485], 'ACHE': [nan, 312.007, 341.1714, 330.0686, 324.233], 'ACIN1': [nan, 538.4047, 876.7195, 873.2385, 521.09], 'ACKR1': [nan, 117.2341, 117.2374, 109.8885, 129.5887], 'ACKR3': [nan, 411.1073, 319.3056, 339.6739, 579.1382], 'ACKR4': [nan, 279.7897, 282.4379, 279.6092, 285.06675], 'ACLY': [nan, 5046.915, 7490.317999999999, 8021.534, 5367.784], 'ACMSD': [nan, 101.5186, 104.3334, 112.805, 105.1739], 'ACO1': [nan, 2704.575, 1822.965, 2948.169, 2343.681], 'ACO2': [nan, 309.6763, 486.8691, 441.1467, 291.112], 'ACOD1': [nan, 107.5264, 112.1882, 114.057, 102.6517], 'ACOT1': [nan, 325.764, 494.0932, 547.0611, 330.5185], 'ACOT11': [nan, 239.5196, 248.13410000000002, 244.81170000000003, 256.3442], 'ACOT12': [nan, 101.27, 108.6624, 106.4066, 106.0118], 'ACOT13': [nan, 426.3474, 449.2599, 504.1035, 464.311], 'ACOT2': [nan, 403.30535999999995, 686.6622, 756.7733999999999, 516.59824], 'ACOT4': [nan, 104.233, 134.941, 114.1054, 112.9567], 'ACOT6': [nan, 113.1718, 105.5607, 104.4147, 112.0292], 'ACOT7': [nan, 2941.2445, 2934.9715, 2398.5, 2910.23464], 'ACOT8': [nan, 143.9349, 204.7876, 205.0391, 173.1985], 'ACOT9': [nan, 849.2746, 1548.9562, 1675.1287, 906.6325], 'ACOX1': [nan, 477.11157, 474.4142, 509.66949999999997, 455.19759999999997], 'ACOX2': [nan, 169.1132, 288.7589, 286.3934, 185.2388], 'ACOX3': [nan, 259.6273, 342.5535, 296.2372, 230.3067], 'ACOXL': [nan, 97.84616, 105.4442, 107.8319, 104.6831], 'ACP1': [nan, 2866.4687, 3015.9168999999997, 3476.0848, 2744.6421], 'ACP2': [nan, 282.902, 588.5055, 702.43, 266.0626], 'ACP3': [nan, 113.4572, 114.2381, 108.6556, 120.091], 'ACP4': [nan, 248.3329, 239.4146, 230.3371, 250.4151], 'ACP5': [nan, 210.5559, 191.7413, 167.9056, 240.3664], 'ACP6': [nan, 219.1252, 278.9784, 368.548, 213.0223], 'ACR': [nan, 99.73406, 116.781, 111.4965, 102.0714], 'ACRBP': [nan, 106.2604, 110.3012, 112.7941, 106.7346], 'ACRV1': [nan, 218.7234, 226.57819999999998, 221.9029, 220.0448], 'ACSBG1': [nan, 113.3429, 119.4192, 116.9413, 108.0103], 'ACSBG2': [nan, 95.71718, 109.4799, 102.1405, 100.6268], 'ACSF2': [nan, 313.9211, 457.2722, 465.607, 274.3585], 'ACSF3': [nan, 119.8282, 113.2766, 116.8104, 118.9315], 'ACSL1': [nan, 160.9985, 135.9969, 133.7077, 145.4972], 'ACSL3': [nan, 4792.8655, 4232.3517, 3952.1996, 4971.7768], 'ACSL4': [nan, 1161.32195, 1521.9068, 1941.18452, 1003.0467000000001], 'ACSL5': [nan, 532.5928, 594.9697, 619.0324, 541.7263], 'ACSL6': [nan, 423.86933, 425.9394, 432.27049999999997, 429.7212], 'ACSM1': [nan, 100.1844, 104.9905, 100.5769, 102.1041], 'ACSM2A': [nan, 107.5662, 109.5413, 106.2736, 103.8411]}\n", "Linked data shape after handling missing values: (0, 1)\n", "Quartiles for 'Underweight':\n", " 25%: nan\n", " 50% (Median): nan\n", " 75%: nan\n", "Min: nan\n", "Max: nan\n", "The distribution of the feature 'Underweight' in this dataset is fine.\n", "\n", "Is trait biased: False\n", "Abnormality detected in the cohort: GSE50982. Preprocessing failed.\n", "Data quality check result: Not usable\n", "Data not saved due to quality issues.\n" ] } ], "source": [ "# 1. Normalize gene symbols in gene expression data\n", "gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Gene data shape after normalization: {gene_data.shape}\")\n", "print(f\"First few gene symbols after normalization: {list(gene_data.index[:10])}\")\n", "\n", "# Save the normalized gene data to CSV\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "gene_data.to_csv(out_gene_data_file)\n", "print(f\"Normalized gene data saved to {out_gene_data_file}\")\n", "\n", "# 2. Extract clinical features using the functions defined in Step 2\n", "clinical_features = geo_select_clinical_features(\n", " 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", "print(\"Clinical features extracted:\")\n", "print(preview_df(clinical_features))\n", "\n", "# Save the clinical data\n", "os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", "clinical_features.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(clinical_features, gene_data)\n", "print(f\"Linked data shape: {linked_data.shape}\")\n", "print(\"Linked data preview:\")\n", "print(preview_df(linked_data))\n", "\n", "# 4. Handle missing values\n", "linked_data = handle_missing_values(linked_data, trait)\n", "print(f\"Linked data shape after handling missing values: {linked_data.shape}\")\n", "\n", "# 5. Determine whether the trait and demographic features are biased\n", "is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)\n", "print(f\"Is trait biased: {is_trait_biased}\")\n", "\n", "# 6. Conduct quality check and save the cohort information\n", "note = \"This dataset contains data on 16p11.2 duplication carriers associated with underweight.\"\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=True,\n", " is_biased=is_trait_biased, \n", " df=linked_data,\n", " note=note\n", ")\n", "\n", "# 7. Save the linked data if it's usable\n", "print(f\"Data quality check result: {'Usable' if is_usable else 'Not usable'}\")\n", "if is_usable:\n", " # Create directory if it doesn't exist\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(f\"Data not saved due to quality issues.\")" ] } ], "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 }