|
| 1 | +# File Size Limit Feature |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The batch processing functions in both `preprocess run` and `explore batch` now support a `--max-file-size-mb` option to skip files that exceed a specified size limit. This is particularly useful when processing large datasets with memory constraints. |
| 6 | + |
| 7 | +## Usage Examples |
| 8 | + |
| 9 | +### Limit to 12 GB (12,000 MB) |
| 10 | + |
| 11 | +For batch preprocessing with the `preprocess run` command: |
| 12 | + |
| 13 | +```bash |
| 14 | +uv run preprocess run \ |
| 15 | + --batch-mode \ |
| 16 | + --input-dir ./data/input \ |
| 17 | + --output-dir ./data/output \ |
| 18 | + --max-file-size-mb 12000 |
| 19 | +``` |
| 20 | + |
| 21 | +For metadata extraction with the `explore batch` command: |
| 22 | + |
| 23 | +```bash |
| 24 | +uv run explore batch ./data/input \ |
| 25 | + --output-dir ./data/output/meta \ |
| 26 | + --max-file-size-mb 12000 |
| 27 | +``` |
| 28 | + |
| 29 | +### How It Works |
| 30 | + |
| 31 | +1. **File Size Check**: Before processing each file, the command checks the file size in megabytes. |
| 32 | + |
| 33 | +2. **Skip Large Files**: If the file size exceeds the specified limit, the file is skipped with a clear message: |
| 34 | + ``` |
| 35 | + [1/5] Skipping dataset_name.h5ad (file size 15000.00 MB exceeds limit 12000.00 MB) |
| 36 | + ``` |
| 37 | + |
| 38 | +3. **Logging**: The skip event is logged with: |
| 39 | + - `message_type`: `skipping_large_file` |
| 40 | + - `file_size_mb`: Actual file size |
| 41 | + - `max_file_size_mb`: The configured limit |
| 42 | + |
| 43 | +4. **Continue Processing**: Other files in the batch continue to be processed normally. |
| 44 | + |
| 45 | +## Size Conversions |
| 46 | + |
| 47 | +For reference, here are common size conversions to MB: |
| 48 | + |
| 49 | +| Size | MB Value | Command Example | |
| 50 | +|------|----------|-----------------| |
| 51 | +| 1 GB | 1024 MB | `--max-file-size-mb 1024` | |
| 52 | +| 5 GB | 5120 MB | `--max-file-size-mb 5120` | |
| 53 | +| 10 GB | 10240 MB | `--max-file-size-mb 10240` | |
| 54 | +| 12 GB | 12288 MB | `--max-file-size-mb 12288` | |
| 55 | +| 50 GB | 51200 MB | `--max-file-size-mb 51200` | |
| 56 | +| 100 GB | 102400 MB | `--max-file-size-mb 102400` | |
| 57 | + |
| 58 | +Note: You can use approximate values like `12000` instead of the exact `12288` for simplicity. |
| 59 | + |
| 60 | +## Complete Example |
| 61 | + |
| 62 | +Process all h5ad files in a directory, but skip files larger than 12 GB: |
| 63 | + |
| 64 | +```bash |
| 65 | +# Preprocessing pipeline with file size limit |
| 66 | +uv run preprocess run \ |
| 67 | + --batch-mode \ |
| 68 | + --input-dir ./data/input \ |
| 69 | + --output-dir ./data/output \ |
| 70 | + --max-file-size-mb 12000 \ |
| 71 | + --skip-existing \ |
| 72 | + --chunk-size 10000 \ |
| 73 | + --compression zstd \ |
| 74 | + --compression-level 3 |
| 75 | +``` |
| 76 | + |
| 77 | +```bash |
| 78 | +# Metadata extraction with file size limit |
| 79 | +uv run explore batch ./data/input \ |
| 80 | + --output-dir ./data/output/meta \ |
| 81 | + --max-file-size-mb 12000 \ |
| 82 | + --skip-existing \ |
| 83 | + --summary \ |
| 84 | + --max-threads 4 |
| 85 | +``` |
| 86 | + |
| 87 | +## Integration with Other Features |
| 88 | + |
| 89 | +The file size limit check works seamlessly with other batch processing features: |
| 90 | + |
| 91 | +- **Skip Existing (`--skip-existing`)**: Files are checked for size before checking if output exists |
| 92 | +- **Logging**: All skipped files are logged with detailed information |
| 93 | +- **Batch Summaries**: Skipped files (due to size) appear in batch processing summaries with failure status |
| 94 | +- **Error Handling**: File size checks happen before processing, preventing out-of-memory errors |
| 95 | + |
| 96 | +## Benefits |
| 97 | + |
| 98 | +1. **Memory Management**: Prevent out-of-memory crashes on systems with limited RAM |
| 99 | +2. **Selective Processing**: Process only datasets that fit your resource constraints |
| 100 | +3. **Batch Safety**: Continue processing other files even when some are too large |
| 101 | +4. **Clear Feedback**: Immediate notification when files are skipped due to size |
| 102 | +5. **Flexible Limits**: Set any size limit that matches your system's capabilities |
| 103 | + |
0 commit comments