Metadata-Version: 2.4
Name: netbalance
Version: 0.2.0
Summary: Balance and visualize multi-cluster interaction networks
Project-URL: Homepage, https://github.com/sobhanAhmadian/netbalance
Project-URL: Repository, https://github.com/sobhanAhmadian/netbalance
Project-URL: Issues, https://github.com/sobhanAhmadian/netbalance/issues
Author-email: sobhanAhmadian <sobhan.ahmadian.moghadam@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Sobhan Ahmadianmoghadam
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.11
Requires-Dist: matplotlib>=3.7
Requires-Dist: networkx>=3.0
Requires-Dist: numpy>=2.0
Description-Content-Type: text/markdown

# netbalance

**netbalance** is a Python library and CLI tool for balancing and visualizing multi-cluster interaction (association) networks.

## Installation

```bash
pip install netbalance
```

## Quick start

Balancing an interaction network using **entity-balanced sampling**:

```bash
cat data/virus-host.csv | netbalance --seed 0 --max-iter 1000
```

Balancing an interaction network using **uniform random sampling** with a 1:1 negative-to-positive ratio:

```bash
cat data/virus-host.csv | netbalance -m balanced --negative-ratio 1.0
```

Visualizing a bipartite network:

```bash
cat data/virus-host.csv | netbalance viz -o virus-host.png
```

## Data format

All inputs are CSVs where the first N columns are entity names (one per cluster) and the last column is a binary label (`1` = positive interaction, `0` = negative):

```
A,B,interaction
A1,B2,1
A1,B4,0
```

The `viz` subcommand requires exactly 2 entity columns (bipartite).

## Python API

If you prefer to use the Python API instead of the CLI, see the [example notebook](example.ipynb).

## Example usage

### Balancing and visualizing a virus-host interaction network

The following cammand uses the entity-balanced sampling method to balance a virus-host interaction network, then visualizes the balanced network as a bipartite graph.

```bash
cat data/virus-host.csv | netbalance --seed 0 --max-iter 20000 --delta 0.001| netbalance viz -o virus-host.png
```

The resulting graph is shown below:

![virus-host](virus-host.png)

### Entity-balanced sampling without the degree-ratio guided intialization

```bash
cat data/virus-host.csv | netbalance --seed 0 --max-iter 20000 --delta 0.001 --no-heuristic
```

