File size: 4,000 Bytes
3d17104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Data Preparation Scripts

Utility scripts for downloading and converting GEO (Gene Expression Omnibus) data to AnnData h5ad format.

## Scripts Overview

### 1. `check_data_status.py`
**Purpose:** Check which required datasets are present and ready for analysis.

**Usage:**
```bash
python3 scripts/data_prep/check_data_status.py
```

**Output:** 
- Lists all required data files and their presence status (✓/✗)
- Shows file sizes in GB
- Provides recommendations for missing datasets

### 2. `convert_series_matrix_to_h5ad.py`
**Purpose:** Convert a single GEO series matrix file to AnnData format.

**Handles:**
- Single .txt or .txt.gz series matrix files
- Automatic gzip decompression
- Sample metadata extraction
- Expression matrix parsing

**Usage:**
```bash
# After downloading GSE148842_series_matrix.txt.gz
python3 scripts/data_prep/convert_series_matrix_to_h5ad.py
```

**Input:** `squidward_study/public_01/series_matrix.txt.gz`  
**Output:** `squidward_study/public_01/pub_all_data.h5ad`

### 3. `convert_geo_to_h5ad.py`
**Purpose:** Convert multiple GEO GPL platform files to AnnData format with automatic merging.

**Handles:**
- Multiple GPL platforms (e.g., GPL18573, GPL24676)
- Metadata extraction (patient ID via regex, treatment conditions)
- Finding common genes across platforms
- Automatic dataset merging
- Sparse CSR matrix creation

**Usage:**
```bash
python3 scripts/data_prep/convert_geo_to_h5ad.py
```

**Input:** `squidward_study/public_01/GSE148842-GPL*.txt`  
**Output:** `squidward_study/public_01/pub_all_data.h5ad`

### 4. `convert_to_h5ad_v3.py`
**Purpose:** Manual regex-based GEO parser (more robust for edge cases).

**Advantages:**
- Uses explicit line-by-line parsing instead of pandas
- Better handling of quote characters and special formatting
- Good fallback when pandas CSV parsing fails

**Usage:**
```bash
python3 scripts/data_prep/convert_to_h5ad_v3.py
```

### 5. `simple_geo_to_h5ad.py`
**Purpose:** Simplified version using pandas for straightforward conversions.

**Features:**
- Direct pandas.read_csv usage
- Minimal dependencies
- Fast for well-formatted GEO files

**Usage:**
```bash
python3 scripts/data_prep/simple_geo_to_h5ad.py
```

## Data Pipeline Workflow

```
1. Download from GEO

2. Check data status
   python3 scripts/data_prep/check_data_status.py

3. Convert to h5ad (choose one)
   - Single file: convert_series_matrix_to_h5ad.py
   - Multiple platforms: convert_geo_to_h5ad.py
   - Edge cases: convert_to_h5ad_v3.py

4. Verify output
   - pub_all_data.h5ad should be created
   - Check dimensions and metadata

5. Proceed to preprocessing
   Notebooks in 03_fig4_drug_response/
```

## Sample Metadata Extraction

All converters extract:
- **Patient ID:** First 5 characters of sample title (e.g., "PW030")
- **Treatment/Condition:** Standardized values:
  - `vehicle` (DMSO controls)
  - `etoposide`
  - `panobinostat`
  - `RO4929097`
  - `Tazemetostat`
  - `Ispenisib`
  - `Ana-12`
  - `none`

## GEO Data Sources

**GSE148842** - GBM Drug Response Study
- Source: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE148842
- Platforms:
  - GPL18573 (Illumina NextSeq 500)
  - GPL24676 (Illumina NextSeq 550)
- Size: ~2.7 GB compressed

## Troubleshooting

| Issue | Solution |
|-------|----------|
| "Could not find series matrix file" | Download from GEO first; check file location |
| "ID_REF line not found" | Use convert_to_h5ad_v3.py (more robust) |
| Memory error with large files | Sparse matrix format reduces memory usage |
| Mismatched gene counts | Check for common genes across platforms |

## Output Format

All scripts produce AnnData (.h5ad) format with:
- **X:** Expression matrix (n_obs × n_vars) as sparse CSR matrix
- **obs:** Sample metadata (patient, condition, original sample name)
- **var:** Gene metadata (gene names)
- **Compression:** gzip for disk efficiency

Example dimensions:
- GBM data: ~50,000 cells × ~60,000 genes
- File size: ~200-300 MB (compressed)