Liu-Hy's picture
Add files using upload-large-folder tool
1f52ac2 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Melanoma"
cohort = "GSE148949"
# Input paths
in_trait_dir = "../DATA/GEO/Melanoma"
in_cohort_dir = "../DATA/GEO/Melanoma/GSE148949"
# Output paths
out_data_file = "./output/preprocess/3/Melanoma/GSE148949.csv"
out_gene_data_file = "./output/preprocess/3/Melanoma/gene_data/GSE148949.csv"
out_clinical_data_file = "./output/preprocess/3/Melanoma/clinical_data/GSE148949.csv"
json_path = "./output/preprocess/3/Melanoma/cohort_info.json"
# Get file paths for SOFT and matrix files
soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
# Get background info and clinical data from the matrix file
background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
# Create dictionary of unique values for each feature
unique_values_dict = get_unique_values_by_row(clinical_data)
# Print the information
print("Dataset Background Information:")
print(background_info)
print("\nSample Characteristics:")
for feature, values in unique_values_dict.items():
print(f"\n{feature}:")
print(values)
# 1. Gene Expression Data Availability
# Looking at series title and summary, this appears to be a microarray study of breast cancer models
# with gene expression data from Agilent arrays
is_gene_available = True
# 2.1 Data Availability
# From sample characteristics, this dataset contains reference samples from various cell lines
# including melanoma (line 6). However it's just a reference pool, not experimental samples
# so no real trait/phenotype data is available
trait_row = None
age_row = None
gender_row = None
# 3. Save Metadata
# Only has gene expression data but no trait data for analysis
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. Skip clinical feature extraction since trait_row is None
# Extract genetic data matrix
genetic_data = get_genetic_data(matrix_file_path)
# Print first 20 row IDs to examine data type
print("First 20 row IDs:")
print(list(genetic_data.index)[:20])
# After examining the IDs and confirming this is gene expression data:
is_gene_available = True
# Save updated metadata
validate_and_save_cohort_info(
is_final=False,
cohort=cohort,
info_path=json_path,
is_gene_available=is_gene_available,
is_trait_available=(trait_row is not None)
)
genetic_data.to_csv(out_gene_data_file)
# Based on my biomedical expertise, looking at the gene identifiers:
# The numeric identifiers (e.g. '41334', '41335' etc.) and '1/2-SBSRNA4'
# appear to be probe IDs or array feature numbers rather than standard human gene symbols
# Gene symbols would typically be in formats like 'BRAF', 'NRAS', 'TP53'
# Therefore this data requires mapping from probe IDs to gene symbols
requires_gene_mapping = True
# Extract gene annotation data from platform section of SOFT file
gene_metadata = get_gene_annotation(soft_file_path)
# Check available columns to find probe ID and gene symbol mappings
print("\nGene annotation data shape:", gene_metadata.shape)
print("\nGene annotation columns:")
print(gene_metadata.columns)
# Preview first few rows to understand data structure
print("\nFirst few rows:")
print(gene_metadata.head())
# Look for probe ID patterns in each column
for col in gene_metadata.columns:
print(f"\nSample values from column '{col}':")
sample_vals = gene_metadata[col].head(10).tolist()
print(sample_vals)
# Based on the output, determine map_config
probe_col = None
gene_col = None
for col in gene_metadata.columns:
# Compare values to gene expression index
sample_vals = set(gene_metadata[col].astype(str).head(100))
genetic_ids = set(list(genetic_data.index)[:100])
overlap = sample_vals & genetic_ids
if len(overlap) > 0:
probe_col = col
break
# Print mapping column candidates
print("\nMapping columns found:")
print(f"Probe ID column: {probe_col}")
print(f"Gene Symbol column: {gene_col}")
# The index already contains gene symbols (e.g. A1BG, A1CF) as seen in output
gene_data = genetic_data.copy()
# Normalize gene symbols to ensure consistency
gene_data = normalize_gene_symbols_in_index(gene_data)
print("\nFirst 10 rows of processed gene expression data:")
print(gene_data.head(10))
# 1. Normalize gene symbols and save gene data
gene_data = normalize_gene_symbols_in_index(genetic_data)
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
gene_data.to_csv(out_gene_data_file)
# No clinical data available, so can't perform associative analysis
# But provide gene_data for validation and indicate bias
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, # Can't do association analysis without trait data
df=gene_data, # Provide gene expression data for validation
note="Dataset contains only reference samples from cell lines. No trait data available for analysis."
)
# Skip saving linked data since dataset is not usable without trait data