{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "763303ca", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:29:49.481161Z", "iopub.status.busy": "2025-03-25T05:29:49.481058Z", "iopub.status.idle": "2025-03-25T05:29:49.668325Z", "shell.execute_reply": "2025-03-25T05:29:49.667933Z" } }, "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 = \"Heart_rate\"\n", "cohort = \"GSE12385\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Heart_rate\"\n", "in_cohort_dir = \"../../input/GEO/Heart_rate/GSE12385\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Heart_rate/GSE12385.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Heart_rate/gene_data/GSE12385.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Heart_rate/clinical_data/GSE12385.csv\"\n", "json_path = \"../../output/preprocess/Heart_rate/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "f13876c8", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "b36b62d0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:29:49.669676Z", "iopub.status.busy": "2025-03-25T05:29:49.669528Z", "iopub.status.idle": "2025-03-25T05:29:50.065525Z", "shell.execute_reply": "2025-03-25T05:29:50.065009Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Gene expression changes in Peripheral Blood Mononuclear cells (PBMC) induced by physical activity\"\n", "!Series_summary\t\"Gene expression changes in Peripheral Blood Mononuclear cells (PBMC) induced by physical activity was investigated in sedentary middle-aged men (mean age 52.6 years and BMI 29.1) who undertook a 24-week physical activity programme with blood sampling in the pre-exercise period , at the end of 24-weeks prescribed physical activity , and following a two-week detraining period.\"\n", "!Series_overall_design\t\"AgilentTM Whole Human Genome Oligo Microarrays were utilised to examine the effects of physical activity on mRNA expression profiles of the Peripheral Blood Mononuclear cells (PBMC) at 3 time points (pre-exercise, after 24 weeks physical activity, and at 26 weeks after 2 weeks detraining. There were 12 participants in this programme.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['Gender: Male'], 1: ['Age (years): 48', 'Age (years): 54', 'Age (years): 56', 'Age (years): 53', 'Age (years): 62', 'Age (years): 59', 'Age (years): 46', 'Age (years): 50', 'Age (years): 51'], 2: ['Height (m): 1.8', 'Height (m): 1.87', 'Height (m): 1.79', 'Height (m): 1.77', 'Height (m): 1.78', 'Height (m): 1.73', 'Height (m): 1.95', 'Height (m): 1.84'], 3: ['Weight (kg): 88', 'Weight (kg): 100.5', 'Weight (kg): 92.8', 'Weight (kg): 87.9', 'Weight (kg): 95.1', 'Weight (kg): 88.2', 'Weight (kg): 129.9', 'Weight (kg): 102.2', 'Weight (kg): 83.7', 'Weight (kg): 96.6', 'Weight (kg): 108.4', 'Weight (kg): 71.7'], 4: ['BMI: 27.3', 'BMI: 29', 'BMI: 28.1', 'BMI: 30', 'BMI: 34', 'BMI: 31.9', 'BMI: 25.8', 'BMI: 28.5', 'BMI: 33', 'BMI: 23'], 5: ['VO2 max: 40', 'VO2 max: 39.1', 'VO2 max: 32.6', 'VO2 max: 43.5', 'VO2 max: 27.1', 'VO2 max: 35.9', 'VO2 max: 28.6', 'VO2 max: 38.4', 'VO2 max: 35.7', 'VO2 max: 34.4', 'VO2 max: 30.4', 'VO2 max: 37.1'], 6: ['IL-6 (pg/ml): 0.36', 'IL-6 (pg/ml): 3.06', 'IL-6 (pg/ml): 2.92', 'IL-6 (pg/ml): 0.2', 'IL-6 (pg/ml): 1.9', 'IL-6 (pg/ml): 1.7', 'IL-6 (pg/ml): 1.68', 'IL-6 (pg/ml): 0.9', 'IL-6 (pg/ml): 0.47', 'IL-6 (pg/ml): 0.72', 'IL-6 (pg/ml): 1.5', 'IL-6 (pg/ml): 0.89']}\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": "5082cea0", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "515108c0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:29:50.066752Z", "iopub.status.busy": "2025-03-25T05:29:50.066642Z", "iopub.status.idle": "2025-03-25T05:29:50.074627Z", "shell.execute_reply": "2025-03-25T05:29:50.074165Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset appears to contain mRNA expression profiles using AgilentTM Whole Human Genome Oligo Microarrays\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "\n", "# Heart rate is not explicitly mentioned in the sample characteristics\n", "# However, there is VO2 max data which is related to cardiorespiratory fitness\n", "# VO2 max is closely associated with heart rate but it's not heart rate itself\n", "# Since we don't have direct heart rate measurements, we need to set trait_row to None\n", "trait_row = None # Heart rate not available\n", "\n", "# Age is available in row 1\n", "age_row = 1\n", "\n", "# Gender is available in row 0 but all subjects are male (constant feature)\n", "# Since it's a constant feature, we'll set it to None\n", "gender_row = None # Only one gender (male) present\n", "\n", "# 2.2 Data Type Conversion\n", "def convert_trait(value):\n", " # This won't be used since trait data is not available\n", " # But defining it for completeness\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " parts = value.split(': ')\n", " if len(parts) > 1:\n", " try:\n", " return float(parts[1]) # Assuming heart rate would be continuous\n", " except (ValueError, TypeError):\n", " return None\n", " return None\n", "\n", "def convert_age(value):\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " parts = value.split(': ')\n", " if len(parts) > 1:\n", " try:\n", " return float(parts[1]) # Age as continuous variable\n", " except (ValueError, TypeError):\n", " return None\n", " return None\n", "\n", "def convert_gender(value):\n", " # This won't be used but defining it for completeness\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " parts = value.split(': ')\n", " if len(parts) > 1:\n", " gender = parts[1].strip().lower()\n", " if gender == 'male':\n", " return 1\n", " elif gender == 'female':\n", " return 0\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Determine trait data availability (trait_row is None, so it's not available)\n", "is_trait_available = trait_row is not None\n", "\n", "# Initial filtering and saving cohort info\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 trait_row is None, we skip the clinical feature extraction step\n", "# (This step would be executed if trait_row were not None)\n" ] }, { "cell_type": "markdown", "id": "8d4c2589", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "b7e0ca3b", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:29:50.076182Z", "iopub.status.busy": "2025-03-25T05:29:50.076010Z", "iopub.status.idle": "2025-03-25T05:29:50.214360Z", "shell.execute_reply": "2025-03-25T05:29:50.214018Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Found data marker at line 73\n", "Header line: \"ID_REF\"\t\"GSM310611\"\t\"GSM310633\"\t\"GSM310636\"\t\"GSM310637\"\t\"GSM310638\"\t\"GSM310639\"\t\"GSM310736\"\t\"GSM310737\"\t\"GSM310738\"\t\"GSM310739\"\t\"GSM310744\"\t\"GSM310745\"\t\"GSM310746\"\t\"GSM310747\"\t\"GSM310748\"\t\"GSM310749\"\t\"GSM310750\"\t\"GSM310751\"\t\"GSM310752\"\t\"GSM310753\"\t\"GSM310754\"\t\"GSM310755\"\t\"GSM310756\"\t\"GSM310757\"\t\"GSM310758\"\t\"GSM310759\"\t\"GSM310760\"\t\"GSM310761\"\t\"GSM310763\"\t\"GSM310765\"\t\"GSM310768\"\t\"GSM310770\"\t\"GSM310774\"\t\"GSM310775\"\t\"GSM310776\"\t\"GSM310777\"\n", "First data line: 1\t1.33E+05\t1.87E+05\t1.72E+05\t1.22E+05\t1.20E+05\t1.61E+05\t1.40E+05\t9.68E+04\t1.47E+05\t1.56E+05\t1.52E+05\t1.46E+05\t1.77E+05\t2.02E+05\t2.12E+05\t1.82E+05\t1.62E+05\t1.61E+05\t2.01E+05\t1.04E+05\t2.03E+05\t2.40E+05\t2.34E+05\t2.01E+05\t1.58E+05\t1.95E+05\t1.59E+05\t1.58E+05\t1.48E+05\t1.74E+05\t1.59E+05\t1.48E+05\t2.05E+05\t1.62E+05\t1.67E+05\t1.61E+05\n", "Index(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13',\n", " '14', '15', '16', '17', '18', '19', '20'],\n", " dtype='object', name='ID')\n" ] } ], "source": [ "# 1. Get the file paths for the SOFT file and matrix file\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. First, let's examine the structure of the matrix file to understand its format\n", "import gzip\n", "\n", "# Peek at the first few lines of the file to understand its structure\n", "with gzip.open(matrix_file, 'rt') as file:\n", " # Read first 100 lines to find the header structure\n", " for i, line in enumerate(file):\n", " if '!series_matrix_table_begin' in line:\n", " print(f\"Found data marker at line {i}\")\n", " # Read the next line which should be the header\n", " header_line = next(file)\n", " print(f\"Header line: {header_line.strip()}\")\n", " # And the first data line\n", " first_data_line = next(file)\n", " print(f\"First data line: {first_data_line.strip()}\")\n", " break\n", " if i > 100: # Limit search to first 100 lines\n", " print(\"Matrix table marker not found in first 100 lines\")\n", " break\n", "\n", "# 3. Now try to get the genetic data with better error handling\n", "try:\n", " gene_data = get_genetic_data(matrix_file)\n", " print(gene_data.index[:20])\n", "except KeyError as e:\n", " print(f\"KeyError: {e}\")\n", " \n", " # Alternative approach: manually extract the data\n", " print(\"\\nTrying alternative approach to read the gene data:\")\n", " with gzip.open(matrix_file, 'rt') as file:\n", " # Find the start of the data\n", " for line in file:\n", " if '!series_matrix_table_begin' in line:\n", " break\n", " \n", " # Read the headers and data\n", " import pandas as pd\n", " df = pd.read_csv(file, sep='\\t', index_col=0)\n", " print(f\"Column names: {df.columns[:5]}\")\n", " print(f\"First 20 row IDs: {df.index[:20]}\")\n", " gene_data = df\n" ] }, { "cell_type": "markdown", "id": "7f250099", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "dc63a246", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:29:50.215784Z", "iopub.status.busy": "2025-03-25T05:29:50.215661Z", "iopub.status.idle": "2025-03-25T05:29:50.217621Z", "shell.execute_reply": "2025-03-25T05:29:50.217332Z" } }, "outputs": [], "source": [ "# Looking at the identifiers from the gene expression data\n", "# The identifiers in the first line appear to be numeric (1, 2, 3, etc.)\n", "# These are not standard human gene symbols, which would typically be alphanumeric like BRCA1, TP53, etc.\n", "# These are likely probe IDs or other platform-specific identifiers that need to be mapped to gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "854c0166", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "ec188a2f", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:29:50.218925Z", "iopub.status.busy": "2025-03-25T05:29:50.218822Z", "iopub.status.idle": "2025-03-25T05:29:51.351333Z", "shell.execute_reply": "2025-03-25T05:29:51.350992Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Examining SOFT file structure:\n", "Line 0: ^DATABASE = GeoMiame\n", "Line 1: !Database_name = Gene Expression Omnibus (GEO)\n", "Line 2: !Database_institute = NCBI NLM NIH\n", "Line 3: !Database_web_link = http://www.ncbi.nlm.nih.gov/geo\n", "Line 4: !Database_email = geo@ncbi.nlm.nih.gov\n", "Line 5: ^SERIES = GSE12385\n", "Line 6: !Series_title = Gene expression changes in Peripheral Blood Mononuclear cells (PBMC) induced by physical activity\n", "Line 7: !Series_geo_accession = GSE12385\n", "Line 8: !Series_status = Public on Aug 03 2010\n", "Line 9: !Series_submission_date = Aug 08 2008\n", "Line 10: !Series_last_update_date = Feb 22 2018\n", "Line 11: !Series_pubmed_id = 20368384\n", "Line 12: !Series_summary = Gene expression changes in Peripheral Blood Mononuclear cells (PBMC) induced by physical activity was investigated in sedentary middle-aged men (mean age 52.6 years and BMI 29.1) who undertook a 24-week physical activity programme with blood sampling in the pre-exercise period , at the end of 24-weeks prescribed physical activity , and following a two-week detraining period.\n", "Line 13: !Series_overall_design = AgilentTM Whole Human Genome Oligo Microarrays were utilised to examine the effects of physical activity on mRNA expression profiles of the Peripheral Blood Mononuclear cells (PBMC) at 3 time points (pre-exercise, after 24 weeks physical activity, and at 26 weeks after 2 weeks detraining. There were 12 participants in this programme.\n", "Line 14: !Series_type = Expression profiling by array\n", "Line 15: !Series_contributor = Dawn,J,Mazzatti\n", "Line 16: !Series_contributor = Daniella,,Markovitch\n", "Line 17: !Series_contributor = FeiLing,,Lim\n", "Line 18: !Series_contributor = Sarah,E,Askew\n", "Line 19: !Series_contributor = Tina,,Hurst\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene annotation preview:\n", "{'ID': [1, 2, 3, 4, 5], 'COL': [266, 266, 266, 266, 266], 'ROW': [170, 168, 166, 164, 162], 'NAME': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner'], 'SPOT_ID': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner'], 'CONTROL_TYPE': ['pos', 'pos', 'pos', 'pos', 'pos'], 'REFSEQ': [nan, nan, nan, nan, nan], 'GB_ACC': [nan, nan, nan, nan, nan], 'GENE': [nan, nan, nan, nan, nan], 'GENE_SYMBOL': [nan, nan, nan, nan, nan], 'GENE_NAME': [nan, nan, nan, nan, nan], 'UNIGENE_ID': [nan, nan, nan, nan, nan], 'ENSEMBL_ID': [nan, nan, nan, nan, nan], 'TIGR_ID': [nan, nan, nan, nan, nan], 'ACCESSION_STRING': [nan, nan, nan, nan, nan], 'CHROMOSOMAL_LOCATION': [nan, nan, nan, nan, nan], 'CYTOBAND': [nan, nan, nan, nan, nan], 'DESCRIPTION': [nan, nan, nan, nan, nan], 'GO_ID': [nan, nan, nan, nan, nan], 'SEQUENCE': [nan, nan, nan, nan, nan], 'SPOT_ID.1': [nan, nan, nan, nan, nan], 'ORDER': [1, 2, 3, 4, 5]}\n" ] } ], "source": [ "# 1. Let's first examine the structure of the SOFT file before trying to parse it\n", "import gzip\n", "\n", "# Look at the first few lines of the SOFT file to understand its structure\n", "print(\"Examining SOFT file structure:\")\n", "try:\n", " with gzip.open(soft_file, 'rt') as file:\n", " # Read first 20 lines to understand the file structure\n", " for i, line in enumerate(file):\n", " if i < 20:\n", " print(f\"Line {i}: {line.strip()}\")\n", " else:\n", " break\n", "except Exception as e:\n", " print(f\"Error reading SOFT file: {e}\")\n", "\n", "# 2. Now let's try a more robust approach to extract the gene annotation\n", "# Instead of using the library function which failed, we'll implement a custom approach\n", "try:\n", " # First, look for the platform section which contains gene annotation\n", " platform_data = []\n", " with gzip.open(soft_file, 'rt') as file:\n", " in_platform_section = False\n", " for line in file:\n", " if line.startswith('^PLATFORM'):\n", " in_platform_section = True\n", " continue\n", " if in_platform_section and line.startswith('!platform_table_begin'):\n", " # Next line should be the header\n", " header = next(file).strip()\n", " platform_data.append(header)\n", " # Read until the end of the platform table\n", " for table_line in file:\n", " if table_line.startswith('!platform_table_end'):\n", " break\n", " platform_data.append(table_line.strip())\n", " break\n", " \n", " # If we found platform data, convert it to a DataFrame\n", " if platform_data:\n", " import pandas as pd\n", " import io\n", " platform_text = '\\n'.join(platform_data)\n", " gene_annotation = pd.read_csv(io.StringIO(platform_text), delimiter='\\t', \n", " low_memory=False, on_bad_lines='skip')\n", " print(\"\\nGene annotation preview:\")\n", " print(preview_df(gene_annotation))\n", " else:\n", " print(\"Could not find platform table in SOFT file\")\n", " \n", " # Try an alternative approach - extract mapping from other sections\n", " with gzip.open(soft_file, 'rt') as file:\n", " for line in file:\n", " if 'ANNOTATION information' in line or 'annotation information' in line:\n", " print(f\"Found annotation information: {line.strip()}\")\n", " if line.startswith('!Platform_title') or line.startswith('!platform_title'):\n", " print(f\"Platform title: {line.strip()}\")\n", " \n", "except Exception as e:\n", " print(f\"Error processing gene annotation: {e}\")\n" ] }, { "cell_type": "markdown", "id": "bebfb9ad", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "a89ceb4d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:29:51.353026Z", "iopub.status.busy": "2025-03-25T05:29:51.352870Z", "iopub.status.idle": "2025-03-25T05:29:51.455122Z", "shell.execute_reply": "2025-03-25T05:29:51.454711Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of genes after mapping: 18379\n", "First 5 gene symbols:\n", "Index(['A1BG', 'A1CF', 'A2BP1', 'A2LD1', 'A2M'], dtype='object', name='Gene')\n" ] } ], "source": [ "# 1. Identify the relevant columns in the gene annotation data\n", "# From the preview, 'ID' contains the probe identifiers seen in gene_data.index (numeric values)\n", "# 'GENE_SYMBOL' contains the gene symbols we want to map to\n", "\n", "# 2. Extract the mapping columns from the gene annotation dataframe\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')\n", "\n", "# 3. Apply the gene mapping to convert probe IDs to gene symbols\n", "# This divides expression values for probes that map to multiple genes\n", "# and sums contributions from all probes mapping to the same gene\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Print summary of the gene data after mapping\n", "print(f\"Number of genes after mapping: {len(gene_data)}\")\n", "print(\"First 5 gene symbols:\")\n", "print(gene_data.index[:5])\n" ] }, { "cell_type": "markdown", "id": "af586edd", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "a5cc10b9", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:29:51.456849Z", "iopub.status.busy": "2025-03-25T05:29:51.456728Z", "iopub.status.idle": "2025-03-25T05:29:51.882223Z", "shell.execute_reply": "2025-03-25T05:29:51.881759Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Genes before normalization: 18379, after: 17901" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Heart_rate/gene_data/GSE12385.csv\n", "Abnormality detected in the cohort: GSE12385. Preprocessing failed.\n", "Trait data is not available. No linked data was created or saved.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "# Apply normalization to the gene data from Step 6\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Genes before normalization: {len(gene_data)}, after: {len(normalized_gene_data)}\")\n", "\n", "# Save the normalized gene data to the output file\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "normalized_gene_data.to_csv(out_gene_data_file)\n", "print(f\"Normalized gene data saved to {out_gene_data_file}\")\n", "\n", "# 2. Define convert functions for trait, age, and gender\n", "def convert_age(value):\n", " \"\"\"Convert age value to continuous numeric type.\"\"\"\n", " if pd.isna(value):\n", " return None\n", " try:\n", " # Extract the numerical value after the colon\n", " parts = value.split(\":\")\n", " if len(parts) < 2:\n", " return None\n", " return float(parts[1].strip())\n", " except (ValueError, IndexError):\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary (0=female, 1=male).\"\"\"\n", " if pd.isna(value):\n", " return None\n", " try:\n", " gender = value.split(\":\")[1].strip().lower()\n", " if \"male\" in gender:\n", " return 1\n", " elif \"female\" in gender:\n", " return 0\n", " else:\n", " return None\n", " except (ValueError, IndexError):\n", " return None\n", "\n", "# 3. Load the clinical data again for clarity\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "background_info, clinical_data = get_background_and_clinical_data(matrix_file)\n", "\n", "# From step 2, we determined that trait data is not available and gender is constant\n", "trait_row = None # Heart rate data is not directly available\n", "age_row = 1 # Age data is available in row 1\n", "gender_row = None # Only one gender (male) present, so it's a constant feature\n", "\n", "# Create a minimal DataFrame with sample IDs for validation\n", "# Use the columns from the gene expression data as samples\n", "sample_ids = normalized_gene_data.columns\n", "minimal_df = pd.DataFrame(index=sample_ids)\n", "\n", "# Since trait data is not available, we mark the dataset as biased (unusable for this trait)\n", "is_biased = True # Dataset is unusable for Heart_rate trait since it's not available\n", "\n", "# 4. Final validation and save\n", "is_gene_available = len(normalized_gene_data) > 0\n", "is_trait_available = trait_row is not None\n", "note = \"Dataset contains gene expression data from male participants undergoing physical activity program. No direct heart rate measurements available, only VO2 max which is related to cardiorespiratory fitness.\"\n", "\n", "is_usable = validate_and_save_cohort_info(\n", " is_final=True, \n", " cohort=cohort, \n", " info_path=json_path, \n", " is_gene_available=is_gene_available, \n", " is_trait_available=is_trait_available, \n", " is_biased=is_biased, # Dataset is unusable due to missing trait\n", " df=minimal_df, # Minimal DataFrame with sample IDs\n", " note=note\n", ")\n", "\n", "# 5. Since trait data is not available (as determined in step 2), \n", "# we can't create useful linked data, so we skip saving it\n", "print(\"Trait data is not available. No linked data was created or 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 }