{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "b052ffda", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:56.371068Z", "iopub.status.busy": "2025-03-25T03:45:56.370659Z", "iopub.status.idle": "2025-03-25T03:45:56.537034Z", "shell.execute_reply": "2025-03-25T03:45:56.536591Z" } }, "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 = \"GSE61281\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Psoriatic_Arthritis\"\n", "in_cohort_dir = \"../../input/GEO/Psoriatic_Arthritis/GSE61281\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Psoriatic_Arthritis/GSE61281.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Psoriatic_Arthritis/gene_data/GSE61281.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Psoriatic_Arthritis/clinical_data/GSE61281.csv\"\n", "json_path = \"../../output/preprocess/Psoriatic_Arthritis/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "7c49de08", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "a46d06ad", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:56.538472Z", "iopub.status.busy": "2025-03-25T03:45:56.538319Z", "iopub.status.idle": "2025-03-25T03:45:56.706466Z", "shell.execute_reply": "2025-03-25T03:45:56.706094Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Human Whole Blood: Psoriatic Arthritis [PsA] vs. Cutaneous Psoriasis Without Arthritis [PsC] vs. Controls\"\n", "!Series_summary\t\"Transcriptional profiling of human whole blood comparing PsA, PsC, and unaffected controls\"\n", "!Series_overall_design\t\"Three condition experiment: PsA, PsC, unaffected controls. Biological replicates: 20 PsA, 20 PsC, 12 controls\"\n", "Sample Characteristics Dictionary:\n", "{0: ['tissue: whole blood'], 1: ['condition: Psoriatic arthritis', 'condition: Cutaneous psoriasis without arthritis', 'condition: Unaffected control'], 2: ['gender: Female', 'gender: Male'], 3: ['batch: 4', 'batch: 3', 'batch: 2', 'batch: 1'], 4: ['psoriasis duration: 48.0', 'psoriasis duration: 37.0', 'psoriasis duration: 22.0', 'psoriasis duration: 13.0', 'psoriasis duration: 33.0', 'psoriasis duration: 18.0', 'psoriasis duration: 38.0', 'psoriasis duration: 24.0', 'psoriasis duration: 19.0', 'psoriasis duration: 28.0', 'psoriasis duration: 20.0', 'psoriasis duration: 14.0', 'psoriasis duration: 4.0', 'psoriasis duration: 15.0', 'psoriasis duration: 7.0', 'psoriasis duration: 16.0', 'psoriasis duration: 31.0', 'psoriasis duration: 27.0', 'psoriasis duration: 16.9158110882957', 'psoriasis duration: 17.7488021902806', 'psoriasis duration: 2.8104038329911', 'psoriasis duration: 0.770020533880903', 'psoriasis duration: 8.89390828199863', 'psoriasis duration: 12.6235455167693', 'psoriasis duration: 18.009582477755', 'psoriasis duration: 44.2600958247776', 'psoriasis duration: 3.8507871321013', 'psoriasis duration: 39.807665982204', 'psoriasis duration: 13.2375085557837', 'psoriasis duration: 30.2026009582478'], 5: ['age of psoriasis onset: 19', 'age of psoriasis onset: 11', 'age of psoriasis onset: 23', 'age of psoriasis onset: 31', 'age of psoriasis onset: 26', 'age of psoriasis onset: 29', 'age of psoriasis onset: 7', 'age of psoriasis onset: 30', 'age of psoriasis onset: 17', 'age of psoriasis onset: 13', 'age of psoriasis onset: 69', 'age of psoriasis onset: 32', 'age of psoriasis onset: 24', 'age of psoriasis onset: 41', 'age of psoriasis onset: 25', 'age of psoriasis onset: 18', 'age of psoriasis onset: 21', 'age of psoriasis onset: 39', 'age of psoriasis onset: 38', 'age of psoriasis onset: 37', 'age of psoriasis onset: 20', 'age of psoriasis onset: 8', 'age of psoriasis onset: 47', 'age of psoriasis onset: 33', 'age of psoriasis onset: 16', 'age of psoriasis onset: 15', 'age of psoriasis onset: n/a']}\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": "747d8f14", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "913de3f7", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:56.707804Z", "iopub.status.busy": "2025-03-25T03:45:56.707691Z", "iopub.status.idle": "2025-03-25T03:45:56.718891Z", "shell.execute_reply": "2025-03-25T03:45:56.718495Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of selected clinical features:\n", "{'GSM1501512': [1.0, 0.0], 'GSM1501513': [1.0, 0.0], 'GSM1501514': [1.0, 1.0], 'GSM1501515': [1.0, 1.0], 'GSM1501516': [1.0, 1.0], 'GSM1501517': [1.0, 1.0], 'GSM1501518': [1.0, 1.0], 'GSM1501519': [1.0, 1.0], 'GSM1501520': [1.0, 1.0], 'GSM1501521': [1.0, 1.0], 'GSM1501522': [1.0, 0.0], 'GSM1501523': [1.0, 0.0], 'GSM1501524': [1.0, 0.0], 'GSM1501525': [1.0, 0.0], 'GSM1501526': [1.0, 0.0], 'GSM1501527': [1.0, 0.0], 'GSM1501528': [1.0, 0.0], 'GSM1501529': [1.0, 1.0], 'GSM1501530': [1.0, 0.0], 'GSM1501531': [1.0, 0.0], 'GSM1501532': [0.0, 1.0], 'GSM1501533': [0.0, 1.0], 'GSM1501534': [0.0, 1.0], 'GSM1501535': [0.0, 1.0], 'GSM1501536': [0.0, 0.0], 'GSM1501537': [0.0, 1.0], 'GSM1501538': [0.0, 1.0], 'GSM1501539': [0.0, 1.0], 'GSM1501540': [0.0, 1.0], 'GSM1501541': [0.0, 1.0], 'GSM1501542': [0.0, 0.0], 'GSM1501543': [0.0, 1.0], 'GSM1501544': [0.0, 0.0], 'GSM1501545': [0.0, 0.0], 'GSM1501546': [0.0, 0.0], 'GSM1501547': [0.0, 0.0], 'GSM1501548': [0.0, 0.0], 'GSM1501549': [0.0, 0.0], 'GSM1501550': [0.0, 0.0], 'GSM1501551': [0.0, 0.0], 'GSM1501552': [0.0, 0.0], 'GSM1501553': [0.0, 1.0], 'GSM1501554': [0.0, 1.0], 'GSM1501555': [0.0, 1.0], 'GSM1501556': [0.0, 0.0], 'GSM1501557': [0.0, 0.0], 'GSM1501558': [0.0, 1.0], 'GSM1501559': [0.0, 0.0], 'GSM1501560': [0.0, 0.0], 'GSM1501561': [0.0, 1.0], 'GSM1501562': [0.0, 0.0], 'GSM1501563': [0.0, 0.0]}\n", "Clinical data saved to ../../output/preprocess/Psoriatic_Arthritis/clinical_data/GSE61281.csv\n" ] } ], "source": [ "import pandas as pd\n", "from typing import Optional, Dict, Any, Callable\n", "import os\n", "import json\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the background information, this seems to be a transcriptional profiling study\n", "# which likely contains gene expression data\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "\n", "# 2.1 Data Availability\n", "\n", "# For trait (Psoriatic Arthritis)\n", "# Key 1 contains \"condition\" which includes our trait of interest\n", "trait_row = 1 \n", "\n", "# For gender\n", "# Key 2 contains gender information\n", "gender_row = 2\n", "\n", "# For age\n", "# There is no direct age information, only \"age of psoriasis onset\" and \"psoriasis duration\"\n", "# We could calculate age, but it's not directly available\n", "age_row = None \n", "\n", "# 2.2 Data Type Conversion Functions\n", "\n", "def convert_trait(value: str) -> Optional[int]:\n", " \"\"\"Convert trait values to binary format.\"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after colon\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " # Check for Psoriatic arthritis vs other conditions\n", " if \"psoriatic arthritis\" in value.lower():\n", " return 1 # Has Psoriatic Arthritis\n", " elif \"cutaneous psoriasis without arthritis\" in value.lower() or \"unaffected control\" in value.lower():\n", " return 0 # Does not have Psoriatic Arthritis\n", " else:\n", " return None\n", "\n", "def convert_gender(value: str) -> Optional[int]:\n", " \"\"\"Convert gender values to binary format (0=female, 1=male).\"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after colon\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " if \"female\" in value.lower():\n", " return 0\n", " elif \"male\" in value.lower():\n", " return 1\n", " else:\n", " return None\n", "\n", "# Age conversion function defined but won't be used as age_row is None\n", "def convert_age(value: str) -> Optional[float]:\n", " \"\"\"Convert age values to float.\"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after colon\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", "# 3. Save Metadata\n", "# Determine trait data availability\n", "is_trait_available = trait_row is not None\n", "\n", "# Initial filtering on usability\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available\n", ")\n", "\n", "# 4. Clinical Feature Extraction\n", "if trait_row is not None:\n", " # Using clinical_data that should be available from previous steps\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", " gender_row=gender_row,\n", " convert_gender=convert_gender,\n", " age_row=age_row,\n", " convert_age=convert_age\n", " )\n", " \n", " # Preview the dataframe\n", " preview = preview_df(selected_clinical_df)\n", " print(\"Preview of selected clinical features:\")\n", " print(preview)\n", " \n", " # Save 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)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "fac20a6e", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "98e9ac20", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:56.720115Z", "iopub.status.busy": "2025-03-25T03:45:56.720005Z", "iopub.status.idle": "2025-03-25T03:45:57.004726Z", "shell.execute_reply": "2025-03-25T03:45:57.004266Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['(+)E1A_r60_1', '(+)E1A_r60_3', '(+)E1A_r60_a104', '(+)E1A_r60_a107',\n", " '(+)E1A_r60_a135', '(+)E1A_r60_a20', '(+)E1A_r60_a22', '(+)E1A_r60_a97',\n", " '(+)E1A_r60_n11', '(+)E1A_r60_n9', '(+)eQC-39', '(+)eQC-40',\n", " '(+)eQC-41', '(+)eQC-42', '(-)3xSLv1', 'A_23_P100001', 'A_23_P100011',\n", " 'A_23_P100022', 'A_23_P100056', 'A_23_P100074'],\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": "d8087673", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "c23e1f03", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:57.006199Z", "iopub.status.busy": "2025-03-25T03:45:57.006071Z", "iopub.status.idle": "2025-03-25T03:45:57.008299Z", "shell.execute_reply": "2025-03-25T03:45:57.007908Z" } }, "outputs": [], "source": [ "# Observing the gene identifiers in the gene expression data\n", "\n", "# The identifiers seen in the data (like A_23_P100001) appear to be Agilent microarray probe IDs\n", "# rather than human gene symbols. These are proprietary identifiers used on Agilent microarray platforms\n", "# and need to be mapped to standard gene symbols for proper analysis.\n", "\n", "# These probe IDs (starting with A_23_P) are a clear indication that we're looking at Agilent array data\n", "# and will require mapping to standard gene symbols.\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "9f1cb6de", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "144b5b72", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:45:57.009679Z", "iopub.status.busy": "2025-03-25T03:45:57.009562Z", "iopub.status.idle": "2025-03-25T03:46:00.988800Z", "shell.execute_reply": "2025-03-25T03:46:00.988251Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['A_23_P100001', 'A_23_P100011', 'A_23_P100022', 'A_23_P100056', 'A_23_P100074'], 'SPOT_ID': ['A_23_P100001', 'A_23_P100011', 'A_23_P100022', 'A_23_P100056', 'A_23_P100074'], 'CONTROL_TYPE': ['FALSE', 'FALSE', 'FALSE', 'FALSE', 'FALSE'], 'REFSEQ': ['NM_207446', 'NM_005829', 'NM_014848', 'NM_194272', 'NM_020371'], 'GB_ACC': ['NM_207446', 'NM_005829', 'NM_014848', 'NM_194272', 'NM_020371'], 'GENE': [400451.0, 10239.0, 9899.0, 348093.0, 57099.0], 'GENE_SYMBOL': ['FAM174B', 'AP3S2', 'SV2B', 'RBPMS2', 'AVEN'], 'GENE_NAME': ['family with sequence similarity 174, member B', 'adaptor-related protein complex 3, sigma 2 subunit', 'synaptic vesicle glycoprotein 2B', 'RNA binding protein with multiple splicing 2', 'apoptosis, caspase activation inhibitor'], 'UNIGENE_ID': ['Hs.27373', 'Hs.632161', 'Hs.21754', 'Hs.436518', 'Hs.555966'], 'ENSEMBL_ID': ['ENST00000557398', nan, 'ENST00000557410', 'ENST00000300069', 'ENST00000306730'], 'TIGR_ID': [nan, nan, nan, nan, nan], 'ACCESSION_STRING': ['ref|NM_207446|ens|ENST00000557398|ens|ENST00000553393|ens|ENST00000327355', 'ref|NM_005829|ref|NM_001199058|ref|NR_023361|ref|NR_037582', 'ref|NM_014848|ref|NM_001167580|ens|ENST00000557410|ens|ENST00000330276', 'ref|NM_194272|ens|ENST00000300069|gb|AK127873|gb|AK124123', 'ref|NM_020371|ens|ENST00000306730|gb|AF283508|gb|BC010488'], 'CHROMOSOMAL_LOCATION': ['chr15:93160848-93160789', 'chr15:90378743-90378684', 'chr15:91838329-91838388', 'chr15:65032375-65032316', 'chr15:34158739-34158680'], 'CYTOBAND': ['hs|15q26.1', 'hs|15q26.1', 'hs|15q26.1', 'hs|15q22.31', 'hs|15q14'], 'DESCRIPTION': ['Homo sapiens family with sequence similarity 174, member B (FAM174B), mRNA [NM_207446]', 'Homo sapiens adaptor-related protein complex 3, sigma 2 subunit (AP3S2), transcript variant 1, mRNA [NM_005829]', 'Homo sapiens synaptic vesicle glycoprotein 2B (SV2B), transcript variant 1, mRNA [NM_014848]', 'Homo sapiens RNA binding protein with multiple splicing 2 (RBPMS2), mRNA [NM_194272]', 'Homo sapiens apoptosis, caspase activation inhibitor (AVEN), mRNA [NM_020371]'], 'GO_ID': ['GO:0016020(membrane)|GO:0016021(integral to membrane)', 'GO:0005794(Golgi apparatus)|GO:0006886(intracellular protein transport)|GO:0008565(protein transporter activity)|GO:0016020(membrane)|GO:0016192(vesicle-mediated transport)|GO:0030117(membrane coat)|GO:0030659(cytoplasmic vesicle membrane)|GO:0031410(cytoplasmic vesicle)', 'GO:0001669(acrosomal vesicle)|GO:0006836(neurotransmitter transport)|GO:0016020(membrane)|GO:0016021(integral to membrane)|GO:0022857(transmembrane transporter activity)|GO:0030054(cell junction)|GO:0030672(synaptic vesicle membrane)|GO:0031410(cytoplasmic vesicle)|GO:0045202(synapse)', 'GO:0000166(nucleotide binding)|GO:0003676(nucleic acid binding)', 'GO:0005515(protein binding)|GO:0005622(intracellular)|GO:0005624(membrane fraction)|GO:0006915(apoptosis)|GO:0006916(anti-apoptosis)|GO:0012505(endomembrane system)|GO:0016020(membrane)'], 'SEQUENCE': ['ATCTCATGGAAAAGCTGGATTCCTCTGCCTTACGCAGAAACACCCGGGCTCCATCTGCCA', 'TCAAGTATTGGCCTGACATAGAGTCCTTAAGACAAGCAAAGACAAGCAAGGCAAGCACGT', 'ATGTCGGCTGTGGAGGGTTAAAGGGATGAGGCTTTCCTTTGTTTAGCAAATCTGTTCACA', 'CCCTGTCAGATAAGTTTAATGTTTAGTTTGAGGCATGAAGAAGAAAAGGGTTTCCATTCT', 'GACCAGCCAGTTTACAAGCATGTCTCAAGCTAGTGTGTTCCATTATGCTCACAGCAGTAA']}\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": "abff591f", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "6b942422", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:46:00.990681Z", "iopub.status.busy": "2025-03-25T03:46:00.990550Z", "iopub.status.idle": "2025-03-25T03:46:01.188756Z", "shell.execute_reply": "2025-03-25T03:46:01.188208Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of genes after mapping: 18488\n", "First 10 gene symbols:\n", "Index(['A1BG', 'A1BG-AS1', 'A1CF', 'A2LD1', 'A2M', 'A2ML1', 'A4GALT', 'A4GNT',\n", " 'AAAS', 'AACS'],\n", " dtype='object', name='Gene')\n" ] } ], "source": [ "# 1. Determine which columns in gene_annotation contain the gene identifiers and gene symbols\n", "# From the preview, it's clear we need 'ID' and 'GENE_SYMBOL'\n", "probe_col = 'ID'\n", "gene_symbol_col = 'GENE_SYMBOL'\n", "\n", "# 2. Get a gene mapping dataframe by extracting the appropriate columns\n", "gene_mapping = get_gene_mapping(gene_annotation, probe_col, gene_symbol_col)\n", "\n", "# 3. Apply the gene mapping to convert probe-level measurements to gene expression data\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Print information about the converted gene expression data\n", "print(f\"Number of genes after mapping: {len(gene_data)}\")\n", "print(\"First 10 gene symbols:\")\n", "print(gene_data.index[:10])\n" ] }, { "cell_type": "markdown", "id": "e9c134ce", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "22bb3d59", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:46:01.190462Z", "iopub.status.busy": "2025-03-25T03:46:01.190330Z", "iopub.status.idle": "2025-03-25T03:46:10.700627Z", "shell.execute_reply": "2025-03-25T03:46:10.700080Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data saved to ../../output/preprocess/Psoriatic_Arthritis/gene_data/GSE61281.csv\n", "Linked data shape before handling missing values: (52, 18490)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data shape after handling missing values: (52, 18490)\n", "For the feature 'Psoriatic_Arthritis', the least common label is '1.0' with 20 occurrences. This represents 38.46% of the dataset.\n", "The distribution of the feature 'Psoriatic_Arthritis' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '1.0' with 24 occurrences. This represents 46.15% 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/GSE61281.csv\n" ] } ], "source": [ "# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.\n", "# Note: We already normalized the gene data in the previous step\n", "normalized_gene_data = gene_data.copy()\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 }