zyzhou110's picture
Upload: scripts/data_prep/README.md
3d17104 verified
# 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)