{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "454f8ef2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:25.130047Z", "iopub.status.busy": "2025-03-25T05:27:25.129930Z", "iopub.status.idle": "2025-03-25T05:27:25.288560Z", "shell.execute_reply": "2025-03-25T05:27:25.288223Z" } }, "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 = \"Head_and_Neck_Cancer\"\n", "cohort = \"GSE151181\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Head_and_Neck_Cancer\"\n", "in_cohort_dir = \"../../input/GEO/Head_and_Neck_Cancer/GSE151181\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Head_and_Neck_Cancer/GSE151181.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Head_and_Neck_Cancer/gene_data/GSE151181.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Head_and_Neck_Cancer/clinical_data/GSE151181.csv\"\n", "json_path = \"../../output/preprocess/Head_and_Neck_Cancer/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "1ca97fc3", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "2763fae3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:25.289922Z", "iopub.status.busy": "2025-03-25T05:27:25.289787Z", "iopub.status.idle": "2025-03-25T05:27:25.469953Z", "shell.execute_reply": "2025-03-25T05:27:25.469590Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Gene and miRNA expression in radioiodine refractory and avid papillary thyroid carcinomas\"\n", "!Series_summary\t\"This SuperSeries is composed of the SubSeries listed below.\"\n", "!Series_overall_design\t\"Refer to individual Series\"\n", "Sample Characteristics Dictionary:\n", "{0: ['histological variant: Classical', 'histological variant: Follicular', 'histological variant: NA', 'histological variant: non-neoplastic thyroid'], 1: ['tissue type: Primary tumor', 'tissue type: synchronous lymph node metastasis', 'tissue type: lymph node metastasis post RAI', 'tissue type: lymph node metastasis_2 post RAI', 'tissue type: lymph node metastasis_1 post RAI', 'tissue type: non-neoplastic thyroid'], 2: ['collection before/after rai: Before', 'collection before/after rai: After'], 3: ['patient id: pt_1', 'patient id: pt_2', 'patient id: pt_3', 'patient id: pt_5', 'patient id: pt_7', 'patient id: pt_8', 'patient id: pt_11', 'patient id: pt_12', 'patient id: pt_13', 'patient id: pt_14', 'patient id: pt_15', 'patient id: pt_19', 'patient id: pt_21', 'patient id: pt_22', 'patient id: pt_23', 'patient id: pt_25', 'patient id: pt_27', 'patient id: pt_28', 'patient id: pt_29', 'patient id: pt_32', 'patient id: pt_34', 'patient id: pt_35', 'patient id: pt_37', 'patient id: pt_39', 'patient id: pt_40', 'patient id: pt_41', 'patient id: pt_42', 'patient id: pt_44', 'patient id: pt_45', 'patient id: pt_46'], 4: ['patient rai responce: Avid', 'patient rai responce: Refractory'], 5: ['rai uptake at the metastatic site: Yes', 'rai uptake at the metastatic site: No'], 6: ['disease: Remission', 'disease: Persistence'], 7: ['lesion by ptc-ma: WT', 'lesion by ptc-ma: BRAFV600E', 'lesion by ptc-ma: RET/PTC1', 'lesion by ptc-ma: RET/PTC1 e NTRK-T1', 'lesion by ptc-ma: RET/PTC3', 'lesion by ptc-ma: NTRK', 'lesion by ptc-ma: TERT228', 'lesion by ptc-ma: TERT250', 'lesion by ptc-ma: BRAFV600E + TERT228', 'lesion by ptc-ma: non-neoplastic thyroid'], 8: ['lesion class: WT', 'lesion class: BRAFV600E', 'lesion class: Fusion', 'lesion class: pTERT', 'lesion class: BRAFV600E +pTERT', 'lesion class: non-neoplastic thyroid'], 9: ['patients with available multiple tumor tissues: No', 'patients with available multiple tumor tissues: pz_7', 'patients with available multiple tumor tissues: pz_22', 'patients with available multiple tumor tissues: pz_34', 'patients with available multiple tumor tissues: pz_40', 'patients with available multiple tumor tissues: pz_41', 'patients with available multiple tumor tissues: pz_42'], 10: ['tumor purity class by cibersort: high purity', 'tumor purity class by cibersort: low purity']}\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": "d60c2ea2", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "69756a3d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:25.471251Z", "iopub.status.busy": "2025-03-25T05:27:25.471136Z", "iopub.status.idle": "2025-03-25T05:27:25.475145Z", "shell.execute_reply": "2025-03-25T05:27:25.474857Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Clinical data is available for GSE151181.\n", "Trait row identified: 4 (patient rai response)\n", "This information has been recorded in ../../output/preprocess/Head_and_Neck_Cancer/cohort_info.json\n", "Note: Actual clinical data extraction would require the proper clinical_data.csv file.\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this appears to be a SuperSeries containing gene expression data\n", "# The title mentions \"Gene and miRNA expression\" so it likely contains gene expression data\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "\n", "# 2.1 Data Availability\n", "# For trait (Head and Neck Cancer):\n", "# Based on the provided information, this appears to be a dataset about thyroid cancer\n", "# Key 4 contains information about \"patient rai response\" which can be used as our trait\n", "trait_row = 4\n", "\n", "# For age:\n", "# There is no age information in the sample characteristics\n", "age_row = None\n", "\n", "# For gender:\n", "# There is no gender information in the sample characteristics\n", "gender_row = None\n", "\n", "# 2.2 Data Type Conversion Functions\n", "\n", "def convert_trait(value):\n", " \"\"\"Convert trait value (radioiodine response) to binary format\"\"\"\n", " if pd.isna(value) or value is None:\n", " return None\n", " \n", " # Extract value after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Convert to binary: Refractory (resistant to treatment) = 1, Avid (responsive) = 0\n", " if 'refractory' in value.lower():\n", " return 1 # Refractory - disease is persistent/resistant\n", " elif 'avid' in value.lower():\n", " return 0 # Avid - disease responds to radioiodine\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age value to numeric\"\"\"\n", " # No age data available\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender value to binary format\"\"\"\n", " # No gender data available\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Determine trait data availability\n", "is_trait_available = trait_row is not None\n", "\n", "# Save initial metadata\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available\n", ")\n", "\n", "# 4. Clinical Feature Extraction\n", "# Since we don't have direct access to the actual clinical data file,\n", "# we'll note that trait information is available and has been recorded in the json file\n", "if trait_row is not None:\n", " print(f\"Clinical data is available for {cohort}.\")\n", " print(f\"Trait row identified: {trait_row} (patient rai response)\")\n", " print(f\"This information has been recorded in {json_path}\")\n", " print(\"Note: Actual clinical data extraction would require the proper clinical_data.csv file.\")\n" ] }, { "cell_type": "markdown", "id": "5e4b312f", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "2604ba6d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:25.476239Z", "iopub.status.busy": "2025-03-25T05:27:25.476134Z", "iopub.status.idle": "2025-03-25T05:27:25.758059Z", "shell.execute_reply": "2025-03-25T05:27:25.757707Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Head_and_Neck_Cancer/GSE151181/GSE151181-GPL21575_series_matrix.txt.gz\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape: (62976, 47)\n", "First 20 gene/probe identifiers:\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 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": "95ec7c47", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "cdf57b28", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:25.759409Z", "iopub.status.busy": "2025-03-25T05:27:25.759287Z", "iopub.status.idle": "2025-03-25T05:27:25.761218Z", "shell.execute_reply": "2025-03-25T05:27:25.760933Z" } }, "outputs": [], "source": [ "# Examining the identifiers in the gene expression data\n", "\n", "# The identifiers in the gene expression data are numeric strings (e.g., '23064070', '23064071')\n", "# These appear to be probe IDs from a microarray platform (GPL23159) rather than standard gene symbols\n", "# Standard human gene symbols would typically be letters or combinations of letters and numbers like \"TP53\", \"BRCA1\", etc.\n", "# These numeric IDs will need to be mapped to standard gene symbols for proper analysis\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "e78d9eff", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "9c889a1f", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:25.762398Z", "iopub.status.busy": "2025-03-25T05:27:25.762299Z", "iopub.status.idle": "2025-03-25T05:27:31.612926Z", "shell.execute_reply": "2025-03-25T05:27:31.612375Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene annotation preview:\n", "Columns in gene annotation: ['ID', 'COL', 'ROW', 'SPOT_ID', 'CONTROL_TYPE', 'miRNA_ID', 'GENE_SYMBOL', 'GENE_NAME', 'ACCESSION_STRING', 'CHROMOSOMAL_LOCATION']\n", "{'ID': ['1', '2', '3', '4', '5'], 'COL': ['192', '192', '192', '192', '192'], 'ROW': ['328', '326', '324', '322', '320'], 'SPOT_ID': ['miRNABrightCorner30', 'Blank', 'Blank', 'Blank', 'Blank'], 'CONTROL_TYPE': ['pos', 'pos', 'pos', 'pos', 'pos'], 'miRNA_ID': [nan, nan, nan, nan, nan], 'GENE_SYMBOL': [nan, nan, nan, nan, nan], 'GENE_NAME': [nan, nan, nan, nan, nan], 'ACCESSION_STRING': [nan, nan, nan, nan, nan], 'CHROMOSOMAL_LOCATION': [nan, nan, nan, nan, nan]}\n", "\n", "Searching for platform information in SOFT file:\n", "Platform ID not found in first 100 lines\n", "\n", "Searching for gene symbol information in SOFT file:\n", "Found references to gene symbols:\n", "#GENE_SYMBOL = Gene Symbol\n", "ID\tCOL\tROW\tSPOT_ID\tCONTROL_TYPE\tmiRNA_ID\tGENE_SYMBOL\tGENE_NAME\tACCESSION_STRING\tCHROMOSOMAL_LOCATION\n", "\n", "Checking for additional annotation files in the directory:\n", "['GSE151181-GPL21575_series_matrix.txt.gz', 'GSE151181-GPL23159_series_matrix.txt.gz']\n" ] } ], "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. 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", "# Let's look for platform information in the SOFT file to understand the annotation better\n", "print(\"\\nSearching for platform information in SOFT file:\")\n", "with gzip.open(soft_file, 'rt') as f:\n", " for i, line in enumerate(f):\n", " if '!Series_platform_id' in line:\n", " print(line.strip())\n", " break\n", " if i > 100: # Limit search to first 100 lines\n", " print(\"Platform ID not found in first 100 lines\")\n", " break\n", "\n", "# Check if the SOFT file includes any reference to gene symbols\n", "print(\"\\nSearching for gene symbol information in SOFT file:\")\n", "with gzip.open(soft_file, 'rt') as f:\n", " gene_symbol_lines = []\n", " for i, line in enumerate(f):\n", " if 'GENE_SYMBOL' in line or 'gene_symbol' in line.lower() or 'symbol' in line.lower():\n", " gene_symbol_lines.append(line.strip())\n", " if i > 1000 and len(gene_symbol_lines) > 0: # Limit search but ensure we found something\n", " break\n", " \n", " if gene_symbol_lines:\n", " print(\"Found references to gene symbols:\")\n", " for line in gene_symbol_lines[:5]: # Show just first 5 matches\n", " print(line)\n", " else:\n", " print(\"No explicit gene symbol references found in first 1000 lines\")\n", "\n", "# Look for alternative annotation files or references in the directory\n", "print(\"\\nChecking for additional annotation files in the directory:\")\n", "all_files = os.listdir(in_cohort_dir)\n", "print([f for f in all_files if 'annotation' in f.lower() or 'platform' in f.lower() or 'gpl' in f.lower()])\n" ] }, { "cell_type": "markdown", "id": "bc7db003", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "c5873e8b", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:31.614953Z", "iopub.status.busy": "2025-03-25T05:27:31.614798Z", "iopub.status.idle": "2025-03-25T05:27:33.337149Z", "shell.execute_reply": "2025-03-25T05:27:33.336517Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Available matrix files: ['GSE151181-GPL21575_series_matrix.txt.gz', 'GSE151181-GPL23159_series_matrix.txt.gz']\n", "Found Clariom gene expression array: GSE151181-GPL21575_series_matrix.txt.gz\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data shape from Clariom array: (62976, 47)\n", "First few probe IDs: ['1', '2', '3', '4', '5']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Platform-specific annotation not found in SOFT file\n", "Successfully mapped probes to genes. Shape: (62976, 47)\n", "Final gene expression data shape after normalization: (0, 47)\n", "Sample of gene symbols: []\n", "Final gene data shape: (0, 47)\n", "Will proceed with probe-level data for further analysis\n" ] } ], "source": [ "# 1. Reassess the matrix files and identify the correct platform\n", "matrix_files = [f for f in os.listdir(in_cohort_dir) if 'matrix' in f.lower()]\n", "print(f\"Available matrix files: {matrix_files}\")\n", "\n", "# From previous output we see two platforms:\n", "# - GPL23159 (Agilent-070156 Human_miRNA_V21.0) - this is a miRNA array\n", "# - GPL21575 (Clariom_S_Human) - this is a gene expression array\n", "\n", "# We want gene expression data for our Head and Neck Cancer trait analysis\n", "# Let's check if we have a Clariom array matrix file which would contain gene expression\n", "clariom_matrix = [f for f in matrix_files if 'GPL21575' in f]\n", "if clariom_matrix:\n", " print(f\"Found Clariom gene expression array: {clariom_matrix[0]}\")\n", " gene_matrix_path = os.path.join(in_cohort_dir, clariom_matrix[0])\n", " \n", " # Extract gene expression data from the correct matrix file\n", " gene_data = get_genetic_data(gene_matrix_path)\n", " print(f\"Gene expression data shape from Clariom array: {gene_data.shape}\")\n", " print(f\"First few probe IDs: {gene_data.index[:5].tolist()}\")\n", " \n", " # Get the annotation for this specific platform\n", " with gzip.open(soft_file, 'rt') as f:\n", " platform_section = False\n", " platform_annotation_text = \"\"\n", " for line in f:\n", " if line.startswith('!Platform_table_begin') and 'GPL21575' in line:\n", " platform_section = True\n", " continue\n", " elif line.startswith('!Platform_table_end') and platform_section:\n", " break\n", " elif platform_section:\n", " platform_annotation_text += line\n", " \n", " # Check if we found platform-specific annotation\n", " if platform_annotation_text:\n", " print(\"Found platform-specific annotation for Clariom array\")\n", " # Parse the annotation to create mapping\n", " platform_annotation_df = pd.read_csv(io.StringIO(platform_annotation_text), sep='\\t')\n", " print(f\"Annotation columns: {platform_annotation_df.columns.tolist()}\")\n", " \n", " # Check for gene symbol column\n", " gene_symbol_cols = [col for col in platform_annotation_df.columns if 'symbol' in col.lower()]\n", " if gene_symbol_cols:\n", " # Create mapping dataframe using the ID column and gene symbol column\n", " prob_col = platform_annotation_df.columns[0] # First column is typically the probe ID\n", " gene_col = gene_symbol_cols[0]\n", " \n", " print(f\"Using mapping from {prob_col} to {gene_col}\")\n", " gene_mapping = platform_annotation_df[[prob_col, gene_col]].dropna(subset=[gene_col])\n", " gene_mapping = gene_mapping.rename(columns={prob_col: 'ID', gene_col: 'Gene'})\n", " gene_mapping['ID'] = gene_mapping['ID'].astype(str)\n", " \n", " # Apply gene mapping\n", " print(f\"Gene mapping shape: {gene_mapping.shape}\")\n", " mapped_gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", " gene_data = mapped_gene_data\n", " else:\n", " print(\"No gene symbol column found in annotation\")\n", " else:\n", " print(\"Platform-specific annotation not found in SOFT file\")\n", "\n", "# If mapping isn't possible or resulting data is empty, continue with original probe IDs\n", "if 'gene_data' not in locals() or gene_data.shape[0] == 0:\n", " print(\"Direct mapping not successful. Using original probe IDs for downstream analysis.\")\n", " # Continue using the original gene expression data\n", " # No need to reassign gene_data as it still contains the probe-level data\n", "else:\n", " # If mapping was successful, apply normalization to handle gene synonyms\n", " print(f\"Successfully mapped probes to genes. Shape: {gene_data.shape}\")\n", " gene_data = normalize_gene_symbols_in_index(gene_data)\n", " print(f\"Final gene expression data shape after normalization: {gene_data.shape}\")\n", " print(f\"Sample of gene symbols: {gene_data.index[:10].tolist()}\")\n", "\n", "# Print final status\n", "print(f\"Final gene data shape: {gene_data.shape}\")\n", "print(f\"Will proceed with {'gene-level' if gene_data.shape[0] > 0 else 'probe-level'} data for further analysis\")\n" ] }, { "cell_type": "markdown", "id": "de2b17c1", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "bb88553a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:33.338897Z", "iopub.status.busy": "2025-03-25T05:27:33.338780Z", "iopub.status.idle": "2025-03-25T05:27:33.361594Z", "shell.execute_reply": "2025-03-25T05:27:33.360930Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape: (0, 47)\n", "Gene data is empty (0 rows). Cannot proceed with proper analysis.\n", "Empty gene expression data saved to ../../output/preprocess/Head_and_Neck_Cancer/gene_data/GSE151181.csv\n", "Clinical features saved to ../../output/preprocess/Head_and_Neck_Cancer/clinical_data/GSE151181.csv\n", "Abnormality detected in the cohort: GSE151181. Preprocessing failed.\n", "Dataset GSE151181 is not usable for Head_and_Neck_Cancer analysis due to empty gene expression data.\n" ] } ], "source": [ "# 1. Since we have empty gene expression data, mark dataset as unusable\n", "print(f\"Gene data shape: {gene_data.shape}\")\n", "print(\"Gene data is empty (0 rows). Cannot proceed with proper analysis.\")\n", "\n", "# Save the empty gene data for documentation\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\"Empty gene expression data saved to {out_gene_data_file}\")\n", "\n", "# 2. Extract clinical features for documentation purposes\n", "if trait_row is not None:\n", " try:\n", " # Extract clinical features using the geo_select_clinical_features function\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", " # 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 features saved to {out_clinical_data_file}\")\n", " except Exception as e:\n", " print(f\"Error extracting clinical features: {e}\")\n", " clinical_features = pd.DataFrame()\n", "\n", "# 3. Mark this dataset as unusable since we have empty gene data\n", "note = \"Dataset cannot be used for analysis due to empty gene expression data. The gene mapping and normalization process resulted in 0 rows of 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=False, # Mark as False since we have 0 rows\n", " is_trait_available=(trait_row is not None),\n", " is_biased=True, # Mark as biased since we can't properly analyze\n", " df=pd.DataFrame(), # Use empty DataFrame\n", " note=note\n", ")\n", "\n", "print(f\"Dataset {cohort} is not usable for {trait} analysis due to empty gene expression data.\")" ] } ], "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 }