|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Von_Hippel_Lindau" |
|
cohort = "GSE33093" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Von_Hippel_Lindau" |
|
in_cohort_dir = "../DATA/GEO/Von_Hippel_Lindau/GSE33093" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Von_Hippel_Lindau/GSE33093.csv" |
|
out_gene_data_file = "./output/preprocess/3/Von_Hippel_Lindau/gene_data/GSE33093.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Von_Hippel_Lindau/clinical_data/GSE33093.csv" |
|
json_path = "./output/preprocess/3/Von_Hippel_Lindau/cohort_info.json" |
|
|
|
|
|
soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
background_info, clinical_data = get_background_and_clinical_data(matrix_file_path) |
|
|
|
|
|
print("Background Information:") |
|
print(background_info) |
|
print("\nClinical Data Shape:", clinical_data.shape) |
|
print("\nFirst few rows of Clinical Data:") |
|
print(clinical_data.head()) |
|
|
|
print("\nSample Characteristics:") |
|
|
|
unique_values_dict = get_unique_values_by_row(clinical_data) |
|
for row, values in unique_values_dict.items(): |
|
print(f"\n{row}:") |
|
print(values) |
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
|
|
trait_row = None |
|
age_row = None |
|
gender_row = None |
|
|
|
|
|
def convert_trait(x): |
|
|
|
return None |
|
|
|
def convert_age(x): |
|
|
|
return None |
|
|
|
def convert_gender(x): |
|
|
|
return None |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
|
|
|
|
genetic_data = get_genetic_data(matrix_file_path) |
|
|
|
|
|
print("Shape of genetic data:", genetic_data.shape) |
|
print("\nFirst 5 rows with sample columns:") |
|
print(genetic_data.head()) |
|
print("\nFirst 20 gene/probe IDs:") |
|
print(list(genetic_data.index[:20])) |
|
|
|
|
|
print("\nFirst few lines of raw matrix file:") |
|
with gzip.open(matrix_file_path, 'rt') as f: |
|
for i, line in enumerate(f): |
|
if i < 10: |
|
print(line.strip()) |
|
elif "!series_matrix_table_begin" in line: |
|
print("\nFound table marker at line", i) |
|
|
|
for _ in range(3): |
|
print(next(f).strip()) |
|
break |
|
|
|
|
|
requires_gene_mapping = True |
|
|
|
gene_annotation = get_gene_annotation(soft_file_path, prefixes=['!Platform_table_begin', '!Platform_table_end']) |
|
|
|
|
|
print("Gene annotation column names:") |
|
print(gene_annotation.columns.tolist()) |
|
|
|
print("\nGene annotation preview:") |
|
preview = preview_df(gene_annotation) |
|
print(preview) |
|
|
|
|
|
print("\nChecking raw SOFT file content around platform table:") |
|
with gzip.open(soft_file_path, 'rt') as f: |
|
in_platform_table = False |
|
for i, line in enumerate(f): |
|
if '!Platform_table_begin' in line: |
|
print(f"\nFound table begin at line {i}:") |
|
in_platform_table = True |
|
|
|
for _ in range(5): |
|
print(next(f).strip()) |
|
break |
|
|
|
platform_data_lines = [] |
|
with gzip.open(soft_file_path, 'rt') as f: |
|
in_platform_table = False |
|
for line in f: |
|
if '!Platform_table_begin' in line: |
|
in_platform_table = True |
|
continue |
|
elif '!Platform_table_end' in line: |
|
in_platform_table = False |
|
break |
|
elif in_platform_table: |
|
platform_data_lines.append(line.strip()) |
|
|
|
|
|
if len(platform_data_lines) > 0: |
|
|
|
platform_data = pd.read_csv(io.StringIO('\n'.join(platform_data_lines)), sep='\t', low_memory=False) |
|
|
|
|
|
print("Platform data columns:", platform_data.columns.tolist()) |
|
print("\nFirst few rows of platform data:") |
|
print(platform_data.head()) |
|
|
|
|
|
id_col = [col for col in platform_data.columns if 'ID' in col.upper()][0] if any('ID' in col.upper() for col in platform_data.columns) else None |
|
gene_col = [col for col in platform_data.columns if 'GENE' in col.upper() and 'SYMBOL' in col.upper()][0] if any('GENE' in col.upper() and 'SYMBOL' in col.upper() for col in platform_data.columns) else None |
|
|
|
if id_col and gene_col: |
|
mapping_df = get_gene_mapping(platform_data, prob_col=id_col, gene_col=gene_col) |
|
gene_data = apply_gene_mapping(genetic_data, mapping_df) |
|
|
|
|
|
if gene_data is not None: |
|
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
|
gene_data.to_csv(out_gene_data_file) |
|
print("\nGene data shape:", gene_data.shape) |
|
print("First few genes and their expression values:") |
|
print(gene_data.head()) |
|
else: |
|
print("Could not identify ID and Gene Symbol columns in platform data") |
|
gene_data = None |
|
else: |
|
print("Failed to extract platform table with probe-gene mappings") |
|
gene_data = None |