|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Parkinsons_Disease" |
|
cohort = "GSE101534" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Parkinsons_Disease" |
|
in_cohort_dir = "../DATA/GEO/Parkinsons_Disease/GSE101534" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Parkinsons_Disease/GSE101534.csv" |
|
out_gene_data_file = "./output/preprocess/3/Parkinsons_Disease/gene_data/GSE101534.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Parkinsons_Disease/clinical_data/GSE101534.csv" |
|
json_path = "./output/preprocess/3/Parkinsons_Disease/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("\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 = 0 |
|
age_row = None |
|
gender_row = None |
|
|
|
|
|
def convert_trait(value): |
|
if not isinstance(value, str): |
|
return None |
|
value = value.lower().split(': ')[-1] |
|
if value == 'patient': |
|
return 1 |
|
elif value == 'healthy': |
|
return 0 |
|
return None |
|
|
|
def convert_age(value): |
|
return None |
|
|
|
def convert_gender(value): |
|
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 |
|
) |
|
|
|
|
|
if trait_row is not None: |
|
selected_clinical = geo_select_clinical_features( |
|
clinical_df=clinical_data, |
|
trait=trait, |
|
trait_row=trait_row, |
|
convert_trait=convert_trait |
|
) |
|
|
|
|
|
preview = preview_df(selected_clinical) |
|
print("Preview of clinical data:", preview) |
|
|
|
|
|
selected_clinical.to_csv(out_clinical_data_file) |
|
|
|
genetic_data = get_genetic_data(matrix_file_path) |
|
|
|
|
|
print("Data structure and head:") |
|
print(genetic_data.head()) |
|
|
|
print("\nShape:", genetic_data.shape) |
|
|
|
print("\nFirst 20 row IDs (gene/probe identifiers):") |
|
print(list(genetic_data.index)[:20]) |
|
|
|
|
|
print("\nFirst 5 column names:") |
|
print(list(genetic_data.columns)[:5]) |
|
|
|
|
|
|
|
requires_gene_mapping = True |
|
|
|
with gzip.open(soft_file_path, 'rt') as f: |
|
in_table = False |
|
table_lines = [] |
|
for i, line in enumerate(f): |
|
if '!Platform_table_begin' in line: |
|
in_table = True |
|
table_lines.append(line) |
|
continue |
|
if in_table and '!Platform_table_end' in line: |
|
break |
|
if in_table: |
|
table_lines.append(line) |
|
if i < 5: |
|
print(line.strip()) |
|
|
|
|
|
table_content = ''.join(table_lines) |
|
gene_annotation = pd.read_csv(io.StringIO(table_content), sep='\t', comment='!') |
|
|
|
|
|
print("\nColumn names:") |
|
print(gene_annotation.columns) |
|
|
|
print("\nPreview of gene annotation data:") |
|
print(preview_df(gene_annotation)) |
|
|
|
gene_annotation = get_gene_annotation(soft_file_path) |
|
|
|
|
|
|
|
|
|
print("Column names in gene annotation data:") |
|
print(gene_annotation.columns.tolist()) |
|
|
|
print("\nSample of gene annotation data:") |
|
print(gene_annotation.head().to_dict('records')) |
|
|
|
|
|
gb_acc_patterns = gene_annotation['GB_ACC'].dropna().str.extract(r'(^[A-Z]{2}_)')[0].value_counts() |
|
print("\nDistribution of GB_ACC identifier types:") |
|
print(gb_acc_patterns) |
|
|
|
|
|
total = len(gene_annotation) |
|
with_gb = gene_annotation['GB_ACC'].notna().sum() |
|
print(f"\nTotal entries: {total}") |
|
print(f"Entries with GB_ACC: {with_gb} ({(with_gb/total)*100:.1f}%)") |
|
|
|
gene_annotation = get_gene_annotation(soft_file_path) |
|
|
|
|
|
mapping_df = gene_annotation[['ID', 'GB_ACC']].dropna() |
|
|
|
|
|
def get_gene_from_refseq(acc): |
|
if pd.isna(acc): |
|
return None |
|
|
|
acc = acc.split('.')[0] |
|
if acc.startswith(('NM_', 'NR_')): |
|
return acc |
|
return None |
|
|
|
mapping_df['Gene'] = mapping_df['GB_ACC'].apply(get_gene_from_refseq) |
|
mapping_df = mapping_df[['ID', 'Gene']].dropna() |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_data, mapping_df) |
|
|
|
print("Gene expression data shape after mapping:", gene_data.shape) |
|
if len(gene_data) > 0: |
|
print("\nFirst few gene symbols:", list(gene_data.index)[:10]) |
|
print("\nPreview of gene expression values:") |
|
print(gene_data.iloc[:5, :5]) |
|
|
|
selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0) |
|
|
|
|
|
trait_biased, clinical_df_processed = judge_and_remove_biased_features(selected_clinical_df, trait) |
|
|
|
|
|
note = "Gene mapping failed - no valid gene expression data obtained." |
|
validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=False, |
|
is_trait_available=True, |
|
is_biased=trait_biased, |
|
df=clinical_df_processed, |
|
note=note |
|
) |
|
|
|
|