Metadata-Version: 2.1
Name: BMINet
Version: 0.1.1
Summary: Machine Learning and Graph based tool for detecting and analyzing Bone-Muscle Interactions
Home-page: https://github.com/Spencer-JRWang/BMINet
Author: Spencer Wang
Author-email: jrwangspencer@stu.suda.edu.cn
Keywords: python,BMINet,Interaction,Network,Bone-Muscle,windows,mac,linux
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: anyio==4.4.0
Requires-Dist: argon2-cffi==23.1.0
Requires-Dist: argon2-cffi-bindings==21.2.0
Requires-Dist: arrow==1.3.0
Requires-Dist: async-lru==2.0.4
Requires-Dist: attrs==24.2.0
Requires-Dist: babel==2.16.0
Requires-Dist: beautifulsoup4==4.12.3
Requires-Dist: bleach==6.1.0
Requires-Dist: catboost==1.2.5
Requires-Dist: certifi==2024.8.30
Requires-Dist: cffi==1.17.1
Requires-Dist: charset-normalizer==3.3.2
Requires-Dist: cloudpickle==3.0.0
Requires-Dist: python-louvain==0.16
Requires-Dist: contourpy==1.3.0
Requires-Dist: cycler==0.12.1
Requires-Dist: defusedxml==0.7.1
Requires-Dist: fastjsonschema==2.20.0
Requires-Dist: fonttools==4.53.1
Requires-Dist: fqdn==1.5.1
Requires-Dist: graphviz==0.20.3
Requires-Dist: h11==0.14.0
Requires-Dist: httpcore==1.0.5
Requires-Dist: httpx==0.27.2
Requires-Dist: ipywidgets==8.1.5
Requires-Dist: isoduration==20.11.0
Requires-Dist: joblib==1.4.2
Requires-Dist: json5==0.9.25
Requires-Dist: jsonpointer==3.0.0
Requires-Dist: jsonschema==4.23.0
Requires-Dist: jsonschema-specifications==2023.12.1
Requires-Dist: jupyter==1.1.1
Requires-Dist: jupyter-console==6.6.3
Requires-Dist: jupyter-events==0.10.0
Requires-Dist: jupyter-lsp==2.2.5
Requires-Dist: jupyter_server==2.14.2
Requires-Dist: jupyter_server_terminals==0.5.3
Requires-Dist: jupyterlab==4.2.5
Requires-Dist: jupyterlab_pygments==0.3.0
Requires-Dist: jupyterlab_server==2.27.3
Requires-Dist: jupyterlab_widgets==3.0.13
Requires-Dist: kiwisolver==1.4.5
Requires-Dist: lightgbm==4.5.0
Requires-Dist: llvmlite==0.43.0
Requires-Dist: MarkupSafe==2.1.5
Requires-Dist: matplotlib==3.9.2
Requires-Dist: mistune==3.0.2
Requires-Dist: nbclient==0.10.0
Requires-Dist: nbconvert==7.16.4
Requires-Dist: nbformat==5.10.4
Requires-Dist: networkx==3.3
Requires-Dist: notebook==7.2.2
Requires-Dist: notebook_shim==0.2.4
Requires-Dist: numba==0.60.0
Requires-Dist: numpy==1.26.0
Requires-Dist: overrides==7.7.0
Requires-Dist: pandas==2.2.2
Requires-Dist: pandocfilters==1.5.1
Requires-Dist: pillow==10.4.0
Requires-Dist: plotly==5.24.0
Requires-Dist: prometheus_client==0.20.0
Requires-Dist: pycparser==2.22
Requires-Dist: pyparsing==3.1.4
Requires-Dist: python-json-logger==2.0.7
Requires-Dist: pytz==2024.1
Requires-Dist: PyYAML==6.0.2
Requires-Dist: referencing==0.35.1
Requires-Dist: requests==2.32.3
Requires-Dist: rfc3339-validator==0.1.4
Requires-Dist: rfc3986-validator==0.1.1
Requires-Dist: rpds-py==0.20.0
Requires-Dist: scikit-learn==1.4.0
Requires-Dist: scipy==1.14.1
Requires-Dist: seaborn==0.13.2
Requires-Dist: Send2Trash==1.8.3
Requires-Dist: setuptools==73.0.1
Requires-Dist: shap==0.46.0
Requires-Dist: slicer==0.0.8
Requires-Dist: sniffio==1.3.1
Requires-Dist: soupsieve==2.6
Requires-Dist: tenacity==9.0.0
Requires-Dist: terminado==0.18.1
Requires-Dist: threadpoolctl==3.5.0
Requires-Dist: tinycss2==1.3.0
Requires-Dist: tqdm==4.66.5
Requires-Dist: types-python-dateutil==2.9.0.20240906
Requires-Dist: tzdata==2024.1
Requires-Dist: uri-template==1.3.0
Requires-Dist: urllib3==2.2.2
Requires-Dist: webcolors==24.8.0
Requires-Dist: webencodings==0.5.1
Requires-Dist: websocket-client==1.8.0
Requires-Dist: wheel==0.44.0
Requires-Dist: widgetsnbextension==4.0.13
Requires-Dist: xgboost==2.1.1


# Introduction of BMINet
![framework](Example/image.png)
Machine learning and network based tool for:
- Classify and predict different disease stages precisely
- Understand machenism using SHAP model explanation
- Detect Bone-Muscle Interact network and detect disease modules
# Install
## Dependency
- **Python>=3.9**
## Quick install
- Install from pypi: `pip install BMINet`
- Or install from GitHub: 
```
git clone https://github.com/Spencer-JRWang/BMINet
cd BMINet
pip install .
```
# Example Usage
- First, you should prepare your data (from CT or MRI etc.): [Example Data](https://github.com/Spencer-JRWang/BMINet/blob/main/Example/data.txt)
- Load your data
```python
import pandas as pd
df = pd.read_csv('Example/data.txt', sep='\t')
```
- Select features
```python
# Load FeatureSelector
from BMINet.Interaction import FeatureSelector
selector = FeatureSelector(core_name="LightGBM")
# Conduct feature selection from df
selected_features = selector.select(df)
```
> core_name should be "LightGBM", "XGBoost" or "CatBoost"

- Build linear formula model
```python
from BMINet.Model import Lasso_Formula
formula = Lasso_Formula(df, disease_pairs=("A", "B"))
print(formula)
```
> Also Ridge, ElasticNet and Simple Linear

- Build stacking model
```python
from BMINet.Interaction import StackingModel
# Load stacking model framework
'''
default: StackingModel(
    base_models = [
            ('LGBM', LGBMClassifier(verbose=-1, n_estimators=1000, max_depth=5)),
            ('XGBoost', XGBClassifier(n_estimators=1000, max_depth=5)),
            ('CatBoost', CatBoostClassifier(verbose=False, iterations=800, max_depth=5))
        ]), 
    meta_model = LogisticRegression()
'''
Model = StackingModel()
best_scores = Model.stacking_model_search(df, selected_features)
```
> Using default base model and meta model, you can also define it yourself

- Predict of each group
```python
# single predict
single_prediction_score = Model.single_predict("A vs B", [...], use_our_model=True)
# multiple predict
multiple_prediction_score = Model.multiple_predict_predict("A vs B", [[...], [...],], use_our_model=True)
```
> If you use `use_our model = True`, you are predicting disease staged based on our data and model
> 
> If you are researching on a brand new project, use `use_our_model = False`

- Basic machine learning plots
```python
from BMINet.plot import plot_ml_roc
plot_ml_roc(best_scores)
from BMINet.plot import plot_precision_recall
plot_precision_recall(best_scores)
from BMINet.plot import plot_score_histogram
plot_score_histogram(best_scores)
from BMINet.plot import plot_calibration_curve
plot_calibration_curve(best_scores)
```
- Model Explanation
```python
from BMINet.Interaction import SHAPVisualizer
# Load explanation class and train it
shap_visualizer = SHAPVisualizer(core_name="LightGBM")
shap_visualizer.train_model(df, selected_features)
# The dir you want to save the files
shap_visualizer.plot_shap('./Example')
shap_visualizer.plot_dependence('./Example')
```

- Network Construction
```python
# Load NetworkConstructor
from BMINet.Interaction import NetworkConstructor
network_constructor = NetworkConstructor(core_name="LightGBM", cutoff = 1.5)

# Construct sub-network list for each group
interactions = network_constructor.construct_network(df, selected_features)
# Construct conmbined network
combined_graph = network_constructor.compose_all(interactions)
# Remove isolated nodes from the network
Graph_BMI = network_constructor.remove_isolated_nodes(combined_graph)
# Save to .graphml file
network_constructor.save_graph(Graph_BMI, './Example')
```

- Network Analysis
```python
from BMINet.Interaction import NetworkMetrics
metrics_calculator = NetworkMetrics(Graph_BMI)
metrics = metrics_calculator.compute_metrics()
```

> You can see more Example usage at [here](https://github.com/Spencer-JRWang/BMINet/blob/main/Example.ipynb)

# Update Log
- 2024/9/5: Version `0.1.0`, fix CatBoost bug
- 2024/9/5: Version `0.1.1`, update prediction threholds
- 2024/11/8: Version `0.1.2`, update linear formula model
