Liu-Hy's picture
Add files using upload-large-folder tool
e6817b9 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Height"
cohort = "GSE101709"
# Input paths
in_trait_dir = "../DATA/GEO/Height"
in_cohort_dir = "../DATA/GEO/Height/GSE101709"
# Output paths
out_data_file = "./output/preprocess/3/Height/GSE101709.csv"
out_gene_data_file = "./output/preprocess/3/Height/gene_data/GSE101709.csv"
out_clinical_data_file = "./output/preprocess/3/Height/clinical_data/GSE101709.csv"
json_path = "./output/preprocess/3/Height/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)
# Get unique values for each clinical feature
unique_values_dict = get_unique_values_by_row(clinical_data)
# Print background information
print("Background Information:")
print(background_info)
print("\nSample Characteristics:")
print(json.dumps(unique_values_dict, indent=2))
# 1. Gene Expression Data Availability
# Based on background info mentioning "gene expression" and Illumina HT12 BeadChip, this is gene expression data
is_gene_available = True
# 2.1 Data Availability
# Height (trait) and clinical data are mentioned in screening questionnaire from background info
trait_row = None # Height not available in sample characteristics
age_row = 1 # Age can be inferred from "age group" field
gender_row = None # Gender not found in sample characteristics
# 2.2 Data Type Conversion Functions
def convert_age(x):
if not isinstance(x, str):
return None
value = x.split(": ")[-1].strip()
if value == "Young":
return 25.5 # Mid-point of 21-30 range mentioned in background
elif value in ["Older", "Frail"]:
return 70 # Approximation for >65 age group
return None
# 3. Save Metadata
is_trait_available = trait_row is not None
validate_and_save_cohort_info(
is_final=False,
cohort=cohort,
info_path=json_path,
is_gene_available=is_gene_available,
is_trait_available=is_trait_available
)
# 4. Clinical Feature Extraction
# Skip as trait_row is None
# Extract gene expression data from the matrix file
genetic_data = get_genetic_data(matrix_file_path)
# Print first 20 row IDs
print("First 20 row IDs:")
print(genetic_data.index[:20].tolist())
# These are Illumina probe IDs (ILMN_) which need to be mapped to human gene symbols
requires_gene_mapping = True
# Extract gene annotation data from SOFT file
gene_metadata = get_gene_annotation(soft_file_path)
# Display information about the annotation data
print("Column names:")
print(gene_metadata.columns.tolist())
print("\nPreview of first few rows:")
print(json.dumps(preview_df(gene_metadata), indent=2))
# 1. ID and Symbol columns contain the mapping information
prob_col = 'ID' # ILMN_* identifiers match those in gene expression data
gene_col = 'Symbol' # Contains gene symbols
# 2. Get gene mapping dataframe
mapping_data = get_gene_mapping(gene_metadata, prob_col, gene_col)
# 3. Apply gene mapping to convert probe-level data to gene expression data
gene_data = apply_gene_mapping(genetic_data, mapping_data)
# Preview the converted gene data
print("Preview of mapped gene expression data:")
print(f"Number of genes: {len(gene_data)}")
print("First few gene symbols:")
print(gene_data.index[:10].tolist())
# 1. Normalize gene symbols and save
gene_data = normalize_gene_symbols_in_index(gene_data)
gene_data.to_csv(out_gene_data_file)
# Create empty clinical features dataframe since trait_row is None
clinical_features = pd.DataFrame()
# 2. Link clinical and genetic data (will contain only gene data since clinical_features is empty)
linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
# 3. Handle missing values (will maintain only gene data since we have no trait)
linked_data = handle_missing_values(linked_data, trait)
# 4. Judge biased features (set is_biased=True since we have no trait data)
is_biased = True
# 5. Final validation and save metadata
note = "Dataset lacks height measurements, though gene expression data is available"
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=is_biased,
df=linked_data,
note=note
)
# 6. Save the linked data only if it's usable (which it won't be due to lack of trait data)
if is_usable:
os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
linked_data.to_csv(out_data_file)