Liu-Hy's picture
Add files using upload-large-folder tool
ba45cf6 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Hypothyroidism"
cohort = "GSE32445"
# Input paths
in_trait_dir = "../DATA/GEO/Hypothyroidism"
in_cohort_dir = "../DATA/GEO/Hypothyroidism/GSE32445"
# Output paths
out_data_file = "./output/preprocess/3/Hypothyroidism/GSE32445.csv"
out_gene_data_file = "./output/preprocess/3/Hypothyroidism/gene_data/GSE32445.csv"
out_clinical_data_file = "./output/preprocess/3/Hypothyroidism/clinical_data/GSE32445.csv"
json_path = "./output/preprocess/3/Hypothyroidism/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
# The series title and description suggest this is a study involving gene regulation,
# so it's likely to have gene expression data
is_gene_available = True
# 2. Variable Availability and Data Type Conversion
# 2.1 Data Availability
# Trait: Not directly available in characteristics - cannot be inferred from strain alone
trait_row = None
# Age: Available in row 2
age_row = 2
# Gender: Available in row 1
gender_row = 1
# 2.2 Data Type Conversion
# Trait converter not needed since trait data not available
def convert_trait(x):
return None
# Age converter - continuous
def convert_age(x):
try:
# Extract value after colon and remove 'months'/'years'
value = x.split(':')[1].strip()
value = value.lower().replace('months', '').replace('years', '').strip()
return float(value)
except:
return None
# Gender converter - binary (female=0, male=1)
def convert_gender(x):
try:
value = x.split(':')[1].strip().lower()
if 'female' in value:
return 0
elif 'male' in value:
return 1
return None
except:
return None
# 3. Save Metadata
# Initial filtering - trait data not available so dataset will be filtered out
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
# 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())
# The row IDs are Illumina probe IDs (starting with 'ILMN_') rather than human gene symbols
# These need to be mapped to gene symbols for analysis
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())
# Look at general data statistics
print("\nData shape:", gene_metadata.shape)
# Display non-NaN value counts for key gene identifier columns
print("\nNumber of non-NaN values in key columns:")
for col in ['Gene Symbol', 'Gene Title']:
print(f"{col}: {gene_metadata[col].notna().sum()}")
# Preview rows with actual gene information
print("\nPreview of rows with gene information:")
gene_rows = gene_metadata[gene_metadata['Gene Symbol'].notna()].head()
print(json.dumps(preview_df(gene_rows), indent=2))
# Extract gene mapping information from gene annotation data
# Split multiple gene symbols and expand them
mapping_data = gene_metadata.loc[:, ['ID', 'Gene Symbol']]
mapping_data = mapping_data.dropna()
# Rename column to match expected name in apply_gene_mapping function
mapping_data = mapping_data.rename(columns={'Gene Symbol': 'Gene'})
# Apply the mapping to get gene-level expression data
gene_data = apply_gene_mapping(genetic_data, mapping_data)
# Preview the results
print("\nNumber of genes after mapping:", len(gene_data))
print("\nFirst few gene symbols:", gene_data.index[:10].tolist())
# Create an empty DataFrame to represent unusable data
empty_df = pd.DataFrame()
# Record that this dataset is unusable
note = "Dataset lacks trait information and gene mapping failed to produce any valid gene expression data."
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, # Set to True to indicate the data is unusable
df=empty_df, # Provide empty DataFrame instead of None
note=note
)