{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "bf392ace", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:45:50.841969Z", "iopub.status.busy": "2025-03-25T05:45:50.841737Z", "iopub.status.idle": "2025-03-25T05:45:51.009901Z", "shell.execute_reply": "2025-03-25T05:45:51.009456Z" } }, "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 = \"Huntingtons_Disease\"\n", "cohort = \"GSE34201\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Huntingtons_Disease\"\n", "in_cohort_dir = \"../../input/GEO/Huntingtons_Disease/GSE34201\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Huntingtons_Disease/GSE34201.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Huntingtons_Disease/gene_data/GSE34201.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Huntingtons_Disease/clinical_data/GSE34201.csv\"\n", "json_path = \"../../output/preprocess/Huntingtons_Disease/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "c2505d32", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "fb905464", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:45:51.011512Z", "iopub.status.busy": "2025-03-25T05:45:51.011169Z", "iopub.status.idle": "2025-03-25T05:45:51.212452Z", "shell.execute_reply": "2025-03-25T05:45:51.211872Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Early transcriptional changes linked to naturally occurring Huntington's disease mutations in human embryonic stem cells\"\n", "!Series_summary\t\"Multiple human embryonic stem (ES) cell lines derived from blastocysts diagnosed as carrying the mutant huntingtin gene by pre-implantation diagnosis were used to explore early developmental changes in gene expression. How mutant huntingtin impacts on signalling pathways in the pre-symptomatic period has remained essentially unexplored in humans due to a previous lack of appropriate models.\"\n", "!Series_overall_design\t\"Total RNA was isolated from 10 human ES cell lines, 6 HD and 4 wild type control, and their neural stem cell (NSC) progeny.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['cell line: VUB01', 'cell line: H9', 'cell line: SA01', 'cell line: SI-187', 'cell line: VUB05', 'cell line: Huez2.3', 'cell line: WT4', 'cell line: SIVF017', 'cell line: SIVF018', 'cell line: SIVF020'], 1: ['hd genotype: wild type', 'hd genotype: HD'], 2: ['cell type: embryonic stem (ES) cells', 'cell type: ES cell-derived neural stem cell (NSC) progeny'], 3: ['gender: male', 'gender: female']}\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": "f3371fe4", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "0eee165a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:45:51.214218Z", "iopub.status.busy": "2025-03-25T05:45:51.214103Z", "iopub.status.idle": "2025-03-25T05:45:51.240844Z", "shell.execute_reply": "2025-03-25T05:45:51.240362Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of clinical data:\n", "{'GSM844017': [0.0, 1.0], 'GSM844018': [0.0, 1.0], 'GSM844019': [0.0, 1.0], 'GSM844020': [0.0, 1.0], 'GSM844021': [0.0, 0.0], 'GSM844022': [0.0, 0.0], 'GSM844023': [0.0, 0.0], 'GSM844024': [0.0, 0.0], 'GSM844025': [0.0, 1.0], 'GSM844026': [0.0, 1.0], 'GSM844027': [0.0, 1.0], 'GSM844028': [0.0, 1.0], 'GSM844029': [1.0, 1.0], 'GSM844030': [1.0, 1.0], 'GSM844031': [1.0, 1.0], 'GSM844032': [1.0, 1.0], 'GSM844033': [1.0, 1.0], 'GSM844034': [1.0, 1.0], 'GSM844035': [1.0, 1.0], 'GSM844036': [1.0, 1.0], 'GSM844037': [1.0, 0.0], 'GSM844038': [1.0, 0.0], 'GSM844039': [1.0, 0.0], 'GSM844040': [1.0, 0.0], 'GSM844041': [0.0, 1.0], 'GSM844042': [0.0, 1.0], 'GSM844043': [0.0, 1.0], 'GSM844044': [1.0, 1.0], 'GSM844045': [1.0, 1.0], 'GSM844046': [1.0, 1.0], 'GSM844047': [1.0, 1.0], 'GSM844048': [1.0, 1.0], 'GSM844049': [1.0, 1.0], 'GSM844050': [1.0, 0.0], 'GSM844051': [1.0, 0.0], 'GSM844052': [1.0, 0.0], 'GSM844053': [0.0, 1.0], 'GSM844054': [0.0, 1.0], 'GSM844055': [0.0, 1.0], 'GSM844056': [0.0, 1.0], 'GSM844057': [0.0, 0.0], 'GSM844058': [0.0, 0.0], 'GSM844059': [0.0, 0.0], 'GSM844060': [0.0, 0.0], 'GSM844061': [0.0, 1.0], 'GSM844062': [0.0, 1.0], 'GSM844063': [0.0, 1.0], 'GSM844064': [0.0, 1.0], 'GSM844065': [1.0, 1.0], 'GSM844066': [1.0, 1.0], 'GSM844067': [1.0, 1.0], 'GSM844068': [1.0, 1.0], 'GSM844069': [1.0, 1.0], 'GSM844070': [1.0, 1.0], 'GSM844071': [1.0, 1.0], 'GSM844072': [1.0, 1.0], 'GSM844073': [1.0, 0.0], 'GSM844074': [1.0, 0.0], 'GSM844075': [1.0, 0.0], 'GSM844076': [1.0, 0.0], 'GSM844077': [1.0, 1.0], 'GSM844078': [1.0, 1.0], 'GSM844079': [1.0, 1.0], 'GSM844080': [1.0, 0.0], 'GSM844081': [1.0, 0.0], 'GSM844082': [1.0, 0.0], 'GSM844083': [0.0, 1.0], 'GSM844084': [0.0, 1.0], 'GSM844085': [0.0, 1.0], 'GSM844086': [1.0, 1.0], 'GSM844087': [1.0, 1.0], 'GSM844088': [1.0, 1.0]}\n", "Clinical data saved to ../../output/preprocess/Huntingtons_Disease/clinical_data/GSE34201.csv\n" ] } ], "source": [ "# Review the background information and sample characteristics to determine data availability\n", "\n", "# 1. Gene Expression Data Availability\n", "# From the background info, this appears to be gene expression data from human ES cell lines\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "# Trait (HD Status) is available in row 1 of the sample characteristics dictionary\n", "trait_row = 1\n", "# Age is not available in the sample characteristics\n", "age_row = None\n", "# Gender is available in row 3\n", "gender_row = 3\n", "\n", "# 2.2 Data Type Conversion Functions\n", "def convert_trait(value):\n", " \"\"\"Convert HD genotype status to binary value.\"\"\"\n", " if not value or pd.isna(value):\n", " return None\n", " \n", " # Extract the value after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip().lower()\n", " else:\n", " value = value.strip().lower()\n", " \n", " if 'wild type' in value or 'wildtype' in value or 'wt' in value or 'control' in value:\n", " return 0\n", " elif 'hd' in value or 'huntington' in value or 'mutant' in value:\n", " return 1\n", " else:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary value (0 for female, 1 for male).\"\"\"\n", " if not value or pd.isna(value):\n", " return None\n", " \n", " # Extract the value after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip().lower()\n", " else:\n", " value = value.strip().lower()\n", " \n", " if 'female' in value or 'f' in value:\n", " return 0\n", " elif 'male' in value or 'm' in value:\n", " return 1\n", " else:\n", " return None\n", "\n", "# Since age is not available, we don't need a convert_age function\n", "convert_age = None\n", "\n", "# 3. Save Metadata\n", "# Check if trait data is available (trait_row is not None)\n", "is_trait_available = trait_row is not None\n", "\n", "# Save initial filtering information\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", " # 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 data\n", " print(\"Preview of clinical data:\")\n", " print(preview_df(selected_clinical_df))\n", " \n", " # Save the clinical data as CSV\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": "752eb5eb", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "cc604ea3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:45:51.242516Z", "iopub.status.busy": "2025-03-25T05:45:51.242408Z", "iopub.status.idle": "2025-03-25T05:45:51.593516Z", "shell.execute_reply": "2025-03-25T05:45:51.593073Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Huntingtons_Disease/GSE34201/GSE34201_series_matrix.txt.gz\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape: (48803, 72)\n", "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" ] } ], "source": [ "# 1. Get the SOFT and matrix file paths again \n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "print(f\"Matrix file found: {matrix_file}\")\n", "\n", "# 2. Use the get_genetic_data function from the library to get the gene_data\n", "try:\n", " gene_data = get_genetic_data(matrix_file)\n", " print(f\"Gene data shape: {gene_data.shape}\")\n", " \n", " # 3. Print the first 20 row IDs (gene or probe identifiers)\n", " print(\"First 20 gene/probe identifiers:\")\n", " print(gene_data.index[:20])\n", "except Exception as e:\n", " print(f\"Error extracting gene data: {e}\")\n" ] }, { "cell_type": "markdown", "id": "0a245e07", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "3708cf6a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:45:51.594829Z", "iopub.status.busy": "2025-03-25T05:45:51.594700Z", "iopub.status.idle": "2025-03-25T05:45:51.596753Z", "shell.execute_reply": "2025-03-25T05:45:51.596419Z" } }, "outputs": [], "source": [ "# Looking at the gene identifiers, I can see they are ILMN_* format identifiers,\n", "# which are Illumina probe IDs, not standard human gene symbols.\n", "# These need to be mapped to official gene symbols for analysis.\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "641d275a", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "75a819f2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:45:51.597939Z", "iopub.status.busy": "2025-03-25T05:45:51.597832Z", "iopub.status.idle": "2025-03-25T05:45:58.032414Z", "shell.execute_reply": "2025-03-25T05:45:58.031714Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene annotation preview:\n", "Columns in gene annotation: ['ID', 'Species', 'Source', 'Search_Key', 'Transcript', 'ILMN_Gene', 'Source_Reference_ID', 'RefSeq_ID', 'Unigene_ID', 'Entrez_Gene_ID', 'GI', 'Accession', 'Symbol', 'Protein_Product', 'Array_Address_Id', 'Probe_Type', 'Probe_Start', 'SEQUENCE', 'Chromosome', 'Probe_Chr_Orientation', 'Probe_Coordinates', 'Cytoband', 'Definition', 'Ontology_Component', 'Ontology_Process', 'Ontology_Function', 'Synonyms', 'GB_ACC']\n", "{'ID': ['ILMN_1825594', 'ILMN_1810803', 'ILMN_1722532', 'ILMN_1884413', 'ILMN_1906034'], 'Species': ['Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens'], 'Source': ['Unigene', 'RefSeq', 'RefSeq', 'Unigene', 'Unigene'], 'Search_Key': ['ILMN_89282', 'ILMN_35826', 'ILMN_25544', 'ILMN_132331', 'ILMN_105017'], 'Transcript': ['ILMN_89282', 'ILMN_35826', 'ILMN_25544', 'ILMN_132331', 'ILMN_105017'], 'ILMN_Gene': ['HS.388528', 'LOC441782', 'JMJD1A', 'HS.580150', 'HS.540210'], 'Source_Reference_ID': ['Hs.388528', 'XM_497527.2', 'NM_018433.3', 'Hs.580150', 'Hs.540210'], 'RefSeq_ID': [nan, 'XM_497527.2', 'NM_018433.3', nan, nan], 'Unigene_ID': ['Hs.388528', nan, nan, 'Hs.580150', 'Hs.540210'], 'Entrez_Gene_ID': [nan, 441782.0, 55818.0, nan, nan], 'GI': [23525203.0, 89042416.0, 46358420.0, 7376124.0, 5437312.0], 'Accession': ['BU678343', 'XM_497527.2', 'NM_018433.3', 'AW629334', 'AI818233'], 'Symbol': [nan, 'LOC441782', 'JMJD1A', nan, nan], 'Protein_Product': [nan, 'XP_497527.2', 'NP_060903.2', nan, nan], 'Array_Address_Id': [1740241.0, 1850750.0, 1240504.0, 4050487.0, 2190598.0], 'Probe_Type': ['S', 'S', 'S', 'S', 'S'], 'Probe_Start': [349.0, 902.0, 4359.0, 117.0, 304.0], 'SEQUENCE': ['CTCTCTAAAGGGACAACAGAGTGGACAGTCAAGGAACTCCACATATTCAT', 'GGGGTCAAGCCCAGGTGAAATGTGGATTGGAAAAGTGCTTCCCTTGCCCC', 'CCAGGCTGTAAAAGCAAAACCTCGTATCAGCTCTGGAACAATACCTGCAG', 'CCAGACAGGAAGCATCAAGCCCTTCAGGAAAGAATATGCGAGAGTGCTGC', 'TGTGCAGAAAGCTGATGGAAGGGAGAAAGAATGGAAGTGGGTCACACAGC'], 'Chromosome': [nan, nan, '2', nan, nan], 'Probe_Chr_Orientation': [nan, nan, '+', nan, nan], 'Probe_Coordinates': [nan, nan, '86572991-86573040', nan, nan], 'Cytoband': [nan, nan, '2p11.2e', nan, nan], 'Definition': ['UI-CF-EC0-abi-c-12-0-UI.s1 UI-CF-EC0 Homo sapiens cDNA clone UI-CF-EC0-abi-c-12-0-UI 3, mRNA sequence', 'PREDICTED: Homo sapiens similar to spectrin domain with coiled-coils 1 (LOC441782), mRNA.', 'Homo sapiens jumonji domain containing 1A (JMJD1A), mRNA.', 'hi56g05.x1 Soares_NFL_T_GBC_S1 Homo sapiens cDNA clone IMAGE:2976344 3, mRNA sequence', 'wk77d04.x1 NCI_CGAP_Pan1 Homo sapiens cDNA clone IMAGE:2421415 3, mRNA sequence'], 'Ontology_Component': [nan, nan, 'nucleus [goid 5634] [evidence IEA]', nan, nan], 'Ontology_Process': [nan, nan, 'chromatin modification [goid 16568] [evidence IEA]; transcription [goid 6350] [evidence IEA]; regulation of transcription, DNA-dependent [goid 6355] [evidence IEA]', nan, nan], 'Ontology_Function': [nan, nan, 'oxidoreductase activity [goid 16491] [evidence IEA]; oxidoreductase activity, acting on single donors with incorporation of molecular oxygen, incorporation of two atoms of oxygen [goid 16702] [evidence IEA]; zinc ion binding [goid 8270] [evidence IEA]; metal ion binding [goid 46872] [evidence IEA]; iron ion binding [goid 5506] [evidence IEA]', nan, nan], 'Synonyms': [nan, nan, 'JHMD2A; JMJD1; TSGA; KIAA0742; DKFZp686A24246; DKFZp686P07111', nan, nan], 'GB_ACC': ['BU678343', 'XM_497527.2', 'NM_018433.3', 'AW629334', 'AI818233']}\n", "\n", "Examining potential gene mapping columns:\n" ] } ], "source": [ "# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "gene_annotation = get_gene_annotation(soft_file)\n", "\n", "# 2. Analyze the gene annotation dataframe to identify which columns contain the gene identifiers and gene symbols\n", "print(\"\\nGene annotation preview:\")\n", "print(f\"Columns in gene annotation: {gene_annotation.columns.tolist()}\")\n", "print(preview_df(gene_annotation, n=5))\n", "\n", "# Look more closely at columns that might contain gene information\n", "print(\"\\nExamining potential gene mapping columns:\")\n", "potential_gene_columns = ['gene_assignment', 'mrna_assignment', 'swissprot', 'unigene']\n", "for col in potential_gene_columns:\n", " if col in gene_annotation.columns:\n", " print(f\"\\nSample values from '{col}' column:\")\n", " print(gene_annotation[col].head(3).tolist())\n" ] }, { "cell_type": "markdown", "id": "0fbd3518", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "b46cf9a8", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:45:58.034310Z", "iopub.status.busy": "2025-03-25T05:45:58.034184Z", "iopub.status.idle": "2025-03-25T05:45:59.020350Z", "shell.execute_reply": "2025-03-25T05:45:59.019691Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping dataframe shape: (35966, 2)\n", "Gene mapping preview:\n", "{'ID': ['ILMN_1810803', 'ILMN_1722532', 'ILMN_1708805', 'ILMN_1672526', 'ILMN_2185604'], 'Gene': ['LOC441782', 'JMJD1A', 'NCOA3', 'LOC389834', 'C17orf77']}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data after mapping - shape: (18839, 72)\n", "First 10 gene symbols after mapping:\n", "['A1BG', 'A2BP1', 'A2M', 'A2ML1', 'A3GALT2', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS', 'AACS']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to ../../output/preprocess/Huntingtons_Disease/gene_data/GSE34201.csv\n" ] } ], "source": [ "# 1. Identify the relevant columns for mapping\n", "# From examining the gene annotation data, we can see:\n", "# - 'ID' column contains the Illumina probe IDs (e.g., ILMN_1825594)\n", "# - 'Symbol' column contains the gene symbols (e.g., JMJD1A)\n", "\n", "# 2. Get the gene mapping dataframe\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol')\n", "print(f\"Gene mapping dataframe shape: {gene_mapping.shape}\")\n", "print(\"Gene mapping preview:\")\n", "print(preview_df(gene_mapping, n=5))\n", "\n", "# 3. Apply the 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 after mapping - shape: {gene_data.shape}\")\n", "print(\"First 10 gene symbols after mapping:\")\n", "print(gene_data.index[:10].tolist())\n", "\n", "# Save the gene expression data to a CSV file\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": "4528d8fd", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "c075e996", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:45:59.022108Z", "iopub.status.busy": "2025-03-25T05:45:59.021980Z", "iopub.status.idle": "2025-03-25T05:46:08.598096Z", "shell.execute_reply": "2025-03-25T05:46:08.597430Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalizing gene symbols...\n", "Gene data shape after normalization: (17552, 72)\n", "First 10 normalized gene symbols:\n", "Index(['A1BG', 'A2M', 'A2ML1', 'A3GALT2', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS',\n", " 'AACS', 'AACSP1'],\n", " dtype='object', name='Gene')\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to: ../../output/preprocess/Huntingtons_Disease/gene_data/GSE34201.csv\n", "\n", "Loading clinical data...\n", "Clinical data preview:\n", "{'GSM844017': [0.0, 1.0], 'GSM844018': [0.0, 1.0], 'GSM844019': [0.0, 1.0], 'GSM844020': [0.0, 1.0], 'GSM844021': [0.0, 0.0], 'GSM844022': [0.0, 0.0], 'GSM844023': [0.0, 0.0], 'GSM844024': [0.0, 0.0], 'GSM844025': [0.0, 1.0], 'GSM844026': [0.0, 1.0], 'GSM844027': [0.0, 1.0], 'GSM844028': [0.0, 1.0], 'GSM844029': [1.0, 1.0], 'GSM844030': [1.0, 1.0], 'GSM844031': [1.0, 1.0], 'GSM844032': [1.0, 1.0], 'GSM844033': [1.0, 1.0], 'GSM844034': [1.0, 1.0], 'GSM844035': [1.0, 1.0], 'GSM844036': [1.0, 1.0], 'GSM844037': [1.0, 0.0], 'GSM844038': [1.0, 0.0], 'GSM844039': [1.0, 0.0], 'GSM844040': [1.0, 0.0], 'GSM844041': [0.0, 1.0], 'GSM844042': [0.0, 1.0], 'GSM844043': [0.0, 1.0], 'GSM844044': [1.0, 1.0], 'GSM844045': [1.0, 1.0], 'GSM844046': [1.0, 1.0], 'GSM844047': [1.0, 1.0], 'GSM844048': [1.0, 1.0], 'GSM844049': [1.0, 1.0], 'GSM844050': [1.0, 0.0], 'GSM844051': [1.0, 0.0], 'GSM844052': [1.0, 0.0], 'GSM844053': [0.0, 1.0], 'GSM844054': [0.0, 1.0], 'GSM844055': [0.0, 1.0], 'GSM844056': [0.0, 1.0], 'GSM844057': [0.0, 0.0], 'GSM844058': [0.0, 0.0], 'GSM844059': [0.0, 0.0], 'GSM844060': [0.0, 0.0], 'GSM844061': [0.0, 1.0], 'GSM844062': [0.0, 1.0], 'GSM844063': [0.0, 1.0], 'GSM844064': [0.0, 1.0], 'GSM844065': [1.0, 1.0], 'GSM844066': [1.0, 1.0], 'GSM844067': [1.0, 1.0], 'GSM844068': [1.0, 1.0], 'GSM844069': [1.0, 1.0], 'GSM844070': [1.0, 1.0], 'GSM844071': [1.0, 1.0], 'GSM844072': [1.0, 1.0], 'GSM844073': [1.0, 0.0], 'GSM844074': [1.0, 0.0], 'GSM844075': [1.0, 0.0], 'GSM844076': [1.0, 0.0], 'GSM844077': [1.0, 1.0], 'GSM844078': [1.0, 1.0], 'GSM844079': [1.0, 1.0], 'GSM844080': [1.0, 0.0], 'GSM844081': [1.0, 0.0], 'GSM844082': [1.0, 0.0], 'GSM844083': [0.0, 1.0], 'GSM844084': [0.0, 1.0], 'GSM844085': [0.0, 1.0], 'GSM844086': [1.0, 1.0], 'GSM844087': [1.0, 1.0], 'GSM844088': [1.0, 1.0]}\n", "\n", "Linking clinical and genetic data...\n", "Linked data shape: (72, 17554)\n", "Linked data preview (first 5 rows, 5 columns):\n", " Huntingtons_Disease Gender A1BG A2M A2ML1\n", "GSM844017 0.0 1.0 8.768847 -4.315860 41.84605\n", "GSM844018 0.0 1.0 7.512886 -5.671984 45.67477\n", "GSM844019 0.0 1.0 4.518019 -6.198073 36.03045\n", "GSM844020 0.0 1.0 -1.635464 -9.090332 63.79180\n", "GSM844021 0.0 0.0 13.535716 -7.224585 39.82544\n", "\n", "Handling missing values...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data shape after handling missing values: (72, 17554)\n", "\n", "Checking for bias in dataset features...\n", "For the feature 'Huntingtons_Disease', the least common label is '0.0' with 30 occurrences. This represents 41.67% of the dataset.\n", "The distribution of the feature 'Huntingtons_Disease' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '0.0' with 22 occurrences. This represents 30.56% 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/Huntingtons_Disease/GSE34201.csv\n" ] } ], "source": [ "# 1. Normalize gene symbols using NCBI database\n", "print(\"Normalizing gene symbols...\")\n", "gene_data = pd.read_csv(out_gene_data_file, index_col=0)\n", "gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Gene data shape after normalization: {gene_data.shape}\")\n", "print(\"First 10 normalized gene symbols:\")\n", "print(gene_data.index[:10])\n", "\n", "# Save the normalized gene data\n", "gene_data.to_csv(out_gene_data_file)\n", "print(f\"Normalized gene data saved to: {out_gene_data_file}\")\n", "\n", "# 2. Load the previously processed clinical data\n", "print(\"\\nLoading clinical data...\")\n", "clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)\n", "print(\"Clinical data preview:\")\n", "print(preview_df(clinical_df))\n", "\n", "# 3. Link clinical and genetic data\n", "print(\"\\nLinking clinical and genetic data...\")\n", "linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data)\n", "print(f\"Linked data shape: {linked_data.shape}\")\n", "print(\"Linked data preview (first 5 rows, 5 columns):\")\n", "if linked_data.shape[0] > 0 and linked_data.shape[1] > 5:\n", " print(linked_data.iloc[:5, :5])\n", "else:\n", " print(linked_data)\n", "\n", "# 4. Handle missing values\n", "print(\"\\nHandling missing values...\")\n", "linked_data_clean = handle_missing_values(linked_data, trait)\n", "print(f\"Linked data shape after handling missing values: {linked_data_clean.shape}\")\n", "\n", "# 5. Check for bias in the dataset\n", "print(\"\\nChecking for bias in dataset features...\")\n", "is_biased, linked_data_clean = judge_and_remove_biased_features(linked_data_clean, trait)\n", "\n", "# 6. Conduct final quality validation\n", "note = \"This GSE34201 dataset contains gene expression data from human embryonic stem cell lines carrying the mutant huntingtin gene, relevant to Huntington's Disease.\"\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_biased,\n", " df=linked_data_clean,\n", " note=note\n", ")\n", "\n", "# 7. Save the linked data if it's usable\n", "if is_usable:\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " linked_data_clean.to_csv(out_data_file, index=True)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(\"Dataset deemed not usable for associative 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 }