File size: 4,178 Bytes
7623c74 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "LDL_Cholesterol_Levels"
cohort = "GSE28893"
# Input paths
in_trait_dir = "../DATA/GEO/LDL_Cholesterol_Levels"
in_cohort_dir = "../DATA/GEO/LDL_Cholesterol_Levels/GSE28893"
# Output paths
out_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/GSE28893.csv"
out_gene_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/gene_data/GSE28893.csv"
out_clinical_data_file = "./output/preprocess/3/LDL_Cholesterol_Levels/clinical_data/GSE28893.csv"
json_path = "./output/preprocess/3/LDL_Cholesterol_Levels/cohort_info.json"
# Get paths for relevant files
soft_path, matrix_path = geo_get_relevant_filepaths(in_cohort_dir)
# Extract background info and clinical data
background_info, clinical_data = get_background_and_clinical_data(matrix_path)
# Get unique values for each clinical feature
sample_chars = get_unique_values_by_row(clinical_data)
# Print dataset background information
print("Background Information:")
print(background_info)
print("\nClinical Features Overview:")
print(json.dumps(sample_chars, indent=2))
# 1. Gene Expression Data Availability
# The dataset is from Illumina Expression Array and is about gene expression in liver tissue
is_gene_available = True
# 2.1 Data Availability
# From background info, this study includes eQTLs related to LDL cholesterol levels
# But trait values are not directly available in sample characteristics
trait_row = None
# Age data is available in row 1
age_row = 1
# Gender data is available in row 2
gender_row = 2
# 2.2 Data Type Conversion Functions
def convert_trait(x):
# Not needed since trait data is not available
return None
def convert_age(x):
try:
# Extract number after colon
age = int(x.split(': ')[1])
return age
except:
return None
def convert_gender(x):
try:
# Extract value after colon and convert to binary
gender = x.split(': ')[1]
if gender == 'F':
return 0
elif gender == 'M':
return 1
return None
except:
return None
# 3. Save metadata - initial filtering
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. Skip clinical feature extraction since trait_row is None
# Get gene expression data
genetic_data = get_genetic_data(matrix_path)
# Preview raw data structure
print("First few rows of the raw data:")
print(genetic_data.head())
print("\nShape of the data:")
print(genetic_data.shape)
# Print first 20 row IDs to verify data structure
print("\nFirst 20 probe/gene identifiers:")
print(list(genetic_data.index)[:20])
# These IDs start with "ILMN_" which indicates they are Illumina probe IDs, not gene symbols
requires_gene_mapping = True
# Extract gene annotation data from SOFT file
gene_metadata = get_gene_annotation(soft_path)
# Preview annotation data structure
print("Gene annotation data preview:")
print(preview_df(gene_metadata))
# 1. 'ID' column in metadata matches ILMN probe IDs in expression data
# 'Symbol' column contains the gene symbols
# 2. Get gene mapping data
mapping_data = get_gene_mapping(gene_metadata, "ID", "Symbol")
# 3. Convert probe-level measurements to gene-level expression
gene_data = apply_gene_mapping(genetic_data, mapping_data)
# Preview result
print("Gene expression data preview:")
print(gene_data.head())
print("\nShape after mapping:", gene_data.shape)
# 1. Normalize gene symbols
gene_data = normalize_gene_symbols_in_index(gene_data)
gene_data.to_csv(out_gene_data_file)
# Since we previously determined trait data is not available (trait_row = None),
# we cannot proceed with data linking and quality assessment
# We need to validate this cohort as not usable
note = "The dataset contains gene expression data but lacks LDL cholesterol level measurements"
is_usable = validate_and_save_cohort_info(
is_final=False, # Use initial filtering since we can't do final validation
cohort=cohort,
info_path=json_path,
is_gene_available=True,
is_trait_available=False
) |