{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8cc11670", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:45.851338Z", "iopub.status.busy": "2025-03-25T03:50:45.851216Z", "iopub.status.idle": "2025-03-25T03:50:46.015220Z", "shell.execute_reply": "2025-03-25T03:50:46.014758Z" } }, "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 = \"GSE140161\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Rheumatoid_Arthritis\"\n", "in_cohort_dir = \"../../input/GEO/Rheumatoid_Arthritis/GSE140161\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Rheumatoid_Arthritis/GSE140161.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Rheumatoid_Arthritis/gene_data/GSE140161.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Rheumatoid_Arthritis/clinical_data/GSE140161.csv\"\n", "json_path = \"../../output/preprocess/Rheumatoid_Arthritis/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "eab9246b", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "aab45389", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:46.016693Z", "iopub.status.busy": "2025-03-25T03:50:46.016539Z", "iopub.status.idle": "2025-03-25T03:50:46.220689Z", "shell.execute_reply": "2025-03-25T03:50:46.220284Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Systems biology demonstrates the predominant role of circulating interferon-alpha in primary Sjögren's syndrome and a genetic association with the class II HLA DQ locus\"\n", "!Series_summary\t\"Primary Sjögren’s syndrome (pSS) is the second most frequent systemic autoimmune disease, affecting 0.1% of the general population. No specific immunomodulatory drug has demonstrated efficacy for this disease, and no biomarker is available to identify patients at risk of developing systemic complications. To characterize the molecular and clinical variability across pSS patients, we integrated transcriptomic, proteomic, cellular and genetic data with clinical phenotypes in a cohort of 351 pSS patients. Unbiased global transcriptomic analysis revealed an IFN gene signature as the strongest driver of transcriptomic variability. The resulting stratification was replicated in three independent cohorts. As transcriptomic analysis did not discriminate between type I and II interferons, we applied digital ELISA to find that the IFN transcriptomic signature was driven by circulating IFNɑ protein levels. This cytokine, detectable in 75% of patients, was significantly associated with clinical and immunological features of disease activity at enrollment, and with increased frequency of systemic complications during the 5-year follow-up. Genetic analysis revealed a significant association between IFNɑ protein levels and an MHC-II HLA-DQ locus and anti-SSA antibody. Additional cellular analysis revealed that the polymorphism acts through upregulation of HLA II molecules on conventional DCs. Our unbiased analysis thus identified the predominance of IFNα as driver of pSS variability, and revealed an association with HLA gene polymorphisms.\"\n", "!Series_overall_design\t\"Whole blood transcriptome from 351 primary Sjögren’s syndrome patients was studied using Affymetrix chip. Resulting data were used to study the biological heterogeneity among patients and to link it to clinical heterogeneity.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['tissue: Whole blood'], 1: ['Sex: female', 'Sex: male'], 2: ['antissa status: Positive', 'antissa status: Negative'], 3: ['antissb status: Negative', 'antissb status: Positive'], 4: ['disease state: Sjögren’s syndrome']}\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": "202826c2", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "7618e4d1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:46.222236Z", "iopub.status.busy": "2025-03-25T03:50:46.222089Z", "iopub.status.idle": "2025-03-25T03:50:46.229381Z", "shell.execute_reply": "2025-03-25T03:50:46.228997Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "import pandas as pd\n", "import numpy as np\n", "import json\n", "from typing import Optional, Callable, Dict, Any\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset appears to contain gene expression data from Affymetrix chip\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "\n", "# For trait: All patients have \"Sjögren's syndrome\", which is not the trait of interest (RA)\n", "trait_row = None # The trait we're looking for (Rheumatoid_Arthritis) is not available\n", "\n", "# For gender: Found in row 1\n", "gender_row = 1\n", "\n", "# For age: Not available in the sample characteristics\n", "age_row = None \n", "\n", "# 2.2 Data Type Conversion\n", "\n", "def convert_trait(value: str) -> Optional[int]:\n", " # We don't need this function as trait data is not available\n", " # But we'll define it for completeness\n", " if value is None:\n", " return None\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " if \"Sjögren's syndrome\" in value:\n", " return 1 # This would be 1 if we were studying Sjögren's syndrome\n", " return None\n", "\n", "def convert_gender(value: str) -> Optional[int]:\n", " if value is None:\n", " return None\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip().lower()\n", " if 'female' in value:\n", " return 0\n", " elif 'male' in value:\n", " return 1\n", " return None\n", "\n", "def convert_age(value: str) -> Optional[float]:\n", " # We don't need this function as age data is not available\n", " # But we'll define it for completeness\n", " if value is None:\n", " return None\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " try:\n", " return float(value)\n", " except (ValueError, TypeError):\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Perform initial filtering on the usability of the dataset\n", "is_trait_available = trait_row is not None\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available\n", ")\n", "\n", "# 4. Clinical Feature Extraction\n", "# Skip this step as trait_row is None\n" ] }, { "cell_type": "markdown", "id": "cb0e8801", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "2ec89307", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:46.230769Z", "iopub.status.busy": "2025-03-25T03:50:46.230656Z", "iopub.status.idle": "2025-03-25T03:50:46.739823Z", "shell.execute_reply": "2025-03-25T03:50:46.739177Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['23064070', '23064071', '23064072', '23064073', '23064074', '23064075',\n", " '23064076', '23064077', '23064078', '23064079', '23064080', '23064081',\n", " '23064083', '23064084', '23064085', '23064086', '23064087', '23064088',\n", " '23064089', '23064090'],\n", " dtype='object', name='ID')\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/media/techt/DATA/GenoAgent/tools/preprocess.py:149: DtypeWarning: Columns (0) have mixed types. Specify dtype option on import or set low_memory=False.\n", " genetic_data = pd.read_csv(file_path, compression='gzip', skiprows=skip_rows, comment='!', delimiter='\\t',\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": "dfa466b5", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "03830b1b", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:46.741694Z", "iopub.status.busy": "2025-03-25T03:50:46.741550Z", "iopub.status.idle": "2025-03-25T03:50:46.743979Z", "shell.execute_reply": "2025-03-25T03:50:46.743529Z" } }, "outputs": [], "source": [ "# Looking at the indices of the gene expression data\n", "# These appear to be numeric identifiers (23064070, 23064071, etc.), not standard human gene symbols\n", "# Standard human gene symbols typically look like BRCA1, TNF, IL6, etc.\n", "# These numeric identifiers are likely probe IDs or some other platform-specific identifiers\n", "# that need to be mapped to human gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "684ec9c8", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "229fd165", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:46.745646Z", "iopub.status.busy": "2025-03-25T03:50:46.745533Z", "iopub.status.idle": "2025-03-25T03:50:57.940921Z", "shell.execute_reply": "2025-03-25T03:50:57.940243Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['TC0100006437.hg.1', 'TC0100006476.hg.1', 'TC0100006479.hg.1', 'TC0100006480.hg.1', 'TC0100006483.hg.1'], 'probeset_id': ['TC0100006437.hg.1', 'TC0100006476.hg.1', 'TC0100006479.hg.1', 'TC0100006480.hg.1', 'TC0100006483.hg.1'], 'seqname': ['chr1', 'chr1', 'chr1', 'chr1', 'chr1'], 'strand': ['+', '+', '+', '+', '+'], 'start': ['69091', '924880', '960587', '966497', '1001138'], 'stop': ['70008', '944581', '965719', '975865', '1014541'], 'total_probes': [10.0, 10.0, 10.0, 10.0, 10.0], 'category': ['main', 'main', 'main', 'main', 'main'], 'SPOT_ID': ['Coding', 'Multiple_Complex', 'Multiple_Complex', 'Multiple_Complex', 'Multiple_Complex'], 'SPOT_ID.1': ['NM_001005484 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000335137 // ENSEMBL // olfactory receptor, family 4, subfamily F, member 5 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000003223 // Havana transcript // olfactory receptor, family 4, subfamily F, member 5[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aal.1 // UCSC Genes // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS30547.1 // ccdsGene // olfactory receptor, family 4, subfamily F, member 5 [Source:HGNC Symbol;Acc:HGNC:14825] // chr1 // 100 // 100 // 0 // --- // 0', 'NM_152486 // RefSeq // Homo sapiens sterile alpha motif domain containing 11 (SAMD11), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000341065 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000342066 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000420190 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000437963 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000455979 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000464948 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000466827 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000474461 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000478729 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:processed_transcript] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000616016 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000616125 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000617307 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618181 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618323 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618779 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000620200 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000622503 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC024295 // GenBank // Homo sapiens sterile alpha motif domain containing 11, mRNA (cDNA clone MGC:39333 IMAGE:3354502), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// BC033213 // GenBank // Homo sapiens sterile alpha motif domain containing 11, mRNA (cDNA clone MGC:45873 IMAGE:5014368), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097860 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097862 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097863 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097865 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:processed_transcript] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097866 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097867 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097868 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000276866 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000316521 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS2.2 // ccdsGene // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009185 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009186 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009187 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009188 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009189 // circbase // Salzman2013 ALT_DONOR, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009190 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009191 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009192 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009193 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009194 // circbase // Salzman2013 ANNOTATED, CDS, coding, OVCODE, OVERLAPTX, OVEXON, UTR3 best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009195 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001abw.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pjt.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pju.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkg.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkh.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkk.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkm.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pko.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axs.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axt.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axu.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axv.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axw.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axx.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axy.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axz.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057aya.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000212 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000212 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000213 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000213 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_198317 // RefSeq // Homo sapiens kelch-like family member 17 (KLHL17), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000338591 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000463212 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000466300 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:nonsense_mediated_decay] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000481067 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000622660 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097875 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097877 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097878 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:nonsense_mediated_decay] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097931 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// BC166618 // GenBank // Synthetic construct Homo sapiens clone IMAGE:100066344, MGC:195481 kelch-like 17 (Drosophila) (KLHL17) mRNA, encodes complete protein. // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS30550.1 // ccdsGene // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009209 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_198317 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aca.3 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acb.2 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayg.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayh.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayi.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayj.1 // UCSC Genes // N/A // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000617073 // ENSEMBL // ncrna:novel chromosome:GRCh38:1:965110:965166:1 gene:ENSG00000277294 gene_biotype:miRNA transcript_biotype:miRNA // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000216 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000216 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_001160184 // RefSeq // Homo sapiens pleckstrin homology domain containing, family N member 1 (PLEKHN1), transcript variant 2, mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// NM_032129 // RefSeq // Homo sapiens pleckstrin homology domain containing, family N member 1 (PLEKHN1), transcript variant 1, mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379407 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379409 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379410 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000480267 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000491024 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC101386 // GenBank // Homo sapiens pleckstrin homology domain containing, family N member 1, mRNA (cDNA clone MGC:120613 IMAGE:40026400), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// BC101387 // GenBank // Homo sapiens pleckstrin homology domain containing, family N member 1, mRNA (cDNA clone MGC:120616 IMAGE:40026404), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097940 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097941 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097942 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000473255 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000473256 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS4.1 // ccdsGene // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS53256.1 // ccdsGene // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// PLEKHN1.aAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 84069 // chr1 // 100 // 100 // 0 // --- // 0 /// PLEKHN1.bAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 84069, RefSeq ID(s) NM_032129 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acd.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001ace.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acf.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayk.1 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayl.1 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000217 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000217 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_005101 // RefSeq // Homo sapiens ISG15 ubiquitin-like modifier (ISG15), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379389 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000624652 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000624697 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC009507 // GenBank // Homo sapiens ISG15 ubiquitin-like modifier, mRNA (cDNA clone MGC:3945 IMAGE:3545944), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097989 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000479384 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000479385 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS6.1 // ccdsGene // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009211 // circbase // Salzman2013 ANNOTATED, CDS, coding, OVCODE, OVEXON, UTR3 best transcript NM_005101 // chr1 // 100 // 100 // 0 // --- // 0 /// ISG15.bAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 9636 // chr1 // 100 // 100 // 0 // --- // 0 /// ISG15.cAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 9636 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acj.5 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayq.1 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayr.1 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 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": "4efd3f21", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "87561486", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:50:57.942827Z", "iopub.status.busy": "2025-03-25T03:50:57.942699Z", "iopub.status.idle": "2025-03-25T03:51:10.143283Z", "shell.execute_reply": "2025-03-25T03:51:10.142930Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First few gene expression indices:\n", "Index(['23064070', '23064071', '23064072', '23064073', '23064074'], dtype='object', name='ID')\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene mapping preview:\n", " ID Gene\n", "0 TC0100006437.hg.1 NM_001005484 // RefSeq // Homo sapiens olfacto...\n", "1 TC0100006476.hg.1 NM_152486 // RefSeq // Homo sapiens sterile al...\n", "2 TC0100006479.hg.1 NM_198317 // RefSeq // Homo sapiens kelch-like...\n", "3 TC0100006480.hg.1 NM_001160184 // RefSeq // Homo sapiens pleckst...\n", "4 TC0100006483.hg.1 NM_005101 // RefSeq // Homo sapiens ISG15 ubiq...\n", "\n", "Number of probes in mapping: 27189\n", "\n", "Applying gene mapping...\n", "Number of expression data indices found in mapping: 27189 out of 27189\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene expression data preview:\n", "(19975, 351)\n", " GSM4155114 GSM4155115 GSM4155116 GSM4155117 GSM4155118 \\\n", "Gene \n", "A1BG 0.422857 0.378571 0.370714 0.392143 0.367857 \n", "A1CF 0.158182 0.156364 0.167273 0.148636 0.152273 \n", "A2M 0.327647 0.332353 0.310588 0.358235 0.351176 \n", "A2ML1 0.209444 0.217222 0.194444 0.185000 0.200000 \n", "A3GALT2 1.032000 0.878000 0.938000 1.006000 0.916000 \n", "\n", " GSM4155119 GSM4155120 GSM4155121 GSM4155122 GSM4155123 ... \\\n", "Gene ... \n", "A1BG 0.392143 0.395714 0.374286 0.387857 0.380714 ... \n", "A1CF 0.146818 0.152727 0.158636 0.164091 0.155455 ... \n", "A2M 0.298235 0.339412 0.362353 0.360588 0.344706 ... \n", "A2ML1 0.185000 0.190556 0.203889 0.196667 0.188333 ... \n", "A3GALT2 0.780000 0.890000 0.860000 0.866000 0.840000 ... \n", "\n", " GSM4155455 GSM4155456 GSM4155457 GSM4155458 GSM4155459 \\\n", "Gene \n", "A1BG 0.390714 0.358571 0.367143 0.379286 0.405000 \n", "A1CF 0.164545 0.151818 0.172273 0.151818 0.166364 \n", "A2M 0.324706 0.311176 0.284706 0.310588 0.292353 \n", "A2ML1 0.187222 0.201111 0.196111 0.184444 0.199444 \n", "A3GALT2 0.842000 0.906000 0.954000 0.878000 0.960000 \n", "\n", " GSM4155460 GSM4155461 GSM4155462 GSM4155463 GSM4155464 \n", "Gene \n", "A1BG 0.397143 0.360714 0.380000 0.385000 0.375000 \n", "A1CF 0.165000 0.170000 0.169545 0.150909 0.158636 \n", "A2M 0.308235 0.287059 0.320000 0.285882 0.324706 \n", "A2ML1 0.186667 0.182778 0.195556 0.170000 0.198333 \n", "A3GALT2 0.894000 0.890000 0.900000 0.908000 0.956000 \n", "\n", "[5 rows x 351 columns]\n" ] } ], "source": [ "# Looking at the gene expression data indices and gene annotation columns\n", "# The gene expression data has indices like '23064070', '23064071', etc.\n", "# We need to find the matching column in the gene annotation dataframe\n", "\n", "# In the annotation dataframe, 'ID' appears to be a probe identifier format (like 'TC0100006437.hg.1')\n", "# However, the gene expression data uses different identifiers\n", "# We need to determine which column matches our expression data indices\n", "\n", "# Examining the first few gene expression indices to see their format\n", "print(\"First few gene expression indices:\")\n", "print(gene_data.index[:5])\n", "\n", "# Check if there's a direct match with any column\n", "# Now let's look at another approach - from the annotation preview, the 'SPOT_ID.1' column \n", "# contains gene information like RefSeq IDs, gene names, etc.\n", "# Let's extract human gene symbols from this field\n", "\n", "# First, let's define the mapping columns\n", "probe_id_col = 'ID' # This is the probe identifier column in the annotation\n", "gene_symbol_col = 'SPOT_ID.1' # This contains gene information including symbols\n", "\n", "# 2. Get gene mapping dataframe\n", "gene_mapping = get_gene_mapping(gene_annotation, probe_id_col, gene_symbol_col)\n", "\n", "# Print the mapping dataframe to observe its structure\n", "print(\"\\nGene mapping preview:\")\n", "print(gene_mapping.head())\n", "\n", "# Check how many probes we have in our mapping\n", "print(f\"\\nNumber of probes in mapping: {len(gene_mapping)}\")\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene expression data\n", "# This handles many-to-many relationships between probes and genes\n", "print(\"\\nApplying gene mapping...\")\n", "# The gene_data index currently uses numbers, but our mapping uses probe IDs\n", "# We need to align our data\n", "\n", "# Check if the gene expression data indices match with our mapping\n", "# If they don't match directly, we need to investigate further\n", "indices_in_mapping = sum(1 for idx in gene_data.index if idx in gene_mapping['ID'].values)\n", "print(f\"Number of expression data indices found in mapping: {indices_in_mapping} out of {len(gene_data.index)}\")\n", "\n", "# If the indices don't directly match, let's try a different approach\n", "# The issue is that we need to map between the numerical indices in gene_data and the \n", "# probe IDs in the annotation\n", "\n", "# Let's create a new mapping for the probe IDs that will work with our expression data\n", "# For this dataset, we will extract gene symbols from the annotation data and \n", "# normalize gene symbols in the index\n", "\n", "# Apply gene mapping to get gene-level expression data\n", "gene_data_mapped = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Normalize gene symbols to ensure consistency\n", "gene_data = normalize_gene_symbols_in_index(gene_data_mapped)\n", "\n", "# Display the resulting gene expression data\n", "print(\"\\nGene expression data preview:\")\n", "print(gene_data.shape)\n", "print(gene_data.head())\n" ] }, { "cell_type": "markdown", "id": "a5f94f8b", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "cf5fbf49", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:51:10.145133Z", "iopub.status.busy": "2025-03-25T03:51:10.144979Z", "iopub.status.idle": "2025-03-25T03:51:15.559736Z", "shell.execute_reply": "2025-03-25T03:51:15.559179Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Rheumatoid_Arthritis/gene_data/GSE140161.csv\n", "No trait data available for linking with gene expression data.\n", "Abnormality detected in the cohort: GSE140161. Preprocessing failed.\n", "No valid linked data to save - dataset doesn't contain Rheumatoid Arthritis data\n" ] } ], "source": [ "# 1. We cannot process clinical features since trait_row is None (no RA data in this dataset)\n", "# This means we're skipping the clinical feature extraction step as specified in the instructions\n", "\n", "# Save the gene data that we've already normalized\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", "# Since there's no trait data in this dataset, we cannot link clinical and genetic data\n", "# We'll create empty placeholder data to properly finish the process\n", "print(\"No trait data available for linking with gene expression data.\")\n", "\n", "# Create a small placeholder dataframe with proper structure\n", "empty_clinical_df = pd.DataFrame(columns=[trait])\n", "# Use first few samples from gene_data for consistent structure\n", "sample_ids = gene_data.columns[:5] if len(gene_data.columns) >= 5 else gene_data.columns\n", "empty_clinical_df = pd.DataFrame(index=sample_ids, columns=[trait])\n", "empty_clinical_df[trait] = None # All None values for trait\n", "\n", "# Skip handling missing values since we don't have valid linked data\n", "\n", "# 5. We'll mark this dataset as not usable due to missing trait data\n", "is_trait_biased = True # Not actually assessed, but marked as biased since trait data is missing\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=False, # No trait data\n", " is_biased=is_trait_biased, \n", " df=empty_clinical_df,\n", " note=\"This dataset contains gene expression data for Crohn's disease, not Rheumatoid Arthritis\"\n", ")\n", "\n", "# 6. Not saving linked data as it's not usable for our purposes\n", "print(\"No valid linked data to save - dataset doesn't contain Rheumatoid Arthritis data\")" ] } ], "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 }