File size: 4,172 Bytes
f811ee7 |
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 |
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Lactose_Intolerance"
cohort = "GSE136395"
# Input paths
in_trait_dir = "../DATA/GEO/Lactose_Intolerance"
in_cohort_dir = "../DATA/GEO/Lactose_Intolerance/GSE136395"
# Output paths
out_data_file = "./output/preprocess/3/Lactose_Intolerance/GSE136395.csv"
out_gene_data_file = "./output/preprocess/3/Lactose_Intolerance/gene_data/GSE136395.csv"
out_clinical_data_file = "./output/preprocess/3/Lactose_Intolerance/clinical_data/GSE136395.csv"
json_path = "./output/preprocess/3/Lactose_Intolerance/cohort_info.json"
# Get file paths for soft and matrix files
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
# Get background info and clinical data from matrix file
background_info, clinical_data = get_background_and_clinical_data(matrix_file)
# Get unique values for each clinical feature row
clinical_features = get_unique_values_by_row(clinical_data)
# Print background info
print("Background Information:")
print(background_info)
print("\nClinical Features and Sample Values:")
print(json.dumps(clinical_features, indent=2))
# 1. Gene Expression Data Availability
# Based on background info mentioning "Microarray analysis" and "skeletal muscle biopsies",
# this dataset contains gene expression data
is_gene_available = True
# 2. Variable Availability and Data Type Conversion
# 2.1 Data Availability
# Lactose intolerance status cannot be determined from this dataset
trait_row = None
# Age data is available at key 2
age_row = 2
# Gender data is available at key 0
gender_row = 0
# 2.2 Data Type Conversion Functions
def convert_trait(x):
return None
def convert_age(x):
try:
# Extract value after colon and convert to float
age = float(x.split(': ')[1])
# Filter out obviously wrong values (like age=5)
if age < 18 or age > 120:
return None
return age
except:
return None
def convert_gender(x):
try:
# Extract value after colon
gender = int(x.split(': ')[1])
# Convert to match our encoding (female=0, male=1)
# The dataset uses opposite encoding (female=1, male=0)
return 1 - gender
except:
return None
# 3. Save metadata
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
)
# 4. Skip clinical feature extraction since trait_row is None
# Extract gene expression data from matrix file
genetic_data = get_genetic_data(matrix_file)
# Print first 20 row IDs
print("First 20 gene/probe IDs:")
print(genetic_data.index[:20].tolist())
# Based on the gene identifiers shown, they appear to be probe IDs from an array platform
# The format "16650001" etc. are numeric probe IDs rather than standard HGNC gene symbols
# This will require mapping to proper gene symbols
requires_gene_mapping = True
# Extract gene annotation from SOFT file
gene_annotation = get_gene_annotation(soft_file)
# Preview column names and first few values
print("Gene Annotation Preview:")
print(preview_df(gene_annotation))
# Based on the IDs shown in genetic_data and gene_annotation,
# the 'ID' column contains probe IDs matching genetic_data's index
# and 'gene_assignment' column contains gene symbol information
mapping_df = get_gene_mapping(gene_annotation, 'ID', 'gene_assignment')
# Apply mapping to convert probe-level data to gene-level data
gene_data = apply_gene_mapping(genetic_data, mapping_df)
# Save gene expression data
gene_data.to_csv(out_gene_data_file)
# Since trait data is not available, create a DataFrame with just gene data
linked_data = gene_data.T # Transpose to have samples as rows
is_biased = True # Dataset is biased due to lack of trait information
note = "Dataset lacks trait (Lactose_Intolerance) information"
is_usable = validate_and_save_cohort_info(
is_final=True,
cohort=cohort,
info_path=json_path,
is_gene_available=True,
is_trait_available=False,
is_biased=is_biased,
df=linked_data,
note=note
) |