{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "cc6a9ff9", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:32.538513Z", "iopub.status.busy": "2025-03-25T03:45:32.538228Z", "iopub.status.idle": "2025-03-25T03:45:32.708620Z", "shell.execute_reply": "2025-03-25T03:45:32.708220Z" } }, "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 = \"GSE57405\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Psoriatic_Arthritis\"\n", "in_cohort_dir = \"../../input/GEO/Psoriatic_Arthritis/GSE57405\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Psoriatic_Arthritis/GSE57405.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Psoriatic_Arthritis/gene_data/GSE57405.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Psoriatic_Arthritis/clinical_data/GSE57405.csv\"\n", "json_path = \"../../output/preprocess/Psoriatic_Arthritis/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "ed300aae", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "3cceafd0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:32.710137Z", "iopub.status.busy": "2025-03-25T03:45:32.709950Z", "iopub.status.idle": "2025-03-25T03:45:32.940086Z", "shell.execute_reply": "2025-03-25T03:45:32.939711Z" } }, "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: ['Sex: M', 'Sex: F'], 1: ['age: 54', 'age: 40', 'age: 64', 'age: 23', 'age: 60', 'age: 32', 'age: 46', 'age: 24', 'age: 62', 'age: 42', 'age: 36', 'age: 44', 'age: 56', 'age: 47', 'age: 50', 'age: 51', 'age: 66', 'age: 28', 'age: 58', 'age: 45', 'age: 19', 'age: 59', 'age: 57', 'age: 53', 'age: 35', 'age: 61', 'age: 39', 'age: 55', 'age: 38', 'age: 52'], 2: ['cell type: primary cell'], 3: ['cell subtype: CD14-'], 4: ['disease status: normal', 'disease status: diseased'], 5: ['disease: Healthy Control', 'disease: Rheumatoid Arthritis', 'disease: Psoriasis', 'disease: Psoriatic Arthritis'], 6: ['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": "ae1c387c", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "afce6678", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:32.941302Z", "iopub.status.busy": "2025-03-25T03:45:32.941181Z", "iopub.status.idle": "2025-03-25T03:45:32.957804Z", "shell.execute_reply": "2025-03-25T03:45:32.957474Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of extracted clinical features:\n", "{'GSM1382105': [0.0, 54.0, 1.0], 'GSM1382106': [0.0, 40.0, 0.0], 'GSM1382107': [0.0, 64.0, 1.0], 'GSM1382108': [0.0, 23.0, 1.0], 'GSM1382109': [0.0, 60.0, 0.0], 'GSM1382110': [0.0, 32.0, 0.0], 'GSM1382111': [0.0, 46.0, 1.0], 'GSM1382112': [0.0, 24.0, 0.0], 'GSM1382113': [0.0, 23.0, 0.0], 'GSM1382114': [0.0, 62.0, 1.0], 'GSM1382115': [0.0, 42.0, 0.0], 'GSM1382116': [0.0, 36.0, 0.0], 'GSM1382117': [0.0, 36.0, 0.0], 'GSM1382118': [0.0, 40.0, 0.0], 'GSM1382119': [0.0, 44.0, 0.0], 'GSM1382120': [0.0, 23.0, 1.0], 'GSM1382121': [0.0, 56.0, 0.0], 'GSM1382122': [0.0, 46.0, 0.0], 'GSM1382123': [0.0, 47.0, 0.0], 'GSM1382124': [0.0, 50.0, 0.0], 'GSM1382125': [0.0, 51.0, 0.0], 'GSM1382126': [0.0, 62.0, 0.0], 'GSM1382127': [0.0, 51.0, 0.0], 'GSM1382128': [0.0, 46.0, 1.0], 'GSM1382129': [0.0, 66.0, 0.0], 'GSM1382130': [0.0, 28.0, 0.0], 'GSM1382131': [0.0, 58.0, 0.0], 'GSM1382132': [0.0, 45.0, 0.0], 'GSM1382133': [0.0, 66.0, 0.0], 'GSM1382134': [0.0, 51.0, 0.0], 'GSM1382135': [0.0, 46.0, 1.0], 'GSM1382136': [0.0, 50.0, 0.0], 'GSM1382137': [0.0, 28.0, 0.0], 'GSM1382138': [0.0, 45.0, 0.0], 'GSM1382139': [0.0, 58.0, 0.0], 'GSM1382140': [0.0, 62.0, 0.0], 'GSM1382141': [0.0, 51.0, 0.0], 'GSM1382142': [0.0, 46.0, 1.0], 'GSM1382143': [0.0, 51.0, 1.0], 'GSM1382144': [0.0, 51.0, 0.0], 'GSM1382145': [0.0, 45.0, 0.0], 'GSM1382146': [0.0, 58.0, 0.0], 'GSM1382147': [0.0, 28.0, 0.0], 'GSM1382148': [0.0, 66.0, 0.0], 'GSM1382149': [0.0, 62.0, 0.0], 'GSM1382150': [0.0, 50.0, 0.0], 'GSM1382151': [0.0, 46.0, 1.0], 'GSM1382152': [0.0, 19.0, 0.0], 'GSM1382153': [0.0, 59.0, 0.0], 'GSM1382154': [0.0, 44.0, 0.0], 'GSM1382155': [0.0, 57.0, 1.0], 'GSM1382156': [0.0, 53.0, 1.0], 'GSM1382157': [0.0, 24.0, 0.0], 'GSM1382158': [0.0, 28.0, 0.0], 'GSM1382159': [0.0, 35.0, 0.0], 'GSM1382160': [0.0, 61.0, 1.0], 'GSM1382161': [0.0, 61.0, 1.0], 'GSM1382162': [0.0, 44.0, 0.0], 'GSM1382163': [0.0, 35.0, 0.0], 'GSM1382164': [0.0, 57.0, 1.0], 'GSM1382165': [0.0, 59.0, 0.0], 'GSM1382166': [0.0, 19.0, 0.0], 'GSM1382167': [0.0, 28.0, 0.0], 'GSM1382168': [0.0, 53.0, 1.0], 'GSM1382169': [0.0, 24.0, 0.0], 'GSM1382170': [0.0, 46.0, 1.0], 'GSM1382171': [0.0, 53.0, 1.0], 'GSM1382172': [0.0, 24.0, 0.0], 'GSM1382173': [0.0, 57.0, 1.0], 'GSM1382174': [0.0, 46.0, 1.0], 'GSM1382175': [0.0, 61.0, 1.0], 'GSM1382176': [0.0, 59.0, 0.0], 'GSM1382177': [0.0, 44.0, 0.0], 'GSM1382178': [0.0, 35.0, 0.0], 'GSM1382179': [0.0, 19.0, 0.0], 'GSM1382180': [0.0, 28.0, 0.0], 'GSM1382181': [1.0, 39.0, 1.0], 'GSM1382182': [1.0, 55.0, 1.0], 'GSM1382183': [1.0, 38.0, 0.0], 'GSM1382184': [1.0, 60.0, 0.0], 'GSM1382185': [1.0, 52.0, 0.0], 'GSM1382186': [1.0, 44.0, 1.0], 'GSM1382187': [1.0, 67.0, 1.0], 'GSM1382188': [1.0, 68.0, 0.0], 'GSM1382189': [1.0, 39.0, 0.0], 'GSM1382190': [1.0, 58.0, 0.0], 'GSM1382191': [1.0, 70.0, 1.0], 'GSM1382192': [1.0, 31.0, 1.0], 'GSM1382193': [1.0, 39.0, 1.0], 'GSM1382194': [1.0, 31.0, 1.0], 'GSM1382195': [1.0, 58.0, 0.0], 'GSM1382196': [1.0, 67.0, 1.0], 'GSM1382197': [1.0, 39.0, 0.0], 'GSM1382198': [1.0, 55.0, 1.0], 'GSM1382199': [1.0, 38.0, 0.0], 'GSM1382200': [1.0, 68.0, 0.0], 'GSM1382201': [1.0, 60.0, 0.0], 'GSM1382202': [1.0, 52.0, 0.0], 'GSM1382203': [1.0, 44.0, 1.0], 'GSM1382204': [1.0, 70.0, 1.0], 'GSM1382205': [1.0, 60.0, 0.0], 'GSM1382206': [1.0, 55.0, 1.0], 'GSM1382207': [1.0, 52.0, 0.0], 'GSM1382208': [1.0, 67.0, 1.0], 'GSM1382209': [1.0, 68.0, 0.0], 'GSM1382210': [1.0, 38.0, 0.0], 'GSM1382211': [1.0, 70.0, 1.0], 'GSM1382212': [1.0, 44.0, 1.0], 'GSM1382213': [1.0, 31.0, 1.0], 'GSM1382214': [1.0, 58.0, 0.0], 'GSM1382215': [1.0, 39.0, 1.0]}\n", "Clinical data saved to ../../output/preprocess/Psoriatic_Arthritis/clinical_data/GSE57405.csv\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset contains gene expression data from CD14+ and CD14- cells\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "\n", "# For trait (Psoriatic Arthritis):\n", "# The trait information is available at key 5 where \"disease\" is recorded\n", "trait_row = 5\n", "\n", "# For age:\n", "# Age information is available at key 1\n", "age_row = 1\n", "\n", "# For gender:\n", "# Gender information is available at key 0 as \"Sex\"\n", "gender_row = 0\n", "\n", "# 2.2 Data Type Conversion Functions\n", "\n", "def convert_trait(value):\n", " \"\"\"Convert disease status to binary, where 1=Psoriatic Arthritis, 0=Other\"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " # Convert to binary based on psoriatic arthritis status\n", " if value.lower() == \"psoriatic arthritis\":\n", " return 1\n", " else:\n", " return 0\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age to continuous numeric value\"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " try:\n", " return float(value)\n", " except (ValueError, TypeError):\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary, where 0=Female, 1=Male\"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \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", " else:\n", " return None\n", "\n", "# 3. Save Metadata for Initial Filtering\n", "# Determine if trait data is available\n", "is_trait_available = trait_row is not None\n", "\n", "# Validate and save cohort information\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 (only if trait_row is not None)\n", "if trait_row is not None:\n", " try:\n", " # Access the clinical_data variable from previous step\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 extracted clinical features\n", " preview = preview_df(selected_clinical_df)\n", " print(\"Preview of extracted clinical features:\")\n", " print(preview)\n", " \n", " # Save the 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, index=False)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n", " except Exception as e:\n", " print(f\"Error in clinical data extraction: {e}\")\n" ] }, { "cell_type": "markdown", "id": "571d5b61", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "32ac394c", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:32.959056Z", "iopub.status.busy": "2025-03-25T03:45:32.958934Z", "iopub.status.idle": "2025-03-25T03:45:33.385023Z", "shell.execute_reply": "2025-03-25T03:45:33.384639Z" } }, "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": "08ab9ea9", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "92982b89", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:33.386811Z", "iopub.status.busy": "2025-03-25T03:45:33.386683Z", "iopub.status.idle": "2025-03-25T03:45:33.388719Z", "shell.execute_reply": "2025-03-25T03:45:33.388395Z" } }, "outputs": [], "source": [ "# Examining the gene identifiers in the gene expression data\n", "\n", "# These identifiers appear to be Affymetrix probe IDs (e.g., '1007_PM_s_at', '1053_PM_at')\n", "# rather than standard human gene symbols (which would look like BRCA1, TP53, etc.)\n", "# The format with \"_PM_\" and suffixes like \"_at\", \"_s_at\" are characteristic of Affymetrix arrays\n", "# These probe IDs will need to be mapped to standard gene symbols for analysis\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "b7c8a4dc", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "f8974676", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:33.390284Z", "iopub.status.busy": "2025-03-25T03:45:33.390170Z", "iopub.status.idle": "2025-03-25T03:45:41.024346Z", "shell.execute_reply": "2025-03-25T03:45:41.023945Z" } }, "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": "fb67dd82", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "2658df55", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:41.026120Z", "iopub.status.busy": "2025-03-25T03:45:41.025981Z", "iopub.status.idle": "2025-03-25T03:45:41.487770Z", "shell.execute_reply": "2025-03-25T03:45:41.487389Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping preview (first 5 rows):\n", " ID Gene\n", "0 1007_PM_s_at DDR1\n", "1 1053_PM_at RFC2\n", "2 117_PM_at HSPA6\n", "3 121_PM_at PAX8\n", "4 1255_PM_g_at GUCA1A\n", "\n", "Converted gene expression data:\n", "Shape: (18989, 111)\n", "First 10 gene symbols: ['A1BG', 'A1CF', 'A2BP1', 'A2LD1', 'A2M', 'A2ML1', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS']\n" ] } ], "source": [ "# 1. Based on observation of the data, we need to map from 'ID' (probe identifiers) to 'Gene Symbol'\n", "# The ID column in the gene annotation matches the index of the gene expression data\n", "\n", "# 2. Get gene mapping dataframe\n", "mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')\n", "\n", "# Print the first few rows of the mapping dataframe to verify\n", "print(\"Gene mapping preview (first 5 rows):\")\n", "print(mapping_df.head())\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene expression data\n", "gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)\n", "\n", "# Print the first 10 gene symbols and their data dimensions\n", "print(\"\\nConverted gene expression data:\")\n", "print(f\"Shape: {gene_data.shape}\")\n", "print(f\"First 10 gene symbols: {list(gene_data.index[:10])}\")\n" ] }, { "cell_type": "markdown", "id": "673a3851", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "5844b865", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:41.489627Z", "iopub.status.busy": "2025-03-25T03:45:41.489462Z", "iopub.status.idle": "2025-03-25T03:45:55.327064Z", "shell.execute_reply": "2025-03-25T03:45:55.326412Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data saved to ../../output/preprocess/Psoriatic_Arthritis/gene_data/GSE57405.csv\n", "Linked data shape before handling missing values: (111, 18625)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data shape after handling missing values: (111, 18625)\n", "For the feature 'Psoriatic_Arthritis', the least common label is '1.0' with 35 occurrences. This represents 31.53% of the dataset.\n", "The distribution of the feature 'Psoriatic_Arthritis' in this dataset is fine.\n", "\n", "Quartiles for 'Age':\n", " 25%: 38.5\n", " 50% (Median): 50.0\n", " 75%: 58.0\n", "Min: 19.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 40 occurrences. This represents 36.04% 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/GSE57405.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 }