Skip to content

Improve DeSide package accessibility with NumPy/Pandas-style imports#4

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-f8f9f9a1-ff82-4711-8cf7-d046a92944b9
Draft

Improve DeSide package accessibility with NumPy/Pandas-style imports#4
Copilot wants to merge 3 commits intomainfrom
copilot/fix-f8f9f9a1-ff82-4711-8cf7-d046a92944b9

Conversation

Copy link

Copilot AI commented Aug 21, 2025

This PR transforms the DeSide package to be as accessible as popular scientific Python packages like NumPy and Pandas, addressing user requests for simplified one-line usage patterns.

Problem

Previously, users had to remember complex nested import paths to use DeSide functionality:

# Before: Complex nested imports required
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

Solution

Now users can import DeSide like NumPy/Pandas with simple one-line patterns:

# After: Simple NumPy/Pandas-style imports
import deside as ds

# All functionality accessible at package level
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'])

Key Improvements

📦 Package-Level Access

  • 52 functions/classes now accessible directly from package root (was 0 before)
  • Comprehensive __init__.py exposing core functionality across all modules
  • Proper __all__ list for clean namespace management

🚀 Ultra-Simple Convenience Functions

Added 4 wrapper functions for common workflows:

# 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'])

✅ Backward Compatibility

All existing import patterns continue to work unchanged:

# Still works exactly as before
from deside.decon_cf import DeSide
from deside.utility.read_file import ReadH5AD

🛡️ Robust Error Handling

Missing dependencies show helpful error messages instead of cryptic import failures:

import deside as ds
ds.ReadH5AD('data.h5ad')  # Clear message: "Install with: pip install deside[full]"

What's Included

Core Classes Exposed

  • ds.DeSide - Main deconvolution model
  • ds.ReadH5AD / ds.ReadExp - Data reading classes
  • ds.BulkGEPGenerator / ds.SingleCellTypeGEPGenerator - Simulation classes

Utility Functions Exposed

  • Data preprocessing: ds.filter_gene_by_expression_log_mean(), ds.log2_transform()
  • Format conversion: ds.log_exp2cpm(), ds.non_log2log_cpm()
  • Evaluation: ds.calculate_rmse(), ds.calculate_r2(), ds.calculate_mae()
  • File operations: ds.check_dir(), ds.read_df()

Visualization Functions

  • ds.plot_gene_exp(), ds.compare_y_y_pred_plot(), ds.plot_pca()

Enhanced Documentation

  • Updated README with simple usage examples
  • Comprehensive example files demonstrating one-line patterns
  • Test suite ensuring backward compatibility and accessibility

Testing

  • ✅ All 52 exposed functions accessible via ds.function_name
  • ✅ Backward compatibility maintained
  • ✅ Robust error handling for missing dependencies
  • ✅ Comprehensive test suite added

This change dramatically improves the user experience, making DeSide as approachable as NumPy (import numpy as np) or Pandas (import pandas as pd), while maintaining full backward compatibility.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits August 21, 2025 13:50
Co-authored-by: OnlyBelter <16537617+OnlyBelter@users.noreply.github.com>
Co-authored-by: OnlyBelter <16537617+OnlyBelter@users.noreply.github.com>
Copilot AI changed the title [WIP] Please review this package and help me improve the accessibility. For example, users can use it by one line code, just like using other wide-spread python packages like NumPy or Pandas. Improve DeSide package accessibility with NumPy/Pandas-style imports Aug 21, 2025
Copilot AI requested a review from OnlyBelter August 21, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants