{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "49a1150d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:31:52.950278Z", "iopub.status.busy": "2025-03-25T08:31:52.950095Z", "iopub.status.idle": "2025-03-25T08:31:53.114459Z", "shell.execute_reply": "2025-03-25T08:31:53.114025Z" } }, "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 = \"Creutzfeldt-Jakob_Disease\"\n", "\n", "# Input paths\n", "tcga_root_dir = \"../../input/TCGA\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Creutzfeldt-Jakob_Disease/TCGA.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Creutzfeldt-Jakob_Disease/gene_data/TCGA.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Creutzfeldt-Jakob_Disease/clinical_data/TCGA.csv\"\n", "json_path = \"../../output/preprocess/Creutzfeldt-Jakob_Disease/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "0bb7174a", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "9cb1d690", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:31:53.115713Z", "iopub.status.busy": "2025-03-25T08:31:53.115574Z", "iopub.status.idle": "2025-03-25T08:31:53.121254Z", "shell.execute_reply": "2025-03-25T08:31:53.120741Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No suitable directory found for Creutzfeldt-Jakob_Disease.\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 Colon and Rectal Cancer\n", "subdirectories = os.listdir(tcga_root_dir)\n", "target_trait = trait.lower().replace(\"_\", \" \") # Convert to lowercase for case-insensitive matching\n", "\n", "# Start with no match, then find the best match based on similarity to target trait\n", "best_match = None\n", "best_match_score = 0\n", "\n", "for subdir in subdirectories:\n", " subdir_lower = subdir.lower()\n", " \n", " # Calculate a simple similarity score - more matching words = better match\n", " # This prioritizes exact matches over partial matches\n", " score = 0\n", " for word in target_trait.split():\n", " if word in subdir_lower:\n", " score += 1\n", " \n", " # Track the best match\n", " if score > best_match_score:\n", " best_match_score = score\n", " best_match = subdir\n", " print(f\"Found potential match: {subdir} (score: {score})\")\n", "\n", "# Use the best match if found\n", "if best_match:\n", " print(f\"Selected directory: {best_match}\")\n", " \n", " # 2. Get the clinical and genetic data file paths\n", " cohort_dir = os.path.join(tcga_root_dir, best_match)\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 best_match:\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 }