<p>Both the <a href="http://etetoolkit.org/docs/latest/index.html" rel="nofollow noreferrer">ETE Toolkit</a> and <a href="https://dendropy.org/#" rel="nofollow noreferrer">DendroPy</a> offer methods of node removal and reattachment - I would think it would be easy enough to hack together an NNI movement function with them. </p>

<p>You could also investigate the source code of <a href="https://biopython.org/wiki/Phylo" rel="nofollow noreferrer">BioPython's</a> <code>NNITreeSearcher()</code> function.</p>

CC BY-SA 4.0
2018-09-10T16:53:55.703Z
I have used biopython among them, but my concern is to return all the trees which are reconstructed before the best tree is reached, and biopython NNITreeSearcher() results one best scored tree.
Sidra Younas
CC BY-SA 4.0
2018-09-10T17:01:19.910Z
That is why I suggested searching the source code to see if you can find the code controlling the NNI moves and use that.
NatWH
CC BY-SA 4.0
2018-09-11T06:07:56.497Z
I have studies biopython module and I found that `_get_neighbors()` function generates all NNI neighbor trees of the given tree.
Sidra Younas
CC BY-SA 4.0
2018-09-10T10:34:18.140Z
2018-09-10T10:34:18.140Z
NatWH
<p>I am working on protein sequence data files for reconstructing phylogenetic tree and I need to generate all <strong>NNI-neighbours</strong> of the tree (two trees are NNI-neighbours if one can be transformed into another by one nearest neighbour interchange operation). Is there any python <strong>package/sorce code</strong> I can access to, which can retrieve all NNI neighbors of a tree.
Earlier I have used biopython 1.72 to generate tree from my dataset. But for now I'm looking for a python package which can do NNI search on my tree and return all NNI-neighbors.</p>

<python><phylogenetics>
python package for NNI neighbors
# python package for NNI neighbors

(Asked by: username_0 on 2018-09-09)

I am working on protein sequence data files for reconstructing phylogenetic tree and I need to generate all **NNI-neighbours** of the tree (two trees are NNI-neighbours if one can be transformed into another by one nearest neighbour interchange operation). Is there any python **package/sorce code** I can access to, which can retrieve all NNI neighbors of a tree.
Earlier I have used biopython 1.72 to generate tree from my dataset. But for now I'm looking for a python package which can do NNI search on my tree and return all NNI-neighbors.

**Tags:** python, phylogenetics

---

## 1 answers

### Answer by username_1 on 2018-09-10. Score: 2

Both the [ETE Toolkit](http://etetoolkit.org/docs/latest/index.html) and [DendroPy](https://dendropy.org/#) offer methods of node removal and reattachment - I would think it would be easy enough to hack together an NNI movement function with them.

You could also investigate the source code of [BioPython's](https://biopython.org/wiki/Phylo) `NNITreeSearcher()` function.

> **Comments:**
> **username_0**: I have used biopython among them, but my concern is to return all the trees which are reconstructed before the best tree is reached, and biopython NNITreeSearcher() results one best scored tree.  
> **username_1**: That is why I suggested searching the source code to see if you can find the code controlling the NNI moves and use that.  
> **username_0**: I have studies biopython module and I found that `_get_neighbors()` function generates all NNI neighbor trees of the given tree.  

---

