From d129c3f5abf63abdaa5a81c5aaa10fb32f5633f8 Mon Sep 17 00:00:00 2001 From: Frederic Lemoine Date: Thu, 30 Jan 2020 19:26:43 +0100 Subject: [PATCH] Documentation nni --- docs/api/nni.md | 52 ++++++++++++++++++++++++++++++++++++++++++ docs/commands/nni.md | 54 ++++++++++++++++++++++++++++++++++++++++++++ docs/index.md | 1 + 3 files changed, 107 insertions(+) create mode 100644 docs/api/nni.md create mode 100644 docs/commands/nni.md diff --git a/docs/api/nni.md b/docs/api/nni.md new file mode 100644 index 0000000..bc866b4 --- /dev/null +++ b/docs/api/nni.md @@ -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 + }) +} +``` diff --git a/docs/commands/nni.md b/docs/commands/nni.md new file mode 100644 index 0000000..66465c2 --- /dev/null +++ b/docs/commands/nni.md @@ -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 +``` diff --git a/docs/index.md b/docs/index.md index 656ebec..6603c8a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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