Liu-Hy's picture
Add files using upload-large-folder tool
6f366b0 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Substance_Use_Disorder"
cohort = "GSE273630"
# Input paths
in_trait_dir = "../DATA/GEO/Substance_Use_Disorder"
in_cohort_dir = "../DATA/GEO/Substance_Use_Disorder/GSE273630"
# Output paths
out_data_file = "./output/preprocess/3/Substance_Use_Disorder/GSE273630.csv"
out_gene_data_file = "./output/preprocess/3/Substance_Use_Disorder/gene_data/GSE273630.csv"
out_clinical_data_file = "./output/preprocess/3/Substance_Use_Disorder/clinical_data/GSE273630.csv"
json_path = "./output/preprocess/3/Substance_Use_Disorder/cohort_info.json"
# Get file paths
soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
# Get background info and clinical data
background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
print("Background Information:")
print(background_info)
print("\nSample Characteristics:")
# Get dictionary of unique values per row
unique_values_dict = get_unique_values_by_row(clinical_data)
for row, values in unique_values_dict.items():
print(f"\n{row}:")
print(values)
# 1. Gene Expression Data Availability
# Based on background info mentioning "dopamine-regulated inflammatory genes" and NanoString technology
is_gene_available = True
# 2.1 Variable Row Identification
# We know from background info study has METH+/- groups, but this info is not in sample characteristics
# Age and gender are constant (all males, age 35-44)
trait_row = None # Not available in sample characteristics
age_row = None # Constant: all 35-44 years old
gender_row = None # Constant: all males
# 2.2 Conversion Functions (defined but won't be used since data not available)
def convert_trait(x):
return None
def convert_age(x):
return None
def convert_gender(x):
return None
# 3. Save Metadata
validate_and_save_cohort_info(
is_final=False,
cohort=cohort,
info_path=json_path,
is_gene_available=is_gene_available,
is_trait_available=False
)
# 4. Clinical Feature Extraction
# Skip since trait_row is None (no clinical data available in sample characteristics)
# Get gene expression data from matrix file
genetic_data = get_genetic_data(matrix_file_path)
# Examine data structure
print("Data structure and head:")
print(genetic_data.head())
print("\nShape:", genetic_data.shape)
print("\nFirst 20 row IDs (gene/probe identifiers):")
print(list(genetic_data.index)[:20])
# Get a few column names to verify sample IDs
print("\nFirst 5 column names:")
print(list(genetic_data.columns)[:5])
# The row IDs appear to be standard human gene symbols
# Examples: ABAT, ABL1, ACAA1, ACHE show typical gene symbol format
requires_gene_mapping = False
# 1. Normalize gene symbols in gene expression data
genetic_data = normalize_gene_symbols_in_index(genetic_data)
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
genetic_data.to_csv(out_gene_data_file)
print("\nGene data shape (normalized gene-level):", genetic_data.shape)
# Since trait data was not available in sample characteristics, we cannot proceed
# with clinical data linkage and remaining steps
is_usable = validate_and_save_cohort_info(
is_final=True,
cohort=cohort,
info_path=json_path,
is_gene_available=True,
is_trait_available=False,
is_biased=True, # Biased since no clinical data available
df=genetic_data, # Pass actual genetic data
note="Gene expression data is available but lacks clinical information for phenotype association studies."
)
# This step is not necessary since gene identifiers are already in human gene symbol format
# From the previous data preview, we can see IDs like ABAT, ABL1, ACAA1 which are standard gene symbols
# No mapping is needed, and gene_data can directly use the genetic_data from previous step
gene_data = genetic_data