|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Adrenocortical_Cancer" |
|
cohort = "GSE67766" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Adrenocortical_Cancer" |
|
in_cohort_dir = "../DATA/GEO/Adrenocortical_Cancer/GSE67766" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Adrenocortical_Cancer/GSE67766.csv" |
|
out_gene_data_file = "./output/preprocess/3/Adrenocortical_Cancer/gene_data/GSE67766.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Adrenocortical_Cancer/clinical_data/GSE67766.csv" |
|
json_path = "./output/preprocess/3/Adrenocortical_Cancer/cohort_info.json" |
|
|
|
|
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
background_info, _ = get_background_and_clinical_data(matrix_file, |
|
prefixes_a=['!Series_title', '!Series_summary', |
|
'!Series_overall_design', '!Series_type', |
|
'!Series_relation'], |
|
prefixes_b=None) |
|
|
|
print("Initial Dataset Information:") |
|
print(background_info) |
|
print("\nChecking for subseries...\n") |
|
|
|
|
|
subseries = None |
|
if 'SuperSeries' in background_info: |
|
for line in background_info.split('\n'): |
|
if '!Series_relation\t' in line: |
|
matches = re.finditer(r'GSE\d+', line) |
|
for match in matches: |
|
potential_subseries = match.group(0) |
|
if potential_subseries != cohort: |
|
subseries_dir = os.path.join(in_trait_dir, potential_subseries) |
|
if os.path.exists(subseries_dir): |
|
print(f"Found valid subseries: {potential_subseries}") |
|
subseries = potential_subseries |
|
break |
|
|
|
|
|
if subseries: |
|
in_cohort_dir = os.path.join(in_trait_dir, subseries) |
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
print(f"\nUsing subseries data from: {in_cohort_dir}\n") |
|
else: |
|
print("\nNo valid subseries found, using original data\n") |
|
|
|
|
|
background_info, clinical_data = get_background_and_clinical_data(matrix_file) |
|
|
|
|
|
sample_characteristics = get_unique_values_by_row(clinical_data) |
|
|
|
|
|
print("Final Dataset Information:") |
|
print(f"{background_info}\n") |
|
|
|
print("Sample Characteristics:") |
|
for feature, values in sample_characteristics.items(): |
|
print(f"Feature: {feature}") |
|
print(f"Values: {values}\n") |
|
|
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
|
|
|
|
trait_row = None |
|
age_row = None |
|
gender_row = None |
|
|
|
|
|
|
|
def convert_trait(x): |
|
if x is None or pd.isna(x): |
|
return None |
|
value = str(x).split(':')[-1].strip() |
|
|
|
return None |
|
|
|
def convert_age(x): |
|
if x is None or pd.isna(x): |
|
return None |
|
value = str(x).split(':')[-1].strip() |
|
|
|
return None |
|
|
|
def convert_gender(x): |
|
if x is None or pd.isna(x): |
|
return None |
|
value = str(x).split(':')[-1].strip().lower() |
|
|
|
return None |
|
|
|
|
|
|
|
validate_and_save_cohort_info(is_final=False, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=is_gene_available, |
|
is_trait_available=False) |
|
|
|
|
|
|
|
|
|
gene_data = get_genetic_data(matrix_file) |
|
|
|
|
|
print("Shape of gene expression data:", gene_data.shape) |
|
print("\nFirst few rows of data:") |
|
print(gene_data.head()) |
|
print("\nFirst 20 gene/probe identifiers:") |
|
print(gene_data.index[:20]) |
|
|
|
|
|
import gzip |
|
with gzip.open(matrix_file, 'rt', encoding='utf-8') as f: |
|
lines = [] |
|
for i, line in enumerate(f): |
|
if "!series_matrix_table_begin" in line: |
|
|
|
for _ in range(5): |
|
lines.append(next(f).strip()) |
|
break |
|
print("\nFirst few lines after matrix marker in raw file:") |
|
for line in lines: |
|
print(line) |
|
|
|
|
|
requires_gene_mapping = True |
|
|
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
gene_annotation = get_gene_annotation(soft_file) |
|
|
|
|
|
print("Gene annotation shape:", gene_annotation.shape) |
|
print("\nGene annotation preview:") |
|
print(preview_df(gene_annotation)) |
|
|
|
print("\nNumber of non-null values in each column:") |
|
print(gene_annotation.count()) |
|
|
|
|
|
print("\nSample mapping columns ('ID' and 'Symbol'):") |
|
print("\nFirst 5 rows:") |
|
print(gene_annotation[['ID', 'Symbol']].head().to_string()) |
|
|
|
print("\nNote: Gene mapping will use:") |
|
print("'ID' column: Probe identifiers") |
|
print("'Symbol' column: Contains gene symbol information") |
|
|
|
|
|
|
|
|
|
|
|
mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol') |
|
|
|
|
|
gene_data = apply_gene_mapping(gene_data, mapping) |
|
|
|
|
|
print("Shape of probe-level data:", gene_data.shape) |
|
print("\nShape after mapping to genes:", gene_data.shape) |
|
print("\nFirst few rows of gene expression data:") |
|
print(gene_data.head()) |
|
print("\nFirst few gene symbols:") |
|
print(gene_data.index[:10]) |
|
|
|
gene_data = normalize_gene_symbols_in_index(gene_data) |
|
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
|
gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
|
|
|
|
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, |
|
df=gene_data, |
|
note="Dataset contains only cell line data (SW-13) without clinical information" |
|
) |
|
|
|
|