Liu-Hy's picture
Add files using upload-large-folder tool
13fd1a3 verified
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "COVID-19"
cohort = "GSE216705"
# Input paths
in_trait_dir = "../DATA/GEO/COVID-19"
in_cohort_dir = "../DATA/GEO/COVID-19/GSE216705"
# Output paths
out_data_file = "./output/preprocess/3/COVID-19/GSE216705.csv"
out_gene_data_file = "./output/preprocess/3/COVID-19/gene_data/GSE216705.csv"
out_clinical_data_file = "./output/preprocess/3/COVID-19/clinical_data/GSE216705.csv"
json_path = "./output/preprocess/3/COVID-19/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 from the soft file since matrix file shows this is a SuperSeries
prefixes_background = ['!Series_title', '!Series_summary', '!Series_overall_design']
prefixes_clinical = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
background_info, clinical_data = filter_content_by_prefix(soft_file_path, prefixes_background, prefixes_clinical,
source_type='file', return_df_a=False, return_df_b=True)
# Extract unique characteristics values while removing prefixes
char_values = {}
for col in clinical_data.columns:
if '!Sample_characteristics_ch1' in str(col):
values = clinical_data[col].dropna()
values = values.str.replace('!Sample_characteristics_ch1 = ', '').unique()
# Group by characteristic type (e.g., tissue, cell type, etc.)
for val in values:
if ':' in val:
key, value = val.split(': ', 1)
if key not in char_values:
char_values[key] = set()
char_values[key].add(value)
# Print the information
print("Dataset Background Information:")
print(background_info)
print("\nSample Characteristics:")
for characteristic, values in char_values.items():
print(f"\n{characteristic}:")
print(list(values))
# 1. Gene Expression Data Availability
# Based on the title mentioning macrophages and GM-CSF, this likely contains gene expression data
is_gene_available = True
# 2. Variable Availability and Data Type Conversion
# Sample characteristics dictionary appears empty, so no clinical data available
trait_row = None
age_row = None
gender_row = None
def convert_trait(x):
pass
def convert_age(x):
pass
def convert_gender(x):
pass
# 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, indicating no clinical data available
# Extract genetic data matrix
genetic_data = get_genetic_data(matrix_file_path)
# Print first few rows with column names to examine data structure
print("Data preview:")
print("\nColumn names:")
print(list(genetic_data.columns)[:5])
print("\nFirst 5 rows:")
print(genetic_data.head())
print("\nShape:", genetic_data.shape)
# Verify this is gene expression data and check identifiers
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)
)
# Save gene expression data
genetic_data.to_csv(out_gene_data_file)
# Row indices appear to be probe IDs (e.g. 10338001) rather than human gene symbols
# These are Illumina probe IDs that need to be mapped to gene symbols
requires_gene_mapping = True
# Extract gene annotation data
gene_metadata = get_gene_annotation(soft_file_path)
# Preview column names and first few values
preview = preview_df(gene_metadata)
print("\nGene annotation columns and sample values:")
print(preview)
# Update gene availability status since we discovered this is mouse data
is_gene_available = False
# 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)
)