{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d5128154", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:08:48.107903Z", "iopub.status.busy": "2025-03-25T06:08:48.107689Z", "iopub.status.idle": "2025-03-25T06:08:48.271850Z", "shell.execute_reply": "2025-03-25T06:08:48.271529Z" } }, "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 = \"Parkinsons_Disease\"\n", "cohort = \"GSE57475\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Parkinsons_Disease\"\n", "in_cohort_dir = \"../../input/GEO/Parkinsons_Disease/GSE57475\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Parkinsons_Disease/GSE57475.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Parkinsons_Disease/gene_data/GSE57475.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Parkinsons_Disease/clinical_data/GSE57475.csv\"\n", "json_path = \"../../output/preprocess/Parkinsons_Disease/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "fa9f8876", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "1a722acb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:08:48.273255Z", "iopub.status.busy": "2025-03-25T06:08:48.273115Z", "iopub.status.idle": "2025-03-25T06:08:48.589687Z", "shell.execute_reply": "2025-03-25T06:08:48.589346Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Association between alpha-synuclein blood transcripts and early Parkinson's disease\"\n", "!Series_summary\t\"Importance. Biological markers of Parkinson’s disease are essential for achieving disease modification. Objective. To determine the association of SNCA blood transcript levels with prevalence of Parkinson’s disease. Background. The SNCA locus is preferentially transcribed in neurons and blood cells. Non-coding genetic variants and neuronal aggregates of α-synuclein protein associate this locus with sporadic Parkinson’s disease and suggest a potential role for abnormal SNCA transcription in the disease mechanism. Here we investigated variation in intracellular SNCA gene expression and SNCA transcript isoform abundance in circulating blood cells of cases with PD and controls in a network of biobanks that represent regional, national, and international populations. Design, Setting, Participants. Three cross-sectional, case-control studies nested in observational biomarker studies. 222 cases with early-stage clinical PD and 183 controls were enrolled from 2005 to 2010 in the Harvard Biomarker Study (HBS) at two Harvard-affiliated tertiary care centers. 76 cases with dopamine transporter imaging (DAT)-confirmed PD and 42 controls were enrolled between August 2007 and December 2008 in the Blood α-Synuclein, Gene Expression and Smell Testing as Diagnostic and Prognostic Biomarkers in Parkinson’s Disease Study (PROBE) study from 22 US tertiary care centers. 202 DAT-confirmed cases with de novo PD and 138 controls were enrolled in the Parkinson’s Progression Markers Initiative (PPMI) between July 2010 and November 2012 from 22 US and international tertiary care centers. Main Outcome Measures. Association of intracellular SNCA transcript abundance with PD estimated on analog and digital expression platforms. Results. Reduced levels of SNCA transcripts were associated with early-stage clinical PD, neuroimaging-confirmed PD, and untreated, neuroimaging-confirmed PD in accessible, peripheral blood cells from a total of 863 individuals. SNCA expression was reduced by 17%, 22%, and 16% in cases compared to controls in the HBS, PROBE, and PPMI study with P values of 0.004, 0.025, and 0.018, respectively, after adjusting for clinical, hematological, and processing covariates. Specific SNCA transcripts with long 3’ untranslated regions (UTR) and those skipping exon 5 are implicated in the accumulation and mitochondrial targeting of α-synuclein protein in Parkinson’s pathology. These transcript isoforms were linked to PD through digital expression analysis. Individuals in the lowest quartile of SNCA expression values had covariate-adjusted odds ratios for PD of 2.14 (95% C. I. 1.1-4.1), 4.5 (95% C. I. 1.3-15), and 2.1 (1.1-4.0) compared to individuals in the highest quartile of expression values in the HBS, PROBE, and PPMI study, respectively. Conclusions and Relevance. Reduced levels of SNCA expression, particularly of disease-relevant transcripts with extended 3’ UTR or exon 5 skipping, are associated with early-stage PD. These findings support a potential role for SNCA as a transcriptional marker of PD and may have implications for patient stratification and risk assessment.\"\n", "!Series_overall_design\t\"93 cases with Dopamine Transporter Imaging (DAT)-confirmed PD and 49 controls were enrolled between August 2007 and December 2008 in the Blood a-Synuclein, Gene Expression and Smell Testing as Diagnostic and Prognostic Biomarkers in Parkinson's Disease Study (PROBE) study from 22 US tertiary care centers.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['age: 62', 'age: 54', 'age: 58', 'age: 76', 'age: 52', 'age: 72', 'age: 78', 'age: 61', 'age: 67', 'age: 68', 'age: 84', 'age: 65', 'age: 86', 'age: 49', 'age: 71', 'age: 69', 'age: 64', 'age: 55', 'age: 60', 'age: 56', 'age: 53', 'age: 63', 'age: 80', 'age: 45', 'age: 75', 'age: 66', 'age: 51', 'age: 70', 'age: 57', 'age: 39'], 1: ['gender: M', 'gender: F'], 2: ['disease state: Dopamine Transporter Imaging (DAT)-confirmed PD', 'disease state: healthy control']}\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": "bacdca32", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "9398b051", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:08:48.591039Z", "iopub.status.busy": "2025-03-25T06:08:48.590917Z", "iopub.status.idle": "2025-03-25T06:08:48.600131Z", "shell.execute_reply": "2025-03-25T06:08:48.599806Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error loading clinical data: All arrays must be of the same length\n", "Preview of selected clinical features:\n", "{}\n", "Clinical data saved to ../../output/preprocess/Parkinsons_Disease/clinical_data/GSE57475.csv\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# From the background information, this dataset appears to be about SNCA gene \n", "# expression in Parkinson's Disease, so gene expression data is likely available\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "# From the sample characteristics dictionary:\n", "trait_row = 2 # 'disease state' at index 2\n", "age_row = 0 # 'age' at index 0\n", "gender_row = 1 # 'gender' at index 1\n", "\n", "# 2.2 Data Type Conversion\n", "def convert_trait(value):\n", " if \":\" in value:\n", " value = value.split(\":\")[1].strip()\n", " if \"PD\" in value or \"parkinson\" in value.lower():\n", " return 1\n", " elif \"control\" in value.lower() or \"healthy\" in value.lower():\n", " return 0\n", " return None\n", "\n", "def convert_age(value):\n", " if \":\" in value:\n", " value = value.split(\":\")[1].strip()\n", " try:\n", " return float(value)\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " if \":\" in value:\n", " value = value.split(\":\")[1].strip()\n", " if value.upper() == 'F' or value.lower() == 'female':\n", " return 0\n", " elif value.upper() == 'M' or value.lower() == 'male':\n", " return 1\n", " return None\n", "\n", "# 3. Save Metadata\n", "# trait_row is not None, so trait data is available\n", "is_trait_available = trait_row is not None\n", "# Initial filtering on usability\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", " # The sample characteristics dictionary provides the unique values, but\n", " # we need the actual data in the format expected by geo_select_clinical_features\n", " \n", " # Try to load the clinical data file directly\n", " try:\n", " # First, try to see if there's a matrix file we can use\n", " matrix_file = f\"{in_cohort_dir}/matrix.txt\"\n", " if os.path.exists(matrix_file):\n", " # Read the matrix file to get the clinical data\n", " with open(matrix_file, 'r') as f:\n", " lines = f.readlines()\n", " \n", " # Extract sample characteristics from the matrix file\n", " sample_chars_data = {}\n", " for i, line in enumerate(lines):\n", " if line.startswith(\"!Sample_characteristics_ch\"):\n", " parts = line.strip().split('\\t')\n", " if len(parts) >= 2:\n", " key = parts[0].replace(\"!Sample_characteristics_ch\", \"\").strip()\n", " value = parts[1]\n", " if key not in sample_chars_data:\n", " sample_chars_data[key] = []\n", " sample_chars_data[key].append(value)\n", " \n", " # Create a DataFrame suitable for geo_select_clinical_features\n", " clinical_data = pd.DataFrame(sample_chars_data)\n", " else:\n", " # If matrix file doesn't exist, create a minimal DataFrame with the information we have\n", " # The function expects a DataFrame where each column corresponds to a feature\n", " # and each row corresponds to a sample\n", " sample_chars = {\n", " 0: ['age: 62', 'age: 54', 'age: 58', 'age: 76', 'age: 52', 'age: 72', 'age: 78', 'age: 61', 'age: 67', 'age: 68', \n", " 'age: 84', 'age: 65', 'age: 86', 'age: 49', 'age: 71', 'age: 69', 'age: 64', 'age: 55', 'age: 60', 'age: 56', \n", " 'age: 53', 'age: 63', 'age: 80', 'age: 45', 'age: 75', 'age: 66', 'age: 51', 'age: 70', 'age: 57', 'age: 39'], \n", " 1: ['gender: M', 'gender: F'], \n", " 2: ['disease state: Dopamine Transporter Imaging (DAT)-confirmed PD', 'disease state: healthy control']\n", " }\n", " \n", " # Since we only have unique values and not the full dataset,\n", " # we'll create a dummy index for the clinical data DataFrame that the function can process\n", " clinical_data = pd.DataFrame({str(k): v for k, v in sample_chars.items()}).T\n", " \n", " except Exception as e:\n", " print(f\"Error loading clinical data: {e}\")\n", " # Create an empty DataFrame as fallback\n", " clinical_data = pd.DataFrame()\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", " # Preview the data\n", " preview = preview_df(selected_clinical_df)\n", " print(\"Preview of selected clinical features:\")\n", " print(preview)\n", " \n", " # Save the processed clinical data\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" ] }, { "cell_type": "markdown", "id": "98e13027", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "73dda1e2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:08:48.601184Z", "iopub.status.busy": "2025-03-25T06:08:48.601079Z", "iopub.status.idle": "2025-03-25T06:08:49.173013Z", "shell.execute_reply": "2025-03-25T06:08:49.172646Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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. 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": "aa6cffae", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "acf09c2d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:08:49.174244Z", "iopub.status.busy": "2025-03-25T06:08:49.174139Z", "iopub.status.idle": "2025-03-25T06:08:49.176123Z", "shell.execute_reply": "2025-03-25T06:08:49.175809Z" } }, "outputs": [], "source": [ "# Gene identifiers analysis \n", "# The identifiers starting with \"ILMN_\" are Illumina probe IDs, not human gene symbols\n", "# These are microarray probe identifiers from Illumina platform and need to be mapped to gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "62990a6e", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "71ac8395", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:08:49.177180Z", "iopub.status.busy": "2025-03-25T06:08:49.177085Z", "iopub.status.idle": "2025-03-25T06:09:03.956564Z", "shell.execute_reply": "2025-03-25T06:09:03.956204Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\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" ] } ], "source": [ "# 1. First get the file paths using geo_get_relevant_filepaths function\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. 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", "# 3. 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": "6c7ed3f1", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "29ab0da4", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:03.957903Z", "iopub.status.busy": "2025-03-25T06:09:03.957753Z", "iopub.status.idle": "2025-03-25T06:09:04.445760Z", "shell.execute_reply": "2025-03-25T06:09:04.445320Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data shape after mapping: (19106, 142)\n", "First 5 gene symbols after mapping:\n", "Index(['A1BG', 'A1CF', 'A26A1', 'A26B1', 'A26C1B'], dtype='object', name='Gene')\n" ] } ], "source": [ "# 1. Identify the relevant columns for mapping\n", "# From the gene annotation preview, we can see:\n", "# - 'ID' column contains the Illumina probe identifiers (e.g., ILMN_1725881)\n", "# - 'Symbol' column contains the gene symbols (e.g., LOC23117, FCGR2B)\n", "\n", "prob_col = 'ID'\n", "gene_col = 'Symbol'\n", "\n", "# 2. Get the gene mapping dataframe\n", "mapping_df = get_gene_mapping(gene_annotation, prob_col, gene_col)\n", "\n", "# 3. Apply the gene mapping to convert probe-level measurements to gene expression data\n", "gene_data = apply_gene_mapping(gene_data, mapping_df)\n", "\n", "# Print the shape of the resulting gene expression dataframe\n", "print(f\"Gene expression data shape after mapping: {gene_data.shape}\")\n", "print(\"First 5 gene symbols after mapping:\")\n", "print(gene_data.index[:5])\n" ] }, { "cell_type": "markdown", "id": "48e27b6c", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "a3e658c3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:04.447314Z", "iopub.status.busy": "2025-03-25T06:09:04.447096Z", "iopub.status.idle": "2025-03-25T06:09:19.174831Z", "shell.execute_reply": "2025-03-25T06:09:19.174455Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data shape after normalization: (18312, 142)\n", "First 5 normalized gene symbols:\n", "Index(['A1BG', 'A1CF', 'A2M', 'A2ML1', 'A3GALT2'], dtype='object', name='Gene')\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Parkinsons_Disease/gene_data/GSE57475.csv\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Clinical data shape: (3, 142)\n", "Clinical data preview:\n", "{'GSM1383302': [1.0, 62.0, 1.0], 'GSM1383303': [1.0, 54.0, 1.0], 'GSM1383304': [1.0, 58.0, 1.0], 'GSM1383305': [1.0, 76.0, 1.0], 'GSM1383306': [1.0, 52.0, 0.0], 'GSM1383307': [1.0, 52.0, 0.0], 'GSM1383308': [1.0, 72.0, 0.0], 'GSM1383309': [1.0, 54.0, 0.0], 'GSM1383310': [1.0, 78.0, 1.0], 'GSM1383311': [1.0, 61.0, 0.0], 'GSM1383312': [1.0, 67.0, 1.0], 'GSM1383313': [1.0, 68.0, 1.0], 'GSM1383314': [1.0, 76.0, 1.0], 'GSM1383315': [1.0, 84.0, 1.0], 'GSM1383316': [1.0, 65.0, 0.0], 'GSM1383317': [1.0, 58.0, 0.0], 'GSM1383318': [1.0, 86.0, 0.0], 'GSM1383319': [1.0, 49.0, 0.0], 'GSM1383320': [1.0, 72.0, 0.0], 'GSM1383321': [1.0, 71.0, 1.0], 'GSM1383322': [1.0, 69.0, 0.0], 'GSM1383323': [1.0, 64.0, 1.0], 'GSM1383324': [1.0, 55.0, 0.0], 'GSM1383325': [1.0, 69.0, 0.0], 'GSM1383326': [1.0, 60.0, 1.0], 'GSM1383327': [1.0, 56.0, 1.0], 'GSM1383328': [1.0, 60.0, 1.0], 'GSM1383329': [1.0, 61.0, 1.0], 'GSM1383330': [1.0, 53.0, 0.0], 'GSM1383331': [1.0, 69.0, 1.0], 'GSM1383332': [1.0, 65.0, 1.0], 'GSM1383333': [1.0, 58.0, 0.0], 'GSM1383334': [1.0, 63.0, 1.0], 'GSM1383335': [1.0, 80.0, 0.0], 'GSM1383336': [1.0, 45.0, 0.0], 'GSM1383337': [1.0, 52.0, 1.0], 'GSM1383338': [1.0, 49.0, 1.0], 'GSM1383339': [1.0, 67.0, 1.0], 'GSM1383340': [1.0, 75.0, 1.0], 'GSM1383341': [1.0, 66.0, 0.0], 'GSM1383342': [1.0, 78.0, 1.0], 'GSM1383343': [1.0, 65.0, 1.0], 'GSM1383344': [1.0, 51.0, 1.0], 'GSM1383345': [1.0, 60.0, 0.0], 'GSM1383346': [1.0, 70.0, 1.0], 'GSM1383347': [1.0, 76.0, 0.0], 'GSM1383348': [1.0, 57.0, 1.0], 'GSM1383349': [1.0, 66.0, 1.0], 'GSM1383350': [1.0, 52.0, 1.0], 'GSM1383351': [1.0, 68.0, 1.0], 'GSM1383352': [1.0, 55.0, 1.0], 'GSM1383353': [1.0, 39.0, 1.0], 'GSM1383354': [1.0, 53.0, 0.0], 'GSM1383355': [1.0, 78.0, 1.0], 'GSM1383356': [1.0, 61.0, 1.0], 'GSM1383357': [1.0, 59.0, 0.0], 'GSM1383358': [1.0, 52.0, 1.0], 'GSM1383359': [1.0, 67.0, 1.0], 'GSM1383360': [1.0, 53.0, 1.0], 'GSM1383361': [1.0, 64.0, 1.0], 'GSM1383362': [1.0, 61.0, 1.0], 'GSM1383363': [1.0, 58.0, 1.0], 'GSM1383364': [1.0, 70.0, 1.0], 'GSM1383365': [1.0, 49.0, 0.0], 'GSM1383366': [1.0, 59.0, 1.0], 'GSM1383367': [1.0, 63.0, 0.0], 'GSM1383368': [1.0, 49.0, 1.0], 'GSM1383369': [1.0, 84.0, 0.0], 'GSM1383370': [1.0, 79.0, 1.0], 'GSM1383371': [1.0, 59.0, 1.0], 'GSM1383372': [1.0, 67.0, 1.0], 'GSM1383373': [1.0, 72.0, 1.0], 'GSM1383374': [1.0, 61.0, 1.0], 'GSM1383375': [1.0, 58.0, 1.0], 'GSM1383376': [1.0, 77.0, 1.0], 'GSM1383377': [1.0, 58.0, 0.0], 'GSM1383378': [1.0, 61.0, 1.0], 'GSM1383379': [1.0, 69.0, 1.0], 'GSM1383380': [1.0, 61.0, 0.0], 'GSM1383381': [1.0, 55.0, 1.0], 'GSM1383382': [1.0, 62.0, 0.0], 'GSM1383383': [1.0, 77.0, 1.0], 'GSM1383384': [1.0, 60.0, 1.0], 'GSM1383385': [1.0, 55.0, 1.0], 'GSM1383386': [1.0, 62.0, 1.0], 'GSM1383387': [1.0, 61.0, 0.0], 'GSM1383388': [1.0, 66.0, 0.0], 'GSM1383389': [1.0, 59.0, 1.0], 'GSM1383390': [1.0, 61.0, 1.0], 'GSM1383391': [1.0, 52.0, 1.0], 'GSM1383392': [1.0, 53.0, 1.0], 'GSM1383393': [1.0, 59.0, 1.0], 'GSM1383394': [1.0, 69.0, 0.0], 'GSM1383395': [0.0, 81.0, 1.0], 'GSM1383396': [0.0, 54.0, 0.0], 'GSM1383397': [0.0, 57.0, 1.0], 'GSM1383398': [0.0, 70.0, 0.0], 'GSM1383399': [0.0, 49.0, 0.0], 'GSM1383400': [0.0, 73.0, 1.0], 'GSM1383401': [0.0, 74.0, 1.0], 'GSM1383402': [0.0, 79.0, 1.0], 'GSM1383403': [0.0, 67.0, 0.0], 'GSM1383404': [0.0, 49.0, 0.0], 'GSM1383405': [0.0, 55.0, 0.0], 'GSM1383406': [0.0, 57.0, 1.0], 'GSM1383407': [0.0, 63.0, 0.0], 'GSM1383408': [0.0, 59.0, 1.0], 'GSM1383409': [0.0, 55.0, 1.0], 'GSM1383410': [0.0, 54.0, 1.0], 'GSM1383411': [0.0, 56.0, 0.0], 'GSM1383412': [0.0, 57.0, 0.0], 'GSM1383413': [0.0, 58.0, 1.0], 'GSM1383414': [0.0, 59.0, 0.0], 'GSM1383415': [0.0, 69.0, 1.0], 'GSM1383416': [0.0, 60.0, 0.0], 'GSM1383417': [0.0, 60.0, 1.0], 'GSM1383418': [0.0, 53.0, 1.0], 'GSM1383419': [0.0, 52.0, 1.0], 'GSM1383420': [0.0, 59.0, 1.0], 'GSM1383421': [0.0, 87.0, 1.0], 'GSM1383422': [0.0, 47.0, 1.0], 'GSM1383423': [0.0, 59.0, 1.0], 'GSM1383424': [0.0, 51.0, 0.0], 'GSM1383425': [0.0, 76.0, 0.0], 'GSM1383426': [0.0, 51.0, 1.0], 'GSM1383427': [0.0, 73.0, 1.0], 'GSM1383428': [0.0, 65.0, 0.0], 'GSM1383429': [0.0, 48.0, 0.0], 'GSM1383430': [0.0, 57.0, 0.0], 'GSM1383431': [0.0, 65.0, 0.0], 'GSM1383432': [0.0, 64.0, 1.0], 'GSM1383433': [0.0, 61.0, 0.0], 'GSM1383434': [0.0, 49.0, 1.0], 'GSM1383435': [0.0, 55.0, 0.0], 'GSM1383436': [0.0, 63.0, 1.0], 'GSM1383437': [0.0, 57.0, 0.0], 'GSM1383438': [0.0, 58.0, 0.0], 'GSM1383439': [0.0, 64.0, 1.0], 'GSM1383440': [0.0, 74.0, 1.0], 'GSM1383441': [0.0, 57.0, 1.0], 'GSM1383442': [0.0, 76.0, 0.0], 'GSM1383443': [0.0, 76.0, 0.0]}\n", "Clinical data saved to ../../output/preprocess/Parkinsons_Disease/clinical_data/GSE57475.csv\n", "Transposed clinical data shape: (142, 3)\n", "Transposed genetic data shape: (142, 18312)\n", "Number of common samples: 142\n", "Linked data shape: (142, 18315)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Data shape after handling missing values: (142, 18315)\n", "For the feature 'Parkinsons_Disease', the least common label is '0.0' with 49 occurrences. This represents 34.51% of the dataset.\n", "The distribution of the feature 'Parkinsons_Disease' in this dataset is fine.\n", "\n", "Quartiles for 'Age':\n", " 25%: 55.0\n", " 50% (Median): 61.0\n", " 75%: 69.0\n", "Min: 39.0\n", "Max: 87.0\n", "The distribution of the feature 'Age' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '0.0' with 54 occurrences. This represents 38.03% of the dataset.\n", "The distribution of the feature 'Gender' in this dataset is fine.\n", "\n", "Data shape after removing biased features: (142, 18315)\n", "Is the trait biased: False\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data saved to ../../output/preprocess/Parkinsons_Disease/GSE57475.csv\n" ] } ], "source": [ "# 1. Normalize gene symbols from the already mapped gene expression data from Step 6\n", "# Apply normalization to standardize gene symbols\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Gene expression data shape after normalization: {normalized_gene_data.shape}\")\n", "print(\"First 5 normalized gene symbols:\")\n", "print(normalized_gene_data.index[:5])\n", "\n", "# Save the normalized 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", "# 2. Load clinical data that was extracted in step 2\n", "# We need to re-extract the clinical features since the previous attempt encountered an error\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "background_info, clinical_data = get_background_and_clinical_data(matrix_file)\n", "\n", "# Extract clinical features with the parameters defined in step 2\n", "selected_clinical_df = geo_select_clinical_features(\n", " clinical_df=clinical_data,\n", " trait=trait,\n", " trait_row=2, # From step 2\n", " convert_trait=convert_trait,\n", " age_row=0, # From step 2\n", " convert_age=convert_age,\n", " gender_row=1, # From step 2\n", " convert_gender=convert_gender\n", ")\n", "\n", "print(\"Clinical data shape:\", selected_clinical_df.shape)\n", "print(\"Clinical data preview:\")\n", "print(preview_df(selected_clinical_df))\n", "\n", "# Save the processed clinical data (rewriting potentially empty file from step 2)\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", "# 3. Link clinical and genetic data\n", "# Transpose clinical data to have samples as rows\n", "clinical_data_t = selected_clinical_df.T\n", "print(f\"Transposed clinical data shape: {clinical_data_t.shape}\")\n", "\n", "# Transpose genetic data to have samples as rows\n", "genetic_data_t = normalized_gene_data.T\n", "print(f\"Transposed genetic data shape: {genetic_data_t.shape}\")\n", "\n", "# Check for overlapping samples\n", "clinical_samples = set(clinical_data_t.index)\n", "genetic_samples = set(genetic_data_t.index)\n", "common_samples = clinical_samples.intersection(genetic_samples)\n", "print(f\"Number of common samples: {len(common_samples)}\")\n", "\n", "# Filter to keep only common samples\n", "clinical_data_t = clinical_data_t.loc[list(common_samples)]\n", "genetic_data_t = genetic_data_t.loc[list(common_samples)]\n", "\n", "# Merge clinical and genetic data\n", "linked_data = pd.concat([clinical_data_t, genetic_data_t], axis=1)\n", "print(f\"Linked data shape: {linked_data.shape}\")\n", "\n", "# 4. Handle missing values\n", "linked_data = handle_missing_values(linked_data, trait)\n", "print(f\"Data shape after handling missing values: {linked_data.shape}\")\n", "\n", "# 5. Determine if trait and demographic features are biased\n", "is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)\n", "print(f\"Data shape after removing biased features: {linked_data.shape}\")\n", "print(f\"Is the trait biased: {is_biased}\")\n", "\n", "# 6. Validate and save cohort info\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=\"Dataset contains gene expression data from blood samples of PD patients and controls.\"\n", ")\n", "\n", "# 7. Save linked data if 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 deemed not usable. Linked data was 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 }