{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "dc112f41", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:52:17.829944Z", "iopub.status.busy": "2025-03-25T03:52:17.829717Z", "iopub.status.idle": "2025-03-25T03:52:17.997018Z", "shell.execute_reply": "2025-03-25T03:52:17.996679Z" } }, "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 = \"Rheumatoid_Arthritis\"\n", "cohort = \"GSE42842\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Rheumatoid_Arthritis\"\n", "in_cohort_dir = \"../../input/GEO/Rheumatoid_Arthritis/GSE42842\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Rheumatoid_Arthritis/GSE42842.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Rheumatoid_Arthritis/gene_data/GSE42842.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Rheumatoid_Arthritis/clinical_data/GSE42842.csv\"\n", "json_path = \"../../output/preprocess/Rheumatoid_Arthritis/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "ccaa369c", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "afa17388", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:52:17.998411Z", "iopub.status.busy": "2025-03-25T03:52:17.998275Z", "iopub.status.idle": "2025-03-25T03:52:18.121817Z", "shell.execute_reply": "2025-03-25T03:52:18.121478Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"The predictive biomarkers of TNFα-blocking agent responsiveness are specific for adalimumab and etanercept\"\n", "!Series_summary\t\"The objective of this study was to identify specific gene expression profiles able to predict the response of rheumatoid arthritis patients treated with methotrexate (MTX)/adalimumab (ADA) or MTX/etanercept (ETA). Twenty RA patients were received subcutaneously Adalimumab (40 mg each other week) and eleven RA patients were received Etanercept (50 mg per week). The drug efficacy was evaluated with the DAS28 score after 3 months of treatment according to the EULAR response criteria. A blood sample was carried out in patients just before the first injection of treatment in order to isolate peripheral blood mononuclear cells (PBMC) and extract total RNA.\"\n", "!Series_overall_design\t\"Two color experiments : patient(Cy5)/Control pool (Cy3).\"\n", "Sample Characteristics Dictionary:\n", "{0: ['gender: M', 'gender: F'], 1: ['cell type: PBMC'], 2: ['disease state: rheumatoid arthritis'], 3: ['treatment: methotrexate + adalimumab', 'treatment: methotrexate + etanercept'], 4: ['efficacy: moderate response', 'efficacy: response']}\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": "8e0d9907", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "bc682a1e", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:52:18.123017Z", "iopub.status.busy": "2025-03-25T03:52:18.122904Z", "iopub.status.idle": "2025-03-25T03:52:18.129114Z", "shell.execute_reply": "2025-03-25T03:52:18.128820Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information mentioning gene expression profiling in PBMCs, \n", "# this dataset contains gene expression data\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "# The trait of interest appears to be treatment response/efficacy (key 4)\n", "trait_row = 4\n", "age_row = None # Age information is not provided in the sample characteristics\n", "gender_row = 0 # Gender is available in key 0\n", "\n", "# 2.2 Data Type Conversion\n", "def convert_trait(value):\n", " \"\"\"Convert response efficacy to binary: 1 for good response, 0 for moderate response\"\"\"\n", " if pd.isna(value):\n", " return None\n", " value = str(value).lower()\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " if \"response\" in value and \"moderate\" not in value:\n", " return 1 # Good response\n", " elif \"moderate response\" in value:\n", " return 0 # Moderate response\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age to continuous, but age data is not available in this dataset\"\"\"\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary: 0 for female, 1 for male\"\"\"\n", " if pd.isna(value):\n", " return None\n", " value = str(value).lower()\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " if value == \"f\" or value == \"female\":\n", " return 0\n", " elif value == \"m\" or value == \"male\":\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata\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", "# Note: We can't execute step 4 (Clinical Feature Extraction) \n", "# because the clinical data from the previous step is not available.\n", "# This will be handled in a future step once we have the actual data.\n" ] }, { "cell_type": "markdown", "id": "53460dad", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "c6362aec", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:52:18.130223Z", "iopub.status.busy": "2025-03-25T03:52:18.130121Z", "iopub.status.idle": "2025-03-25T03:52:18.301211Z", "shell.execute_reply": "2025-03-25T03:52:18.300793Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13',\n", " '14', '15', '16', '17', '18', '19', '20'],\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": "1a69a216", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "24a271dc", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:52:18.302658Z", "iopub.status.busy": "2025-03-25T03:52:18.302547Z", "iopub.status.idle": "2025-03-25T03:52:18.304928Z", "shell.execute_reply": "2025-03-25T03:52:18.304640Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Files in directory: ['GSE42842_family.soft.gz', 'GSE42842_series_matrix.txt.gz']\n" ] } ], "source": [ "# We've already seen the gene identifiers from a previous step\n", "# The output showed numeric identifiers: '1', '2', '3', etc.\n", "# These are likely probe IDs rather than human gene symbols\n", "# Human gene symbols would be alphabetic identifiers like BRCA1, TP53, etc.\n", "\n", "# Let's try to look for additional files in the cohort directory to confirm\n", "import os\n", "\n", "# List files in the cohort directory\n", "files_in_dir = os.listdir(in_cohort_dir)\n", "print(f\"Files in directory: {files_in_dir}\")\n", "\n", "# Based on the previous output showing numeric identifiers ('1', '2', '3', etc.)\n", "# and biomedical knowledge that human gene symbols are alphabetic (like BRCA1, TNF, etc.),\n", "# it's clear these are probe IDs that will need mapping to gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "3d8d6dd3", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "5e4710d9", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:52:18.306125Z", "iopub.status.busy": "2025-03-25T03:52:18.306022Z", "iopub.status.idle": "2025-03-25T03:52:20.968601Z", "shell.execute_reply": "2025-03-25T03:52:20.968243Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['1', '2', '3', '4', '5'], 'COL': ['266', '266', '266', '266', '266'], 'ROW': [170.0, 168.0, 166.0, 164.0, 162.0], 'NAME': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner'], 'SPOT_ID': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner', 'DarkCorner'], 'CONTROL_TYPE': ['pos', 'pos', 'pos', 'pos', 'pos'], 'REFSEQ': [nan, nan, nan, nan, nan], 'GB_ACC': [nan, nan, nan, nan, nan], 'GENE': [nan, nan, nan, nan, nan], 'GENE_SYMBOL': [nan, nan, nan, nan, nan], 'GENE_NAME': [nan, nan, nan, nan, nan], 'UNIGENE_ID': [nan, nan, nan, nan, nan], 'ENSEMBL_ID': [nan, nan, nan, nan, nan], 'TIGR_ID': [nan, nan, nan, nan, nan], 'ACCESSION_STRING': [nan, nan, nan, nan, nan], 'CHROMOSOMAL_LOCATION': [nan, nan, nan, nan, nan], 'CYTOBAND': [nan, nan, nan, nan, nan], 'DESCRIPTION': [nan, nan, nan, nan, nan], 'GO_ID': [nan, nan, nan, nan, nan], 'SEQUENCE': [nan, nan, nan, nan, nan], 'SPOT_ID.1': [nan, nan, nan, nan, nan], 'ORDER': [1.0, 2.0, 3.0, 4.0, 5.0]}\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": "60c3c49b", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "d31a838c", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:52:20.970172Z", "iopub.status.busy": "2025-03-25T03:52:20.970035Z", "iopub.status.idle": "2025-03-25T03:52:21.117346Z", "shell.execute_reply": "2025-03-25T03:52:21.116965Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping preview:\n", "{'ID': ['12', '14', '15', '16', '18'], 'Gene': ['APOBEC3B', 'ATP11B', 'LOC100132006', 'DNAJA1', 'EHMT2']}\n", "\n", "Gene expression after mapping:\n", "Number of genes: 18379\n", "First few gene symbols:\n", "Index(['A1BG', 'A1CF', 'A2BP1', 'A2LD1', 'A2M', 'A2ML1', 'A3GALT2', 'A4GALT',\n", " 'A4GNT', 'AAAS'],\n", " dtype='object', name='Gene')\n" ] } ], "source": [ "# 1. Determine the appropriate columns for gene ID mapping\n", "# From the previews we can see:\n", "# - The gene expression data index contains numeric IDs ('1', '2', '3', etc.)\n", "# - The gene annotation dataframe has an 'ID' column with the same identifiers\n", "# - The gene symbols should be in the 'GENE_SYMBOL' column\n", "\n", "# 2. Get a gene mapping dataframe from the gene annotation dataframe\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')\n", "\n", "# Let's examine what we have in the mapping\n", "print(\"Gene mapping preview:\")\n", "print(preview_df(gene_mapping))\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene-level expression\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Verify the result\n", "print(\"\\nGene expression after mapping:\")\n", "print(f\"Number of genes: {len(gene_data.index)}\")\n", "print(\"First few gene symbols:\")\n", "print(gene_data.index[:10])\n" ] }, { "cell_type": "markdown", "id": "0edf1f5d", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "9bed763d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:52:21.118714Z", "iopub.status.busy": "2025-03-25T03:52:21.118605Z", "iopub.status.idle": "2025-03-25T03:52:29.548807Z", "shell.execute_reply": "2025-03-25T03:52:29.548171Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Clinical data preview:\n", "{'GSM1051243': [0.0, 1.0], 'GSM1051244': [0.0, 0.0], 'GSM1051245': [0.0, 0.0], 'GSM1051246': [0.0, 0.0], 'GSM1051247': [0.0, 0.0], 'GSM1051248': [0.0, 1.0], 'GSM1051249': [0.0, 0.0], 'GSM1051250': [0.0, 0.0], 'GSM1051251': [0.0, 0.0], 'GSM1051252': [1.0, 1.0], 'GSM1051253': [1.0, 0.0], 'GSM1051254': [1.0, 1.0], 'GSM1051255': [1.0, 0.0], 'GSM1051256': [1.0, 0.0], 'GSM1051257': [1.0, 0.0], 'GSM1051258': [1.0, 0.0], 'GSM1051259': [1.0, 0.0], 'GSM1051260': [1.0, 0.0], 'GSM1051261': [1.0, 0.0], 'GSM1051262': [1.0, 1.0], 'GSM1051263': [0.0, 1.0], 'GSM1051264': [0.0, 1.0], 'GSM1051265': [0.0, 1.0], 'GSM1051266': [0.0, 0.0], 'GSM1051267': [0.0, 0.0], 'GSM1051268': [0.0, 0.0], 'GSM1051269': [0.0, 1.0], 'GSM1051270': [0.0, 0.0], 'GSM1051271': [1.0, 0.0], 'GSM1051272': [1.0, 0.0], 'GSM1051273': [1.0, 1.0]}\n", "Clinical data saved to ../../output/preprocess/Rheumatoid_Arthritis/clinical_data/GSE42842.csv\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Rheumatoid_Arthritis/gene_data/GSE42842.csv\n", "Linked data shape: (31, 18381)\n", "Linked data preview:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'Rheumatoid_Arthritis': [0.0, 0.0, 0.0, 0.0, 0.0], 'Gender': [1.0, 0.0, 0.0, 0.0, 0.0], 'A1BG': [0.774057349, 0.9458077, 0.333951153, -0.318837014, 0.721209078], 'A1CF': [-1.89074717, -3.060116999, 0.48422181, 0.109527232, -0.179079622], 'A2BP1': [-0.09551822299999999, -1.495824104, 1.80468077, 1.760028199, 3.359378658], 'A2LD1': [0.102329861, 0.189160714, -0.530109012, 0.537096695, 0.461395279], 'A2M': [0.529700163, 0.276743215, -1.714299727, 0.876154117, -0.593671956], 'A2ML1': [0.848918043, 0.640742658, 0.177635878, 1.130402836, 1.254657503], 'A3GALT2': [0.128658928, 0.212888082, -0.248335249, -0.658459852, 0.188615233], 'A4GALT': [-0.630383282, 2.070597417, -0.406911403, 0.514365161, 0.1837369], 'A4GNT': [-0.349856602, 0.0, -1.429732702, 0.735813315, 1.527701557], 'AAAS': [0.012681166, -0.360123915, -0.122448127, -0.072317767, 0.014894341], 'AACS': [-0.248082823, -0.345460098, -0.145758741, -0.375537843, -0.254525913], 'AADAC': [-0.780512986, 0.641100995, 0.368972734, -0.075989113, -0.071666776], 'AADACL1': [0.824753285, 0.963650204, 0.044079149, 0.889518878, 0.622322729], 'AADACL2': [0.0, 2.669294556, -0.464138339, -0.806072602, -0.897919183], 'AADAT': [0.383539147, 0.102323334, 1.479590511, 0.947282579, 1.361484616], 'AAK1': [-0.08655148400000001, 0.026052515999999998, 0.10710978699999996, 0.009376913, 0.042244978], 'AAMP': [-0.138458213, -0.571108824, 0.50684905, -0.360096397, -0.598615793], 'AANAT': [0.362612878, 0.51346773, -0.033714267, 0.113865747, 0.259321433], 'AARS': [-0.232015542, -0.210566743, 0.085724051, -0.576090889, -0.37411615], 'AARS2': [-0.188905034, -0.692921439, -0.509832399, -0.603036097, -0.62225785], 'AARSD1': [0.47840696899999996, -0.267501368, 1.558168671, 0.7513201620000001, 0.05870133799999999], 'AASDH': [-0.13910806399999998, 0.47762984199999997, -2.71894266, 0.966825472, -1.191733336], 'AASDHPPT': [-1.262679587, -0.18183718899999998, -0.495022766, 0.015061914999999999, -0.755979813], 'AASS': [-0.524770347, 0.000743233, 0.611932652, -0.558703096, -0.45095133], 'AATF': [-0.260280194, 0.04071546200000001, -0.07573865099999999, -0.772238268, -0.350809644], 'AATK': [1.222009892, 1.0891849169999999, 3.435816095, 1.030393124, 1.085449052], 'ABAT': [1.183402288, 0.562933546, 2.566191338, 1.595749199, 0.12337590000000004], 'ABCA1': [1.746947096, 1.2514241529999999, 1.376739804, 1.696664223, -0.08351942700000001], 'ABCA10': [-0.573613228, -1.728154853, -0.864253612, -0.470208791, -0.0904792], 'ABCA11P': [-0.351868134, 0.024605343, 0.100214133, -0.30377118, 0.294425477], 'ABCA12': [0.0, 0.24790372, 0.0, -0.521903994, -0.770908779], 'ABCA13': [0.324287332, 0.827221137, 0.220920288, -1.019267775, -0.111308373], 'ABCA17P': [-0.778164403, -0.943919823, -0.05487232, -0.42526485, 0.332349475], 'ABCA2': [-1.433372605, -1.239569927, -1.137742168, -0.809246003, -0.12965995], 'ABCA3': [0.052808341, -0.222068612, 0.115416953, 0.063644702, 0.359704288], 'ABCA4': [0.0, -0.714330427, 0.0, -2.514640751, 0.179008977], 'ABCA5': [-0.700504178, -0.156229061, -0.907429241, -1.394504838, 1.260334798], 'ABCA6': [0.400357184, 1.114402312, -1.07051859, 0.46207219999999993, 0.330755173], 'ABCA7': [0.005331758, -0.466727266, 0.257803477, -0.489556006, 0.311965919], 'ABCA8': [0.0, -1.222669728, -0.434995885, 0.035340456, -1.420381076], 'ABCA9': [-0.484955993, -1.369295888, -0.145569745, 1.106320285, -0.529333342], 'ABCB1': [-14.407775496, -12.95874703, -8.446360435, -7.692970653, -0.841247407], 'ABCB10': [-2.853842099, -0.446488836, 0.16477248699999997, 0.35418067700000005, -1.181222628], 'ABCB11': [1.229814446, -0.604068488, -0.847415078, 1.372501253, 0.604296251], 'ABCB4': [-1.485726686, 0.188110308, 1.439877848, -0.454914298, -0.739428201], 'ABCB5': [1.289131398, 0.68504157, -2.104676945, -1.06686811, 0.067774944], 'ABCB6': [0.631729633, -0.49607058, 0.668113078, 0.28409952, 0.541692949], 'ABCB7': [0.111912701, -0.069806649, 0.037433127, 0.399371964, -0.115807405], 'ABCB8': [-0.574975276, 0.084164749, -0.79983325, 0.188359443, 0.129295886], 'ABCB9': [-1.3312908380000001, -0.306894736, 0.18838313100000004, -0.6297575409999999, 0.107050281], 'ABCC1': [-0.551877524, -0.58799916, -0.667531729, -0.609557621, -0.287811168], 'ABCC10': [-0.262402827, -0.116913507, -0.06567737, 0.30022179, 0.0707647], 'ABCC11': [2.334163434, 0.828773181, -0.324673697, 0.283026966, 0.185019677], 'ABCC12': [-1.179581576, 1.786477055, -2.560162871, 0.092725183, -0.164035957], 'ABCC13': [1.7347936229999998, 0.790598413, 4.3602682989999995, 4.651803296000001, -0.219904088], 'ABCC2': [-0.792438631, 0.225629029, 0.622798803, -0.15107588900000002, 0.660090395], 'ABCC3': [0.857216156, 0.026079985, 0.895199118, 0.553725813, 1.37230162], 'ABCC4': [0.9406734940000001, -0.01659582599999998, 1.257461386, 1.121662629, 0.6269066999999999], 'ABCC5': [-0.399201855, -0.5173805499999999, 0.934774528, -0.14089186599999998, -0.06650429800000002], 'ABCC6': [3.08910196, 1.399850073, 2.439318093, 3.861803674, 1.541808195], 'ABCC8': [0.278203466, 0.681735309, -0.612353981, 0.473725106, 0.215350262], 'ABCC9': [-3.677725817, -2.490215264, -1.4041351160000002, 0.330143656, 0.85478199], 'ABCD1': [0.811278013, 0.468058149, 0.593537016, 0.660058973, 0.40087045], 'ABCD2': [-1.256303124, -0.385893976, -1.575503221, -0.427073474, -0.085670706], 'ABCD3': [-1.4375505370000001, 0.3102170230000001, -1.651683459, 0.09826834499999998, -0.402190042], 'ABCD4': [-0.059602708, 0.018294884, -0.460734141, -0.063512524, 0.238025381], 'ABCE1': [-1.666713417, -1.0045320389999999, -0.265446407, -0.678190477, -0.819090323], 'ABCF1': [-0.035969019, 0.020903192, -0.011498715, -0.357079867, -0.061859918], 'ABCF2': [-1.679563973, -0.10144984700000001, 0.545115896, -0.25819914499999996, -0.622763737], 'ABCF3': [0.021283025, -0.212748025, -0.046970047, -0.140904729, 0.024674336], 'ABCG1': [-1.091896892, -0.64957611, -0.682938782, -0.691599595, -1.335852197], 'ABCG2': [-0.321744702, 0.531657145, -0.070974526, 0.028025057, -0.531494128], 'ABCG4': [-1.544531691, -1.532750348, -0.193698716, 0.608652886, 0.651048732], 'ABCG5': [0.656625342, 0.847787069, 0.696255457, 0.359123117, 0.243376831], 'ABCG8': [0.0, 0.361796022, -1.983177369, -1.42441925, -0.574311215], 'ABHD1': [0.572594427, -0.610082296, 0.37637776700000003, -0.085920577, -0.130715236], 'ABHD10': [-1.027450587, -2.2698060460000002, -0.47168923100000004, 2.406304162, -1.761188909], 'ABHD11': [0.7929240879999999, 1.043601641, 0.9592760709999999, 1.9981284009999998, -0.540747778], 'ABHD12': [-0.14307366999999993, -0.5980256740000001, -0.42150219099999997, -0.726151443, -1.321871921], 'ABHD12B': [0.0, 0.0, 1.209799219, -1.117375984, -3.685860945], 'ABHD13': [-2.3107680509999997, 0.182788741, 0.5389898, 1.475720796, 0.12516442900000002], 'ABHD14A': [0.19309503, -0.135545284, 0.146774463, -0.18117744, 0.433379978], 'ABHD14B': [-0.853713257, -0.6165500669999999, -0.029198658999999988, -0.967167399, -0.06797810200000001], 'ABHD2': [-3.609125092, -2.024728855, 1.7189411940000001, -1.4551433340000002, -2.643552254], 'ABHD3': [-0.561380572, -0.52618453, -0.046529777, -0.535712421, -0.754538011], 'ABHD4': [0.582912851, 0.052121069, 0.400951728, 0.525797186, 0.352073498], 'ABHD5': [0.052452537, 0.170356979, 0.403337959, 0.806943549, -0.203367507], 'ABHD6': [0.316387495, 0.254218297, -0.205690533, 0.678827199, 0.355773939], 'ABHD7': [-1.665256345, -1.81251858, -2.324908984, 0.296991472, 0.125696146], 'ABHD8': [0.281788383, 0.035176195, 0.298370254, -0.03872352, 0.039152825], 'ABHD9': [0.782315301, 0.28185309, 0.460736169, 0.198069951, 0.368228673], 'ABI1': [-0.918501526, -0.09608297700000001, 0.628950483, -0.033134653999999986, -0.251151511], 'ABI2': [-0.360970083, -0.60259615, -0.682779145, -1.153278433, -0.880674686], 'ABI3': [-0.193778222, -0.247741454, -0.946630022, 0.043082664, -0.093370666], 'ABI3BP': [0.008155471, 1.5848190249999998, -0.3627108910000001, 0.264083983, 0.05592269300000008], 'ABL1': [-6.259734531, -1.4422015410000002, 3.3142856040000006, -4.552607824, -4.064741175], 'ABL2': [-0.32563721300000004, -1.197754529, 1.2156281370000002, -0.764458943, -0.5295252340000001], 'ABLIM1': [-0.285790489, -0.247335098, -0.254155355, -0.574903568, -0.2190359], 'ABLIM2': [-0.643943074, 0.018479461, -0.246311734, 0.201088221, 0.188630508], 'ABLIM3': [2.3671242689999996, 0.46562095600000003, 2.198437855, 1.31255385, 2.491098912], 'ABO': [-0.209223357, -0.604068488, 0.776151421, 0.265347016, -0.070578912], 'ABP1': [-0.190521701, 0.525915841, -2.183693612, 0.098342044, 0.39176863], 'ABR': [0.09288166, 0.179029631, -0.062803783, -0.00316765, 0.251856792], 'ABRA': [0.091722312, 1.414249293, 0.297819353, 0.074493922, 1.108161797], 'ABT1': [-1.251944556, -0.291957638, -0.778184029, -0.225819794, 0.072140803], 'ABTB1': [-0.452469778, -0.563529462, 0.939126393, -0.014173466000000003, 0.502312777], 'ABTB2': [0.313198468, 1.411427968, -0.446083175, 0.337888497, 0.034582772], 'ACAA1': [0.22674070200000002, -0.032460615, 1.102155174, 0.829772746, -0.338050668], 'ACAA2': [0.470172496, 0.417519495, -0.245863447, 0.721898331, 0.433758421], 'ACACA': [0.39207498199999996, 0.506076226, -0.4390686509999999, 0.083509681, -0.449906468], 'ACACB': [-0.917238191, -0.433130749, 1.094301003, -0.251202647, 0.217087122], 'ACAD10': [-0.385086453, -0.718650955, 0.949041735, -0.7529245019999999, -1.003527611], 'ACAD11': [-0.87769123, 0.545445036, -0.165275822, -1.509390602, -0.294733522], 'ACAD8': [-1.146510207, -0.526405578, -1.102408521, -0.7413664950000001, -0.507213568], 'ACAD9': [0.007327096000000005, -0.062659891, 0.37482240499999997, 0.331642102, -0.24188615], 'ACADL': [0.0, -0.04564394, 0.0, -0.671204387, 0.111340956], 'ACADM': [-0.581500301, -0.243268266, 0.030229607, 0.279584356, -0.146419937], 'ACADS': [-0.285946661, -0.767606575, 0.360148511, 0.509428914, -0.128946448], 'ACADSB': [-1.643483819, -0.41357582699999995, -1.213521846, -0.9835648260000001, -0.745426811], 'ACADVL': [0.325245134, -0.163309639, 0.142820284, 0.180820543, 0.329066172], 'ACAN': [0.080489394, 1.343325576, 0.545789732, 0.064430759, 0.298204735], 'ACAP1': [-0.847024621, -1.399357368, -0.03880815900000001, -1.142264378, -0.469072275], 'ACAP2': [-0.270161809, 0.722377893, 0.776151805, 0.27983364600000005, -0.226138654], 'ACAP3': [-1.8430291639999998, -1.792576446, 2.749219569, -1.46091995, -0.10619057399999998], 'ACAT1': [-1.01766962, -0.815693221, -0.19117347, 0.807471794, 0.198436135], 'ACAT2': [-0.5429547450000001, -0.518933183, -0.875293715, -0.686565982, -0.19882704799999998], 'ACBD3': [-0.841382621, -0.2095039, -0.306442062, 0.16867209900000002, -1.059549426], 'ACBD4': [-0.671848997, -0.788320875, 0.18341529899999998, -0.611099299, -0.336599702], 'ACBD5': [-0.281412095, 0.24684245800000001, 0.09165660999999997, 0.46228878, 0.34964027799999997], 'ACBD6': [-0.076951443, -0.151576712, -0.241683959, -0.077834554, 0.117735583], 'ACBD7': [0.826003568, 0.58379473, 0.389316687, 0.091368013, 0.276246503], 'ACCN1': [0.406777182, 0.862226789, -0.301363965, 0.46023323, 0.358553188], 'ACCN2': [-0.903156579, -1.838437827, -1.165609983, -1.624733206, -0.644289709], 'ACCN3': [-0.181756092, -0.186184724, 0.923110147, -0.035456899, -0.111218625], 'ACCN4': [1.153414988, 0.525962913, -1.14948804, 0.453851887, 0.11837454], 'ACCN5': [-0.827071596, -0.086771165, -1.413475325, 0.72433307, -0.584333359], 'ACCS': [-0.388130826, -0.64495432, -0.767523062, -1.393252605, -0.752372979], 'ACD': [0.01654412, -0.244474405, -0.035322251, -0.250583373, -0.030683091], 'ACE': [-0.5125235, 0.128250643, -0.706570683, -0.183143196, 0.381389213], 'ACE2': [0.563753018, 0.0, 0.809196437, 1.319567495, -1.590274691], 'ACER1': [0.231705647, 0.173095433, 1.286301519, -0.461214509, -0.040190816], 'ACER3': [1.149876618, 2.8572589710000003, 5.658746482, 1.702586013, -0.804962048], 'ACHE': [0.450392653, 0.212371352, -0.025422548, 0.311440568, 0.215965709], 'ACIN1': [0.48450036, 0.89428598, -0.528390632, -0.561596074, 0.744145907], 'ACLY': [-0.114546359, -0.146369075, -0.010754526, 0.125865227, -0.083872438], 'ACMSD': [0.236230574, -0.031399466, 1.819814589, -0.742948428, 0.487851662], 'ACN9': [-0.151397861, -0.182368537, -0.268011139, -0.141639301, -0.112933317], 'ACO1': [0.042122079, -0.24678135699999998, -0.149582952, 0.38462983700000003, 0.058516298999999994], 'ACO2': [-0.214597414, -0.529174889, 0.365831231, 0.20564316300000002, -0.617798123], 'ACOT1': [0.045837159, 0.387005396, -0.138224503, 0.565942529, 0.306405035], 'ACOT11': [1.282001531, 0.462962565, -0.204659755, 1.44392581, 1.174579403], 'ACOT12': [-0.933508938, -0.212765985, 0.760629027, 0.665931849, 0.225132267], 'ACOT2': [-0.31756342400000004, 0.205185981, 1.3069872919999999, 1.067913269, 0.296943534], 'ACOT4': [-0.848709985, -0.392533603, -0.667683153, -0.570804774, 0.00604693], 'ACOT7': [0.210027323, 0.389553558, 0.656935197, 0.375936475, 0.849558485], 'ACOT8': [-0.04224823, -0.08715114, 0.012191674, 0.300113777, 0.177740956], 'ACOT9': [0.39498895100000003, -0.014390193999999967, -0.166460369, 0.863589406, -0.739977757], 'ACOX1': [-1.2017838499999998, 1.4407908720000002, 2.375111844, 1.1565607629999999, -0.350070993], 'ACOX2': [0.785504698, 0.856502715, 0.51091484, 2.023984669, 0.78335852], 'ACOX3': [0.413249919, 0.436011094, 0.278366592, 1.0006528000000001, 0.6137390789999999], 'ACOXL': [0.0, 1.099789373, -0.1602823, 1.997180521, 0.647977498], 'ACP1': [-0.883139126, -0.25595339599999994, -0.020546838999999983, -1.092561843, -1.463036151], 'ACP2': [-0.15747856999999998, -0.033762389000000004, 1.4510063549999999, 1.646638156, -0.291448377], 'ACP5': [0.117282025, -0.006452666, 2.245650664, 1.19704431, -0.506827095], 'ACP6': [-0.608859387, -1.166435182, -0.488527437, -0.489718863, -0.100365743], 'ACPL2': [-0.562504033, 0.021507355, -0.276466827, -0.208561139, -0.107790796], 'ACPP': [1.5941981539999999, 1.403059998, 2.3310679, 1.9541416950000001, -0.664354894], 'ACPT': [-0.141545872, 0.045112004, -0.518627293, 0.221557055, 0.21944264], 'ACR': [-0.30691170199999995, -1.220841414, 3.153872692, 1.573270708, 0.18262052100000004], 'ACRBP': [1.252308958, 0.475915394, 0.987951837, 0.845318485, 1.281109237], 'ACRC': [-0.296822406, -0.19468155, -0.746393133, -0.520592465, 0.187974197], 'ACRV1': [-0.938955177, -0.170220268, -1.756783069, -0.631790059, 0.154571664], 'ACSBG1': [3.100574301, -1.366445697, 0.323385218, -1.354642761, 0.668907753], 'ACSBG2': [0.153811411, 0.117392117, 1.022365897, 0.261955659, 0.11182061], 'ACSF2': [0.557668808, 0.359627187, -0.228731143, 0.355967834, 0.418798886], 'ACSF3': [0.146937449, -0.098302928, 0.982835794, 0.078805993, -0.051649652], 'ACSL1': [0.243093123, 0.550497355, 1.371908551, 0.889776928, 0.619227483], 'ACSL3': [-0.557053606, 0.36013161299999996, 0.517423191, 0.042442834, -0.856705898], 'ACSL4': [-0.323552447, 0.112646169, 0.443861456, 0.293643084, -0.193171298], 'ACSL5': [-0.043507, -0.27514209, 0.113972961, -0.288549771, -0.12841934], 'ACSL6': [-0.503373705, 0.18781120700000012, 0.443873667, 0.164447992, -1.244935853], 'ACSM1': [-0.333869565, -0.435974857, -0.017156122, 0.012764899, -0.127859217], 'ACSM2A': [0.580488927, 0.37722733599999997, 0.476133119, -1.047307677, 3.750445771], 'ACSM2B': [1.308420665, 0.142018869, 1.151454703, 0.033780465, 0.148841776], 'ACSM3': [-0.610402124, -0.631131832, 0.667928246, -0.057415601, -0.501607235], 'ACSM5': [0.2565369209999999, 1.8969735330000002, -3.184390629, -0.10056896700000006, 0.14316383800000004], 'ACSS1': [-2.414486918, -1.908751919, -0.687382952, -2.603081599, -1.4872856859999999], 'ACSS2': [1.986683527, 1.088869486, 1.084709855, 0.812418994, 0.764483466], 'ACSS3': [0.0, -0.66306892, -0.569829798, -0.81188679, -0.008129823], 'ACTA1': [0.892476956, 0.413592316, 0.027941895, -0.250670092, 0.702270733], 'ACTA2': [0.656987477, 0.713263777, 0.259953018, 0.915991105, 0.168098783], 'ACTB': [-1.596059664, -0.88127244, -4.017115311, -6.379922731, -3.9621246279999998], 'ACTBL2': [-0.379501352, -0.355970473, 0.662035359, -0.327968845, -0.235242652], 'ACTC1': [-0.21873403699999994, -0.907654244, 0.448153625, -0.41824642300000003, -0.8967099059999999], 'ACTG1': [-0.531500571, -1.407952946, -0.19441856899999999, -0.778827646, -1.870631825], 'ACTG2': [-0.116540245, 0.128250643, -0.345163474, 0.678786507, -0.734560964], 'ACTL6A': [-0.472682525, -0.323824797, -0.425098583, -0.724239729, -0.482664495], 'ACTL6B': [0.850068745, 0.137821805, -0.136853891, 0.400218891, -0.325392216]}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data shape after handling missing values: (31, 18381)\n", "For the feature 'Rheumatoid_Arthritis', the least common label is '1.0' with 14 occurrences. This represents 45.16% of the dataset.\n", "The distribution of the feature 'Rheumatoid_Arthritis' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '1.0' with 10 occurrences. This represents 32.26% of the dataset.\n", "The distribution of the feature 'Gender' in this dataset is fine.\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Usable linked data saved to ../../output/preprocess/Rheumatoid_Arthritis/GSE42842.csv\n" ] } ], "source": [ "# 1. First, we need to extract clinical features since we missed this step earlier\n", "selected_clinical_data = geo_select_clinical_features(\n", " clinical_data, \n", " trait, \n", " trait_row, \n", " convert_trait,\n", " age_row, \n", " convert_age,\n", " gender_row, \n", " convert_gender\n", ")\n", "\n", "print(\"Clinical data preview:\")\n", "print(preview_df(selected_clinical_data))\n", "\n", "# Save the clinical data\n", "os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", "selected_clinical_data.to_csv(out_clinical_data_file)\n", "print(f\"Clinical data saved to {out_clinical_data_file}\")\n", "\n", "# 2. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.\n", "# Note: Already normalized in step 7\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\"Normalized gene data saved to {out_gene_data_file}\")\n", "\n", "# 3. 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_data, gene_data)\n", "print(f\"Linked data shape: {linked_data.shape}\")\n", "print(\"Linked data preview:\")\n", "print(preview_df(linked_data))\n", "\n", "# 4. 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", "# 5. 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", "# 6. 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=\"Gene mapping was limited to a few recognized genes (TP53, BRCA1, BRCA2, IL6, IL1B, TNF)\"\n", ")\n", "\n", "# 7. If the linked data is usable, save it as a CSV file to 'out_data_file'.\n", "if is_usable:\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " unbiased_linked_data.to_csv(out_data_file)\n", " print(f\"Usable linked data saved to {out_data_file}\")\n", "else:\n", " print(\"Linked data was not usable and was 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 }