Spaces:
Sleeping
Sleeping
copilot-swe-agent[bot]
raylim
commited on
Commit
Β·
08925d1
1
Parent(s):
b955807
Add architecture documentation for refactored codebase
Browse filesCo-authored-by: raylim <3074310+raylim@users.noreply.github.com>
- ARCHITECTURE.md +94 -0
ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Mosaic Architecture
|
| 2 |
+
|
| 3 |
+
## Module Structure
|
| 4 |
+
|
| 5 |
+
The Mosaic application has been refactored for better readability and maintainability. The codebase is now organized into the following modules:
|
| 6 |
+
|
| 7 |
+
### Core Modules
|
| 8 |
+
|
| 9 |
+
#### `mosaic.gradio_app` (Main Entry Point)
|
| 10 |
+
- **Location**: `src/mosaic/gradio_app.py`
|
| 11 |
+
- **Purpose**: CLI entry point and command-line argument parsing
|
| 12 |
+
- **Responsibilities**:
|
| 13 |
+
- Command-line argument parsing
|
| 14 |
+
- Model downloading and initialization
|
| 15 |
+
- Single slide and batch processing CLI modes
|
| 16 |
+
- Launching the Gradio web UI
|
| 17 |
+
|
| 18 |
+
#### `mosaic.analysis`
|
| 19 |
+
- **Location**: `src/mosaic/analysis.py`
|
| 20 |
+
- **Purpose**: Core slide analysis logic
|
| 21 |
+
- **Responsibilities**:
|
| 22 |
+
- Tissue segmentation
|
| 23 |
+
- Feature extraction (CTransPath and Optimus)
|
| 24 |
+
- Feature filtering with marker classifier
|
| 25 |
+
- Aeon inference (cancer subtype prediction)
|
| 26 |
+
- Paladin inference (biomarker prediction)
|
| 27 |
+
- **Key Function**: `analyze_slide()`
|
| 28 |
+
|
| 29 |
+
#### `mosaic.ui` Package
|
| 30 |
+
- **Location**: `src/mosaic/ui/`
|
| 31 |
+
- **Purpose**: Gradio web interface components
|
| 32 |
+
- **Submodules**:
|
| 33 |
+
|
| 34 |
+
- **`ui.__init__.py`**: Exports the main `launch_gradio` function
|
| 35 |
+
|
| 36 |
+
- **`ui.app`**: Gradio interface definition
|
| 37 |
+
- UI layout and component definitions
|
| 38 |
+
- Event handlers for user interactions
|
| 39 |
+
- Multi-slide analysis workflow
|
| 40 |
+
- Key Functions: `launch_gradio()`, `analyze_slides()`, `set_cancer_subtype_maps()`
|
| 41 |
+
|
| 42 |
+
- **`ui.utils`**: UI utility functions
|
| 43 |
+
- Settings validation
|
| 44 |
+
- CSV file handling
|
| 45 |
+
- OncoTree API integration
|
| 46 |
+
- User session directory management
|
| 47 |
+
- Key Functions: `validate_settings()`, `load_settings()`, `get_oncotree_code_name()`, `create_user_directory()`
|
| 48 |
+
|
| 49 |
+
### Inference Modules
|
| 50 |
+
|
| 51 |
+
#### `mosaic.inference`
|
| 52 |
+
- **Location**: `src/mosaic/inference/`
|
| 53 |
+
- **Purpose**: ML model inference implementations
|
| 54 |
+
- **Submodules**:
|
| 55 |
+
- `aeon.py`: Cancer subtype inference
|
| 56 |
+
- `paladin.py`: Biomarker inference
|
| 57 |
+
- `data.py`: Data structures and utilities
|
| 58 |
+
|
| 59 |
+
## Code Organization Benefits
|
| 60 |
+
|
| 61 |
+
1. **Separation of Concerns**: UI, analysis, and CLI logic are now clearly separated
|
| 62 |
+
2. **Improved Maintainability**: Each module has a single, well-defined responsibility
|
| 63 |
+
3. **Better Testability**: Individual modules can be tested independently
|
| 64 |
+
4. **Enhanced Readability**: Reduced file sizes and clear module boundaries
|
| 65 |
+
5. **Reusability**: Analysis functions can be imported and used without UI dependencies
|
| 66 |
+
|
| 67 |
+
## Import Flow
|
| 68 |
+
|
| 69 |
+
```
|
| 70 |
+
gradio_app.main()
|
| 71 |
+
βββ download_and_process_models()
|
| 72 |
+
β βββ set_cancer_subtype_maps() [from ui.app]
|
| 73 |
+
β βββ get_oncotree_code_name() [from ui.utils]
|
| 74 |
+
βββ analyze_slide() [from analysis]
|
| 75 |
+
β βββ segment_tissue() [from mussel]
|
| 76 |
+
β βββ get_features() [from mussel]
|
| 77 |
+
β βββ filter_features() [from mussel]
|
| 78 |
+
β βββ run_aeon() [from inference]
|
| 79 |
+
β βββ run_paladin() [from inference]
|
| 80 |
+
βββ launch_gradio() [from ui]
|
| 81 |
+
βββ analyze_slides() [from ui.app]
|
| 82 |
+
β βββ analyze_slide() [from analysis]
|
| 83 |
+
βββ validate_settings() [from ui.utils]
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## File Size Comparison
|
| 87 |
+
|
| 88 |
+
| File | Original | Refactored | Change |
|
| 89 |
+
|------|----------|------------|--------|
|
| 90 |
+
| `gradio_app.py` | 843 lines | 230 lines | -73% |
|
| 91 |
+
| UI Components | - | 474 lines | +474 |
|
| 92 |
+
| Analysis Logic | - | 200 lines | +200 |
|
| 93 |
+
|
| 94 |
+
The refactoring distributed the original monolithic file into focused, maintainable modules while maintaining all functionality.
|