{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "31136847", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:04:45.217570Z", "iopub.status.busy": "2025-03-25T06:04:45.217335Z", "iopub.status.idle": "2025-03-25T06:04:45.385351Z", "shell.execute_reply": "2025-03-25T06:04:45.384956Z" } }, "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 = \"Ovarian_Cancer\"\n", "cohort = \"GSE201525\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Ovarian_Cancer\"\n", "in_cohort_dir = \"../../input/GEO/Ovarian_Cancer/GSE201525\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Ovarian_Cancer/GSE201525.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Ovarian_Cancer/gene_data/GSE201525.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Ovarian_Cancer/clinical_data/GSE201525.csv\"\n", "json_path = \"../../output/preprocess/Ovarian_Cancer/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "f8395e54", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "f86cb3fd", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:04:45.386862Z", "iopub.status.busy": "2025-03-25T06:04:45.386712Z", "iopub.status.idle": "2025-03-25T06:04:45.525652Z", "shell.execute_reply": "2025-03-25T06:04:45.525317Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Files in the directory:\n", "['GSE201525-GPL21810_series_matrix.txt.gz', 'GSE201525_family.soft.gz']\n", "SOFT file: ../../input/GEO/Ovarian_Cancer/GSE201525/GSE201525_family.soft.gz\n", "Matrix file: ../../input/GEO/Ovarian_Cancer/GSE201525/GSE201525-GPL21810_series_matrix.txt.gz\n", "Background Information:\n", "!Series_title\t\"Investigation of the anti-tumour properties of interferon epsilon in high grade serous ovarian cancer\"\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: ['treatment: UT', 'treatment: 1000IU_IFNE', 'treatment: 100IU_IFNE', 'treatment: 10IU_IFNE', 'treatment: 1000IU_IFNB', 'treatment: 100IU_IFNB', 'treatment: 10IU_IFNB'], 1: ['replicate: R1', 'replicate: R2', 'replicate: R3']}\n" ] } ], "source": [ "# 1. Check what files are actually in the directory\n", "import os\n", "print(\"Files in the directory:\")\n", "files = os.listdir(in_cohort_dir)\n", "print(files)\n", "\n", "# 2. Find appropriate files with more flexible pattern matching\n", "soft_file = None\n", "matrix_file = None\n", "\n", "for file in files:\n", " file_path = os.path.join(in_cohort_dir, file)\n", " # Look for files that might contain SOFT or matrix data with various possible extensions\n", " if 'soft' in file.lower() or 'family' in file.lower() or file.endswith('.soft.gz'):\n", " soft_file = file_path\n", " if 'matrix' in file.lower() or file.endswith('.txt.gz') or file.endswith('.tsv.gz'):\n", " matrix_file = file_path\n", "\n", "if not soft_file:\n", " print(\"Warning: Could not find a SOFT file. Using the first .gz file as fallback.\")\n", " gz_files = [f for f in files if f.endswith('.gz')]\n", " if gz_files:\n", " soft_file = os.path.join(in_cohort_dir, gz_files[0])\n", "\n", "if not matrix_file:\n", " print(\"Warning: Could not find a matrix file. Using the second .gz file as fallback if available.\")\n", " gz_files = [f for f in files if f.endswith('.gz')]\n", " if len(gz_files) > 1 and soft_file != os.path.join(in_cohort_dir, gz_files[1]):\n", " matrix_file = os.path.join(in_cohort_dir, gz_files[1])\n", " elif len(gz_files) == 1 and not soft_file:\n", " matrix_file = os.path.join(in_cohort_dir, gz_files[0])\n", "\n", "print(f\"SOFT file: {soft_file}\")\n", "print(f\"Matrix file: {matrix_file}\")\n", "\n", "# 3. Read files if found\n", "if soft_file and matrix_file:\n", " # 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", " \n", " try:\n", " background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)\n", " \n", " # Obtain the sample characteristics dictionary from the clinical dataframe\n", " sample_characteristics_dict = get_unique_values_by_row(clinical_data)\n", " \n", " # 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", " except Exception as e:\n", " print(f\"Error processing files: {e}\")\n", " # Try swapping files if first attempt fails\n", " print(\"Trying to swap SOFT and matrix files...\")\n", " temp = soft_file\n", " soft_file = matrix_file\n", " matrix_file = temp\n", " try:\n", " background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)\n", " sample_characteristics_dict = get_unique_values_by_row(clinical_data)\n", " print(\"Background Information:\")\n", " print(background_info)\n", " print(\"Sample Characteristics Dictionary:\")\n", " print(sample_characteristics_dict)\n", " except Exception as e:\n", " print(f\"Still error after swapping: {e}\")\n", "else:\n", " print(\"Could not find necessary files for processing.\")\n" ] }, { "cell_type": "markdown", "id": "8d3c1b86", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "6202334b", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:04:45.527087Z", "iopub.status.busy": "2025-03-25T06:04:45.526964Z", "iopub.status.idle": "2025-03-25T06:04:45.534498Z", "shell.execute_reply": "2025-03-25T06:04:45.534182Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 1. Assess gene expression data availability\n", "# Based on the provided information, we cannot determine if gene expression data is present\n", "# The Series title suggests this might be interferon treatment data, but we don't have explicit confirmation\n", "# Let's set this to False until we can verify gene expression data exists\n", "is_gene_available = False\n", "\n", "# 2. Variable availability and data type conversion\n", "# From the sample characteristics dictionary, we can see:\n", "# - There are treatment groups (UT, IFNE at different doses, IFNB at different doses)\n", "# - There are replicates (R1, R2, R3)\n", "# But no direct information about Ovarian Cancer status, age, or gender\n", "\n", "# 2.1 Data Availability\n", "# None of the required variables appear to be directly available in the sample characteristics\n", "trait_row = None # No direct ovarian cancer status information\n", "age_row = None # No age information\n", "gender_row = None # No gender information\n", "\n", "# 2.2 Data Type Conversion Functions\n", "# Although we don't have these data, we'll define conversion functions as required\n", "\n", "def convert_trait(value):\n", " \"\"\"Convert trait value to binary format (0 or 1)\"\"\"\n", " if value is None or pd.isna(value):\n", " return None\n", " \n", " # Extract the value after colon if present\n", " if isinstance(value, str) and ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Convert to binary\n", " value_lower = str(value).lower()\n", " if 'control' in value_lower or 'normal' in value_lower or 'healthy' in value_lower:\n", " return 0\n", " elif 'cancer' in value_lower or 'tumor' in value_lower or 'oc' in value_lower:\n", " return 1\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age value to numeric format\"\"\"\n", " if value is None or pd.isna(value):\n", " return None\n", " \n", " # Extract the value after colon if present\n", " if isinstance(value, str) and ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Try to convert to float\n", " try:\n", " age = float(value)\n", " return age\n", " except (ValueError, TypeError):\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender value to binary format (0=female, 1=male)\"\"\"\n", " if value is None or pd.isna(value):\n", " return None\n", " \n", " # Extract the value after colon if present\n", " if isinstance(value, str) and ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Convert to binary\n", " value_lower = str(value).lower()\n", " if 'f' in value_lower or 'female' in value_lower:\n", " return 0\n", " elif 'm' in value_lower or 'male' in value_lower:\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Trait data is not available (trait_row is None)\n", "is_trait_available = trait_row is not None\n", "\n", "# Validate and save cohort 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", "# Since trait_row is None, we skip this substep\n" ] }, { "cell_type": "markdown", "id": "88972b4b", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "83a237c5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:04:45.535718Z", "iopub.status.busy": "2025-03-25T06:04:45.535600Z", "iopub.status.idle": "2025-03-25T06:04:45.718315Z", "shell.execute_reply": "2025-03-25T06:04:45.717944Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This appears to be a SuperSeries. Looking at the SOFT file to find potential subseries:\n", "Found potential subseries references:\n", "!Series_relation = SuperSeries of: GSE201337\n", "!Series_relation = SuperSeries of: GSE201345\n", "!Series_relation = SuperSeries of: GSE215261\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene data extraction result:\n", "Number of rows: 62976\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. First get the path to the soft and matrix files\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. Looking more carefully at the background information\n", "# This is a SuperSeries which doesn't contain direct gene expression data\n", "# Need to investigate the soft file to find the subseries\n", "print(\"This appears to be a SuperSeries. Looking at the SOFT file to find potential subseries:\")\n", "\n", "# Open the SOFT file to try to identify subseries\n", "with gzip.open(soft_file, 'rt') as f:\n", " subseries_lines = []\n", " for i, line in enumerate(f):\n", " if 'Series_relation' in line and 'SuperSeries of' in line:\n", " subseries_lines.append(line.strip())\n", " if i > 1000: # Limit search to first 1000 lines\n", " break\n", "\n", "# Display the subseries found\n", "if subseries_lines:\n", " print(\"Found potential subseries references:\")\n", " for line in subseries_lines:\n", " print(line)\n", "else:\n", " print(\"No subseries references found in the first 1000 lines of the SOFT file.\")\n", "\n", "# Despite trying to extract gene data, we expect it might fail because this is a SuperSeries\n", "try:\n", " gene_data = get_genetic_data(matrix_file)\n", " print(\"\\nGene data extraction result:\")\n", " print(\"Number of rows:\", len(gene_data))\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", " print(\"This confirms the dataset is a SuperSeries without direct gene expression data.\")\n" ] }, { "cell_type": "markdown", "id": "fdc3499d", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "5c9bcc0c", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:04:45.719690Z", "iopub.status.busy": "2025-03-25T06:04:45.719566Z", "iopub.status.idle": "2025-03-25T06:04:45.721548Z", "shell.execute_reply": "2025-03-25T06:04:45.721227Z" } }, "outputs": [], "source": [ "# Based on the observed identifiers, these appear to be just numeric values\n", "# (1, 2, 3, 4, etc.) rather than standard human gene symbols\n", "# These are likely probe IDs or feature indices that need to be mapped to gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "94df2e27", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "b6a19e1d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:04:45.722748Z", "iopub.status.busy": "2025-03-25T06:04:45.722638Z", "iopub.status.idle": "2025-03-25T06:04:48.536420Z", "shell.execute_reply": "2025-03-25T06:04:48.535782Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['1', '2', '3', '4', '5'], 'COL': ['192', '192', '192', '192', '192'], 'ROW': [328.0, 326.0, 324.0, 322.0, 320.0], 'NAME': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'A_51_P399985', 'A_55_P2508138'], 'SPOT_ID': ['CONTROL', 'CONTROL', 'CONTROL', nan, nan], 'CONTROL_TYPE': ['pos', 'pos', 'pos', 'FALSE', 'FALSE'], 'REFSEQ': [nan, nan, nan, 'NM_015742', 'NR_028378'], 'GB_ACC': [nan, nan, nan, 'NM_015742', 'NR_028378'], 'LOCUSLINK_ID': [nan, nan, nan, 17925.0, 100034739.0], 'GENE_SYMBOL': [nan, nan, nan, 'Myo9b', 'Gm17762'], 'GENE_NAME': [nan, nan, nan, 'myosin IXb', 'predicted gene, 17762'], 'UNIGENE_ID': [nan, nan, nan, 'Mm.33779', 'Mm.401643'], 'ENSEMBL_ID': [nan, nan, nan, 'ENSMUST00000170242', nan], 'ACCESSION_STRING': [nan, nan, nan, 'ref|NM_015742|ref|NM_001142322|ref|NM_001142323|ens|ENSMUST00000170242', 'ref|NR_028378|gb|AK171729|gb|AK045818|gb|AK033161'], 'CHROMOSOMAL_LOCATION': [nan, nan, nan, 'chr8:73884459-73884518', 'chr2:17952143-17952202'], 'CYTOBAND': [nan, nan, nan, 'mm|8qB3.3', 'mm|2qA3'], 'DESCRIPTION': [nan, nan, nan, 'Mus musculus myosin IXb (Myo9b), transcript variant 3, mRNA [NM_015742]', 'Mus musculus predicted gene, 17762 (Gm17762), long non-coding RNA [NR_028378]'], 'GO_ID': [nan, nan, nan, 'GO:0000146(microfilament motor activity)|GO:0000166(nucleotide binding)|GO:0001726(ruffle)|GO:0002548(monocyte chemotaxis)|GO:0003774(motor activity)|GO:0003779(actin binding)|GO:0005096(GTPase activator activity)|GO:0005516(calmodulin binding)|GO:0005524(ATP binding)|GO:0005622(intracellular)|GO:0005737(cytoplasm)|GO:0005856(cytoskeleton)|GO:0005884(actin filament)|GO:0005938(cell cortex)|GO:0007165(signal transduction)|GO:0007266(Rho protein signal transduction)|GO:0008152(metabolic process)|GO:0008270(zinc ion binding)|GO:0016020(membrane)|GO:0016459(myosin complex)|GO:0016887(ATPase activity)|GO:0030010(establishment of cell polarity)|GO:0030027(lamellipodium)|GO:0030898(actin-dependent ATPase activity)|GO:0031941(filamentous actin)|GO:0032433(filopodium tip)|GO:0033275(actin-myosin filament sliding)|GO:0035556(intracellular signal transduction)|GO:0043008(ATP-dependent protein binding)|GO:0043531(ADP binding)|GO:0043547(positive regulation of GTPase activity)|GO:0046872(metal ion binding)|GO:0048246(macrophage chemotaxis)|GO:0048471(perinuclear region of cytoplasm)|GO:0051015(actin filament binding)|GO:0072673(lamellipodium morphogenesis)', nan], 'SEQUENCE': [nan, nan, nan, 'ACGGAGCCAGGGACTTGGAACCTTTAGGAACAATCAGTGCATCCGGTGACAGCCTGGGTT', 'GGAAAGTACTTCAGCTTCACTCTTTAATTCTCCTTTACTACAATTAAAACTTTCGGTCAG'], 'SPOT_ID.1': [nan, nan, nan, nan, nan]}\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. 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": "886eb829", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "b9f039af", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:04:48.538185Z", "iopub.status.busy": "2025-03-25T06:04:48.538055Z", "iopub.status.idle": "2025-03-25T06:04:48.681775Z", "shell.execute_reply": "2025-03-25T06:04:48.681166Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Original gene expression data shape: (511, 24)\n", "Number of unique gene symbols after mapping: 511\n", "First 10 gene symbols:\n", "Index(['A130033P14', 'A230055C15', 'A330044H09', 'A430057O09', 'A430085C19',\n", " 'A530028O18', 'A830011I04', 'AA060545', 'AA066038', 'AA386476'],\n", " dtype='object', name='Gene')\n" ] } ], "source": [ "# 1. Determine which columns to use for mapping\n", "# The 'ID' column in gene_annotation contains numeric identifiers matching expression data\n", "# The 'GENE_SYMBOL' column contains the gene symbols we want to map to\n", "prob_col = 'ID'\n", "gene_col = 'GENE_SYMBOL'\n", "\n", "# 2. Get gene mapping dataframe with the two identified columns\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col)\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene-level expression data\n", "# Here we handle many-to-many relations between probes and genes\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Print information about the results\n", "print(f\"Original gene expression data shape: {gene_data.shape}\")\n", "print(f\"Number of unique gene symbols after mapping: {len(gene_data.index.unique())}\")\n", "print(\"First 10 gene symbols:\")\n", "print(gene_data.index[:10])\n" ] }, { "cell_type": "markdown", "id": "d8f387fd", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "4e73c640", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:04:48.683438Z", "iopub.status.busy": "2025-03-25T06:04:48.683324Z", "iopub.status.idle": "2025-03-25T06:04:48.768035Z", "shell.execute_reply": "2025-03-25T06:04:48.767502Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "After normalization: (30, 24)\n", "Gene expression data saved to ../../output/preprocess/Ovarian_Cancer/gene_data/GSE201525.csv\n", "Sample IDs from gene data: 24 samples\n", "Clinical data shape: (1, 24)\n", "Clinical data saved to ../../output/preprocess/Ovarian_Cancer/clinical_data/GSE201525.csv\n", "Shape of linked data: (24, 31)\n", "No valid trait values available, skipping missing value handling\n", "Shape of linked data after handling missing values: (24, 31)\n", "Dataset validation failed due to missing trait information. Final linked data not saved.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/media/techt/DATA/GenoAgent/tools/preprocess.py:400: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n", " linked_data = pd.concat([clinical_df, genetic_df], axis=0).T\n" ] } ], "source": [ "# 1. Normalize gene symbols\n", "import numpy as np\n", "\n", "# Get mapping using the correct column names as identified in Step 6\n", "prob_col = 'ID'\n", "gene_col = 'GENE_SYMBOL'\n", "\n", "# First normalize gene symbols in the gene expression data\n", "try:\n", " gene_data_normalized = normalize_gene_symbols_in_index(gene_data)\n", " print(f\"After normalization: {gene_data_normalized.shape}\")\n", "except Exception as e:\n", " print(f\"Error during normalization: {e}\")\n", " # If normalization fails, continue with the original mapped data\n", " gene_data_normalized = gene_data\n", "\n", "# Save the gene data\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "gene_data_normalized.to_csv(out_gene_data_file)\n", "print(f\"Gene expression data saved to {out_gene_data_file}\")\n", "\n", "# 2. Given the information we've gathered, this is a SuperSeries dataset that doesn't \n", "# have appropriate clinical data for Ovarian Cancer studies\n", "# Create a minimal clinical dataframe with missing trait values\n", "sample_ids = gene_data.columns.tolist()\n", "print(f\"Sample IDs from gene data: {len(sample_ids)} samples\")\n", "\n", "# Create an empty clinical dataframe\n", "# Since we don't have proper trait information, we'll set all values to NaN\n", "clinical_df = pd.DataFrame(index=[trait], columns=sample_ids)\n", "clinical_df.loc[trait] = np.nan # Using NaN to indicate missing trait information\n", "\n", "print(f\"Clinical data shape: {clinical_df.shape}\")\n", "\n", "# Save the clinical data\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", "\n", "# 3. Link clinical and genetic data\n", "linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data_normalized)\n", "print(f\"Shape of linked data: {linked_data.shape}\")\n", "\n", "# 4. Handle missing values in the linked data\n", "# Skip missing value handling if all trait values are NaN\n", "if clinical_df.loc[trait].isna().all():\n", " print(\"No valid trait values available, skipping missing value handling\")\n", " linked_data_cleaned = linked_data\n", "else:\n", " print(\"Handling missing values...\")\n", " linked_data_cleaned = handle_missing_values(linked_data, trait)\n", "print(f\"Shape of linked data after handling missing values: {linked_data_cleaned.shape}\")\n", "\n", "# 5. Since all samples have missing trait values, the trait is considered biased\n", "# In this case, we don't need to call judge_and_remove_biased_features\n", "is_trait_biased = True\n", "\n", "# 6. Validate the dataset and save cohort information\n", "note = \"This is a SuperSeries (GSE201525) containing multiple subseries. No direct trait information for Ovarian Cancer is available in this dataset. The gene expression data can be extracted but lacks appropriate clinical annotation for case-control analysis.\"\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=True,\n", " is_trait_available=False, # No trait information available\n", " is_biased=is_trait_biased,\n", " df=linked_data_cleaned,\n", " note=note\n", ")\n", "\n", "# 7. Save the linked data if it's usable (which it won't be due to missing trait info)\n", "if is_usable:\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " linked_data_cleaned.to_csv(out_data_file)\n", " print(f\"Saved processed linked data to {out_data_file}\")\n", "else:\n", " print(\"Dataset validation failed due to missing trait information. Final 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 }