-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2930692
commit d129c3f
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters