Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions ACCESSIBILITY_IMPROVEMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# DeSide Accessibility Improvement: Before vs After

## Problem Statement
Users requested that DeSide package be as accessible as NumPy or Pandas, allowing one-line imports and usage patterns.

## Before: Complex Import Patterns ❌

```python
# Users had to remember complex module paths
from deside.decon_cf import DeSide
from deside.utility.read_file import ReadH5AD, ReadExp
from deside.utility import check_dir, calculate_rmse, filter_gene_by_expression_log_mean
from deside.plot import compare_y_y_pred_plot, plot_gene_exp
from deside.simulation import BulkGEPGenerator

# Multiple import statements needed for basic workflow
```

## After: Simple NumPy/Pandas-like Usage ✅

```python
# Single import like NumPy/Pandas
import deside as ds

# Everything accessible at package level - 52 functions total!
model = ds.DeSide(model_dir='./models')
data = ds.ReadH5AD('data.h5ad')
rmse = ds.calculate_rmse(y_true, y_pred)
ds.plot_gene_exp(data, genes=['CD3D'])
ds.check_dir('./results')
```

## Ultra-Simple Convenience Functions 🚀

```python
import deside as ds

# Complete workflows in one line!
predictions = ds.quick_deconvolution('data.h5ad')
data = ds.load_and_preprocess('data.h5ad', filter_genes=True)
metrics = ds.evaluate_predictions('true.csv', 'pred.csv', plot_results=True)
model = ds.create_training_workflow('train.h5ad', ['T', 'B', 'Macro'])
```

## Key Improvements

### 1. **Package-Level Access** 📦
- **Before**: 0 functions accessible at package level
- **After**: 52 functions/classes accessible with `ds.function_name`

### 2. **Convenience Functions** 🛠️
Added 4 wrapper functions for common workflows:
- `quick_deconvolution()` - Complete deconvolution in one line
- `load_and_preprocess()` - Simplified data loading with preprocessing
- `evaluate_predictions()` - Easy evaluation with metrics and plots
- `create_training_workflow()` - Simplified model training

### 3. **Backward Compatibility** ✅
All existing import patterns still work:
```python
# Still works exactly as before
from deside.decon_cf import DeSide
from deside.utility.read_file import ReadH5AD
```

### 4. **Robust Error Handling** 🛡️
Missing dependencies show helpful error messages:
```python
import deside as ds
ds.ReadH5AD('data.h5ad') # Shows: "Install with: pip install deside[full]"
```

### 5. **Enhanced Documentation** 📚
- Updated README with simple usage examples
- Created comprehensive examples directory
- Added accessibility test suite

## Usage Comparison

### Data Loading & Preprocessing
```python
# Before (multiple imports needed)
from deside.utility.read_file import ReadH5AD
from deside.utility import filter_gene_by_expression_log_mean, check_dir

data_reader = ReadH5AD('data.h5ad')
expression_data = data_reader.get_df()
filtered_data = filter_gene_by_expression_log_mean(expression_data)
check_dir('./results')

# After (single import, direct access)
import deside as ds

data = ds.load_and_preprocess('data.h5ad') # One-liner!
ds.check_dir('./results')
```

### Model Training & Prediction
```python
# Before
from deside.decon_cf import DeSide
from deside.utility import check_dir

check_dir('./models')
model = DeSide(model_dir='./models')
# ... complex training setup ...
predictions = model.predict(input_file='test.h5ad')

# After
import deside as ds

predictions = ds.quick_deconvolution('test.h5ad') # One-liner!
# OR for custom training:
model = ds.create_training_workflow('train.h5ad', ['T', 'B', 'Macro'])
```

### Evaluation & Visualization
```python
# Before
from deside.utility import calculate_rmse, calculate_r2
from deside.plot import compare_y_y_pred_plot

rmse = calculate_rmse(y_true, y_pred)
r2 = calculate_r2(y_true, y_pred)
compare_y_y_pred_plot(y_true, y_pred, result_file_dir='./results')

# After
import deside as ds

metrics = ds.evaluate_predictions(y_true, y_pred, plot_results=True) # One-liner!
# OR individual functions:
rmse = ds.calculate_rmse(y_true, y_pred)
```

## Impact

✅ **Goal Achieved**: DeSide is now as accessible as NumPy/Pandas
✅ **One-line imports**: `import deside as ds`
✅ **52 functions** available at package level
✅ **4 convenience functions** for ultra-simple workflows
✅ **Backward compatibility** maintained
✅ **Enhanced user experience** with helpful error messages

Users can now use DeSide with the same simplicity as popular packages like NumPy and Pandas!
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,80 @@ python3 -m pip install --upgrade pip
pip install deside
```

## Quick Start

DeSide now supports one-line imports similar to NumPy and Pandas for improved accessibility:

```python
import deside as ds

# Create a DeSide model
model = ds.DeSide(model_dir='./models')

# Load data
data = ds.ReadH5AD('data.h5ad')
expression_matrix = data.get_df()

# Preprocess data
ds.check_dir('./results')
filtered_genes = ds.filter_gene_by_expression_log_mean(expression_matrix)

# Train model (example)
model.train_model(training_set_file_path=['training.h5ad'])

# Make predictions
predictions = model.predict(input_file='test.h5ad', output_file_path='predictions.csv')

# Evaluate results
rmse = ds.calculate_rmse(y_true, predictions)
r2 = ds.calculate_r2(y_true, predictions)

# Visualize results
ds.compare_y_y_pred_plot(y_true, predictions, result_file_dir='./results')
```

## Usage Examples
Usage examples can be found: [DeSide_mini_example](https://github.com/OnlyBelter/DeSide_mini_example)
Detailed usage examples can be found: [DeSide_mini_example](https://github.com/OnlyBelter/DeSide_mini_example)

Three examples are provided:
- Using pre-trained model
- Training a model from scratch
- Generating a synthetic dataset

### Available Functions at Package Level

DeSide now exposes 40+ functions directly at the package level for easy access:

**Core Classes:**
- `ds.DeSide` - Main deconvolution model
- `ds.ReadH5AD` - Read .h5ad files
- `ds.ReadExp` - Read expression data

**Data Preprocessing:**
- `ds.filter_gene_by_expression_log_mean()` - Filter genes by expression
- `ds.log2_transform()` - Log2 transformation
- `ds.center_value()` - Center data values

**Data Format Conversion:**
- `ds.log_exp2cpm()` - Convert log expression to CPM
- `ds.non_log2log_cpm()` - Convert non-log to log CPM

**Evaluation Metrics:**
- `ds.calculate_rmse()` - Root mean squared error
- `ds.calculate_r2()` - R-squared coefficient
- `ds.calculate_mae()` - Mean absolute error

**Visualization:**
- `ds.plot_gene_exp()` - Plot gene expression
- `ds.compare_y_y_pred_plot()` - Compare predictions vs truth
- `ds.plot_pca()` - PCA visualization

**Simulation:**
- `ds.BulkGEPGenerator` - Generate synthetic bulk data
- `ds.segment_generation_fraction()` - Generate cell proportions

And many more! See the full list with `dir(deside)` after importing.

## Documentation
For all detailed documentation, please check https://deside.readthedocs.io/. The documentation will demonstrate the usage of DeSide from the following aspects:
- Installation in a virtual environment
Expand Down
Loading