{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0e75b5eb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:07:06.365098Z", "iopub.status.busy": "2025-03-25T05:07:06.364861Z", "iopub.status.idle": "2025-03-25T05:07:06.537650Z", "shell.execute_reply": "2025-03-25T05:07:06.537116Z" } }, "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 = \"X-Linked_Lymphoproliferative_Syndrome\"\n", "cohort = \"GSE190042\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/X-Linked_Lymphoproliferative_Syndrome\"\n", "in_cohort_dir = \"../../input/GEO/X-Linked_Lymphoproliferative_Syndrome/GSE190042\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/X-Linked_Lymphoproliferative_Syndrome/GSE190042.csv\"\n", "out_gene_data_file = \"../../output/preprocess/X-Linked_Lymphoproliferative_Syndrome/gene_data/GSE190042.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/X-Linked_Lymphoproliferative_Syndrome/clinical_data/GSE190042.csv\"\n", "json_path = \"../../output/preprocess/X-Linked_Lymphoproliferative_Syndrome/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "7a64741c", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "dd8817dc", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:07:06.539432Z", "iopub.status.busy": "2025-03-25T05:07:06.539273Z", "iopub.status.idle": "2025-03-25T05:07:06.843923Z", "shell.execute_reply": "2025-03-25T05:07:06.843330Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Files in the cohort directory:\n", "['GSE190042_family.soft.gz', 'GSE190042_series_matrix.txt.gz']\n", "Identified SOFT files: ['GSE190042_family.soft.gz']\n", "Identified matrix files: ['GSE190042_series_matrix.txt.gz']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Background Information:\n", "!Series_title\t\"Integration between MCL1 gene co-expression module and the Revised International Staging System enables precise prognostication and prediction of response to proteasome inhibitor-based therapy in individual multiple myeloma\"\n", "!Series_summary\t\"We recently identified a gene module of 87 genes co-expressed with MCL1 (MCL1-M), a critical regulator of plasma cell survival. MCL1-M captures both MM cell-intrinsically acting signals and the signals regulating the interaction between MM cells with bone marrow microenvironment. MM can be clustered into MCL1-M high and MCL1-M low subtypes. While the MCL1-M high MMs are enriched in a preplasmablast signature, the MCL1-M low MMs are enriched in B cell-specific genes. In multiple independent datasets, MCL1-M high MMs exhibited poorer prognosis compared to MCL1-M low MMs. Re-analysis of the phase III HOVON-65/GMMG-HD4 showed that only MCL1-M MMs, but not MCL1-M low MMs, benefited from bortezomib-based treatment. To translate the MCL1-M clustering scheme into a platform for individual diagnosis, we refined the classifier genes and developed a support vector machine-based algorithm.\"\n", "!Series_summary\t\"Individual MMs with transcriptome assessed at the RNA-seq or U133 plus 2.0 array platform can be robustly assigned as the MCL1-M high or low subtype with high confidence. Analyses of the MM samples in the HOVON-65/GMMG-HD4 trial and APEX trial reinforce that only MCL1-M high MMs benefit from bortezomib-based treatment with a hazard ratio of 0.58 (P = 0.010) and 0.47 (P = 0.009), respectively. Thus, MCL1-M based subtyping assigns MMs into prognostic and predictive molecular subtypes driven by subtype-specific pathogenic pathways.\"\n", "!Series_overall_design\t\"We also generated our own data set based on 72 newly diagnosed MM samples  from Chaoyang hospital in Beijing. All participants signed the informed consent form, and the study was approved by the institutional ethical review board of the Chao-Yang Hospital, Capital Medical University (Beijing, China). Patients were treated between August 2015 and September 2019, the longest follow-up period was 67 months. Bone marrow CD138+ cells were purified for the preparation of total mRNA for the transcriptome profiling using Affymetrix PrimeView array according to standard protocols.\"\n", "\n", "Sample Characteristics Dictionary:\n", "{0: ['batch: Batch 1', 'batch: Batch 3', 'batch: Batch 2', 'batch: Batch 4'], 1: ['gender: F', 'gender: M'], 2: ['age: 72', 'age: 77', 'age: 56', 'age: 67', 'age: 55', 'age: 73', 'age: 62', 'age: 49', 'age: 78', 'age: 66', 'age: 64', 'age: 47', 'age: 69', 'age: 59', 'age: 81', 'age: 65', 'age: 51', 'age: 70', 'age: 79', 'age: 75', 'age: 54', 'age: 61', 'age: 44', 'age: 52', 'age: 60', 'age: 68', 'age: 58', 'age: 84', 'age: 76', 'age: 53'], 3: ['time at diagnosis: 43355', 'time at diagnosis: 43341', 'time at diagnosis: 43441', 'time at diagnosis: 43439', 'time at diagnosis: 43516', 'time at diagnosis: 43372', 'time at diagnosis: 43507', 'time at diagnosis: 43535', 'time at diagnosis: 43373', 'time at diagnosis: 43409', 'time at diagnosis: 43453', 'time at diagnosis: 43509', 'time at diagnosis: 43536', 'time at diagnosis: 43510', 'time at diagnosis: 43040', 'time at diagnosis: 43460', 'time at diagnosis: 43593', 'time at diagnosis: 43472', 'time at diagnosis: 43514', 'time at diagnosis: 43477', 'time at diagnosis: 43519', 'time at diagnosis: 43525', 'time at diagnosis: 43480', 'time at diagnosis: 43520', 'time at diagnosis: 43546', 'time at diagnosis: 43553', 'time at diagnosis: 43476', 'time at diagnosis: 43530', 'time at diagnosis: 43550', 'time at diagnosis: 43412'], 4: ['type: IgA-k', 'type: IgG-K', 'type: Lambda', 'type: IgA-L', 'type: kappa', 'type: IgG-L', 'type: IgD-Lambda', 'type: IgG-Lambda', 'type: IgA-Lambda', 'type: PCL', 'type: IgD-L', 'type: NS', 'type: IgG-k', 'type: IgA-Lambda,IgG-Lambda', 'type: IgG-Lambda;Lambda'], 5: ['riss: I', 'riss: II', 'riss: III', 'treatment strategy: PCD*1'], 6: ['treatment strategy: RD*4 RCD*10,Rd-R maintenance', 'treatment strategy: VTD*5, ITD*2, VRD*1', 'treatment strategy: BCDT*4 ,BCD*7,RCD*8,R maintenance', 'treatment strategy: TD*1,PTD*2 VRD*2 ASCT,VR maintenance', 'treatment strategy: PDD*1,V-DEAP*2,VT-DEAP*2,ASCT, R maintenance', 'treatment strategy: BCD*2 BTD*2 RD*4,R maintenance', 'treatment strategy: BCD*7, RCD*5, RD-R maintenance', 'treatment strategy: BCDT*2, PCD*1,RCD*2, ASCT,R maintenance', 'treatment strategy: BCD*2, VRD*4, VRCD*2, VBiRD,IRCD,TMD,CETD*4,CAR-T', 'treatment strategy: PDD*9, VRD*1, R maintenance', 'treatment strategy: PCD*4', 'treatment strategy: PDD*6 ,RCD*6 RD maintenance', 'treatment strategy: NO', 'treatment strategy: VRD*2 ,PDD*2,TD maintenance', 'treatment strategy: VAD&IE*12, EPA&EP*4,Radiation', 'treatment strategy: VRD*1, VTD*2', 'treatment strategy: VRD*5, ASCT,R maintenance', 'treatment strategy: BD', 'treatment strategy: VTD*3', 'treatment strategy: VRDD*3 NR,V-DECP', 'treatment strategy: PCDD*1, PCDT*1', 'treatment strategy: BTD*8,T maintenance', 'treatment strategy: VRDD*2 ,VRD*2, RD maintenance', 'treatment strategy: VRD*4 ,IRD*,4 RD maintenance', 'treatment strategy: VRD*6, ASCT,VRD*2,VR maintenance', 'treatment strategy: PDD*1, R maintenance', 'treatment strategy: PDD*6 ,ID-I maintenance', 'treatment strategy: Dara-VMP', 'treatment strategy: PCD*1,PCDT*2,PCDT*2 ASCT, R maintenance', 'treatment strategy: VRD*8,VBiRD*4, Rd-R maintenance'], 7: ['best respose: CR', 'best respose: PR', 'best respose: CR MRD+', 'best respose: MR', 'best respose: VGPR MRD+', 'best respose: VGPR', 'best respose: CR MRD-', 'chromosome: 46,XY[20]', 'chromosome: 44,X,-X,+1,der(1;21)(q10;q10),add(6)(q21),-13,-14,del(17)(q21),add(19)(q13),+2 1[3]/46,XX[17]', 'best respose: NR', 'best respose: sCR MRD+', 'best respose: CR ,MRD+', 'pfs1(months): 1', 'best respose: 髓内达sCR,MRD-', 'chromosome: 41,X,-X,dic(1;5)(p13;q33),-3,add(4)(p11),-5,-7,der(9)t(7;9)(q11;p24),del(11)(q13q2 1),-13,-14,add(15)(q24),-21,+4mar[1]/46,XX[29] 实验诊断提示:分析30个中期分裂相,1个核型存在染色体数目及结构异常,其余为正常核型,', 'best respose: PD', 'best respose: SD', 'chromosome: 52,XY,+2,add(3)(q26),del(4)(q21),del(4)(q31),+der(6)t(1;6)(q11;q13),+7,add(8)(q24) ×2,+9,+11,del(16)(q22),+20,add(21)(p11)[19]/46,XY[1]', 'best respose: sCR,MRD-', 'best respose: Scr', 'best respose: sCR', 'best respose: CR,MRD+', 'best respose: PR MRD+'], 8: ['chromosome: 46 xx[20]/56,xx,+x,+4,+5,+10,+10,+11,+12,+19,+20,+22[1]', 'chromosome: ND', 'chromosome: 46,XY[20]', 'chromosome: 46,XY[8]', 'chromosome: 46,XX[20]', 'chromosome: 46,XX[15]', 'chromosome: 45,X,-Y[5]/46,XY[15]', 'chromosome: 46,XX,del(1)(p11),add(2)(p21),-4,+9,-13,add(22)(p11),+mar[10]', 'chromosome: 45,XX,der(13;14)(q10;q10)[20]', 'FISH: IGH/CCND1', 'chromosome: 46,XX[9]', 'FISH: negtive', 'FISH: 1q21+,IGH/FGFR3', 'chromosome: 43,X,-X,del(4)(q27q35),add(5)(q33),add(8)(q24),der(11)del(11)(q23)t(11;14)(q13; q32),-13,-14,der(14)t(11;14),-16,-17,-19,-22,+4mar[8]/46,XX[2]', 'chromosome: 44,XX,+del(3)(p13),-6,-10,-12,-13,-14,-17,-20,+4mar[cp6]/46,XX[7]', 'chromosome: 46,XX,inv(9)(p12q13)c[20]', 'chromosome: 50~52,XX,+add(1)(p13),+11,-14,+19,-22,+3~4mar,inc[cp3]/46,XX[17]', 'chromosome: 68~81,…[5]/46,XY[9]', 'chromosome: 47,XY,+Y[2]/46,XY[18]', 'chromosome: 46,XX[14]', 'os(months): 1', 'chromosome: 46,XY,del(20)(q11)[10]/46,XY[10]', 'FISH: 1q21(+4),TP53 - ,IGH/FGFR3', 'FISH: 1q21(+4),IGH +', 'FISH: 1q21(+3),CCND1+,MAF -,FGFR3 -', 'FISH: 1q21(+3),MAF -', 'chromosome: 53,XY,+add(1)(p13),+5,+9,add(13)(q32),+14,+18,+add(19)(q13),+21[2]/46,XY[18]', 'chromosome: 46,XY[15]', 'chromosome: complicated', 'chromosome: hypodiploids'], 9: ['FISH: negtive', 'FISH: ND', 'FISH: 1q21+,IGH-', 'FISH: 1q21+,IGH/FGFR3', 'FISH: MAF-,CCND1+', 'FISH: 1q21+,TP53+,MAF+,CCND1+,IGH/FGFR3+', 'FISH: 1q21+', 'FISH: 1q21+,TP53+,CCND1+', 'FISH: IGH/MAF,1q21+,TP53+', 'FISH: CCND1', 'FISH: 1q21+,FGFR3 -', 'FISH: TP53-,IGH-', 'pfs1(months): 5', 'FISH: 1q21+,IGH/CCND1', 'FISH: 1q21+,TP53-,IGH/CCND1', nan, 'FISH: t(4;14)', 'pfs1(months): 10', 'FISH: TP53 -,MAF-,IGH/CCND1', 'FISH: IGH/CCND1', 'FISH: IGH+', 'FISH: 1q21+,IGH/MAF', 'FISH: 1q21', 'FISH: TP53-,IGH/FGFR3', 'FISH: MAF-', 'FISH: TP53 -', 'FISH: 1q21 +、IGH +', 'FISH: t(11;14)69.5%', 'FISH: 1q21+,IGH/FGFR3', 'FISH: IGH-'], 10: ['pfs1(months): 32', nan, 'pfs1(months): 21', 'os(months): 5', 'pfs1(months): 20', 'pfs1(months): 16', 'os(months): 10', 'pfs1(months): 5', 'pfs1(months): 2', 'pfs1(months): 28', 'pfs1(months): 19', 'pfs1(months): 11', 'pfs1(months): 22', 'pfs1(months): 13', 'pfs1(months): 26', 'pfs1(months): 1', 'pfs1(months): 14', 'os(months): 2', 'pfs1(months): 4', 'pfs1(months): 23', 'pfs1(months): 37', 'pfs1(months): 29', 'pfs1(months): 41', 'pfs1(months): 9', 'pfs1(months): 33', 'pfs1(months): 12', 'pfs1(months): 8', 'pfs1(months): 35', 'pfs1(months): 67', 'pfs1(months): 57'], 11: [nan, 'os(months): 29', 'os(months): 5', 'os(months): 2', 'os(months): 11', 'os(months): 21', 'os(months): 1', 'os(months): 18', 'os(months): 23', 'os(months): 19', 'os(months): 37', 'os(months): 40', 'os(months): 12', 'os(months): 44', 'os(months): 9', 'os(months): 6', 'os(months): 24']}\n" ] } ], "source": [ "# 1. Let's first list the directory contents to understand what files are available\n", "import os\n", "\n", "print(\"Files in the cohort directory:\")\n", "files = os.listdir(in_cohort_dir)\n", "print(files)\n", "\n", "# Adapt file identification to handle different naming patterns\n", "soft_files = [f for f in files if 'soft' in f.lower() or '.soft' in f.lower() or '_soft' in f.lower()]\n", "matrix_files = [f for f in files if 'matrix' in f.lower() or '.matrix' in f.lower() or '_matrix' in f.lower()]\n", "\n", "# If no files with these patterns are found, look for alternative file types\n", "if not soft_files:\n", " soft_files = [f for f in files if f.endswith('.txt') or f.endswith('.gz')]\n", "if not matrix_files:\n", " matrix_files = [f for f in files if f.endswith('.txt') or f.endswith('.gz')]\n", "\n", "print(\"Identified SOFT files:\", soft_files)\n", "print(\"Identified matrix files:\", matrix_files)\n", "\n", "# Use the first files found, if any\n", "if len(soft_files) > 0 and len(matrix_files) > 0:\n", " soft_file = os.path.join(in_cohort_dir, soft_files[0])\n", " matrix_file = os.path.join(in_cohort_dir, matrix_files[0])\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(\"\\nBackground Information:\")\n", " print(background_info)\n", " print(\"\\nSample Characteristics Dictionary:\")\n", " print(sample_characteristics_dict)\n", "else:\n", " print(\"No appropriate files found in the directory.\")\n" ] }, { "cell_type": "markdown", "id": "bcacd718", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "b9916786", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:07:06.845598Z", "iopub.status.busy": "2025-03-25T05:07:06.845474Z", "iopub.status.idle": "2025-03-25T05:07:06.852590Z", "shell.execute_reply": "2025-03-25T05:07:06.852143Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Yes, this dataset has gene expression data from Affymetrix PrimeView array \n", "# based on the background information\n", "is_gene_available = True\n", "\n", "# 2. Data Availability and Conversion\n", "\n", "# 2.1 Trait Availability - For X-Linked Lymphoproliferative Syndrome\n", "# This dataset appears to be about Multiple Myeloma (MM), not X-Linked Lymphoproliferative Syndrome\n", "# Looking at the sample characteristics, row 4 contains different MM types\n", "trait_row = None # Not available for this specific trait\n", "\n", "# 2.2 Age Availability\n", "age_row = 2 # Row 2 contains age information\n", "\n", "# 2.3 Gender Availability\n", "gender_row = 1 # Row 1 contains gender information\n", "\n", "# Data Type Conversion Functions\n", "def convert_trait(value):\n", " # Not needed since trait data is not available\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age values to continuous numeric format.\"\"\"\n", " if not value or \":\" not in value:\n", " return None\n", " \n", " # Extract the value after the colon\n", " try:\n", " age_str = value.split(\":\")[1].strip()\n", " age = int(age_str)\n", " return age\n", " except (IndexError, ValueError):\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender values to binary format (0 for female, 1 for male).\"\"\"\n", " if not value or \":\" not in value:\n", " return None\n", " \n", " # Extract the value after the colon\n", " gender_str = value.split(\":\")[1].strip().upper()\n", " \n", " if gender_str == 'F':\n", " return 0\n", " elif gender_str == 'M':\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save metadata - initial filtering\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", "# Skip the clinical feature extraction since trait_row is None\n" ] }, { "cell_type": "markdown", "id": "6fb7c6f2", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "2a4bdda7", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:07:06.854235Z", "iopub.status.busy": "2025-03-25T05:07:06.854121Z", "iopub.status.idle": "2025-03-25T05:07:07.372317Z", "shell.execute_reply": "2025-03-25T05:07:07.371758Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First 20 gene/probe identifiers:\n", "Index(['11715100_at', '11715101_s_at', '11715102_x_at', '11715103_x_at',\n", " '11715104_s_at', '11715105_at', '11715106_x_at', '11715107_s_at',\n", " '11715108_x_at', '11715109_at', '11715110_at', '11715111_s_at',\n", " '11715112_at', '11715113_x_at', '11715114_x_at', '11715115_s_at',\n", " '11715116_s_at', '11715117_x_at', '11715118_s_at', '11715119_s_at'],\n", " dtype='object', name='ID')\n", "\n", "Gene expression data shape: (49395, 93)\n" ] } ], "source": [ "# Use the helper function to get the proper file paths\n", "soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# Extract gene expression data\n", "try:\n", " gene_data = get_genetic_data(matrix_file_path)\n", " \n", " # Print the first 20 row IDs (gene or probe identifiers)\n", " print(\"First 20 gene/probe identifiers:\")\n", " print(gene_data.index[:20])\n", " \n", " # Print shape to understand the dataset dimensions\n", " print(f\"\\nGene expression data shape: {gene_data.shape}\")\n", " \n", "except Exception as e:\n", " print(f\"Error extracting gene data: {e}\")\n" ] }, { "cell_type": "markdown", "id": "9576608b", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "8b064e60", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:07:07.374106Z", "iopub.status.busy": "2025-03-25T05:07:07.373944Z", "iopub.status.idle": "2025-03-25T05:07:07.376455Z", "shell.execute_reply": "2025-03-25T05:07:07.376013Z" } }, "outputs": [], "source": [ "# Looking at the gene identifiers, these appear to be probe IDs (like 11715100_at) from a microarray platform,\n", "# not standard human gene symbols. Probe IDs need to be mapped to gene symbols for biological interpretation.\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "70490563", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "9d39c05d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:07:07.378108Z", "iopub.status.busy": "2025-03-25T05:07:07.377961Z", "iopub.status.idle": "2025-03-25T05:07:23.266396Z", "shell.execute_reply": "2025-03-25T05:07:23.266018Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sample of gene expression data (first 5 rows, first 5 columns):\n", " GSM5712490 GSM5712491 GSM5712492 GSM5712493 GSM5712494\n", "ID \n", "11715100_at 2.652299 2.531051 2.739871 3.976684 2.408006\n", "11715101_s_at 4.540201 5.137441 5.230140 5.703439 4.493873\n", "11715102_x_at 3.252726 3.500768 3.883513 4.755649 3.197220\n", "11715103_x_at 3.439989 3.527640 3.938015 3.352165 3.707648\n", "11715104_s_at 4.226395 3.921919 4.393433 4.070046 3.989882\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Platform information:\n", "!Series_title = Integration between MCL1 gene co-expression module and the Revised International Staging System enables precise prognostication and prediction of response to proteasome inhibitor-based therapy in individual multiple myeloma\n", "!Platform_title = [PrimeView] Affymetrix Human Gene Expression Array\n", "!Platform_description = July 10, 2019: annotation table updated with netaffx build 36\n", "#Target Description =\n", "#Annotation Description =\n", "ID\tGeneChip Array\tSpecies Scientific Name\tAnnotation Date\tSequence Type\tSequence Source\tTranscript ID(Array Design)\tTarget Description\tGB_ACC\tGI\tRepresentative Public ID\tArchival UniGene Cluster\tUniGene ID\tGenome Version\tAlignments\tGene Title\tGene Symbol\tChromosomal Location\tUnigene Cluster Type\tEnsembl\tEntrez Gene\tSwissProt\tEC\tOMIM\tRefSeq Protein ID\tRefSeq Transcript ID\tGene Ontology Biological Process\tGene Ontology Cellular Component\tGene Ontology Molecular Function\tPathway\tInterPro\tAnnotation Description\tAnnotation Transcript Cluster\tTranscript Assignments\tAnnotation Notes\tSPOT_ID\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n", "!Sample_description = see next sheet\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene annotation columns:\n", "['ID', 'GeneChip Array', 'Species Scientific Name', 'Annotation Date', 'Sequence Type', 'Sequence Source', 'Transcript ID(Array Design)', 'Target Description', 'GB_ACC', 'GI', 'Representative Public ID', 'Archival UniGene Cluster', 'UniGene ID', 'Genome Version', 'Alignments', 'Gene Title', 'Gene Symbol', 'Chromosomal Location', 'Unigene Cluster Type', 'Ensembl', 'Entrez Gene', 'SwissProt', 'EC', 'OMIM', 'RefSeq Protein ID', 'RefSeq Transcript ID', 'Gene Ontology Biological Process', 'Gene Ontology Cellular Component', 'Gene Ontology Molecular Function', 'Pathway', 'InterPro', 'Annotation Description', 'Annotation Transcript Cluster', 'Transcript Assignments', 'Annotation Notes', 'SPOT_ID']\n", "\n", "Gene annotation preview:\n", "{'ID': ['11715100_at', '11715101_s_at', '11715102_x_at', '11715103_x_at', '11715104_s_at'], 'GeneChip Array': ['Human Genome PrimeView Array', 'Human Genome PrimeView Array', 'Human Genome PrimeView Array', 'Human Genome PrimeView Array', 'Human Genome PrimeView Array'], 'Species Scientific Name': ['Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens'], 'Annotation Date': ['30-Mar-16', '30-Mar-16', '30-Mar-16', '30-Mar-16', '30-Mar-16'], 'Sequence Type': ['Consensus sequence', 'Consensus sequence', 'Consensus sequence', 'Consensus sequence', 'Consensus sequence'], 'Sequence Source': ['Affymetrix Proprietary Database', 'Affymetrix Proprietary Database', 'Affymetrix Proprietary Database', 'Affymetrix Proprietary Database', 'Affymetrix Proprietary Database'], 'Transcript ID(Array Design)': ['g21264570', 'g21264570', 'g21264570', 'g22748780', 'g30039713'], 'Target Description': ['g21264570 /TID=g21264570 /CNT=1 /FEA=FLmRNA /TIER=FL /STK=0 /DEF=g21264570 /REP_ORG=Homo sapiens', 'g21264570 /TID=g21264570 /CNT=1 /FEA=FLmRNA /TIER=FL /STK=0 /DEF=g21264570 /REP_ORG=Homo sapiens', 'g21264570 /TID=g21264570 /CNT=1 /FEA=FLmRNA /TIER=FL /STK=0 /DEF=g21264570 /REP_ORG=Homo sapiens', 'g22748780 /TID=g22748780 /CNT=1 /FEA=FLmRNA /TIER=FL /STK=0 /DEF=g22748780 /REP_ORG=Homo sapiens', 'g30039713 /TID=g30039713 /CNT=1 /FEA=FLmRNA /TIER=FL /STK=0 /DEF=g30039713 /REP_ORG=Homo sapiens'], 'GB_ACC': [nan, nan, nan, nan, nan], 'GI': [21264570.0, 21264570.0, 21264570.0, 22748780.0, 30039713.0], 'Representative Public ID': ['g21264570', 'g21264570', 'g21264570', 'g22748780', 'g30039713'], 'Archival UniGene Cluster': ['---', '---', '---', '---', '---'], 'UniGene ID': ['Hs.247813', 'Hs.247813', 'Hs.247813', 'Hs.465643', 'Hs.352515'], 'Genome Version': ['February 2009 (Genome Reference Consortium GRCh37)', 'February 2009 (Genome Reference Consortium GRCh37)', 'February 2009 (Genome Reference Consortium GRCh37)', 'February 2009 (Genome Reference Consortium GRCh37)', 'February 2009 (Genome Reference Consortium GRCh37)'], 'Alignments': ['chr6:26271145-26271612 (-) // 100.0 // p22.2', 'chr6:26271145-26271612 (-) // 100.0 // p22.2', 'chr6:26271145-26271612 (-) // 100.0 // p22.2', 'chr19:4639529-5145579 (+) // 48.53 // p13.3', 'chr17:72920369-72929640 (+) // 100.0 // q25.1'], 'Gene Title': ['histone cluster 1, H3g', 'histone cluster 1, H3g', 'histone cluster 1, H3g', 'tumor necrosis factor, alpha-induced protein 8-like 1', 'otopetrin 2'], 'Gene Symbol': ['HIST1H3G', 'HIST1H3G', 'HIST1H3G', 'TNFAIP8L1', 'OTOP2'], 'Chromosomal Location': ['chr6p22.2', 'chr6p22.2', 'chr6p22.2', 'chr19p13.3', 'chr17q25.1'], 'Unigene Cluster Type': ['full length', 'full length', 'full length', 'full length', 'full length'], 'Ensembl': ['ENSG00000273983 /// OTTHUMG00000014436', 'ENSG00000273983 /// OTTHUMG00000014436', 'ENSG00000273983 /// OTTHUMG00000014436', 'ENSG00000185361 /// OTTHUMG00000182013', 'ENSG00000183034 /// OTTHUMG00000179215'], 'Entrez Gene': ['8355', '8355', '8355', '126282', '92736'], 'SwissProt': ['P68431', 'P68431', 'P68431', 'Q8WVP5', 'Q7RTS6'], 'EC': ['---', '---', '---', '---', '---'], 'OMIM': ['602815', '602815', '602815', '615869', '607827'], 'RefSeq Protein ID': ['NP_003525', 'NP_003525', 'NP_003525', 'NP_001161414 /// NP_689575 /// XP_005259544 /// XP_011525982', 'NP_835454 /// XP_011523781'], 'RefSeq Transcript ID': ['NM_003534', 'NM_003534', 'NM_003534', 'NM_001167942 /// NM_152362 /// XM_005259487 /// XM_011527680', 'NM_178160 /// XM_011525479'], 'Gene Ontology Biological Process': ['0000183 // chromatin silencing at rDNA // traceable author statement /// 0002230 // positive regulation of defense response to virus by host // inferred from mutant phenotype /// 0006325 // chromatin organization // traceable author statement /// 0006334 // nucleosome assembly // inferred from direct assay /// 0006334 // nucleosome assembly // inferred from mutant phenotype /// 0006335 // DNA replication-dependent nucleosome assembly // inferred from direct assay /// 0007264 // small GTPase mediated signal transduction // traceable author statement /// 0007596 // blood coagulation // traceable author statement /// 0010467 // gene expression // traceable author statement /// 0031047 // gene silencing by RNA // traceable author statement /// 0032776 // DNA methylation on cytosine // traceable author statement /// 0040029 // regulation of gene expression, epigenetic // traceable author statement /// 0044267 // cellular protein metabolic process // traceable author statement /// 0045814 // negative regulation of gene expression, epigenetic // traceable author statement /// 0051290 // protein heterotetramerization // inferred from direct assay /// 0060968 // regulation of gene silencing // inferred from direct assay /// 0098792 // xenophagy // inferred from mutant phenotype', '0000183 // chromatin silencing at rDNA // traceable author statement /// 0002230 // positive regulation of defense response to virus by host // inferred from mutant phenotype /// 0006325 // chromatin organization // traceable author statement /// 0006334 // nucleosome assembly // inferred from direct assay /// 0006334 // nucleosome assembly // inferred from mutant phenotype /// 0006335 // DNA replication-dependent nucleosome assembly // inferred from direct assay /// 0007264 // small GTPase mediated signal transduction // traceable author statement /// 0007596 // blood coagulation // traceable author statement /// 0010467 // gene expression // traceable author statement /// 0031047 // gene silencing by RNA // traceable author statement /// 0032776 // DNA methylation on cytosine // traceable author statement /// 0040029 // regulation of gene expression, epigenetic // traceable author statement /// 0044267 // cellular protein metabolic process // traceable author statement /// 0045814 // negative regulation of gene expression, epigenetic // traceable author statement /// 0051290 // protein heterotetramerization // inferred from direct assay /// 0060968 // regulation of gene silencing // inferred from direct assay /// 0098792 // xenophagy // inferred from mutant phenotype', '0000183 // chromatin silencing at rDNA // traceable author statement /// 0002230 // positive regulation of defense response to virus by host // inferred from mutant phenotype /// 0006325 // chromatin organization // traceable author statement /// 0006334 // nucleosome assembly // inferred from direct assay /// 0006334 // nucleosome assembly // inferred from mutant phenotype /// 0006335 // DNA replication-dependent nucleosome assembly // inferred from direct assay /// 0007264 // small GTPase mediated signal transduction // traceable author statement /// 0007596 // blood coagulation // traceable author statement /// 0010467 // gene expression // traceable author statement /// 0031047 // gene silencing by RNA // traceable author statement /// 0032776 // DNA methylation on cytosine // traceable author statement /// 0040029 // regulation of gene expression, epigenetic // traceable author statement /// 0044267 // cellular protein metabolic process // traceable author statement /// 0045814 // negative regulation of gene expression, epigenetic // traceable author statement /// 0051290 // protein heterotetramerization // inferred from direct assay /// 0060968 // regulation of gene silencing // inferred from direct assay /// 0098792 // xenophagy // inferred from mutant phenotype', '0032007 // negative regulation of TOR signaling // not recorded /// 0032007 // negative regulation of TOR signaling // inferred from sequence or structural similarity', '---'], 'Gene Ontology Cellular Component': ['0000228 // nuclear chromosome // inferred from direct assay /// 0000786 // nucleosome // inferred from direct assay /// 0000788 // nuclear nucleosome // inferred from direct assay /// 0005576 // extracellular region // traceable author statement /// 0005634 // nucleus // inferred from direct assay /// 0005654 // nucleoplasm // traceable author statement /// 0005694 // chromosome // inferred from electronic annotation /// 0016020 // membrane // inferred from direct assay /// 0043234 // protein complex // inferred from direct assay /// 0070062 // extracellular exosome // inferred from direct assay', '0000228 // nuclear chromosome // inferred from direct assay /// 0000786 // nucleosome // inferred from direct assay /// 0000788 // nuclear nucleosome // inferred from direct assay /// 0005576 // extracellular region // traceable author statement /// 0005634 // nucleus // inferred from direct assay /// 0005654 // nucleoplasm // traceable author statement /// 0005694 // chromosome // inferred from electronic annotation /// 0016020 // membrane // inferred from direct assay /// 0043234 // protein complex // inferred from direct assay /// 0070062 // extracellular exosome // inferred from direct assay', '0000228 // nuclear chromosome // inferred from direct assay /// 0000786 // nucleosome // inferred from direct assay /// 0000788 // nuclear nucleosome // inferred from direct assay /// 0005576 // extracellular region // traceable author statement /// 0005634 // nucleus // inferred from direct assay /// 0005654 // nucleoplasm // traceable author statement /// 0005694 // chromosome // inferred from electronic annotation /// 0016020 // membrane // inferred from direct assay /// 0043234 // protein complex // inferred from direct assay /// 0070062 // extracellular exosome // inferred from direct assay', '0005737 // cytoplasm // not recorded /// 0005737 // cytoplasm // inferred from sequence or structural similarity', '0016020 // membrane // inferred from electronic annotation /// 0016021 // integral component of membrane // inferred from electronic annotation'], 'Gene Ontology Molecular Function': ['0003677 // DNA binding // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0042393 // histone binding // inferred from physical interaction /// 0046982 // protein heterodimerization activity // inferred from electronic annotation', '0003677 // DNA binding // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0042393 // histone binding // inferred from physical interaction /// 0046982 // protein heterodimerization activity // inferred from electronic annotation', '0003677 // DNA binding // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0042393 // histone binding // inferred from physical interaction /// 0046982 // protein heterodimerization activity // inferred from electronic annotation', '0005515 // protein binding // inferred from physical interaction', '---'], 'Pathway': ['---', '---', '---', '---', '---'], 'InterPro': ['IPR007125 // Histone H2A/H2B/H3 // 9.3E-34 /// IPR007125 // Histone H2A/H2B/H3 // 1.7E-37', 'IPR007125 // Histone H2A/H2B/H3 // 9.3E-34 /// IPR007125 // Histone H2A/H2B/H3 // 1.7E-37', 'IPR007125 // Histone H2A/H2B/H3 // 9.3E-34 /// IPR007125 // Histone H2A/H2B/H3 // 1.7E-37', 'IPR008477 // Protein of unknown function DUF758 // 8.4E-86 /// IPR008477 // Protein of unknown function DUF758 // 6.8E-90', 'IPR004878 // Otopetrin // 9.4E-43 /// IPR004878 // Otopetrin // 9.4E-43 /// IPR004878 // Otopetrin // 9.4E-43 /// IPR004878 // Otopetrin // 3.9E-18 /// IPR004878 // Otopetrin // 3.8E-20 /// IPR004878 // Otopetrin // 5.2E-16'], 'Annotation Description': ['This probe set was annotated using the Matching Probes based pipeline to a Entrez Gene identifier using 4 transcripts. // false // Matching Probes // A', 'This probe set was annotated using the Matching Probes based pipeline to a Entrez Gene identifier using 4 transcripts. // false // Matching Probes // A', 'This probe set was annotated using the Matching Probes based pipeline to a Entrez Gene identifier using 4 transcripts. // false // Matching Probes // A', 'This probe set was annotated using the Matching Probes based pipeline to a Entrez Gene identifier using 9 transcripts. // false // Matching Probes // A', 'This probe set was annotated using the Matching Probes based pipeline to a Entrez Gene identifier using 6 transcripts. // false // Matching Probes // A'], 'Annotation Transcript Cluster': ['ENST00000614378(11),NM_003534(11),OTTHUMT00000040099(11),uc003nhi.3', 'ENST00000614378(11),NM_003534(11),OTTHUMT00000040099(11),uc003nhi.3', 'ENST00000614378(11),NM_003534(11),OTTHUMT00000040099(11),uc003nhi.3', 'BC017672(11),BC044250(9),ENST00000327473(11),ENST00000536716(11),NM_001167942(11),NM_152362(11),OTTHUMT00000458662(11),uc002max.3,uc021une.1', 'ENST00000331427(11),ENST00000580223(11),NM_178160(11),OTTHUMT00000445306(11),uc010wrp.2,XM_011525479(11)'], 'Transcript Assignments': ['ENST00000614378 // ensembl_havana_transcript:known chromosome:GRCh38:6:26269405:26271815:-1 gene:ENSG00000273983 gene_biotype:protein_coding transcript_biotype:protein_coding // ensembl // 11 // --- /// NM_003534 // Homo sapiens histone cluster 1, H3g (HIST1H3G), mRNA. // refseq // 11 // --- /// OTTHUMT00000040099 // otter:known chromosome:VEGA61:6:26269405:26271815:-1 gene:OTTHUMG00000014436 gene_biotype:protein_coding transcript_biotype:protein_coding // vega // 11 // --- /// uc003nhi.3 // --- // ucsc_genes // 11 // ---', 'ENST00000614378 // ensembl_havana_transcript:known chromosome:GRCh38:6:26269405:26271815:-1 gene:ENSG00000273983 gene_biotype:protein_coding transcript_biotype:protein_coding // ensembl // 11 // --- /// GENSCAN00000029819 // cdna:genscan chromosome:GRCh38:6:26270974:26271384:-1 transcript_biotype:protein_coding // ensembl // 11 // --- /// NM_003534 // Homo sapiens histone cluster 1, H3g (HIST1H3G), mRNA. // refseq // 11 // --- /// OTTHUMT00000040099 // otter:known chromosome:VEGA61:6:26269405:26271815:-1 gene:OTTHUMG00000014436 gene_biotype:protein_coding transcript_biotype:protein_coding // vega // 11 // --- /// uc003nhi.3 // --- // ucsc_genes // 11 // ---', 'ENST00000614378 // ensembl_havana_transcript:known chromosome:GRCh38:6:26269405:26271815:-1 gene:ENSG00000273983 gene_biotype:protein_coding transcript_biotype:protein_coding // ensembl // 11 // --- /// NM_003534 // Homo sapiens histone cluster 1, H3g (HIST1H3G), mRNA. // refseq // 11 // --- /// OTTHUMT00000040099 // otter:known chromosome:VEGA61:6:26269405:26271815:-1 gene:OTTHUMG00000014436 gene_biotype:protein_coding transcript_biotype:protein_coding // vega // 11 // --- /// uc003nhi.3 // --- // ucsc_genes // 11 // ---', 'BC017672 // Homo sapiens tumor necrosis factor, alpha-induced protein 8-like 1, mRNA (cDNA clone MGC:17791 IMAGE:3885999), complete cds. // gb // 11 // --- /// BC044250 // accn=BC044250 class=mRNAlike lncRNA name=Human lncRNA ref=JounralRNA transcriptId=673 cpcScore=-0.1526100 cnci=-0.1238602 // noncode // 9 // --- /// BC044250 // Homo sapiens tumor necrosis factor, alpha-induced protein 8-like 1, mRNA (cDNA clone IMAGE:5784807). // gb // 9 // --- /// ENST00000327473 // ensembl_havana_transcript:known chromosome:GRCh38:19:4639518:4655568:1 gene:ENSG00000185361 gene_biotype:protein_coding transcript_biotype:protein_coding // ensembl // 11 // --- /// ENST00000536716 // ensembl:known chromosome:GRCh38:19:4640017:4655568:1 gene:ENSG00000185361 gene_biotype:protein_coding transcript_biotype:protein_coding // ensembl // 11 // --- /// NM_001167942 // Homo sapiens tumor necrosis factor, alpha-induced protein 8-like 1 (TNFAIP8L1), transcript variant 1, mRNA. // refseq // 11 // --- /// NM_152362 // Homo sapiens tumor necrosis factor, alpha-induced protein 8-like 1 (TNFAIP8L1), transcript variant 2, mRNA. // refseq // 11 // --- /// NONHSAT060631 // Non-coding transcript identified by NONCODE: Exonic // noncode // 9 // --- /// OTTHUMT00000458662 // otter:known chromosome:VEGA61:19:4639518:4655568:1 gene:OTTHUMG00000182013 gene_biotype:protein_coding transcript_biotype:protein_coding // vega // 11 // --- /// uc002max.3 // --- // ucsc_genes // 11 // --- /// uc021une.1 // --- // ucsc_genes // 11 // ---', 'ENST00000331427 // ensembl:known chromosome:GRCh38:17:74924275:74933911:1 gene:ENSG00000183034 gene_biotype:protein_coding transcript_biotype:protein_coding // ensembl // 11 // --- /// ENST00000580223 // havana:known chromosome:GRCh38:17:74924603:74933912:1 gene:ENSG00000183034 gene_biotype:protein_coding transcript_biotype:protein_coding // ensembl // 11 // --- /// GENSCAN00000013715 // cdna:genscan chromosome:GRCh38:17:74924633:74933545:1 transcript_biotype:protein_coding // ensembl // 11 // --- /// NM_178160 // Homo sapiens otopetrin 2 (OTOP2), mRNA. // refseq // 11 // --- /// OTTHUMT00000445306 // otter:known chromosome:VEGA61:17:74924603:74933912:1 gene:OTTHUMG00000179215 gene_biotype:protein_coding transcript_biotype:protein_coding // vega // 11 // --- /// uc010wrp.2 // --- // ucsc_genes // 11 // --- /// XM_011525479 // PREDICTED: Homo sapiens otopetrin 2 (OTOP2), transcript variant X1, mRNA. // refseq // 11 // ---'], 'Annotation Notes': ['---', '---', 'GENSCAN00000029819 // ensembl // 4 // Cross Hyb Matching Probes', '---', '---'], 'SPOT_ID': [nan, nan, nan, nan, nan]}\n", "\n", "Matching rows in annotation for sample IDs: 940\n", "\n", "Potential gene symbol columns: ['GeneChip Array', 'Species Scientific Name', 'Archival UniGene Cluster', 'UniGene ID', 'Gene Title', 'Gene Symbol', 'Unigene Cluster Type', 'Entrez Gene', 'Gene Ontology Biological Process', 'Gene Ontology Cellular Component', 'Gene Ontology Molecular Function']\n", "\n", "Is this dataset likely to contain gene expression data? True\n" ] } ], "source": [ "# 1. This part examines the data more thoroughly to determine what type of data it contains\n", "try:\n", " # First, let's check a few rows of the gene_data we extracted in Step 3\n", " print(\"Sample of gene expression data (first 5 rows, first 5 columns):\")\n", " print(gene_data.iloc[:5, :5])\n", " \n", " # Analyze the SOFT file to identify the data type and mapping information\n", " platform_info = []\n", " with gzip.open(soft_file_path, 'rt', encoding='latin-1') as f:\n", " for line in f:\n", " if line.startswith(\"!Platform_title\") or line.startswith(\"!Series_title\") or \"description\" in line.lower():\n", " platform_info.append(line.strip())\n", " \n", " print(\"\\nPlatform information:\")\n", " for line in platform_info:\n", " print(line)\n", " \n", " # Extract the gene annotation using the library function\n", " gene_annotation = get_gene_annotation(soft_file_path)\n", " \n", " # Display column names of the annotation dataframe\n", " print(\"\\nGene annotation columns:\")\n", " print(gene_annotation.columns.tolist())\n", " \n", " # Preview the annotation dataframe\n", " print(\"\\nGene annotation preview:\")\n", " annotation_preview = preview_df(gene_annotation)\n", " print(annotation_preview)\n", " \n", " # Check if ID column exists in the gene_annotation dataframe\n", " if 'ID' in gene_annotation.columns:\n", " # Check if any of the IDs in gene_annotation match those in gene_data\n", " sample_ids = list(gene_data.index[:10])\n", " matching_rows = gene_annotation[gene_annotation['ID'].isin(sample_ids)]\n", " print(f\"\\nMatching rows in annotation for sample IDs: {len(matching_rows)}\")\n", " \n", " # Look for gene symbol column\n", " gene_symbol_candidates = [col for col in gene_annotation.columns if 'gene' in col.lower() or 'symbol' in col.lower() or 'name' in col.lower()]\n", " print(f\"\\nPotential gene symbol columns: {gene_symbol_candidates}\")\n", " \n", "except Exception as e:\n", " print(f\"Error analyzing gene annotation data: {e}\")\n", " gene_annotation = pd.DataFrame()\n", "\n", "# Based on our analysis, determine if this is really gene expression data\n", "# Check the platform description and match with the data we've extracted\n", "is_gene_expression = False\n", "for info in platform_info:\n", " if 'expression' in info.lower() or 'transcript' in info.lower() or 'mrna' in info.lower():\n", " is_gene_expression = True\n", " break\n", "\n", "print(f\"\\nIs this dataset likely to contain gene expression data? {is_gene_expression}\")\n", "\n", "# If this isn't gene expression data, we need to update our metadata\n", "if not is_gene_expression:\n", " print(\"\\nNOTE: Based on our analysis, this dataset doesn't appear to contain gene expression data.\")\n", " print(\"It appears to be a different type of data (possibly SNP array or other genomic data).\")\n", " # Update is_gene_available for metadata\n", " is_gene_available = False\n", " \n", " # Save the updated metadata\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" ] }, { "cell_type": "markdown", "id": "c1cafebe", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "17a9a4ab", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:07:23.267735Z", "iopub.status.busy": "2025-03-25T05:07:23.267613Z", "iopub.status.idle": "2025-03-25T05:07:24.912615Z", "shell.execute_reply": "2025-03-25T05:07:24.912234Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping (first 5 rows):\n", " ID Gene\n", "0 11715100_at HIST1H3G\n", "1 11715101_s_at HIST1H3G\n", "2 11715102_x_at HIST1H3G\n", "3 11715103_x_at TNFAIP8L1\n", "4 11715104_s_at OTOP2\n", "\n", "Gene expression data after mapping (shape): (19963, 93)\n", "\n", "Gene expression data after mapping (first 5 rows, first 5 columns):\n", " GSM5712490 GSM5712491 GSM5712492 GSM5712493 GSM5712494\n", "Gene \n", "A1BG 4.833014 4.952351 5.425290 5.064699 6.160388\n", "A1CF 5.632894 5.491876 5.734211 5.515223 5.677337\n", "A2M 5.809853 6.800766 5.038784 4.354973 3.747210\n", "A2ML1 4.576426 4.744677 4.659546 3.889619 4.376735\n", "A3GALT2 1.890677 2.295096 2.298677 2.079080 1.970331\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene expression data saved to: ../../output/preprocess/X-Linked_Lymphoproliferative_Syndrome/gene_data/GSE190042.csv\n" ] } ], "source": [ "# Based on the previous output, we've found that:\n", "# 1. Gene expression data uses probe IDs like '11715100_at' as row indices\n", "# 2. The gene annotation data has these probe IDs in the 'ID' column\n", "# 3. The gene symbols are in the 'Gene Symbol' column\n", "\n", "# 1. Extract the mapping from the gene annotation dataframe\n", "gene_mapping = get_gene_mapping(gene_annotation, 'ID', 'Gene Symbol')\n", "\n", "# Print preview of the mapping\n", "print(\"Gene mapping (first 5 rows):\")\n", "print(gene_mapping.head())\n", "\n", "# 2. Apply the mapping to convert probe-level measurements to gene expression values\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Print shape to understand the resulting gene expression dataset dimensions\n", "print(f\"\\nGene expression data after mapping (shape): {gene_data.shape}\")\n", "\n", "# Preview the first few rows of the gene expression data\n", "print(\"\\nGene expression data after mapping (first 5 rows, first 5 columns):\")\n", "print(gene_data.iloc[:5, :5])\n", "\n", "# Save the gene expression data for later use\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\"\\nGene expression data saved to: {out_gene_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "88d8ac25", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "efcb14b4", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:07:24.914010Z", "iopub.status.busy": "2025-03-25T05:07:24.913881Z", "iopub.status.idle": "2025-03-25T05:07:26.203016Z", "shell.execute_reply": "2025-03-25T05:07:26.202633Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape after normalization: (19758, 93)\n", "First few gene symbols after normalization: ['A1BG', 'A1CF', 'A2M', 'A2ML1', 'A3GALT2', 'A4GALT', 'A4GNT', 'AAAS', 'AACS', 'AACSP1']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/X-Linked_Lymphoproliferative_Syndrome/gene_data/GSE190042.csv\n", "Is trait data available for X-Linked_Lymphoproliferative_Syndrome? False\n", "This dataset doesn't contain data for the trait: X-Linked_Lymphoproliferative_Syndrome\n", "Abnormality detected in the cohort: GSE190042. Preprocessing failed.\n", "Data quality check result: Not usable\n", "Data not saved due to missing trait information.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the obtained gene expression data\n", "try:\n", " # Now let's normalize the gene data using the provided function\n", " normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", " print(f\"Gene data shape after normalization: {normalized_gene_data.shape}\")\n", " print(f\"First few gene symbols after normalization: {list(normalized_gene_data.index[:10])}\")\n", " \n", " # Save the normalized gene data\n", " os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", " normalized_gene_data.to_csv(out_gene_data_file)\n", " print(f\"Normalized gene data saved to {out_gene_data_file}\")\n", "except Exception as e:\n", " print(f\"Error in gene normalization: {e}\")\n", " # If normalization fails, use the original gene data\n", " normalized_gene_data = gene_data\n", " print(\"Using original gene data without normalization\")\n", "\n", "# 2. Handle the case where trait data isn't available\n", "# Recall that in step 2, we determined trait_row = None\n", "is_trait_available = trait_row is not None\n", "print(f\"Is trait data available for {trait}? {is_trait_available}\")\n", "\n", "if not is_trait_available:\n", " print(f\"This dataset doesn't contain data for the trait: {trait}\")\n", " \n", " # When trait data isn't available, we should mark the dataset as not usable\n", " # for our specific trait study, even if it contains gene expression data\n", " \n", " # Creating a mock dataframe with the correct structure for validation\n", " df_for_validation = pd.DataFrame(index=normalized_gene_data.columns[:5], columns=[trait])\n", " \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,\n", " is_biased=False, # Using a concrete value instead of None\n", " df=df_for_validation, # Passing a valid dataframe with appropriate structure\n", " note=f\"Dataset contains gene expression data but no information about {trait}.\"\n", " )\n", " \n", " print(f\"Data quality check result: {'Usable' if is_usable else 'Not usable'}\")\n", " print(\"Data not saved due to missing trait information.\")\n", "else:\n", " # This block would handle the case where trait data is available\n", " # Since we determined in step 2 that trait_row is None, this block won't be executed\n", " \n", " # 3. Load/create the clinical data\n", " try:\n", " # Try to load clinical data from a file\n", " clinical_data = pd.read_csv(out_clinical_data_file, index_col=0)\n", " print(\"Loaded clinical data:\")\n", " print(clinical_data.head())\n", " except Exception as e:\n", " print(f\"Error loading clinical data: {e}\")\n", " # Recreate clinical features using the original clinical_df\n", " soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)\n", " background_info, clinical_df = get_background_and_clinical_data(matrix_file_path)\n", " \n", " clinical_data = geo_select_clinical_features(\n", " clinical_df,\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", " ).T # Transpose to get samples as rows\n", " \n", " # 4. Link clinical and genetic data\n", " gene_data_for_linking = normalized_gene_data.T\n", " common_samples = set(clinical_data.index).intersection(gene_data_for_linking.index)\n", " \n", " clinical_data = clinical_data.loc[clinical_data.index.isin(common_samples)]\n", " gene_data_for_linking = gene_data_for_linking.loc[gene_data_for_linking.index.isin(common_samples)]\n", " \n", " linked_data = pd.concat([clinical_data, gene_data_for_linking], axis=1)\n", " \n", " # 5. Handle missing values\n", " linked_data = handle_missing_values(linked_data, trait)\n", " \n", " # 6. Determine whether the trait and demographic features are biased\n", " is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)\n", " \n", " # 7. Quality validation and save\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=linked_data,\n", " note=\"Dataset with trait and gene data.\"\n", " )\n", " \n", " # 8. Save the linked data if it's usable\n", " if is_usable:\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " linked_data.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", " else:\n", " print(f\"Data not saved due to quality issues.\")" ] } ], "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 }