{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e19fae99", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:02:49.985676Z", "iopub.status.busy": "2025-03-25T06:02:49.985188Z", "iopub.status.idle": "2025-03-25T06:02:50.149824Z", "shell.execute_reply": "2025-03-25T06:02:50.149520Z" } }, "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 = \"GSE126308\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Ovarian_Cancer\"\n", "in_cohort_dir = \"../../input/GEO/Ovarian_Cancer/GSE126308\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Ovarian_Cancer/GSE126308.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Ovarian_Cancer/gene_data/GSE126308.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Ovarian_Cancer/clinical_data/GSE126308.csv\"\n", "json_path = \"../../output/preprocess/Ovarian_Cancer/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "b0b62a0a", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "b49f79b3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:02:50.151185Z", "iopub.status.busy": "2025-03-25T06:02:50.151047Z", "iopub.status.idle": "2025-03-25T06:02:50.312023Z", "shell.execute_reply": "2025-03-25T06:02:50.311755Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Biomarkers in older ovarian cancer patients\"\n", "!Series_summary\t\"Identification and validation of potential prognostic biomarkers in older ovarian cancer patients with high-grade serous adenocarcinoma (HGSC)\"\n", "!Series_overall_design\t\"Biomarker study with the purpose of identifying and validating biomarkers in patients with early disease progression of HGSC vs. patients with late.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['gender: female'], 1: ['tissue: ovarian tumor biopsy'], 2: ['diagnosis: high-grade serous adenocarcinoma (HGSC)'], 3: ['disease progression: early', 'disease progression: late']}\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": "bdaf2c9a", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "ab7bc4fe", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:02:50.313147Z", "iopub.status.busy": "2025-03-25T06:02:50.313034Z", "iopub.status.idle": "2025-03-25T06:02:50.320468Z", "shell.execute_reply": "2025-03-25T06:02:50.320197Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of selected clinical features:\n", "{'GSM3596018': [1.0], 'GSM3596019': [0.0], 'GSM3596020': [1.0], 'GSM3596021': [1.0], 'GSM3596022': [0.0], 'GSM3596023': [0.0], 'GSM3596024': [1.0], 'GSM3596025': [0.0], 'GSM3596026': [0.0], 'GSM3596027': [1.0], 'GSM3596028': [1.0], 'GSM3596029': [1.0], 'GSM3596030': [0.0], 'GSM3596031': [0.0], 'GSM3596032': [1.0], 'GSM3596033': [1.0], 'GSM3596034': [1.0], 'GSM3596035': [1.0], 'GSM3596036': [1.0], 'GSM3596037': [1.0], 'GSM3596038': [1.0], 'GSM3596039': [1.0], 'GSM3596040': [0.0], 'GSM3596041': [0.0], 'GSM3596042': [0.0], 'GSM3596043': [0.0], 'GSM3596044': [0.0], 'GSM3596045': [0.0], 'GSM3596046': [0.0], 'GSM3596047': [0.0], 'GSM3596048': [0.0], 'GSM3596049': [0.0], 'GSM3596050': [0.0], 'GSM3596051': [0.0], 'GSM3596052': [0.0], 'GSM3596053': [0.0], 'GSM3596054': [1.0], 'GSM3596055': [0.0], 'GSM3596056': [0.0], 'GSM3596057': [0.0], 'GSM3596058': [0.0], 'GSM3596059': [1.0], 'GSM3596060': [1.0], 'GSM3596061': [0.0], 'GSM3596062': [0.0], 'GSM3596063': [1.0], 'GSM3596064': [0.0], 'GSM3596065': [0.0], 'GSM3596066': [0.0], 'GSM3596067': [1.0]}\n", "Clinical data saved to ../../output/preprocess/Ovarian_Cancer/clinical_data/GSE126308.csv\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information and sample characteristics, this dataset appears to contain gene expression data\n", "# from ovarian tumor biopsies of patients with high-grade serous adenocarcinoma (HGSC).\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "# Analyzing the sample characteristics dictionary:\n", "\n", "# Trait (Ovarian Cancer): The key 3 contains \"disease progression: early\" and \"disease progression: late\"\n", "# which can be used as a proxy for cancer outcome/progression\n", "trait_row = 3\n", "\n", "# Age: No explicit age information is provided in the sample characteristics\n", "age_row = None\n", "\n", "# Gender: Key 0 contains gender information, but it shows all patients are female\n", "# Since there's only one value (female), it's constant and not useful for association studies\n", "gender_row = None\n", "\n", "# 2.2 Data Type Conversion\n", "# Convert disease progression to binary (early: 1, late: 0)\n", "def convert_trait(value):\n", " if value is None:\n", " return None\n", " # Extract the value part after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " if 'early' in value.lower():\n", " return 1 # Early disease progression\n", " elif 'late' in value.lower():\n", " return 0 # Late disease progression\n", " else:\n", " return None\n", "\n", "# Define empty conversion functions for completeness, though they won't be used\n", "def convert_age(value):\n", " return None\n", "\n", "def convert_gender(value):\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Initial filtering on usability\n", "is_trait_available = trait_row is not None\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", " # Extract clinical features\n", " selected_clinical_df = geo_select_clinical_features(\n", " clinical_df=clinical_data,\n", " trait=\"Disease_Progression\", # Using a more descriptive name for the 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 extracted clinical features\n", " preview = preview_df(selected_clinical_df)\n", " print(\"Preview of selected clinical features:\")\n", " print(preview)\n", " \n", " # Save the clinical data to CSV\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " selected_clinical_df.to_csv(out_clinical_data_file, index=True)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "26911a49", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "de7b97eb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:02:50.321416Z", "iopub.status.busy": "2025-03-25T06:02:50.321306Z", "iopub.status.idle": "2025-03-25T06:02:50.560173Z", "shell.execute_reply": "2025-03-25T06:02:50.559722Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['2824546_st', '2824549_st', '2824551_st', '2824554_st', '2827992_st',\n", " '2827995_st', '2827996_st', '2828010_st', '2828012_st', '2835442_st',\n", " '2835447_st', '2835453_st', '2835456_st', '2835459_st', '2835461_st',\n", " '2839509_st', '2839511_st', '2839513_st', '2839515_st', '2839517_st'],\n", " dtype='object', name='ID')\n" ] } ], "source": [ "# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.\n", "gene_data = get_genetic_data(matrix_file)\n", "\n", "# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.\n", "print(gene_data.index[:20])\n" ] }, { "cell_type": "markdown", "id": "b0df51c2", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "b7ce8a34", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:02:50.562130Z", "iopub.status.busy": "2025-03-25T06:02:50.561965Z", "iopub.status.idle": "2025-03-25T06:02:50.563989Z", "shell.execute_reply": "2025-03-25T06:02:50.563721Z" } }, "outputs": [], "source": [ "# These appear to be Affymetrix probeset IDs (with the '_st' suffix), not human gene symbols\n", "# They need to be mapped to official gene symbols for meaningful analysis\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "ba445a01", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "09dbe40d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:02:50.565399Z", "iopub.status.busy": "2025-03-25T06:02:50.565288Z", "iopub.status.idle": "2025-03-25T06:02:56.980997Z", "shell.execute_reply": "2025-03-25T06:02:56.980626Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['TC01000001.hg.1', 'TC01000002.hg.1', 'TC01000003.hg.1', 'TC01000004.hg.1', 'TC01000005.hg.1'], 'probeset_id': ['TC01000001.hg.1', 'TC01000002.hg.1', 'TC01000003.hg.1', 'TC01000004.hg.1', 'TC01000005.hg.1'], 'seqname': ['chr1', 'chr1', 'chr1', 'chr1', 'chr1'], 'strand': ['+', '+', '+', '+', '+'], 'start': ['11869', '29554', '69091', '160446', '317811'], 'stop': ['14409', '31109', '70008', '161525', '328581'], 'total_probes': [49.0, 60.0, 30.0, 30.0, 191.0], 'gene_assignment': ['NR_046018 // DDX11L1 // DEAD/H (Asp-Glu-Ala-Asp/His) box helicase 11 like 1 // 1p36.33 // 100287102 /// ENST00000456328 // DDX11L5 // DEAD/H (Asp-Glu-Ala-Asp/His) box helicase 11 like 5 // 9p24.3 // 100287596 /// ENST00000456328 // DDX11L1 // DEAD/H (Asp-Glu-Ala-Asp/His) box helicase 11 like 1 // 1p36.33 // 100287102', 'ENST00000408384 // MIR1302-11 // microRNA 1302-11 // --- // 100422919 /// ENST00000408384 // MIR1302-10 // microRNA 1302-10 // --- // 100422834 /// ENST00000408384 // MIR1302-9 // microRNA 1302-9 // --- // 100422831 /// ENST00000408384 // MIR1302-2 // microRNA 1302-2 // --- // 100302278 /// ENST00000469289 // MIR1302-11 // microRNA 1302-11 // --- // 100422919 /// ENST00000469289 // MIR1302-10 // microRNA 1302-10 // --- // 100422834 /// ENST00000469289 // MIR1302-9 // microRNA 1302-9 // --- // 100422831 /// ENST00000469289 // MIR1302-2 // microRNA 1302-2 // --- // 100302278 /// ENST00000473358 // MIR1302-11 // microRNA 1302-11 // --- // 100422919 /// ENST00000473358 // MIR1302-10 // microRNA 1302-10 // --- // 100422834 /// ENST00000473358 // MIR1302-9 // microRNA 1302-9 // --- // 100422831 /// ENST00000473358 // MIR1302-2 // microRNA 1302-2 // --- // 100302278 /// OTTHUMT00000002841 // OTTHUMG00000000959 // NULL // --- // --- /// OTTHUMT00000002841 // RP11-34P13.3 // NULL // --- // --- /// OTTHUMT00000002840 // OTTHUMG00000000959 // NULL // --- // --- /// OTTHUMT00000002840 // RP11-34P13.3 // NULL // --- // ---', 'NM_001005484 // OR4F5 // olfactory receptor, family 4, subfamily F, member 5 // 1p36.33 // 79501 /// ENST00000335137 // OR4F5 // olfactory receptor, family 4, subfamily F, member 5 // 1p36.33 // 79501 /// OTTHUMT00000003223 // OR4F5 // NULL // --- // ---', 'OTTHUMT00000007169 // OTTHUMG00000002525 // NULL // --- // --- /// OTTHUMT00000007169 // RP11-34P13.9 // NULL // --- // ---', 'NR_028322 // LOC100132287 // uncharacterized LOC100132287 // 1p36.33 // 100132287 /// NR_028327 // LOC100133331 // uncharacterized LOC100133331 // 1p36.33 // 100133331 /// ENST00000425496 // LOC101060495 // uncharacterized LOC101060495 // --- // 101060495 /// ENST00000425496 // LOC101060494 // uncharacterized LOC101060494 // --- // 101060494 /// ENST00000425496 // LOC101059936 // uncharacterized LOC101059936 // --- // 101059936 /// ENST00000425496 // LOC100996502 // uncharacterized LOC100996502 // --- // 100996502 /// ENST00000425496 // LOC100996328 // uncharacterized LOC100996328 // --- // 100996328 /// ENST00000425496 // LOC100287894 // uncharacterized LOC100287894 // 7q11.21 // 100287894 /// NR_028325 // LOC100132062 // uncharacterized LOC100132062 // 5q35.3 // 100132062 /// OTTHUMT00000346878 // OTTHUMG00000156968 // NULL // --- // --- /// OTTHUMT00000346878 // RP4-669L17.10 // NULL // --- // --- /// OTTHUMT00000346879 // OTTHUMG00000156968 // NULL // --- // --- /// OTTHUMT00000346879 // RP4-669L17.10 // NULL // --- // --- /// OTTHUMT00000346880 // OTTHUMG00000156968 // NULL // --- // --- /// OTTHUMT00000346880 // RP4-669L17.10 // NULL // --- // --- /// OTTHUMT00000346881 // OTTHUMG00000156968 // NULL // --- // --- /// OTTHUMT00000346881 // RP4-669L17.10 // NULL // --- // ---'], 'mrna_assignment': ['NR_046018 // RefSeq // Homo sapiens DEAD/H (Asp-Glu-Ala-Asp/His) box helicase 11 like 1 (DDX11L1), non-coding RNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000456328 // ENSEMBL // cdna:known chromosome:GRCh37:1:11869:14409:1 gene:ENSG00000223972 gene_biotype:pseudogene transcript_biotype:processed_transcript // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aaa.3 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// uc010nxq.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// uc010nxr.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0', 'ENST00000408384 // ENSEMBL // ncrna:miRNA chromosome:GRCh37:1:30366:30503:1 gene:ENSG00000221311 gene_biotype:miRNA transcript_biotype:miRNA // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000469289 // ENSEMBL // havana:lincRNA chromosome:GRCh37:1:30267:31109:1 gene:ENSG00000243485 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000473358 // ENSEMBL // havana:lincRNA chromosome:GRCh37:1:29554:31097:1 gene:ENSG00000243485 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000002841 // Havana transcript // cdna:all chromosome:VEGA52:1:30267:31109:1 Gene:OTTHUMG00000000959 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000002840 // Havana transcript // cdna:all chromosome:VEGA52:1:29554:31097:1 Gene:OTTHUMG00000000959 // chr1 // 100 // 100 // 0 // --- // 0', 'NM_001005484 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000335137 // ENSEMBL // cdna:known chromosome:GRCh37:1:69091:70008:1 gene:ENSG00000186092 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aal.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000003223 // Havana transcript // cdna:all chromosome:VEGA52:1:69091:70008:1 Gene:OTTHUMG00000001094 // chr1 // 100 // 100 // 0 // --- // 0', 'ENST00000496488 // ENSEMBL // havana:lincRNA chromosome:GRCh37:1:160446:161525:1 gene:ENSG00000241599 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000007169 // Havana transcript // cdna:all chromosome:VEGA52:1:160446:161525:1 Gene:OTTHUMG00000002525 // chr1 // 100 // 100 // 0 // --- // 0', 'NR_028322 // RefSeq // Homo sapiens uncharacterized LOC100132287 (LOC100132287), non-coding RNA. // chr1 // 100 // 100 // 0 // --- // 0 /// NR_028327 // RefSeq // Homo sapiens uncharacterized LOC100133331 (LOC100133331), non-coding RNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000425496 // ENSEMBL // ensembl:lincRNA chromosome:GRCh37:1:324756:328453:1 gene:ENSG00000237094 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000426316 // ENSEMBL // [retired] cdna:known chromosome:GRCh37:1:317811:328455:1 gene:ENSG00000240876 gene_biotype:processed_transcript transcript_biotype:processed_transcript // chr1 // 100 // 100 // 0 // --- // 0 /// NR_028325 // RefSeq // Homo sapiens uncharacterized LOC100132062 (LOC100132062), non-coding RNA. // chr1 // 100 // 100 // 0 // --- // 0 /// uc009vjk.2 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// uc021oeh.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// uc021oei.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346906 // Havana transcript // [retired] cdna:all chromosome:VEGA50:1:317811:328455:1 Gene:OTTHUMG00000156972 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346878 // Havana transcript // cdna:all chromosome:VEGA52:1:320162:321056:1 Gene:OTTHUMG00000156968 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346879 // Havana transcript // cdna:all chromosome:VEGA52:1:320162:324461:1 Gene:OTTHUMG00000156968 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346880 // Havana transcript // cdna:all chromosome:VEGA52:1:317720:324873:1 Gene:OTTHUMG00000156968 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346881 // Havana transcript // cdna:all chromosome:VEGA52:1:322672:324955:1 Gene:OTTHUMG00000156968 // chr1 // 100 // 100 // 0 // --- // 0'], 'swissprot': ['NR_046018 // B7ZGX0 /// NR_046018 // B7ZGX2 /// NR_046018 // B7ZGX7 /// NR_046018 // B7ZGX8 /// ENST00000456328 // B7ZGX0 /// ENST00000456328 // B7ZGX2 /// ENST00000456328 // B7ZGX3 /// ENST00000456328 // B7ZGX7 /// ENST00000456328 // B7ZGX8 /// ENST00000456328 // Q6ZU42', '---', 'NM_001005484 // Q8NH21 /// ENST00000335137 // Q8NH21', '---', 'NR_028325 // B4DYM5 /// NR_028325 // B4E0H4 /// NR_028325 // B4E3X0 /// NR_028325 // B4E3X2 /// NR_028325 // Q6ZQS4'], 'unigene': ['NR_046018 // Hs.714157 // testis| normal| adult /// ENST00000456328 // Hs.719844 // brain| testis| normal /// ENST00000456328 // Hs.714157 // testis| normal| adult /// ENST00000456328 // Hs.618434 // testis| normal', 'ENST00000469289 // Hs.622486 // eye| normal| adult /// ENST00000469289 // Hs.729632 // testis| normal /// ENST00000469289 // Hs.742718 // testis /// ENST00000473358 // Hs.622486 // eye| normal| adult /// ENST00000473358 // Hs.729632 // testis| normal /// ENST00000473358 // Hs.742718 // testis', 'NM_001005484 // Hs.554500 // --- /// ENST00000335137 // Hs.554500 // ---', '---', 'NR_028322 // Hs.446409 // adrenal gland| blood| bone| brain| connective tissue| embryonic tissue| eye| intestine| kidney| larynx| lung| lymph node| mouth| pharynx| placenta| prostate| skin| testis| thymus| thyroid| uterus| bladder carcinoma| chondrosarcoma| colorectal tumor| germ cell tumor| head and neck tumor| kidney tumor| leukemia| lung tumor| normal| primitive neuroectodermal tumor of the CNS| uterine tumor|embryoid body| blastocyst| fetus| neonate| adult /// NR_028327 // Hs.733048 // ascites| bladder| blood| brain| embryonic tissue| eye| intestine| kidney| larynx| liver| lung| mammary gland| mouth| pancreas| placenta| prostate| skin| stomach| testis| thymus| thyroid| trachea| uterus| bladder carcinoma| breast (mammary gland) tumor| colorectal tumor| gastrointestinal tumor| head and neck tumor| kidney tumor| leukemia| liver tumor| lung tumor| normal| pancreatic tumor| prostate cancer| retinoblastoma| skin tumor| soft tissue/muscle tissue tumor| uterine tumor|embryoid body| blastocyst| fetus| adult /// ENST00000425496 // Hs.744556 // mammary gland| normal| adult /// ENST00000425496 // Hs.660700 // eye| placenta| testis| normal| adult /// ENST00000425496 // Hs.518952 // blood| brain| intestine| lung| mammary gland| mouth| muscle| pharynx| placenta| prostate| spleen| testis| thymus| thyroid| trachea| breast (mammary gland) tumor| colorectal tumor| head and neck tumor| leukemia| lung tumor| normal| prostate cancer| fetus| adult /// ENST00000425496 // Hs.742131 // testis| normal| adult /// ENST00000425496 // Hs.636102 // uterus| uterine tumor /// ENST00000425496 // Hs.646112 // brain| intestine| larynx| lung| mouth| prostate| testis| thyroid| colorectal tumor| head and neck tumor| lung tumor| normal| prostate cancer| adult /// ENST00000425496 // Hs.647795 // brain| lung| lung tumor| adult /// ENST00000425496 // Hs.684307 // --- /// ENST00000425496 // Hs.720881 // testis| normal /// ENST00000425496 // Hs.729353 // brain| lung| placenta| testis| trachea| lung tumor| normal| fetus| adult /// ENST00000425496 // Hs.735014 // ovary| ovarian tumor /// NR_028325 // Hs.732199 // ascites| blood| brain| connective tissue| embryonic tissue| eye| intestine| kidney| lung| ovary| placenta| prostate| stomach| testis| thymus| uterus| chondrosarcoma| colorectal tumor| gastrointestinal tumor| kidney tumor| leukemia| lung tumor| normal| ovarian tumor| fetus| adult'], 'category': ['main', 'main', 'main', 'main', 'main'], 'locus type': ['Coding', 'Coding', 'Coding', 'Coding', 'Coding'], 'notes': ['---', '---', '---', '---', '2 retired transcript(s) from ENSEMBL, Havana transcript'], 'SPOT_ID': ['chr1(+):11869-14409', 'chr1(+):29554-31109', 'chr1(+):69091-70008', 'chr1(+):160446-161525', 'chr1(+):317811-328581']}\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": "82f1be58", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "d848e140", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:02:56.982800Z", "iopub.status.busy": "2025-03-25T06:02:56.982681Z", "iopub.status.idle": "2025-03-25T06:02:58.679046Z", "shell.execute_reply": "2025-03-25T06:02:58.678675Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of gene expression data after mapping:\n", " GSM3596018 GSM3596019 GSM3596020 GSM3596021 GSM3596022 \\\n", "Gene \n", "A1BG 6.12260 6.339200 5.827900 6.005450 6.104400 \n", "A1BG-AS1 1.82860 1.877100 1.690500 1.849950 1.934200 \n", "A1CF 0.41832 0.420420 0.415560 0.425280 0.407020 \n", "A2M 2.29640 2.325617 2.331117 2.338433 2.284167 \n", "A2M-AS1 1.45670 1.468750 1.471750 1.457400 1.430400 \n", "\n", " GSM3596023 GSM3596024 GSM3596025 GSM3596026 GSM3596027 ... \\\n", "Gene ... \n", "A1BG 6.16070 6.341150 6.247650 6.018950 6.04270 ... \n", "A1BG-AS1 1.91520 2.008550 1.947150 1.910250 1.92280 ... \n", "A1CF 0.42452 0.441580 0.427800 0.420120 0.42674 ... \n", "A2M 2.30545 2.198733 2.278983 2.205517 2.29945 ... \n", "A2M-AS1 1.45345 1.344100 1.413150 1.360950 1.44525 ... \n", "\n", " GSM3596058 GSM3596059 GSM3596060 GSM3596061 GSM3596062 \\\n", "Gene \n", "A1BG 5.95325 5.785650 6.001800 5.968550 5.90080 \n", "A1BG-AS1 1.78925 1.927850 1.833200 1.901350 1.83500 \n", "A1CF 0.42826 0.407980 0.416240 0.410480 0.41632 \n", "A2M 2.46535 2.346717 2.290833 2.371267 2.38640 \n", "A2M-AS1 1.59305 1.405150 1.434200 1.537500 1.54530 \n", "\n", " GSM3596063 GSM3596064 GSM3596065 GSM3596066 GSM3596067 \n", "Gene \n", "A1BG 5.893700 5.828700 5.97295 5.581900 6.048100 \n", "A1BG-AS1 1.963800 1.906800 1.95105 1.814100 1.956600 \n", "A1CF 0.424940 0.399940 0.40940 0.361940 0.403560 \n", "A2M 2.533183 2.460467 2.35255 2.174333 2.304617 \n", "A2M-AS1 1.678550 1.547500 1.54355 1.379200 1.481350 \n", "\n", "[5 rows x 50 columns]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to ../../output/preprocess/Ovarian_Cancer/gene_data/GSE126308.csv\n" ] } ], "source": [ "# 1. Identify the relevant columns for gene mapping\n", "# From the gene annotation preview, we see:\n", "# - 'probeset_id' is the probe identifier (same format as gene expression data)\n", "# - 'gene_assignment' contains gene symbols in a complex format\n", "\n", "# Extract the mapping between probeset_id and gene symbols\n", "mapping_data = get_gene_mapping(gene_annotation, 'ID', 'gene_assignment')\n", "\n", "# 2. Apply the gene mapping to convert probe-level measurements to gene expression\n", "gene_data = apply_gene_mapping(gene_data, mapping_data)\n", "\n", "# 3. Normalize gene symbols to standard format and handle duplicates\n", "gene_data = normalize_gene_symbols_in_index(gene_data)\n", "\n", "# 4. Preview the first few rows of converted gene expression data\n", "print(\"Preview of gene expression data after mapping:\")\n", "print(gene_data.head())\n", "\n", "# 5. Save the gene expression data\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "gene_data.to_csv(out_gene_data_file)\n", "print(f\"Gene expression data saved to {out_gene_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "e6278621", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "a1a64414", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:02:58.680697Z", "iopub.status.busy": "2025-03-25T06:02:58.680576Z", "iopub.status.idle": "2025-03-25T06:03:11.208381Z", "shell.execute_reply": "2025-03-25T06:03:11.208015Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "For the feature 'Disease_Progression', the least common label is '1.0' with 20 occurrences. This represents 40.00% of the dataset.\n", "The distribution of the feature 'Disease_Progression' in this dataset is fine.\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data saved to ../../output/preprocess/Ovarian_Cancer/GSE126308.csv\n" ] } ], "source": [ "# 1. Gene data has already been normalized in the previous step\n", "# No need to normalize again, we can directly use the gene_data from the previous step\n", "\n", "# 2. Load the clinical data from the file since we need it for linking\n", "# Loading clinical data from file to ensure it's available\n", "clinical_data = pd.read_csv(out_clinical_data_file, index_col=0)\n", "\n", "# Link the clinical and genetic data\n", "linked_data = geo_link_clinical_genetic_data(clinical_data, gene_data)\n", "\n", "# 3. Handle missing values in the linked data\n", "linked_data = handle_missing_values(linked_data, \"Disease_Progression\") # Using the trait name we assigned in step 2\n", "\n", "# 4. Determine whether the trait and some demographic features are severely biased, and remove biased features\n", "is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, \"Disease_Progression\")\n", "\n", "# 5. Conduct quality check and save the cohort information\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_trait_biased, \n", " df=unbiased_linked_data,\n", " note=\"Cohort contains ovarian cancer patients with early vs. late disease progression.\"\n", ")\n", "\n", "# 6. If the linked data is usable, save it as a CSV file\n", "if is_usable:\n", " # Create directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " # Save the data\n", " unbiased_linked_data.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(\"Data quality check failed. 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 }