{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4cec85f2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:10.173881Z", "iopub.status.busy": "2025-03-25T04:29:10.173708Z", "iopub.status.idle": "2025-03-25T04:29:10.380392Z", "shell.execute_reply": "2025-03-25T04:29:10.379866Z" } }, "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 = \"GSE57802\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Underweight\"\n", "in_cohort_dir = \"../../input/GEO/Underweight/GSE57802\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Underweight/GSE57802.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Underweight/gene_data/GSE57802.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Underweight/clinical_data/GSE57802.csv\"\n", "json_path = \"../../output/preprocess/Underweight/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "b15ae8dc", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "8bf51267", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:10.381979Z", "iopub.status.busy": "2025-03-25T04:29:10.381823Z", "iopub.status.idle": "2025-03-25T04:29:10.601385Z", "shell.execute_reply": "2025-03-25T04:29:10.600741Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Files in the cohort directory:\n", "['GSE57802_family.soft.gz', 'GSE57802_series_matrix.txt.gz']\n", "Identified SOFT files: ['GSE57802_family.soft.gz']\n", "Identified matrix files: ['GSE57802_series_matrix.txt.gz']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Background Information:\n", "!Series_title\t\"Transcriptome Profiling of patients with 16p11.2 rearrangements\"\n", "!Series_summary\t\"The 600kb BP4-BP5 16p11.2 CNV (copy number variant) is associated with neuroanatomical, neurocognitive and metabolic disorders. These recurrent rearrangements are associated with reciprocal phenotypes such as obesity and underweight, macro- and microcephaly, as well as autism spectrum disorder (ASD) and schizophrenia. Here we interrogated the transcriptome of individuals carrying reciprocal CNVs in 16p11.2.\"\n", "!Series_summary\t\"The genome-wide transcript perturbations correlated with clinical endophenotypes of the CNV and were enriched for genes associated with ASD. We uncovered a significant correlation between copy number changes and expression levels of genes mutated in ciliopathies.\"\n", "!Series_overall_design\t\"Transcriptome profiles of lymphoblastoid cell lines of 50 16p11.2 deletion carriers, 31 16p11.2 duplication carriers and 17 controls.\"\n", "\n", "Sample Characteristics Dictionary:\n", "{0: ['cell type: lymphoblastoid'], 1: ['gender: M', 'gender: F'], 2: ['age: 46', 'age: 33', 'age: NA', 'age: 22', 'age: 52', 'age: 25', 'age: 31', 'age: 60', 'age: 40', 'age: 50', 'age: 51', 'age: 39', 'age: 6', 'age: 56', 'age: 16', 'age: 41', 'age: 35', 'age: 4', 'age: 10', 'age: 12', 'age: 7', 'age: 1.4', 'age: 38', 'age: 14.7', 'age: 11', 'age: 12.8', 'age: 11.9', 'age: 7.7', 'age: 3.3', 'age: 1.5'], 3: ['copy number 16p11.2: 2', 'copy number 16p11.2: 1', 'copy number 16p11.2: 3'], 4: ['genotype: Control', 'genotype: 600kbdel', 'genotype: 600kbdup'], 5: ['family identifier: 201', 'family identifier: 202', 'family identifier: 203', 'family identifier: 204', 'family identifier: 205', 'family identifier: 206', 'family identifier: 207', 'family identifier: 208', 'family identifier: 209', 'family identifier: 210', 'family identifier: 211', 'family identifier: 212', 'family identifier: 213', 'family identifier: 84', 'family identifier: 63', 'family identifier: 1', 'family identifier: 4', 'family identifier: 5', 'family identifier: 8', 'family identifier: 11', 'family identifier: 12', 'family identifier: 13', 'family identifier: 14', 'family identifier: 15', 'family identifier: 17', 'family identifier: 20', 'family identifier: 23', 'family identifier: 24', 'family identifier: 26', 'family identifier: 28'], 6: ['kinship: unrelated', 'kinship: father', 'kinship: sibling', 'kinship: mother', 'kinship: proband', 'kinship: pat grandfather']}\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": "386309bb", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "9488c364", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:10.602709Z", "iopub.status.busy": "2025-03-25T04:29:10.602585Z", "iopub.status.idle": "2025-03-25T04:29:10.608276Z", "shell.execute_reply": "2025-03-25T04:29:10.607811Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Trait row: 4\n", "Age row: 2\n", "Gender row: 1\n", "Conversion functions defined for trait, age, and gender.\n", "is_gene_available: True\n", "is_trait_available: True\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset contains transcriptome profiles\n", "# which suggests gene expression data is available\n", "is_gene_available = True\n", "\n", "# 2. Clinical Feature Extraction\n", "\n", "# 2.1 Data Availability\n", "# For trait (Underweight):\n", "# From background info, we see that the dataset includes data on 16p11.2 CNV which is associated with\n", "# underweight/obesity. The key 3 'copy number 16p11.2' or key 4 'genotype' can be used to determine underweight.\n", "# We'll use key 4 as it's more specific and differentiates between deletion (del) and duplication (dup)\n", "trait_row = 4\n", "\n", "# For age:\n", "# Age information is available under key 2\n", "age_row = 2\n", "\n", "# For gender:\n", "# Gender information is available under key 1\n", "gender_row = 1\n", "\n", "# 2.2 Data Type Conversion Functions\n", "\n", "def convert_trait(value):\n", " \"\"\"Convert genotype information to binary trait (Underweight).\"\"\"\n", " if not value or 'genotype:' not in value:\n", " return None\n", " # Extract value after the colon and strip whitespace\n", " genotype = value.split('genotype:')[1].strip()\n", " \n", " # Based on background information, 16p11.2 duplication is associated with underweight\n", " # and deletion with obesity. So duplication = 1 (presence of underweight trait)\n", " if genotype == '600kbdup':\n", " return 1\n", " elif genotype == '600kbdel' or genotype == 'Control':\n", " return 0\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age information to continuous numeric values.\"\"\"\n", " if not value or 'age:' not in value:\n", " return None\n", " # Extract value after the colon and strip whitespace\n", " age_str = value.split('age:')[1].strip()\n", " if age_str == 'NA':\n", " return None\n", " try:\n", " # Convert to float to handle decimal ages\n", " return float(age_str)\n", " except ValueError:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender information to binary (0=female, 1=male).\"\"\"\n", " if not value or 'gender:' not in value:\n", " return None\n", " # Extract value after the colon and strip whitespace\n", " gender = value.split('gender:')[1].strip()\n", " if gender == 'F':\n", " return 0\n", " elif gender == 'M':\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata - Conduct initial filtering\n", "# Check if trait data is available\n", "is_trait_available = trait_row is not None\n", "# Save the information using the library function\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", "# For now, just define the variables and functions for later use\n", "# since we don't have access to the clinical data yet\n", "# The actual extraction will be done in a subsequent step\n", "print(f\"Trait row: {trait_row}\")\n", "print(f\"Age row: {age_row}\")\n", "print(f\"Gender row: {gender_row}\")\n", "print(\"Conversion functions defined for trait, age, and gender.\")\n", "print(f\"is_gene_available: {is_gene_available}\")\n", "print(f\"is_trait_available: {is_trait_available}\")\n" ] }, { "cell_type": "markdown", "id": "96114ff1", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "3cf058c4", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:10.609423Z", "iopub.status.busy": "2025-03-25T04:29:10.609309Z", "iopub.status.idle": "2025-03-25T04:29:11.002438Z", "shell.execute_reply": "2025-03-25T04:29:11.002073Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First 20 gene/probe identifiers:\n", "Index(['1007_PM_s_at', '1053_PM_at', '117_PM_at', '121_PM_at', '1255_PM_g_at',\n", " '1294_PM_at', '1316_PM_at', '1320_PM_at', '1405_PM_i_at', '1431_PM_at',\n", " '1438_PM_at', '1487_PM_at', '1494_PM_f_at', '1552256_PM_a_at',\n", " '1552257_PM_a_at', '1552258_PM_at', '1552261_PM_at', '1552263_PM_at',\n", " '1552264_PM_a_at', '1552266_PM_at'],\n", " dtype='object', name='ID')\n", "\n", "Gene expression data shape: (54715, 99)\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": "26128b81", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "f504e6cc", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:11.003627Z", "iopub.status.busy": "2025-03-25T04:29:11.003510Z", "iopub.status.idle": "2025-03-25T04:29:11.005442Z", "shell.execute_reply": "2025-03-25T04:29:11.005138Z" } }, "outputs": [], "source": [ "# These identifiers (1007_PM_s_at, 1053_PM_at, etc.) are Affymetrix probe IDs\n", "# from the Affymetrix GeneChip Human Genome U133 Plus 2.0 Array\n", "# They are not human gene symbols and need to be mapped to gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "17c3b756", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "962e1cb9", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:11.006437Z", "iopub.status.busy": "2025-03-25T04:29:11.006332Z", "iopub.status.idle": "2025-03-25T04:29:18.214113Z", "shell.execute_reply": "2025-03-25T04:29:18.213540Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['1007_PM_s_at', '1053_PM_at', '117_PM_at', '121_PM_at', '1255_PM_g_at'], 'GB_ACC': ['U48705', 'M87338', 'X51757', 'X69699', 'L36861'], 'SPOT_ID': [nan, nan, nan, nan, nan], 'Species Scientific Name': ['Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens'], 'Annotation Date': ['Aug 20, 2010', 'Aug 20, 2010', 'Aug 20, 2010', 'Aug 20, 2010', 'Aug 20, 2010'], 'Sequence Type': ['Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence'], 'Sequence Source': ['Affymetrix Proprietary Database', 'GenBank', 'Affymetrix Proprietary Database', 'GenBank', 'Affymetrix Proprietary Database'], 'Target Description': ['U48705 /FEATURE=mRNA /DEFINITION=HSU48705 Human receptor tyrosine kinase DDR gene, complete cds', 'M87338 /FEATURE= /DEFINITION=HUMA1SBU Human replication factor C, 40-kDa subunit (A1) mRNA, complete cds', \"X51757 /FEATURE=cds /DEFINITION=HSP70B Human heat-shock protein HSP70B' gene\", 'X69699 /FEATURE= /DEFINITION=HSPAX8A H.sapiens Pax8 mRNA', 'L36861 /FEATURE=expanded_cds /DEFINITION=HUMGCAPB Homo sapiens guanylate cyclase activating protein (GCAP) gene exons 1-4, complete cds'], 'Representative Public ID': ['U48705', 'M87338', 'X51757', 'X69699', 'L36861'], 'Gene Title': ['discoidin domain receptor tyrosine kinase 1', 'replication factor C (activator 1) 2, 40kDa', \"heat shock 70kDa protein 6 (HSP70B')\", 'paired box 8', 'guanylate cyclase activator 1A (retina)'], 'Gene Symbol': ['DDR1', 'RFC2', 'HSPA6', 'PAX8', 'GUCA1A'], 'ENTREZ_GENE_ID': ['780', '5982', '3310', '7849', '2978'], 'RefSeq Transcript ID': ['NM_001954 /// NM_013993 /// NM_013994', 'NM_002914 /// NM_181471', 'NM_002155', 'NM_003466 /// NM_013951 /// NM_013952 /// NM_013953 /// NM_013992', 'NM_000409'], 'Gene Ontology Biological Process': ['0001558 // regulation of cell growth // inferred from electronic annotation /// 0001952 // regulation of cell-matrix adhesion // inferred from electronic annotation /// 0006468 // protein amino acid phosphorylation // inferred from electronic annotation /// 0007155 // cell adhesion // inferred from electronic annotation /// 0007155 // cell adhesion // traceable author statement /// 0007169 // transmembrane receptor protein tyrosine kinase signaling pathway // inferred from electronic annotation /// 0007566 // embryo implantation // inferred from electronic annotation /// 0008285 // negative regulation of cell proliferation // inferred from electronic annotation /// 0018108 // peptidyl-tyrosine phosphorylation // inferred from electronic annotation /// 0031100 // organ regeneration // inferred from electronic annotation /// 0043583 // ear development // inferred from electronic annotation /// 0043588 // skin development // inferred from electronic annotation /// 0051789 // response to protein stimulus // inferred from electronic annotation /// 0060444 // branching involved in mammary gland duct morphogenesis // inferred from electronic annotation /// 0060749 // mammary gland alveolus development // inferred from electronic annotation', '0006260 // DNA replication // not recorded /// 0006260 // DNA replication // inferred from electronic annotation /// 0006297 // nucleotide-excision repair, DNA gap filling // not recorded /// 0015979 // photosynthesis // inferred from electronic annotation /// 0015995 // chlorophyll biosynthetic process // inferred from electronic annotation', '0006950 // response to stress // inferred from electronic annotation /// 0006986 // response to unfolded protein // traceable author statement', '0001656 // metanephros development // inferred from electronic annotation /// 0006350 // transcription // inferred from electronic annotation /// 0007275 // multicellular organismal development // inferred from electronic annotation /// 0009653 // anatomical structure morphogenesis // traceable author statement /// 0030154 // cell differentiation // inferred from electronic annotation /// 0030878 // thyroid gland development // inferred from electronic annotation /// 0045449 // regulation of transcription // inferred from electronic annotation /// 0045893 // positive regulation of transcription, DNA-dependent // inferred from sequence or structural similarity /// 0045893 // positive regulation of transcription, DNA-dependent // inferred from direct assay /// 0045944 // positive regulation of transcription from RNA polymerase II promoter // inferred from electronic annotation', '0007165 // signal transduction // non-traceable author statement /// 0007601 // visual perception // inferred from electronic annotation /// 0007601 // visual perception // traceable author statement /// 0007602 // phototransduction // inferred from electronic annotation /// 0031282 // regulation of guanylate cyclase activity // inferred from electronic annotation /// 0050896 // response to stimulus // inferred from electronic annotation'], 'Gene Ontology Cellular Component': ['0005576 // extracellular region // inferred from electronic annotation /// 0005886 // plasma membrane // inferred from electronic annotation /// 0005887 // integral to plasma membrane // traceable author statement /// 0016020 // membrane // inferred from electronic annotation /// 0016021 // integral to membrane // inferred from electronic annotation /// 0016323 // basolateral plasma membrane // inferred from electronic annotation', '0005634 // nucleus // inferred from electronic annotation /// 0005654 // nucleoplasm // not recorded /// 0005663 // DNA replication factor C complex // inferred from direct assay /// 0005663 // DNA replication factor C complex // inferred from electronic annotation', nan, '0005634 // nucleus // inferred from electronic annotation /// 0005654 // nucleoplasm // inferred from sequence or structural similarity /// 0005654 // nucleoplasm // inferred from electronic annotation', '0016020 // membrane // inferred from electronic annotation'], 'Gene Ontology Molecular Function': ['0000166 // nucleotide binding // inferred from electronic annotation /// 0004672 // protein kinase activity // inferred from electronic annotation /// 0004713 // protein tyrosine kinase activity // inferred from electronic annotation /// 0004714 // transmembrane receptor protein tyrosine kinase activity // inferred from electronic annotation /// 0004714 // transmembrane receptor protein tyrosine kinase activity // traceable author statement /// 0004872 // receptor activity // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0005515 // protein binding // inferred from electronic annotation /// 0005524 // ATP binding // inferred from electronic annotation /// 0016301 // kinase activity // inferred from electronic annotation /// 0016740 // transferase activity // inferred from electronic annotation', '0000166 // nucleotide binding // inferred from electronic annotation /// 0003677 // DNA binding // inferred from electronic annotation /// 0003689 // DNA clamp loader activity // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0005524 // ATP binding // inferred from electronic annotation /// 0005524 // ATP binding // traceable author statement /// 0016851 // magnesium chelatase activity // inferred from electronic annotation /// 0017111 // nucleoside-triphosphatase activity // inferred from electronic annotation', '0000166 // nucleotide binding // inferred from electronic annotation /// 0005524 // ATP binding // inferred from electronic annotation', '0003677 // DNA binding // inferred from direct assay /// 0003677 // DNA binding // inferred from electronic annotation /// 0003700 // transcription factor activity // traceable author statement /// 0004996 // thyroid-stimulating hormone receptor activity // traceable author statement /// 0005515 // protein binding // inferred from sequence or structural similarity /// 0005515 // protein binding // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0016563 // transcription activator activity // inferred from sequence or structural similarity /// 0016563 // transcription activator activity // inferred from direct assay /// 0016563 // transcription activator activity // inferred from electronic annotation /// 0043565 // sequence-specific DNA binding // inferred from electronic annotation', '0005509 // calcium ion binding // inferred from electronic annotation /// 0008048 // calcium sensitive guanylate cyclase activator activity // traceable author statement /// 0008048 // calcium sensitive guanylate cyclase activator activity // inferred from electronic annotation /// 0030249 // guanylate cyclase regulator activity // inferred from electronic annotation']}\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": "08e144d4", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "01b76e46", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:18.215639Z", "iopub.status.busy": "2025-03-25T04:29:18.215505Z", "iopub.status.idle": "2025-03-25T04:29:19.657543Z", "shell.execute_reply": "2025-03-25T04:29:19.656885Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping dataframe shape: (41796, 2)\n", "First few rows of the gene mapping dataframe:\n", " ID Gene\n", "0 1007_PM_s_at DDR1\n", "1 1053_PM_at RFC2\n", "2 117_PM_at HSPA6\n", "3 121_PM_at PAX8\n", "4 1255_PM_g_at GUCA1A\n", "Gene expression data shape after mapping: (18989, 99)\n", "First few rows of the gene expression data after mapping:\n", " GSM1389621 GSM1389622 GSM1389623 GSM1389624 GSM1389625 GSM1389626 \\\n", "Gene \n", "A1BG 5.1530 4.2584 4.5459 4.9238 5.1245 5.0254 \n", "A1CF 3.1398 3.1938 3.2668 3.3192 3.1315 2.8158 \n", "A2BP1 11.9172 12.2129 11.5026 11.8598 12.2363 12.2537 \n", "A2LD1 8.1127 7.3163 7.9812 7.6193 8.3075 8.1315 \n", "A2M 6.0117 4.9206 5.4258 5.1350 5.4096 5.1066 \n", "\n", " GSM1389627 GSM1389628 GSM1389629 GSM1389630 ... GSM1389710 \\\n", "Gene ... \n", "A1BG 4.9052 4.7084 4.7691 4.8557 ... 4.8641 \n", "A1CF 3.2405 2.9256 3.0895 3.0603 ... 3.0214 \n", "A2BP1 12.3472 11.8402 12.0957 11.5131 ... 11.9211 \n", "A2LD1 7.5114 8.2257 7.9985 7.9282 ... 8.0998 \n", "A2M 5.3594 4.8987 5.6223 5.2235 ... 5.1128 \n", "\n", " GSM1389711 GSM1389712 GSM1389713 GSM1389714 GSM1389715 GSM1389716 \\\n", "Gene \n", "A1BG 5.3607 5.0123 4.6514 5.1240 4.1753 4.6768 \n", "A1CF 2.9654 3.1095 3.0851 3.0848 2.8349 3.1181 \n", "A2BP1 11.9108 11.7283 11.6747 12.6372 11.8298 12.1305 \n", "A2LD1 8.1618 7.7818 8.1840 7.9099 7.6905 7.7111 \n", "A2M 5.6892 5.5955 5.5182 5.6262 5.5216 5.3034 \n", "\n", " GSM1389717 GSM1389718 GSM1389719 \n", "Gene \n", "A1BG 4.2457 5.4619 4.6868 \n", "A1CF 2.9969 2.9435 3.0805 \n", "A2BP1 11.8877 11.9019 11.8521 \n", "A2LD1 7.5684 7.8571 6.9150 \n", "A2M 4.7599 5.5409 5.4744 \n", "\n", "[5 rows x 99 columns]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to ../../output/preprocess/Underweight/gene_data/GSE57802.csv\n" ] } ], "source": [ "# 1. Identify the columns in the gene annotation dataframe that store gene identifiers and gene symbols\n", "# From the preview, we can see that 'ID' contains the probe identifiers matching those in the gene expression data\n", "# 'Gene Symbol' contains the corresponding gene symbols\n", "prob_col = 'ID'\n", "gene_col = 'Gene Symbol'\n", "\n", "# 2. Get a gene mapping dataframe by extracting these two columns\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col)\n", "print(f\"Gene mapping dataframe shape: {gene_mapping.shape}\")\n", "print(\"First few rows of the gene mapping dataframe:\")\n", "print(gene_mapping.head())\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene expression data\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "print(f\"Gene expression data shape after mapping: {gene_data.shape}\")\n", "print(\"First few rows of the gene expression data after mapping:\")\n", "print(gene_data.head())\n", "\n", "# Save the gene expression data to a file\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\"Gene expression data saved to {out_gene_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "eccfba3c", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "c9ae7ad3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:29:19.658980Z", "iopub.status.busy": "2025-03-25T04:29:19.658843Z", "iopub.status.idle": "2025-03-25T04:29:32.475350Z", "shell.execute_reply": "2025-03-25T04:29:32.474693Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape after normalization: (18622, 99)\n", "First few gene symbols after normalization: ['A1BG', 'A1BG-AS1', 'A1CF', 'A2M', 'A2ML1', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS', 'AACS']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Underweight/gene_data/GSE57802.csv\n", "Clinical features extracted:\n", "{'GSM1389621': [0.0, 46.0, 1.0], 'GSM1389622': [0.0, 33.0, 0.0], 'GSM1389623': [0.0, nan, 1.0], 'GSM1389624': [0.0, nan, 0.0], 'GSM1389625': [0.0, 22.0, 1.0], 'GSM1389626': [0.0, 52.0, 1.0], 'GSM1389627': [0.0, 25.0, 1.0], 'GSM1389628': [0.0, 31.0, 0.0], 'GSM1389629': [0.0, 60.0, 1.0], 'GSM1389630': [0.0, nan, 1.0], 'GSM1389631': [0.0, 40.0, 1.0], 'GSM1389632': [0.0, 50.0, 1.0], 'GSM1389633': [0.0, 51.0, 1.0], 'GSM1389634': [0.0, 39.0, 1.0], 'GSM1389635': [0.0, 6.0, 1.0], 'GSM1389636': [0.0, 51.0, 1.0], 'GSM1389637': [0.0, 56.0, 0.0], 'GSM1389638': [0.0, 16.0, 1.0], 'GSM1389639': [0.0, 41.0, 1.0], 'GSM1389640': [0.0, 31.0, 0.0], 'GSM1389641': [0.0, 35.0, 1.0], 'GSM1389642': [0.0, 4.0, 1.0], 'GSM1389643': [0.0, 10.0, 0.0], 'GSM1389644': [0.0, 12.0, 0.0], 'GSM1389645': [0.0, 7.0, 1.0], 'GSM1389646': [0.0, 6.0, 1.0], 'GSM1389647': [0.0, 1.4, 1.0], 'GSM1389648': [0.0, 10.0, 0.0], 'GSM1389649': [0.0, 6.0, 1.0], 'GSM1389650': [0.0, 38.0, 1.0], 'GSM1389651': [0.0, 14.7, 1.0], 'GSM1389652': [0.0, 11.0, 0.0], 'GSM1389653': [0.0, 7.0, 0.0], 'GSM1389654': [0.0, 12.8, 1.0], 'GSM1389655': [0.0, 11.9, 0.0], 'GSM1389656': [0.0, 7.7, 0.0], 'GSM1389657': [0.0, 3.3, 1.0], 'GSM1389658': [0.0, 1.5, 1.0], 'GSM1389659': [0.0, 16.0, 1.0], 'GSM1389660': [0.0, 40.0, 0.0], 'GSM1389661': [0.0, 39.0, 0.0], 'GSM1389662': [0.0, 12.0, 1.0], 'GSM1389663': [0.0, 5.9, 1.0], 'GSM1389664': [0.0, 4.1, 0.0], 'GSM1389665': [0.0, 5.2, 1.0], 'GSM1389666': [0.0, 9.0, 1.0], 'GSM1389667': [0.0, 37.0, 1.0], 'GSM1389668': [0.0, 14.8, 1.0], 'GSM1389669': [0.0, 15.0, 1.0], 'GSM1389670': [0.0, 5.7, 1.0], 'GSM1389671': [0.0, 23.0, 1.0], 'GSM1389672': [0.0, 6.8, 1.0], 'GSM1389673': [0.0, 53.0, 1.0], 'GSM1389674': [0.0, 8.8, 1.0], 'GSM1389675': [0.0, 6.8, 1.0], 'GSM1389676': [0.0, 26.0, 0.0], 'GSM1389677': [0.0, 21.0, 1.0], 'GSM1389678': [0.0, 13.0, 1.0], 'GSM1389679': [0.0, 12.0, 0.0], 'GSM1389680': [0.0, 21.0, 0.0], 'GSM1389681': [0.0, 10.0, 1.0], 'GSM1389682': [0.0, 15.0, 0.0], 'GSM1389683': [0.0, 11.0, 1.0], 'GSM1389684': [0.0, 5.5, 1.0], 'GSM1389685': [0.0, 3.7, 1.0], 'GSM1389686': [0.0, 4.0, 1.0], 'GSM1389687': [0.0, 7.0, 0.0], 'GSM1389688': [1.0, 5.0, 1.0], 'GSM1389689': [1.0, 5.0, 0.0], 'GSM1389690': [1.0, 42.0, 0.0], 'GSM1389691': [1.0, 42.0, 0.0], 'GSM1389692': [1.0, 5.0, 1.0], 'GSM1389693': [1.0, 8.0, 0.0], 'GSM1389694': [1.0, 15.0, 0.0], 'GSM1389695': [1.0, 3.4, 0.0], 'GSM1389696': [1.0, 44.0, 0.0], 'GSM1389697': [1.0, 16.0, 0.0], 'GSM1389698': [1.0, 52.0, 0.0], 'GSM1389699': [1.0, 28.0, 0.0], 'GSM1389700': [1.0, 0.6, 1.0], 'GSM1389701': [1.0, 14.0, 0.0], 'GSM1389702': [1.0, 1.8, 0.0], 'GSM1389703': [1.0, 40.0, 1.0], 'GSM1389704': [1.0, 9.0, 1.0], 'GSM1389705': [1.0, 5.2, 0.0], 'GSM1389706': [1.0, 5.5, 1.0], 'GSM1389707': [1.0, 28.0, 0.0], 'GSM1389708': [1.0, 42.0, 1.0], 'GSM1389709': [1.0, 12.8, 0.0], 'GSM1389710': [1.0, 36.0, 0.0], 'GSM1389711': [1.0, 3.0, 0.0], 'GSM1389712': [1.0, 41.0, 0.0], 'GSM1389713': [1.0, 6.0, 1.0], 'GSM1389714': [1.0, 76.0, 1.0], 'GSM1389715': [1.0, 47.0, 1.0], 'GSM1389716': [1.0, 44.0, 0.0], 'GSM1389717': [1.0, 3.0, 0.0], 'GSM1389718': [1.0, 34.0, 0.0], 'GSM1389719': [1.0, 11.0, 1.0]}\n", "Clinical data saved to ../../output/preprocess/Underweight/clinical_data/GSE57802.csv\n", "Linked data shape: (99, 18625)\n", "Linked data preview:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'Underweight': [0.0, 0.0, 0.0, 0.0, 0.0], 'Age': [46.0, 33.0, nan, nan, 22.0], 'Gender': [1.0, 0.0, 1.0, 0.0, 1.0], 'A1BG': [5.153, 4.2584, 4.5459, 4.9238, 5.1245], 'A1BG-AS1': [4.4607, 4.087, 4.518, 4.7735, 4.4022], 'A1CF': [3.1398, 3.1938, 3.2668, 3.3192, 3.1315], 'A2M': [6.011699999999999, 4.9206, 5.425800000000001, 5.135, 5.409599999999999], 'A2ML1': [5.9201999999999995, 5.6129999999999995, 5.434799999999999, 5.4277999999999995, 5.3739], 'A4GALT': [3.5943, 3.7949, 3.6152, 3.1873, 3.7345], 'A4GNT': [3.1132, 3.0257, 3.019, 3.1873, 3.133], 'AAA1': [5.8944, 6.0103, 5.616, 5.5187, 5.4543], 'AAAS': [4.5034, 4.3817, 4.6228, 4.5142, 4.6848], 'AACS': [8.0014, 8.192, 7.9628, 7.7601, 8.2706], 'AACSP1': [2.4715, 2.7737, 2.7885, 3.0716, 2.7716], 'AADAC': [2.8244, 2.771, 2.9491, 2.6525, 2.9194], 'AADACL2': [2.6007, 2.6733, 2.6212, 2.5502, 2.4922], 'AADAT': [3.3793, 2.9596, 2.9957, 3.0025, 2.8109], 'AAGAB': [16.0607, 16.642, 17.156200000000002, 15.819600000000001, 16.7413], 'AAK1': [29.1696, 31.4883, 31.125, 30.3352, 30.725199999999997], 'AAMDC': [13.081800000000001, 14.7146, 13.9723, 13.4071, 13.999000000000002], 'AAMP': [7.3665, 7.5039, 7.7629, 7.5155, 7.5267], 'AANAT': [2.5787, 2.5289, 2.7375, 2.6636, 2.4102], 'AAR2': [7.161, 7.1564, 7.2273, 7.0735, 6.9017], 'AARS1': [9.5959, 9.2678, 9.2509, 9.2162, 9.6626], 'AARS2': [11.3488, 11.5253, 11.5121, 11.4919, 11.278500000000001], 'AARSD1': [10.537600000000001, 9.8322, 10.1164, 11.0901, 9.8003], 'AASDH': [14.437, 14.4663, 13.8337, 14.126999999999999, 14.4678], 'AASDHPPT': [20.9827, 22.0385, 20.828100000000003, 21.0915, 20.6067], 'AASS': [6.507, 7.052300000000001, 6.4626, 6.0059000000000005, 6.1671], 'AATF': [9.6622, 9.6131, 9.6978, 9.6625, 9.817], 'AATK': [3.0957, 2.7927, 3.1333, 3.1287, 3.1385], 'ABAT': [15.5409, 13.9949, 16.1015, 16.838900000000002, 16.3315], 'ABCA1': [13.554300000000001, 10.8706, 11.8642, 11.0493, 11.551400000000001], 'ABCA11P': [4.056, 4.0175, 4.2263, 5.0346, 4.0879], 'ABCA12': [2.9564, 2.8586, 2.8957, 5.4941, 3.068], 'ABCA13': [7.3281, 7.3948, 7.4101, 7.3507, 7.5553], 'ABCA17P': [2.5947, 2.7928, 2.5794, 2.508, 2.8762], 'ABCA2': [9.4271, 9.4336, 9.2569, 9.1854, 10.1561], 'ABCA3': [4.8302, 3.831, 4.3393, 4.1996, 4.5992], 'ABCA4': [5.2667, 5.365, 5.1358, 4.9246, 5.0384], 'ABCA5': [12.9824, 12.3712, 13.6427, 12.9855, 13.385], 'ABCA6': [6.5463, 6.3064, 7.1399, 7.7402, 6.2786], 'ABCA7': [4.7003, 5.1435, 5.3641, 4.8281, 4.8931], 'ABCA8': [7.9828, 8.1354, 8.2576, 8.3611, 7.9543], 'ABCA9': [7.577500000000001, 8.2905, 8.3246, 8.0793, 7.6556999999999995], 'ABCB1': [11.42155, 10.33225, 13.247, 9.37405, 10.46565], 'ABCB10': [8.657, 8.9125, 8.9748, 9.2568, 8.9819], 'ABCB11': [5.3321000000000005, 5.4831, 5.6292, 5.3877, 5.382], 'ABCB4': [15.44445, 14.71635, 15.8702, 15.53895, 15.726849999999999], 'ABCB5': [10.4115, 10.620899999999999, 10.169, 10.7046, 10.2927], 'ABCB6': [8.2566, 8.3855, 8.741900000000001, 8.886700000000001, 8.7934], 'ABCB7': [9.0387, 9.0191, 8.6585, 9.0705, 9.3277], 'ABCB8': [7.193199999999999, 6.32, 6.716200000000001, 6.9868, 6.928800000000001], 'ABCB9': [11.6051, 10.8867, 10.4396, 10.121, 11.6064], 'ABCC1': [13.288699999999999, 12.743599999999999, 12.995999999999999, 13.569199999999999, 13.2332], 'ABCC10': [13.2752, 13.490300000000001, 13.8454, 12.052700000000002, 13.4703], 'ABCC11': [5.6888000000000005, 5.3725, 5.9897, 5.6296, 5.6208], 'ABCC12': [5.553100000000001, 5.2805, 5.8416, 5.6149000000000004, 5.293900000000001], 'ABCC13': [10.169, 10.1665, 9.8232, 10.014199999999999, 10.0052], 'ABCC2': [2.746, 2.94, 2.9898, 2.9857, 3.0747], 'ABCC3': [18.9837, 18.1184, 18.3149, 18.543, 19.4973], 'ABCC4': [22.011899999999997, 21.7546, 20.5683, 21.6347, 23.140800000000002], 'ABCC5': [11.7747, 12.0808, 12.1767, 12.3387, 10.9055], 'ABCC6': [6.97275, 6.41565, 6.85825, 6.53825, 7.04935], 'ABCC6P1': [2.2831, 2.4348, 2.4444, 2.3819, 2.4916], 'ABCC6P2': [1.39695, 1.24015, 1.32865, 1.36035, 1.34615], 'ABCC8': [6.014, 6.1005, 6.0123, 6.093, 6.3261], 'ABCC9': [13.7439, 13.1481, 13.8748, 14.013300000000001, 14.1035], 'ABCD1': [6.0569, 5.8618, 6.4569, 6.7078, 6.2574], 'ABCD2': [3.0602, 2.9885, 3.801, 2.8871, 3.103], 'ABCD3': [13.265899999999998, 13.610800000000001, 13.8077, 12.6692, 12.8916], 'ABCD4': [9.3511, 9.918, 9.7738, 9.3038, 9.375599999999999], 'ABCE1': [18.793300000000002, 19.0591, 18.8632, 20.1371, 18.9409], 'ABCF1': [9.1403, 8.6862, 8.9951, 8.8071, 8.7177], 'ABCF2': [22.8027, 22.7715, 22.6173, 23.2997, 22.814799999999998], 'ABCF3': [6.3608, 6.2232, 6.4826, 6.056, 6.2038], 'ABCG1': [12.8209, 11.141200000000001, 12.4037, 11.418500000000002, 13.1796], 'ABCG2': [2.8414, 2.7964, 3.001, 3.0776, 2.9735], 'ABCG4': [2.982, 2.8347, 2.8356, 2.6242, 2.8143], 'ABCG5': [2.6248, 2.5271, 2.4645, 2.6611, 2.4888], 'ABCG8': [3.2994, 3.2944, 3.4185, 2.9659, 3.2957], 'ABHD1': [7.9338, 7.7014, 7.8826, 7.9954, 8.0998], 'ABHD10': [15.1027, 16.1522, 16.0656, 16.3011, 16.022399999999998], 'ABHD11': [12.241399999999999, 12.0992, 12.1786, 12.2185, 11.85], 'ABHD12': [16.8212, 15.508199999999999, 14.2347, 16.4357, 13.5397], 'ABHD12B': [5.274100000000001, 5.2128, 5.213, 5.3266, 5.3167], 'ABHD13': [11.438600000000001, 11.9225, 11.21, 11.5573, 11.2297], 'ABHD14A': [5.0396, 5.1538, 5.3578, 4.4299, 5.1568], 'ABHD14B': [6.7271, 6.5802, 6.5248, 7.1234, 7.2183], 'ABHD15': [4.1137, 3.5197, 4.475, 3.9272, 3.7791], 'ABHD16A': [10.3185, 9.7146, 9.8902, 9.3536, 9.9208], 'ABHD16B': [2.9032, 2.7472, 2.9133, 2.9169, 2.7266], 'ABHD17A': [8.5871, 8.903, 8.7975, 8.3965, 8.5974], 'ABHD17B': [17.3679, 17.768099999999997, 17.4436, 17.7749, 16.8181], 'ABHD17C': [5.1227, 5.492, 4.4434, 6.6319, 4.6023], 'ABHD18': [11.4252, 11.7725, 12.1783, 11.4434, 11.579799999999999], 'ABHD2': [30.3354, 31.7792, 32.722300000000004, 31.3429, 29.5016], 'ABHD3': [8.8955, 9.3315, 9.183, 8.9754, 9.0425], 'ABHD4': [8.2088, 8.1777, 8.642800000000001, 7.3848, 7.378399999999999], 'ABHD5': [16.2369, 17.0897, 17.1552, 15.609, 15.961], 'ABHD6': [17.8031, 14.5827, 18.3505, 23.4148, 15.860800000000001], 'ABHD8': [3.3455, 2.9301, 3.0925, 2.939, 3.2089], 'ABI1': [21.8004, 22.5554, 21.476399999999998, 22.275100000000002, 22.0713], 'ABI2': [36.7954, 37.6382, 37.924099999999996, 38.1406, 37.1614], 'ABI3': [6.1547, 6.4737, 6.3396, 6.4126, 6.5856], 'ABI3BP': [7.96, 7.4178, 7.947100000000001, 8.0239, 8.1839], 'ABITRAM': [7.5757, 7.2216, 7.5356, 7.3076, 7.4096], 'ABL1': [7.8097, 7.938, 8.0571, 8.3155, 7.7845], 'ABL2': [15.7394, 14.863399999999999, 14.9515, 15.826699999999999, 15.179400000000001], 'ABLIM1': [15.005700000000001, 13.6075, 14.791899999999998, 14.694600000000001, 15.186], 'ABLIM2': [15.1861, 15.3244, 16.0382, 15.9956, 15.8927], 'ABLIM3': [2.8858, 2.6609, 2.8046, 2.5746, 2.8759], 'ABO': [8.661100000000001, 8.264299999999999, 8.1136, 8.308399999999999, 8.2558], 'ABR': [11.0137, 11.1201, 10.755600000000001, 10.5982, 10.3804], 'ABRA': [5.5252, 5.2075, 5.2885, 5.3662, 5.5038], 'ABRACL': [10.4949, 10.9451, 10.491, 10.9074, 10.4579], 'ABRAXAS1': [10.761500000000002, 11.3357, 11.184000000000001, 11.3745, 10.9333], 'ABRAXAS2': [15.1736, 14.5762, 15.4571, 14.885200000000001, 15.220200000000002], 'ABT1': [7.3856, 7.2854, 7.3648, 7.3931, 7.1847], 'ABTB1': [16.494, 16.1921, 15.7534, 16.369, 16.3244], 'ABTB2': [9.6619, 9.8183, 9.8744, 7.479699999999999, 9.6784], 'ABTB3': [5.5189, 5.329, 5.6152999999999995, 5.6917, 5.4689], 'ACAA1': [16.7626, 16.469, 17.0394, 16.8607, 16.3062], 'ACAA2': [13.1207, 12.5199, 12.4437, 12.5138, 12.7978], 'ACACA': [14.0461, 14.402099999999999, 13.9405, 14.3108, 14.415500000000002], 'ACACB': [19.6766, 19.9388, 20.6324, 17.9555, 19.0795], 'ACAD10': [12.9327, 13.7109, 13.3687, 13.0098, 12.9082], 'ACAD11': [3.7473, 3.70855, 3.80995, 3.69075, 3.9692], 'ACAD8': [7.5567, 7.5111, 7.9202, 7.4884, 7.4258], 'ACAD9': [9.6189, 9.9621, 10.1449, 10.8285, 10.2395], 'ACADL': [5.3306000000000004, 5.429, 5.2566, 5.414899999999999, 5.3238], 'ACADM': [11.3743, 11.4386, 11.4445, 11.3227, 11.2313], 'ACADS': [5.4131, 5.5254, 5.815, 5.6231, 5.4729], 'ACADSB': [13.2299, 13.2865, 12.8381, 13.5073, 13.3777], 'ACADVL': [8.7876, 8.4381, 8.4511, 8.4325, 8.5656], 'ACAN': [11.6016, 11.534, 10.89, 11.2949, 10.7615], 'ACAP1': [15.6968, 15.5595, 15.1815, 15.331, 15.9702], 'ACAP2': [16.343, 16.6316, 16.1824, 16.1313, 16.1168], 'ACAP3': [6.896800000000001, 7.0713, 7.4311, 6.9138, 7.1297], 'ACAT1': [16.0743, 15.706499999999998, 15.8846, 16.6755, 16.5711], 'ACAT2': [9.5206, 9.7362, 9.3854, 9.8237, 9.3553], 'ACBD3': [16.4576, 15.556899999999999, 15.7214, 13.162500000000001, 15.5718], 'ACBD4': [3.909, 3.7277, 3.8311, 3.6876, 3.9026], 'ACBD5': [14.0034, 14.0008, 14.1897, 13.6981, 13.956], 'ACBD6': [8.1126, 8.1534, 7.8636, 8.2134, 8.1714], 'ACCS': [4.7341, 5.3414, 4.2491, 4.9486, 4.7178], 'ACD': [7.1048, 7.4047, 7.3728, 7.327, 7.3224], 'ACE': [5.6025, 5.1043, 5.2331, 5.460699999999999, 5.7146], 'ACE2': [5.635199999999999, 5.6815, 5.4441, 5.0776, 5.514], 'ACER1': [2.7046, 2.7381, 2.688, 2.5621, 2.5918], 'ACER3': [25.572699999999998, 25.7893, 23.9431, 24.485, 25.5029], 'ACHE': [5.6871, 5.394299999999999, 5.9017, 5.5485, 6.1491], 'ACIN1': [6.1868, 6.1465, 6.1971, 6.1515, 5.9565], 'ACKR1': [4.5485, 4.52655, 4.30365, 4.6924, 4.485], 'ACKR3': [14.0787, 14.8285, 11.8137, 15.6298, 15.979399999999998], 'ACKR4': [5.9572, 5.8955, 5.97835, 5.8713, 5.7334000000000005], 'ACLY': [28.651600000000002, 28.477600000000002, 28.091099999999997, 28.2443, 28.4212], 'ACMSD': [2.6611, 2.4655, 2.5216, 2.53, 2.3929], 'ACO1': [5.9811, 6.7146, 6.8584, 7.3054, 6.522], 'ACO2': [12.5639, 12.3523, 12.5221, 12.5637, 12.154900000000001], 'ACOD1': [2.9474, 2.7851, 2.5213, 2.7691, 2.9728], 'ACOT1': [3.58675, 3.7238, 3.5759, 3.7668, 3.7226], 'ACOT11': [12.5475, 12.1962, 11.2958, 12.0265, 12.048200000000001], 'ACOT12': [2.6784, 2.9291, 2.6705, 2.9435, 3.0426], 'ACOT13': [9.0219, 9.1513, 9.1337, 9.1649, 9.129], 'ACOT2': [3.58675, 3.7238, 3.5759, 3.7668, 3.7226], 'ACOT4': [4.0541, 4.1637, 4.8058, 5.4187, 4.7425], 'ACOT6': [2.7131, 2.4577, 2.4305, 2.2894, 2.2725], 'ACOT7': [13.7722, 14.5247, 14.1814, 15.953599999999998, 13.947399999999998], 'ACOT8': [9.7577, 9.7725, 10.044, 9.901299999999999, 9.5149], 'ACOT9': [8.7944, 8.5247, 8.7181, 8.5453, 8.7833], 'ACOX1': [24.4738, 24.895, 26.3561, 25.0051, 24.971899999999998], 'ACOX2': [2.6061, 2.2977, 2.4554, 2.5495, 2.6824], 'ACOX3': [11.7691, 12.572, 11.9871, 12.3185, 11.3148], 'ACOXL': [7.9925, 7.7737, 7.7963000000000005, 7.0672, 8.391300000000001], 'ACP1': [31.3001, 31.4972, 31.174500000000002, 32.1111, 31.5197], 'ACP2': [6.3285, 6.1442, 6.8445, 5.1397, 5.975], 'ACP3': [5.427, 7.8353, 6.965999999999999, 5.489599999999999, 5.8603000000000005], 'ACP4': [2.9326, 2.8954, 2.8113, 2.9315, 2.8015], 'ACP5': [6.5646, 6.9922, 7.5894, 6.1468, 6.8502], 'ACP6': [7.0591, 6.6888, 6.3131, 6.5433, 6.9883], 'ACR': [2.4355, 2.5896, 2.3129, 2.3146, 2.403], 'ACRBP': [9.4602, 9.6633, 9.1081, 9.5237, 9.6155], 'ACRV1': [15.8392, 16.0901, 16.682299999999998, 16.2876, 16.4855], 'ACSBG1': [5.087899999999999, 5.110799999999999, 4.8886, 5.1677, 5.2239], 'ACSBG2': [2.6819, 2.4266, 2.7867, 2.6685, 2.8106], 'ACSF2': [4.8289, 5.3457, 4.6808, 4.8682, 4.917], 'ACSF3': [7.0466, 6.8843, 7.2771, 7.1221000000000005, 6.7147], 'ACSL1': [19.3438, 18.6629, 18.7226, 18.805, 18.3827], 'ACSL3': [25.0333, 25.529600000000002, 23.8031, 24.2594, 25.4147], 'ACSL4': [23.316, 22.5716, 22.7551, 20.6514, 22.4998], 'ACSL5': [16.6681, 16.7341, 16.6694, 16.1545, 16.3434], 'ACSL6': [13.699, 14.197, 14.1177, 14.4246, 14.2852], 'ACSM1': [5.2224, 5.924, 5.887499999999999, 5.4708, 5.6411], 'ACSM2A': [5.716749999999999, 5.65715, 5.3403, 5.7011, 5.7965], 'ACSM2B': [5.716749999999999, 5.65715, 5.3403, 5.7011, 5.7965], 'ACSM3': [9.018, 12.199, 11.799199999999999, 9.2448, 9.9853], 'ACSM5': [8.482800000000001, 8.5643, 8.2784, 8.9144, 8.2578], 'ACSS1': [19.1886, 19.8216, 18.3351, 19.1178, 19.2293], 'ACSS2': [5.1501, 4.9738, 4.1992, 4.5888, 5.4784]}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data shape after handling missing values: (99, 18625)\n", "For the feature 'Underweight', the least common label is '1.0' with 32 occurrences. This represents 32.32% of the dataset.\n", "The distribution of the feature 'Underweight' in this dataset is fine.\n", "\n", "Quartiles for 'Age':\n", " 25%: 6.4\n", " 50% (Median): 14.7\n", " 75%: 36.5\n", "Min: 0.6\n", "Max: 76.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 41 occurrences. This represents 41.41% of the dataset.\n", "The distribution of the feature 'Gender' in this dataset is fine.\n", "\n", "Is trait biased: False\n", "Data quality check result: Usable\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data saved to ../../output/preprocess/Underweight/GSE57802.csv\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 }