{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "b3142ad1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:49:57.204601Z", "iopub.status.busy": "2025-03-25T03:49:57.204504Z", "iopub.status.idle": "2025-03-25T03:49:57.362794Z", "shell.execute_reply": "2025-03-25T03:49:57.362461Z" } }, "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 = \"Retinoblastoma\"\n", "cohort = \"GSE63529\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Retinoblastoma\"\n", "in_cohort_dir = \"../../input/GEO/Retinoblastoma/GSE63529\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Retinoblastoma/GSE63529.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Retinoblastoma/gene_data/GSE63529.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Retinoblastoma/clinical_data/GSE63529.csv\"\n", "json_path = \"../../output/preprocess/Retinoblastoma/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "27f4747f", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "25a08e87", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:49:57.364176Z", "iopub.status.busy": "2025-03-25T03:49:57.364040Z", "iopub.status.idle": "2025-03-25T03:49:57.456704Z", "shell.execute_reply": "2025-03-25T03:49:57.456408Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Comparison of parental and CDKi-resistant ovarian cancer cell lines\"\n", "!Series_summary\t\"High-grade serous ovarian cancers (HGSOC) are genomically complex, heterogeneous cancers with a high mortality rate, due to acquired chemoresistance and lack of targeted therapy options. Cyclin-dependent kinase inhibitors (CDKi) target the retinoblastoma (RB) signaling network, and have been successfully incorporated into treatment regimens for breast and other cancers. Here, we have compared mechanisms of response and resistance to three CDKi that target either CDK4/6 or CDK2 and abrogate E2F target gene expression. We identify CCNE1 gain and RB1 loss as mechanisms of resistance to CDK4/6 inhibition, whereas receptor tyrosine kinase (RTK) and RAS signaling is associated with CDK2 inhibitor resistance. Mechanistically, we show that ETS factors are mediators of RTK/RAS signaling that cooperate with E2F in cell cycle progression. Consequently, CDK2 inhibition sensitizes cyclin E1-driven but not RAS-driven ovarian cancer cells to platinum-based chemotherapy. In summary, this study outlines a rational approach for incorporating CDKi into treatment regimens for HGSOC.\"\n", "!Series_overall_design\t\"For parental HEY, two replicates per condition (control=10%, SNS032-treated, PD0332991-treated) were analyzed. For CDKi-resistant cells, two individual subclones derived from single cells were analyzed, except OAW28 sublines (two polyclonal populations per subline), OV90-PD/SNS-R (two polyclonal populations) and OV90-SNS-R-1 (polyclonal population, whereas OV90-SNS-R-2 is derived from a single colony).\"\n", "Sample Characteristics Dictionary:\n", "{0: ['cell line/subline: HEY', 'cell line/subline: HEY_SNS032-resistant', 'cell line/subline: HEY_PD0332991-resistant', 'cell line/subline: HEY_PD0332991/SNS032-resistant', 'cell line/subline: OAW28_parental', 'cell line/subline: OAW28_PD0332991/SNS032-resistant', 'cell line/subline: OV90_parental', 'cell line/subline: OAW28_SNS032-resistant', 'cell line/subline: OV90_PD0332991/SNS032-resistant', 'cell line/subline: OV90_SNS032-resistant', 'cell line/subline: SKOV3_parental', 'cell line/subline: SKOV3_PD0332991/SNS032-resistant_late', 'cell line/subline: SKOV3_SNS032-resistant', 'cell line/subline: SKOV3_PD0332991/SNS032-resistant_late_CDKi release', 'cell line/subline: SKOV3_PD0332991/SNS032-resistant_early'], 1: ['cell type: Ovarian cancer cell line'], 2: ['cell subtype/phenotype: parental', 'cell subtype/phenotype: SNS032-resistant', 'cell subtype/phenotype: PD0332991-resistant', 'cell subtype/phenotype: PD0332991/SNS032-resistant'], 3: ['treated with: none (control)', 'treated with: SNS032', 'treated with: PD0332991', nan]}\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": "5db0f9bc", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "30cf8905", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:49:57.457602Z", "iopub.status.busy": "2025-03-25T03:49:57.457496Z", "iopub.status.idle": "2025-03-25T03:49:57.462262Z", "shell.execute_reply": "2025-03-25T03:49:57.461985Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset contains gene expression data from cell lines\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "\n", "# For trait (Retinoblastoma): Not directly available in sample characteristics\n", "# However, the dataset is about Retinoblastoma (RB) signaling network in ovarian cancer\n", "# This is not patient-level data for Retinoblastoma, but cell lines\n", "trait_row = None # Not available at sample level \n", "\n", "# For age: Not available in this dataset (cell line study)\n", "age_row = None\n", "\n", "# For gender: Not applicable for cell lines\n", "gender_row = None\n", "\n", "# 2.2 Data Type Conversion Functions\n", "\n", "# For trait - not needed as data isn't available\n", "def convert_trait(value):\n", " return None\n", "\n", "# For age - not needed as data isn't available\n", "def convert_age(value):\n", " return None\n", "\n", "# For gender - not needed as data isn't available\n", "def convert_gender(value):\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Initial filtering to determine dataset usability\n", "is_trait_available = (trait_row is not None) # False in this case\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 step\n", "# (No clinical feature extraction to perform)\n" ] }, { "cell_type": "markdown", "id": "d442f2bf", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "ed075295", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:49:57.463107Z", "iopub.status.busy": "2025-03-25T03:49:57.463005Z", "iopub.status.idle": "2025-03-25T03:49:57.580801Z", "shell.execute_reply": "2025-03-25T03:49:57.580472Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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\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\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(gene_data.index[:20])\n" ] }, { "cell_type": "markdown", "id": "5aa1e77d", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "86979587", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:49:57.582035Z", "iopub.status.busy": "2025-03-25T03:49:57.581918Z", "iopub.status.idle": "2025-03-25T03:49:57.583748Z", "shell.execute_reply": "2025-03-25T03:49:57.583476Z" } }, "outputs": [], "source": [ "# These identifiers are Illumina probe IDs, not human gene symbols\n", "# ILMN_ prefix is characteristic of Illumina BeadArray microarray probes\n", "# These need to be mapped to human gene symbols for biological interpretation\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "70216cb0", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "fee0a2f8", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:49:57.584747Z", "iopub.status.busy": "2025-03-25T03:49:57.584644Z", "iopub.status.idle": "2025-03-25T03:50:01.181044Z", "shell.execute_reply": "2025-03-25T03:50:01.180689Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['ILMN_1343048', 'ILMN_1343049', 'ILMN_1343050', 'ILMN_1343052', 'ILMN_1343059'], 'Species': [nan, nan, nan, nan, nan], 'Source': [nan, nan, nan, nan, nan], 'Search_Key': [nan, nan, nan, nan, nan], 'Transcript': [nan, nan, nan, nan, nan], 'ILMN_Gene': [nan, nan, nan, nan, nan], 'Source_Reference_ID': [nan, nan, nan, nan, nan], 'RefSeq_ID': [nan, nan, nan, nan, nan], 'Unigene_ID': [nan, nan, nan, nan, nan], 'Entrez_Gene_ID': [nan, nan, nan, nan, nan], 'GI': [nan, nan, nan, nan, nan], 'Accession': [nan, nan, nan, nan, nan], 'Symbol': ['phage_lambda_genome', 'phage_lambda_genome', 'phage_lambda_genome:low', 'phage_lambda_genome:low', 'thrB'], 'Protein_Product': [nan, nan, nan, nan, 'thrB'], 'Probe_Id': [nan, nan, nan, nan, nan], 'Array_Address_Id': [5090180.0, 6510136.0, 7560739.0, 1450438.0, 1240647.0], 'Probe_Type': [nan, nan, nan, nan, nan], 'Probe_Start': [nan, nan, nan, nan, nan], 'SEQUENCE': ['GAATAAAGAACAATCTGCTGATGATCCCTCCGTGGATCTGATTCGTGTAA', 'CCATGTGATACGAGGGCGCGTAGTTTGCATTATCGTTTTTATCGTTTCAA', 'CCGACAGATGTATGTAAGGCCAACGTGCTCAAATCTTCATACAGAAAGAT', 'TCTGTCACTGTCAGGAAAGTGGTAAAACTGCAACTCAATTACTGCAATGC', 'CTTGTGCCTGAGCTGTCAAAAGTAGAGCACGTCGCCGAGATGAAGGGCGC'], 'Chromosome': [nan, nan, nan, nan, nan], 'Probe_Chr_Orientation': [nan, nan, nan, nan, nan], 'Probe_Coordinates': [nan, nan, nan, nan, nan], 'Cytoband': [nan, nan, nan, nan, nan], 'Definition': [nan, nan, nan, nan, nan], 'Ontology_Component': [nan, nan, nan, nan, nan], 'Ontology_Process': [nan, nan, nan, nan, nan], 'Ontology_Function': [nan, nan, nan, nan, nan], 'Synonyms': [nan, nan, nan, nan, nan], 'Obsolete_Probe_Id': [nan, nan, nan, nan, nan], 'GB_ACC': [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": "ba34c61c", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "27f1a288", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:01.182282Z", "iopub.status.busy": "2025-03-25T03:50:01.182159Z", "iopub.status.idle": "2025-03-25T03:50:01.357819Z", "shell.execute_reply": "2025-03-25T03:50:01.357451Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data after mapping (first 5 genes):\n", " GSM1551822 GSM1551823 GSM1551824 GSM1551825 GSM1551826 GSM1551827 \\\n", "Gene \n", "A1BG 31.82586 49.63005 26.43715 30.91755 203.61640 44.67797 \n", "A1CF 41.20912 33.54251 33.00000 33.00000 94.47501 33.00000 \n", "A26C3 38.00962 33.00000 33.00000 40.55023 33.00000 33.00000 \n", "A2BP1 44.00000 50.24579 44.00000 44.00000 51.90125 44.00000 \n", "A2LD1 184.73540 26.63804 252.88430 181.11670 262.97600 169.51240 \n", "\n", " GSM1551828 GSM1551829 GSM1551830 GSM1551831 ... GSM1551846 \\\n", "Gene ... \n", "A1BG 35.65852 30.68812 25.05865 25.17648 ... 22.00000 \n", "A1CF 33.00000 33.00000 33.00000 33.00000 ... 33.72447 \n", "A26C3 33.00000 33.00000 33.00000 33.00000 ... 37.76488 \n", "A2BP1 44.00000 44.00000 44.00000 44.00000 ... 44.00000 \n", "A2LD1 203.44190 297.79900 120.46250 155.10080 ... 119.79210 \n", "\n", " GSM1551847 GSM1551848 GSM1551849 GSM1551850 GSM1551851 GSM1551852 \\\n", "Gene \n", "A1BG 46.57168 43.87407 27.34362 29.3245 27.60207 26.94254 \n", "A1CF 33.00000 33.00000 33.00000 33.0000 34.24624 33.00000 \n", "A26C3 62.37114 36.62504 33.00000 33.0000 33.00000 33.00000 \n", "A2BP1 48.16492 48.44497 44.00000 44.0000 47.19382 44.00000 \n", "A2LD1 83.02063 117.81130 83.63787 143.5479 70.97436 273.51340 \n", "\n", " GSM1551853 GSM1551854 GSM1551855 \n", "Gene \n", "A1BG 24.58930 30.87610 40.4313 \n", "A1CF 33.00000 33.00000 33.0000 \n", "A26C3 33.31700 38.56084 33.0000 \n", "A2BP1 44.18612 44.00000 44.0000 \n", "A2LD1 72.44486 105.39950 87.4166 \n", "\n", "[5 rows x 34 columns]\n", "\n", "Gene expression data shape: (21372, 34)\n" ] } ], "source": [ "# 1. Determine which columns contain probe IDs and gene symbols\n", "# From the previous outputs, we can see:\n", "# - In gene_data, the index has ILMN_ identifiers (Illumina probe IDs)\n", "# - In gene_annotation, 'ID' column has the same ILMN_ format, and 'Symbol' column contains gene symbols\n", "\n", "# 2. Get the gene mapping dataframe by extracting the relevant columns\n", "probe_col = 'ID' # Column containing probe IDs that match gene_data index\n", "gene_col = 'Symbol' # Column containing gene symbols\n", "\n", "mapping_data = get_gene_mapping(gene_annotation, probe_col, gene_col)\n", "\n", "# 3. Apply the gene mapping to convert probe-level data to gene-level data\n", "gene_data = apply_gene_mapping(gene_data, mapping_data)\n", "\n", "# Print the first few rows of the resulting gene expression data\n", "print(\"Gene expression data after mapping (first 5 genes):\")\n", "print(gene_data.head(5))\n", "\n", "# Print the shape of the gene expression data\n", "print(f\"\\nGene expression data shape: {gene_data.shape}\")\n" ] }, { "cell_type": "markdown", "id": "4ceec055", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "18fe9e01", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:01.359275Z", "iopub.status.busy": "2025-03-25T03:50:01.359163Z", "iopub.status.idle": "2025-03-25T03:50:01.745262Z", "shell.execute_reply": "2025-03-25T03:50:01.744869Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data shape: (20259, 34)\n", "First few normalized gene symbols: ['A1BG', 'A1BG-AS1', 'A1CF', 'A2M', 'A2ML1', 'A3GALT2', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Retinoblastoma/gene_data/GSE63529.csv\n", "No clinical data available for patient-level Retinoblastoma in this dataset.\n", "This dataset doesn't contain patient-level Retinoblastoma trait data and cannot be used for association studies.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the obtained gene expression data\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Normalized gene data shape: {normalized_gene_data.shape}\")\n", "print(f\"First few normalized gene symbols: {list(normalized_gene_data.index[:10])}\")\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. Since we determined in Step 2 that trait data (patient-level Retinoblastoma data) \n", "# is not available in this dataset, we can't proceed with linking clinical and genetic data\n", "print(\"No clinical data available for patient-level Retinoblastoma in this dataset.\")\n", "\n", "# 3-5. For datasets without trait data, we use is_final=False in the validation\n", "# This will record the dataset's metadata but not attempt final validation\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort, \n", " info_path=json_path, \n", " is_gene_available=True, \n", " is_trait_available=False\n", ")\n", "\n", "# 6. Since the dataset doesn't have trait data, we don't save any linked data file\n", "print(f\"This dataset doesn't contain patient-level Retinoblastoma trait data and cannot be used for association studies.\")" ] } ], "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 }