Skip to content

Commit

Permalink
Documentation nni
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Jan 30, 2020
1 parent 2930692 commit d129c3f
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
52 changes: 52 additions & 0 deletions docs/api/nni.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Gotree: toolkit and api for phylogenetic tree manipulation

## API

### nni

Merging two trees

```go
package main

import (
"fmt"
"os"

"github.com/evolbioinfo/gotree/io/newick"
"github.com/evolbioinfo/gotree/tree"
)

func main() {
var t *tree.Tree
var f *os.File
var err error

if f, err = os.Open("t1.nw"); err != nil {
panic(err)
}
defer f.Close()
if t, err = newick.NewParser(f).Parse(); err != nil {
panic(err)
}

r := &tree.NNIRearranger{}

r.Rearrange(t, func(re tree.Rearrangement) bool {
if err = re.Apply(); err != nil {
return false
}
if err = t.CheckTreePostOrder(); err != nil {
return false
}
fmt.Println(t.Newick())
if err = re.Undo(); err != nil {
return false
}
if err = t.CheckTreePostOrder(); err != nil {
return false
}
return true
})
}
```
54 changes: 54 additions & 0 deletions docs/commands/nni.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Gotree: toolkit and api for phylogenetic tree manipulation

## Commands

### nni
This command generates all NNI neighbors from a given tree.

#### Usage

```
Usage:
gotree nni [flags]
Flags:
-h, --help help for nni
-i, --input string Input Tree (default "stdin")
-o, --output string NNI output tree file (default "stdout")
Global Flags:
--format string Input tree format (newick, nexus, or phyloxml) (default "newick")
```

#### Example

* Generates NNI neighbors

```
echo "(n1_1,n1_2,(n2_1,n2_2)n2)n1;" | gotree nni
```

It should give the following trees:
```
(n1_1,n2_2,(n2_1,n1_2)n2)n1;
(n1_1,n2_1,(n1_2,n2_2)n2)n1;
```


Tree:
```
n1_1 ---------------+ +--------------- n2_1
|----------------|
n1_2 ---------------+ +--------------- n2_2
```

NNIs:
```
n1_1 ---------------+ +--------------- n2_1
|----------------|
n2_2 ---------------+ +--------------- n1_2
n1_1 ---------------+ +--------------- n1_2
|----------------|
n2_1 ---------------+ +--------------- n2_2
```
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Command | Subcommand
-- | yuletree | Randomly generates Yule-Harding trees
[matrix](commands/matrix.md) ([api](api/matrix.md)) | | Prints distance matrix associated to the input tree
[merge](commands/merge.md) ([api](api/merge.md)) | | Merges two rooted trees
[nni](commands/nni.md) ([api](api/nni.md)) | | Generates all NNI neighbors from a given tree
[prune](commands/prune.md) ([api](api/prune.md)) | | Removes tips of input trees
[reformat](commands/reformat.md) ([api](api/reformat.md)) | | Reformats input file
-- | newick | Reformats input file (nexus, newick, phyloxml) into newick
Expand Down

0 comments on commit d129c3f

Please sign in to comment.