Download output/preprocess/Autoinflammatory_Disorders/code/TCGA.py from Liu-Hy/GenoTEX: direct link, hf CLI and curl.
- Browser
- Download file 5.1 kB
-
https://huggingface.co/datasets/Liu-Hy/GenoTEX/resolve/main/output/preprocess/Autoinflammatory_Disorders/code/TCGA.py
- Command line
-
hf download hf://datasets/Liu-Hy/GenoTEX/output/preprocess/Autoinflammatory_Disorders/code/TCGA.py
-
curl -L -o TCGA.py https://huggingface.co/datasets/Liu-Hy/GenoTEX/resolve/main/output/preprocess/Autoinflammatory_Disorders/code/TCGA.py
5.1 kB
| # Path Configuration | |
| from tools.preprocess import * | |
| # Processing context | |
| trait = "Autoinflammatory_Disorders" | |
| # Input paths | |
| tcga_root_dir = "../DATA/TCGA" | |
| # Output paths | |
| out_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/TCGA.csv" | |
| out_gene_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/gene_data/TCGA.csv" | |
| out_clinical_data_file = "./output/z1/preprocess/Autoinflammatory_Disorders/clinical_data/TCGA.csv" | |
| json_path = "./output/z1/preprocess/Autoinflammatory_Disorders/cohort_info.json" | |
| # Step 1: Initial Data Loading | |
| import os | |
| import pandas as pd | |
| # Discover available TCGA cohort directories | |
| available_dirs = [d for d in os.listdir(tcga_root_dir) if os.path.isdir(os.path.join(tcga_root_dir, d))] | |
| # Try to find a TCGA cohort relevant to Autoinflammatory Disorders (unlikely among cancer cohorts) | |
| keywords = [ | |
| "autoinflammatory", "auto-inflammatory", "autoinflammation", "autoinflamm", | |
| "periodic_fever", "periodic-fever", "fmf", "traps", "hids", "caps", "nlrp", "inflam" | |
| ] | |
| matches = [] | |
| for d in available_dirs: | |
| name_l = d.lower() | |
| score = sum(1 for k in keywords if k in name_l) | |
| if score > 0: | |
| # Prefer more keyword hits and shorter names (more specific) | |
| matches.append((score, -len(d), d)) | |
| if not matches: | |
| # No suitable TCGA cohort for autoinflammatory disorders; record and skip | |
| validate_and_save_cohort_info( | |
| is_final=False, | |
| cohort="TCGA", | |
| info_path=json_path, | |
| is_gene_available=False, | |
| is_trait_available=False | |
| ) | |
| selected_dir = None | |
| clinical_df = pd.DataFrame() | |
| genetic_df = pd.DataFrame() | |
| else: | |
| # Select the best match | |
| matches.sort(reverse=True) | |
| selected_dir = matches[0][2] | |
| if selected_dir: | |
| cohort_dir = os.path.join(tcga_root_dir, selected_dir) | |
| clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) | |
| clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, compression='infer', low_memory=False) | |
| genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, compression='infer', low_memory=False) | |
| print(list(clinical_df.columns)) | |
| # Step 2: Initial Data Loading | |
| import os | |
| import pandas as pd | |
| # Use the provided list of subdirectories but ensure they exist on disk | |
| provided_subdirs = [ | |
| 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)', 'TCGA_Uterine_Carcinosarcoma_(UCS)', | |
| 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)', 'TCGA_Testicular_Cancer_(TGCT)', | |
| 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)', 'TCGA_Rectal_Cancer_(READ)', | |
| 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)', | |
| 'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)', | |
| 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)', | |
| 'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)', | |
| 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', | |
| 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)', 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', | |
| 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)', 'TCGA_Glioblastoma_(GBM)', | |
| 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)', 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', | |
| 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)', 'TCGA_Breast_Cancer_(BRCA)', | |
| 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)', 'TCGA_Adrenocortical_Cancer_(ACC)', | |
| 'TCGA_Acute_Myeloid_Leukemia_(LAML)' | |
| ] | |
| available_dirs = [d for d in provided_subdirs if os.path.isdir(os.path.join(tcga_root_dir, d))] | |
| # Search for directories matching autoinflammatory disorders (unlikely in TCGA cancer cohorts) | |
| keywords = [ | |
| "autoinflammatory", "auto-inflammatory", "autoinflammation", "autoinflamm", | |
| "periodic_fever", "periodic-fever", "fmf", "traps", "hids", "caps", "nlrp", "inflam" | |
| ] | |
| matches = [] | |
| for d in available_dirs: | |
| name_l = d.lower() | |
| score = sum(1 for k in keywords if k in name_l) | |
| if score > 0: | |
| matches.append((score, -len(d), d)) | |
| if not matches: | |
| # No suitable TCGA cohort for Autoinflammatory Disorders; record and skip | |
| validate_and_save_cohort_info( | |
| is_final=False, | |
| cohort="TCGA", | |
| info_path=json_path, | |
| is_gene_available=False, | |
| is_trait_available=False | |
| ) | |
| selected_dir = None | |
| clinical_df = pd.DataFrame() | |
| genetic_df = pd.DataFrame() | |
| else: | |
| # Select the most specific match (more keywords, shorter name) | |
| matches.sort(reverse=True) | |
| selected_dir = matches[0][2] | |
| # If a directory was selected, locate files and load data | |
| if selected_dir: | |
| cohort_dir = os.path.join(tcga_root_dir, selected_dir) | |
| clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir) | |
| clinical_df = pd.read_csv(clinical_file_path, sep='\t', index_col=0, compression='infer', low_memory=False) | |
| genetic_df = pd.read_csv(genetic_file_path, sep='\t', index_col=0, compression='infer', low_memory=False) | |
| print(list(clinical_df.columns)) |