File size: 5,297 Bytes
f88156f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "4e210e5d",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:17:45.192780Z",
"iopub.status.busy": "2025-03-25T08:17:45.192678Z",
"iopub.status.idle": "2025-03-25T08:17:45.355666Z",
"shell.execute_reply": "2025-03-25T08:17:45.355278Z"
}
},
"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 = \"Chronic_Fatigue_Syndrome\"\n",
"\n",
"# Input paths\n",
"tcga_root_dir = \"../../input/TCGA\"\n",
"\n",
"# Output paths\n",
"out_data_file = \"../../output/preprocess/Chronic_Fatigue_Syndrome/TCGA.csv\"\n",
"out_gene_data_file = \"../../output/preprocess/Chronic_Fatigue_Syndrome/gene_data/TCGA.csv\"\n",
"out_clinical_data_file = \"../../output/preprocess/Chronic_Fatigue_Syndrome/clinical_data/TCGA.csv\"\n",
"json_path = \"../../output/preprocess/Chronic_Fatigue_Syndrome/cohort_info.json\"\n"
]
},
{
"cell_type": "markdown",
"id": "6e7e812d",
"metadata": {},
"source": [
"### Step 1: Initial Data Loading"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fa0b8d64",
"metadata": {
"execution": {
"iopub.execute_input": "2025-03-25T08:17:45.356928Z",
"iopub.status.busy": "2025-03-25T08:17:45.356785Z",
"iopub.status.idle": "2025-03-25T08:17:45.362170Z",
"shell.execute_reply": "2025-03-25T08:17:45.361838Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No suitable directory found for Chronic_Fatigue_Syndrome.\n",
"Skipping this trait as no suitable data was found.\n"
]
}
],
"source": [
"import os\n",
"import pandas as pd\n",
"\n",
"# 1. Find the most relevant directory for Osteoporosis\n",
"subdirectories = os.listdir(tcga_root_dir)\n",
"target_trait = trait.lower().replace(\"_\", \" \") # Convert to lowercase for case-insensitive matching\n",
"\n",
"# Search for related terms to Osteoporosis\n",
"related_terms = [\"osteoporosis\", \"bone\", \"density\", \"skeletal\", \"bone mineral\", \"fracture\"]\n",
"matched_dir = None\n",
"\n",
"for subdir in subdirectories:\n",
" subdir_lower = subdir.lower()\n",
" # Check if any related term is in the directory name\n",
" if any(term in subdir_lower for term in related_terms):\n",
" matched_dir = subdir\n",
" print(f\"Found potential match: {subdir}\")\n",
" # If exact match found, select it\n",
" if \"osteoporosis\" in subdir_lower:\n",
" print(f\"Selected as best match: {subdir}\")\n",
" matched_dir = subdir\n",
" break\n",
"\n",
"# If we found a potential match, use it\n",
"if matched_dir:\n",
" print(f\"Selected directory: {matched_dir}\")\n",
" \n",
" # 2. Get the clinical and genetic data file paths\n",
" cohort_dir = os.path.join(tcga_root_dir, matched_dir)\n",
" clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)\n",
" \n",
" print(f\"Clinical file: {os.path.basename(clinical_file_path)}\")\n",
" print(f\"Genetic file: {os.path.basename(genetic_file_path)}\")\n",
" \n",
" # 3. Load the data files\n",
" clinical_df = pd.read_csv(clinical_file_path, sep='\\t', index_col=0)\n",
" genetic_df = pd.read_csv(genetic_file_path, sep='\\t', index_col=0)\n",
" \n",
" # 4. Print clinical data columns for inspection\n",
" print(\"\\nClinical data columns:\")\n",
" print(clinical_df.columns.tolist())\n",
" \n",
" # Print basic information about the datasets\n",
" print(f\"\\nClinical data shape: {clinical_df.shape}\")\n",
" print(f\"Genetic data shape: {genetic_df.shape}\")\n",
" \n",
" # Check if we have both gene and trait data\n",
" is_gene_available = genetic_df.shape[0] > 0\n",
" is_trait_available = clinical_df.shape[0] > 0\n",
" \n",
"else:\n",
" print(f\"No suitable directory found for {trait}.\")\n",
" is_gene_available = False\n",
" is_trait_available = False\n",
"\n",
"# Record the data availability\n",
"validate_and_save_cohort_info(\n",
" is_final=False,\n",
" cohort=\"TCGA\",\n",
" info_path=json_path,\n",
" is_gene_available=is_gene_available,\n",
" is_trait_available=is_trait_available\n",
")\n",
"\n",
"# Exit if no suitable directory was found\n",
"if not matched_dir:\n",
" print(\"Skipping this trait as no suitable data was found.\")"
]
}
],
"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
}
|