{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "5e2ff7d7", "metadata": {}, "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 = \"Hypertension\"\n", "cohort = \"GSE128381\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Hypertension\"\n", "in_cohort_dir = \"../../input/GEO/Hypertension/GSE128381\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Hypertension/GSE128381.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Hypertension/gene_data/GSE128381.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Hypertension/clinical_data/GSE128381.csv\"\n", "json_path = \"../../output/preprocess/Hypertension/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "cceec978", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": null, "id": "a5cd6db3", "metadata": {}, "outputs": [], "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": "f1ff32d7", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": null, "id": "52ca1237", "metadata": {}, "outputs": [], "source": [ "I'll provide a corrected implementation that properly handles the sample characteristics dictionary:\n", "\n", "```python\n", "# 1. Assess gene expression data availability\n", "# Based on the series title and summary, this dataset appears to contain gene expression data from RNA microarray\n", "is_gene_available = True\n", "\n", "# 2. Variable availability and data type conversion\n", "# 2.1. Identify rows for trait, age, and gender in the sample characteristics dictionary\n", "# For hypertension, row 14 contains gestational hypertension information\n", "trait_row = 14\n", "\n", "# Age information is available in row 10 (maternal age)\n", "age_row = 10\n", "\n", "# Gender information is available in row 6\n", "gender_row = 6\n", "\n", "# 2.2. Define conversion functions for each variable\n", "\n", "def convert_trait(value):\n", " \"\"\"Convert hypertension status to binary.\"\"\"\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Convert to binary (0: no, 1: yes)\n", " if value == '0 (no)':\n", " return 0\n", " elif value == '1 (yes)':\n", " return 1\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age to continuous numeric value.\"\"\"\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Extract the numeric value\n", " try:\n", " # Extract just the number\n", " if '(year)' in value:\n", " value = value.replace('(year)', '').strip()\n", " return float(value)\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary (0: female, 1: male).\"\"\"\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Convert to binary\n", " if value.lower() == 'female':\n", " return 0\n", " elif value.lower() == 'male':\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save metadata about usability\n", "# Check if trait data is available\n", "is_trait_available = trait_row is not None\n", "\n", "# Validate and save cohort info for initial filtering\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. Extract clinical features if trait data is available\n", "if trait_row is not None:\n", " # Create a DataFrame from the sample characteristics dictionary\n", " sample_chars = {0: ['tissue: Placenta'], \n", " 1: ['labeling date: 6/12/2017', 'labeling date: 4/21/2017', 'labeling date: 6/9/2017', 'labeling date: 5/29/2017', 'labeling date: 6/7/2017', 'labeling date: 6/13/2017', 'labeling date: 6/15/2017', 'labeling date: 6/14/2017', 'labeling date: 2/20/2017', 'labeling date: 8/15/2017'], \n", " 2: ['hybridization date: 6/28/2017', 'hybridization date: 4/24/2017', 'hybridization date: 6/27/2017', 'hybridization date: 6/21/2017', 'hybridization date: 6/26/2017', 'hybridization date: 7/3/2017', 'hybridization date: 7/12/2017', 'hybridization date: 7/4/2017', 'hybridization date: 2/22/2017', 'hybridization date: 7/10/2017', 'hybridization date: 8/17/2017'], \n", " 3: ['date delivery: 1/24/2014', 'date delivery: 1/25/2014', 'date delivery: 2/15/2014', 'date delivery: 2/7/2014', 'date delivery: 4/24/2014', 'date delivery: 3/9/2014', 'date delivery: 3/14/2014', 'date delivery: 4/13/2014', 'date delivery: 5/2/2014', 'date delivery: 5/22/2014', 'date delivery: 5/28/2014', 'date delivery: 7/14/2014', 'date delivery: 7/17/2014', 'date delivery: 8/14/2014', 'date delivery: 9/5/2014', 'date delivery: 9/12/2014', 'date delivery: 9/15/2014', 'date delivery: 9/24/2014', 'date delivery: 10/3/2014', 'date delivery: 10/31/2014', 'date delivery: 10/10/2014', 'date delivery: 10/24/2014', 'date delivery: 11/6/2014', 'date delivery: 11/7/2014', 'date delivery: 12/5/2014', 'date delivery: 2/13/2015', 'date delivery: 2/24/2015', 'date delivery: 5/1/2015', 'date delivery: 2/28/2015', 'date delivery: 3/6/2015'], \n", " 4: ['maternal pre-pregnancy bmi: 23', 'maternal pre-pregnancy bmi: 31.2', 'maternal pre-pregnancy bmi: 18.4', 'maternal pre-pregnancy bmi: 25.3', 'maternal pre-pregnancy bmi: 22.4', 'maternal pre-pregnancy bmi: 19.7', 'maternal pre-pregnancy bmi: 22', 'maternal pre-pregnancy bmi: 21.1', 'maternal pre-pregnancy bmi: 18.7', 'maternal pre-pregnancy bmi: 34.3', 'maternal pre-pregnancy bmi: 39.3', 'maternal pre-pregnancy bmi: 19.3', 'maternal pre-pregnancy bmi: 24.3', 'maternal pre-pregnancy bmi: 28.4', 'maternal pre-pregnancy bmi: 47.2', 'maternal pre-pregnancy bmi: 18.2', 'maternal pre-pregnancy bmi: 23.4', 'maternal pre-pregnancy bmi: 27.5', 'maternal pre-pregnancy bmi: 19.6', 'maternal pre-pregnancy bmi: 26.2', 'maternal pre-pregnancy bmi: 19.5', 'maternal pre-pregnancy bmi: 27.1', 'maternal pre-pregnancy bmi: 25.4', 'maternal pre-pregnancy bmi: 29', 'maternal pre-pregnancy bmi: 26.6', 'maternal pre-pregnancy bmi: 16.8', 'maternal pre-pregnancy bmi: 24.9', 'maternal pre-pregnancy bmi: 24.7', 'maternal pre-pregnancy bmi: 29.9', 'maternal pre-pregnancy bmi: 22.2'], \n", " 5: ['birth weight (gram): 3575', 'birth weight (gram): 3635', 'birth weight (gram): 2415', 'birth weight (gram): 3725', 'birth weight (gram): 3965', 'birth weight (gram): 3735', 'birth weight (gram): 2775', 'birth weight (gram): 1930', 'birth weight (gram): 2890', 'birth weight (gram): 3240', 'birth weight (gram): 2700', 'birth weight (gram): 2590', 'birth weight (gram): 3135', 'birth weight (gram): 1765', 'birth weight (gram): 2975', 'birth weight (gram): 3100', 'birth weight (gram): 3055',\n" ] }, { "cell_type": "markdown", "id": "77a821dd", "metadata": {}, "source": [ "### Step 3: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": null, "id": "acab4277", "metadata": {}, "outputs": [], "source": [ "# Analyzing sample data\n", "import os\n", "import json\n", "import pandas as pd\n", "from typing import Optional, Dict, Any, Callable\n", "\n", "# Check for various possible locations/naming of the clinical data\n", "possible_clinical_files = [\n", " os.path.join(in_cohort_dir, \"sample_characteristics.csv\"),\n", " os.path.join(in_cohort_dir, \"characteristics.csv\"),\n", " os.path.join(in_cohort_dir, \"clinical_data.csv\"),\n", " os.path.join(in_cohort_dir, \"samples.csv\"),\n", " os.path.join(in_cohort_dir, \"metadata.csv\")\n", "]\n", "\n", "clinical_data = pd.DataFrame()\n", "found_clinical_file = False\n", "\n", "for file_path in possible_clinical_files:\n", " if os.path.exists(file_path):\n", " clinical_data = pd.read_csv(file_path, index_col=0)\n", " print(f\"Sample characteristics data loaded successfully from {file_path}\")\n", " print(f\"Shape of clinical_data: {clinical_data.shape}\")\n", " \n", " # Check the first few rows to see column names and data structure\n", " print(\"\\nPreview of clinical_data:\")\n", " print(clinical_data.head())\n", " \n", " # Check unique values for each row to determine data availability\n", " print(\"\\nUnique values for each row:\")\n", " for i, row in clinical_data.iterrows():\n", " print(f\"Row {i}: {row.unique()}\")\n", " \n", " found_clinical_file = True\n", " break\n", "\n", "if not found_clinical_file:\n", " print(\"Clinical data file not found in any expected location. Checking for any CSV files in the directory.\")\n", " \n", " # Look for any CSV files in the directory\n", " all_files = os.listdir(in_cohort_dir)\n", " csv_files = [f for f in all_files if f.endswith('.csv')]\n", " \n", " if csv_files:\n", " print(f\"Found the following CSV files: {csv_files}\")\n", " # Try to load the first CSV file found\n", " first_csv = os.path.join(in_cohort_dir, csv_files[0])\n", " try:\n", " clinical_data = pd.read_csv(first_csv, index_col=0)\n", " print(f\"Loaded {first_csv} as clinical data\")\n", " print(f\"Shape of clinical_data: {clinical_data.shape}\")\n", " print(\"\\nPreview of clinical_data:\")\n", " print(clinical_data.head())\n", " found_clinical_file = True\n", " except Exception as e:\n", " print(f\"Error loading {first_csv}: {e}\")\n", " else:\n", " print(f\"No CSV files found in {in_cohort_dir}\")\n", "\n", "# Function to help extract values after colon\n", "def extract_value_after_colon(text):\n", " if pd.isna(text):\n", " return None\n", " if ':' in str(text):\n", " return str(text).split(':', 1)[1].strip()\n", " return str(text).strip()\n", "\n", "# 1. Gene Expression Data Availability\n", "# Assuming gene expression data is likely available unless we find evidence to the contrary\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# Identifying rows for trait, age, and gender data\n", "trait_row = None\n", "age_row = None\n", "gender_row = None\n", "\n", "# Check if clinical data is available before proceeding\n", "if not clinical_data.empty:\n", " # Checking sample characteristics for trait data\n", " for i, row in clinical_data.iterrows():\n", " unique_values = row.unique()\n", " row_str = ' '.join([str(v) for v in unique_values if pd.notna(v)])\n", " \n", " # Check for hypertension-related terms\n", " if 'hypertension' in row_str.lower() or 'blood pressure' in row_str.lower() or 'bp' in row_str.lower():\n", " trait_row = i\n", " print(f\"Found trait data in row {i}: {unique_values}\")\n", " \n", " # Check for age-related terms\n", " if 'age' in row_str.lower() or 'year' in row_str.lower():\n", " age_row = i\n", " print(f\"Found age data in row {i}: {unique_values}\")\n", " \n", " # Check for gender-related terms\n", " if 'gender' in row_str.lower() or 'sex' in row_str.lower() or 'male' in row_str.lower() or 'female' in row_str.lower():\n", " gender_row = i\n", " print(f\"Found gender data in row {i}: {unique_values}\")\n", "else:\n", " print(\"No clinical data available. Cannot identify trait, age, or gender information.\")\n", "\n", "# Define conversion functions\n", "def convert_trait(value):\n", " if pd.isna(value):\n", " return None\n", " \n", " value = extract_value_after_colon(value).lower()\n", " \n", " if 'yes' in value or 'hypertension' in value or 'high' in value:\n", " return 1\n", " elif 'no' in value or 'normal' in value or 'control' in value:\n", " return 0\n", " return None\n", "\n", "def convert_age(value):\n", " if pd.isna(value):\n", " return None\n", " \n", " value = extract_value_after_colon(value)\n", " \n", " # Try to extract number from the string\n", " import re\n", " numbers = re.findall(r'\\d+\\.?\\d*', value)\n", " if numbers:\n", " return float(numbers[0])\n", " return None\n", "\n", "def convert_gender(value):\n", " if pd.isna(value):\n", " return None\n", " \n", " value = extract_value_after_colon(value).lower()\n", " \n", " if 'male' in value or 'm' == value:\n", " return 1\n", " elif 'female' in value or 'f' == value:\n", " return 0\n", " return None\n", "\n", "# 3. Save Metadata\n", "is_trait_available = trait_row is not None\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available\n", ")\n", "\n", "# 4. Clinical Feature Extraction\n", "if trait_row is not None:\n", " # Extract clinical features\n", " 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 if age_row is not None else None,\n", " gender_row=gender_row,\n", " convert_gender=convert_gender if gender_row is not None else None\n", " )\n", " \n", " # Preview the clinical dataframe\n", " print(\"\\nPreview of processed clinical data:\")\n", " preview = preview_df(clinical_df)\n", " print(preview)\n", " \n", " # Save clinical data to CSV\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " clinical_df.to_csv(out_clinical_data_file)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n", "else:\n", " print(\"No trait data found. Skipping clinical feature extraction.\")\n", " \n", " # Even if we don't have trait data, we should still create the output directory\n", " # in case we need to save other data files later\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n" ] }, { "cell_type": "markdown", "id": "bcca9e87", "metadata": {}, "source": [ "### Step 4: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": null, "id": "478d30de", "metadata": {}, "outputs": [], "source": [ "# 1. First get the file paths again to access the matrix file\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. Use the get_genetic_data function from the library to get the gene_data from the matrix_file\n", "gene_data = get_genetic_data(matrix_file)\n", "\n", "# 3. Print the first 20 row IDs (gene or probe identifiers) for future observation\n", "print(\"First 20 gene/probe identifiers:\")\n", "print(gene_data.index[:20])\n" ] }, { "cell_type": "markdown", "id": "78d02625", "metadata": {}, "source": [ "### Step 5: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": null, "id": "2a19bc85", "metadata": {}, "outputs": [], "source": [ "# Reviewing the gene identifiers\n", "# The identifiers starting with \"A_19_P\" appear to be Agilent microarray probe IDs,\n", "# not standard human gene symbols like BRCA1, TP53, etc.\n", "# These need to be mapped to standard gene symbols for analysis\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "2d78c90b", "metadata": {}, "source": [ "### Step 6: Gene Annotation" ] }, { "cell_type": "code", "execution_count": null, "id": "b2111549", "metadata": {}, "outputs": [], "source": [ "# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.\n", "gene_annotation = get_gene_annotation(soft_file)\n", "\n", "# 2. Use the 'preview_df' function from the library to preview the data and print out the results.\n", "print(\"Gene annotation preview:\")\n", "print(preview_df(gene_annotation))\n" ] }, { "cell_type": "markdown", "id": "9315667a", "metadata": {}, "source": [ "### Step 7: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": null, "id": "d08ddd54", "metadata": {}, "outputs": [], "source": [ "# 1. Determine mapping columns\n", "# From the gene annotation preview, we can see:\n", "# - The 'ID' column contains probe IDs like 'A_23_P117082' matching the expression data index\n", "# - The 'GENE_SYMBOL' column contains human gene symbols like 'HEBP1', 'KCNE4', etc.\n", "\n", "# 2. Get gene mapping dataframe by extracting relevant columns\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')\n", "\n", "# 3. Apply gene mapping to convert probe-level data to gene-level data\n", "# This handles many-to-many relationships between probes and genes\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Display first few genes to verify mapping worked correctly\n", "print(\"First 10 genes after mapping:\")\n", "print(gene_data.index[:10])\n", "print(\"\\nShape of gene expression data after mapping:\")\n", "print(gene_data.shape)\n" ] }, { "cell_type": "markdown", "id": "81c5a1c0", "metadata": {}, "source": [ "### Step 8: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": null, "id": "74769718", "metadata": {}, "outputs": [], "source": [ "# 1. First, we need to re-obtain the clinical data from the matrix file since it wasn't successfully loaded in previous steps\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# Re-extract background information and clinical data from the matrix file\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", "# Get unique values for each row to identify trait, age, and gender rows\n", "sample_chars = get_unique_values_by_row(clinical_data)\n", "\n", "# Identify rows for hypertension trait, age, and gender based on the sample characteristics\n", "trait_row = 14 # 'gestational hypertension: 0 (no)' / 'gestational hypertension: 1 (yes)'\n", "age_row = 10 # 'maternal age (year): XX'\n", "gender_row = 6 # 'Sex: Male' / 'Sex: Female'\n", "\n", "# Define conversion functions for each variable\n", "def convert_trait(value):\n", " \"\"\"Convert hypertension status to binary.\"\"\"\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Convert to binary (0: no, 1: yes)\n", " if '0 (no)' in value:\n", " return 0\n", " elif '1 (yes)' in value:\n", " return 1\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age to continuous numeric value.\"\"\"\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Extract the numeric value\n", " try:\n", " # Parse the year value\n", " year_value = value.replace('(year)', '').strip()\n", " return float(year_value)\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary (0: female, 1: male).\"\"\"\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Convert to binary\n", " if value.lower() == 'female':\n", " return 0\n", " elif value.lower() == 'male':\n", " return 1\n", " else:\n", " return None\n", "\n", "# Extract clinical features\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", "# Save the extracted clinical features to a CSV file\n", "os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", "selected_clinical_df.to_csv(out_clinical_data_file)\n", "print(f\"Clinical data saved to {out_clinical_data_file}\")\n", "\n", "# Re-extract the gene expression data from the matrix file\n", "gene_data_raw = get_genetic_data(matrix_file)\n", "\n", "# Extract gene annotation data from the SOFT file\n", "gene_annotation = get_gene_annotation(soft_file)\n", "\n", "# Get gene mapping dataframe\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')\n", "\n", "# Apply gene mapping to convert probe-level data to gene-level data\n", "gene_data = apply_gene_mapping(gene_data_raw, gene_mapping)\n", "\n", "# Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "normalized_gene_data.to_csv(out_gene_data_file)\n", "print(f\"Normalized gene data saved to {out_gene_data_file}\")\n", "\n", "# Link the clinical and genetic data\n", "linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)\n", "print(f\"Shape of linked data before missing value handling: {linked_data.shape}\")\n", "\n", "# Handle missing values systematically\n", "linked_data = handle_missing_values(linked_data, trait)\n", "print(f\"Shape of linked data after missing value handling: {linked_data.shape}\")\n", "\n", "# Check if the trait and demographic features are severely biased\n", "is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)\n", "\n", "# Validate and save cohort information\n", "note = \"Dataset containing maternal gestational hypertension information and placental gene expression data.\"\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,\n", " note=note\n", ")\n", "\n", "# 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.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(\"Dataset is not usable for trait-gene association studies due to quality issues.\")" ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 5 }