{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "2b69f3d0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:44:54.801849Z", "iopub.status.busy": "2025-03-25T03:44:54.801368Z", "iopub.status.idle": "2025-03-25T03:44:54.969840Z", "shell.execute_reply": "2025-03-25T03:44:54.969399Z" } }, "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 = \"Psoriatic_Arthritis\"\n", "cohort = \"GSE57383\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Psoriatic_Arthritis\"\n", "in_cohort_dir = \"../../input/GEO/Psoriatic_Arthritis/GSE57383\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Psoriatic_Arthritis/GSE57383.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Psoriatic_Arthritis/gene_data/GSE57383.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Psoriatic_Arthritis/clinical_data/GSE57383.csv\"\n", "json_path = \"../../output/preprocess/Psoriatic_Arthritis/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "6251efed", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "7ca8adbe", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:44:54.971250Z", "iopub.status.busy": "2025-03-25T03:44:54.971106Z", "iopub.status.idle": "2025-03-25T03:44:55.204945Z", "shell.execute_reply": "2025-03-25T03:44:55.204559Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Gene expression of CD14+ cells from RA, PsA and PsO patients with Infliximab treatment\"\n", "!Series_summary\t\"objection: The immune inflammatory disorders rheumatoid arthritis (RA), psoriatic arthritis (PsA) and psoriasis (Ps) share common pathologic features and show responsiveness to anti-tumor necrosis factor (TNF) agents yet they are phenotypically distinct. The aim of this study was to examine if anti-TNF therapy is associated with divergent gene expression profiles in circulating cells and target tissues of patients with these diseases\"\n", "!Series_summary\t\"Method: Peripheral blood CD14+ and CD14- cells were isolated from 9 RA, 12 PsA and 10 Ps patients before and after infliximab (IFX) treatment\"\n", "!Series_overall_design\t\"Between April 2007 and June 2009, 31 patients with active RA, PsA and Ps who were naïve to anti-TNF agents, were recruited from the Faculty Rheumatology Clinics at the University of Rochester Medical Center after informed, written consent was obtained in a protocol approved by the Research Subjects Review Board at the University of Rochester Medical Center. Of the 31 subjects, 9 had active RA and 12 had PsA despite treatment with Disease Modifying Anti-Rheumatic Drugs (DMARDs). Also, 10 patients with extensive Ps (>5% BSA) documented by a dermatologist, were enrolled and they were examined by a rheumatologist to exclude the presence of inflammatory arthritis. Nineteen healthy controls were also recruited.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['response: .', 'response: responder', 'response: nonresponder'], 1: ['Sex: F', 'Sex: M'], 2: ['age: 40', 'age: 54', 'age: 36', 'age: 23', 'age: 42', 'age: 24', 'age: 62', 'age: 46', 'age: 56', 'age: 32', 'age: 47', 'age: 60', 'age: 44', 'age: 64', 'age: 19', 'age: 61', 'age: 57', 'age: 35', 'age: 53', 'age: 59', 'age: 28', 'age: 39', 'age: 38', 'age: 52', 'age: 70', 'age: 58', 'age: 68', 'age: 67', 'age: 31', 'age: 55'], 3: ['cell type: primary cell'], 4: ['cell subtype: CD14+'], 5: ['disease: normal', 'disease: diseased'], 6: ['disease: Health Control', 'disease: Psoriasis', 'disease: Psoriatic Arthritis', 'disease: Rheumatoid Arthritis'], 7: ['time point: wk0', 'time point: wk2', 'time point: wk10']}\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": "fadc1323", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "563278a0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:44:55.206244Z", "iopub.status.busy": "2025-03-25T03:44:55.206129Z", "iopub.status.idle": "2025-03-25T03:44:55.222267Z", "shell.execute_reply": "2025-03-25T03:44:55.221885Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of clinical data:\n", "{'GSM1381524': [0.0, 40.0, 0.0], 'GSM1381525': [0.0, 40.0, 0.0], 'GSM1381526': [0.0, 54.0, 1.0], 'GSM1381527': [0.0, 36.0, 0.0], 'GSM1381528': [0.0, 23.0, 0.0], 'GSM1381529': [0.0, 42.0, 0.0], 'GSM1381530': [0.0, 24.0, 0.0], 'GSM1381531': [0.0, 23.0, 1.0], 'GSM1381532': [0.0, 62.0, 1.0], 'GSM1381533': [0.0, 46.0, 1.0], 'GSM1381534': [0.0, 56.0, 0.0], 'GSM1381535': [0.0, 32.0, 0.0], 'GSM1381536': [0.0, 47.0, 0.0], 'GSM1381537': [0.0, 60.0, 0.0], 'GSM1381538': [0.0, 44.0, 0.0], 'GSM1381539': [0.0, 46.0, 0.0], 'GSM1381540': [0.0, 36.0, 0.0], 'GSM1381541': [0.0, 64.0, 1.0], 'GSM1381542': [0.0, 23.0, 1.0], 'GSM1381543': [nan, 19.0, 0.0], 'GSM1381544': [nan, 24.0, 0.0], 'GSM1381545': [nan, 46.0, 1.0], 'GSM1381546': [nan, 61.0, 1.0], 'GSM1381547': [nan, 57.0, 1.0], 'GSM1381548': [nan, 57.0, 1.0], 'GSM1381549': [nan, 35.0, 0.0], 'GSM1381550': [nan, 53.0, 1.0], 'GSM1381551': [nan, 59.0, 0.0], 'GSM1381552': [nan, 53.0, 1.0], 'GSM1381553': [nan, 44.0, 0.0], 'GSM1381554': [nan, 59.0, 0.0], 'GSM1381555': [nan, 19.0, 0.0], 'GSM1381556': [nan, 44.0, 0.0], 'GSM1381557': [nan, 44.0, 0.0], 'GSM1381558': [nan, 61.0, 1.0], 'GSM1381559': [nan, 57.0, 1.0], 'GSM1381560': [nan, 46.0, 1.0], 'GSM1381561': [nan, 24.0, 0.0], 'GSM1381562': [nan, 28.0, 0.0], 'GSM1381563': [nan, 28.0, 0.0], 'GSM1381564': [nan, 28.0, 0.0], 'GSM1381565': [nan, 24.0, 0.0], 'GSM1381566': [nan, 35.0, 0.0], 'GSM1381567': [nan, 53.0, 1.0], 'GSM1381568': [nan, 61.0, 1.0], 'GSM1381569': [nan, 59.0, 0.0], 'GSM1381570': [nan, 46.0, 1.0], 'GSM1381571': [nan, 19.0, 0.0], 'GSM1381572': [nan, 35.0, 0.0], 'GSM1381573': [1.0, 39.0, 0.0], 'GSM1381574': [1.0, 38.0, 0.0], 'GSM1381575': [1.0, 52.0, 0.0], 'GSM1381576': [1.0, 52.0, 0.0], 'GSM1381577': [1.0, 70.0, 1.0], 'GSM1381578': [1.0, 39.0, 1.0], 'GSM1381579': [1.0, 60.0, 0.0], 'GSM1381580': [1.0, 38.0, 0.0], 'GSM1381581': [1.0, 58.0, 0.0], 'GSM1381582': [1.0, 68.0, 0.0], 'GSM1381583': [1.0, 70.0, 1.0], 'GSM1381584': [1.0, 39.0, 0.0], 'GSM1381585': [1.0, 60.0, 0.0], 'GSM1381586': [1.0, 38.0, 0.0], 'GSM1381587': [1.0, 67.0, 1.0], 'GSM1381588': [1.0, 31.0, 1.0], 'GSM1381589': [1.0, 39.0, 1.0], 'GSM1381590': [1.0, 44.0, 1.0], 'GSM1381591': [1.0, 39.0, 0.0], 'GSM1381592': [1.0, 39.0, 1.0], 'GSM1381593': [1.0, 58.0, 0.0], 'GSM1381594': [1.0, 60.0, 0.0], 'GSM1381595': [1.0, 52.0, 0.0], 'GSM1381596': [1.0, 58.0, 0.0], 'GSM1381597': [1.0, 70.0, 1.0], 'GSM1381598': [1.0, 67.0, 1.0], 'GSM1381599': [1.0, 31.0, 1.0], 'GSM1381600': [1.0, 31.0, 1.0], 'GSM1381601': [1.0, 55.0, 1.0], 'GSM1381602': [1.0, 68.0, 0.0], 'GSM1381603': [1.0, 55.0, 1.0], 'GSM1381604': [1.0, 44.0, 1.0], 'GSM1381605': [1.0, 44.0, 1.0], 'GSM1381606': [1.0, 67.0, 1.0], 'GSM1381607': [1.0, 55.0, 1.0], 'GSM1381608': [1.0, 68.0, 0.0], 'GSM1381609': [nan, 28.0, 0.0], 'GSM1381610': [nan, 50.0, 0.0], 'GSM1381611': [nan, 28.0, 0.0], 'GSM1381612': [nan, 28.0, 0.0], 'GSM1381613': [nan, 45.0, 0.0], 'GSM1381614': [nan, 50.0, 0.0], 'GSM1381615': [nan, 51.0, 1.0], 'GSM1381616': [nan, 50.0, 0.0], 'GSM1381617': [nan, 51.0, 0.0], 'GSM1381618': [nan, 62.0, 0.0], 'GSM1381619': [nan, 66.0, 0.0], 'GSM1381620': [nan, 46.0, 1.0], 'GSM1381621': [nan, 45.0, 0.0], 'GSM1381622': [nan, 58.0, 0.0], 'GSM1381623': [nan, 62.0, 0.0], 'GSM1381624': [nan, 58.0, 0.0], 'GSM1381625': [nan, 51.0, 0.0], 'GSM1381626': [nan, 51.0, 0.0], 'GSM1381627': [nan, 66.0, 0.0], 'GSM1381628': [nan, 58.0, 0.0], 'GSM1381629': [nan, 51.0, 0.0], 'GSM1381630': [nan, 46.0, 1.0], 'GSM1381631': [nan, 45.0, 0.0], 'GSM1381632': [nan, 66.0, 0.0], 'GSM1381633': [nan, 46.0, 1.0], 'GSM1381634': [nan, 51.0, 0.0], 'GSM1381635': [nan, 62.0, 0.0]}\n", "Clinical data saved to ../../output/preprocess/Psoriatic_Arthritis/clinical_data/GSE57383.csv\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset appears to contain gene expression data from CD14+ cells,\n", "# not just miRNA or methylation data\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "# For trait - the disease/control status can be found in key 6 of the sample characteristics\n", "trait_row = 6\n", "\n", "# For age - age information is in key 2\n", "age_row = 2\n", "\n", "# For gender - sex information is in key 1\n", "gender_row = 1\n", "\n", "# 2.2 Data Type Conversion\n", "def convert_trait(value):\n", " \"\"\"Convert disease status to binary (0 for control, 1 for Psoriatic Arthritis)\"\"\"\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " # Psoriatic Arthritis is our trait of interest\n", " if value == \"Psoriatic Arthritis\":\n", " return 1\n", " elif value == \"Health Control\":\n", " return 0\n", " else:\n", " # Other diseases (Psoriasis, Rheumatoid Arthritis) are not our target trait\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age string to integer value\"\"\"\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " try:\n", " return int(value)\n", " except (ValueError, TypeError):\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary (0 for female, 1 for male)\"\"\"\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " if value.upper() == 'F':\n", " return 0\n", " elif value.upper() == 'M':\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Determine trait data availability\n", "is_trait_available = trait_row is not None\n", "\n", "# Conduct initial filtering\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", " 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 extracted features\n", " print(\"Preview of clinical data:\")\n", " print(preview_df(clinical_df))\n", " \n", " # Create the directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " \n", " # Save the clinical data\n", " clinical_df.to_csv(out_clinical_data_file)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "347160ff", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "253a338d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:44:55.223403Z", "iopub.status.busy": "2025-03-25T03:44:55.223293Z", "iopub.status.idle": "2025-03-25T03:44:55.628543Z", "shell.execute_reply": "2025-03-25T03:44:55.628023Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['1007_PM_s_at', '1053_PM_at', '117_PM_at', '121_PM_at', '1255_PM_g_at',\n", " '1294_PM_at', '1316_PM_at', '1320_PM_at', '1405_PM_i_at', '1431_PM_at',\n", " '1438_PM_at', '1487_PM_at', '1494_PM_f_at', '1552256_PM_a_at',\n", " '1552257_PM_a_at', '1552258_PM_at', '1552261_PM_at', '1552263_PM_at',\n", " '1552264_PM_a_at', '1552266_PM_at'],\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": "2330bc0b", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "d11694b1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:44:55.630003Z", "iopub.status.busy": "2025-03-25T03:44:55.629884Z", "iopub.status.idle": "2025-03-25T03:44:55.631963Z", "shell.execute_reply": "2025-03-25T03:44:55.631595Z" } }, "outputs": [], "source": [ "# These identifiers follow the Affymetrix probe ID format (e.g., '1007_PM_s_at', '1053_PM_at')\n", "# These are microarray probe identifiers from the Affymetrix platform, not standard human gene symbols\n", "# They need to be mapped to standard gene symbols for biological interpretation\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "8a77db31", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "79f419a2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:44:55.633298Z", "iopub.status.busy": "2025-03-25T03:44:55.633191Z", "iopub.status.idle": "2025-03-25T03:45:02.971579Z", "shell.execute_reply": "2025-03-25T03:45:02.971152Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['1007_PM_s_at', '1053_PM_at', '117_PM_at', '121_PM_at', '1255_PM_g_at'], 'GB_ACC': ['U48705', 'M87338', 'X51757', 'X69699', 'L36861'], 'SPOT_ID': [nan, nan, nan, nan, nan], 'Species Scientific Name': ['Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens'], 'Annotation Date': ['Aug 20, 2010', 'Aug 20, 2010', 'Aug 20, 2010', 'Aug 20, 2010', 'Aug 20, 2010'], 'Sequence Type': ['Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence'], 'Sequence Source': ['Affymetrix Proprietary Database', 'GenBank', 'Affymetrix Proprietary Database', 'GenBank', 'Affymetrix Proprietary Database'], 'Target Description': ['U48705 /FEATURE=mRNA /DEFINITION=HSU48705 Human receptor tyrosine kinase DDR gene, complete cds', 'M87338 /FEATURE= /DEFINITION=HUMA1SBU Human replication factor C, 40-kDa subunit (A1) mRNA, complete cds', \"X51757 /FEATURE=cds /DEFINITION=HSP70B Human heat-shock protein HSP70B' gene\", 'X69699 /FEATURE= /DEFINITION=HSPAX8A H.sapiens Pax8 mRNA', 'L36861 /FEATURE=expanded_cds /DEFINITION=HUMGCAPB Homo sapiens guanylate cyclase activating protein (GCAP) gene exons 1-4, complete cds'], 'Representative Public ID': ['U48705', 'M87338', 'X51757', 'X69699', 'L36861'], 'Gene Title': ['discoidin domain receptor tyrosine kinase 1', 'replication factor C (activator 1) 2, 40kDa', \"heat shock 70kDa protein 6 (HSP70B')\", 'paired box 8', 'guanylate cyclase activator 1A (retina)'], 'Gene Symbol': ['DDR1', 'RFC2', 'HSPA6', 'PAX8', 'GUCA1A'], 'ENTREZ_GENE_ID': ['780', '5982', '3310', '7849', '2978'], 'RefSeq Transcript ID': ['NM_001954 /// NM_013993 /// NM_013994', 'NM_002914 /// NM_181471', 'NM_002155', 'NM_003466 /// NM_013951 /// NM_013952 /// NM_013953 /// NM_013992', 'NM_000409'], 'Gene Ontology Biological Process': ['0001558 // regulation of cell growth // inferred from electronic annotation /// 0001952 // regulation of cell-matrix adhesion // inferred from electronic annotation /// 0006468 // protein amino acid phosphorylation // inferred from electronic annotation /// 0007155 // cell adhesion // inferred from electronic annotation /// 0007155 // cell adhesion // traceable author statement /// 0007169 // transmembrane receptor protein tyrosine kinase signaling pathway // inferred from electronic annotation /// 0007566 // embryo implantation // inferred from electronic annotation /// 0008285 // negative regulation of cell proliferation // inferred from electronic annotation /// 0018108 // peptidyl-tyrosine phosphorylation // inferred from electronic annotation /// 0031100 // organ regeneration // inferred from electronic annotation /// 0043583 // ear development // inferred from electronic annotation /// 0043588 // skin development // inferred from electronic annotation /// 0051789 // response to protein stimulus // inferred from electronic annotation /// 0060444 // branching involved in mammary gland duct morphogenesis // inferred from electronic annotation /// 0060749 // mammary gland alveolus development // inferred from electronic annotation', '0006260 // DNA replication // not recorded /// 0006260 // DNA replication // inferred from electronic annotation /// 0006297 // nucleotide-excision repair, DNA gap filling // not recorded /// 0015979 // photosynthesis // inferred from electronic annotation /// 0015995 // chlorophyll biosynthetic process // inferred from electronic annotation', '0006950 // response to stress // inferred from electronic annotation /// 0006986 // response to unfolded protein // traceable author statement', '0001656 // metanephros development // inferred from electronic annotation /// 0006350 // transcription // inferred from electronic annotation /// 0007275 // multicellular organismal development // inferred from electronic annotation /// 0009653 // anatomical structure morphogenesis // traceable author statement /// 0030154 // cell differentiation // inferred from electronic annotation /// 0030878 // thyroid gland development // inferred from electronic annotation /// 0045449 // regulation of transcription // inferred from electronic annotation /// 0045893 // positive regulation of transcription, DNA-dependent // inferred from sequence or structural similarity /// 0045893 // positive regulation of transcription, DNA-dependent // inferred from direct assay /// 0045944 // positive regulation of transcription from RNA polymerase II promoter // inferred from electronic annotation', '0007165 // signal transduction // non-traceable author statement /// 0007601 // visual perception // inferred from electronic annotation /// 0007601 // visual perception // traceable author statement /// 0007602 // phototransduction // inferred from electronic annotation /// 0031282 // regulation of guanylate cyclase activity // inferred from electronic annotation /// 0050896 // response to stimulus // inferred from electronic annotation'], 'Gene Ontology Cellular Component': ['0005576 // extracellular region // inferred from electronic annotation /// 0005886 // plasma membrane // inferred from electronic annotation /// 0005887 // integral to plasma membrane // traceable author statement /// 0016020 // membrane // inferred from electronic annotation /// 0016021 // integral to membrane // inferred from electronic annotation /// 0016323 // basolateral plasma membrane // inferred from electronic annotation', '0005634 // nucleus // inferred from electronic annotation /// 0005654 // nucleoplasm // not recorded /// 0005663 // DNA replication factor C complex // inferred from direct assay /// 0005663 // DNA replication factor C complex // inferred from electronic annotation', nan, '0005634 // nucleus // inferred from electronic annotation /// 0005654 // nucleoplasm // inferred from sequence or structural similarity /// 0005654 // nucleoplasm // inferred from electronic annotation', '0016020 // membrane // inferred from electronic annotation'], 'Gene Ontology Molecular Function': ['0000166 // nucleotide binding // inferred from electronic annotation /// 0004672 // protein kinase activity // inferred from electronic annotation /// 0004713 // protein tyrosine kinase activity // inferred from electronic annotation /// 0004714 // transmembrane receptor protein tyrosine kinase activity // inferred from electronic annotation /// 0004714 // transmembrane receptor protein tyrosine kinase activity // traceable author statement /// 0004872 // receptor activity // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0005515 // protein binding // inferred from electronic annotation /// 0005524 // ATP binding // inferred from electronic annotation /// 0016301 // kinase activity // inferred from electronic annotation /// 0016740 // transferase activity // inferred from electronic annotation', '0000166 // nucleotide binding // inferred from electronic annotation /// 0003677 // DNA binding // inferred from electronic annotation /// 0003689 // DNA clamp loader activity // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0005524 // ATP binding // inferred from electronic annotation /// 0005524 // ATP binding // traceable author statement /// 0016851 // magnesium chelatase activity // inferred from electronic annotation /// 0017111 // nucleoside-triphosphatase activity // inferred from electronic annotation', '0000166 // nucleotide binding // inferred from electronic annotation /// 0005524 // ATP binding // inferred from electronic annotation', '0003677 // DNA binding // inferred from direct assay /// 0003677 // DNA binding // inferred from electronic annotation /// 0003700 // transcription factor activity // traceable author statement /// 0004996 // thyroid-stimulating hormone receptor activity // traceable author statement /// 0005515 // protein binding // inferred from sequence or structural similarity /// 0005515 // protein binding // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0016563 // transcription activator activity // inferred from sequence or structural similarity /// 0016563 // transcription activator activity // inferred from direct assay /// 0016563 // transcription activator activity // inferred from electronic annotation /// 0043565 // sequence-specific DNA binding // inferred from electronic annotation', '0005509 // calcium ion binding // inferred from electronic annotation /// 0008048 // calcium sensitive guanylate cyclase activator activity // traceable author statement /// 0008048 // calcium sensitive guanylate cyclase activator activity // inferred from electronic annotation /// 0030249 // guanylate cyclase regulator activity // inferred from electronic annotation']}\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": "aec25930", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "421b85b1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:02.972887Z", "iopub.status.busy": "2025-03-25T03:45:02.972775Z", "iopub.status.idle": "2025-03-25T03:45:03.443942Z", "shell.execute_reply": "2025-03-25T03:45:03.443494Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First few rows of mapped gene expression data:\n", " GSM1381524 GSM1381525 GSM1381526 GSM1381527 GSM1381528 GSM1381529 \\\n", "Gene \n", "A1BG 5.7818 6.2652 5.9438 6.0062 6.2384 5.8118 \n", "A1CF 4.0327 4.0811 4.2793 4.3403 4.2245 3.9326 \n", "A2BP1 12.2527 11.7734 12.2891 11.7696 12.4713 11.7472 \n", "A2LD1 8.3018 9.2080 9.2638 8.4592 9.0925 8.5653 \n", "A2M 9.2125 9.2819 9.6747 9.4160 11.6454 10.0736 \n", "\n", " GSM1381530 GSM1381531 GSM1381532 GSM1381533 ... GSM1381626 \\\n", "Gene ... \n", "A1BG 5.7488 6.5247 5.8682 6.3062 ... 5.5508 \n", "A1CF 4.3102 4.7254 4.0183 4.0832 ... 4.0731 \n", "A2BP1 12.0019 13.4765 12.4701 12.3507 ... 12.2121 \n", "A2LD1 7.9601 9.2121 8.5095 8.7122 ... 8.6532 \n", "A2M 8.8847 9.4880 9.8342 10.0027 ... 11.1036 \n", "\n", " GSM1381627 GSM1381628 GSM1381629 GSM1381630 GSM1381631 GSM1381632 \\\n", "Gene \n", "A1BG 5.6774 6.3123 6.5896 5.8075 5.9969 6.0868 \n", "A1CF 4.1420 4.0413 4.2164 4.2150 4.0491 4.1326 \n", "A2BP1 11.9510 12.3870 12.3877 12.1209 12.2898 11.9056 \n", "A2LD1 7.9644 8.5882 8.3345 8.5646 8.3518 7.9960 \n", "A2M 9.1892 9.6430 9.9358 9.4084 9.6993 8.9235 \n", "\n", " GSM1381633 GSM1381634 GSM1381635 \n", "Gene \n", "A1BG 5.7961 6.0842 6.3289 \n", "A1CF 4.2087 4.3393 4.2935 \n", "A2BP1 11.9631 12.8061 12.1889 \n", "A2LD1 8.2720 8.0723 8.3977 \n", "A2M 9.2713 9.0454 9.1745 \n", "\n", "[5 rows x 112 columns]\n" ] } ], "source": [ "# 1. Identify which columns in the gene annotation dataframe correspond to gene identifiers and gene symbols\n", "# By examining the preview, 'ID' column contains probe IDs matching those in gene_data\n", "# 'Gene Symbol' column contains the corresponding gene symbols\n", "prob_col = 'ID'\n", "gene_col = 'Gene Symbol'\n", "\n", "# 2. Get a gene mapping dataframe by extracting these two columns\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col)\n", "\n", "# 3. Convert probe-level measurements to gene expression data\n", "# This function handles dividing probe expression when mapping to multiple genes\n", "# and sums up all probe contributions for each gene\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Print first few rows to verify the mapping was successful\n", "print(\"First few rows of mapped gene expression data:\")\n", "print(gene_data.head())\n" ] }, { "cell_type": "markdown", "id": "7dd7ee13", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "7f8ce0d5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:03.445657Z", "iopub.status.busy": "2025-03-25T03:45:03.445544Z", "iopub.status.idle": "2025-03-25T03:45:13.272469Z", "shell.execute_reply": "2025-03-25T03:45:13.271801Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data saved to ../../output/preprocess/Psoriatic_Arthritis/gene_data/GSE57383.csv\n", "Linked data shape before handling missing values: (112, 18625)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data shape after handling missing values: (55, 18625)\n", "For the feature 'Psoriatic_Arthritis', the least common label is '0.0' with 19 occurrences. This represents 34.55% of the dataset.\n", "The distribution of the feature 'Psoriatic_Arthritis' in this dataset is fine.\n", "\n", "Quartiles for 'Age':\n", " 25%: 39.0\n", " 50% (Median): 46.0\n", " 75%: 60.0\n", "Min: 23.0\n", "Max: 70.0\n", "The distribution of the feature 'Age' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '1.0' with 24 occurrences. This represents 43.64% of the dataset.\n", "The distribution of the feature 'Gender' in this dataset is fine.\n", "\n", "Data is usable. Saving to ../../output/preprocess/Psoriatic_Arthritis/GSE57383.csv\n" ] } ], "source": [ "# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "normalized_gene_data.to_csv(out_gene_data_file)\n", "print(f\"Gene data saved to {out_gene_data_file}\")\n", "\n", "# Re-extract clinical features since we need it for linking\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", "# 2. Link the clinical and genetic data with the 'geo_link_clinical_genetic_data' function from the library.\n", "linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)\n", "print(f\"Linked data shape before handling missing values: {linked_data.shape}\")\n", "\n", "# 3. Handle missing values in the linked data\n", "linked_data = handle_missing_values(linked_data, trait)\n", "print(f\"Linked data shape after handling missing values: {linked_data.shape}\")\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, trait)\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=\"Dataset contains gene expression from endothelial cells derived from circulating progenitors of RA patients\"\n", ")\n", "\n", "# 6. If the linked data is usable, save it as a CSV file to 'out_data_file'.\n", "if is_usable:\n", " print(f\"Data is usable. Saving to {out_data_file}\")\n", " unbiased_linked_data.to_csv(out_data_file)\n", "else:\n", " print(\"Data is not usable. Not saving linked data file.\")" ] } ], "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 }