{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "cf51964c", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:57.021877Z", "iopub.status.busy": "2025-03-25T04:04:57.021437Z", "iopub.status.idle": "2025-03-25T04:04:57.193629Z", "shell.execute_reply": "2025-03-25T04:04:57.193295Z" } }, "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 = \"Stroke\"\n", "cohort = \"GSE47727\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Stroke\"\n", "in_cohort_dir = \"../../input/GEO/Stroke/GSE47727\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Stroke/GSE47727.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Stroke/gene_data/GSE47727.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Stroke/clinical_data/GSE47727.csv\"\n", "json_path = \"../../output/preprocess/Stroke/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "7a79409c", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "f67b64e8", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:57.195034Z", "iopub.status.busy": "2025-03-25T04:04:57.194879Z", "iopub.status.idle": "2025-03-25T04:04:57.540217Z", "shell.execute_reply": "2025-03-25T04:04:57.539882Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Global peripheral blood gene expression study [HumanHT-12 V3.0]\"\n", "!Series_summary\t\"Samples were collected from 'control participants' of the Heart and Vascular Health (HVH) study that constitutes a group of population based case control studies of myocardial infarction (MI), stroke, venous thromboembolism (VTE), and atrial fibrillation (AF) conducted among 30-79 year old members of Group Health, a large integrated health care organization in Washington State.\"\n", "!Series_overall_design\t\"Total RNA was isolated from peripheral collected using PAXgene tubes and gene expression was profiled using the Illumina platform.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['age (yrs): 67', 'age (yrs): 54', 'age (yrs): 73', 'age (yrs): 52', 'age (yrs): 75', 'age (yrs): 59', 'age (yrs): 74', 'age (yrs): 76', 'age (yrs): 58', 'age (yrs): 60', 'age (yrs): 66', 'age (yrs): 70', 'age (yrs): 78', 'age (yrs): 77', 'age (yrs): 72', 'age (yrs): 57', 'age (yrs): 63', 'age (yrs): 62', 'age (yrs): 64', 'age (yrs): 61', 'age (yrs): 69', 'age (yrs): 68', 'age (yrs): 82', 'age (yrs): 71', 'age (yrs): 56', 'age (yrs): 53', 'age (yrs): 49', 'age (yrs): 51', 'age (yrs): 79', 'age (yrs): 80'], 1: ['gender: male', 'gender: female'], 2: ['tissue: blood']}\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": "ae0d285c", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "8e833f6b", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:57.541307Z", "iopub.status.busy": "2025-03-25T04:04:57.541194Z", "iopub.status.idle": "2025-03-25T04:04:57.545701Z", "shell.execute_reply": "2025-03-25T04:04:57.545413Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Clinical feature extraction skipped because trait data is not available.\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# From the background information, we can see this dataset contains gene expression data \n", "# profiled using the Illumina platform (HumanHT-12 V3.0)\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "# Looking at the sample characteristics dictionary:\n", "\n", "# For trait (Stroke): \n", "# This dataset doesn't explicitly mention stroke status in the sample characteristics.\n", "# Looking at the background, these are \"control participants\" for various studies including stroke.\n", "# So all participants seem to be controls (non-stroke), making this a constant feature.\n", "trait_row = None # No variable stroke status information is available\n", "\n", "# For age: We can find age data in key 0\n", "age_row = 0\n", "\n", "# For gender: We can find gender data in key 1\n", "gender_row = 1\n", "\n", "# 2.2 Data Type Conversion\n", "# Since trait_row is None, we still need to define convert_trait to follow the function signature\n", "def convert_trait(value):\n", " return None # Since trait data is not available\n", "\n", "def convert_age(value):\n", " try:\n", " # Extract the age value after the colon and space\n", " if ':' in value:\n", " age_str = value.split(': ')[1]\n", " return float(age_str) # Convert to float for continuous data\n", " return None\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " try:\n", " # Extract the gender value after the colon and space\n", " if ':' in value:\n", " gender_str = value.split(': ')[1].lower()\n", " if 'female' in gender_str:\n", " return 0\n", " elif 'male' in gender_str:\n", " return 1\n", " return None\n", " except:\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Determine trait data availability\n", "is_trait_available = trait_row is not None\n", "# Save initial filtering result\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", "# According to the instructions, we should skip this step if trait_row is None\n", "if trait_row is not None:\n", " selected_clinical_df = geo_select_clinical_features(\n", " clinical_df=clinical_data,\n", " trait=trait,\n", " trait_row=trait_row,\n", " convert_trait=convert_trait,\n", " age_row=age_row,\n", " convert_age=convert_age,\n", " gender_row=gender_row,\n", " convert_gender=convert_gender\n", " )\n", " \n", " # Preview the selected clinical data\n", " preview = preview_df(selected_clinical_df)\n", " print(\"Preview of selected clinical features:\")\n", " print(preview)\n", " \n", " # Save the clinical data\n", " selected_clinical_df.to_csv(out_clinical_data_file, index=False)\n", "else:\n", " print(\"Clinical feature extraction skipped because trait data is not available.\")\n" ] }, { "cell_type": "markdown", "id": "671216a1", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "7eb470a7", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:57.546629Z", "iopub.status.busy": "2025-03-25T04:04:57.546526Z", "iopub.status.idle": "2025-03-25T04:04:58.174786Z", "shell.execute_reply": "2025-03-25T04:04:58.174439Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Stroke/GSE47727/GSE47727_series_matrix.txt.gz\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape: (48803, 122)\n", "First 20 gene/probe identifiers:\n", "Index(['ILMN_1343291', 'ILMN_1343295', 'ILMN_1651199', 'ILMN_1651209',\n", " 'ILMN_1651210', 'ILMN_1651221', 'ILMN_1651228', 'ILMN_1651229',\n", " 'ILMN_1651230', 'ILMN_1651232', 'ILMN_1651235', 'ILMN_1651236',\n", " 'ILMN_1651237', 'ILMN_1651238', 'ILMN_1651249', 'ILMN_1651253',\n", " 'ILMN_1651254', 'ILMN_1651259', 'ILMN_1651260', 'ILMN_1651262'],\n", " dtype='object', name='ID')\n" ] } ], "source": [ "# 1. Get the SOFT and matrix file paths again \n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "print(f\"Matrix file found: {matrix_file}\")\n", "\n", "# 2. Use the get_genetic_data function from the library to get the gene_data\n", "try:\n", " gene_data = get_genetic_data(matrix_file)\n", " print(f\"Gene data shape: {gene_data.shape}\")\n", " \n", " # 3. Print the first 20 row IDs (gene or probe identifiers)\n", " print(\"First 20 gene/probe identifiers:\")\n", " print(gene_data.index[:20])\n", "except Exception as e:\n", " print(f\"Error extracting gene data: {e}\")\n" ] }, { "cell_type": "markdown", "id": "928201a4", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "f985fa38", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:58.175936Z", "iopub.status.busy": "2025-03-25T04:04:58.175812Z", "iopub.status.idle": "2025-03-25T04:04:58.177691Z", "shell.execute_reply": "2025-03-25T04:04:58.177404Z" } }, "outputs": [], "source": [ "# The gene identifiers shown are ILMN_XXXXXX format, which are Illumina BeadArray probe IDs\n", "# These are not human gene symbols but rather probe identifiers specific to Illumina microarray platforms\n", "# They need to be mapped to proper gene symbols for downstream analysis\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "56012e2d", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "7fed4daa", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:58.178616Z", "iopub.status.busy": "2025-03-25T04:04:58.178510Z", "iopub.status.idle": "2025-03-25T04:05:08.965225Z", "shell.execute_reply": "2025-03-25T04:05:08.964628Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene annotation preview:\n", "Columns in gene annotation: ['ID', 'nuID', 'Species', 'Source', 'Search_Key', 'Transcript', 'ILMN_Gene', 'Source_Reference_ID', 'RefSeq_ID', 'Unigene_ID', 'Entrez_Gene_ID', 'GI', 'Accession', 'Symbol', 'Protein_Product', 'Array_Address_Id', 'Probe_Type', 'Probe_Start', 'SEQUENCE', 'Chromosome', 'Probe_Chr_Orientation', 'Probe_Coordinates', 'Cytoband', 'Definition', 'Ontology_Component', 'Ontology_Process', 'Ontology_Function', 'Synonyms', 'Obsolete_Probe_Id', 'GB_ACC']\n", "{'ID': ['ILMN_1725881', 'ILMN_1910180', 'ILMN_1804174', 'ILMN_1796063', 'ILMN_1811966'], 'nuID': ['rp13_p1x6D80lNLk3c', 'NEX0oqCV8.er4HVfU4', 'KyqQynMZxJcruyylEU', 'xXl7eXuF7sbPEp.KFI', '9ckqJrioiaej9_ajeQ'], 'Species': ['Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens'], 'Source': ['RefSeq', 'Unigene', 'RefSeq', 'RefSeq', 'RefSeq'], 'Search_Key': ['ILMN_44919', 'ILMN_127219', 'ILMN_139282', 'ILMN_5006', 'ILMN_38756'], 'Transcript': ['ILMN_44919', 'ILMN_127219', 'ILMN_139282', 'ILMN_5006', 'ILMN_38756'], 'ILMN_Gene': ['LOC23117', 'HS.575038', 'FCGR2B', 'TRIM44', 'LOC653895'], 'Source_Reference_ID': ['XM_933824.1', 'Hs.575038', 'XM_938851.1', 'NM_017583.3', 'XM_936379.1'], 'RefSeq_ID': ['XM_933824.1', nan, 'XM_938851.1', 'NM_017583.3', 'XM_936379.1'], 'Unigene_ID': [nan, 'Hs.575038', nan, nan, nan], 'Entrez_Gene_ID': [23117.0, nan, 2213.0, 54765.0, 653895.0], 'GI': [89040007.0, 10437021.0, 88952550.0, 29029528.0, 89033487.0], 'Accession': ['XM_933824.1', 'AK024680', 'XM_938851.1', 'NM_017583.3', 'XM_936379.1'], 'Symbol': ['LOC23117', nan, 'FCGR2B', 'TRIM44', 'LOC653895'], 'Protein_Product': ['XP_938917.1', nan, 'XP_943944.1', 'NP_060053.2', 'XP_941472.1'], 'Array_Address_Id': [1710221.0, 5900364.0, 2480717.0, 1300239.0, 4480719.0], 'Probe_Type': ['I', 'S', 'I', 'S', 'S'], 'Probe_Start': [122.0, 1409.0, 1643.0, 2901.0, 25.0], 'SEQUENCE': ['GGCTCCTCTTTGGGCTCCTACTGGAATTTATCAGCCATCAGTGCATCTCT', 'ACACCTTCAGGAGGGAAGCCCTTATTTCTGGGTTGAACTCCCCTTCCATG', 'TAGGGGCAATAGGCTATACGCTACAGCCTAGGTGTGTAGTAGGCCACACC', 'CCTGCCTGTCTGCCTGTGACCTGTGTACGTATTACAGGCTTTAGGACCAG', 'CTAGCAGGGAGCGGTGAGGGAGAGCGGCTGGATTTCTTGCGGGATCTGCA'], 'Chromosome': ['16', nan, nan, '11', nan], 'Probe_Chr_Orientation': ['-', nan, nan, '+', nan], 'Probe_Coordinates': ['21766363-21766363:21769901-21769949', nan, nan, '35786070-35786119', nan], 'Cytoband': ['16p12.2a', nan, '1q23.3b', '11p13a', '10q11.23b'], 'Definition': ['PREDICTED: Homo sapiens KIAA0220-like protein, transcript variant 11 (LOC23117), mRNA.', 'Homo sapiens cDNA: FLJ21027 fis, clone CAE07110', 'PREDICTED: Homo sapiens Fc fragment of IgG, low affinity IIb, receptor (CD32) (FCGR2B), mRNA.', 'Homo sapiens tripartite motif-containing 44 (TRIM44), mRNA.', 'PREDICTED: Homo sapiens similar to protein geranylgeranyltransferase type I, beta subunit (LOC653895), mRNA.'], 'Ontology_Component': [nan, nan, nan, 'intracellular [goid 5622] [evidence IEA]', nan], 'Ontology_Process': [nan, nan, nan, nan, nan], 'Ontology_Function': [nan, nan, nan, 'zinc ion binding [goid 8270] [evidence IEA]; metal ion binding [goid 46872] [evidence IEA]', nan], 'Synonyms': [nan, nan, nan, 'MGC3490; MC7; HSA249128; DIPB', nan], 'Obsolete_Probe_Id': [nan, nan, nan, 'MGC3490; MC7; HSA249128; DIPB', nan], 'GB_ACC': ['XM_933824.1', 'AK024680', 'XM_938851.1', 'NM_017583.3', 'XM_936379.1']}\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", "#ILMN_Gene = Internal gene symbol\n", "#Symbol = Gene symbol from the source database\n", "#Synonyms = Gene symbol synonyms from Refseq\n", "ID\tnuID\tSpecies\tSource\tSearch_Key\tTranscript\tILMN_Gene\tSource_Reference_ID\tRefSeq_ID\tUnigene_ID\tEntrez_Gene_ID\tGI\tAccession\tSymbol\tProtein_Product\tArray_Address_Id\tProbe_Type\tProbe_Start\tSEQUENCE\tChromosome\tProbe_Chr_Orientation\tProbe_Coordinates\tCytoband\tDefinition\tOntology_Component\tOntology_Process\tOntology_Function\tSynonyms\tObsolete_Probe_Id\tGB_ACC\n", "\n", "Checking for additional annotation files in the directory:\n", "[]\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": "bcade3e8", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "837e2716", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:08.966640Z", "iopub.status.busy": "2025-03-25T04:05:08.966511Z", "iopub.status.idle": "2025-03-25T04:05:10.967873Z", "shell.execute_reply": "2025-03-25T04:05:10.967503Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping dataframe shape: (36157, 2)\n", "First 5 rows of gene mapping:\n", " ID Gene\n", "0 ILMN_1725881 LOC23117\n", "2 ILMN_1804174 FCGR2B\n", "3 ILMN_1796063 TRIM44\n", "4 ILMN_1811966 LOC653895\n", "5 ILMN_1668162 DGAT2L3\n", "Gene expression data after mapping, shape: (19120, 122)\n", "First 10 gene symbols in the processed gene expression data:\n", "Index(['A1BG', 'A1CF', 'A26A1', 'A26B1', 'A26C1B', 'A26C3', 'A2BP1', 'A2M',\n", " 'A2ML1', 'A3GALT2'],\n", " dtype='object', name='Gene')\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to: ../../output/preprocess/Stroke/gene_data/GSE47727.csv\n", "Skipping linking clinical and genetic data because trait information is not available in this dataset.\n" ] } ], "source": [ "# 1. Determine which columns to use for mapping\n", "# From the previous output we can see:\n", "# - The gene expression data has identifiers like 'ILMN_1343291' in the index (probe IDs)\n", "# - In the gene annotation data, the 'ID' column contains these same identifiers\n", "# - The 'Symbol' column in the gene annotation data contains the gene symbols we want\n", "\n", "prob_col = 'ID' # Column containing probe identifiers\n", "gene_col = 'Symbol' # Column containing gene symbols\n", "\n", "# 2. Get the gene mapping dataframe\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col)\n", "print(f\"Gene mapping dataframe shape: {gene_mapping.shape}\")\n", "print(\"First 5 rows of gene mapping:\")\n", "print(gene_mapping.head())\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene expression data\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "print(f\"Gene expression data after mapping, shape: {gene_data.shape}\")\n", "print(\"First 10 gene symbols in the processed gene expression data:\")\n", "print(gene_data.index[:10])\n", "\n", "# Save the gene expression data to a file\n", "gene_data.to_csv(out_gene_data_file)\n", "print(f\"Gene expression data saved to: {out_gene_data_file}\")\n", "\n", "# Since we already determined that trait data is not available in this dataset (trait_row is None),\n", "# we won't proceed with linking clinical and genetic data for this particular dataset.\n", "print(\"Skipping linking clinical and genetic data because trait information is not available in this dataset.\")\n" ] }, { "cell_type": "markdown", "id": "87501197", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "6f4827bd", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:10.969277Z", "iopub.status.busy": "2025-03-25T04:05:10.969155Z", "iopub.status.idle": "2025-03-25T04:05:12.447850Z", "shell.execute_reply": "2025-03-25T04:05:12.447528Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Original gene data shape: (19120, 122)\n", "Gene data shape after normalization: (18326, 122)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene expression data saved to ../../output/preprocess/Stroke/gene_data/GSE47727.csv\n", "No trait data available. Can't proceed with linking clinical and genetic data.\n", "Abnormality detected in the cohort: GSE47727. Preprocessing failed.\n", "Dataset deemed not usable due to missing trait data.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the obtained gene expression data\n", "# Use the gene_data variable that was already loaded in Step 4\n", "print(f\"Original gene data shape: {gene_data.shape}\")\n", "\n", "# Normalize gene symbols\n", "gene_data_normalized = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Gene data shape after normalization: {gene_data_normalized.shape}\")\n", "\n", "# Save the normalized gene expression 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\"Normalized gene expression data saved to {out_gene_data_file}\")\n", "\n", "# 2. No clinical data available (trait_row is None from previous steps)\n", "# We can't proceed with linking clinical and genetic data\n", "print(\"No trait data available. Can't proceed with linking clinical and genetic data.\")\n", "\n", "# Create a minimal dataframe for validation purposes \n", "# (since we need a valid DataFrame when is_final=True)\n", "empty_df = pd.DataFrame({\"dummy\": [0]})\n", "\n", "# Since trait data is not available, the dataset is not usable for our purposes\n", "# We pass is_biased=True to indicate unusable 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=False,\n", " is_biased=True, # Setting is_biased to True since missing trait data makes dataset unusable\n", " df=empty_df,\n", " note=\"No stroke-specific trait data available in this dataset. Contains gene expression data from peripheral blood of older adults, but without clear stroke indicators.\"\n", ")\n", "print(\"Dataset deemed not usable due to missing trait 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 }