Metadata-Version: 2.1
Name: tanglegram
Version: 0.2.0
Summary: Plot simple tanglegrams from two dendrograms
Home-page: https://github.com/schlegelp/tanglegram
Author: Philipp Schlegel
Author-email: pms70@cam.ac.uk
License: GNU GPL V3
Keywords: python tanglegram dendrogram
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3
Description-Content-Type: text/markdown
License-File: LICENSE

tanglegram
==========
Uses scipy and matplotlib to plot simple tanglegrams. Inspired by the amazing [dendextend](https://github.com/talgalili/dendextend) by Tal Galili.

## Installation
First, get [PIP](https://pip.pypa.io/en/stable/installing/) and then run in terminal:

```
pip3 install tanglegram -U
```

To install the bleeding-edge version from Github you can run:

```
pip3 install git+git://github.com/schlegelp/tanglegram@master
```

**Attention**: on Windows, the dependencies (i.e. Numpy, Pandas and SciPy) will likely fail to install automatically. Your best bet is to get a Python distribution that already includes them (e.g. [Anaconda](https://www.continuum.io/downloads)).


#### Dependencies
Installing via [PIP](https://pip.pypa.io/en/stable/installing/) should install all external dependencies. You may run into problems on Windows though. In that case, you need to install dependencies manually, here is a list of dependencies (check out `install_requires` in [setup.py](https://raw.githubusercontent.com/schlegelp/PyMaid/master/setup.py) for version info):

- [Pandas](http://pandas.pydata.org/)
- [SciPy](http://www.scipy.org)
- [Numpy](http://www.scipy.org)
- [Matplotlib](http://www.matplotlib.org)

## How it works

`tanglegram` exposes three functions:

1. `tanglegram.plot` plots a tanglegram (optionally untangling)
2. `tanglegram.entanglement` measures the entanglement between two linkages
3. `tanglegram.untangle` rotates dendrograms to minimize entanglement

```Python
import tanglegram as tg
import matplotlib.pyplot as plt
import pandas as pd

# Generate two distance matrices and just switch labels in one
labelsA= ['A', 'B', 'C', 'D']
labelsB= ['B', 'A', 'C', 'D']
data = [[ 0,  .1,  .4, .3],
        [.1,   0,  .5, .6],
        [ .4, .5,   0, .2],
        [ .3, .6,  .2,  0]]

mat1 = pd.DataFrame(data,
                    columns=labelsA,
                    index=labelsA)

mat2 = pd.DataFrame(data,
                    columns=labelsB,
                    index=labelsB)

# Plot tanglegram
fig = tg.plot(mat1, mat2, sort=False)
plt.show()
```

<img src="https://user-images.githubusercontent.com/7161148/105351954-2ae19f80-5be5-11eb-9dad-2dd0fe83d44d.png" width="650">

```Python
# Plot again but this time try minimizing cross-over
fig = tg.plot(mat1, mat2, sort=True)
plt.show()
```

<img src="https://user-images.githubusercontent.com/7161148/105351772-e8b85e00-5be4-11eb-9343-db42f143ec68.png" width="650">


## Known Issues:
* layout does not scale well, i.e. small dendrograms look weird

## License:
This code is under GNU GPL V3


