{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "5febc4f2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:58:16.135847Z", "iopub.status.busy": "2025-03-25T03:58:16.135474Z", "iopub.status.idle": "2025-03-25T03:58:16.299656Z", "shell.execute_reply": "2025-03-25T03:58:16.299325Z" } }, "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 = \"Sjögrens_Syndrome\"\n", "cohort = \"GSE143153\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Sjögrens_Syndrome\"\n", "in_cohort_dir = \"../../input/GEO/Sjögrens_Syndrome/GSE143153\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Sjögrens_Syndrome/GSE143153.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Sjögrens_Syndrome/gene_data/GSE143153.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Sjögrens_Syndrome/clinical_data/GSE143153.csv\"\n", "json_path = \"../../output/preprocess/Sjögrens_Syndrome/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "91361b8b", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "9f6c74bb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:58:16.301037Z", "iopub.status.busy": "2025-03-25T03:58:16.300898Z", "iopub.status.idle": "2025-03-25T03:58:16.468344Z", "shell.execute_reply": "2025-03-25T03:58:16.468012Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Microarray analysis of salivary gland CD4+ T cells\"\n", "!Series_summary\t\"Whole human genome arrays were used to assess the transcriptome differences in CD3+CD4+CD45RA- memory T cells isolated and sorted from minor salivary gland biopsy tissue of individuals who met 2002 American European Consensus Group classification criteria for primary Sjogren’s syndrome (SS) and subjects who did not meet criteria for SS, lacked focal lymphocytic sialoadenitis, lacked anti-Ro antibodies, lacked anti-La antibodies, but who had subjective symptoms of dryness (non-SS, sicca controls).\"\n", "!Series_overall_design\t\"Samples from 17 pSS and 15 non-SS subjects were hybridized to Agilent Whole Human Genome 8x60K microarrays in three batches (Batch 1: 2 pSS, 3 non-SS; Batch 2: 6 pSS, 5 non-SS; Batch 3: 9 pSS, 7 non-SS).  All data were pooled to assess potential batch effects by principal components analysis and gene expression data were quality control checked using the arrayQualityMetrics R package. Batch effects were equalized via ComBat analysis (‘Surrogate Variable Analysis’ R package Ver 3.8.0; manual specification of batches).\"\n", "Sample Characteristics Dictionary:\n", "{0: ['subject id: Subject 1', 'subject id: Subject 2', 'subject id: Subject 3', 'subject id: Subject 4', 'subject id: Subject 5', 'subject id: Subject 6', 'subject id: Subject 7', 'subject id: Subject 8', 'subject id: Subject 9', 'subject id: Subject 10', 'subject id: Subject 11', 'subject id: Subject 12', 'subject id: Subject 13', 'subject id: Subject 14', 'subject id: Subject 15', 'subject id: Subject 16', 'subject id: Subject 17', 'subject id: Subject 18', 'subject id: Subject 19', 'subject id: Subject 20', 'subject id: Subject 21', 'subject id: Subject 22', 'subject id: Subject 23', 'subject id: Subject 24', 'subject id: Subject 25', 'subject id: Subject 26', 'subject id: Subject 27', 'subject id: Subject 28', 'subject id: Subject 29', 'subject id: Subject 30'], 1: ['aecg disease classification: Primary SS', 'aecg disease classification: non-SS'], 2: ['age: 56', 'age: 51', 'age: 37', 'age: 40', 'age: 41', 'age: 50', 'age: 38', 'age: 58', 'age: 55', 'age: 35', 'age: 43', 'age: 62', 'age: 46', 'age: 66', 'age: 60', 'age: 63', 'age: 19', 'age: 64', 'age: 71', 'age: 30', 'age: 31', 'age: 45'], 3: ['Sex: M', 'Sex: F'], 4: ['race: White', 'race: More Than One', 'race: Native American', 'race: Black'], 5: ['batch: Batch 1', 'batch: Batch 2', 'batch: Batch 3'], 6: ['cell type: Minor salivary gland memory CD4 T cells']}\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": "ae4f4831", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "17c44a37", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:58:16.469518Z", "iopub.status.busy": "2025-03-25T03:58:16.469410Z", "iopub.status.idle": "2025-03-25T03:58:16.473894Z", "shell.execute_reply": "2025-03-25T03:58:16.473602Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Trait data (Sjögrens_Syndrome) available at row 1\n", "Age data available at row 2\n", "Gender data available at row 3\n", "Clinical data conversion functions defined:\n", "- convert_trait: Converts 'Primary SS' to 1, 'non-SS' to 0\n", "- convert_age: Converts age values to float\n", "- convert_gender: Converts 'M' to 1, 'F' to 0\n" ] } ], "source": [ "import os\n", "import json\n", "import pandas as pd\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 microarrays\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "# For trait: From the sample characteristics dictionary, key 1 contains disease classification\n", "trait_row = 1\n", "\n", "# For age: From the sample characteristics dictionary, key 2 contains age information\n", "age_row = 2\n", "\n", "# For gender: From the sample characteristics dictionary, key 3 contains sex information\n", "gender_row = 3\n", "\n", "# 2.2 Data Type Conversion\n", "# Function for trait conversion\n", "def convert_trait(value):\n", " # Extract the value after colon and strip whitespace\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " # Convert to binary: Primary SS = 1, non-SS = 0\n", " if \"Primary SS\" in value:\n", " return 1\n", " elif \"non-SS\" in value:\n", " return 0\n", " else:\n", " return None\n", "\n", "# Function for age conversion\n", "def convert_age(value):\n", " # Extract the value after colon and strip whitespace\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " # Convert to numeric (continuous)\n", " try:\n", " return float(value)\n", " except:\n", " return None\n", "\n", "# Function for gender conversion\n", "def convert_gender(value):\n", " # Extract the value after colon and strip whitespace\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " # Convert to binary: M = 1, F = 0\n", " if value.upper() == \"M\":\n", " return 1\n", " elif value.upper() == \"F\":\n", " return 0\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Determine trait data availability\n", "is_trait_available = trait_row is not None\n", "\n", "# Save cohort information for initial filtering\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available\n", ")\n", "\n", "# 4. Clinical Feature Extraction (Only if trait_row is not None)\n", "# At this analysis step, we're examining the availability of data rather than\n", "# processing actual files, which will be done in later steps\n", "if trait_row is not None:\n", " print(f\"Trait data (Sjögrens_Syndrome) available at row {trait_row}\")\n", " if age_row is not None:\n", " print(f\"Age data available at row {age_row}\")\n", " if gender_row is not None:\n", " print(f\"Gender data available at row {gender_row}\")\n", " \n", " print(\"Clinical data conversion functions defined:\")\n", " print(\"- convert_trait: Converts 'Primary SS' to 1, 'non-SS' to 0\")\n", " print(\"- convert_age: Converts age values to float\")\n", " print(\"- convert_gender: Converts 'M' to 1, 'F' to 0\")\n" ] }, { "cell_type": "markdown", "id": "6d8890e0", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "9146ffa1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:58:16.474947Z", "iopub.status.busy": "2025-03-25T03:58:16.474846Z", "iopub.status.idle": "2025-03-25T03:58:16.689194Z", "shell.execute_reply": "2025-03-25T03:58:16.688819Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13',\n", " '14', '15', '16', '17', '18', '19', '20'],\n", " dtype='object', name='ID')\n" ] } ], "source": [ "# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.\n", "gene_data = get_genetic_data(matrix_file)\n", "\n", "# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.\n", "print(gene_data.index[:20])\n" ] }, { "cell_type": "markdown", "id": "29cec565", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "cc847c92", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:58:16.690432Z", "iopub.status.busy": "2025-03-25T03:58:16.690323Z", "iopub.status.idle": "2025-03-25T03:58:16.692196Z", "shell.execute_reply": "2025-03-25T03:58:16.691913Z" } }, "outputs": [], "source": [ "# Looking at the gene identifiers, these appear to be simple numeric identifiers (1, 2, 3, etc.)\n", "# rather than human gene symbols (like BRCA1, TP53, etc.).\n", "# In GEO datasets, numeric identifiers typically need to be mapped to gene symbols\n", "# using the platform annotation information.\n", "\n", "# These numeric identifiers are not standard human gene symbols and will need mapping\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "95c699dd", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "a25b6aeb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:58:16.693265Z", "iopub.status.busy": "2025-03-25T03:58:16.693164Z", "iopub.status.idle": "2025-03-25T03:58:19.548654Z", "shell.execute_reply": "2025-03-25T03:58:19.548024Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['1', '2', '3', '4', '5'], 'ProbeName': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'A_23_P326296', 'A_24_P287941'], 'GB_ACC': [nan, nan, nan, 'NM_144987', 'NM_013290'], 'ControlType': [1.0, 1.0, 1.0, 0.0, 0.0], 'accessions': [nan, nan, nan, 'ref|NM_144987|ref|NM_001040425|ens|ENST00000292879|ens|ENST00000392196', 'ref|NM_013290|ref|NM_016556|ens|ENST00000393795|ens|ENST00000253789'], 'GeneName': ['GE_BrightCorner', 'DarkCorner', 'DarkCorner', 'U2AF1L4', 'PSMC3IP'], 'Description': [nan, nan, nan, 'ref|Homo sapiens U2 small nuclear RNA auxiliary factor 1-like 4 (U2AF1L4), transcript variant 2, mRNA [NM_144987]', 'ref|Homo sapiens PSMC3 interacting protein (PSMC3IP), transcript variant 1, mRNA [NM_013290]'], 'chr_coord': [nan, nan, nan, 'hs|chr19:036235296-036235237', 'hs|chr17:040724775-040724716'], 'SEQUENCE': [nan, nan, nan, 'GTATGGGGAGATTGAAGAGATGAATGTGTGCGACAACCTTGGGGACCACGTCGTGGGCAA', 'AAATTGCAGTAGCTTGAGGTTAACATTTAGACTTGGAACAATGCTAAAGGAAAGCATTTG'], 'SPOT_ID': ['--GE_BrightCorner', '--DarkCorner', '--DarkCorner', nan, nan]}\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": "1e3d5122", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "6b8bf1f1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:58:19.550653Z", "iopub.status.busy": "2025-03-25T03:58:19.550496Z", "iopub.status.idle": "2025-03-25T03:58:19.818086Z", "shell.execute_reply": "2025-03-25T03:58:19.817532Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data after mapping (first 5 rows):\n", " GSM4251021 GSM4251022 GSM4251023 GSM4251024 GSM4251025 GSM4251026 \\\n", "Gene \n", "A1BG 4.960248 8.602593 3.865823 4.940824 3.691263 6.169120 \n", "A1CF 43.791353 95.789151 95.931706 94.097990 87.790806 55.940933 \n", "A2BP1 10.506252 13.071567 15.081290 16.994973 13.472849 10.773222 \n", "A2LD1 2.345080 2.535318 2.443681 2.792124 2.568849 2.539543 \n", "A2M 65.219899 95.236352 28.492692 37.175936 98.877802 96.035878 \n", "\n", " GSM4251027 GSM4251028 GSM4251029 GSM4251030 ... GSM4251043 \\\n", "Gene ... \n", "A1BG 3.047159 4.265922 9.047001 2.880536 ... 5.092730 \n", "A1CF 53.160565 52.885941 45.794629 71.312747 ... 51.482496 \n", "A2BP1 9.149361 9.223923 9.372810 11.239728 ... 8.634298 \n", "A2LD1 2.646762 8.445838 2.447784 2.602923 ... 1.994271 \n", "A2M 94.991213 70.156849 59.228763 78.823490 ... 55.593573 \n", "\n", " GSM4251044 GSM4251045 GSM4251046 GSM4251047 GSM4251048 GSM4251049 \\\n", "Gene \n", "A1BG 7.560336 5.930857 4.582531 9.011594 6.989225 5.356378 \n", "A1CF 43.681968 67.932147 58.647923 58.232091 50.510335 89.212101 \n", "A2BP1 10.258410 9.566104 11.429759 17.110309 9.757985 14.345206 \n", "A2LD1 1.519834 1.724250 4.196019 3.689943 2.087420 5.684992 \n", "A2M 44.463836 86.226242 106.758576 103.033064 89.101012 32.135287 \n", "\n", " GSM4251050 GSM4251051 GSM4251052 \n", "Gene \n", "A1BG 3.349631 2.567970 4.118886 \n", "A1CF 65.981340 68.665182 57.072306 \n", "A2BP1 13.560348 16.111916 10.799361 \n", "A2LD1 2.374661 3.874853 4.566462 \n", "A2M 93.552892 109.549608 61.546523 \n", "\n", "[5 rows x 32 columns]\n", "\n", "Shape of gene expression data: (20147, 32)\n" ] } ], "source": [ "# 1. Identify the relevant columns for mapping\n", "# From the preview, we can see that:\n", "# - 'ID' column contains numeric identifiers matching the gene expression data index\n", "# - 'GeneName' column contains the human gene symbols we want to map to\n", "\n", "# 2. Get a gene mapping dataframe\n", "prob_col = 'ID' # Column containing probe IDs\n", "gene_col = 'GeneName' # Column containing gene symbols\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col, gene_col)\n", "\n", "# 3. Apply the gene mapping to convert probe-level measurements to gene expression data\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Let's examine the first few rows of the gene expression data after mapping\n", "print(\"Gene expression data after mapping (first 5 rows):\")\n", "print(gene_data.head())\n", "\n", "# Check the shape of the resulting gene expression data\n", "print(f\"\\nShape of gene expression data: {gene_data.shape}\")\n" ] }, { "cell_type": "markdown", "id": "cc5f5c7c", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "ae470be6", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:58:19.819958Z", "iopub.status.busy": "2025-03-25T03:58:19.819814Z", "iopub.status.idle": "2025-03-25T03:58:28.112764Z", "shell.execute_reply": "2025-03-25T03:58:28.111888Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Clinical data saved to ../../output/preprocess/Sjögrens_Syndrome/clinical_data/GSE143153.csv\n", "Normalized gene data shape: (19274, 32)\n", "First few normalized gene symbols: ['A1BG', 'A1BG-AS1', 'A1CF', 'A2M', 'A2ML1', 'A4GALT', 'A4GNT', 'AAA1', 'AAAS', 'AACS']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Sjögrens_Syndrome/gene_data/GSE143153.csv\n", "Linked data shape: (32, 19277)\n", " Sjögrens_Syndrome Age Gender A1BG A1BG-AS1 A1CF \\\n", "GSM4251021 1.0 56.0 1.0 4.960248 4.592398 43.791353 \n", "GSM4251022 1.0 51.0 0.0 8.602593 3.327157 95.789151 \n", "GSM4251023 0.0 37.0 0.0 3.865823 5.551529 95.931706 \n", "GSM4251024 0.0 40.0 0.0 4.940824 3.408210 94.097990 \n", "GSM4251025 0.0 41.0 0.0 3.691263 5.024266 87.790806 \n", "\n", " A2M A2ML1 A4GALT A4GNT ... ZWILCH \\\n", "GSM4251021 65.219899 3.988163 15.353936 2.987036 ... 5.716409 \n", "GSM4251022 95.236352 2.219424 16.845896 4.322902 ... 3.196549 \n", "GSM4251023 28.492692 4.329435 18.440743 7.215498 ... 4.035570 \n", "GSM4251024 37.175936 4.833797 17.263753 3.104170 ... 2.323874 \n", "GSM4251025 98.877802 4.673251 13.087190 4.312082 ... 2.301789 \n", "\n", " ZWINT ZXDA ZXDB ZXDC ZYG11A ZYG11B \\\n", "GSM4251021 29.619017 3.175254 2.785184 8.422094 5.534263 8.687829 \n", "GSM4251022 14.640629 8.081257 2.129172 10.124353 9.908285 3.843989 \n", "GSM4251023 13.494070 7.137765 1.817091 6.651723 4.481387 4.939778 \n", "GSM4251024 16.347799 2.880983 1.745957 5.384165 5.431337 4.362793 \n", "GSM4251025 13.833641 3.975335 2.536201 4.941374 4.947386 3.954731 \n", "\n", " ZYX ZZEF1 ZZZ3 \n", "GSM4251021 18.791314 7.059974 68.712940 \n", "GSM4251022 14.004866 1.315878 57.471144 \n", "GSM4251023 13.350255 0.673019 55.260944 \n", "GSM4251024 23.630775 2.417558 53.441399 \n", "GSM4251025 19.817722 1.624646 50.524028 \n", "\n", "[5 rows x 19277 columns]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Shape after handling missing values: (32, 19277)\n", "For the feature 'Sjögrens_Syndrome', the least common label is '0.0' with 15 occurrences. This represents 46.88% of the dataset.\n", "The distribution of the feature 'Sjögrens_Syndrome' in this dataset is fine.\n", "\n", "Quartiles for 'Age':\n", " 25%: 38.0\n", " 50% (Median): 45.5\n", " 75%: 58.0\n", "Min: 19.0\n", "Max: 71.0\n", "The distribution of the feature 'Age' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '1.0' with 3 occurrences. This represents 9.38% of the dataset.\n", "The distribution of the feature 'Gender' in this dataset is severely biased.\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data saved to ../../output/preprocess/Sjögrens_Syndrome/GSE143153.csv\n" ] } ], "source": [ "# 1. Extract clinical features\n", "clinical_features = geo_select_clinical_features(\n", " clinical_data, \n", " trait=trait, \n", " trait_row=trait_row, \n", " convert_trait=convert_trait,\n", " age_row=age_row, \n", " convert_age=convert_age,\n", " gender_row=gender_row, \n", " convert_gender=convert_gender\n", ")\n", "\n", "# Save the clinical features data\n", "os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", "clinical_features.to_csv(out_clinical_data_file)\n", "print(f\"Clinical data saved to {out_clinical_data_file}\")\n", "\n", "# 1. Normalize gene symbols in the gene expression data\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Normalized gene data shape: {normalized_gene_data.shape}\")\n", "print(f\"First few normalized gene symbols: {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", "\n", "# 2. Link the clinical and genetic data\n", "linked_data = geo_link_clinical_genetic_data(clinical_features, normalized_gene_data)\n", "print(f\"Linked data shape: {linked_data.shape}\")\n", "print(linked_data.head())\n", "\n", "# 3. Handle missing values in the linked data\n", "linked_data = handle_missing_values(linked_data, trait)\n", "print(f\"Shape after handling missing values: {linked_data.shape}\")\n", "\n", "# 4. Determine whether the trait and demographic features are severely biased\n", "is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)\n", "\n", "# 5. Conduct quality check and save the cohort information\n", "is_usable = validate_and_save_cohort_info(\n", " is_final=True, \n", " cohort=cohort, \n", " info_path=json_path, \n", " is_gene_available=True, \n", " is_trait_available=True,\n", " is_biased=is_trait_biased, \n", " df=unbiased_linked_data,\n", " note=f\"Dataset contains gene expression data from CD4 T-cells of pSS patients and healthy controls.\"\n", ")\n", "\n", "# 6. Save the data if it's usable\n", "if is_usable:\n", " # Create directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " # Save the data\n", " unbiased_linked_data.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(f\"Data quality check failed. The dataset is not suitable for association studies.\")" ] } ], "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 }