[med-svn] [r-cran-phangorn] 01/04: New upstream version 2.2.0

Andreas Tille tille at debian.org
Thu Sep 7 10:02:45 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository r-cran-phangorn.

commit acb5880655e7a07649d1d754d84fa5ee5e102535
Author: Andreas Tille <tille at debian.org>
Date:   Thu Sep 7 11:52:56 2017 +0200

    New upstream version 2.2.0
---
 DESCRIPTION                                        |   15 +-
 MD5                                                |  239 ++--
 NAMESPACE                                          |   26 +-
 NEWS                                               |   21 +
 R/Coalescent.R                                     |   26 +
 R/Densi.R                                          |   50 +
 R/RcppExports.R                                    |    8 +
 R/SH.R                                             |   38 +-
 R/SOWH.R                                           |   49 +
 R/ancestral_pml.R                                  |   83 +-
 R/bootstrap.R                                      |  138 ++
 R/cladePar.R                                       |   27 +
 R/clanistic.R                                      |  129 ++
 R/delta.score.R                                    |   69 +
 R/dist.p.R                                         |   69 +-
 R/distSeq.R                                        |  187 ++-
 R/distTree.R                                       |  117 ++
 R/fitch.R                                          |  270 ++--
 R/hadamard.R                                       |  127 +-
 R/lento.R                                          |   92 ++
 R/modelTest.R                                      |   67 +
 R/neighborNet.R                                    |  475 ++++++-
 R/networx.R                                        | 1333 +++++-------------
 R/parsimony.R                                      |  158 ++-
 R/phangorn-package.R                               |   99 ++
 R/phyDat.R                                         |  245 +++-
 R/phylo.R                                          | 1447 ++++----------------
 R/pmlMix.R                                         |  463 +++++++
 R/pmlPart.R                                        |  933 +++++++++++++
 R/read.nexus.splits.R                              |  483 +++++++
 R/simSeq.R                                         |   88 +-
 R/splits.R                                         |  542 ++++++++
 R/superTree.R                                      |   46 +
 R/treeManipulation.R                               |  168 ++-
 R/treedist.R                                       |  273 ++--
 README.md                                          |    4 +-
 build/vignette.rds                                 |  Bin 376 -> 376 bytes
 inst/doc/Ancestral.R                               |   19 +-
 inst/doc/Ancestral.Rnw                             |    9 +-
 inst/doc/Ancestral.pdf                             |  Bin 245485 -> 261131 bytes
 inst/doc/IntertwiningTreesAndNetworks.R            |  105 +-
 inst/doc/IntertwiningTreesAndNetworks.Rmd          |  144 +-
 inst/doc/IntertwiningTreesAndNetworks.html         |  147 +-
 inst/doc/Networx.html                              |   14 +-
 inst/doc/Trees.R                                   |    4 +-
 inst/doc/Trees.Rnw                                 |    4 +-
 inst/doc/Trees.pdf                                 |  Bin 167906 -> 167923 bytes
 inst/doc/phangorn-specials.R                       |    9 +-
 inst/doc/phangorn-specials.Rnw                     |    3 +-
 inst/doc/phangorn-specials.pdf                     |  Bin 179955 -> 180130 bytes
 inst/extdata/trees/RAxML_bestTree.3moles           |    1 +
 inst/extdata/trees/RAxML_bestTree.AIs              |    1 +
 inst/extdata/trees/RAxML_bestTree.Wang.out         |    1 +
 inst/extdata/trees/RAxML_bestTree.YCh              |    1 +
 inst/extdata/trees/RAxML_bestTree.mtG              |    1 +
 inst/extdata/trees/RAxML_bipartitions.3moles       |    1 +
 inst/extdata/trees/RAxML_bipartitions.AIs          |    1 +
 inst/extdata/trees/RAxML_bipartitions.YCh          |    1 +
 inst/extdata/trees/RAxML_bipartitions.mtG          |    1 +
 .../trees/RAxML_bipartitionsBranchLabels.3moles    |    1 +
 .../trees/RAxML_bipartitionsBranchLabels.AIs       |    1 +
 .../trees/RAxML_bipartitionsBranchLabels.YCh       |    1 +
 .../trees/RAxML_bipartitionsBranchLabels.mtG       |    1 +
 inst/extdata/trees/RAxML_bootstrap.3moles          | 1000 ++++++++++++++
 inst/extdata/trees/RAxML_bootstrap.AIs             |  550 ++++++++
 inst/extdata/trees/RAxML_bootstrap.Wang.out        | 1000 ++++++++++++++
 inst/extdata/trees/RAxML_bootstrap.YCh             |  250 ++++
 inst/extdata/trees/RAxML_bootstrap.mtG             |  100 ++
 inst/extdata/trees/RAxML_distances.Wang.nxs        | 1193 ++++++++++++++++
 inst/extdata/trees/Splits.txt                      |  115 ++
 inst/extdata/trees/primates.dna                    |   61 +
 man/Ancestors.Rd                                   |   61 +-
 man/CI.Rd                                          |   34 +
 man/Laurasiatherian.Rd                             |   38 +-
 man/NJ.Rd                                          |   58 +-
 man/SH.test.Rd                                     |   49 +-
 man/SOWH.test.Rd                                   |   72 +-
 man/addConfidences.Rd                              |   81 +-
 man/allTrees.Rd                                    |   38 +-
 man/ancestral.pml.Rd                               |  106 +-
 man/as.networx.Rd                                  |  141 ++
 man/as.splits.Rd                                   |  151 +-
 man/bab.Rd                                         |   88 +-
 man/bootstrap.pml.Rd                               |  152 +-
 man/chloroplast.Rd                                 |   35 +-
 man/cladePar.Rd                                    |   79 +-
 man/coalSpeciesTree.Rd                             |   41 +
 man/consensusNet.Rd                                |   65 +-
 man/cophenetic.networx.Rd                          |   25 +-
 man/delta.score.Rd                                 |   69 +-
 man/densiTree.Rd                                   |  105 +-
 man/designTree.Rd                                  |   86 +-
 man/dfactorial.Rd                                  |   41 +-
 man/dist.hamming.Rd                                |   96 +-
 man/dist.p.Rd                                      |   99 +-
 man/distanceHadamard.Rd                            |   46 +-
 man/getClans.Rd                                    |  200 +--
 man/hadamard.Rd                                    |   90 +-
 man/lento.Rd                                       |   77 +-
 man/maxCladeCred.Rd                                |   68 +-
 man/midpoint.Rd                                    |   74 +-
 man/modelTest.Rd                                   |  109 +-
 man/neighborNet.Rd                                 |   55 +-
 man/nni.Rd                                         |   54 +-
 man/parsimony.Rd                                   |  133 +-
 man/phangorn-package.Rd                            |   55 +-
 man/phyDat.Rd                                      |  239 ++--
 man/plot.networx.Rd                                |  154 ---
 man/pml.Rd                                         |  288 ++--
 man/pml.fit.Rd                                     |  131 +-
 man/pmlCluster.Rd                                  |  102 +-
 man/pmlMix.Rd                                      |   80 +-
 man/pmlPart.Rd                                     |  102 +-
 man/read.aa.Rd                                     |   67 +-
 man/read.nexus.splits.Rd                           |   81 ++
 man/simSeq.Rd                                      |   82 +-
 man/splitsNetwork.Rd                               |   80 +-
 man/superTree.Rd                                   |   96 +-
 man/treedist.Rd                                    |  157 ++-
 man/upgma.Rd                                       |   73 +-
 man/writeDist.Rd                                   |   65 +
 man/yeast.Rd                                       |   40 +-
 src/RcppExports.cpp                                |   24 +
 src/dist.c                                         |    2 +-
 src/fitch.c                                        |   99 +-
 src/ml.c                                           |  173 ++-
 src/phangorn.c                                     |   10 +-
 src/phangorn_help.cpp                              |   54 +-
 src/registerDynamicSymbol.c                        |  154 +++
 src/sankoff.c                                      |    2 +-
 src/sprdist.c                                      |   54 +-
 tests/testthat/test_pmlPart.R                      |  167 +++
 tests/testthat/test_treeManipulation.R             |    7 +-
 vignettes/Ancestral.Rnw                            |    9 +-
 vignettes/IntertwiningTreesAndNetworks.Rmd         |  144 +-
 vignettes/Trees.Rnw                                |    4 +-
 vignettes/cophylo.png                              |  Bin 0 -> 13176 bytes
 vignettes/phangorn-specials.Rnw                    |    3 +-
 vignettes/phangorn.bib                             |   44 +
 139 files changed, 14137 insertions(+), 4765 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index b4eaf19..0bdbd51 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
 Package: phangorn
 Title: Phylogenetic Analysis in R
-Version: 2.1.1
-Date: 2016-12-03
+Version: 2.2.0
+Date: 2017-4-3
 Authors at R: c(person("Klaus", "Schliep", email="klaus.schliep at gmail.com", role = c("aut", "cre")), 
   person("Emmanuel", "Paradis", role = c("aut")), 
   person("Leonardo", "de Oliveira Martins", role = c("aut")), 
@@ -11,9 +11,9 @@ Authors at R: c(person("Klaus", "Schliep", email="klaus.schliep at gmail.com", role =
   person("Michelle", "Kendall", email="m.kendall at imperial.ac.uk", role = c("ctb")))
 Maintainer: Klaus Schliep <klaus.schliep at gmail.com>
 Description: Phylogenetic analysis in R: Estimation of phylogenetic
-        trees and networks using Maximum Likelihood, Maximum Parsimony,
-        distance methods and Hadamard conjugation.
-Depends: R (>= 3.2.0), ape (>= 4.0)
+    trees and networks using Maximum Likelihood, Maximum Parsimony,
+    distance methods and Hadamard conjugation.
+Depends: R (>= 3.2.0), ape (>= 4.1)
 Imports: quadprog, igraph (>= 1.0), Matrix, parallel, methods, utils,
         stats, graphics, grDevices, fastmatch, magrittr, Rcpp (>=
         0.12.0)
@@ -25,8 +25,9 @@ License: GPL (>= 2)
 VignetteBuilder: utils, knitr
 URL: https://github.com/KlausVigo/phangorn
 Repository: CRAN
+RoxygenNote: 6.0.1
 NeedsCompilation: yes
-Packaged: 2016-12-03 22:25:47 UTC; klaus
+Packaged: 2017-04-03 18:16:30 UTC; klaus
 Author: Klaus Schliep [aut, cre],
   Emmanuel Paradis [aut],
   Leonardo de Oliveira Martins [aut],
@@ -34,4 +35,4 @@ Author: Klaus Schliep [aut, cre],
   Tim W. White [aut],
   Cyrill Stachniss [ctb],
   Michelle Kendall [ctb]
-Date/Publication: 2016-12-04 11:42:04
+Date/Publication: 2017-04-03 20:40:30 UTC
diff --git a/MD5 b/MD5
index 804bd2e..30bd471 100644
--- a/MD5
+++ b/MD5
@@ -1,55 +1,62 @@
-1caf854c8e3d0058f87b4e52606bf9a6 *DESCRIPTION
-f8dbf6fef0c3d19291595e95e407f2eb *NAMESPACE
-bbe4b979bbcd18715eee2072e9305ed8 *NEWS
-9441c4e1029cac2a635d71e9acad4ffb *R/Coalescent.R
-2abb1811fe55334d88817d7c7ad2984d *R/Densi.R
-b743c4769d78295ac28702f376be88f7 *R/RcppExports.R
-0708ebbd9a9a0ba33f932d172d01ecc6 *R/SH.R
-f916be823b9a838d49145695b0a37aa1 *R/SOWH.R
-3cfc639a09a0e3c003929e7ff015df46 *R/ancestral_pml.R
-fd1201d71dddabc5bedf25753bf0d317 *R/bootstrap.R
-089d06695316d8734e5647d50eaa2b12 *R/cladePar.R
-b308a91826087b5dfcbc2075a0cc3a90 *R/clanistic.R
-62d2375bf3497590ad11af0de6e77efa *R/dist.p.R
-64b92983be4d54d166713ba0e69cd6a9 *R/distSeq.R
-f13145e51b142a4124e83ecdf947a9d2 *R/distTree.R
-31c6e8e64ddaaef935571c2b0a136d69 *R/fitch.R
-3c0ccfb95517188a1d8f4059b7f192d2 *R/hadamard.R
-42fe926e668d07ef6aee042b4a69de95 *R/modelTest.R
-c4c58c9e35b58e21176f482fd6150002 *R/neighborNet.R
-76da6b713d332fcce747148396563a1b *R/networx.R
-3223d2ae933dadce81bc77821cc99cde *R/parsimony.R
-c90c106b1ea0dc8dc6f088b3fd51b280 *R/phyDat.R
-7faa9011d21ceb145671ad0f32a54d00 *R/phylo.R
+97e1f40c823226b6ebb8f42d12d795e4 *DESCRIPTION
+9e5468a969c600d3ff5ec35fa0c8a90a *NAMESPACE
+257a4fbbea94f98a230120e5ff028e7b *NEWS
+1ef00135014f9e495ff41eb45dcca4d9 *R/Coalescent.R
+cd1a4f88a060c63423cf617a07f031a9 *R/Densi.R
+a00a0fe66993c92052d5af0f80cb0851 *R/RcppExports.R
+fe281b57ab54311e64cc267d0719bbd8 *R/SH.R
+0d548c2c3104564732a46fa2f3d1312c *R/SOWH.R
+ea8c89cdf0325dd3176018bb67f22b81 *R/ancestral_pml.R
+f4ddcf2602124b68e6f752087746e4d1 *R/bootstrap.R
+401a8d5f8c87121972c6a5b6c378ba47 *R/cladePar.R
+b5c3692e66f1ea332aea1ce3f9f3c9b9 *R/clanistic.R
+b3dca4761a3ae2b8cc296221a08cd004 *R/delta.score.R
+7a2ce76e926883e59de472bb91ea4034 *R/dist.p.R
+9474a5820f1cd7287815f722f986b79c *R/distSeq.R
+13a98b9e3b7054a3fa85ee1da1c7b1b1 *R/distTree.R
+c5a66391f77ac4c51fbfd48ef9a57559 *R/fitch.R
+4c73a9b536cfec7895443314fcb2e0ed *R/hadamard.R
+a2908e013493f7d05e262bf180384b75 *R/lento.R
+e6f12258ea0fa95a001b2a84fc237f05 *R/modelTest.R
+9fcd69842ea1009742d7d0f3dacf3864 *R/neighborNet.R
+95d31a8eb59f2eb08a503368bff62c62 *R/networx.R
+786d1f13224c24e72eae26e6c2e57bde *R/parsimony.R
+42f6732305063749d522b071c33c589e *R/phangorn-package.R
+5c3800b5983c78c275020ef52cf415ae *R/phyDat.R
+21711bbb4aec8296567959f77092cae3 *R/phylo.R
+c5af47c5153814f692e41862c301ae69 *R/pmlMix.R
+75600fcdd14b09360b353d1f81cc677f *R/pmlPart.R
+df0639ec774ea043f921405d5c77dcbd *R/read.nexus.splits.R
 b33943cef8181fd573939c9e1a003fdb *R/sankoff.R
-1e46863e6ff14de9597b86c4dedbd02d *R/simSeq.R
-9f64c372e0892738ccb107683440af5d *R/superTree.R
+67bffb5a3a0d80e29e4c7a4884308c42 *R/simSeq.R
+1ac323d2313f61550dbddae86182f422 *R/splits.R
+e9a09e2d30bb3160e286f4088855efa8 *R/superTree.R
 2b4d6884b4ee2b92e617cea76f79d3da *R/sysdata.rda
-40a44fc429cb60a112307c22f8f0de8f *R/treeManipulation.R
-fcffc8940c7bee194489d3b8180bced0 *R/treedist.R
+d1016c591e36cae9ba68ae585a0e9fe5 *R/treeManipulation.R
+40aec9e5475b3bf054819df0ca3ce0fd *R/treedist.R
 e07b91ecaa99e7e6023fed5d9760705e *R/zzz.R
-7191ca543e47e3eaf4ec6fb397d2e079 *README.md
-4a4c3e4965d40f619e29c1707cb472f0 *build/vignette.rds
+ef488a760b95741190af87fac5b78928 *README.md
+9f29e99c38ee1d065ddaf005cd8d71bc *build/vignette.rds
 4a92b07bcd170e85bd237e460acafa93 *data/Laurasiatherian.RData
 4b269c2e640293341b9b1c04d4dd7f4e *data/chloroplast.RData
 19f84425e8caaf9f605490cdff17dd81 *data/yeast.RData
 b4d3fa3f40aae3a68846d1f28274e9a0 *inst/CITATION
 61b3722df2ead748e0db8595428412a1 *inst/README
-56efa08410f500fc3b4851b71058ad27 *inst/doc/Ancestral.R
-bf3e208e4fceec83ea3d522adb1b0272 *inst/doc/Ancestral.Rnw
-d3291689993a930c8352226395dfedf1 *inst/doc/Ancestral.pdf
-0862fe6de86381ba4ad9c8d1b4b02198 *inst/doc/IntertwiningTreesAndNetworks.R
-af3eb8b8f4e4512cb5e22c8cec8538eb *inst/doc/IntertwiningTreesAndNetworks.Rmd
-c274e3f8a6d69e55ac9b75c2972d140d *inst/doc/IntertwiningTreesAndNetworks.html
+f96bf72ac20dcf02fbb2d759564dcff6 *inst/doc/Ancestral.R
+64fff86b1bee1edb0472897565110ada *inst/doc/Ancestral.Rnw
+2a3d056343f4f9ee2878f2aa0380aa45 *inst/doc/Ancestral.pdf
+ded9d871b4e54387c14340167f196a93 *inst/doc/IntertwiningTreesAndNetworks.R
+1ca8a38bf33510e70adf046d0924be2f *inst/doc/IntertwiningTreesAndNetworks.Rmd
+4f748d56a5f50155b3d3f477b10a5a48 *inst/doc/IntertwiningTreesAndNetworks.html
 d24a83a2803108ede87eff4de3c13ae8 *inst/doc/Networx.R
 fe641c0b4c7aac7aabf24c47ed6cde40 *inst/doc/Networx.Rmd
-640f7d533c3af0b9b62e6762e33cec3c *inst/doc/Networx.html
-1effe50d23f90af16c248d52ddedda58 *inst/doc/Trees.R
-5aa283308c069783e018a708a19c6439 *inst/doc/Trees.Rnw
-8b7350a9103d1cf8226c306c70a0601e *inst/doc/Trees.pdf
-ef0fbc15af66dff9fb288de1abbf8901 *inst/doc/phangorn-specials.R
-25becba1a0c2b64b7166f0b5eb72c4f2 *inst/doc/phangorn-specials.Rnw
-3ae1044de42534384f6d31000b699d1f *inst/doc/phangorn-specials.pdf
+5fdd659afe065dcb3e5bdf0cd10c6c6c *inst/doc/Networx.html
+2e0cca02797f23bf9415bb4fd566fce9 *inst/doc/Trees.R
+843c9f5979f259b3f49edfe2221524b6 *inst/doc/Trees.Rnw
+bc7aa4ae7f195c80085f51e6a8c60518 *inst/doc/Trees.pdf
+5ec124cf0e66f4bccae5e77c63c06608 *inst/doc/phangorn-specials.R
+f70ed8003af4fa9913530caf3f3c8ce2 *inst/doc/phangorn-specials.Rnw
+31fc544e66f66924603134bd3df92674 *inst/doc/phangorn-specials.pdf
 3009f9da02a198cb557d435cc5ad8c7f *inst/extdata/Blosum62.dat
 72f496d4c6e937ffe744d25bd8891313 *inst/extdata/Dayhoff.dat
 5aa357dab0e72b27023e4302bc37dbad *inst/extdata/FLU.dat
@@ -66,70 +73,96 @@ ddc4bd45521cd72848aaf2f79b90ac6e *inst/extdata/lg.dat
 917303a3df098f9137c651de0afa78fa *inst/extdata/mtArt.dat
 1cd5e39670b86d32b5fe5c27dcc79648 *inst/extdata/mtREV24.dat
 0ca0d0e987fcebf847a876779eddd934 *inst/extdata/mtmam.dat
+20be734137b889e34006f8b8bd969054 *inst/extdata/trees/RAxML_bestTree.3moles
+384aa1b8d633aa8c9f533396bd6798cb *inst/extdata/trees/RAxML_bestTree.AIs
+757e4718b72d7829b5ceb34f765dc626 *inst/extdata/trees/RAxML_bestTree.Wang.out
+5c7b80221c2dc93d4e6a6b857ccb62e8 *inst/extdata/trees/RAxML_bestTree.YCh
+0e77d8f9386ddaee1de2f6678530c823 *inst/extdata/trees/RAxML_bestTree.mtG
+2f7670326d5ff9235ecd0943944b6d59 *inst/extdata/trees/RAxML_bipartitions.3moles
+959bc9ea585c21ab89b3f32a5bb49d25 *inst/extdata/trees/RAxML_bipartitions.AIs
+46c172becde7e1d90ab68820b0c48822 *inst/extdata/trees/RAxML_bipartitions.YCh
+75061d3e313e19632dcbce0ef48e9cdc *inst/extdata/trees/RAxML_bipartitions.mtG
 2212d49c7269978890887be3686c12f9 *inst/extdata/trees/RAxML_bipartitions.woodmouse
+b1b3ceb83427c63fed23790fd563ef6e *inst/extdata/trees/RAxML_bipartitionsBranchLabels.3moles
+41fd855853c4ceb7e28d5212b1c72d9b *inst/extdata/trees/RAxML_bipartitionsBranchLabels.AIs
+0d8694f8ea078f981819be215fb724ba *inst/extdata/trees/RAxML_bipartitionsBranchLabels.YCh
+abcfbaf31212288e26a67c5b6c30ae70 *inst/extdata/trees/RAxML_bipartitionsBranchLabels.mtG
+25077ff0b9f822583f5ae13d8bbc181a *inst/extdata/trees/RAxML_bootstrap.3moles
+bd830645e73afa0ee2cb121c22c4d2f2 *inst/extdata/trees/RAxML_bootstrap.AIs
+086fb65b6bd2d40f09fff513b86d55cc *inst/extdata/trees/RAxML_bootstrap.Wang.out
+49ade6ade3f8f08033b887a001243c86 *inst/extdata/trees/RAxML_bootstrap.YCh
+d2016de5a6926dd0b62c49502ec2d6b9 *inst/extdata/trees/RAxML_bootstrap.mtG
 000df141b844795d38e5a755aa360f97 *inst/extdata/trees/RAxML_bootstrap.woodmouse
+6cd945acf5464dce8e10c350097e2c20 *inst/extdata/trees/RAxML_distances.Wang.nxs
+02888c45178001387b7a5397a3a17d3c *inst/extdata/trees/Splits.txt
+d3069d1eff9e70bed655b8962bf4ee2b *inst/extdata/trees/primates.dna
 129e8c41182f3557b1b9911625e100b9 *inst/extdata/trees/woodmouse.fasta
 421488c1ce8687879f64a350fca6d055 *inst/extdata/trees/woodmouse.mrbayes.nex.con
 d83fc4958acba1f1d0ca4092393c5b3d *inst/extdata/trees/woodmouse.mrbayes.nex.run1.t
 e185a8c9c7aed17a3e216cb78d517fd4 *inst/extdata/trees/woodmouse.mrbayes.nex.run2.t
 01399608c5cc2927ebed0659ac78863d *inst/extdata/trees/woodmouse.nxs
 87fa1533c4dfe7074237cfa2196bcbeb *inst/extdata/wag.dat
-3f0079d336b3fd0bc1209681ce725421 *man/Ancestors.Rd
-bda5669b71de975e1309d909c495b71f *man/Laurasiatherian.Rd
-4d6fb151c28a597eadc0d4ec2c59a504 *man/NJ.Rd
-5dd84777963b553e8c89bddc951b17c8 *man/SH.test.Rd
-095dc6d3e4c11d8ae6a83967a88dfb4c *man/SOWH.test.Rd
-0ad5edc3e25f1b6bb10c816e8b866320 *man/addConfidences.Rd
-7e03e8af0658fc2b19d1e51b0fad7a26 *man/allTrees.Rd
-8a9aaa3662de9d68b72a0790cb255866 *man/ancestral.pml.Rd
-074100ce52115557988ff5f316420999 *man/as.splits.Rd
-3b53888e5f37fd54344286a9175d8dc2 *man/bab.Rd
-7c2aead89db45adc53a75fbecb93e90e *man/bootstrap.pml.Rd
-22ad0ef60c2edd8b3d003f170f2fa15a *man/chloroplast.Rd
-4361615c7d1dc7beb8a4e6118505423c *man/cladePar.Rd
-5befa0cf9c4edc213566b3f60f8838ed *man/consensusNet.Rd
-55baf4b98181f03c2c1489a98d504e2d *man/cophenetic.networx.Rd
-c090d7ec936738daaea76e99f1f9bab0 *man/delta.score.Rd
-50af51e1ddb4295a8ee2791e49237f00 *man/densiTree.Rd
-f44e43abbbf7707821627c8e88f6e9fa *man/designTree.Rd
-b888d59a2b1fe266b098544b8ac86eed *man/dfactorial.Rd
-1e97d5bbdae42152778a84aff952a8cd *man/dist.hamming.Rd
-5505391fb32d03f9a3c2b8a14ebf03de *man/dist.p.Rd
-789d097683def6234f407e69cc3ee9b2 *man/distanceHadamard.Rd
-72abceeb247f22b3da6560df0c20468a *man/getClans.Rd
-619845889ee2d3b241af8a114eac9330 *man/hadamard.Rd
-f8cf4238c40481ee6c09cc935fc07f12 *man/lento.Rd
-aec58935c6251ba62808ea67d130a7f2 *man/maxCladeCred.Rd
-e18f9490c68933d8f946f3d3d3993f25 *man/midpoint.Rd
-30c8fe2f9863788d48b2846d9a303905 *man/modelTest.Rd
-7c85721291853f713eac8637c358f7a5 *man/neighborNet.Rd
-14f5a70080bc79967555dfcbe839c459 *man/nni.Rd
-ad48146c276212ea82c236bbdabc923f *man/parsimony.Rd
-ad095b45d2e89f45bc9938857c0bbe6d *man/phangorn-package.Rd
-cf9e0177d4e92a1576d5f5e7d158cb4c *man/phyDat.Rd
-8be8be7777fcec2c8ede18bead01240c *man/plot.networx.Rd
-9d9a2c930b17961fef4845dd6c52991e *man/pml.Rd
-f30af37ac4943192c369d32a712751ba *man/pml.fit.Rd
-9506d15a81467d18f40bb4741b3d9d28 *man/pmlCluster.Rd
-8b06bdee57c510a690ea04b40bac4844 *man/pmlMix.Rd
-ff67d17fa29bf88cea645905334c5ecc *man/pmlPart.Rd
-bfc83a71d7de4e1c0b994b8b9c853439 *man/read.aa.Rd
-6d5fd22b2c6dbe501b0ea18f7b96cf85 *man/simSeq.Rd
-2e7848b9bac018bde56302f70066a49a *man/splitsNetwork.Rd
-1276a142c217c44f2e0b1277a600c25d *man/superTree.Rd
-ba64cab5b9f597473c7f465a9f4eca34 *man/treedist.Rd
-64399c9fb7fb25d103c25aa925ab7a10 *man/upgma.Rd
-b97649fe8b91a0632a1ded89a6f43125 *man/yeast.Rd
+262c256e03eaef606dc387d26eda20f8 *man/Ancestors.Rd
+fb7e8c839911bae9099cced6ddc9f3c9 *man/CI.Rd
+e72793e4e3e08c49156b1357a9291a01 *man/Laurasiatherian.Rd
+35fb7d5dc48d2c99dd92124deba2faa4 *man/NJ.Rd
+38cf872ad462bcff836121bc2949ecc5 *man/SH.test.Rd
+4e98f950b33245fe670bf81f28ba30bf *man/SOWH.test.Rd
+37794a8759c4e5354e0305540f5fa878 *man/addConfidences.Rd
+c04c9432a573eb46abf88a4168eaa19e *man/allTrees.Rd
+6770144d1d8c6c4fee1b9ea437ec319e *man/ancestral.pml.Rd
+5f28334e1c861cd5edc0932b029e9fad *man/as.networx.Rd
+df2f4d5bfa1cf071228330cf78aca468 *man/as.splits.Rd
+51a2297dc7795006f77bca7df316a091 *man/bab.Rd
+bc0647d303ba2085e68ce113996c67bb *man/bootstrap.pml.Rd
+84449bdbd0b2adefb75bd71de6be5d8d *man/chloroplast.Rd
+e3e081603a2f00f835c0396194786bbc *man/cladePar.Rd
+d81de5004225837a7687707d22b34146 *man/coalSpeciesTree.Rd
+f62143567d4d4bb7c90add6cd1bba6c6 *man/consensusNet.Rd
+9a6059134efdbcae3f438ef949806bfd *man/cophenetic.networx.Rd
+5173eb8e2f87b21391e5c49c0927e905 *man/delta.score.Rd
+329637a9af4ab6fb5ffc47d7b28a4214 *man/densiTree.Rd
+8ac20c262a5ea83d81305952d3af6e49 *man/designTree.Rd
+dfbc54435ddc425192da2b8de37a90fe *man/dfactorial.Rd
+88105511ddc6e8276caacabc9c24dc8c *man/dist.hamming.Rd
+8fcacb6c33ff58c13368c99876f08414 *man/dist.p.Rd
+746b18349456ef2a1170410181a03aee *man/distanceHadamard.Rd
+0f9ac2386c3188935b5cbbf3502d9f92 *man/getClans.Rd
+f3fc41a84f7ad7e9ff1aed80af1749fd *man/hadamard.Rd
+fafe9fa7dfc0ee65f7b4af06a6f259fc *man/lento.Rd
+5a7846ea5f055c1e43bc4b9c23f31fc9 *man/maxCladeCred.Rd
+35cbd67a227c166e0aa53136e4cdff06 *man/midpoint.Rd
+ffba58b40070ca9f49c1f683efc0c816 *man/modelTest.Rd
+cc7c4671f631780dfdf621343998d6d0 *man/neighborNet.Rd
+338b14a841e98a6a8845eacdb33615e4 *man/nni.Rd
+e77789b0937f14c8ff119745664c14a1 *man/parsimony.Rd
+868acc3c4940b61304ddc3907a9e6448 *man/phangorn-package.Rd
+f543513e2efd6c6a939d3f4d6ba36228 *man/phyDat.Rd
+5f096f044b245f1724ddad252bd86e0e *man/pml.Rd
+f60d00714d4ed8e74769c63b6f3bc5a0 *man/pml.fit.Rd
+98a2f214a42fa5997c1f8b77bdc75640 *man/pmlCluster.Rd
+e918d08c90af8471e9ab94c102dd54a6 *man/pmlMix.Rd
+5b805e13703fbf5a15a8002f96016755 *man/pmlPart.Rd
+331cc7b9328ef3de64da631bacb4dcf7 *man/read.aa.Rd
+218c08b8b950b4813a00533c4e0239bd *man/read.nexus.splits.Rd
+20b1d9170bea996b7c840474cf3c0f75 *man/simSeq.Rd
+2b3a9ca8866169bd0df735ff7aaf2300 *man/splitsNetwork.Rd
+b756b7650b25d2ea878bab26fd55c3fc *man/superTree.Rd
+3dd9d5fcdd19c7b856bf58d4557c7d33 *man/treedist.Rd
+67067f0938439b3fc79270500c10f16f *man/upgma.Rd
+64676660c80daff9613450064cd286e3 *man/writeDist.Rd
+7b4fdcfc85bc945a86723f094057dbcb *man/yeast.Rd
 9a8d913f59a18a676121ea930cbe958f *src/Makevars
-3178e5cc701bd341b1f3fa3626f1e0b5 *src/RcppExports.cpp
-80c91abd1d67687878dc151c7440aaf9 *src/dist.c
-4244d0890739f29f204ad5745970f151 *src/fitch.c
-b36357bbe2bc513c2216e905c30f173b *src/ml.c
-1c1ea4701d57f7b819a659fdc586aa63 *src/phangorn.c
-13be023855d3786e428a079593ed4177 *src/phangorn_help.cpp
+98f3466473bd7d26ca7e6295e710b297 *src/RcppExports.cpp
+90aaf317a0778e08b0d399f4537a02cf *src/dist.c
+e211ccf823a225c647122c1c90713c08 *src/fitch.c
+68a32efe33bea769d0f0ace7486ff2f7 *src/ml.c
+cfd28e6e6c34376c9475c938c4a68745 *src/phangorn.c
+b16ad90df408504fbf7678e38bef7cef *src/phangorn_help.cpp
 d8e5c864aa0b122ce426a67479d3a610 *src/read_aa.c
-636bf81aacbb5ac0e06d0ae063a0ce75 *src/sankoff.c
-2910bd3e2e2383f7bac46180d62243a4 *src/sprdist.c
+ad85c0f11dbf6a9f062cd66d5aa61f09 *src/registerDynamicSymbol.c
+ed187ba616f3547f4aa344e815b446b2 *src/sankoff.c
+144b2b620cce6bf849f725be5f5e2cdc *src/sprdist.c
 7d1eaef831fb2372b367f5be1b0a5790 *tests/testthat.R
 97d94788752f552d019cdaafcf7a66bc *tests/testthat/test_dist_tree.R
 92512e2f264d4a11382ddd89e2a515d1 *tests/testthat/test_distances.R
@@ -137,17 +170,19 @@ d8e5c864aa0b122ce426a67479d3a610 *src/read_aa.c
 59cb415b0af45af3bd1494226260791e *tests/testthat/test_parsimony.R
 06a0631572d94f45d220b55847f9f661 *tests/testthat/test_phyDat.R
 870574752144d6ca09f3c3a784abe284 *tests/testthat/test_pml.R
+dff1cb0e8a174c5a149bec33b346a51f *tests/testthat/test_pmlPart.R
 7688c6569491421417861398008a0232 *tests/testthat/test_splits.R
 20ec41bfea311dd762e984f834a26948 *tests/testthat/test_superTree.R
-b46633e27e0dd867a89d4c40e4eabfb3 *tests/testthat/test_treeManipulation.R
+1ad2de0e9fc0a4fdbb3eae96d63e413a *tests/testthat/test_treeManipulation.R
 98d3d4091f9bacf2771d037df005daaf *tests/testthat/test_treedist.R
-bf3e208e4fceec83ea3d522adb1b0272 *vignettes/Ancestral.Rnw
-af3eb8b8f4e4512cb5e22c8cec8538eb *vignettes/IntertwiningTreesAndNetworks.Rmd
+64fff86b1bee1edb0472897565110ada *vignettes/Ancestral.Rnw
+1ca8a38bf33510e70adf046d0924be2f *vignettes/IntertwiningTreesAndNetworks.Rmd
 fe641c0b4c7aac7aabf24c47ed6cde40 *vignettes/Networx.Rmd
 a8250afd3b341e6c3f889e9454d5bc5f *vignettes/Trees.RData
-5aa283308c069783e018a708a19c6439 *vignettes/Trees.Rnw
+843c9f5979f259b3f49edfe2221524b6 *vignettes/Trees.Rnw
+3b1285249eed24e70427c0b56450533a *vignettes/cophylo.png
 6af5f4d4c2e93469cc19d46a97ab5d0f *vignettes/exdna.txt
 1ca8b1d97a011a9d0ecd9630d548dfb3 *vignettes/movie.gif
-25becba1a0c2b64b7166f0b5eb72c4f2 *vignettes/phangorn-specials.Rnw
-16fa639fbbf08ae193a36f714197a2fa *vignettes/phangorn.bib
+f70ed8003af4fa9913530caf3f3c8ce2 *vignettes/phangorn-specials.Rnw
+aaa85872349d15fb613959ab2ade650c *vignettes/phangorn.bib
 d3069d1eff9e70bed655b8962bf4ee2b *vignettes/primates.dna
diff --git a/NAMESPACE b/NAMESPACE
index 27af5dd..30ef584 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,3 +1,4 @@
+
 useDynLib(phangorn, .registration=TRUE)
 
 importFrom(ape, as.DNAbin, as.phylo, plot.phylo, as.prop.part, nj,old2new.phylo, dist.dna,
@@ -7,7 +8,8 @@ importFrom(ape, as.DNAbin, as.phylo, plot.phylo, as.prop.part, nj,old2new.phylo,
     node.depth.edgelength, drop.tip, stree, rtree, rcoal, rmtree, is.ultrametric, .PlotPhyloEnv,
     nodelabels, edgelabels, BOTHlabels, read.nexus.data, write.nexus.data, 
     read.dna, write.dna, reorder.phylo, dist.nodes, collapse.singles, rotate, prop.clades,
-    fastme.bal, fastme.ols, Nnode, image.DNAbin, ONEwise, as.AAbin, as.phyDat.AAbin, image.AAbin)
+    fastme.bal, fastme.ols, Nnode, image.DNAbin, ONEwise, as.AAbin, as.phyDat.AAbin, image.AAbin, 
+    as.bitsplits, as.bitsplits.prop.part, arecompatible, is.compatible, is.compatible.bitsplits)
 # is.binary,
 importFrom(igraph, graph, graph_from_adjacency_matrix, layout_with_kk, plot.igraph,
     shortest_paths, set.edge.attribute, set_edge_attr, decompose, components, groups,
@@ -16,7 +18,7 @@ importFrom(igraph, graph, graph_from_adjacency_matrix, layout_with_kk, plot.igra
 
 
 importFrom(Rcpp,sourceCpp)
-importFrom(magrittr,"%>%")
+importFrom(magrittr,"%>%", "%<>%")
 importFrom(Matrix, Matrix, sparseMatrix, spMatrix, crossprod, solve) #, %*%
 importFrom(fastmatch, fmatch)
 #importFrom(nnls, nnls)
@@ -27,11 +29,11 @@ importFrom(quadprog, solve.QP, solve.QP.compact)
 importFrom(stats, AIC, BIC, logLik, reorder, update, optim, optimize, constrOptim, na.omit, 
            cophenetic, hclust, as.dist, pchisq, reshape, qgamma, pgamma, model.matrix,
            aggregate, lm.fit, xtabs, quantile, sd) 
-importFrom(graphics, plot.new, plot.window, text, par, plot, abline, strwidth, axis, title, segments, 
+importFrom(graphics, plot, plot.default, plot.new, plot.window, text, par, abline, strwidth, axis, title, segments, 
            points, image, matplot, legend, hist) 
 importFrom(utils, read.table, download.file, citation, stack, installed.packages, write.table, combn) 
 importFrom(grDevices, rgb, rainbow, adjustcolor, col2rgb)
-importFrom(methods, hasArg)
+importFrom(methods, hasArg, is)
 #importFrom(Rcpp, evalCpp)
 #importMethodsFrom(Biostrings,as.matrix)
 #importFrom(Biostrings,DNAMultipleAlignment)
@@ -44,9 +46,9 @@ export(pml, optim.pml, pml.control, parsimony, optim.parsimony, pratchet, NJ, UN
     dfactorial, ldfactorial, hadamard, nni, allSitePattern, allSplits, allCircularSplits, fhm, 
     distanceHadamard, treedist, sankoff, fitch, h2st, h4st, dist.logDet, dist.hamming, 
     dist.ml, dist.p, upgma, wpgma, write.nexus.splits, read.nexus.splits,
-    read.nexus.networx, write.nexus.networx, write.splits, pmlPart, 
+    read.nexus.networx, write.nexus.networx, write.splits, write.nexus.dist, pmlPart, 
     pmlCluster, pmlMix, pmlPen, read.aa, allTrees, designTree, designSplits, nnls.tree,
-    nnls.splits, nnls.phylo, nnls.networx, neighborNet, pmlPart2multiPhylo,
+    nnls.splits, nnls.phylo, nnls.networx, neighborNet, pmlPart2multiPhylo, multiphyDat2pmlPart,
     splitsNetwork, simSeq, SH.test, bootstrap.pml, bootstrap.phyDat, RF.dist, wRF.dist, 
     KF.dist, path.dist, sprdist, SPR.dist, rNNI, 
     rSPR, plotBS, Ancestors, Descendants, mrca.phylo, Children, Siblings, pace, modelTest, 
@@ -54,10 +56,11 @@ export(pml, optim.pml, pml.control, parsimony, optim.parsimony, pratchet, NJ, UN
     getClips, getDiversity, midpoint, pruneTree, acctran, getRoot, plotAnc, consensusNet, 
     bab, random.addition, diversity, baseFreq, densiTree, superTree, coalSpeciesTree, 
     pml.fit, pml.init, pml.free, edQt, lli, cladePar, addConfidences, createLabel,
-    countCycles, SOWH.test, plot.networx, presenceAbsence, as.networx.splits, addTrivialSplits,
+    SOWH.test, presenceAbsence, as.networx.splits, addTrivialSplits, removeTrivialSplits,
     phyDat2alignment, AICc, readDist, writeDist, discrete.gamma, matchSplits, 
-    distinct.splits, c.splits, dna2codon, codon2dna,
+    distinct.splits, c.splits, dna2codon, codon2dna, genlight2phyDat,
     removeUndeterminedSites, phyDat2MultipleAlignment, delta.score, maxCladeCred, as.MultipleAlignment)
+# plot.networx, countCycles, 
 
 S3method('[', splits)          
 S3method(addConfidences, phylo)
@@ -72,9 +75,11 @@ S3method(c, phyDat)
 S3method(c, splits)
 S3method(cbind, phyDat)
 S3method(unique, phyDat) 
+S3method(as.bitsplits, splits)
 S3method(as.matrix, splits)
 S3method(as.Matrix, splits) 
 S3method(as.networx, splits)
+S3method(unique, splits)
 S3method(as.networx, phylo)
 #S3method(as.igraph, networx)
 S3method(as.phyDat, DNAbin)
@@ -99,6 +104,8 @@ S3method(image, phyDat)
 S3method(logLik, pml)
 S3method(logLik, pmlPart)
 S3method(logLik, pmlMix)
+S3method(midpoint, phylo)
+S3method(midpoint, multiPhylo)
 S3method(plot, pml)
 S3method(plot, pmlPart)
 S3method(plot, networx)
@@ -119,6 +126,3 @@ S3method(summary, clanistics)
 S3method(summary, SOWH)
 S3method(update, pml)
 S3method(vcov, pml)
-
-
-
diff --git a/NEWS b/NEWS
index 92cee36..8f308a9 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,24 @@
+     CHANGES in PHANGORN VERSION 2.2.0
+
+NEW FEATURES
+
+    o midpoint in now generic and works for multiPhylo objects
+
+    o as.bitsplits.splits to better interact with ape
+
+BUG FIXES
+
+    o bug fix in RI and CI for ambiguous data  
+
+OTHER CHANGES
+
+    o added roxygen2 documentation, so R code is now much better documented,
+    
+      reorganisation of some documentation
+    
+    o many more unit tests
+
+
      CHANGES in PHANGORN VERSION 2.1.0
 
 NEW FEATURES
diff --git a/R/Coalescent.R b/R/Coalescent.R
index f962566..c790bda 100644
--- a/R/Coalescent.R
+++ b/R/Coalescent.R
@@ -54,6 +54,32 @@ comp2 <- function(x, y){
 # single linkage of minimal coalescent times
 # extends speciesTree fom ape
 
+
+
+#' Species Tree
+#' 
+#' \code{coalSpeciesTree} estimates species trees and can handle multiple
+#' individuals per species.
+#' 
+#' \code{coalSpeciesTree} estimates a single linkage tree as suggested by Liu
+#' et al. (2010) from the element wise minima of the cophenetic matrices of the
+#' gene trees. It extends \code{speciesTree} in ape as it allows that have
+#' several individuals per gene tree.
+#' 
+#' @export
+#' 
+#' @param tree an object of class \code{multiPhylo}
+#' @param X A \code{phyDat} object to define which individual belongs to which
+#' species.
+#' @param sTree A species tree which fixes the topology.
+#' @return The function returns an object of class \code{phylo}.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com} Emmanuel Paradies
+#' @seealso \code{\link{speciesTree}}
+#' @references Liu, L., Yu, L. and Pearl, D. K. (2010) Maximum tree: a
+#' consistent estimator of the species tree. \emph{Journal of Mathematical
+#' Biology}, \bold{60}, 95--106.
+#' @keywords cluster
+#' 
 coalSpeciesTree <- function(tree, X, sTree=NULL){
   
   if(is.null(X))return(speciesTree(tree))  
diff --git a/R/Densi.R b/R/Densi.R
index db53164..a60e170 100644
--- a/R/Densi.R
+++ b/R/Densi.R
@@ -18,6 +18,56 @@ getAges <- function(x){
 }
 
 
+
+
+#' Plots a densiTree.
+#' 
+#' An R function to plot trees similar to those produced by DensiTree.
+#' 
+#' If no consensus tree is provided \code{densiTree} computes a rooted
+#' mrp.supertree as a backbone. This should avoid too many unnecessary
+#' crossings of edges.  Trees should be rooted, other wise the output may not
+#' make sense.
+#' 
+#' @param x an object of class \code{multiPhylo}.
+#' @param type a character string specifying the type of phylogeny, so far
+#' "cladogram" (default) or "phylogram" (the default) are supported.
+#' @param alpha parameter for semi-transparent colors.
+#' @param consensus A tree which is used to define the order of the tip labels.
+#' @param optim not yet used.
+#' @param scaleX scale trees to have identical heights.
+#' @param col edge color.
+#' @param width edge width.
+#' @param cex a numeric value giving the factor scaling of the tip labels.
+#' @param \dots further arguments to be passed to plot.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{plot.phylo}}, \code{\link{plot.networx}}
+#' @references densiTree is inspired from the great
+#' \href{https://www.cs.auckland.ac.nz/~remco/DensiTree}{DensiTree} program of Remco
+#' Bouckaert.
+#' 
+#' Remco R. Bouckaert (2010) DensiTree: making sense of sets of phylogenetic
+#' trees \emph{Bioinformatics}, \bold{26 (10)}, 1372-1373.
+#' @keywords plot
+#' @examples
+#'   
+#' data(Laurasiatherian)
+#' set.seed(1)
+#' bs <- bootstrap.phyDat(Laurasiatherian, FUN = 
+#'    function(x)upgma(dist.hamming(x)), bs=25)
+#' # cladogram nice to show topological differences
+#' densiTree(bs, optim=TRUE, type="cladogram", col="blue")
+#' densiTree(bs, optim=TRUE, type="phylogram", col="green")
+#' \dontrun{
+#' # phylograms are nice to show different age estimates
+#' require(PhyloOrchard)
+#' data(BinindaEmondsEtAl2007)
+#' BinindaEmondsEtAl2007 <- .compressTipLabel(BinindaEmondsEtAl2007) 
+#' densiTree(BinindaEmondsEtAl2007, type="phylogram", col="red")
+#' }
+#' 
+#' 
+#' @export densiTree
 densiTree <- function(x, type="cladogram", alpha=1/length(x), consensus=NULL, optim=FALSE, scaleX=FALSE, col=1, width=1, cex=.8, ...) {
   if(!inherits(x,"multiPhylo"))stop("x must be of class multiPhylo")
   compressed <- ifelse(is.null(attr(x, "TipLabel")), FALSE, TRUE)
diff --git a/R/RcppExports.R b/R/RcppExports.R
index d540bb3..81f0e28 100644
--- a/R/RcppExports.R
+++ b/R/RcppExports.R
@@ -5,6 +5,14 @@ allDescCPP <- function(orig, nTips) {
     .Call('phangorn_allDescCPP', PACKAGE = 'phangorn', orig, nTips)
 }
 
+bipartCPP <- function(orig, nTips) {
+    .Call('phangorn_bipartCPP', PACKAGE = 'phangorn', orig, nTips)
+}
+
+bipCPP <- function(orig, nTips) {
+    .Call('phangorn_bipCPP', PACKAGE = 'phangorn', orig, nTips)
+}
+
 allChildrenCPP <- function(orig) {
     .Call('phangorn_allChildrenCPP', PACKAGE = 'phangorn', orig)
 }
diff --git a/R/SH.R b/R/SH.R
index 9a8652c..e46d54c 100644
--- a/R/SH.R
+++ b/R/SH.R
@@ -1,3 +1,39 @@
+#' Shimodaira-Hasegawa Test
+#' 
+#' This function computes the Shimodaira--Hasegawa test for a set of trees.
+#' 
+#' 
+#' @param ... either a series of objects of class \code{"pml"} separated by
+#' commas, a list containing such objects or an object of class
+#' \code{"pmlPart"}.
+#' @param B the number of bootstrap replicates.
+#' @param data an object of class \code{"phyDat"}.
+#' @return a numeric vector with the P-value associated with each tree given in
+#' \code{...}.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{pml}}, \code{\link{pmlPart}}, \code{\link{pmlCluster}},
+#' \code{\link{SOWH.test}}
+#' @references Shimodaira, H. and Hasegawa, M. (1999) Multiple comparisons of
+#' log-likelihoods with applications to phylogenetic inference. \emph{Molecular
+#' Biology and Evolution}, \bold{16}, 1114--1116.
+#' @keywords models
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' dm <- dist.logDet(Laurasiatherian)
+#' tree1 <- NJ(dm)
+#' tree2 <- unroot(upgma(dm))
+#' fit1 <- pml(tree1, Laurasiatherian)
+#' fit2 <- pml(tree2, Laurasiatherian)
+#' fit1 <- optim.pml(fit1) # optimize edge weights
+#' fit2 <- optim.pml(fit2)
+#' SH.test(fit1, fit2, B=500)
+#' # in real analysis use larger B, e.g. 10000
+#' \dontrun{
+#' example(pmlPart)
+#' SH.test(sp, B=1000)
+#' }
+#' 
 SH.test <- function (..., B = 10000, data = NULL)
 {
     fits <- list(...)
@@ -48,4 +84,4 @@ SH.test <- function (..., B = 10000, data = NULL)
     else colnames(res) <- c("Partition", "Trees", "ln L", "Diff ln L",
                             "p-value")
     res
-}
\ No newline at end of file
+}
diff --git a/R/SOWH.R b/R/SOWH.R
index c841198..fdf8bc8 100644
--- a/R/SOWH.R
+++ b/R/SOWH.R
@@ -1,3 +1,52 @@
+#' Swofford-Olsen-Waddell-Hillis Test
+#' 
+#' This function computes the Swofford--Olsen--Waddell--Hillis (SOWH) test, a
+#' parametric bootstrap test. The function is computational very demanding and
+#' likely to be very slow.
+#' 
+#' \code{SOWH.test} performs a parametric bootstrap test to compare two trees.
+#' It makes extensive use \code{simSeq} and \code{optim.pml} and can take quite
+#' long.
+#' 
+#' @param x an object of class \code{"pml"}.
+#' @param n the number of bootstrap replicates.
+#' @param restricted list of restricted parameter settings.
+#' @param optNni Logical value indicating whether topology gets optimized
+#' (NNI).
+#' @param trace Show output during computations.
+#' @param \dots Further arguments passed to \code{"optim.pml"}.
+#' @return an object of class SOWH. That is a list with three elements, one is
+#' a matrix containing for each bootstrap replicate the (log-) likelihood of
+#' the restricted and unrestricted estimate and two pml objects of the
+#' restricted and unrestricted model.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{pml}}, \code{\link{pmlPart}}, \code{\link{pmlCluster}},
+#' \code{\link{simSeq}}, \code{\link{SH.test}}
+#' @references Goldman, N., Anderson, J. P., and Rodrigo, A. G. (2000)
+#' Likelihood -based tests of topologies in phylogenetics. \emph{Systematic
+#' Biology} \bold{49} 652-670.
+#' 
+#' Swofford, D.L., Olsen, G.J., Waddell, P.J. and Hillis, D.M. (1996)
+#' Phylogenetic Inference in Hillis, D.M., Moritz, C. and Mable, B.K. (Eds.)
+#' \emph{Molecular Systematics} (2nd ed.) 407-514, Sunderland, MA: Sinauer
+#' @keywords models
+#' @examples
+#' 
+#' # in real analysis use larger n, e.g. 500 preferably more
+#' \dontrun{
+#' data(Laurasiatherian)
+#' dm <- dist.logDet(Laurasiatherian)
+#' tree <- NJ(dm)
+#' fit <- pml(tree, Laurasiatherian)
+#' fit <- optim.pml(fit, TRUE)
+#' set.seed(6)
+#' tree <- rNNI(fit$tree, 1)
+#' fit <- update(fit, tree = tree)
+#' (res <- SOWH.test(fit, n=100))
+#' summary(res)
+#' }
+#' 
+#' @export SOWH.test
 SOWH.test <- function(x, n=100, restricted=list(optNni=FALSE), optNni=TRUE, trace = 1, ...){
   
   res = matrix(NA, n, 2)
diff --git a/R/ancestral_pml.R b/R/ancestral_pml.R
index dac7d69..967ccf8 100644
--- a/R/ancestral_pml.R
+++ b/R/ancestral_pml.R
@@ -1,10 +1,67 @@
 #
 # ancestral sequences ML
 #
-ancestral.pml <- function (object, type=c("marginal", "ml", "bayes")) 
+
+
+#' Ancestral character reconstruction.
+#' 
+#' Marginal reconstruction of the ancestral character states.
+#' 
+#' The argument "type" defines the criterion to assign the internal nodes. For
+#' \code{ancestral.pml} so far "ml" and (empirical) "bayes" and for
+#' \code{ancestral.pars} "MPR" and "ACCTRAN" are possible.
+#' 
+#' With parsimony reconstruction one has to keep in mind that there will be
+#' often no unique solution.
+#' 
+#' For further details see vignette("Ancestral").
+#' 
+#' @param object an object of class pml
+#' @param tree a tree, i.e. an object of class pml
+#' @param data an object of class phyDat
+#' @param type method used to assign characters to internal nodes, see details.
+#' @param i plots the i-th site pattern of the \code{data}.
+#' @param col a vector containing the colors for all possible states.
+#' @param cex.pie a numeric defining the size of the pie graphs
+#' @param pos a character string defining the position of the legend
+#' @param cost A cost matrix for the transitions between two states.
+#' @param return return a \code{phyDat} object or matrix of probabilities. 
+#' @param \dots Further arguments passed to or from other methods.
+#' @return %A matrix containing the the estimates character states. An object
+#' of class "phyDat", containing the ancestral states of all nodes.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{pml}}, \code{\link{parsimony}}, \code{\link[ape]{ace}},
+#' \code{\link[ape]{root}}
+#' @references Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer
+#' Associates, Sunderland.
+#' 
+#' Swofford, D.L., Maddison, W.P. (1987) Reconstructing ancestral character
+#' states under Wagner parsimony. \emph{Math. Biosci.} \bold{87}: 199--229
+#' 
+#' Yang, Z. (2006). \emph{Computational Molecular evolution}. Oxford University
+#' Press, Oxford.
+#' @keywords ~kwd1 ~kwd2
+#' @examples
+#' 
+#' example(NJ)
+#' fit = pml(tree, Laurasiatherian)
+#' anc.ml = ancestral.pml(fit, type = "ml")
+#' anc.p = ancestral.pars(tree, Laurasiatherian)
+#' \dontrun{
+#' require(seqLogo)
+#' seqLogo( t(subset(anc.ml, 48, 1:20)[[1]]), ic.scale=FALSE)
+#' seqLogo( t(subset(anc.p, 48, 1:20)[[1]]), ic.scale=FALSE)
+#' }
+#' # plot the first site pattern
+#' plotAnc(tree, anc.ml, 1)
+#' # plot the third character 
+#' plotAnc(tree, anc.ml, attr(anc.ml, "index")[3])
+#' 
+#' @rdname ancestral.pml
+#' @export 
+ancestral.pml <- function (object, type=c("marginal", "ml", "bayes"), return="prob") 
 {
     call <- match.call()
-    type <- match.arg(type)
     pt <- match.arg(type, c("marginal", "joint", "ml", "bayes"))   
     tree = object$tree 
     
@@ -36,7 +93,9 @@ ancestral.pml <- function (object, type=c("marginal", "ml", "bayes"))
     
     
     tmp = length(data)
-    result = new2old.phyDat(data) 
+    
+    if(return!="phyDat")result = new2old.phyDat(data) 
+    else result[1:nTips] = data
     eig = object$eig
     
     bf = object$bf
@@ -49,13 +108,19 @@ ancestral.pml <- function (object, type=c("marginal", "ml", "bayes"))
     nTips = as.integer(length(tree$tip.label))
     mNodes = as.integer(max(node) + 1)
     contrast = attr(data, "contrast")
+# proper format    
+    eps <- 1.0e-5
+    ind1 <- which( apply(contrast, 1, function(x)sum(x > eps)) == 1L)
+    ind2 <- which( contrast[ind1, ] > eps, arr.ind = TRUE)
+    pos <- ind2[match(as.integer(1L:ncol(contrast)),  ind2[,2]),1]
+    
     nco = as.integer(dim(contrast)[1])
     for(i in 1:l)dat[i,(nTips + 1):m] <- .Call("LogLik2", data, P[i,], nr, nc, node, edge, nTips, mNodes, contrast, nco, PACKAGE = "phangorn")
     
     parent <- tree$edge[, 1]
     child <- tree$edge[, 2]
     nTips = min(parent) - 1
-    
+# in C with scaling    
     for(i in 1:l){     
         for (j in (m - 1):1) {
             if (child[j] > nTips){
@@ -68,10 +133,14 @@ ancestral.pml <- function (object, type=c("marginal", "ml", "bayes"))
         tmp <- matrix(0, nr, nc)
         if(inv>0) tmp = as.matrix(INV) * inv
         for(i in 1:l){  
+# scaling!!!            
             tmp = tmp + w[i] * dat[[i, j]]                                 
         }
         if ( (pt == "bayes") || (pt == "marginal")) tmp = tmp * rep(bf, each=nr)
         tmp = tmp / rowSums(tmp)
+        
+        if(return=="phyDat") tmp <- pos[apply(tmp, 1, which.max)]
+        
         result[[j]] = tmp
     } 
     attributes(result) = x
@@ -85,6 +154,7 @@ ancestral.pml <- function (object, type=c("marginal", "ml", "bayes"))
 #}
     
 
+# in ancestral.pml
 ancestral2phyDat <- function(x) {
     eps <- 1.0e-5
     contr <- attr(x, "contrast")
@@ -99,6 +169,11 @@ ancestral2phyDat <- function(x) {
 }
 
 
+# in ancestral.pml
+# variante fuer parsimony und ambiguous DNA 
+
+
+# raus ??
 fast.tree  = function(tree, node){
     parent = c(node, Ancestors(tree, node))
     children = Descendants(tree, parent, 'children')
diff --git a/R/bootstrap.R b/R/bootstrap.R
index 7991378..9f424e8 100644
--- a/R/bootstrap.R
+++ b/R/bootstrap.R
@@ -1,3 +1,88 @@
+#' Bootstrap
+#' 
+#' \code{bootstrap.pml} performs (non-parametric) bootstrap analysis and
+#' \code{bootstrap.phyDat} produces a list of bootstrapped data sets.
+#' \code{plotBS} plots a phylogenetic tree with the with the bootstrap values
+#' assigned to the (internal) edges.
+#' 
+#' It is possible that the bootstrap is performed in parallel, with help of the
+#' multicore package. Unfortunately the multicore package does not work under
+#' windows or with GUI interfaces ("aqua" on a mac). However it will speed up
+#' nicely from the command line ("X11").
+#' 
+#' @param x an object of class \code{pml} or \code{phyDat}.
+#' @param bs number of bootstrap samples.
+#' @param trees return trees only (default) or whole \code{pml} objects.
+#' @param multicore logical, whether models should estimated in parallel.
+#' @param mc.cores The number of cores to use during bootstrap. Only supported
+#' on UNIX-alike systems.
+#' @param jumble logical, jumble the order of the sequences.
+#' @param \dots further parameters used by \code{optim.pml} or
+#' \code{plot.phylo}.
+#' @param FUN the function to estimate the trees.
+#' @param tree The tree on which edges the bootstrap values are plotted.
+#' @param BStrees a list of trees (object of class "multiPhylo").
+#' @param type the type of tree to plot, so far "cladogram", "phylogram" and
+#' "unrooted" are supported.
+#' @param bs.col color of bootstrap support labels.
+#' @param bs.adj one or two numeric values specifying the horizontal and
+#' vertical justification of the bootstrap labels.
+#' @param p only plot support values higher than this percentage number
+#' (default is 80).
+#' @param frame a character string specifying the kind of frame to be printed
+#' around the bootstrap values. This must be one of "none" (the default),
+#' "rect" or "circle".
+#' @return \code{bootstrap.pml} returns an object of class \code{multi.phylo}
+#' or a list where each element is an object of class \code{pml}. \code{plotBS}
+#' returns silently a tree, i.e. an object of class \code{phylo} with the
+#' bootstrap values as node labels. The argument \code{BStrees} is optional and
+#' if not supplied the tree with labels supplied in the \code{node.label} slot.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{optim.pml}}, \code{\link{pml}},
+#' \code{\link{plot.phylo}},
+#' \code{\link{nodelabels}},\code{\link{consensusNet}} and
+#' \code{\link{SOWH.test}} for parametric bootstrap
+#' @references Felsenstein J. (1985) Confidence limits on phylogenies. An
+#' approach using the bootstrap. \emph{Evolution} \bold{39}, 783--791
+#' 
+#' Penny D. and Hendy M.D. (1985) Testing methods evolutionary tree
+#' construction. \emph{Cladistics} \bold{1}, 266--278
+#' 
+#' Penny D. and Hendy M.D. (1986) Estimating the reliability of evolutionary
+#' trees. \emph{Molecular Biology and Evolution} \bold{3}, 403--417
+#' @keywords cluster
+#' @examples
+#' 
+#' \dontrun{
+#' data(Laurasiatherian)
+#' dm <- dist.logDet(Laurasiatherian)
+#' tree <- NJ(dm)
+#' # NJ
+#' set.seed(123)
+#' NJtrees <- bootstrap.phyDat(Laurasiatherian, FUN=function(x)NJ(dist.logDet(x)), bs=100)
+#' treeNJ <- plotBS(tree, NJtrees, "phylogram")
+#' 
+#' # Maximum likelihood
+#' fit <- pml(tree, Laurasiatherian)
+#' fit <- optim.pml(fit, rearrangements="NNI")
+#' set.seed(123)
+#' bs <- bootstrap.pml(fit, bs=100, optNni=TRUE)
+#' treeBS <- plotBS(fit$tree,bs)
+#' 
+#' # Maximum parsimony
+#' treeMP <- pratchet(Laurasiatherian)
+#' treeMP <- acctran(treeMP, Laurasiatherian)
+#' set.seed(123)
+#' BStrees <- bootstrap.phyDat(Laurasiatherian, pratchet, bs = 100)
+#' treeMP <- plotBS(treeMP, BStrees, "phylogram")
+#' add.scale.bar()
+#' 
+#' # export tree with bootstrap values as node labels
+#' # write.tree(treeBS)
+#' }
+#' 
+#' @rdname bootstrap.pml
+#' @export
 bootstrap.pml <- function (x, bs = 100, trees = TRUE, multicore=FALSE, mc.cores = NULL, ...) 
 {
     if(multicore && is.null(mc.cores)){
@@ -38,6 +123,8 @@ bootstrap.pml <- function (x, bs = 100, trees = TRUE, multicore=FALSE, mc.cores
 }
 
 
+#' @rdname bootstrap.pml
+#' @export
 bootstrap.phyDat <- function (x, FUN, bs = 100, multicore=FALSE, mc.cores = NULL, jumble=TRUE, ...) 
 {
     if(multicore && is.null(mc.cores)){
@@ -106,6 +193,8 @@ checkLabels <- function(tree, tip){
 }
 
 
+#' @rdname bootstrap.pml
+#' @export
 plotBS <- function (tree, BStrees, type = "unrooted", bs.col = "black", 
                     bs.adj = NULL, p=50, frame="none",...) 
 {
@@ -162,6 +251,55 @@ plotBS <- function (tree, BStrees, type = "unrooted", bs.col = "black",
 }
 
 
+
+
+#' Maximum clade credibility tree
+#' 
+#' \code{maxCladeCred} computes the maximum clade credibility tree from a
+#' sample of trees.
+#' 
+#' So far just the best tree is returned. No annotations or transformations of
+#' edge length are performed.
+#' 
+#' If a list of partition is provided then the clade credibility is computed
+#' for the trees in x.
+#' 
+#' @param x \code{x} is an object of class \code{multiPhylo} or \code{phylo}
+#' @param tree logical indicating whether return the tree with the clade
+#' credibility (default) or the clade credibility score for all trees.
+#' @param rooted logical, if FALSE the tree with highest maximum bipartition
+#' credibility is returned.
+#' @param part a list of partitions as returned by \code{prop.part}
+#' @return a tree (an object of class \code{phylo}) with the highest clade
+#' credibility or a numeric vector of clade credibilities for each tree.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{consensus}}, \code{\link{consensusNet}},
+#' \code{\link{prop.part}}
+#' @keywords cluster
+#' @examples
+#' 
+#' 
+#' data(Laurasiatherian)
+#' set.seed(42)
+#' bs <- bootstrap.phyDat(Laurasiatherian, FUN = function(x)upgma(dist.hamming(x)), 
+#'     bs=100)
+#' class(bs) <- 'multiPhylo'
+#' 
+#' strict_consensus <- consensus(bs)
+#' majority_consensus <- consensus(bs, p=.5)
+#' max_clade_cred <- maxCladeCred(bs)
+#' par(mfrow = c(1,3), mar = c(1,4,1,1))
+#' plot(strict_consensus, main="Strict consensus tree")
+#' plot(majority_consensus, main="Majority consensus tree")
+#' plot(max_clade_cred, main="Maximum clade credibility tree")
+#' 
+#' # compute clade credibility for trees given a prop.part object
+#' pp <- prop.part(bs)
+#' tree <- rNNI(bs[[1]], 20)
+#' maxCladeCred(c(tree, bs[[1]]), tree=FALSE, part = pp)
+#' # first value likely be -Inf
+#' 
+#' @export maxCladeCred
 maxCladeCred <- function(x, tree=TRUE, part=NULL, rooted=TRUE){
     if(inherits(x, "phylo")) x <- c(x)
     if (is.null(part)){ 
diff --git a/R/cladePar.R b/R/cladePar.R
index 35da6c5..88c7fae 100644
--- a/R/cladePar.R
+++ b/R/cladePar.R
@@ -1,3 +1,30 @@
+#' Utility function to plot.phylo
+#' 
+#' cladePar can help you coloring (choosing edge width/type) of clades.
+#' 
+#' 
+#' @param tree an object of class phylo.
+#' @param node the node which is the common ancestor of the clade.
+#' @param edge.color see plot.phylo.
+#' @param tip.color see plot.phylo.
+#' @param edge.width see plot.phylo.
+#' @param edge.lty see plot.phylo.
+#' @param x the result of a previous call to cladeInfo.
+#' @param plot logical, if TRUE the tree is plotted.
+#' @param \dots Further arguments passed to or from other methods.
+#' @return A list containing the information about the edges and tips.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{plot.phylo}}
+#' @keywords plot
+#' @examples
+#' 
+#' tree = rtree(10)
+#' plot(tree)
+#' nodelabels()
+#' x = cladePar(tree, 12)
+#' cladePar(tree, 18, "blue", "blue", x=x, plot=TRUE)
+#' 
+#' @export cladePar
 cladePar = function(tree, node, edge.color="red", tip.color=edge.color, edge.width = 1, edge.lty = 1, x=NULL, plot=FALSE, ...){
     if(is.null(x)){
         m = max(tree$edge)
diff --git a/R/clanistic.R b/R/clanistic.R
index 02c6c1a..4794394 100644
--- a/R/clanistic.R
+++ b/R/clanistic.R
@@ -1,6 +1,127 @@
 ###########################################################################################
 
 
+
+
+#' Clans, slices and clips
+#' 
+#' Functions for clanistics to compute clans, slices, clips for unrooted trees
+#' and functions to quantify the fragmentation of trees.
+#' 
+#' Every split in an unrooted tree defines two complementary clans. Thus for an
+#' unrooted binary tree with \eqn{n} leaves there are \eqn{2n - 3} edges, and
+#' therefore \eqn{4n - 6} clans (including \eqn{n} trivial clans containing
+#' only one leave).
+#' 
+#' Slices are defined by a pair of splits or tripartitions, which are not
+#' clans. The number of distinguishable slices for a binary tree with \eqn{n}
+#' tips is \eqn{2n^2 - 10n + 12}.
+#' 
+#' %A clip is a different type of partition as it is defined by evolutionary or
+#' cophenetic distance and not by the topology. Namely clips are groups of
+#' leaves for which the maximum pairwise distance is smaller than threshold.
+#' %For a better separation we additionally demand that the maximum pairwise
+#' distance within a clip is lower than the distance between any member of the
+#' clip and any other tip.
+#' 
+#' A clip is a different type of partition, defining groups of leaves that are
+#' related in terms of evolutionary distances and not only topology.  Namely,
+#' clips are groups of leaves for which all pairwise path-length distances are
+#' smaller than a given threshold value (Lapointe et al. 2010). There exists
+#' different numbers of clips for different thresholds, the largest (and
+#' trivial) one being the whole tree.  There is always a clip containing only
+#' the two leaves with the smallest pairwise distance.
+#' 
+#' Clans, slices and clips can be used to characterize how well a vector of
+#' categorial characters (natives/intruders) fit on a tree. We will follow the
+#' definitions of Lapointe et al.(2010).  A complete clan is a clan that
+#' contains all leaves of a given state/color, but can also contain leaves of
+#' another state/color. A clan is homogeneous if it only contains leaves of one
+#' state/color.
+#' 
+#' \code{getDiversity} computes either the \cr Shannon Diversity: \eqn{H =
+#' -\sum_{i=1}^{k}(N_i/N) log(N_i/N), N=\sum_{i=1}^{k} N_i}{H = -sum(N_i/N) *
+#' log(N_i/N), N=sum(N_i)} \cr or the \cr Equitability Index: \eqn{E = H /
+#' log(N)} \cr where \eqn{N_i} are the sizes of the \eqn{k} largest homogeneous
+#' clans of intruders.  If the categories of the data can be separated by an
+#' edge of the tree then the E-value will be zero, and maximum equitability
+#' (E=1) is reached if all intruders are in separate clans. getDiversity
+#' computes these Intruder indices for the whole tree, complete clans and
+#' complete slices. Additionally the parsimony scores (p-scores) are reported.
+#' The p-score indicates if the leaves contain only one color (p-score=0), if
+#' the the leaves can be separated by a single split (perfect clan, p-score=1)
+#' or by a pair of splits (perfect slice, p-score=2).
+#' 
+#' So far only 2 states are supported (native, intruder), however it is also
+#' possible to recode several states into the native or intruder state using
+#' contrasts, for details see section 2 in vignette("phangorn-specials").
+#' Furthermore unknown character states are coded as ambiguous character, which
+#' can act either as native or intruder minimizing the number of clans or
+#' changes (in parsimony analysis) needed to describe a tree for given data.
+#' 
+#' Set attribute labels to "old" for analysis as in Schliep et al. (2010) or to
+#' "new" for names which are more intuitive.
+#' 
+#' \code{diversity} returns a data.frame with the parsimony score for each tree
+#' and each levels of the variables in \code{X}. \code{X} has to be a
+#' \code{data.frame} where each column is a factor and the rownames of \code{X}
+#' correspond to the tips of the trees.
+#' 
+#' %TODO See also vignette("Clanistic").
+#' 
+#' @param tree An object of class phylo or multiPhylo (getDiversity).
+#' @param all A logical, return all or just the largest clip.
+#' @param x An object of class phyDat.
+#' @param norm A logical, return Equitability Index (default) or Shannon
+#' Diversity.
+#' @param var.names A vector of variable names.
+#' @param labels see details.
+#' @param X a data.frame
+#' @return getClans, getSlices and getClips return a matrix of partitions, a
+#' matrix of ones and zeros where rows correspond to a clan, slice or clip and
+#' columns to tips. A one indicates that a tip belongs to a certain partition.
+#' \cr getDiversity returns a list with tree object, the first is a data.frame
+#' of the equitability index or Shannon divergence and parsimony scores
+#' (p-score) for all trees and variables. The data.frame has two attributes,
+#' the first is a splits object to identify the taxa of each tree and the
+#' second is a splits object containing all partitions that perfectly fit.
+#' @author Klaus Schliep \email{klaus.schliep@@snv.jussieu.fr}
+#' 
+#' Francois-Joseph Lapointe \email{francois-joseph.lapointe@@umontreal.ca}
+#' @seealso \code{\link{parsimony}}, Consistency index \code{\link{CI}},
+#' Retention index \code{\link{RI}}, \code{\link{phyDat}}
+#' @references Lapointe, F.-J., Lopez, P., Boucher, Y., Koenig, J., Bapteste,
+#' E. (2010) Clanistics: a multi-level perspective for harvesting unrooted gene
+#' trees. \emph{Trends in Microbiology} 18: 341-347
+#' 
+#' Wilkinson, M., McInerney, J.O., Hirt, R.P., Foster, P.G., Embley, T.M.
+#' (2007) Of clades and clans: terms for phylogenetic relationships in unrooted
+#' trees. \emph{Trends in Ecology and Evolution} 22: 114-115
+#' 
+#' Schliep, K., Lopez, P., Lapointe F.-J., Bapteste E. (2011) Harvesting
+#' Evolutionary Signals in a Forest of Prokaryotic Gene Trees, \emph{Molecular
+#' Biology and Evolution} 28(4): 1393-1405
+#' @keywords cluster
+#' @examples
+#' 
+#' set.seed(111)
+#' tree = rtree(10)
+#' getClans(tree)
+#' getClips(tree, all=TRUE)
+#' getSlices(tree)
+#' 
+#' set.seed(123)
+#' trees = rmtree(10, 20)
+#' X = matrix(sample(c("red", "blue", "violet"), 100, TRUE, c(.5,.4, .1)), ncol=5, 
+#'     dimnames=list(paste('t',1:20, sep=""), paste('Var',1:5, sep="_")))
+#' x = phyDat(X, type = "USER", levels = c("red", "blue"), ambiguity="violet")
+#' plot(trees[[1]], "u", tip.color = X[trees[[1]]$tip,1])  # intruders are blue 
+#' 
+#' (divTab <- getDiversity(trees, x, var.names=colnames(X)))
+#' summary(divTab)
+#' 
+#' @rdname getClans
+#' @export 
 getClans = function (tree) 
 {
 	if (is.rooted(tree)) 
@@ -30,6 +151,8 @@ getClans = function (tree)
 }
 
 
+#' @rdname getClans
+#' @export
 getSlices <- function(tree){
     nTips = length(tree$tip.label)
     clans = getClans(tree)
@@ -66,6 +189,8 @@ getSlices <- function(tree){
 }
 
 
+#' @rdname getClans
+#' @export
 getClips = function (tree, all = TRUE) 
 {
     if (any(is.na(tree$edge.length))) 
@@ -249,6 +374,8 @@ getDiv <- function(tree, x, native=NULL){
 }
 
 
+#' @rdname getClans
+#' @export
 getDiversity <- function (tree, x, norm = TRUE, var.names = NULL, labels="new") 
 {
     k = 1
@@ -367,6 +494,8 @@ compareSplits <- function(res, nam1, nam2){
 }
 
 
+#' @rdname getClans
+#' @export
 diversity <- function(tree, X){  
 # from kknn
     contr.dummy <- function (n, contrasts = TRUE) 
diff --git a/R/delta.score.R b/R/delta.score.R
new file mode 100644
index 0000000..44fdc23
--- /dev/null
+++ b/R/delta.score.R
@@ -0,0 +1,69 @@
+################################################################################
+# delta.score
+################################################################################
+# Calculated from mathematical description given in Gray et al. (2010) Phil.
+# Trans. Roy. Soc. B. 
+# delta.score reference: Holland et al. (2002) Mol. Biol. Evol.
+################################################################################ 
+
+
+# Calculating Delta and Q-residual scores 
+# internal
+delta.quartet <-
+    function(quartet,dist.dna) {
+        m1 <- dist.dna[quartet[1],quartet[2]] + dist.dna[quartet[3],quartet[4]]
+        m2 <- dist.dna[quartet[1],quartet[3]] + dist.dna[quartet[2],quartet[4]]
+        m3 <- dist.dna[quartet[1],quartet[4]] + dist.dna[quartet[2],quartet[3]]
+        m <- sort(c(m1,m2,m3),decreasing=T)
+        if((m[1]-m[3])!=0) {
+            ret <- (m[1]-m[2])/(m[1]-m[3])
+        } else {
+            ret <- 0
+        }
+        return(ret)
+    }
+
+
+
+
+#' Computes the \eqn{\delta} score
+#' 
+#' Computes the treelikeness
+#' 
+#' 
+#' @param x an object of class \code{phyDat}
+#' @param arg Specifies the return value, one of "all", "mean" or "sd"
+#' @param ...  further arguments passed through \code{dist.hamming}
+#' @return A vector containing the \eqn{\delta} scores.
+#' @author Alastair Potts and Klaus Schliep
+#' @seealso \code{\link{dist.hamming}}
+#' @references BR Holland, KT Huber, A Dress, V Moulton (2002) \eqn{\delta}
+#' Plots: a tool for analyzing phylogenetic distance data Russell D. Gray,
+#' David Bryant, Simon J. Greenhill (2010) On the shape and fabric of human
+#' history \emph{Molecular Biology and Evolution}, \bold{19(12)} 2051--2059
+#' 
+#' Russell D. Gray, David Bryant, Simon J. Greenhill (2010) On the shape and
+#' fabric of human history \emph{Phil. Trans. R. Soc. B}, \bold{365}
+#' 3923--3933; DOI: 10.1098/rstb.2010.0162
+#' @keywords cluster
+#' @examples
+#' 
+#' data(yeast)
+#' hist(delta.score(yeast, "all"))
+#' 
+#' @export delta.score
+delta.score <- function(x, arg="mean", ...) {
+    # dist.dna <- as.matrix(dist.dna(dna,"raw"))   
+    # dist.dna(dna,"raw") is equivalent to dist.hamming(as.phyDat(dna), exclude="all") 
+    dist.dna <- as.matrix(dist.hamming(x, ...))
+    # Number of quartets
+    # choose(length(names(x)),4)
+    # Create all quartets
+    all.quartets <- t(combn(names(x),4))
+    delta.values <- apply(all.quartets[,],1,delta.quartet,dist.dna)
+    if (!arg%in%c("all", "mean","sd")) stop("return options are: all, mean, or sd")
+    if (arg=='all') return(delta.values)
+    if (arg=='mean') return(mean(delta.values))
+    if (arg=='sd') return(sd(delta.values))
+}
+
diff --git a/R/dist.p.R b/R/dist.p.R
index a12d7b9..1c3ae8d 100644
--- a/R/dist.p.R
+++ b/R/dist.p.R
@@ -1,4 +1,71 @@
-
+#' Pairwise Polymorphism P-Distances from DNA Sequences
+#' 
+#' This function computes a matrix of pairwise uncorrected polymorphism
+#' p-distances. Polymorphism p-distances include intra-individual site
+#' polymorphisms (2ISPs; e.g. "R") when calculating genetic distances.
+#' 
+#' The polymorphism p-distances (Potts et al. 2014) have been developed to
+#' analyse intra-individual variant polymorphism. For example, the widely used
+#' ribosomal internal transcribed spacer (ITS) region (e.g. Alvarez and Wendel,
+#' 2003) consists of 100's to 1000's of units within array across potentially
+#' multiple nucleolus organising regions (Bailey et al., 2003; Goeker and
+#' Grimm, 2008). This can give rise to intra-individual site polymorphisms
+#' (2ISPs) that can be detected from direct-PCR sequencing or cloning . Clone
+#' consensus sequences (see Goeker and Grimm, 2008) can be analysed with this
+#' function.
+#' 
+#' @param x a matrix containing DNA sequences; this must be of class "phyDat"
+#' (use as.phyDat to convert from DNAbin objects).
+#' @param cost A cost matrix or "polymorphism" for a predefined one.
+#' @param ignore.indels a logical indicating whether gaps are treated as fifth
+#' state or not. Warning, each gap site is treated as a characters, so an an
+#' indel that spans a number of base positions would be treated as multiple
+#' character states.
+#' @return an object of class \code{dist}.
+#' @author Klaus Schliep and Alastair Potts
+#' @seealso \code{\link[ape]{dist.dna}}, \code{\link[phangorn]{dist.hamming}}
+#' @references Alvarez, I., and J. F. Wendel. (2003) Ribosomal ITS sequences
+#' and plant phylogenetic inference. \emph{ Molecular Phylogenetics and
+#' Evolution}, \bold{29}, 417--434.
+#' 
+#' Bailey, C. D., T. G. Carr, S. A. Harris, and C. E. Hughes. (2003)
+#' Characterization of angiosperm nrDNA polymorphism, paralogy, and
+#' pseudogenes. \emph{Molecular Phylogenetics and Evolution} \bold{29},
+#' 435--455.
+#' 
+#' Goeker, M., and G. Grimm. (2008) General functions to transform associate
+#' data to host data, and their use in phylogenetic inference from sequences
+#' with intra-individual variability. \emph{BMC Evolutionary Biology},
+#' \bold{8}:86.
+#' 
+#' Potts, A.J., T.A. Hedderson, and G.W. Grimm. (2014) Constructing phylogenies
+#' in the presence of intra-individual site polymorphisms (2ISPs) with a focus
+#' on the nuclear ribosomal cistron. \emph{Systematic Biology}, \bold{63},
+#' 1--16
+#' @keywords cluster
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' laura = as.DNAbin(Laurasiatherian)
+#' 
+#' dm <- dist.p(Laurasiatherian, "polymorphism")
+#' 
+#' ########################################################
+#' # Dealing with indel 2ISPs
+#' # These can be coded using an "x" in the alignment. Note
+#' # that as.character usage in the read.dna() function.
+#' #########################################################
+#' cat("3 5",
+#'     "No305     ATRA-",
+#'     "No304     ATAYX",
+#'     "No306     ATAGA",
+#'     file = "exdna.txt", sep = "\n")
+#' (ex.dna <- read.dna("exdna.txt", format = "sequential", as.character=TRUE))
+#' dat= phyDat(ex.dna, "USER", levels=unique(as.vector(ex.dna)))
+#' dist.p(dat)
+#' 
+#' 
+#' @export dist.p
 dist.p <- function (x, cost="polymorphism", ignore.indels=TRUE) 
 {
     if (!inherits(x,"phyDat")) 
diff --git a/R/distSeq.R b/R/distSeq.R
index 8269d5a..2dea1fe 100644
--- a/R/distSeq.R
+++ b/R/distSeq.R
@@ -1,6 +1,66 @@
 #
 # dist
 #
+
+
+#' Pairwise Distances from Sequences
+#' 
+#' \code{dist.hamming}, \code{dist.ml} and \code{dist.logDet} compute pairwise
+#' distances for an object of class \code{phyDat}.  \code{dist.ml} uses DNA /
+#' AA sequences to compute distances under different substitution models.
+#' 
+#' So far 17 amino acid models are supported ("WAG", "JTT", "LG", "Dayhoff",
+#' "cpREV", "mtmam", "mtArt", "MtZoa", "mtREV24", "VT","RtREV", "HIVw", "HIVb",
+#' "FLU", "Blossum62", "Dayhoff_DCMut" and "JTT_DCMut") and additional rate
+#' matrices and frequencies can be supplied.
+#' 
+#' The "F81" model uses empirical base frequencies, the "JC69" equal base
+#' frequencies. This is even the case if the data are not nucleotides.
+#' 
+#' @param x An object of class \code{phyDat}
+#' @param ratio Compute uncorrected ('p') distance or character difference.
+#' @param model One of "JC69", "F81" or one of 17 amino acid models see
+#' details.
+#' @param exclude One of "none", "all", "pairwise" indicating whether to delete
+#' the sites with missing data (or ambiguous states). The default is handle
+#' missing data as in pml.
+#' @param bf A vector of base frequencies.
+#' @param Q A vector containing the lower triangular part of the rate matrix.
+#' @param k Number of intervals of the discrete gamma distribution.
+#' @param shape Shape parameter of the gamma distribution.
+#' @param \dots Further arguments passed to or from other methods.
+#' @return an object of class \code{dist}
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso For more distance methods for nucleotide data see
+#' \code{\link[ape]{dist.dna}} and \code{\link{dist.p}} for pairwise
+#' polymorphism p-distances. \code{\link{writeDist}} for export and import distances.
+#' @references Lockhart, P. J., Steel, M. A., Hendy, M. D. and Penny, D. (1994)
+#' Recovering evolutionary trees under a more realistic model of sequence
+#' evolution. \emph{Molecular Biology and Evolution}, \bold{11}, 605--602.
+#' 
+#' Jukes TH and Cantor CR (1969). \emph{Evolution of Protein Molecules}. New
+#' York: Academic Press. 21--132.
+#' @keywords cluster
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' dm1 <- dist.hamming(Laurasiatherian)
+#' tree1 <- NJ(dm1)
+#' dm2 <- dist.logDet(Laurasiatherian)
+#' tree2 <- NJ(dm2)
+#' treedist(tree1,tree2)
+#' # JC model
+#' dm3 <- dist.ml(Laurasiatherian)
+#' tree3 <- NJ(dm3)
+#' treedist(tree1,tree3)
+#' # F81 + Gamma
+#' dm4 <- dist.ml(Laurasiatherian, model="F81", k=4, shape=.4)
+#' tree4 <- NJ(dm4)
+#' treedist(tree1,tree4)
+#' treedist(tree3,tree4)
+#' 
+#' @rdname dist.hamming 
+#' @export 
 dist.hamming <- function (x, ratio = TRUE, exclude = "none") 
 {
     if (!inherits(x,"phyDat")) 
@@ -69,7 +129,8 @@ dist.hamming <- function (x, ratio = TRUE, exclude = "none")
 }
 
 
-
+#' @rdname dist.hamming
+#' @export
 dist.ml <- function (x, model = "JC69", exclude = "none", bf = NULL, Q = NULL, k=1L, shape=1, ...) 
 {
     if (!inherits(x,"phyDat")) 
@@ -161,7 +222,9 @@ dist.ml <- function (x, model = "JC69", exclude = "none", bf = NULL, Q = NULL, k
     return(d)
 }
 
-   
+
+#' @rdname dist.hamming
+#' @export   
 dist.logDet = function (x) 
 {
     if (!inherits(x,"phyDat")) 
@@ -199,21 +262,117 @@ dist.logDet = function (x)
 }
 
 
-readDist <- function(file){ #, format="phylip"
-    tmp <- read.table(file, skip=1, stringsAsFactors = FALSE)
-    labels = tmp[,1]
-    dm <- as.matrix(tmp[,-1]) 
-    dimnames(dm)=list(labels, labels)    
-    as.dist(dm)
-}
+
+
+#' Writing and reading distances in phylip and nexus format
+#' 
+#' \code{readDist}, \code{writeDist} and \code{write.nexus.dist} are useful to 
+#' exchange distance matrices with other phylogenetic programs.  
+#' 
+#' 
+#' @param x A \code{dist} object.
+#' @param file A file name.
+#' @param format file format, default is "phylip", only other option so far is "nexus". 
+#' @param \dots Further arguments passed to or from other methods. 
+#' @param upper	logical value indicating whether the upper triangle of the distance 
+#' matrix should be printed.
+#' @param diag	logical value indicating whether the diagonal of the distance matrix 
+#' should be printed.
+#' @param digits passed to format inside of \code{write.nexus.dist}.
+#' @param taxa logical. If TRUE a taxa block is added.
+#' @param append logical. If TRUE the nexus blocks will be added to a file.
+#' @return an object of class \code{dist}
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso To compute distance matrices see \code{\link{dist.ml}}
+#' \code{\link[ape]{dist.dna}} and \code{\link{dist.p}} for pairwise
+#' polymorphism p-distances
+#' @references Maddison, D. R., Swofford, D. L. and Maddison, W. P. (1997) 
+#' NEXUS: an extensible file format for systematic information. 
+#' \emph{Systematic Biology}, \bold{46}, 590--621.
+#' 
+#' @keywords cluster
+#' @examples
+#' 
+#' data(yeast)
+#' dm <- dist.ml(yeast)
+#' writeDist(dm)
+#' write.nexus.dist(dm)
+#' 
+#' @rdname writeDist 
+#' @export writeDist
+writeDist <- function(x, file="", format="phylip", ...){ 
+    format <- match.arg(format, c("phylip", "nexus"))
+    if(format=="phylip"){
+        x <- as.matrix(x)
+#        x <- format(x, digits = digits, justify = "none")
+        cat(ncol(x), "\n", file=file)
+        write.table(x, file, append=TRUE, quote=FALSE, col.names=FALSE)
+    }
+    else write.nexus.dist(x, file=file, ...)
+}    
     
+
+#' @rdname writeDist
+#' @export 
+write.nexus.dist <- function(x, file="", append=FALSE, upper=FALSE, diag=TRUE, digits = getOption("digits"), taxa=!append){
     
-writeDist <- function(dm, file=""){ # , format="phylip"
-    dm <- as.matrix(dm)
-    cat(ncol(dm), "\n", file=file)
-    write.table(dm, file, append=TRUE, quote=FALSE, col.names=FALSE)
-}    
+    taxa.labels <- attr(x, "Labels")
+    ntaxa <- length(taxa.labels)
     
+    m <- as.matrix(x)
+    cf <- format(m, digits = digits, justify = "none")    
+    l <-  length(attr(x, "Labels"))
+    if(upper) diag <- TRUE
+    if (!upper) cf[row(cf) < col(cf)] <- ""
+    if (!diag) cf[row(cf) == col(cf)] <- ""    
     
+    cf2 <- apply(cf, 1, "paste0", collapse=" ")
+    cf2 <- paste(attr(x, "Labels"), cf2)
+    cf2 <- trimws(cf2, "right")
+    
+    if(!append)cat("#NEXUS\n\n", file = file)  
+    
+    if(taxa){
+        cat(paste("BEGIN TAXA;\n\tDIMENSIONS ntax=", ntaxa, ";\n", 
+                  sep = ""), file = file, append = TRUE)
+        cat("\tTAXLABELS", paste(taxa.labels, sep = " "), ";\nEND;\n\n", 
+            file = file, append = TRUE)
+    }
+    
+    cat("BEGIN DISTANCES; \n", file = file, append = TRUE)
+    if(upper) cat("\tFORMAT TRIANGLE = BOTH;\n", file = file, append = TRUE)
+    else cat("\tFORMAT TRIANGLE = LOWER;\n", file = file, append = TRUE)
+    if(!diag) cat("\tFORMAT NODIAGONAL;\n", file = file, append = TRUE)
+    cat("\tMatrix \n", file = file, append = TRUE)
+    #    for(i in 1:(l-1)) cat("\t", cf2[i], "\n", sep="", file = file, append = TRUE)
+    for(i in 1:l) cat("\t", cf2[i], "\n", sep="", file = file, append = TRUE)
+    #    cat("\t", cf2[l], ";\n", file = file, sep="", append = TRUE)
+    #    cat("END; \n", file = file, append = TRUE)
+    cat("\t;\nEND; \n", file = file, append = TRUE)
+}
+
+
+
+RSS <- function(x, dm, trace=0){
+    labels=attr(x, "labels")
+    dm = as.matrix(dm)
+    k = dim(dm)[1]
+    dm = dm[labels,labels]
+    y = dm[lower.tri(dm)]
+    betahat <- attr(x, "weights")
+    X = splits2design(x)
+    RSS = sum((y-(X%*%betahat))^2)
+    RSS
+}    
+
 
 
+#' @rdname writeDist
+#' @export  
+readDist <- function(file){ #, format="phylip"
+    tmp <- read.table(file, skip=1, stringsAsFactors = FALSE)
+    labels = tmp[,1]
+    dm <- as.matrix(tmp[,-1]) 
+    dimnames(dm)=list(labels, labels)    
+    as.dist(dm)
+}
\ No newline at end of file
diff --git a/R/distTree.R b/R/distTree.R
index ca5d097..7eee067 100644
--- a/R/distTree.R
+++ b/R/distTree.R
@@ -1,6 +1,33 @@
 #
 # UPGMA, NJ, UNJ, nnls
 #
+
+
+#' UPGMA and WPGMA
+#' 
+#' UPGMA and WPGMA clustering. Just a wrapper function around
+#' \code{\link[stats]{hclust}}.
+#' 
+#' 
+#' @param D A distance matrix.
+#' @param method The agglomeration method to be used. This should be (an
+#' unambiguous abbreviation of) one of "ward", "single", "complete", "average",
+#' "mcquitty", "median" or "centroid". The default is "average".
+#' @param \dots Further arguments passed to or from other methods.
+#' @return A phylogenetic tree of class \code{phylo}.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{hclust}}, \code{\link{dist.hamming}}, \code{\link{NJ}},
+#' \code{\link{as.phylo}}, \code{\link{fastme}}, \code{\link{nnls.tree}}
+#' @keywords cluster
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' dm = dist.ml(Laurasiatherian)
+#' tree = upgma(dm)
+#' plot(tree)
+#' 
+#' @rdname upgma
+#' @export 
 "upgma" <- function(D,method="average",...){
     DD=as.dist(D)
     hc = hclust(DD,method=method,...)
@@ -10,6 +37,8 @@
 }
 
 
+#' @rdname upgma
+#' @export
 "wpgma" <- function(D,method="mcquitty",...){
     DD=as.dist(D)
     hc = hclust(DD,method=method,...)
@@ -139,9 +168,47 @@ NJ_old <- function(x)
 }
 
 
+
+
+#' Neighbor-Joining
+#' 
+#' This function performs the neighbor-joining tree estimation of Saitou and
+#' Nei (1987). UNJ is the unweighted version from Gascuel (1997).
+#' 
+#' @aliases PNJ
+#' 
+#' @param x A distance matrix.
+#' @return an object of class \code{"phylo"}.
+#' @author Klaus P. Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link[ape]{nj}}, \code{\link[ape]{dist.dna}},
+#' \code{\link[phangorn]{dist.hamming}}, \code{\link[phangorn]{upgma}},
+#' \code{\link[ape]{fastme}}
+#' @references Saitou, N. and Nei, M. (1987) The neighbor-joining method: a new
+#' method for reconstructing phylogenetic trees. \emph{Molecular Biology and
+#' Evolution}, \bold{4}, 406--425.
+#' 
+#' Studier, J. A and Keppler, K. J. (1988) A Note on the Neighbor-Joining
+#' Algorithm of Saitou and Nei. \emph{Molecular Biology and Evolution},
+#' \bold{6}, 729--731.
+#' 
+#' Gascuel, O. (1997) Concerning the NJ algorithm and its unweighted version,
+#' UNJ. in Birkin et. al. \emph{Mathematical Hierarchies and Biology},
+#' 149--170.
+#' @keywords cluster
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' dm <- dist.ml(Laurasiatherian)
+#' tree <- NJ(dm)
+#' plot(tree)
+#' 
+#' @rdname NJ
+#' @export 
 NJ <- function(x) reorder(nj(x), "postorder")
 
 
+#' @rdname NJ
+#' @export
 UNJ <- function(x) 
 {
     x = as.matrix(x)
@@ -264,6 +331,46 @@ PNJ <- function (data)
 #
 
 # as.Matrix, sparse = TRUE, 
+
+
+#' Compute a design matrix or non-negative LS
+#' 
+#' \code{nnls.tree} estimates the branch length using non-negative least
+#' squares given a tree and a distance matrix.  \code{designTree} and
+#' \code{designSplits} compute design matrices for the estimation of edge
+#' length of (phylogenetic) trees using linear models.  For larger trees a
+#' sparse design matrix can save a lot of memory. %\code{designTree} also
+#' computes a contrast matrix if the method is "rooted".
+#' 
+#' @param tree an object of class \code{phylo}
+#' @param method design matrix for an "unrooted" or "rooted" ultrametric tree.
+#' @param sparse return a sparse design matrix.
+#' @param x number of taxa.
+#' @param splits one of "all", "star".
+#' @param dm a distance matrix.
+#' @param rooted compute a "rooted" or "unrooted" tree.
+#' @param trace defines how much information is printed during optimisation.
+#' @param \dots further arguments, passed to other methods.
+#' @return \code{nnls.tree} return a tree, i.e. an object of class
+#' \code{phylo}.  \code{designTree} and \code{designSplits} a matrix, possibly
+#' sparse.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link[ape]{fastme}},
+#' \code{\link[phangorn]{distanceHadamard}},
+#' \code{\link[phangorn]{splitsNetwork}}, \code{\link[phangorn]{upgma}}
+#' @keywords cluster
+#' @examples
+#' 
+#' example(NJ)
+#' dm <-  as.matrix(dm)
+#' y <- dm[lower.tri(dm)]
+#' X <- designTree(tree)
+#' lm(y~X-1)
+#' # avoids negative edge weights 
+#' tree2 = nnls.tree(dm, tree)
+#' 
+#' @rdname designTree
+#' @export 
 designTree <- function(tree, method="unrooted", sparse=FALSE, ...){
     if (!is.na(pmatch(method, "all"))) 
         method <- "unrooted"
@@ -422,6 +529,8 @@ designUnrooted2 <- function (tree, sparse=TRUE)
 }
 
 
+#' @rdname designTree
+#' @export
 nnls.tree <- function(dm, tree, rooted=FALSE, trace=1){
     if(is.rooted(tree) & rooted==FALSE){
         tree = unroot(tree)
@@ -511,11 +620,15 @@ nnls.tree <- function(dm, tree, rooted=FALSE, trace=1){
 }
 
 
+#' @rdname designTree
+#' @export
 nnls.phylo <- function(x, dm, rooted=FALSE, trace=0){
     nnls.tree(dm, x, rooted, trace=trace)
 }
 
 
+#' @rdname designTree
+#' @export
 nnls.splits <- function(x, dm, trace=0){
     labels=attr(x, "labels")
     dm = as.matrix(dm)
@@ -568,6 +681,8 @@ nnls.splits <- function(x, dm, trace=0){
 }  
 
 
+#' @rdname designTree
+#' @export
 nnls.networx <- function(x, dm){
 #    spl <- attr(x, "splits")
     spl <- x$splits
@@ -582,6 +697,8 @@ nnls.networx <- function(x, dm){
 }
 
 
+#' @rdname designTree
+#' @export
 designSplits <- function (x, splits = "all", ...) 
 {
     if (!is.na(pmatch(splits, "all"))) 
diff --git a/R/fitch.R b/R/fitch.R
index c47fc18..1d9cf38 100644
--- a/R/fitch.R
+++ b/R/fitch.R
@@ -1,3 +1,5 @@
+#' @rdname parsimony
+#' @export
 fitch <- function (tree, data, site="pscore") 
 { 
     if (!inherits(data,"phyDat")) 
@@ -83,7 +85,8 @@ fnodesNew5 <- function (EDGE, nTips, nr, m= as.integer(max(EDGE)+1L))
 }   
 
 
-
+#' @rdname parsimony
+#' @export
 random.addition <- function(data, method="fitch") 
 {
     label <- names(data)
@@ -425,127 +428,67 @@ getOrder <- function (x)
 }
 
 
-bab_old <- function (data, tree = NULL, trace = 1, ...) 
-{
-    o = order(attr(data, "weight"), decreasing = TRUE)
-    data = subset(data, , o)
-    nr <- attr(data, "nr")
-    pis <- parsinfo(data)
-    p0 <- sum(attr(data, "weight")[pis[, 1]] * pis[, 2])
-    if (length(pis) > 0) 
-        data <- getRows(data, c(1:nr)[-pis[, 1]], TRUE)
-    tree <- pratchet(data, start = tree, trace = trace - 1, ...)
-    data <- subset(data, tree$tip.label) 
-    nr <- as.integer(attr(data, "nr"))
-    inord <- getOrder(data)
-    lb <- lowerBound(data)
-    nTips <- m <- length(data)
-    
-    nr <- as.integer(attr(data, "nr"))
-    TMP <- matrix(0, m, nr)
-    for (i in 4:m) {
-        TMP[i, ] = lowerBound(subset(data, inord[1:i]))
-    }
-
-    weight <- as.double(attr(data, "weight"))
-    data <- prepareDataFitch(data)
-    m = nr*(2L*nTips - 2L)
-    on.exit(.C("fitch_free"))
-    .C("fitch_init", as.integer(data), as.integer(nTips*nr), as.integer(m), as.double(weight), as.integer(nr))
-    mmsAmb = 0
-    mmsAmb = TMP %*% weight  
-    mmsAmb = mmsAmb[nTips] - mmsAmb
-    mms0 = 0 
-    mms0 = mms0 + mmsAmb
-
-    minPars = mms0[1]
-    kPars = 0
-
-    if (trace) 
-        print(paste("lower bound:", p0 + mms0[1]))
-    bound <- fast.fitch(tree, nr)
-    if (trace) 
-        print(paste("upper bound:", bound + p0))
-
-    startTree <- structure(list(edge = structure(c(rep(nTips+1L, 3), as.integer(inord)[1:3]), .Dim = c(3L, 2L)), 
-        tip.label = tree$tip.label, Nnode = 1L), .Names = c("edge", "tip.label", "Nnode"), class = "phylo", order = "postorder")
-
-    trees <- vector("list", nTips)
-    trees[[3]] <- list(startTree$edge)
-    for(i in 4:nTips) trees[[i]] <- vector("list", (2L*i) - 5L) # new
-
-# index M[i] is neues node fuer edge i+1
-# index L[i] is length(node) tree mit i+1 
-    L = as.integer( 2L*(1L:nTips) -3L ) 
-    M = as.integer( 1L:nTips + nTips - 1L )    
-
-    PSC <- matrix(c(3,1,0), 1, 3)
-    PSC[1,3] <- fast.fitch(startTree, nr)
-
-    k = 4L
-    Nnode = 1L
-    npsc = 1
-
-    result <- list() 
-    while (npsc > 0) {
-        a = PSC[npsc,1]
-        b = PSC[npsc,2]
-        PSC = PSC[-npsc,, drop=FALSE]  
-
-        tmpTree <- trees[[a]][[b]]
-        edge = tmpTree[,2]  
-        score = fnodesNew5(tmpTree, nTips, nr, M[a])[edge] + mms0[a+1L] 
-        score <- .Call("FITCHTRIP3", as.integer(inord[a+1L]), as.integer(nr), as.integer(edge), as.double(score), as.double(bound), PACKAGE="phangorn")    
-                   
-        ms = min(score)
-        if(ms<=bound){
-            if((a+1L)<nTips){
-                ind = (1:L[a])[score<=bound]
-                for(i in 1:length(ind))trees[[a+1]][[i]] <- .Call("AddOne", tmpTree, as.integer(inord[a+1L]), as.integer(ind[i]), as.integer(L[a]), as.integer(M[a]), PACKAGE="phangorn") 
-                l = length(ind)
-                os = order(score[ind], decreasing=TRUE)
-                PSC = rbind(PSC, cbind(rep(a+1, l), os, score[ind][os] ))
-            }
-            else{
-                ind = which(score==ms) 
-                tmp <- vector("list", length(ind)) 
-                for(i in 1:length(ind))tmp[[i]] <- .Call("AddOne", tmpTree, as.integer(inord[a+1L]), as.integer(ind[i]), as.integer(L[a]), as.integer(M[a]), PACKAGE="phangorn")
-
-                if(ms < bound){
-                     bound = ms
-                     if(trace)cat("upper bound:", bound, "\n") 
-                     result = tmp    
-                     PSC = PSC[PSC[,3]<(bound+1e-8),]  
-
-                }
-                else result = c(result, tmp)  
-            }
-        }    
-        npsc = nrow(PSC)
-    }
-    for(i in 1:length(result)){
-        result[[i]] = structure(list(edge = result[[i]], Nnode = nTips-2L), .Names = c("edge", "Nnode"), class = "phylo", order = "postorder")
-    }
-    attr(result, "TipLabel") = tree$tip.label
-    class(result) <- "multiPhylo"
-    return(result)
-}
-
-
-
+#' Branch and bound for finding all most parsimonious trees
+#' 
+#' \code{bab} finds all most parsimonious trees.
+#' 
+#' This implementation is very slow and depending on the data may take very
+#' long time. In the worst case all (2n-5)!! possible trees have to be
+#' examined. For 10 species there are already 2027025 tip-labelled unrooted
+#' trees. It only uses some basic strategies to find a lower and upper bounds
+#' similar to penny from phylip. It uses a very basic heuristic approach of
+#' MinMax Squeeze (Holland et al. 2005) to improve the lower bound.  On the
+#' positive side \code{bab} is not like many other implementations restricted
+#' to binary or nucleotide data.
+#' 
+#' @aliases bab BranchAndBound
+#' @param data an object of class phyDat.
+#' @param tree a phylogenetic tree an object of class phylo, otherwise a
+#' pratchet search is performed.
+#' @param trace defines how much information is printed during optimisation.
+#' @param \dots Further arguments passed to or from other methods
+#' @return \code{bab} returns all most parsimonious trees in an object of class
+#' \code{multiPhylo}.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com} based on work on Liam
+#' Revell
+#' @seealso \code{\link{pratchet}}, \code{\link{dfactorial}}
+#' @references Hendy, M.D. and Penny D. (1982) Branch and bound algorithms to
+#' determine minimal evolutionary trees.  \emph{Math. Biosc.} \bold{59},
+#' 277-290
+#' 
+#' Holland, B.R., Huber, K.T. Penny, D. and Moulton, V. (2005) The MinMax
+#' Squeeze: Guaranteeing a Minimal Tree for Population Data, \emph{Molecular
+#' Biology and Evolution}, \bold{22}, 235--242
+#' 
+#' White, W.T. and Holland, B.R. (2011) Faster exact maximum parsimony search
+#' with XMP. \emph{Bioinformatics}, \bold{27(10)},1359--1367
+#' @keywords cluster ~kwd2
+#' @examples
+#' 
+#' data(yeast)
+#' dfactorial(11)
+#' # choose only the first two genes
+#' gene12 <- subset(yeast, , 1:3158, site.pattern=FALSE) 
+#' trees <- bab(gene12)
+#' 
+#' @export bab
 bab <- function (data, tree = NULL, trace = 1, ...) 
 {
     if(!is.null(tree)) data <- subset(data, tree$tip.label) 
-    o = order(attr(data, "weight"), decreasing = TRUE)
-    data = subset(data, , o)
+    pBound=TRUE
+
     nr <- attr(data, "nr")
     pis <- parsinfo(data)
     p0 <- sum(attr(data, "weight")[pis[, 1]] * pis[, 2])
     if (length(pis) > 0) 
         data <- getRows(data, c(1:nr)[-pis[, 1]], TRUE)
+    # TODO unique data
     # added compressSites
     data <- compressSites(data)
-    
+
+    o = order(attr(data, "weight"), decreasing = TRUE)
+    data = subset(data, , o)
+        
     tree <- pratchet(data, start = tree, trace = trace - 1, ...)
     data <- subset(data, tree$tip.label) 
     nr <- as.integer(attr(data, "nr"))
@@ -554,11 +497,14 @@ bab <- function (data, tree = NULL, trace = 1, ...)
     nTips <- m <- length(data)
     
     nr <- as.integer(attr(data, "nr"))
-    TMP <- matrix(0, m, nr)
+    TMP <- UB <- matrix(0, m, nr)
     for (i in 4:m) {
         TMP[i, ] = lowerBound(subset(data, inord[1:i]))
+        UB[i, ] = upperBound(subset(data, inord[1:i]))
     }
     
+    dat_used <- subset(data, inord)
+    
     weight <- as.double(attr(data, "weight"))
     data <- prepareDataFitch(data)
     m = nr*(2L*nTips - 2L)
@@ -567,9 +513,11 @@ bab <- function (data, tree = NULL, trace = 1, ...)
     mmsAmb = 0
     mmsAmb = TMP %*% weight  
     mmsAmb = mmsAmb[nTips] - mmsAmb
-    mms0 = 0 
+    mms0 = 0
+    if(pBound) mms0 = pBound(dat_used, UB) 
     mms0 = mms0 + mmsAmb
     
+    
     minPars = mms0[1]
     kPars = 0
     
@@ -591,8 +539,8 @@ bab <- function (data, tree = NULL, trace = 1, ...)
     L = as.integer( 2L*(1L:nTips) -3L ) 
     M = as.integer( 1L:nTips + nTips - 1L )    
     
-#   PSC = matrix(0, sum(sapply(trees, length)), 3)    
-#   PSC[1,] = c(3,1,0)  
+    #   PSC = matrix(0, sum(sapply(trees, length)), 3)    
+    #   PSC[1,] = c(3,1,0)  
     
     PSC <- matrix(c(3,1,0), 1, 3)
     PSC[1,3] <- fast.fitch(startTree, nr)
@@ -601,12 +549,14 @@ bab <- function (data, tree = NULL, trace = 1, ...)
     Nnode = 1L
     npsc = 1
     
+    blub = numeric(nTips)
+    
     result <- list() 
     while (npsc > 0) {
         a = PSC[npsc,1]
         b = PSC[npsc,2]
         PSC = PSC[-npsc,, drop=FALSE]  
-        
+        npsc <- npsc - 1L        
         tmpTree <- trees[[a]][[b]]
         edge = tmpTree[,2]  
         score = fnodesNew5(tmpTree, nTips, nr, M[a])[edge] + mms0[a+1L] 
@@ -618,10 +568,13 @@ bab <- function (data, tree = NULL, trace = 1, ...)
                 ind = (1:L[a])[score<=bound]
                 trees[[a+1]][1:length(ind)] <- .Call("AddOnes", tmpTree, as.integer(inord[a+1L]), as.integer(ind), as.integer(L[a]), as.integer(M[a]), PACKAGE="phangorn") 
                 l = length(ind)
-#                os = order(score[ind], decreasing=TRUE)     
+                #                os = order(score[ind], decreasing=TRUE)     
                 os = seq_len(l)
+                # in C pushback                
                 PSC = rbind(PSC, cbind(rep(a+1, l), os, score[ind] ))
-#                PSC = rbind(PSC, cbind(rep(a+1, l), os, score[ind][os] ))
+                npsc <- npsc + l
+                blub[a] = blub[a] + l
+                #                PSC = rbind(PSC, cbind(rep(a+1, l), os, score[ind][os] ))
             }
             else{
                 ind = which(score==ms) 
@@ -630,20 +583,93 @@ bab <- function (data, tree = NULL, trace = 1, ...)
                 
                 if(ms < bound){
                     bound = ms
-                    if(trace)cat("upper bound:", bound, "\n") 
+                    if(trace)cat("upper bound:", bound + p0, "\n") 
                     result = tmp    
                     PSC = PSC[PSC[,3]<(bound+1e-8),]  
-                    
+                    npsc = nrow(PSC)
                 }
                 else result = c(result, tmp)  
             }
         }    
-        npsc = nrow(PSC)
+        # not needed here        
+#        npsc = nrow(PSC)
     }
     for(i in 1:length(result)){
         result[[i]] = structure(list(edge = result[[i]], Nnode = nTips-2L), .Names = c("edge", "Nnode"), class = "phylo", order = "postorder")
     }
     attr(result, "TipLabel") = tree$tip.label
+#    attr(result, "visited") = blub
     class(result) <- "multiPhylo"
     return(result)
 }
+
+
+pBound <- function(x, UB){
+    tip <- names(x)
+    att = attributes(x)
+    nc = attr(x, "nc")
+    nr = attr(x, "nr")
+    contrast = attr(x, "contrast")
+    rownames(contrast) = attr(x, "allLevels")
+    colnames(contrast) = attr(x, "levels")
+    weight0 <- attr(x, "weight")
+    attr(x, "weight") = rep(1, nr)
+    attr(x, "index") = NULL
+    
+    y <- as.character(x)
+    #    states <- apply(y, 2, unique.default)
+    #    singles <- match(attr(x, "levels"), attr(x, "allLevels"))
+    singles <- attr(x, "levels")
+    fun2 <- function(x, singles)all(x %in% singles)
+    
+    fun1 <- function(x){cumsum(!duplicated(x))-1L}
+    #    pmax 
+    #    ntips > pmax
+    
+    tmp <- apply(y, 2, fun2, singles)
+    ind <- which(tmp)
+    if(length(ind)<2) return(numeric(nTips))
+    
+    y <- y[, ind, drop=FALSE]
+    weight0 <- weight0[ind]
+    
+    UB <- UB[, ind, drop=FALSE]    
+    single_dis <- apply(y, 2, fun1)
+    # single_dis <- lowerBound
+    
+    nTips <- nrow(y) 
+    l <- length(weight0)
+    
+    res <- numeric(nTips)
+    
+    for(i in 1:(l-1)){
+        for(j in (i+1):l){
+            #            cat(i, j, "\n")
+            if( (weight0[i] > 0) & (weight0[j] > 0) ){
+                z <- paste(y[,i], y[,j], sep="_")
+                dis2 <- single_dis[,i] + single_dis[,j]
+                #                D1 <- (dis2[nTips] - dis2) 
+                dis <- fun1(z)
+                #                dis <- pmax(dis, dis2)
+                #                D2 <- dis[nTips] - (UB[, i] + UB[, j])
+                if(dis[nTips] > dis2[nTips]){
+                    
+                    ub <- UB[,i] + UB[,j]
+                    dis <- dis[nTips] - ub
+                    d2 <- dis2[nTips] - dis2
+                    dis <- pmax(dis, d2) - d2
+                    
+                    if(sum(dis[4:nTips])>0){
+                        wmin <- min(weight0[i], weight0[j])
+                        weight0[i] <- weight0[i] - wmin
+                        weight0[j] <- weight0[j] - wmin
+                        res <- res + dis * wmin
+                    }
+                }
+            }    
+            if( weight0[i] < 1e-6 )  break()
+        }
+    }
+    res
+}
+
diff --git a/R/hadamard.R b/R/hadamard.R
index f940fc6..80eb146 100644
--- a/R/hadamard.R
+++ b/R/hadamard.R
@@ -27,13 +27,36 @@ dec2bin <- function (x, k=ceiling(log2(x)))
 }
 
 # double factorial: log version
-"ldfactorial" <- function(x){
+#' @rdname dfactorial
+#' @export
+ldfactorial <- function(x){
     x = (x+1)/2
     res = lgamma(2*x)-(lgamma(x)+(x-1)*log(2))
     res
 }
 
 # double factorial
+
+
+#' Arithmetic Operators
+#' 
+#' double factorial function
+#' 
+#' 
+#' @param x a numeric scalar or vector
+#' @return \code{dfactorial(x)} returns the double factorial, that is
+#' \eqn{x\!\! = 1 * 3 * 5 * \ldots * x } and \code{ldfactorial(x)} is the
+#' natural logarithm of it.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link[base:Special]{factorial}},
+#' \code{\link[ape]{howmanytrees}}
+#' @keywords classif
+#' @examples
+#' 
+#' dfactorial(1:10)
+#' 
+#' @rdname dfactorial
+#' @export dfactorial
 "dfactorial" <- function(x){exp(ldfactorial(x))}
 
 
@@ -41,6 +64,74 @@ dec2bin <- function (x, k=ceiling(log2(x)))
 # Hadamard Conjugation
 #
 
+
+### @aliases hadamard fhm h4st h2st
+
+#' Hadamard Matrices and Fast Hadamard Multiplication
+#' 
+#' A collection of functions to perform Hadamard conjugation.  %Hv of a
+#' Hadamard matrix H with a vector v using fast Hadamard multiplication.
+#' 
+#' \code{h2st} and \code{h4st} perform Hadamard conjugation for 2-state
+#' (binary, RY-coded) or 4-state (DNA/RNA) data. \code{write.nexus.splits}
+#' writes splits returned from \code{h2st} or
+#' \code{\link[phangorn]{distanceHadamard}} to a nexus file, which can be
+#' processed by Spectronet or Splitstree.
+#' 
+#' @param x a vector of length \eqn{2^n}, where n is an integer.
+#' @param v a vector of length \eqn{2^n}, where n is an integer.
+#' @param obj a data.frame or character matrix, typical a sequence alignment.
+#' @param eps Threshold value for splits.
+#' @param levels levels of the sequences.
+#' @return \code{hadamard} returns a Hadamard matrix. \code{fhm} returns the
+#' fast Hadamard multiplication.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{distanceHadamard}}, \code{\link{lento}},
+#' \code{\link{plot.networx}}
+#' @references Hendy, M.D. (1989). The relationship between simple evolutionary
+#' tree models and observable sequence data. \emph{Systematic Zoology},
+#' \bold{38} 310--321.
+#' 
+#' Hendy, M. D. and Penny, D. (1993). Spectral Analysis of Phylogenetic Data.
+#' \emph{Journal of Classification}, \bold{10}, 5--24.
+#' 
+#' Hendy, M. D. (2005). Hadamard conjugation: an analytical tool for
+#' phylogenetics. In O. Gascuel, editor, \emph{Mathematics of evolution and
+#' phylogeny}, Oxford University Press, Oxford
+#' 
+#' Waddell P. J. (1995). Statistical methods of phylogenetic analysis:
+#' Including hadamard conjugation, LogDet transforms, and maximum likelihood.
+#' \emph{PhD thesis}.
+#' @keywords cluster
+#' @examples
+#' 
+#' H <- hadamard(3)
+#' v <- 1:8
+#' H %*% v
+#' fhm(v)
+#' 
+#' data(yeast)
+#' 
+#' # RY-coding
+#' dat_ry <- acgt2ry(yeast)
+#' fit2 <- h2st(dat_ry)
+#' lento(fit2)
+#' 
+#' # write.nexus.splits(fit2, file = "test.nxs")
+#' # read this file into Spectronet or Splitstree to show the network
+#' \dontrun{
+#' dat = as.character(yeast)
+#' dat4 = phyDat(dat, type="USER", levels=c("a","c", "g", "t"), ambiguity=NULL)
+#' fit4 = h4st(dat4)
+#' 
+#' par(mfrow=c(3,1))
+#' lento(fit4[[1]], main="Transversion")
+#' lento(fit4[[2]], main="Transition 1")
+#' lento(fit4[[3]], main="Transition 2")
+#' }
+#' 
+#' @rdname hadamard
+#' @export hadamard
 hadamard <- function(x){
     res=1
     while(x>0){
@@ -51,6 +142,8 @@ hadamard <- function(x){
 }
 
 
+#' @rdname hadamard
+#' @export
 fhm <- function(v){
     n = length(v)
     n = log2(n)
@@ -73,6 +166,34 @@ split2seq = function(q){
 }
 
 
+
+
+#' Distance Hadamard
+#' 
+#' Distance Hadamard produces spectra of splits from a distance matrix.
+#' 
+#' 
+#' @param dm A distance matrix.
+#' @param eps Threshold value for splits.
+#' @return \code{distanceHadamard} returns a matrix. The first column contains
+#' the distance spectra, the second one the edge-spectra. If eps is positive an
+#' object of with all splits greater eps is returned.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}, Tim White
+#' @seealso \code{\link{hadamard}}, \code{\link{lento}},
+#' \code{\link{plot.networx}}, \code{\link{neighborNet}}
+#' @references Hendy, M. D. and Penny, D. (1993). Spectral Analysis of
+#' Phylogenetic Data. \emph{Journal of Classification}, \bold{10}, 5-24.
+#' @keywords cluster
+#' @examples
+#' 
+#' data(yeast)
+#' dm = dist.hamming(yeast)
+#' dm = as.matrix(dm)
+#' fit = distanceHadamard(dm)
+#' lento(fit)
+#' plot(as.networx(fit), "2D")
+#' 
+#' @export distanceHadamard
 distanceHadamard <- function (dm, eps = 0.001) 
 {
     if (inherits(dm,"dist")) {
@@ -109,6 +230,8 @@ distanceHadamard <- function (dm, eps = 0.001)
 }
 
 
+#' @rdname hadamard
+#' @export
 h4st = function(obj, levels=c('a','c','g','t')){
     if (is.matrix(obj)) 
         obj = as.data.frame(t(obj))
@@ -163,6 +286,8 @@ h4st = function(obj, levels=c('a','c','g','t')){
 }
 
 
+#' @rdname hadamard
+#' @export
 h2st <- function (obj, eps=0.001) 
 {
     if (!inherits(obj,"phyDat")) stop("Error") 
diff --git a/R/lento.R b/R/lento.R
new file mode 100644
index 0000000..a02bf0d
--- /dev/null
+++ b/R/lento.R
@@ -0,0 +1,92 @@
+#' Lento plot
+#' 
+#' The lento plot represents support and conflict of splits/bipartitions.
+#' 
+#' 
+#' @param obj an object of class phylo, multiPhylo or splits
+#' @param xlim graphical parameter
+#' @param ylim graphical parameter
+#' @param main graphical parameter
+#' @param sub graphical parameter
+#' @param xlab graphical parameter
+#' @param ylab graphical parameter
+#' @param bipart plot bipartition information.
+#' @param trivial logical, whether to present trivial splits (default is
+#' FALSE).
+#' @param col color for the splits / bipartition.
+#' @param \dots Further arguments passed to or from other methods.
+#' @return lento returns a plot.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{as.splits}, \link{hadamard}}
+#' @references Lento, G.M., Hickson, R.E., Chambers G.K., and Penny, D. (1995)
+#' Use of spectral analysis to test hypotheses on the origin of pinninpeds.
+#' \emph{Molecular Biology and Evolution}, \bold{12}, 28-52.
+#' @keywords cluster plot
+#' @examples
+#' 
+#' data(yeast)
+#' yeast.ry = acgt2ry(yeast)
+#' splits.h = h2st(yeast.ry)
+#' lento(splits.h, trivial=TRUE) 
+#' 
+#' @export lento
+lento <- function (obj, xlim = NULL, ylim = NULL, main = "Lento plot", 
+                   sub = NULL, xlab = NULL, ylab = NULL, bipart=TRUE, trivial=FALSE, col = rgb(0,0,0,.5), ...) 
+{
+    if (inherits(obj,"phylo")){ 
+        if(inherits(obj,"phylo",TRUE)==1)  obj <- as.splits(obj)[obj$edge[,2]]
+        obj <- as.splits(obj)
+    }
+    if (inherits(obj,"multiPhylo")) 
+        obj = as.splits(obj)    
+    labels = attr(obj, "labels") 
+    l = length(labels)
+    if(!trivial){
+        triv = lengths(obj)
+        #        triv = sapply(obj, length)
+        ind = logical(length(obj)) 
+        ind[(triv >1) & (triv < (l-1))] = TRUE
+        if(length(col)==length(obj)) col=col[ind] 
+        obj = obj[ind]
+    }
+    CM = compatible(obj)
+    support = attr(obj, "weights")
+    if (is.null(support)) 
+        support = rep(1, length(obj))
+    conflict = -as.matrix(CM) %*% support
+    n = length(support)
+    if (is.null(ylim)) {
+        eps = (max(support) - min(conflict)) * 0.05
+        ylim = c(min(conflict) - eps, max(support) + eps)
+    }
+    if (is.null(xlim)) {
+        xlim = c(0, n + 1)
+    }
+    
+    ord = order(support, decreasing = TRUE)
+    support = support[ord]
+    conflict = conflict[ord]
+    if(length(col)==length(obj)) col=col[ord]
+    plot.new()
+    plot.window(xlim, ylim)
+    title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...)
+    segments(0:(n - 1), support, y1 = conflict, ...)
+    segments(1:n, support, y1 = conflict, ...)
+    segments(0:(n - 1), support, x1 = 1:n, ...)
+    segments(0:(n - 1), conflict, x1 = 1:n, ...)
+    abline(h = 0)
+    axis(2, ...)
+    aty = diff(ylim)/(l+1)
+    at = min(ylim) + (1:l) * aty
+    if(bipart){
+        Y = rep(at, n)
+        X = rep((1:n)-.5, each=l)
+        Circles = matrix(1, l, n)
+        for(i in 1:n) Circles[obj[[ord[i]]],i] = 19   
+        #    axis(4, labels=labels, at=at)
+        col = rep(col, each=l)
+        text(x=n+.1,y=at, labels, pos=4, ...) 
+        points(X,Y,pch = as.numeric(Circles), col = col, ...)
+    }
+    invisible(list(support = cbind(support, conflict), splits=obj[ord]))
+}
diff --git a/R/modelTest.R b/R/modelTest.R
index da93060..22c232f 100644
--- a/R/modelTest.R
+++ b/R/modelTest.R
@@ -4,6 +4,73 @@ aic.weights <- function(aic){
 }
 
 
+
+
+#' ModelTest
+#' 
+#' Comparison of different nucleotide or amino acid substitution models
+#' 
+#' \code{modelTest} estimates all the specified models for a given tree and
+#' data.  When the mclapply is available, the computations are done in
+#' parallel. \code{modelTest} runs each model in one thread.  This is may not
+#' work within a GUI interface and will not work under Windows.
+#' 
+#' @aliases modelTest AICc
+#' @param object an object of class phyDat or pml
+#' @param tree a phylogenetic tree.
+#' @param model a vector containing the substitution models to compare with
+#' each other or "all" to test all available models
+#' @param G logical, TRUE (default) if (discrete) Gamma model should be tested
+#' @param I logical, TRUE (default) if invariant sites should be tested
+#' @param FREQ logical, FALSE (default) if TRUE amino acid frequencies will be
+#' estimated.
+#' @param k number of rate classes
+#' @param control A list of parameters for controlling the fitting process.
+#' @param multicore logical, whether models should estimated in parallel.
+#' @param mc.cores The number of cores to use, i.e. at most how many child
+#' processes will be run simultaneously. Must be at least one, and
+#' parallelization requires at least two cores.
+#' @return A data.frame containing the log-likelihood, number of estimated
+#' parameters, AIC, AICc and BIC all tested models.  The data.frame has an
+#' attributes "env" which is an environment which contains all the trees, the
+#' data and the calls to allow get the estimated models, e.g. as a starting
+#' point for further analysis (see example).
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{pml}}, \code{\link{anova}}, \code{\link[stats]{AIC}}
+#' @references Burnham, K. P. and Anderson, D. R (2002) \emph{Model selection
+#' and multimodel inference: a practical information-theoretic approach}. 2nd
+#' ed. Springer, New York
+#' 
+#' Posada, D. and Crandall, K.A. (1998) MODELTEST: testing the model of DNA
+#' substitution. \emph{Bioinformatics} \bold{14(9)}: 817-818
+#' 
+#' Posada, D. (2008) jModelTest: Phylogenetic Model Averaging. \emph{Molecular
+#' Biology and Evolution} \bold{25}: 1253-1256
+#' 
+#' Darriba D., Taboada G.L., Doallo R and Posada D. (2011) ProtTest 3: fast
+#' selection of best-fit models of protein evolution. . \emph{Bioinformatics}
+#' \bold{27}: 1164-1165
+#' @keywords cluster
+#' @examples
+#' 
+#' \dontrun{    
+#' example(NJ)
+#' (mT <- modelTest(Laurasiatherian, tree))
+#' 
+#' # some R magic
+#' env = attr(mT, "env")
+#' ls(env=env)
+#' (F81 <- get("F81+G", env)) # a call  
+#' eval(F81, env=env)
+#' 
+#' data(chloroplast)
+#' (mTAA <- modelTest(chloroplast, model=c("JTT", "WAG", "LG")))
+#' 
+#' # test all available amino acid models
+#' (mTAA_all <- modelTest(chloroplast, model="all", multicore=TRUE, mc.cores=2))
+#' }
+#' 
+#' @export modelTest
 modelTest <- function (object, tree = NULL, model = c("JC", "F81", "K80", 
     "HKY", "SYM", "GTR"), G = TRUE, I = TRUE, FREQ=FALSE, k = 4, 
     control = pml.control(epsilon = 1e-08, maxit = 10, trace = 1), 
diff --git a/R/neighborNet.R b/R/neighborNet.R
index 023d295..736bdd5 100644
--- a/R/neighborNet.R
+++ b/R/neighborNet.R
@@ -3,7 +3,7 @@ cyclicSplits <- function(k, labels=NULL){
     k = as.integer(k)
     l = (k-1L) %/% 2L
     res <- vector("list", k*(k-1L)/2)
-    res[1:k] = 1L:k
+    res[1:k] = 1L:k  
     ind = k
     if(k>3){
         fun = function(x,y){
@@ -40,6 +40,37 @@ distC <- function(d, CL){
 }
 
 
+updateDM <- function(DM, d, CL, j){
+    l=length(CL)
+    for(i in 1:l){
+        DM[i,j] <- DM[j, i] <- mean.default(d[CL[[i]], CL[[j]]])
+    }
+    DM[j,j] <- 0
+    DM
+}
+
+
+Rx <- function(d, x, CL){
+    lx <- length(x)
+    res <- numeric(lx)
+    lC <- length(CL)
+    for(i in 1:lx){
+        xi = x[i]
+        tmp=0
+        for(j in 1:lx){
+            if(j!=i) tmp = tmp + d[xi, x[j]]
+        }
+        if(lC>0){
+        for(j in 1:lC){
+            tmp = tmp + mean.default(d[xi, CL[[j]]])
+        }   
+        }    
+        res[i] = tmp
+    }
+    res
+}
+    
+
 reduc <- function(d, x, y, z){
   u <- 2/3* d[x, ] + d[y,]/3
   v <- 2/3* d[z, ] + d[y,]/3
@@ -53,7 +84,8 @@ reduc <- function(d, x, y, z){
   d[, y] <- 0
   
   d[x, z] <- d[z, x] <- uv
-  diag(d) <- 0
+  d[x,x] <- d[z,z] <- 0
+#  diag(d) <- 0
   d 
 }
 
@@ -71,11 +103,14 @@ getOrderingNN <- function (x)
   CL[1:l] <- ORD <- 1:l
   lCL <- length(CL)
   ord <- CL   
+  
+  DM <- d
+  
   while (lCL>1){
     i = 0
     j = 0
- #   browser()
     DM = distC(d, CL)
+    
     l = nrow(DM)
     if(l>2){
     r = rowSums(DM)/(l - 2)
@@ -84,8 +119,10 @@ getOrderingNN <- function (x)
     e1 = tmp[[4]]
     e2 = tmp[[5]]
     }
-    else {e1 = 1
-     e2=2}
+    else {
+        e1 = 1
+        e2 = 2   
+    }
     n1 <- length(CL[[e1]])
     n2 <- length(CL[[e2]])
     if(n1==1 & n2==1){
@@ -101,28 +138,15 @@ getOrderingNN <- function (x)
       DM2 = distC(d, CLtmp)
       if(ltmp>2) rtmp = rowSums(DM2)/(ltmp - 2)
       DM2 = DM2 - outer(rtmp, rtmp, "+")
-      
+# compute only this       
       TMP = DM2[1:n1, (n1+1):(n1+n2)]
-#browser()
-#      dtmp = d[CL[[e1]], CL[[e2]]]
-#      rtmp = numeric(n1+n2)
-#      for(ii in 1:(n1+n2)){
-#          for(jj in 1:ltmp){if(ii!=jj) rtmp[ii]=rtmp[ii] + mean.default(d[CLtmp[[ii]], CLtmp[[jj]]])
-#        }
-#      }
-#browser()      
-#      rtmp = rtmp/(ltmp-2)
-#      TMP2  = dtmp + rep(rtmp[1:n1],n2) + rep(rtmp[(n1+1):(n1+n2)], each=n1) 
-
-#browser()
 
       blub = which.min(TMP)
-#      print(blub)
 #print("blub")      
       if(n1==2 & n2==1){
         if(blub == 2){
           newCL <- c(CL[[e1]][1], CL[[e2]])
-          newOrd <-  c(CL[[e1]], ord[[e2]]) 
+          newOrd <-  c(ord[[e1]], ord[[e2]]) 
           d <- reduc(d, CL[[e1]][1], CL[[e1]][2], CL[[e2]]) 
         }
         else{
@@ -136,7 +160,7 @@ getOrderingNN <- function (x)
       if(n1==1 & n2==2){
         if(blub==1){
           newCL <- c(CL[[e1]], CL[[e2]][2])
-          newOrd <-  c(CL[[e1]], ord[[e2]])
+          newOrd <-  c(ord[[e1]], ord[[e2]])
           d <- reduc(d, CL[[e1]], CL[[e2]][1], CL[[e2]][2])
         }
         else{
@@ -157,7 +181,6 @@ getOrderingNN <- function (x)
           newOrd <-  c(ord[[e1]], ord[[e2]])      
           d <- reduc(d, CL[[e1]][1], CL[[e1]][2], CL[[e2]][1]) 
           d <- reduc(d, CL[[e1]][1], CL[[e2]][1], CL[[e2]][2]) 
-          
         }
         if(blub==3){
           newCL <- c(CL[[e1]][2], CL[[e2]][1])
@@ -176,11 +199,192 @@ getOrderingNN <- function (x)
         ord <- c(ord[-c(e1,e2)], list(newOrd))
         lCL <- lCL - 1L
         }
+  }
+  newOrd
+} 
+
+
+# computes ordering O(n^2) statt O(n^3) !!!
+# needs debugging
+getOrderingNN2 <- function (x) 
+{
+    x = as.matrix(x)
+    labels <- attr(x, "Labels")
+    if (is.null(labels)) 
+        labels = colnames(x)
+    d = x #as.matrix(x)
+    l = dim(d)[1]
+    CL = vector("list", l)  
+    CL[1:l] <- 1L:l
+    lCL <- length(CL)
+    ord <- CL   
+    
+    DM <- d
+    z <- 0
+#browser()    
+    while (lCL>1){
+        i = 0
+        j = 0
+#        DM = distC(d, CL)
+        z=z+1
+        
+        l = nrow(DM)
+        if(l>2){
+            r = rowSums(DM)/(l - 2)
+            tmp <- .C("out", as.double(DM), as.double(r), as.integer(l), 
+                      as.integer(i), as.integer(j), PACKAGE = "phangorn")
+            e1 = tmp[[4]]
+            e2 = tmp[[5]]
+        }
+        else {
+            e1 = 1
+            e2 = 2   
+        }
+        n1 <- length(CL[[e1]])
+        n2 <- length(CL[[e2]])
+        if(n1==1 & n2==1){
+            newCL <- c(CL[[e1]], CL[[e2]])
+            newOrd <- newCL
+            
+#            CL2 = CL      
+#            DM_1 <- distC2(d, CL2, e1, e2)
+            
+            CL[[e1]] <- newCL
+            DM <- updateDM(DM, d, CL, e1)
+            DM <- DM[-e2, -e2, drop=FALSE]
+            CL <- CL[-e2]
+            
+#            CL = c(CL[-c(e1,e2)], list(newCL))
+#browser()
+           
+            ord[[e1]] <- newCL
+            ord <- ord[-e2]
+            
+#            ord <- c(ord[-c(e1,e2)], list(newCL))
+            
+            lCL <- lCL - 1L
+        }
+        else{
+            CLtmp = c(as.list(CL[[e1]]), as.list(CL[[e2]]), CL[-c(e1,e2)])
+            ltmp =length(CLtmp)
+#            DM2 = distC(d, CLtmp)
+#            z=z+1
+            
+            CLtmp2 <- c(CL[[e1]], CL[[e2]])
+            rtmp2 <- Rx(d, CLtmp2, CL[-c(e1,e2)])
+            if(ltmp>2) rtmp2 = rtmp2/(ltmp - 2)          
+            DM3 <- d[CLtmp2, CLtmp2] - outer(rtmp2, rtmp2, "+")
+            
+#            if(ltmp>2) rtmp = rowSums(DM2)/(ltmp - 2)
+#            DM2 = DM2 - outer(rtmp, rtmp, "+")
+# compute only this       
+#            TMP = DM2[1:n1, (n1+1):(n1+n2)]
+            TMP2 = DM3[1:n1, (n1+1):(n1+n2)]
+#            blub = which.min(TMP)
+            blub = which.min(TMP2)
+
+            if(n1==2 & n2==1){
+                if(blub == 2){
+                    newCL <- c(CL[[e1]][1], CL[[e2]])
+                    newOrd <-  c(ord[[e1]], ord[[e2]]) 
+                    d <- reduc(d, CL[[e1]][1], CL[[e1]][2], CL[[e2]]) 
+                }
+                else{
+                    newCL <- c(CL[[e2]], CL[[e1]][2])
+                    newOrd <- c(ord[[e2]], ord[[e1]])
+                    d <- reduc(d, CL[[e2]], CL[[e1]][1], CL[[e1]][2]) 
+                }
+                
+            }
+            if(n1==1 & n2==2){
+                if(blub==1){
+                    newCL <- c(CL[[e1]], CL[[e2]][2])
+                    newOrd <-  c(ord[[e1]], ord[[e2]])
+                    d <- reduc(d, CL[[e1]], CL[[e2]][1], CL[[e2]][2])
+                }
+                else{
+                    newCL <- c(CL[[e2]][1], CL[[e1]])
+                    newOrd <- c(ord[[e2]], ord[[e1]])
+                    d <- reduc(d, CL[[e2]][1], CL[[e2]][2], CL[[e1]])
+                }
+            }
+            if(n1==2 & n2==2){
+                if(blub==1){
+                    newCL <- c(CL[[e1]][2], CL[[e2]][2])
+                    newOrd <-  c(rev(ord[[e1]]), ord[[e2]])
+                    d <- reduc(d, CL[[e1]][2], CL[[e1]][1], CL[[e2]][1]) 
+                    d <- reduc(d, CL[[e1]][2], CL[[e2]][1], CL[[e2]][2]) 
+                }
+                if(blub==2){
+                    newCL <- c(CL[[e1]][1], CL[[e2]][2])
+                    newOrd <-  c(ord[[e1]], ord[[e2]])      
+                    d <- reduc(d, CL[[e1]][1], CL[[e1]][2], CL[[e2]][1]) 
+                    d <- reduc(d, CL[[e1]][1], CL[[e2]][1], CL[[e2]][2]) 
+                }
+                if(blub==3){
+                    newCL <- c(CL[[e1]][2], CL[[e2]][1])
+                    newOrd <-  c(rev(ord[[e1]]), rev(ord[[e2]]))
+                    d <- reduc(d, CL[[e1]][2], CL[[e1]][1], CL[[e2]][2]) 
+                    d <- reduc(d, CL[[e1]][2], CL[[e2]][2], CL[[e2]][1]) 
+                }
+                if(blub==4){
+                    newCL <- c(CL[[e1]][1], CL[[e2]][1])
+                    newOrd <-  c(ord[[e1]], rev(ord[[e2]])) 
+                    d <- reduc(d, CL[[e1]][1], CL[[e1]][2], CL[[e2]][2]) 
+                    d <- reduc(d, CL[[e1]][1], CL[[e2]][2], CL[[e2]][1]) 
+                }
+            }
+#            CL <- c(CL[-c(e1,e2)], list(newCL))
+#            ord <- c(ord[-c(e1,e2)], list(newOrd))
+            
+#            browser()
+            
+            ord[[e1]] <- newOrd
+            ord <- ord[-e2]
+            
+            CL[[e1]] <- newCL           
+
+            DM <- updateDM(DM, d, CL, e1)
+            DM <- DM[-e2, -e2, drop=FALSE]
+
+            CL <- CL[-e2]
+            lCL <- lCL - 1L
+        }
     }
+#    print(z)
+#    browser()
     newOrd
-} 
+}
+
 
-#
+#' Computes a neighborNet from a distance matrix
+#' 
+#' Computes a neighborNet, i.e. an object of class \code{networx} from a
+#' distance matrix.
+#' 
+#' \code{neighborNet} is still experimental. The cyclic ordering sometimes
+#' differ from the SplitsTree implementation, the \emph{ord} argument can be
+#' used to enforce a certain circular ordering.
+#' 
+#' @param x a distance matrix.
+#' @param ord a circular ordering.
+#' @return \code{neighborNet} returns an object of class networx.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{splitsNetwork}}, \code{\link{consensusNet}},
+#' \code{\link{plot.networx}}, \code{\link{lento}},
+#' \code{\link{cophenetic.networx}}, \code{\link{distanceHadamard}}
+#' @references Bryant, D. & Moulton, V. (2004) Neighbor-Net: An Agglomerative
+#' Method for the Construction of Phylogenetic Networks. \emph{Molecular
+#' Biology and Evolution}, 2004, \bold{21}, 255-265
+#' @keywords hplot
+#' @examples
+#' 
+#' data(yeast)
+#' dm <- dist.ml(yeast)
+#' nnet <- neighborNet(dm)
+#' plot(nnet, "2D")
+#' 
+#' @export neighborNet
 neighborNet <-  function(x, ord=NULL){
     x = as.matrix(x)
     labels <- attr(x, "Labels")[[1]]
@@ -197,3 +401,226 @@ neighborNet <-  function(x, ord=NULL){
 } 
 
 
+getOrderingNN4 <- function (x, splits=TRUE) 
+{
+    x = as.matrix(x)
+    labels <- attr(x, "Labels")
+    if (is.null(labels)) 
+        labels = colnames(x)
+    d = x #as.matrix(x)
+    l = dim(d)[1]
+    CL = vector("list", l)  
+    CL[1:l] <- 1L:l
+    lCL <- length(CL)
+    ord <- CL   
+    
+    res <- vector("list", min(6*l, choose(l, 2)))
+    res[1:l] <- 1L:l
+    nres <- l
+    
+    DM <- d
+    z <- 0
+    #browser()    
+    while (lCL>1){
+        i = 0
+        j = 0
+        #        DM = distC(d, CL)
+        z=z+1
+        
+        l = nrow(DM)
+        if(l>2){
+            r = rowSums(DM)/(l - 2)
+            tmp <- .C("out", as.double(DM), as.double(r), as.integer(l), 
+                      as.integer(i), as.integer(j), PACKAGE = "phangorn")
+            e1 = tmp[[4]]
+            e2 = tmp[[5]]
+        }
+        else {
+            e1 = 1
+            e2 = 2   
+        }
+        n1 <- length(CL[[e1]])
+        n2 <- length(CL[[e2]])
+        if(n1==1 & n2==1){
+            newCL <- c(CL[[e1]], CL[[e2]])
+            newOrd <- newCL
+            
+            CL[[e1]] <- newCL
+            DM <- updateDM(DM, d, CL, e1)
+            DM <- DM[-e2, -e2, drop=FALSE]
+            CL <- CL[-e2]
+            
+            ord[[e1]] <- newCL
+            ord <- ord[-e2]
+            
+            nres <- nres+1L
+            res[[nres]] <- sort(ord[[e1]])
+            
+            lCL <- lCL - 1L
+        }
+        else{
+            CLtmp = c(as.list(CL[[e1]]), as.list(CL[[e2]]), CL[-c(e1,e2)])
+            ltmp =length(CLtmp)
+            #            DM2 = distC(d, CLtmp)
+            #            z=z+1
+            
+            CLtmp2 <- c(CL[[e1]], CL[[e2]])
+            rtmp2 <- Rx(d, CLtmp2, CL[-c(e1,e2)])
+            if(ltmp>2) rtmp2 = rtmp2/(ltmp - 2)          
+            DM3 <- d[CLtmp2, CLtmp2] - outer(rtmp2, rtmp2, "+")
+            
+            #            if(ltmp>2) rtmp = rowSums(DM2)/(ltmp - 2)
+            #            DM2 = DM2 - outer(rtmp, rtmp, "+")
+            # compute only this       
+            #            TMP = DM2[1:n1, (n1+1):(n1+n2)]
+            TMP2 = DM3[1:n1, (n1+1):(n1+n2)]
+            #            blub = which.min(TMP)
+            blub = which.min(TMP2)
+            
+            if(n1==2 & n2==1){
+                if(blub == 2){
+                    newCL <- c(CL[[e1]][1], CL[[e2]])   ## ??
+                    newOrd <-  c(ord[[e1]], ord[[e2]])  ## ?? 
+                    d <- reduc(d, CL[[e1]][1], CL[[e1]][2], CL[[e2]]) 
+                    nres <- nres+1L
+                    res[[nres]] <- sort(newOrd)
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e1]][2]))
+                }
+                else{
+                    newCL <- c(CL[[e2]], CL[[e1]][2])   ## ??
+                    newOrd <- c(ord[[e2]], ord[[e1]])   ## ??
+                    d <- reduc(d, CL[[e2]], CL[[e1]][1], CL[[e1]][2]) 
+                    nres <- nres+1L
+                    res[[nres]] <- sort(newOrd)
+                    # nres <- nres+1L
+                    # res[[nres]] <- sort(c(newCL, CL[[e1]][1]))
+                }
+            }
+            if(n1==1 & n2==2){
+                if(blub==1){
+                    newCL <- c(CL[[e1]], CL[[e2]][2])
+                    newOrd <-  c(ord[[e1]], ord[[e2]])
+                    d <- reduc(d, CL[[e1]], CL[[e2]][1], CL[[e2]][2])
+                    nres <- nres+1L
+                    res[[nres]] <- sort(newOrd)
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e2]][1]))
+                }
+                else{
+                    newCL <- c(CL[[e2]][1], CL[[e1]])
+                    newOrd <- c(ord[[e2]], ord[[e1]])
+                    d <- reduc(d, CL[[e2]][1], CL[[e2]][2], CL[[e1]])
+                    nres <- nres+1L
+                    res[[nres]] <- sort(newOrd)
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e2]][2]))
+                }
+            }
+            if(n1==2 & n2==2){
+                if(blub==1){
+                    newCL <- c(CL[[e1]][2], CL[[e2]][2])
+                    newOrd <-  c(rev(ord[[e1]]), ord[[e2]])
+                    d <- reduc(d, CL[[e1]][2], CL[[e1]][1], CL[[e2]][1]) 
+                    d <- reduc(d, CL[[e1]][2], CL[[e2]][1], CL[[e2]][2]) 
+                    
+                    nres <- nres+1L
+                    res[[nres]] <- sort(newOrd)
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e1]][1]))
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e2]][1]))
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e1]][1], CL[[e2]][1]))
+                }
+                if(blub==2){
+                    newCL <- c(CL[[e1]][1], CL[[e2]][2])
+                    newOrd <-  c(ord[[e1]], ord[[e2]])      
+                    d <- reduc(d, CL[[e1]][1], CL[[e1]][2], CL[[e2]][1]) 
+                    d <- reduc(d, CL[[e1]][1], CL[[e2]][1], CL[[e2]][2]) 
+                    
+                    nres <- nres+1L
+                    res[[nres]] <- sort(newOrd)
+                    #                   nres <- nres+1L
+                    #                   res[[nres]] <- sort(c(newCL, CL[[e1]][2]))
+                    #                   nres <- nres+1L
+                    #                   res[[nres]] <- sort(c(newCL, CL[[e2]][1]))
+                    #                   nres <- nres+1L
+                    #                   res[[nres]] <- sort(c(newCL, CL[[e1]][2], CL[[e2]][1]))
+                }
+                if(blub==3){
+                    newCL <- c(CL[[e1]][2], CL[[e2]][1])
+                    newOrd <-  c(rev(ord[[e1]]), rev(ord[[e2]]))
+                    d <- reduc(d, CL[[e1]][2], CL[[e1]][1], CL[[e2]][2]) 
+                    d <- reduc(d, CL[[e1]][2], CL[[e2]][2], CL[[e2]][1]) 
+                    
+                    nres <- nres+1L
+                    res[[nres]] <- sort(newOrd)
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e1]][1]))
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e2]][2]))
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e1]][1], CL[[e2]][2]))
+                }
+                if(blub==4){
+                    newCL <- c(CL[[e1]][1], CL[[e2]][1])
+                    newOrd <-  c(ord[[e1]], rev(ord[[e2]])) 
+                    d <- reduc(d, CL[[e1]][1], CL[[e1]][2], CL[[e2]][2]) 
+                    d <- reduc(d, CL[[e1]][1], CL[[e2]][2], CL[[e2]][1]) 
+                    
+                    nres <- nres+1L
+                    res[[nres]] <- sort(newOrd)
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e1]][2]))
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e2]][2]))
+                    #                    nres <- nres+1L
+                    #                    res[[nres]] <- sort(c(newCL, CL[[e1]][2], CL[[e2]][2]))
+                }
+            }
+            
+            ord[[e1]] <- newOrd
+            ord <- ord[-e2]
+            
+            CL[[e1]] <- newCL           
+            
+            DM <- updateDM(DM, d, CL, e1)
+            DM <- DM[-e2, -e2, drop=FALSE]
+            
+            CL <- CL[-e2]
+            lCL <- lCL - 1L
+        }
+    }
+    #    print(z)
+    #    browser()
+    if(!splits)return(newOrd)
+    res <- res[1L:nres]
+    attr(res, 'labels') <- labels
+    attr(res, "cycle") <- newOrd
+    class(res)="splits"
+    res   
+}
+
+
+removeNonsense <- function(obj){
+    nTips <- length(attr(obj, "label"))
+    l <- lengths(obj)
+    ind <- which((l == 0L) | (l == nTips))
+    obj <- obj[-ind]
+}
+
+
+neighborNet2 <-  function(x){
+    x = as.matrix(x)
+    labels <- attr(x, "Labels")[[1]]
+    if (is.null(labels)) 
+        labels = colnames(x)
+    l <- length(labels)    
+    #browser()    
+    spl <- getOrderingNN4(x) %>% removeNonsense %>% unique
+    spl <- nnls.splits(spl, x)
+    # nnls.split mit nnls statt quadprog
+    as.networx(spl)
+}
+
diff --git a/R/networx.R b/R/networx.R
index c86f58b..e703f92 100644
--- a/R/networx.R
+++ b/R/networx.R
@@ -1,439 +1,46 @@
-#
-# splits format, networx, Matrix, lento plot 
-#
-as.splits <- function (x, ...){
-    if(inherits(x, "splits")) return(x)
-    UseMethod("as.splits")
-}
-
-
-as.Matrix <- function (x, ...){
-    if (inherits(x,"Matrix")) return(x)
-    UseMethod("as.Matrix")
-}
-
-
-as.matrix.splits <- function(x, zero.print = 0L, one.print=1L, ...){
-   m = length(x)
-   labels = attr(x, "labels")
-   n = length(labels)    
-   res = matrix(zero.print, m, n)
-   for(i in 1:m)res[i,x[[i]]]=one.print
-   dimnames(res) = list(names(x), labels)
-   res
-}
-
-
-as.Matrix.splits <- function(x, ...){
-    labels = attr(x, "labels")
-    l = length(x)
-    j = unlist(x)
-#    i = rep(1:l, sapply(x, length))
-    i = rep(1:l, lengths(x))
-    sparseMatrix(i,j, x = rep(1L, length(i)), dimnames = list(NULL, labels)) # included x und labels
-}
-
-
-print.splits <- function (x, maxp = getOption("max.print"), 
-    zero.print = ".", one.print="|", ...)
-{
-    x.orig <- x
-    cx <- as.matrix(x, zero.print = zero.print, one.print=one.print)
-    print(cx, quote = FALSE, right = TRUE, max = maxp)
-    invisible(x.orig)
-}
-
-
-"[.splits" = function(x, i){
-    tmp = attributes(x)
-    result = unclass(x)[i]
-    if(!is.null(tmp$weights)) tmp$weights = tmp$weights[i] 
-    if(!is.null(tmp$confidences)) tmp$confidences = tmp$confidences[i]
-    if(!is.null(tmp$intervals)) tmp$intervals = tmp$intervals[i] 
-    if(!is.null(tmp$data)) tmp$data = tmp$data[i,, drop=FALSE] 
-    attributes(result) = tmp
-    result
-}
-
-changeOrder <- function(x, labels){
-    oldL <- attr(x, "labels")
-    ind <- match(oldL,labels)
-    for(i in 1:length(x))
-        x[[i]] <- sort(ind[x[[i]]])
-    if(!is.null(attr(x, "cycle")))
-        attr(x, "cycle") <- ind[attr(x, "cycle")]
-    attr(x, "labels") <- labels
-    x    
-}
-
-
-#orderSplitLabel = function(x, order){
-#    label = attr(x, "labels")
-#    nTips = length(label)
-#    ord = match(label, order)
-#    for(i in 1:length(x))
-#        x[[i]] = sort(ord[x[[i]]])
-#    attr(x, "labels") = order
-#    x
-#}
-
-
-# returns order of x$edge
-presenceAbsenceOld <- function(x, y){
-    X <- as.splits(x)
-    Y <- as.splits(y)
-    labels <- attr(X, "labels") 
-    #    if(inherits(x,"phylo")) X <- X[x$edge[,2]]
-    #    if(inherits(y,"phylo")) Y <- Y[y$edge[,2]]
-    Y <- changeOrder(Y, labels) # orderSplitLabel
-    nTips <- length(labels)
-    X <- oneWise(X, nTips)
-    Y <- oneWise(Y, nTips)
-    res <- match(X, Y)    
-    res <- !is.na(res)
-    if(inherits(x, "networx")){
-        res <- res[x$splitIndex]    
-    }    
-    if(class(x)[1]=="phylo"){
-        # res <- res[x$edge[,2]]
-        x$node.label = res[-c(1:length(labels))]
-        return(x)
-    }
-    res            
-}
-
-
-presenceAbsence <- function(x,y){
-    spl <- as.splits(y)
-    l <- length(spl)
-    attr(spl, "confidences") <- rep(1, l)
-    addConfidences(x, y)
-}
-
-
-matchSplits <- function(x, y, as.in=TRUE){
-    tiplabel <- attr(x, "label")
-    if(any(is.na(match(tiplabel, attr(y, "label"))))) stop("x and y have different labels!")
-    nTips <- length(tiplabel)
-    y <- changeOrder(y, tiplabel)
-    y <- SHORTwise(y, nTips)
-    if(as.in) return(match(SHORTwise(x, nTips), y, nomatch = 0L) > 0L)
-    match(SHORTwise(x, nTips), y)
-}
-
-
-optCycle <- function(splits, tree){
-    tips = tree$tip.label
-    tree = reorder(tree)
-    nodes = sort(unique(tree$edge[,1]))
-    
-    M = as.matrix(splits)
-    
-    l = as.integer(nrow(M))
-    m = as.integer(ncol(M))
-
-    tmp = tree$edge[,2]
-    tmp = tmp[tmp<=m]
-
-    start <- .C("countCycle", M[, tmp], l, m, integer(1))[[4]]
-    best = start
-    eps = 1
-    if(eps>0){
-        for(i in 1:length(nodes)){
-           tmptree = rotate(tree, nodes[i])
-           tmp = tmptree$edge[,2]
-           tmp = tmp[tmp<=m]
-           tmpC <- .C("countCycle", M[, tmp], l, m, integer(1))[[4]]
-           if(tmpC < best){
-              best <- tmpC
-              tree = tmptree
-           }
-        }
-        eps = start - best
-    }
-    tree # list(best, tree)
-}
-
-
-countCycles <- function(splits, tree=NULL, ord=NULL){
-  M = as.matrix(splits)
-  l = as.integer(nrow(M))
-  m = as.integer(ncol(M))
-  if(!is.null(tree))  ord  = getOrdering(tree)
-  res <- .C("countCycle2", M[, ord], l, m, integer(l))[[4]]
-  res
-}
-
-  
-c.splits <- function (..., recursive=FALSE) 
-{
-    x <- list(...)
-    if (length(x) == 1 && !inherits(x[[1]], "splits")) x <- x[[1]]
-    n <- length(x)
-    match.names <- function(a, b) {
-        if (any(!(a %in% b))) 
-            stop("names do not match previous names")
-    }
-    if (n == 1) 
-        return(x[[1]])
-
-    labels <- attr(x[[1]], "labels")
-    cycle <- attr(x[[1]], "cycle")
-    for (i in 2:n) {
-        match.names(labels, attr(x[[i]], "labels"))
-        x[[i]] <- changeOrder(x[[i]], labels)
-    }
-    w <- as.vector(sapply(x, attr, "weights"))
-    x <- lapply(x, unclass)
-    res <- structure(do.call("c", x), class=c("splits", "prop.part"))
-    names(res) <- NULL
-#        res <- structure(NextMethod("c"), class=c("splits", "prop.part"))
-    attr(res, "labels") <- labels
-    attr(res, "weights") <- w
-    attr(res, "cycle") <- cycle
-    res
-}
-
-
-distinct.splits <- function(...){
-    tmp <- c(...)
-    res <- unique(tmp)
-    attributes(res) <-  attributes(tmp)
-    attr(res, "weights") <- tabulate(match(tmp, res))
-    res
-}
-
-
-## as.splits.phylo
-# computes splits from phylo
-as.splits.phylo <- function(x, ...){
-    result <- bip(x)
-    if(!is.null(x$edge.length)){
-        edge.weights <- numeric(max(x$edge))
-        edge.weights[x$edge[,2]] <- x$edge.length
-        attr(result, "weights") <- edge.weights
-    }
-    if(!is.null(x$node.label)){
-        conf <- x$node.label
-        if(is.character(conf)) conf <- as.numeric(conf)
-        if(max(na.omit(conf)) > (1 + 1e-8))conf <- conf / 100
-        #if(!is.null(scale)) conf <- conf / scale
-        attr(result, "confidences") <- c(rep(1, length(x$tip.label)), conf)
-#        attr(result, "confidences") <- c(rep("", length(x$tip.label)), x$node.label)
-    }    
-    attr(result, "labels") <- x$tip.label
-    class(result) <- c('splits', 'prop.part')
-    result 
-}
-
-
-# computes splits from multiPhylo object (e.g. bootstrap, MCMC etc.)
-# unrooted trees
-as.splits.multiPhylo <- function(x, ...){
-#    if(inherits(x,"multiPhylo"))x = .uncompressTipLabel(x)
-#    if(inherits(x,"multiPhylo"))class(x)='list'  # prop.part allows not yet multiPhylo
-#    firstTip = x[[1]]$tip[1]
-#    x = lapply(x, root, firstTip) # old trick 
-    lx <-  length(x)
-    x <- unroot(x)  
-#    lapply(x, unroot)
-#    class(x) <- "multiPhylo"
-    splits <- prop.part(x)
-    class(splits)='list'
-    weights = attr(splits, 'number')    
-    lab = attr(splits,'labels')
-    attr(splits,'labels') <- attr(splits, 'number') <- NULL
-    l = length(lab)
-    splitTips = vector('list', l)
-    for(i in 1:l) splitTips[[i]] = i
-    result = c(splitTips,splits)
-    attr(result, "weights") = c(rep(lx, l), weights)
-    attr(result, "confidences") <- attr(result, "weights") / lx
-    attr(result, "summary") <- list(confidences="ratio", ntrees=l, clades=FALSE) 
-    attr(result, "labels") <- lab
-    class(result) = c('splits', 'prop.part')
-    result  
-}
-
-
-as.splits.prop.part <- function(x, ...){
-    if(is.null(attr(x, "number")))  
-        attr(x, "weights") = rep(1, length(x)) 
-	 else{ 
-        attr(x, "weights") = attr(x, "number")
-        attr(x, "confidences") = attr(x, "number") / attr(x, "number")[1] 
-   	}    
-    class(x) = c('splits', 'prop.part')	
-    x
-}
-
-
-as.splits.networx <- function(x, ...){
-#    if(!is.null(attr(x, "splits")))attr(x, "splits")
-    if(!is.null(x$splits)) x$splits
-    else warning("No split object included!")    
-}
-
-
-as.prop.part.splits <- function(x, ...){
-    attr(x, "number") = attr(x, "weights")
-    attr(x, "weights") = NULL
-    class(x) = c('prop.part')	
-    x
-}
-
-## as.splits.phylo
-as.phylo.splits <- function (x, result = "phylo", ...) 
-{
-    result <- match.arg(result, c("phylo", "all"))
-    labels = attr(x, "labels")
-    nTips = length(labels)
-    weights = attr(x, "weights")
-    nTips = length(labels)
-    x = SHORTwise(x, nTips)
-    dm = as.matrix(compatible(x))
-    rs = rowSums(dm)
-    ind = which(rs == 0)
-    if (any(rs > 0)) {
-        tmp = which(rs > 0)
-        candidates = tmp[order(rs[tmp])]
-        for (i in candidates) {
-            if (sum(dm[ind, i]) == 0) 
-                ind = c(ind, i)
-        }
-    }
-    splits = x[ind]
-    weights = weights[ind]
-    l = length(ind)
-    res = matrix(0L, l, nTips)
-    for (i in 1:l) res[i, splits[[i]]] = 1L
-    dm2 = (crossprod(res * weights, 1 - res))
-    dm2 = dm2 + t(dm2)
-    dimnames(dm2) = list(labels, labels)
-    tree <- di2multi(NJ(dm2), tol = 1e-08)
-    attr(tree, "order") = NULL
-    tree <- reorder(tree)    
-    tree <- optCycle(x, tree)
-    tree <- reorder(tree, "postorder")
-    if (result == "phylo") 
-        return(tree)  
-#    tree = reroot(tree, Ancestors(tree, 1, "parent")) 
-    spl = as.splits(tree)
-    spl = SHORTwise(spl, nTips)
-    spl <- spl[tree$edge[,2]]
-    list(tree = tree, index = tree$edge[, 2], split = spl, rest = x[-ind])
-}
-
-
-# computes compatible splits
-compatible <- function(obj){
-    labels = attr(obj, "labels")
-    if(!inherits(obj, "splits"))stop("obj needs to be of class splits")
-    
-    l = length(labels)
-    n = length(obj)
-    
-    bp = matrix(0L, n, l)
-    for(i in 1:n)bp[i,obj[[i]]] = 1L
-    bp[bp[, 1] == 0L, ] = 1L - bp[bp[, 1] == 0L, ]
-    k=1
-    res = matrix(0L, n, n) 
-            
-    tmp1 = tcrossprod(bp) #sum(bp[i,]* bp[j,])
-    tmp2 = tcrossprod(1L - bp) #sum((1L - bp[i,])*(1L - bp[j,]))
-    tmp3 = tcrossprod(bp, 1L - bp) #sum(bp[i,]*(1L - bp[j,]))
-    tmp4 = tcrossprod(1L - bp, bp) #sum((1L - bp[i,])*bp[j,]) 
-    res[(tmp1 * tmp2 * tmp3 * tmp4)>0]=1L
-    k = k+1
-    
-    res = res[lower.tri(res)]
-    attr(res, "Size") <- n
-    attr(res, "Diag") <- FALSE
-    attr(res, "Upper") <- FALSE
-    class(res) <- "dist"
-    return(res)
-}
-
-    
-compatible2 <- function (obj1, obj2=NULL) 
-{   
-    if (!inherits(obj1, "splits")) 
-        stop("obj needs to be of class splits")
-    labels = attr(obj1, "labels")    
-    l = length(labels)
-    n = length(obj1)
-    bp1 = as.matrix(obj1)
-    bp1[bp1[, 1] == 0L, ] = 1L - bp1[bp1[, 1] == 0L, ] 
-    if(!is.null(obj2)){
-        m = length(obj2) 
-        bp2 = as.matrix(obj2)
-        labels2 = attr(obj2, "labels")
-        bp2 = bp2[, match(labels2, labels), drop=FALSE]
-        bp2[bp2[, 1] == 0L, ] = 1L - bp2[bp2[, 1] == 0L, ]
-    }
-    else bp2 = bp1
-
-    if(is.null(obj2)) res = matrix(0L, n, n)
-    else res = matrix(0L, n, m)
-
-    tmp1 = tcrossprod(bp1, bp2)
-    tmp2 = tcrossprod(1L - bp1, 1L - bp2)
-    tmp3 = tcrossprod(bp1, 1L - bp2)
-    tmp4 = tcrossprod(1L - bp1, bp2)
-    res[(tmp1 * tmp2 * tmp3 * tmp4) > 0] = 1L
-    if(is.null(obj2)){
-        res = res[lower.tri(res)]
-        attr(res, "Size") <- n
-        attr(res, "Diag") <- FALSE
-        attr(res, "Upper") <- FALSE
-        class(res) <- "dist"
-    }
-    return(res)
-}
-
-
-compatible3 <- function(x, y=NULL) 
-{
-    if (!inherits(x, "splits")) 
-        stop("x needs to be of class splits")
-    if(is.null(y)) y <- x
-        
-    if (!inherits(y, "splits")) 
-        stop("y needs to be of class splits")
-    xlabels = attr(x, "labels")
-    ylabels = attr(y, "labels")
-    if(identical(xlabels, ylabels)) labels = xlabels 
-    else labels = intersect(xlabels, ylabels)
-    nx = length(x)
-    ny = length(y)   
-    bp1 = as.matrix(x)[,labels, drop=FALSE]
-    bp2 = as.matrix(y)[,labels, drop=FALSE]
-    rs1 = rowSums(bp1)
-    rs2 = rowSums(bp2)
-    res = matrix(0L, nx, ny)
-    tmp1 = tcrossprod(bp1, bp2)
-    res = matrix(0L, nx, ny)
-    for(i in 1:nx){
-        for(j in 1:ny){            
-            if(tmp1[i, j]==rs1[i]) res[i,j] = 1
-            if(tmp1[i, j]==rs2[j]) res[i,j] = 2
-            if(tmp1[i, j]==rs1[i] & tmp1[i, j]==rs2[j])res[i,j] = 3
-        }
-    }      
-    if(is.null(y)){
-        res = res[lower.tri(res)]
-        attr(res, "Size") <- length(x)
-        attr(res, "Diag") <- FALSE
-        attr(res, "Upper") <- FALSE
-        class(res) <- "dist"
-    }
-    return(res)
-}
-    
-
-#
-# splits
-#
+#' Phylogenetic Network
+#' 
+#' \code{splitsNetwork} estimates weights for a splits graph from a distance
+#' matrix.
+#' 
+#' \code{splitsNetwork} fits non-negative least-squares phylogenetic networks
+#' using L1 (LASSO), L2(ridge regression) constraints.  The function minimizes
+#' the penalized least squares 
+#' \deqn{\beta = min \sum(dm - X\beta)^2 + \lambda \|\beta \|^2_2 }{ beta = sum(dm - X*beta)^2 + lambda |beta|^2_2 } 
+#' with respect to \deqn{\|\beta \|_1 <= \gamma, \beta >= 0}{ |beta|_1 = gamma, beta >= 0} 
+#' where \eqn{X} is a design matrix constructed with \code{designSplits}.
+#' External edges are fitted without L1 or L2 constraints.
+#' 
+#' @param dm A distance matrix.
+#' @param splits a splits object, containing all splits to consider, otherwise
+#' all possible splits are used
+#' @param gamma penalty value for the L1 constraint.
+#' @param lambda penalty value for the L2 constraint.
+#' @param weight a vector of weights.
+#' @return \code{splitsNetwork} returns a splits object with a matrix added.
+#' The first column contains the indices of the splits, the second column an
+#' unconstrained fit without penalty terms and the third column the constrained
+#' fit.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link[phangorn]{distanceHadamard}},
+#' \code{\link[phangorn]{designTree}} \code{\link[phangorn]{consensusNet}},
+#' \code{\link[phangorn]{plot.networx}}
+#' @references Efron, Hastie, Johnstone and Tibshirani (2004) Least Angle
+#' Regression (with discussion) \emph{Annals of Statistics} \bold{32(2)}, 407--499
+#' 
+#' K. P. Schliep (2009). Some Applications of statistical phylogenetics (PhD
+#' Thesis)
+#' @keywords cluster
+#' @examples
+#' 
+#' data(yeast)
+#' dm = dist.ml(yeast)
+#' fit = splitsNetwork(dm)
+#' net = as.networx(fit)
+#' plot(net, "2D")
+#' write.nexus.splits(fit)
+#' 
+#' @export splitsNetwork
 splitsNetwork <- function(dm, splits=NULL, gamma=.1, lambda=1e-6, weight=NULL){
   dm = as.matrix(dm)
   k = dim(dm)[1]
@@ -513,6 +120,8 @@ splitsNetwork <- function(dm, splits=NULL, gamma=.1, lambda=1e-6, weight=NULL){
 }
 
 
+#' @rdname as.splits
+#' @export
 allSplits = function(k, labels=NULL){
   result <- lapply(1:(2^(k-1)-1),dec2Bin)
   if(is.null(labels)) labels=(as.character(1:k))
@@ -522,6 +131,8 @@ allSplits = function(k, labels=NULL){
 }   
 
 
+#' @rdname as.splits
+#' @export
 allCircularSplits <- function(k, labels=NULL){
     k = as.integer(k)
     l = (k-1L) %/% 2L
@@ -811,6 +422,86 @@ circNetwork <- function(x, ord=NULL){
 }
 
 
+#' Phylogenetic networks
+#' 
+#' \code{as.networx} convert \code{splits} objects into a \code{networx}
+#' object. And most important there exists a generic \code{plot} function to plot 
+#' phylogenetic network or split graphs.
+#' 
+#' @details A \code{networx} object hold the information for a phylogenetic network and
+#' extends the \code{phylo} object. Therefore some generic function for
+#' \code{phylo} objects will also work for \code{networx} objects.  The
+#' argument \code{planar = TRUE} will create a planar split graph based on a cyclic
+#' ordering. These objects can be nicely plotted in \code{"2D"}. So far not all
+#' parameters behave the same on the the \code{rgl} \code{"3D"} and basic graphic \code{"2D"}
+#' device.
+#' 
+#' Often it is easier and safer to supply vectors of graphical parameters for
+#' splits (e.g. splits.color) than for edges. These overwrite values edge.color.
+#' 
+#' @aliases networx 
+#' @param x an object of class \code{"splits"} (as.networx) or \code{"networx"}
+#' (plot)
+#' @param planar logical whether to produce a planar graph from only cyclic
+#' splits (may excludes splits).
+#' @param coord add coordinates of the nodes, allows to reproduce the plot.
+#' @param type "3D" to plot using rgl or "2D" in the normal device.
+#' @param use.edge.length a logical indicating whether to use the edge weights
+#' of the network to draw the branches (the default) or not.
+#' @param show.tip.label a logical indicating whether to show the tip labels on
+#' the graph (defaults to \code{TRUE}, i.e. the labels are shown).
+#' @param show.edge.label a logical indicating whether to show the tip labels
+#' on the graph.
+#' @param edge.label an additional vector of edge labels (normally not needed).
+#' @param show.node.label a logical indicating whether to show the node labels
+#' (see example).
+#' @param node.label an additional vector of node labels (normally not needed).
+#' @param show.nodes a logical indicating whether to show the nodes (see
+#' example).
+#' @param tip.color the colors used for the tip labels.
+#' @param edge.color the colors used to draw edges.
+#' @param edge.width the width used to draw edges.
+#' @param edge.lty a vector of line types.
+#' @param split.color the colors used to draw edges.
+#' @param split.width the width used to draw edges.
+#' @param split.lty a vector of line types.
+#' @param font an integer specifying the type of font for the labels: 1 (plain
+#' text), 2 (bold), 3 (italic, the default), or 4 (bold italic).
+#' @param cex a numeric value giving the factor scaling of the labels.
+#' @param cex.node.label a numeric value giving the factor scaling of the node
+#' labels.
+#' @param cex.edge.label a numeric value giving the factor scaling of the edge
+#' labels.
+#' @param col.node.label the colors used for the node labels.
+#' @param col.edge.label the colors used for the edge labels.
+#' @param font.node.label the font used for the node labels.
+#' @param font.edge.label the font used for the edge labels.
+#' @param \dots Further arguments passed to or from other methods.
+#' @note The internal representation is likely to change.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{consensusNet}}, \code{\link{neighborNet}},
+#' \code{\link{splitsNetwork}}, \code{\link{hadamard}},
+#' \code{\link{distanceHadamard}}, \code{\link{layout_with_kk}},
+#' \code{\link[ape]{evonet}}, \code{\link[ape]{as.igraph}},
+#' \code{\link{densiTree}}
+#' @references Dress, A.W.M. and Huson, D.H. (2004) Constructing Splits Graphs
+#' \emph{IEEE/ACM Transactions on Computational Biology and Bioinformatics
+#' (TCBB)}, \bold{1(3)}, 109--115
+#' @keywords plot
+#' @examples
+#' 
+#' set.seed(1)
+#' tree1 = rtree(20, rooted=FALSE)
+#' sp = as.splits(rNNI(tree1, n=10))
+#' net = as.networx(sp)
+#' plot(net, "2D")
+#' \dontrun{
+#' # also see example in consensusNet 
+#' example(consensusNet)
+#' }
+#' 
+#' @rdname as.networx
+#' @export as.networx
 as.networx <- function (x, ...) 
 {
     if (inherits(x, "networx")) 
@@ -849,6 +540,17 @@ addTrivialSplits <- function(obj){
 }
 
 
+removeTrivialSplits <- function(obj){
+    nTips <- length(attr(obj, "label"))
+    l <- lengths(obj)
+    ind <- which((l == 0L) | (l == 1L) | (l == nTips) | (l == (nTips-1L)))
+    obj[-ind]
+}
+
+
+#' @rdname as.networx
+#' @method as.networx splits
+#' @export
 as.networx.splits <- function(x, planar=FALSE, coord = c("none", "2D", "3D"), ...){
   label <- attr(x, "label")
   
@@ -918,7 +620,10 @@ as.networx.splits <- function(x, planar=FALSE, coord = c("none", "2D", "3D"), ..
 #    as.networx(x, ...)
 #}
 
-## as.splits.phylo
+
+#' @rdname as.networx
+#' @method as.networx phylo
+#' @export
 as.networx.phylo <- function(x, ...){
     spl <- as.splits(x)
     spl <- spl[x$tree[,2]]
@@ -935,6 +640,52 @@ as.networx.phylo <- function(x, ...){
 #}
 
 
+
+
+#' Computes a consensusNetwork from a list of trees Computes a \code{networx}
+#' object from a collection of splits.
+#' 
+#' Computes a consensusNetwork, i.e. an object of class \code{networx} from a
+#' list of trees, i.e. an class of class \code{multiPhylo}. Computes a
+#' \code{networx} object from a collection of splits.
+#' 
+#' 
+#' @param obj An object of class multiPhylo.
+#' @param prob the proportion a split has to be present in all trees to be
+#' represented in the network.
+#' @param \dots Further arguments passed to or from other methods.
+#' @return \code{consensusNet} returns an object of class networx.  This is
+#' just an intermediate to plot phylogenetic networks with igraph.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{splitsNetwork}}, \code{\link{neighborNet}},
+#' \code{\link{lento}}, \code{\link{distanceHadamard}},
+#' \code{\link{plot.networx}}, \code{\link{maxCladeCred}}
+#' @references Holland B.R., Huber K.T., Moulton V., Lockhart P.J. (2004) Using
+#' consensus networks to visualize contradictory evidence for species
+#' phylogeny. \emph{Molecular Biology and Evolution}, \bold{21}, 1459--61
+#' @keywords hplot
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' set.seed(1)
+#' bs <- bootstrap.phyDat(Laurasiatherian, FUN = function(x)nj(dist.hamming(x)), 
+#'     bs=50)
+#' class(bs) <- 'multiPhylo'
+#' cnet = consensusNet(bs, .3)
+#' plot(cnet, "2D")
+#' \dontrun{
+#' library(rgl)
+#' open3d()
+#' plot(cnet, show.tip.label=FALSE, show.nodes=TRUE)
+#' plot(cnet, type = "2D", show.edge.label=TRUE)
+#' 
+#' tmpfile <- normalizePath(system.file("extdata/trees/RAxML_bootstrap.woodmouse", package="phangorn"))
+#' trees <- read.tree(tmpfile)
+#' cnet_woodmouse = consensusNet(trees, .3)
+#' plot(cnet_woodmouse, type = "2D", show.edge.label=TRUE)
+#' }
+#' 
+#' @export consensusNet
 consensusNet <- function (obj, prob = 0.3, ...) 
 {
     l = length(obj)
@@ -951,6 +702,8 @@ consensusNet <- function (obj, prob = 0.3, ...)
 }
 
 
+#' @rdname addConfidences
+#' @export
 createLabel <- function(x, y, label_y, type="edge", nomatch=NA){
     spl_x <- as.splits(x)
     if(inherits(x, "phylo", TRUE)==1) spl_x <- spl_x[x$edge[,2]]
@@ -977,11 +730,102 @@ createLabel <- function(x, y, label_y, type="edge", nomatch=NA){
 }
 
 
+
+
+#' Compare splits and add support values to an object
+#' 
+#' Add support values to a \code{splits}, \code{phylo} or \code{networx}
+#' object.
+#' 
+#' @param x an object of class \code{splits}, \code{phylo} or \code{networx}
+#' @param y an object of class \code{splits}, \code{phylo}, \code{multiPhylo}
+#' or \code{networx}
+#' @param ...  Further arguments passed to or from other methods.
+#' @param label_y label of y matched on x. Will be usually of
+#' length(as.splits(x)).
+#' @param type should labels returned for edges (in \code{networx}) or splits.
+#' @param nomatch default value if no match between x and y is found.
+#' @return The object \code{x} with added bootstrap / MCMC support values.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{as.splits}}, \code{\link{as.networx}},
+#' \code{\link{RF.dist}}, \code{\link{plot.phylo}}
+#' @keywords cluster
+#' @examples
+#' 
+#' data(woodmouse)
+#' woodmouse <- phyDat(woodmouse)
+#' tmpfile <- normalizePath(system.file("extdata/trees/RAxML_bootstrap.woodmouse", package="phangorn"))
+#' boot_trees <- read.tree(tmpfile)
+#' 
+#' dm <- dist.ml(woodmouse)
+#' tree <- upgma(dm)
+#' nnet <- neighborNet(dm)
+#' 
+#' tree <- addConfidences(tree, boot_trees)
+#' nnet <- addConfidences(nnet, boot_trees)
+#' 
+#' plot(tree, show.node.label=TRUE)
+#' plot(nnet, "2D", show.edge.label=TRUE)
+#' 
+#' @rdname addConfidences
+#' @export 
 addConfidences <- function (x, y, ...) UseMethod("addConfidences")
 
 
+# some function to add confidences on splits if trees have different taxa
+#
+addConfidencesMultiPhylo <- function(spl, trees){
+    
+    fun <- function(spl, intersect_labels){
+        spl2 <- spl
+        
+        index <- match(attr(spl, "labels"), intersect_labels)
+        attr(spl2, "labels") <- intersect_labels 
+        for(i in 1:length(spl2)){
+            spl2[[i]] <- sort(na.omit(index[spl[[i]]]))
+        }
+        l_spl <- lengths(spl2)
+        l <- length(intersect_labels)
+        ind <- which( (l_spl > 1) & (l_spl < (l-1L)) ) 
+        if(length(ind)==0)return(NULL)
+        list(spl=spl2[ind], index=ind)
+    }
+    
+    spl_labels <- attr(spl, "labels")
+    zaehler <- numeric(length(spl))
+    nenner <- numeric(length(spl))
+    
+    for(i in 1:length(trees)){
+#        print(i)
+        intersect_labels <- intersect(trees[[i]]$tip.label, spl_labels)
+        if(length(intersect_labels) > 3){    
+            tmp <- fun(spl, intersect_labels)
+            if(!is.null(tmp)){
+                tree_spl <- as.splits(trees[[i]])
+                if(!identical(intersect_labels, trees[[i]]$tip.label))
+                    tree_spl <- fun(tree_spl, intersect_labels)[[1]]
+                comp <- compatible_2(as.bitsplits(tmp[[1]]), as.bitsplits(tree_spl))
+                #            print(comp)
+                ind <- tmp$index
+                zaehler[ind] <- zaehler[ind] + comp 
+                nenner[ind] <- nenner[ind] + 1L
+            }
+        }    
+        #        print(zaehler)
+    }
+    confidences <- zaehler / nenner
+    attr(spl, "confidences") <- confidences
+    spl
+}            
+
+
+
 # y now more general 
-addConfidences.splits <- function(x, y, ...){
+addConfidences.splits <- function(x, y, scaler=1, ...){
+    if (hasArg(add)) 
+        add <- list(...)$add
+    else add <- FALSE
+    
     tiplabel <- attr(x, "label")
     nTips = length(tiplabel)
 #    x = addTrivialSplits(x) 
@@ -993,25 +837,34 @@ addConfidences.splits <- function(x, y, ...){
         ind2 <- match(1:length(ind), y$edge[, 2])
         y$edge[ind2, 2] <- order(ind)
     }
+    if(inherits(y, "multiPhylo")){
+        if(inherits(try(.compressTipLabel(y), TRUE), "try-error")){
+            res <- addConfidencesMultiPhylo(x, y) 
+            return(res)
+        }
+    }
+#    browser()
     spl <- as.splits(y)
     spl <- changeOrder(spl, tiplabel)
-    spl <- SHORTwise(spl, nTips)
+    spl <- oneWise(spl, nTips)
 #    ind <- match(SHORTwise(x, nTips), spl)
 #    ind
-    ind <- match(SHORTwise(x, nTips), spl)
+    ind <- match(oneWise(x, nTips), spl)
     #    pos <-  which(ind > nTips)
     pos <-  which(!is.na(ind))
-    confidences <- numeric(length(x))  #character 
-    confidences[pos] <- attr(spl, "confidences")[ind[pos]]
+    confidences <- rep(NA_real_, length(x)) #numeric(length(x))  #character 
+    confidences[pos] <- attr(spl, "confidences")[ind[pos]] * scaler
+    if(add==TRUE) confidences <- paste(prettyNum(attr(x, "confidences")) , prettyNum(confidences * scaler), sep="/")
     #        y$node.label[ind[pos] - nTips]
     attr(x, "confidences") <- confidences
     x  
 }
 
 
-addConfidences.networx <- function(x, y, ...){
+
+addConfidences.networx <- function(x, y, scaler=1, ...){
     spl <- x$splits
-    spl <- addConfidences(spl, y, ...)
+    spl <- addConfidences(spl, y, scaler=scaler, ...)
     x$splits <- spl
     x    
 }
@@ -1019,14 +872,58 @@ addConfidences.networx <- function(x, y, ...){
 ## as.splits.phylo
 addConfidences.phylo <- function(x, y, ...){
 #    call <- x$call
-    conf = attr(addConfidences(as.splits(x), y), "confidences")
+    if (hasArg(as.is)) 
+        as.is <- list(...)$as.is
+    else as.is <- TRUE
+    nTips <- length(x$tip.label)
+    spl <- as.splits(x) %>% oneWise(nTips=nTips)
+    conf = attr(addConfidences(spl, y), "confidences")
+    l <- lengths(spl)
     if(is.character(conf)) conf <- as.numeric(conf)
+    ind <- (l==1L) | (l==(nTips-1L)) | (l==nTips)
+    conf[ind==TRUE] <- NA_real_
     nTips = length(x$tip.label)
-    x$node.label = conf[-c(1:nTips)]  * 100
+    if(!as.is) conf <- conf * 100
+    x$node.label = conf[-c(1:nTips)]
     x      
 } 
 
 
+# returns order of x$edge
+presenceAbsenceOld <- function(x, y){
+    X <- as.splits(x)
+    Y <- as.splits(y)
+    labels <- attr(X, "labels") 
+    #    if(inherits(x,"phylo")) X <- X[x$edge[,2]]
+    #    if(inherits(y,"phylo")) Y <- Y[y$edge[,2]]
+    Y <- changeOrder(Y, labels) # orderSplitLabel
+    nTips <- length(labels)
+    X <- oneWise(X, nTips)
+    Y <- oneWise(Y, nTips)
+    res <- match(X, Y)    
+    res <- !is.na(res)
+    if(inherits(x, "networx")){
+        res <- res[x$splitIndex]    
+    }    
+    if(class(x)[1]=="phylo"){
+        # res <- res[x$edge[,2]]
+        x$node.label = res[-c(1:length(labels))]
+        return(x)
+    }
+    res            
+}
+
+
+#' @rdname addConfidences
+#' @export
+presenceAbsence <- function(x,y){
+    spl <- as.splits(y)
+    l <- length(spl)
+    attr(spl, "confidences") <- rep(1, l)
+    addConfidences(x, y)
+}
+
+
 reorder.networx <- function (x, order =  "cladewise", index.only = FALSE, ...) 
 {
     order <- match.arg(order, c("cladewise", "postorder"))
@@ -1149,7 +1046,11 @@ edgeLabels <- function(xx,yy,zz=NULL, edge){
 }
 
 
-plot.networx = function(x, type="3D", use.edge.length = TRUE, show.tip.label=TRUE,
+
+#' @rdname as.networx
+#' @method plot networx
+#' @export
+plot.networx <- function(x, type="3D", use.edge.length = TRUE, show.tip.label=TRUE,
     show.edge.label=FALSE, edge.label=NULL, show.node.label = FALSE, node.label=NULL,
     show.nodes=FALSE, tip.color = "black", 
     edge.color="black", edge.width = 3, edge.lty = 1,
@@ -1164,9 +1065,14 @@ plot.networx = function(x, type="3D", use.edge.length = TRUE, show.tip.label=TRU
 # test    
 #    x = reorder(x)
     nTips = length(x$tip.label)
-    conf = attr(x$splits,"confidences") * 100
+    conf = attr(x$splits,"confidences") 
     index = x$splitIndex
-    if(is.null(edge.label) & !is.null(conf))edge.label = conf[index]
+    if(is.null(edge.label) & !is.null(conf)){
+        conf = conf[index]
+        if(!is.null(x$translate)) conf[match(x$translate$node, x$edge[,2])] = ""
+        else conf[x$edge[,2] <= nTips] = ""    
+        edge.label = conf
+    }
     if(is.null(node.label))node.label = as.character(1:max(x$edge))
     if(show.tip.label)node.label[1:nTips] = ""
     
@@ -1342,535 +1248,6 @@ plot2D <- function(coords, net, show.tip.label=TRUE,
     }   
 }   
    
-## as.splits.phylo    
-lento <- function (obj, xlim = NULL, ylim = NULL, main = "Lento plot", 
-    sub = NULL, xlab = NULL, ylab = NULL, bipart=TRUE, trivial=FALSE, col = rgb(0,0,0,.5), ...) 
-{
-    if (inherits(obj,"phylo")){ 
-        if(inherits(obj,"phylo",TRUE)==1)  obj <- as.splits(obj)[obj$edge[,2]]
-        obj <- as.splits(obj)
-    }
-    if (inherits(obj,"multiPhylo")) 
-        obj = as.splits(obj)    
-    labels = attr(obj, "labels") 
-    l = length(labels)
-    if(!trivial){
-        triv = lengths(obj)
-#        triv = sapply(obj, length)
-        ind = logical(length(obj)) 
-        ind[(triv >1) & (triv < (l-1))] = TRUE
-        if(length(col)==length(obj)) col=col[ind] 
-        obj = obj[ind]
-        }
-    CM = compatible(obj)
-    support = attr(obj, "weights")
-    if (is.null(support)) 
-        support = rep(1, length(obj))
-    conflict = -as.matrix(CM) %*% support
-    n = length(support)
-    if (is.null(ylim)) {
-        eps = (max(support) - min(conflict)) * 0.05
-        ylim = c(min(conflict) - eps, max(support) + eps)
-    }
-    if (is.null(xlim)) {
-        xlim = c(0, n + 1)
-    }
 
-    ord = order(support, decreasing = TRUE)
-    support = support[ord]
-    conflict = conflict[ord]
-    if(length(col)==length(obj)) col=col[ord]
-    plot.new()
-    plot.window(xlim, ylim)
-    title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...)
-    segments(0:(n - 1), support, y1 = conflict, ...)
-    segments(1:n, support, y1 = conflict, ...)
-    segments(0:(n - 1), support, x1 = 1:n, ...)
-    segments(0:(n - 1), conflict, x1 = 1:n, ...)
-    abline(h = 0)
-    axis(2, ...)
-    aty = diff(ylim)/(l+1)
-    at = min(ylim) + (1:l) * aty
-    if(bipart){
-        Y = rep(at, n)
-        X = rep((1:n)-.5, each=l)
-        Circles = matrix(1, l, n)
-        for(i in 1:n) Circles[obj[[ord[i]]],i] = 19   
-#    axis(4, labels=labels, at=at)
-        col = rep(col, each=l)
-        text(x=n+.1,y=at, labels, pos=4, ...) 
-        points(X,Y,pch = as.numeric(Circles), col = col, ...)
-        }
-    invisible(list(support = cbind(support, conflict), splits=obj[ord]))
-    }
 
-    
-write.splits = function (x, file = "", zero.print = ".", one.print = "|", print.labels = TRUE, ...) 
-{
-    labels = attr(x, "labels")
-    x.orig <- x
-    cx <- as.matrix(x, zero.print = zero.print, one.print = one.print)
-    w = FALSE
-    if (!is.null(attr(x, "names"))) {
-        nam = TRUE
-        vnames = format(attr(x, "names"))
-    }
-    nam = FALSE
-    if (!is.null(attr(x, "weights"))) {
-        w = TRUE
-        weight = format(attr(x, "weights"))
-    }
-    d = FALSE
-    if (!is.null(attr(x, "data"))) {
-        d = TRUE
-        data = attr(x, "data")
-    }
-    if(print.labels){for(i in 1:length(labels)) cat(labels[i], "\n", file = file, append = TRUE)}
-    if (w) 
-        cat("weight", "\t", file = file, append = TRUE)
-    if (d) 
-        cat(paste(colnames(data), "\t"), file = file, append = TRUE)
-    cat("\n", file = file, append = TRUE) #"Matrix", 
-    for (i in 1:length(x)) {
-        if (nam) 
-            cat(vnames[i], "\t", file = file, append = TRUE)
-        if (d) 
-            cat(paste(data[i, ], "\t"), file = file, append = TRUE)
-        if (w) 
-            cat(weight[i], "\t", file = file)
-        cat("\n", paste(cx[i, ], collapse = ""),"\n",  file = file, append = TRUE)
-    }
-}
- 
-
-write.nexus.splits <- function (obj, file = "", weights=NULL, taxa=TRUE, append=FALSE) 
-{
-    taxa.labels <- attr(obj, "labels")
-    ntaxa <- length(taxa.labels)
-    obj <- oneWise(obj, ntaxa)
-    ind <- which(lengths(obj)==ntaxa)
-#    ind <- which(sapply(obj, length)==ntaxa)
-    if(length(ind))obj <- obj[-ind] 
-    nsplits <- length(obj)    
-    if(is.null(weights))weight <- attr(obj, "weights") 
-    if (is.null(weight)) fwei <- FALSE
-    else fwei <- TRUE
-#    if (is.null(weight)) weight = numeric(nsplits) + 100
-    if(!append){cat("#NEXUS\n\n", file = file)
-    cat("[Splits block for Spectronet or Splitstree]\n", file = file, append = TRUE)
-    cat("[generated by phangorn:\n", file = file, append = TRUE)
-    cat(format(citation("phangorn"), "text"), "]\n\n",
-       file = file, append = TRUE)}
-# TAXON BLOCK    
-    if(taxa){
-    cat(paste("BEGIN TAXA;\n\tDIMENSIONS ntax=", ntaxa, ";\n", 
-        sep = ""), file = file, append = TRUE)
-    cat("\tTAXLABELS", paste(taxa.labels, sep = " "), ";\nEND;\n\n", 
-        file = file, append = TRUE)
-    }
-# SPLITS BLOCK      
-    cat(paste("BEGIN SPLITS;\n\tDIMENSIONS ntax=", ntaxa, " nsplits=", nsplits,
-        ";\n", sep = ""), file = file, append = TRUE)     
-    format = "\tFORMAT labels=left" 
-         # weights=yes
-    if(fwei) format = paste(format, "weights=yes") 
-    else format = paste(format, "weights=no") 
-    fcon = fint = flab = FALSE
-    if(!is.null(attr(obj, "confidences"))){ 
-        format = paste(format, "confidences=yes")
-        fcon=TRUE
-        conf = attr(obj, "confidences")
-        if(storage.mode(conf) == "character"){ 
-            conf[conf==""] = "0"
-            attr(obj, "confidences") = conf
-        }                                       
-    }
-    else format = paste(format, "confidences=no") 
-    if(!is.null(attr(obj, "intervals"))){ 
-        format = paste(format, "intervals=yes")
-        fint=TRUE
-    }
-    else format = paste(format, "intervals=no") 
-    if(!is.null(attr(obj, "splitlabels"))) flab=TRUE
-    format = paste(format, ";\n",  sep = "")
-    cat(format, file = file, append = TRUE)
-    if(!is.null(attr(obj, "cycle"))){
-        cycle <- paste(attr(obj, "cycle"), collapse = " ")
-        cat("\tCYCLE\t", cycle, ";\n", sep="", file = file, append = TRUE)
-    }
-    cat("\tMATRIX\n", file = file, append = TRUE)    
-    
-    for (i in 1:nsplits){
-        slab <- ifelse(flab, attr(obj, "splitlabels")[i], i)
-        swei <- ifelse(fwei, paste(weight[i], "\t"), "")
-        scon <- ifelse(fcon, paste(attr(obj, "confidences")[i], "\t"), "")
-        sint <- ifelse(fint, paste(attr(obj, "intervals")[i], "\t"), "")
-#        cat("\t\t", slab, "\t", weight[i], "\t", scon, sint, paste(obj[[i]], collapse=" "), 
-#            ",\n", file = file, append = TRUE, sep = "") 
-        cat("\t\t", slab, "\t", swei, scon, sint, paste(obj[[i]], collapse=" "), 
-            ",\n", file = file, append = TRUE, sep = "")      
-    }
-    cat("\t;\nEND;\n", file = file, append = TRUE)
-}
-
-
-write.nexus.networx <- function(obj, file = "", taxa=TRUE, splits=TRUE, append=FALSE){
-    if(!append){
-        cat("#NEXUS\n\n", file = file)
-        cat("[Splits block for Spectronet or Splitstree]\n", file = file, append = TRUE)
-        cat("[generated by phangorn:\n", file = file, append = TRUE)
-        cat(format(citation("phangorn"), "text"), "]\n\n",
-            file = file, append = TRUE)
-        }
-    ntaxa <- length(obj$tip.label)
-    # TAXON BLOCK    
-    if(taxa){
-        cat(paste("BEGIN TAXA;\n\tDIMENSIONS NTAX=", ntaxa, ";\n", 
-            sep = ""), file = file, append = TRUE)
-        if(splits)taxalabel <- attr(obj$splits, "labels")
-        else taxalabel <- obj$tip.label
-        cat("\tTAXLABELS", paste(taxalabel, sep = " "), ";\nEND;\n\n", 
-            file = file, append = TRUE)
-    }
-# SPLITS BLOCK    
-    spl <- obj$splits
-    if(splits){
-#        spl <- changeOrder(spl, obj$tip.label) # orderSplitLabel
-        write.nexus.splits(spl, file = file, weights=NULL, append = TRUE, taxa=FALSE) 
-    }
-    nvertices <- max(obj$edge)
-    
-    #    if(is.null(attr(obj, "coords")))   
-    if(is.null(obj$.plot$vertices)) vertices <- coords(obj, "2D")
-    else vertices <- obj$.plot$vertices
-    
-    # y-axis differs between R and SplitsTree
-    vertices[,2] <- -vertices[,2]
-    
-    if(is.null(obj$.plot)) edge.col <- obj$.plot$edge.color 
-    else edge.col=NULL 
-    nedges <- nrow(obj$edge)
-# NETWORK BLOCK
-    cat(paste("BEGIN NETWORK;\nDIMENSIONS ntax=", ntaxa,
-              "\tnvertices=", nvertices, "\tnedges=", nedges,";\n", sep = ""), file = file, append = TRUE)  
-    cat("DRAW to_scale;\n", file = file, append = TRUE)
-    cat("TRANSLATE\n", file = file, append = TRUE)
-    if(is.null(obj$translate)){
-        for(i in 1:ntaxa){
-            cat(i, " ", obj$tip.label[i], ",\n", sep="", file = file, append = TRUE)
-        }
-    }
-    else {
-        translate <- obj$translate
-        for(i in 1:nrow(translate)){
-            cat(translate$node[i], " ", translate$label[i], ",\n", sep="", file = file, append = TRUE)
-        }        
-    }
-    cat(";\nVERTICES\n", file = file, append = TRUE)
-    for(i in 1:nvertices){
-        cat(i, "\t", vertices[i,1], "\t", vertices[i,2], ",\n", sep="", file = file, append = TRUE)
-    }
-    if(!is.null(obj$tip.label)){
-    cat(";\nVLABELS\n", file = file, append = TRUE)
-    if(is.null(obj$translate)){    
-        for(i in 1:ntaxa){
-            cat(i, "\t", obj$tip.label[i], ",\n", sep="", file = file, append = TRUE)
-        }
-    }
-    else{
-        for(i in 1:nrow(translate)){
-            cat(translate[i,1], " ", translate[i,2], ",\n", sep="", file = file, append = TRUE)
-        }           
-    }     
-    }    
-# cnet$splitIndex if splits = TRUE    
-    cat(";\nEDGES\n", file = file, append = TRUE)
-    
-    if(is.null(obj$.plot$edge.color)) edge.col="black"
-    else edge.col <- obj$.plot$edge.color
-    if(length(edge.col)<nedges) edge.col <- rep(edge.col, length=nedges) 
-    
-    splI <- TRUE
-    if(is.null(obj$splitIndex))splI <- FALSE
-    for(i in 1:nedges){
-        ecoli = edge.col[i]
-        spInd <- ifelse(splI, paste("\ts=", obj$splitIndex[i], sep=""), "")
-        edgeCol <- ifelse(ecoli=="black", "", paste("\tfg=", paste(col2rgb(ecoli), collapse=" "), sep=""))
-        cat(i, "\t", obj$edge[i,1], "\t", obj$edge[i,2], spInd, edgeCol, ",\n", sep="", file = file, append = TRUE)
-        }
-    cat(";\n", file = file, append = TRUE)
-    cat("END;\n", file = file, append = TRUE)
-# force SplitsTree to accept the file    
-    cat("\nBEGIN st_Assumptions;\n    uptodate;\nEND; [st_Assumptions]\n", file = file, append = TRUE)
-}
-
-
-read.nexus.networx <- function(file, splits=TRUE){
-    spl <- NULL
-    if(splits)spl <-read.nexus.splits(file)
-    
-    X <- scan(file = file, what = "", sep = "\n", quiet = TRUE)
-    semico <- grep(";", X)
-    X=gsub("\\[(.*?)\\]", "", X) # get rid of comments
-    
-    netStart <- grep("BEGIN NETWORK;", X, ignore.case = TRUE)
-    netEnd <- grep("END;", X, ignore.case = TRUE)
-    netEnd <- netEnd[netEnd>netStart][1]
-    dims <- grep("DIMENSION", X, ignore.case = TRUE)
-    dims <- dims[(dims>netStart) & (dims<netEnd)]
-    
-    ntaxa = 0
-    nvertices = 0 
-    nedges = 0
-    
-    if(length(dims)>0){
-        tmp = X[dims]    
-        tmp = gsub("\\s+", "", tmp)
-        
-        ntaxa <- as.numeric(sub("(.+?)(ntax\\s*\\=\\s*)(\\d+)(.+)", 
-            "\\3", tmp, perl = TRUE, ignore.case = TRUE))
-        nvertices  <- as.numeric(sub("(.+?)(nvertices\\s*\\=\\s*)(\\d+)(.+)", 
-            "\\3", tmp, perl = TRUE, ignore.case = TRUE))
-        nedges <- as.numeric(sub("(.+?)(nedges\\s*\\=\\s*)(\\d+)(.+)", 
-            "\\3", tmp, perl = TRUE, ignore.case = TRUE))
-    }
-    transl <- grep("TRANSLATE", X, ignore.case = TRUE)
-    translation <- if (length(transl) == 1 && transl > netStart) TRUE
-    else FALSE
-    translate.nodes <- FALSE
-    if (translation) {
-        end <- semico[semico > transl][1]
-        x <- X[(transl + 1):end]
-        x <- unlist(strsplit(x, "[,; \t]"))
-        x <- x[nzchar(x)]
-        x <- gsub("['\']", "", x)
-        if(length(x) == 2*ntaxa){
-            TRANS <- matrix(x, ncol = 2, byrow = TRUE)
-            TRANS[, 2] <- gsub("['\"]", "", TRANS[, 2])
-            TRANS <- list(node=as.numeric(TRANS[,1]), label=TRANS[,2])
-#            translate.nodes <- TRUE
-        }
-        else{
-#            TRANS <- matrix(NA, nrow = ntaxa, ncol = 2)
-            y <- as.numeric(x)
-            node <- numeric(ntaxa)
-            label <- character(ntaxa)
-            k=1
-            for(i in 1:length(x)){
-                if(!is.na(y[i])) tmp <- y[i]
-                else{
-                    node[k] <- tmp
-                    label[k] <- x[i]
-#                    TRANS[k, ] <- c(tmp, x[i])
-                    k=k+1
-                }
-                
-            }
-            TRANS <- list(node=node, label=label)
-        }    
-#        n <- dim(TRANS)[1]
-    }
-    
-    
-    vert <- grep("VERTICES", X, ignore.case = TRUE)
-    start <- vert[vert>max(dims, netStart)][1] + 1
-    end <- semico[semico>start][1] -1
-    VERT <- matrix(0, nvertices, 3, dimnames = list(NULL, c("id", "x", "y")))
-    j=1
-    for(i in start:end){
-        tmp <- X[i]
-#        tmp <- sub("\\s+", "", tmp) 
-        tmp <- gsub("\\,", "", tmp)  
-        tmp <- strsplit(tmp, "[[:space:]]")[[1]]
-        VERT[j,1] <- as.numeric(tmp[1]) 
-        VERT[j,2] <- as.numeric(tmp[2])
-        VERT[j,3] <- as.numeric(tmp[3])
-        j=j+1
-    }
-    
-    edges <- grep("EDGES", X, ignore.case = TRUE)
-    start <- edges[edges>max(dims, netStart)][1] + 1
-    end <- semico[semico>start][1] -1
-    EDGE <- NULL
-    if(splits) EDGE <- matrix(0, nedges, 4, dimnames = list(NULL, c("id", "vert_id_2", "vert_id_2", "splits_id")))
-    else EDGE <- matrix(0, nedges, 3, dimnames = list(NULL, c("id", "vert_id_2", "vert_id_2")))
-    j=1
-    for(i in start:end){
-        tmp <- X[i]
-        tmp <- gsub("\\,", "", tmp)
-        #        tmp <- sub("\\s+", "", tmp) 
-        tmp <- strsplit(tmp, "[[:space:]]")[[1]]
-        EDGE[j,1] <- as.numeric(tmp[1]) 
-        EDGE[j,2] <- as.numeric(tmp[2])
-        EDGE[j,3] <- as.numeric(tmp[3])
-        if(splits){
-            EDGE[j,4] <- as.numeric(sub("s=", "", tmp[4], ignore.case = TRUE))
-        }    
-        j=j+1
-    }
-    
-    swapEdge <- function(x, old, new) {
-        x[x==new] <- -1L
-        x[x==old] <- new
-        x[x==-1L] <- old
-        x     
-    }
-    swapRow <- function(x, old, new) {
-        tmp <- x[old,]
-        x[old,] <- x[new,]
-        x[new,] <- tmp
-        x     
-    }
-    splitIndex <- if(ncol(EDGE)==4) EDGE[,4]
-    else NULL
-# quick and dirty   
-    el = sqrt(rowSums((VERT[EDGE[,2],c(2:3)] - VERT[EDGE[,3],c(2:3)])^2))
-    edge <- EDGE[,c(2:3)]
-    vert <- VERT[,c(2:3)]
-    
-    
-    if(translate.nodes){
-#        oldLabel <- as.integer(as.numeric(TRANS[,1]))
-        oldLabel <- as.integer(TRANS$node)
-        for(i in 1:ntaxa){
-            edge <- swapEdge(edge, oldLabel[i], i) 
-            vert <- swapRow(vert, oldLabel[i], i)
-        }
-    }
-    dimnames(edge) <- NULL
-    # y-axis differs between in R and SplitsTree
-    vert[,2] <- -vert[,2]  
-#    translate=data.frame(as.numeric(TRANS[,1]), TRANS[,2], stringsAsFactors=FALSE)
-    plot <- list(vertices=vert)        
-    obj <- list(edge=edge, tip.label=TRANS$label, edge.length=el, Nnode=max(edge)-ntaxa,
-        splitIndex=splitIndex, splits=spl, translate=TRANS) 
-    obj$.plot <- list(vertices = vert, edge.color="black", edge.width=3, edge.lty = 1)
-    class(obj) <- c("networx", "phylo")
-    reorder(obj)
-    obj
-}
-
-
-read.nexus.splits <- function(file)
-{
-    X <- scan(file = file, what = "", sep = "\n", quiet = TRUE)
-    semico <- grep(";", X)
-    X=gsub("\\[(.*?)\\]", "", X) # get rid of comments
-    i1 <- grep("TAXLABELS", X, ignore.case = TRUE)    
-    taxlab <- ifelse(length(i1)>0, TRUE, FALSE) 
-    if (taxlab) {
-        end <- semico[semico >= i1][1]
-        x <- X[(i1):end] # assumes not a 'new line' after "TRANSLATE"
-        x <- gsub("TAXLABELS", "", x, ignore.case = TRUE)
-        x <- unlist(strsplit(x, "[,; \t]"))   
-        x <- x[nzchar(x)]
-        x <- gsub("['\"]", "", x)
-        xntaxa <- length(x)
-    }
-    sp <- grep("SPLITS;", X, ignore.case = TRUE)
-    spEnd <- grep("END;", X, ignore.case = TRUE)
-    spEnd <- spEnd[spEnd>sp][1]
-    dims <- grep("DIMENSION", X, ignore.case = TRUE)
-    cyc <- grep("CYCLE", X, ignore.case = TRUE)
-    matr <- grep("MATRIX", X, ignore.case = TRUE)
-    format <- grep("FORMAT", X, ignore.case = TRUE)
-    start <- matr[matr>sp][1] + 1
-    end <- semico[semico>start][1] -1
-    format <- format[(format>sp) & (format<spEnd)]
-    
-    res <- vector("list", end - start + 1)
-    weights = numeric(end - start + 1)
-    j=1
-    
-    flab = fwei = fcon = fint = FALSE
-    
-    if(length(format)>0){
-        tmp = X[format]    
-        tmp = gsub("\\;", "", tmp)
-        tmp = gsub("\\s+", "", tmp)
-        flab = grepl("labels=left", tmp, ignore.case = TRUE) 
-        fwei = grepl("weights=yes", tmp, ignore.case = TRUE) 
-        fcon = grepl("confidences=yes", tmp, ignore.case = TRUE) 
-        fint = grepl("intervals=yes", tmp, ignore.case = TRUE) 
-        # = as.numeric(na.omit(as.numeric(strsplit(tmp, " ")[[1]])))        
-        ind = cumsum(c(flab, fwei, fcon, fint))
-        mformat = sum(c(flab, fwei, fcon, fint))
-     }
-    
-    if(fint)intervals = numeric(end - start + 1)
-    if(fcon)confidences = numeric(end - start + 1)
-    if(flab)labels = vector("character", end - start + 1)
-   
-    for(i in start:end){
-        tmp = X[i]
-        tmp = sub("\\s+", "", tmp) 
-        tmp = strsplit(tmp, "\t")[[1]]
-        if(flab)labels[j] = as.numeric(tmp[ind[1]])        
-        if(fwei)weights[j] = as.numeric(tmp[ind[2]])
-        if(fcon)confidences[j] = as.numeric(tmp[ind[3]])
-        if(fint)intervals[j] = as.numeric(tmp[ind[4]])
-        tmp = tmp[length(tmp)]
-        tmp = gsub("\\,", "", tmp)
-        res[[j]] = as.integer(na.omit(as.numeric(strsplit(tmp, " ")[[1]])))
-        j=j+1
-    }
-    if(length(cyc)>0){
-        tmp = X[cyc]    
-        tmp = gsub("\\;", "", tmp)
-        tmp = gsub("CYCLE", "", tmp, ignore.case = TRUE)
-        tmp = sub("\\s+", "", tmp)
-        cyc = as.integer(na.omit(as.numeric(strsplit(tmp, " ")[[1]])))
-    }
-    attr(res, "labels") = x
-    if(fwei)attr(res, "weights") = weights
-    if(fint)attr(res, "intervals") = intervals
-    if(fcon)attr(res, "confidences") = confidences
-    if(flab)attr(res, "splitlabels") = labels
-    attr(res, "cycle") = cyc 
-    class(res) = "splits"
-    res
-}
-
-
-
-################################################################################
-# delta.score
-################################################################################
-# Calculated from mathematical description given in Gray et al. (2010) Phil.
-# Trans. Roy. Soc. B. 
-# delta.score reference: Holland et al. (2002) Mol. Biol. Evol.
-################################################################################ 
-
-
-# Calculating Delta and Q-residual scores 
-# internal
-delta.quartet <-
-    function(quartet,dist.dna) {
-        m1 <- dist.dna[quartet[1],quartet[2]] + dist.dna[quartet[3],quartet[4]]
-        m2 <- dist.dna[quartet[1],quartet[3]] + dist.dna[quartet[2],quartet[4]]
-        m3 <- dist.dna[quartet[1],quartet[4]] + dist.dna[quartet[2],quartet[3]]
-        m <- sort(c(m1,m2,m3),decreasing=T)
-        if((m[1]-m[3])!=0) {
-            ret <- (m[1]-m[2])/(m[1]-m[3])
-        } else {
-            ret <- 0
-        }
-        return(ret)
-    }
-
-
-delta.score <- function(x, arg="mean", ...) {
-        # dist.dna <- as.matrix(dist.dna(dna,"raw"))   
-        # dist.dna(dna,"raw") is equivalent to dist.hamming(as.phyDat(dna), exclude="all") 
-        dist.dna <- as.matrix(dist.hamming(x, ...))
-        # Number of quartets
-        # choose(length(names(x)),4)
-        # Create all quartets
-        all.quartets <- t(combn(names(x),4))
-        delta.values <- apply(all.quartets[,],1,delta.quartet,dist.dna)
-        if (!arg%in%c("all", "mean","sd")) stop("return options are: all, mean, or sd")
-        if (arg=='all') return(delta.values)
-        if (arg=='mean') return(mean(delta.values))
-        if (arg=='sd') return(sd(delta.values))
-    }
 
diff --git a/R/parsimony.R b/R/parsimony.R
index 65e87b1..7cf4238 100644
--- a/R/parsimony.R
+++ b/R/parsimony.R
@@ -15,6 +15,76 @@ sankoff.quartet <- function (dat, cost, p, l, weight)
 }
 
 
+
+
+#' Parsimony tree.
+#' 
+#' 
+#' \code{parsimony} returns the parsimony score of a tree using either the
+#' sankoff or the fitch algorithm. \code{optim.parsimony} tries to find the
+#' maximum parsimony tree using either Nearest Neighbor Interchange (NNI)
+#' rearrangements or sub tree pruning and regrafting (SPR). \code{pratchet}
+#' implements the parsimony ratchet (Nixon, 1999) and is the preferred way to
+#' search for the best tree.  \code{random.addition} can be used to produce
+#' starting trees. 
+#' 
+#' The "SPR" rearrangements are so far only available for the "fitch" method,
+#' "sankoff" only uses "NNI". The "fitch" algorithm only works correct for
+#' binary trees.
+#' 
+#' @aliases parsimony 
+#' @aliases optim.parsimony sankoff fitch pratchet
+#' random.addition acctran
+#' @param data A object of class phyDat containing sequences.
+#' @param tree tree to start the nni search from.
+#' @param method one of 'fitch' or 'sankoff'.
+#' @param cost A cost matrix for the transitions between two states.
+#' @param site return either 'pscore' or 'site' wise parsimony scores.
+#' @param trace defines how much information is printed during optimisation.
+#' @param rearrangements SPR or NNI rearrangements.
+#' @param start a starting tree can be supplied.
+#' @param maxit maximum number of iterations in the ratchet.
+#' @param k number of rounds ratchet is stopped, when there is no improvement.
+#' @param all return all equally good trees or just one of them.
+#' @param perturbation whether using a ratchet or stochastic (nni) for
+#' shuffling the tree.
+#' @param ... Further arguments passed to or from other methods (e.g.
+#' model="sankoff" and cost matrix).
+#' @return \code{parsimony} returns the maximum parsimony score (pscore).
+#' \code{optim.parsimony} returns a tree after NNI rearrangements.
+#' \code{pratchet} returns a tree or list of trees containing the best tree(s)
+#' found during the search.  \code{acctran} returns a tree with edge length
+#' according to the ACCTRAN criterion.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{bab}}, \code{\link{CI}}, \code{\link{RI}}, \code{\link{ancestral.pml}}, 
+#' \code{\link{nni}}, \code{\link{NJ}}, \code{\link{pml}}, \code{\link{getClans}}
+#' ,\code{\link{ancestral.pars}}, \code{\link{bootstrap.pml}}
+#' @references Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer
+#' Associates, Sunderland.
+#' 
+#' Nixon, K. (1999) The Parsimony Ratchet, a New Method for Rapid Parsimony
+#' Analysis. \emph{Cladistics} \bold{15}, 407-414
+#' @keywords cluster
+#' @examples
+#' 
+#' set.seed(3)
+#' data(Laurasiatherian)
+#' dm = dist.hamming(Laurasiatherian)
+#' tree = NJ(dm)
+#' parsimony(tree, Laurasiatherian)
+#' treeRA <- random.addition(Laurasiatherian)
+#' treeNNI <- optim.parsimony(tree, Laurasiatherian)
+#' treeRatchet <- pratchet(Laurasiatherian, start=tree, maxit=100, k=5)
+#' # assign edge length
+#' treeRatchet <- acctran(treeRatchet, Laurasiatherian)
+#' 
+#' plot(midpoint(treeRatchet))
+#' add.scale.bar(0,0, length=100)
+#' 
+#' parsimony(c(tree,treeNNI, treeRatchet), Laurasiatherian)
+#' 
+#' @rdname parsimony
+#' @export
 parsimony <- function(tree, data, method='fitch', ...){
     if (class(data)[1] != "phyDat") stop("data must be of class phyDat")
     if(method=='sankoff') result <- sankoff(tree, data, ...)
@@ -23,6 +93,8 @@ parsimony <- function(tree, data, method='fitch', ...){
 }
 
 
+#' @rdname ancestral.pml
+#' @export
 ancestral.pars <- function (tree, data, type = c("MPR", "ACCTRAN"), cost=NULL) 
 {
     call <- match.call()
@@ -66,6 +138,8 @@ ancestral.pars <- function (tree, data, type = c("MPR", "ACCTRAN"), cost=NULL)
 }
 
 
+#' @rdname ancestral.pml
+#' @export
 pace <- ancestral.pars
 
 
@@ -136,7 +210,8 @@ mpr <- function(tree, data, cost=NULL){
 }
 
 
-
+#' @rdname ancestral.pml
+#' @export
 plotAnc <- function (tree, data, i = 1, col=NULL, cex.pie=par("cex"), pos="bottomright", ...)
 {
    y = subset(data, , i)
@@ -233,7 +308,8 @@ parsinfo <- function (x)
 }
 
 
-lowerBound <- function(x, cost=NULL){
+# had problems with ambiguous states
+lowerBound_old <- function(x, cost=NULL){
     tip <- names(x)
     att = attributes(x)
     nc = attr(x, "nc")
@@ -254,7 +330,8 @@ lowerBound <- function(x, cost=NULL){
             states = as.data.frame(states, stringsAsFactors=FALSE)
             class(states) = "list"
         }
-        nst <- sapply(states, length)
+        nst <- lengths(states)
+#        nst <- sapply(states, length)
     }
     res = numeric(nr)
     ust = sort(unique(nst))
@@ -277,6 +354,49 @@ lowerBound <- function(x, cost=NULL){
 }
 
 
+# greedy algorithm of Maximum Set Packing (MSP) problem (should work in most instances)
+lowerBound <- function(x, cost=NULL){
+    tip <- names(x)
+    att = attributes(x)
+    nc = attr(x, "nc")
+    nr = attr(x, "nr")
+    contrast = attr(x, "contrast")
+    rownames(contrast) = attr(x, "allLevels")
+    colnames(contrast) = attr(x, "levels")
+    attr(x, "weight") = rep(1, nr)
+    attr(x, "index") = NULL
+    
+    y <- as.character(x)
+    states <- apply(y, 2, unique.default)
+    
+    singles <- which(rowSums(contrast) == 1) # 
+    noinfo <- which(rowSums(contrast) == nc) # 
+    ambiguous <- which( (rowSums(contrast) > 1) & (rowSums(contrast) < nc) )  # 
+    singles <- names(singles)
+    noinfo <- names(noinfo)
+    ambiguous <- names(ambiguous)
+    
+    fun <- function(states, contrast, singles, noinfo, ambiguous){
+        if(length(states)==1) return(0)
+        states <- setdiff(states, noinfo) # get rid of "-", "?" in DNA 
+        if( (length(states)==0) | (length(states)==1) ) return(0)
+        if( any(states %in% ambiguous)) {
+            n <- 0
+            contrast <- contrast[states, , drop=FALSE]
+            while(nrow(contrast) > 0){
+                m <- which.max(colSums(contrast))
+                contrast <- contrast[contrast[, m]==0 , , drop=FALSE]
+                n <- n+1
+            }
+            return(n-1)
+        }
+        else return(length(states)-1)
+    }
+    res <- sapply(states, fun, contrast, singles, noinfo, ambiguous)    
+    res
+}
+
+
 upperBound <- function(x, cost=NULL){
     tree = stree(length(x), tip.label=names(x))
     if(is.null(cost))cost <- 1 - diag(attr(x, "nc")) 
@@ -284,6 +404,27 @@ upperBound <- function(x, cost=NULL){
 }
 
 
+
+#' Consistency Index and Retention Index
+#' 
+#' \code{CI} and \code{RI} compute the Consistency Index (CI) and Retention Index (RI).
+#' 
+#' @details The Consistency Index is defined as minimum number of changes divided by the 
+#' number of changes required on the tree (parsimony score). The Consistency 
+#' Index is equal to one if there is no homoplasy.
+#' And the Retention Index is defined as
+#' \deqn{RI = \frac{MaxChanges - ObsChanges}{MaxChanges - MinChanges}}{RI = (MaxChanges - ObsChanges) / (MaxChanges - MinChanges)}
+#' 
+#' @param data A object of class phyDat containing sequences.
+#' @param tree tree to start the nni search from.
+#' @param cost A cost matrix for the transitions between two states.
+#' @param sitewise return CI/RI for alignment or sitewise
+#' 
+#' @seealso \code{\link{parsimony}}, \code{\link{pratchet}}, \code{\link{fitch}}, 
+#' \code{\link{sankoff}}, \code{\link{bab}}, \code{\link{ancestral.pars}}
+#' 
+#' @rdname CI
+#' @export
 CI <- function (tree, data, cost = NULL, sitewise=FALSE) 
 {
     if(sitewise) pscore = sankoffNew(tree, data, cost = cost, site="site")
@@ -298,6 +439,8 @@ CI <- function (tree, data, cost = NULL, sitewise=FALSE)
 }
 
 
+#' @rdname CI
+#' @export
 RI <- function (tree, data, cost = NULL, sitewise=FALSE) 
 {
     if(sitewise) pscore = sankoffNew(tree, data, cost = cost, site="site")
@@ -482,7 +625,8 @@ prepareDataSankoff <- function(data){
 }
 
 
-
+#' @rdname parsimony
+#' @export
 sankoff <- function (tree, data, cost = NULL, site = 'pscore') 
 {
     if (!inherits(data,"phyDat")) 
@@ -646,6 +790,8 @@ sankoff.nni = function (tree, data, cost, ...)
 }
 
 
+#' @rdname parsimony
+#' @export
 optim.parsimony <- function(tree,data, method='fitch', cost=NULL, trace=1, rearrangements="SPR", ...){
     if(method=='fitch') result <- optim.fitch(tree=tree, data=data, trace=trace, rearrangements=rearrangements, ...) 
     if(method=='sankoff') result <- optim.sankoff(tree=tree, data=data, cost=cost, trace=trace, ...)
@@ -653,6 +799,8 @@ optim.parsimony <- function(tree,data, method='fitch', cost=NULL, trace=1, rearr
 }
 
 
+#' @rdname parsimony
+#' @export
 # perturbation="ratchet", "stochastic"
 pratchet <- function (data, start=NULL, method="fitch", maxit=1000, k=10, trace=1, all=FALSE, rearrangements="SPR", perturbation="ratchet", ...) 
 {
@@ -835,6 +983,8 @@ ptree <- function (tree, data, type = "ACCTRAN", retData = FALSE)
 }
 
 
+#' @rdname parsimony
+#' @export
 acctran <- function(tree, data) ptree(tree, data, type="ACCTRAN", retData=FALSE)
 
 
diff --git a/R/phangorn-package.R b/R/phangorn-package.R
new file mode 100644
index 0000000..b85ab31
--- /dev/null
+++ b/R/phangorn-package.R
@@ -0,0 +1,99 @@
+
+
+#' Chloroplast alignment
+#' 
+#' Amino acid alignment of 15 genes of 19 different chloroplast.
+#' 
+#' 
+#' @name chloroplast
+#' @docType data
+#' @keywords datasets
+#' @examples
+#' 
+#' data(chloroplast)
+#' chloroplast
+#' 
+NULL
+
+
+
+
+
+#' Laurasiatherian data (AWCMEE)
+#' 
+#' Laurasiatherian RNA sequence data
+#' 
+#' 
+#' @name Laurasiatherian
+#' @docType data
+#' @source Data have been taken from \url{http://www.allanwilsoncentre.ac.nz/}
+#' and were converted to R format by \email{klaus.schliep at gmail.com}.
+#' @keywords datasets
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' str(Laurasiatherian)
+#' 
+NULL
+
+
+
+
+
+#' Phylogenetic analysis in R
+#' 
+#' Phylogenetic analysis in R (Estimation of phylogenetic trees and networks
+#' using Maximum Likelihood, Maximum Parsimony, Distance methods & Hadamard
+#' conjugation)
+#' 
+#' The complete list of functions can be displayed with \code{library(help =
+#' phangorn)}.
+#' 
+#' Further information is available in several vignettes. To show the available
+#' vignettes in an HTML browser type \code{browseVignettes("phangorn")}.
+#' \tabular{ll}{ \code{Trees} \tab Constructing phylogenetic trees (source,
+#' pdf) \cr \code{phangorn-specials} \tab Advanced features (source, pdf) \cr
+#' \code{Ancestral} \tab Ancestral sequence reconstruction (source, pdf) \cr
+#' \code{Networx} \tab Splits and Networx (source, html) \cr } The first
+#' vignette (to display type \code{vignette('Trees')}) gives an introduction in
+#' phylogenetic analysis with phangorn. The second vignette (phangorn-special)
+#' covers more advanced feature like defining special character spaces and
+#' things which fit nowhere else.  More information on \bold{phangorn} can be
+#' found on \url{http://www.phangorn.org}.
+#' 
+#' 
+#' @name phangorn-package
+#' @aliases phangorn-package phangorn
+#' @docType package
+#' @author Klaus Schliep
+#' 
+#' Maintainer: Klaus Schliep <klaus.schliep@@gmail.com>
+#' @references Schliep K.P. (2011) phangorn: Phylogenetic analysis in R.
+#' \emph{Bioinformatics}, 27(4) 592-593
+#' @keywords package
+NULL
+
+
+
+
+
+#' Yeast alignment (Rokas et al.)
+#' 
+#' Alignment of 106 genes of 8 different species of yeast.
+#' 
+#' 
+#' @name yeast
+#' @docType data
+#' @references Rokas, A., Williams, B. L., King, N., and Carroll, S. B. (2003)
+#' Genome-scale approaches to resolving incongruence in molecular phylogenies.
+#' \emph{Nature}, \bold{425}(6960): 798--804
+#' @keywords datasets
+#' @examples
+#' 
+#' data(yeast)
+#' str(yeast)
+#' 
+NULL
+
+
+
diff --git a/R/phyDat.R b/R/phyDat.R
index f428768..387d930 100644
--- a/R/phyDat.R
+++ b/R/phyDat.R
@@ -93,8 +93,11 @@ phyDat.default <- function (data, levels = NULL, return.index = TRUE, contrast =
     
     row.names(data) = as.character(1:p)
     data = na.omit(data)
-    
     aaa = match(index, attr(data, "na.action"))
+    
+
+    if(!is.null(attr(data, "na.action"))) warning("Found unknown characters (not supplied in levels). Deleted sites with with unknown states.")
+    
     index = index[is.na(aaa)] 
     index = match(index, unique(index))
     rn = as.numeric(rownames(data))
@@ -169,7 +172,9 @@ phyDat.DNA = function (data, return.index = TRUE)
     row.names(data) = as.character(1:p)
     data = na.omit(data)
     rn = as.numeric(rownames(data))
-
+    
+    if(!is.null(attr(data, "na.action"))) warning("Found unknown characters. Deleted sites with with unknown states.")
+    
     aaa = match(index, attr(data, "na.action"))
     index = index[is.na(aaa)] 
     index = match(index, unique(index))
@@ -251,6 +256,8 @@ phyDat.AA <- function (data, return.index = TRUE)
     data = na.omit(data)
     rn = as.numeric(rownames(data))
 
+    if(!is.null(attr(data, "na.action"))) warning("Found unknown characters. Deleted sites with with unknown states.")
+    
     aaa = match(index, attr(data, "na.action"))
     index = index[is.na(aaa)] 
     index = match(index, unique(index))
@@ -342,7 +349,9 @@ phyDat.codon <- function (data, return.index = TRUE)
     row.names(data) = as.character(1:p)
     data = na.omit(data)
     rn = as.numeric(rownames(data))
-
+    
+    if(!is.null(attr(data, "na.action"))) warning("Found unknown characters. Deleted sites with with unknown states.")
+    
     aaa = match(index, attr(data, "na.action"))
     index = index[is.na(aaa)] 
     index = match(index, unique(index))
@@ -368,24 +377,135 @@ phyDat.codon <- function (data, return.index = TRUE)
 }
 
 
+#' Conversion among Sequence Formats
+#' 
+#' These functions transform several DNA formats into the \code{phyDat} format.
+#' \code{allSitePattern} generates an alignment of all possible site patterns.
+#' 
+#' If \code{type} "USER" a vector has to be give to \code{levels}. For example
+#' c("a", "c", "g", "t", "-") would create a data object that can be used in
+#' phylogenetic analysis with gaps as fifth state.  There is a more detailed
+#' example for specifying "USER" defined data formats in the vignette
+#' "phangorn-specials".
+#' 
+#' \code{allSitePattern} returns all possible site patterns and can be useful
+#' in simulation studies. For further details see the vignette
+#' phangorn-specials.
+#' 
+#' \code{write.phyDat} calls the function write.dna or write.nexus.data and
+#' \code{read.phyDat} calls the function \code{read.dna}, \code{read.aa} or
+#' \code{read.nexus.data} see for more details over there.
+#' 
+#' You may import data directly with \code{\link[ape]{read.dna}} or
+#' \code{\link[ape]{read.nexus.data}} and convert the data to class phyDat.
+#' 
+#' The generic function \code{c} can be used to to combine sequences and
+#' \code{unique} to get all unique sequences or unique haplotypes.
+#' 
+#' \code{acgt2ry} converts a \code{phyDat} object of nucleotides into an binary
+#' ry-coded dataset.
+#' 
+#' @aliases 
+#' as.phyDat.character as.phyDat.data.frame as.phyDat.matrix
+#' as.MultipleAlignment as.MultipleAlignment.phyDat cbind.phyDat c.phyDat 
+#' acgt2ry removeUndeterminedSites phyDat2MultipleAlignment 
+#' @param data An object containing sequences.
+#' @param x An object containing sequences.
+#' @param type Type of sequences ("DNA", "AA", "CODON" or "USER").
+#' @param levels Level attributes.
+#' @param return.index If TRUE returns a index of the site patterns.
+#' @param file A file name.
+#' @param format File format of the sequence alignment (see details).  Several
+#' popular formats are supported: "phylip", "interleaved", "sequential",
+#' "clustal", "fasta" or "nexus", or any unambiguous abbreviation of these.
+#' @param colsep a character used to separate the columns (a single space by
+#' default).
+#' @param nbcol a numeric specifying the number of columns per row (-1 by
+#' default); may be negative implying that the nucleotides are printed on a
+#' single line.
+#' @param n Number of sequences.
+#' @param names Names of sequences.
+#' @param subset a subset of taxa.
+#' @param select a subset of characters.
+#' @param site.pattern select site pattern or sites.
+#' @param allLevels return original data.
+#' @param obj as object of class phyDat
+#' @param freq logical, if 'TRUE', frequencies or counts are returned otherwise
+#' proportions
+#' @param all all a logical; if all = TRUE, all counts of bases, ambiguous
+#' codes, missing data, and alignment gaps are returned as defined in the
+#' contrast.
+#' @param drop.unused.levels logical, drop unused levels
+#' @param incomparables for compatibility with unique.
+#' @param identical if TRUE (default) sequences have to be identical, if FALSE
+#' sequences are considered duplicates if distance between sequences is zero
+#' (happens frequently with ambiguous sites).
+#' @param ambiguity character for ambiguous character and no contrast is provided.
+#' @param ... further arguments passed to or from other methods.
+#' @return The functions return an object of class \code{phyDat}.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{DNAbin}}, \code{\link{as.DNAbin}},
+#' \code{\link{read.dna}}, \code{\link{read.aa}}, \code{\link{read.nexus.data}}
+#' and the chapter 1 in the \code{vignette("phangorn-specials",
+#' package="phangorn")} and the example of \code{\link{pmlMix}} for the use of
+#' \code{allSitePattern}
+#' @keywords cluster
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' class(Laurasiatherian)
+#' Laurasiatherian
+#' baseFreq(Laurasiatherian)
+#' baseFreq(Laurasiatherian, all=TRUE)
+#' subset(Laurasiatherian, subset=1:5)
+#' # transform into old ape format
+#' LauraChar <- as.character(Laurasiatherian)
+#' # and back 
+#' Laura <- phyDat(LauraChar, return.index=TRUE)
+#' all.equal(Laurasiatherian, Laura)
+#' allSitePattern(5)
+#' 
+#' @rdname phyDat
+#' @export 
+phyDat <- function (data, type="DNA", levels=NULL, return.index = TRUE,...) 
+{
+    if (inherits(data,"DNAbin")) type <- "DNA"
+    pt <- match.arg(type, c("DNA", "AA", "CODON", "USER"))  
+    if(pt=="DNA") dat <- phyDat.DNA(data, return.index=return.index,...)
+    if(pt=="AA") dat <- phyDat.AA(data, return.index=return.index, ...)
+    if(pt=="CODON") dat <- phyDat.codon(data, return.index=return.index, ...)
+    if(pt=="USER") dat <- phyDat.default(data, levels = levels, return.index=return.index, ...)
+    dat
+}
+
+
+#' @rdname phyDat
+#' @export
 dna2codon <- function(x){
     if(!inherits(x, "phyDat"))stop("x needs to be of class phyDat!")
     phyDat.codon(as.character(x))
 }
 
 
+#' @rdname phyDat
+#' @export
 codon2dna <- function(x){
     if(!inherits(x, "phyDat"))stop("x needs to be of class phyDat!")
     phyDat.DNA(as.character(x))
 }
 
 
+#' @rdname phyDat
+#' @export
 as.phyDat <- function (x, ...){
     if (inherits(x,"phyDat")) return(x)
     UseMethod("as.phyDat")
 }
 
 
+#' @rdname phyDat
+#' @method as.phyDat factor
+#' @export
 as.phyDat.factor <- function(x, ...){
     nam <- names(x)
     lev <- levels(x)
@@ -394,9 +514,16 @@ as.phyDat.factor <- function(x, ...){
     phyDat(x, type="USER", levels = lev, ...)
 }
 
+
+#' @rdname phyDat
+#' @method as.phyDat DNAbin
+#' @export
 as.phyDat.DNAbin <- function(x,...) phyDat.DNA(x,...)
 
 
+#' @rdname phyDat
+#' @method as.phyDat alignment
+#' @export
 as.phyDat.alignment <- function (x, type="DNA",...) 
 {
     x$seq <- tolower(x$seq)
@@ -411,7 +538,8 @@ as.phyDat.alignment <- function (x, type="DNA",...)
 
 
 #as.alignment.phyDat <- function(x, ...) as.alignment(as.character(x))
-
+#' @rdname phyDat
+#' @export
 phyDat2alignment <-  function(x){
     z = as.character(x)
     nam = rownames(z)
@@ -426,6 +554,9 @@ phyDat2alignment <-  function(x){
 }
 
 
+#' @rdname phyDat
+#' @method as.phyDat MultipleAlignment
+#' @export
 as.phyDat.MultipleAlignment <- function(x, ...){
     if (requireNamespace('Biostrings')){
     if(inherits(x, "DNAMultipleAlignment"))
@@ -495,6 +626,8 @@ acgt2ry <- function(obj){
 }
 
 
+#' @rdname phyDat
+#' @export
 # replace as.character.phyDat weniger Zeilen, works also for codons
 as.character.phyDat <- function (x, allLevels=TRUE, ...) 
 {
@@ -538,6 +671,8 @@ as.character.phyDat <- function (x, allLevels=TRUE, ...)
 }
 
 
+#' @rdname phyDat
+#' @export
 as.data.frame.phyDat <- function(x, ...){
   nr <- attr(x, "nr")
   nc <- attr(x, "nc")
@@ -565,6 +700,8 @@ as.data.frame.phyDat <- function(x, ...){
 #}
 
 # quite abit faster
+#' @rdname phyDat
+#' @export
 as.DNAbin.phyDat <- function (x, ...) 
 {
     if(attr(x, "type")=="DNA"){
@@ -601,24 +738,13 @@ as.DNAbin.phyDat <- function (x, ...)
 }
 
 
-#if (getRversion() >= "2.15.1") utils::globalVariables("as.AAbin")
+#' @rdname phyDat
+#' @export
 as.AAbin.phyDat <- function(x,...) {
    if(attr(x, "type")=="AA") return(as.AAbin(as.character(x, ...)))
    else stop("x must be a amino acid sequence")
 }
 
- 
-phyDat <- function (data, type="DNA", levels=NULL, return.index = TRUE,...) 
-{
-    if (inherits(data,"DNAbin")) type <- "DNA"
-    pt <- match.arg(type, c("DNA", "AA", "CODON", "USER"))  
-    if(pt=="DNA") dat <- phyDat.DNA(data, return.index=return.index,...)
-    if(pt=="AA") dat <- phyDat.AA(data, return.index=return.index, ...)
-    if(pt=="CODON") dat <- phyDat.codon(data, return.index=return.index, ...)
-    if(pt=="USER") dat <- phyDat.default(data, levels = levels, return.index=return.index, ...)
-    dat
-}
-
 
 print.phyDat = function (x, ...) 
 {
@@ -725,6 +851,8 @@ cbind.phyDat <- function(..., gaps="-", compress=TRUE){
 c.phyDat <- cbind.phyDat
 
 
+#' @rdname phyDat
+#' @export
 write.phyDat <- function(x, file, format="phylip", colsep = "", nbcol=-1, ...){
     formats <- c("phylip", "nexus", "interleaved", "sequential", "fasta")
     format <- match.arg(tolower(format), formats)
@@ -740,6 +868,8 @@ write.phyDat <- function(x, file, format="phylip", colsep = "", nbcol=-1, ...){
 }
 
 
+#' @rdname phyDat
+#' @export
 read.phyDat <- function(file, format="phylip", type="DNA", ...){
     
     formats <- c("phylip", "nexus", "interleaved", "sequential", "fasta", "clustal")
@@ -752,12 +882,21 @@ read.phyDat <- function(file, format="phylip", type="DNA", ...){
             data = read.dna(file, format, as.character = TRUE, ...)
         }
         if (type == "AA") data = read.aa(file, format=format, ...)
+        if (type == "USER"){
+            data = read.dna(file, format, as.character = TRUE)
+            extras <- match.call(expand.dots = FALSE)$...
+            extras <- lapply(extras, eval)
+            return(phyDat(data, type, levels=extras$levels, ambiguity = extras$ambiguity, 
+                contrast = extras$contrast))
+        }
         # raus
     }
     phyDat(data, type, return.index = TRUE)
 }
 
 
+#' @rdname phyDat
+#' @export
 baseFreq <- function(obj, freq=FALSE, all=FALSE, drop.unused.levels = FALSE){
     if (!inherits(obj,"phyDat")) 
         stop("data must be of class phyDat")
@@ -819,6 +958,9 @@ getRows <- function (data, rows, site.pattern = TRUE)
 }
 
 
+#' @rdname phyDat
+#' @method subset phyDat
+#' @export
 subset.phyDat <- function (x, subset, select, site.pattern = TRUE,...) 
 {  
      
@@ -883,6 +1025,9 @@ duplicated_map <- function(x, ...){
 }   
 
 
+#' @rdname phyDat
+#' @method unique phyDat
+#' @export
 unique.phyDat <- function(x, incomparables=FALSE, identical=TRUE, ...){
     if(identical) return(getCols(x, !duplicated(x)))
     getCols(x, !duplicated_phyDat(x))
@@ -910,7 +1055,8 @@ removeParsUninfoSites <- function(data){
 }
 
 
-
+#' @rdname phyDat
+#' @export
 allSitePattern <- function(n,levels=c("a","c","g","t"), names=NULL){
     l=length(levels)
     X=vector("list", n)
@@ -944,16 +1090,29 @@ write.phylip <- function(data, weight, file=""){
 
 read.FASTA.AA <- function (file) 
 {
-    if (length(grep("^(ht|f)tp:", file))) {
+    if (length(grep("^(ht|f)tp(s|):", file))) {
         url <- file
         file <- tempfile()
         download.file(url, file)
     }
-    sz <- file.info(file)$size
-    x <- readBin(file, "raw", sz)
-    icr <- which(x == as.raw(13))
-    if (length(icr)) 
-        x <- x[-icr]
+    if (is(file, "connection")) {
+        if (!isOpen(file, "rt")) {
+            open(file, "rt")
+            on.exit(close(file))
+        }
+        x <- scan(file, what = character(), sep = "\n", quiet = TRUE)
+        x <- charToRaw(paste(x, collapse = "\n"))
+        sz <- length(x)
+    } else {
+        sz <- file.size(file)
+        x <- readBin(file, "raw", sz)
+    }
+    ## if the file is larger than 1 Gb we assume that it is
+    ## UNIX-encoded and skip the search-replace of carriage returns
+    if (sz < 1e9) {
+        icr <- which(x == as.raw(0x0d)) # CR
+        if (length(icr)) x <- x[-icr]
+    }
     res <- .Call("rawStream2phyDat", x)
     
     aa <- c("a", "r", "n", "d", "c", "q", "e", "g", "h", "i", 
@@ -989,6 +1148,39 @@ read.FASTA.AA <- function (file)
 
 
 # throw out
+
+
+#' Read Amino Acid Sequences in a File
+#' 
+#' This function reads amino acid sequences in a file, and returns a matrix
+#' list of DNA sequences with the names of the taxa read in the file as row
+#' names.
+#' 
+#' 
+#' @param file a file name specified by either a variable of mode character, or
+#' a double-quoted string.
+#' @param format a character string specifying the format of the DNA sequences.
+#' Three choices are possible: \code{"interleaved"}, \code{"sequential"}, or
+#' \code{"fasta"}, or any unambiguous abbreviation of these.
+#' @param skip the number of lines of the input file to skip before beginning
+#' to read data.
+#' @param nlines the number of lines to be read (by default the file is read
+#' until its end).
+#' @param comment.char a single character, the remaining of the line after this
+#' character is ignored.
+#' @param seq.names the names to give to each sequence; by default the names
+#' read in the file are used.
+#' @return a matrix of amino acid sequences.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link[ape]{read.dna}}, \code{\link[ape]{read.GenBank}},
+#' \code{\link[phangorn]{phyDat}}, \code{\link[seqinr]{read.alignment}}
+#' @references % Anonymous. FASTA format description. %
+#' \url{https://www.ncbi.nlm.nih.gov/blast/fasta.shtml} Felsenstein, J. (1993)
+#' Phylip (Phylogeny Inference Package) version 3.5c. Department of Genetics,
+#' University of Washington.
+#' \url{http://evolution.genetics.washington.edu/phylip/phylip.html}
+#' @keywords IO
+#' @export read.aa
 read.aa <- function (file, format = "interleaved", skip = 0, nlines = 0, 
     comment.char = "#", seq.names = NULL) 
 {
@@ -1093,6 +1285,8 @@ read.aa <- function (file, format = "interleaved", skip = 0, nlines = 0,
 }
 
 
+#' @rdname phyDat
+#' @export
 genlight2phyDat <- function(x, ambiguity=NA){
     tmp <- as.matrix(x)
     lev <- na.omit(unique(as.vector(tmp)))
@@ -1100,6 +1294,9 @@ genlight2phyDat <- function(x, ambiguity=NA){
 }
 
 
+#' @rdname phyDat
+#' @method image phyDat
+#' @export
 image.phyDat <- function(x, ...){
     if(attr(x, "type")=="AA")image(as.AAbin(x), ...)
     if(attr(x, "type")=="DNA")image(as.DNAbin(x), ...)
diff --git a/R/phylo.R b/R/phylo.R
index 1d30607..9eee324 100644
--- a/R/phylo.R
+++ b/R/phylo.R
@@ -19,6 +19,8 @@ edgeLengthIndex <- function(child, parent, nTips){
 #
 # Maximum likelihood estimation
 #
+#' @rdname pml.fit
+#' @export
 discrete.gamma <- function (alpha, k) 
 {
     if (k == 1) return(1)
@@ -299,6 +301,8 @@ getP <- function(el, eig=edQt(), g=1.0){
 }
 
 
+#' @rdname pml.fit
+#' @export
 lli <- function (data, tree=NULL, ...) 
 {
     contrast <- attr(data, "contrast")
@@ -310,6 +314,8 @@ lli <- function (data, tree=NULL, ...)
 }
 
 
+#' @rdname pml.fit
+#' @export
 edQt <- function (Q = c(1, 1, 1, 1, 1, 1), bf = c(0.25, 0.25, 0.25, 0.25)) 
 {
     l = length(bf)
@@ -352,12 +358,16 @@ edQ2 <- function(Q){
 }
 
 
+#' @rdname pml.fit
+#' @export
 pml.free <- function(){
     .C("ll_free")
 #    rm(.INV, .iind, envir = parent.frame())
 }
 
 
+#' @rdname pml.fit
+#' @export
 pml.init <- function(data, k=1L){
     nTips <- length(data)
     nr <- attr(data, "nr")
@@ -698,6 +708,8 @@ phangornParseFormula <- function(model){
 }
 
 
+#' @rdname pml
+#' @export
 pml.control <- function (epsilon = 1e-08, maxit = 10, trace = 1) 
 {
     if (!is.numeric(epsilon) || epsilon <= 0) 
@@ -858,398 +870,6 @@ pml.move <- function(EDGE, el, data, g, w, eig, k, nTips, bf){
 }
 
 
-
-#
-# pmlPart + pmlCluster
-#
-optimPartQ <- function (object, Q = c(1, 1, 1, 1, 1, 1), ...) 
-{
-    l = length(Q)
-    Q = Q[-l]
-    Q = sqrt(Q)
-    fn = function(Q, object, ...) {
-        result <- 0
-        Q = c(Q^2, 1)
-        n <- length(object)
-        for (i in 1:n) result <- result + update(object[[i]], Q = Q, ...)$logLik
-        result
-    }
-    res = optim(par = Q, fn = fn, gr = NULL, method = "L-BFGS-B", 
-        lower = 0, upper = Inf, control = list(fnscale = -1, 
-            maxit = 25), object = object, ...)
-    res[[1]] = c(res[[1]]^2, 1)
-    res
-}
-
-
-optimPartQGeneral <- function (object, Q = c(1, 1, 1, 1, 1, 1), subs=rep(1,length(Q)), ...) 
-{
-    m = length(Q)
-    n = max(subs)
-    ab = numeric(n)
-    for(i in 1:n) ab[i]=log(Q[which(subs==i)[1]])
-    fn = function(ab, object, m, n, subs, ...) {
-        Q = numeric(m)
-        for(i in 1:n)Q[subs==i] = ab[i]
-        Q = exp(Q)
-        result = 0
-        for (i in 1:length(object)) result <- result + update(object[[i]], Q = Q, ...)$logLik
-        result
-    }
-    res = optim(par = ab, fn = fn, gr = NULL, method = "L-BFGS-B", 
-        lower = -Inf, upper = Inf, control = list(fnscale = -1, 
-            maxit = 25), object = object, m=m, n=n, subs=subs, ...)
-    Q = rep(1, m)
-    for(i in 1:n) Q[subs==i] = exp(res[[1]][i])
-    res[[1]] = Q
-    res
-}
-
-
-optimPartBf <- function (object, bf = c(0.25, 0.25, 0.25, 0.25), ...) 
-{
-    l = length(bf)
-    nenner = 1/bf[l]
-    lbf = log(bf * nenner)
-    lbf = lbf[-l]
-    fn = function(lbf, object, ...) {
-        result <- 0
-        bf = exp(c(lbf, 0))
-        bf = bf/sum(bf)
-        n <- length(object)
-        for (i in 1:n) result <- result + update(object[[i]], 
-            bf = bf, ...)$logLik
-        result
-    }
-    res = optim(par = lbf, fn = fn, gr = NULL, method = "Nelder-Mead", 
-        control = list(fnscale = -1, maxit = 500), object, ...)
-    print(res[[2]])
-    bf = exp(c(res[[1]], 0))
-    bf = bf/sum(bf)
-}
-
-
-optimPartInv <- function (object, inv = 0.01, ...) 
-{
-    fn = function(inv, object, ...) {
-        result <- 0
-        n <- length(object)
-        for (i in 1:n) result <- result + update(object[[i]], inv = inv, 
-            ...)$logLik
-        result
-    }
-    res = optimize(f = fn, interval = c(0, 1), lower = 0, upper = 1, 
-        maximum = TRUE, tol = 1e-04, object, ...)
-#    print(res[[2]])
-    res[[1]]
-}
-
-
-optimPartGamma <- function (object, shape = 1, ...) 
-{
-    fn = function(shape, object, ...) {
-        result <- 0
-        n <- length(object)
-        for (i in 1:n) result <- result + update(object[[i]], shape = shape, 
-            ...)$logLik
-        result
-    }    
-    res = optimize(f = fn, interval = c(0, 100), lower = 0, upper = 100, 
-        maximum = TRUE, tol = 0.01, object, ...)
-    res
-}
-
-
-dltmp <- function (fit, i=1, transform=transform) # i = weights
-{
-    tree = fit$tree 
-    data = getCols(fit$data, tree$tip.label) 
-    if (is.null(attr(tree, "order")) || attr(tree, "order") == 
-        "cladewise") 
-        tree <- reorder(tree, "postorder")
-    q = length(tree$tip.label)
-    node <- tree$edge[, 1]
-    edge <- tree$edge[, 2]
-    m = length(edge) + 1  # max(edge)
-    dat = vector(mode = "list", length = m)
-    eig = fit$eig
-    w = fit$w[i]
-    g = fit$g[i]
-    bf = fit$bf
-    el <- tree$edge.length
-    P <- getP(el, eig, g)
-    nr <- as.integer(attr(data, "nr"))
-    nc <- as.integer(attr(data, "nc"))
-    node = as.integer(node - min(node))
-    edge = as.integer(edge - 1)
-    nTips = as.integer(length(tree$tip.label))
-    mNodes = as.integer(max(node) + 1)
-    contrast = attr(data, "contrast")
-    nco = as.integer(dim(contrast)[1])
-    dat[(q + 1):m] <- .Call("LogLik2", data, P, nr, nc, node, edge, nTips, mNodes, contrast, nco)
-    result = dat[[q+1]] %*% (bf * w)
-
-    parent <- tree$edge[, 1]
-    child <- tree$edge[, 2]
-    nTips = min(parent) - 1
-    datp = vector("list", m)
-    el = tree$edge.length 
-    if (transform) dP = getdP(tree$edge.length, eig, g)
-    else dP = getdP2(tree$edge.length, eig, g)
-   
-    datp[(nTips + 1)] = dat[(nTips + 1)]
-    l = length(child)
-    dl = matrix(0, nr, l)
-    for (j in (m - 1):1) {
-        # tips have factor format, internal edges are matrices
-        if (child[j] > nTips){
-             tmp2 = (datp[[parent[j]]]/(dat[[child[j]]] %*% P[[j]]))
-             dl[, j] = (tmp2 * (dat[[child[j]]] %*% dP[[j]])) %*% (w * bf)
-             datp[[child[j]]] = (tmp2 %*% P[[j]]) * dat[[child[j]]]  
-             }
-        else{
-             tmp2 = (datp[[parent[j]]]/((contrast %*% P[[j]])[data[[child[j]]],] ))
-             dl[, j] = (tmp2 * ((contrast %*% dP[[j]])[data[[child[j]]],]) ) %*% (w * bf)    
-             }
-    }
-    dl
-}
-
-
-dl <- function(x, transform = TRUE){
-  w = x$w 
-  l=length(x$w)
-  dl = dltmp(x, 1, transform)
-  i=2
-  while(i < (l+1)){
-    dl = dl + dltmp(x, i, transform)
-    i = i + 1
-  } 
-  dl
-}
-
-
-# add control and change edge
-optimPartEdge <- function (object, ...) 
-{
-    tree <- object[[1]]$tree
-    theta <- object[[1]]$tree$edge.length
-    n <- length(object)
-    l <- length(theta)
-    nrv <- numeric(n)
-    for (i in 1:n) nrv[i] = attr(object[[i]]$data, "nr")
-    cnr <- cumsum(c(0, nrv))
-    weight = numeric(sum(nrv))
-    dl <- matrix(NA, sum(nrv), l)
-    for (i in 1:n) weight[(cnr[i] + 1):cnr[i + 1]] = attr(object[[i]]$data, 
-        "weight")
-    ll0 = 0
-    for (i in 1:n) ll0 = ll0 + object[[i]]$logLik
-    eps = 1
-    scalep =1
-    k = 1
-    while (eps > 0.001 & k<50) {
-        if(scalep==1){
-            for (i in 1:n) {
-                lv = drop(exp(object[[i]]$site))
-                dl[(cnr[i] + 1):cnr[i + 1], ] = dl(object[[i]], TRUE)/lv
-            }
-            sc = colSums(weight * dl)
-            F = crossprod(dl * weight, dl) + diag(l)*1e-10
-            # add small ridge penalty for numerical stability 
-        }
-        thetaNew = log(theta) + scalep * solve(F, sc)
-        tree$edge.length = as.numeric(exp(thetaNew))
-        for (i in 1:n) object[[i]] <- update(object[[i]], tree = tree)
-        ll1 = 0
-        for (i in 1:n) ll1 = ll1 + object[[i]]$logLik
-        eps <- ll1 - ll0
-        if (eps < 0 || is.nan(eps)) {
-            scalep = scalep/2
-            eps = 1
-            thetaNew = log(theta)
-            ll1 = ll0
-        }
-        else scalep = 1
-        theta = exp(thetaNew)
-        ll0 <- ll1
-        k=k+1
-    }
-    object
-}
-
-
-makePart <- function(fit, rooted, weight=~index+genes){
-    if(inherits(fit,"phyDat")){
-        x <- fit
-        dm <- dist.ml(x)
-        if(!rooted) tree <- NJ(dm)
-        else tree <- upgma(dm)
-        fit <- pml(tree, x, k=4)
-    }     
-    dat <- fit$data 
-    if(class(weight)[1]=="formula")     
-        weight <- xtabs(weight, data=attr(dat, "index"))
-    fits <- NULL 
-    for(i in 1:dim(weight)[2]){ 
-        ind <- which(weight[,i] > 0)
-        dat2 <- getRows(dat, ind)
-        attr(dat2, "weight") <- weight[ind,i]
-        fits[[i]] <- update(fit, data = dat2)
-    }
-    names(fits) = colnames(fits)
-    fits    
-}
-
-
-multiphyDat2pmlPart <- function(x, rooted=FALSE, ...){
-    fun <-  function(x, ...){
-        dm <- dist.ml(x)
-        if(!rooted) tree <- NJ(dm)
-        else tree <- upgma(dm)
-        fit <- pml(tree, x, ...)
-    }
-    fits <- lapply(x at seq, fun, ...)
-    fits
-}
-
-
-pmlPart2multiPhylo <- function(x){
-    res <- lapply(x$fits, FUN=function(x)x$tree)
-    class(res) <- "multiPhylo"
-    res
-}
-
-
-plot.pmlPart<- function(x, ...){
-    plot(pmlPart2multiPhylo(x), ...)
-}
-
-
-pmlPart <- function (formula, object, control=pml.control(epsilon=1e-8, maxit=10, trace=1), model=NULL, rooted=FALSE, ...) 
-{
-    call <- match.call()
-    form <- phangornParseFormula(formula)
-    opt <- c("nni", "bf", "Q", "inv", "shape", "edge", "rate")
-    optAll <- match(opt, form$left)
-    optPart <- match(opt, form$right)
-    AllNNI <- !is.na(optAll[1])
-    AllBf <- !is.na(optAll[2])
-    AllQ <- !is.na(optAll[3])
-    AllInv <- !is.na(optAll[4])
-    AllGamma <- !is.na(optAll[5])
-    AllEdge <- !is.na(optAll[6])
-    PartNni <- !is.na(optPart[1])
-    PartBf <- !is.na(optPart[2])
-    PartQ <- !is.na(optPart[3])
-    PartInv <- !is.na(optPart[4])
-    PartGamma <- !is.na(optPart[5])
-    PartEdge <- !is.na(optPart[6])
-    PartRate <- !is.na(optPart[7])
- 
-    if(PartNni) PartEdge <- TRUE
-    
-    if(inherits(object,"multiphyDat")){
-        if(AllNNI || AllEdge) object <- do.call(cbind.phyDat, object at seq)
-        else fits <- multiphyDat2pmlPart(object, rooted=rooted, ...)
-    } 
-    if(inherits(object,"pml")) fits <- makePart(object, rooted=rooted, ...) 
-    if(inherits(object,"phyDat")) fits <- makePart(object, rooted=rooted, ...)
-    if(inherits(object,"pmlPart")) fits <- object$fits
-    if(inherits(object,"list")) fits <- object
-
-
-    trace = control$trace
-    epsilon = control$epsilon
-    maxit = control$maxit
-
-    p <- length(fits)
- #   if(length(model)<p) model = rep(model, length = p)
-
-    m = 1
-    logLik = 0
-    for (i in 1:p) logLik = logLik + fits[[i]]$log
-    eps = 10
-    while (eps > epsilon & m < maxit) {
-        loli = 0
-        if(any(c(PartNni, PartBf, PartInv, PartQ, PartGamma, PartEdge, PartRate))){
-            for (i in 1:p) {
-                fits[[i]] = optim.pml(fits[[i]], optNni=PartNni, optBf=PartBf, 
-                    optQ=PartQ, optInv=PartInv, optGamma=PartGamma,  optEdge=PartEdge, 
-                    optRate=PartRate, optRooted=rooted,  
-                    control = pml.control(maxit = 3, epsilon = 1e-8, trace-1), model=model[i])
-            }
-        } 
-        if (AllQ) {
-            Q = fits[[1]]$Q
-            subs = c(1:(length(Q)-1), 0)
-            newQ <- optimPartQGeneral(fits, Q=Q, subs=subs)
-            for (i in 1:p) fits[[i]] <- update(fits[[i]], Q = newQ[[1]])
-        }
-        if (AllBf) {
-             bf = fits[[1]]$bf
-            newBf <- optimPartBf(fits, bf=bf)
-            for (i in 1:p) fits[[i]] <- update(fits[[i]], bf = newBf)
-        }
-        if (AllInv) {
-            inv = fits[[1]]$inv
-            newInv <- optimPartInv(fits, inv=inv)
-            for (i in 1:p) fits[[i]] <- update(fits[[i]], inv = newInv)
-        }
-        if (AllGamma) {
-            shape = fits[[1]]$shape
-            newGamma <- optimPartGamma(fits, shape=shape)[[1]]
-            for (i in 1:p) fits[[i]] <- update(fits[[i]], shape = newGamma)
-        }
-        if (AllNNI){
-            fits <- optimPartNNI(fits,AllEdge)
-            if(trace>0) cat(attr(fits,"swap"), " NNI operations performed")
-        }
-        if (AllEdge) 
-            fits <- optimPartEdge(fits)
-        if (PartRate){
-            tree = fits[[1]]$tree
-            rate=numeric(p)
-            wp =numeric(p) 
-            for(i in 1:p){
-                wp[i]=sum(fits[[i]]$weight)
-                rate[i] <- fits[[i]]$rate
-                }          
-            ratemult = sum(wp) / sum(wp*rate)
-            tree$edge.length = tree$edge.length/ratemult  
-            for(i in 1:p)fits[[i]] = update(fits[[i]], tree=tree, rate=rate[i]*ratemult)   
-        }
-        loli <- 0
-        for (i in 1:p) loli <- loli + fits[[i]]$log
-        eps = (logLik - loli)/loli
-        if(trace>0) cat("loglik:", logLik, "-->", loli, "\n")
-        logLik <- loli
-        m = m + 1
-    }
-    
-    df <- matrix(1, 6 ,2)
-    colnames(df) <- c("#df", "group")
-    rownames(df) <- c("Edge", "Shape", "Inv", "Bf", "Q", "Rate")
-    df[1,1] <- length(fits[[1]]$tree$edge.length)
-    df[2,1] <- fits[[1]]$k > 1
-    df[3,1] <- fits[[1]]$inv > 0
-    df[4,1] <- length(unique(fits[[1]]$bf)) - 1
-    df[5,1] <- length(unique(fits[[1]]$Q)) - 1
-    df[6,1] <- 0 # rates 
-    if(PartEdge) df[1,2] = p
-    if(PartGamma) df[2,2] = p
-    if(PartInv) df[3,2] = p
-    if(PartBf) df[4,2] = p
-    if(PartQ) df[5,2] = p
-    if(PartRate) df[6,1] = p-1     
-    attr(logLik, "df") = sum(df[,1]*df[,2])
-    object <- list(logLik = logLik, fits = fits, call = call, df=df)
-    class(object) <- "pmlPart" 
-    object
-}
-
-
-
 bip <- function (obj) 
 {
     if (is.null(attr(obj, "order")) || attr(obj, "order") == 
@@ -1273,6 +893,22 @@ bipart <- function(obj){
 }
 
 
+bip2 <- function(x) 
+{
+    x <- reorder(x, "postorder")
+    nTips <- as.integer(length(x$tip.label))
+    .Call('phangorn_bipCPP', PACKAGE = 'phangorn', x$edge, nTips)
+}
+
+
+bipart2 <- function(x) 
+{
+    x <- reorder(x, "postorder")
+    nTips <- as.integer(length(x$tip.label))
+    .Call('phangorn_bipartCPP', PACKAGE = 'phangorn', x$edge, nTips)
+}
+
+
 bipartition <- function (tree) 
 {
     if(is.rooted(tree))tree <- unroot(tree)
@@ -1296,256 +932,6 @@ bipartition <- function (tree)
 }
 
 
-
-pmlCluster.fit <- function (formula, fit, weight, p = 4, part = NULL, control=pml.control(epsilon=1e-8, maxit=10, trace=1), ...) 
-{
-    call <- match.call()
-    form <- phangornParseFormula(formula)
-    opt <- c("nni", "bf", "Q", "inv", "shape", "edge", "rate")
-    optAll <- match(opt, form$left)
-    optPart <- match(opt, form$right)
-    AllNNI <- !is.na(optAll[1])
-    AllBf <- !is.na(optAll[2])
-    AllQ <- !is.na(optAll[3])
-    AllInv <- !is.na(optAll[4])
-    AllGamma <- !is.na(optAll[5])
-    AllEdge <- !is.na(optAll[6])
-    PartNni <- !is.na(optPart[1])
-    PartBf <- !is.na(optPart[2])
-    PartQ <- !is.na(optPart[3])
-    PartInv <- !is.na(optPart[4])
-    PartGamma <- !is.na(optPart[5])
-    PartEdge <- !is.na(optPart[6])
-    PartRate <- !is.na(optPart[7])
-    if(PartNni) PartEdge <- TRUE
-    nrw <- dim(weight)[1]
-    ncw <- dim(weight)[2]
-    if (is.null(part)){ 
-        part = rep(1:p, length=ncw)
-        part = sample(part)
-        }
-    Part = part
-    Gtrees = vector("list", p)
-    dat <- fit$data
-    attr(fit$orig.data, "index") <- attr(dat, "index") <- NULL
-    for (i in 1:p) Gtrees[[i]] = fit$tree
-    fits = vector("list", p)
-    for (i in 1:p) fits[[i]] = fit
-    trace = control$trace
-    eps = 0
-    m = 1
-    logLik = fit$log
-    trees = list()
-    weights = matrix(0, nrw, p)
-    lls = matrix(0, nrw, p)
-    loli = fit$log
-    oldpart = part
-    eps2 = 1
-    iter = 0
-    swap = 1
-    while (eps < ncw || abs(eps2) > control$eps) {
-        df2 = 0
-        
-        if(any(c(PartNni, PartBf, PartInv, PartQ, PartGamma, PartEdge, PartRate))){
-            for (i in 1:p) {
-                weights[, i] = rowSums(weight[, which(part == i), 
-                    drop = FALSE])
-                ind <- which(weights[, i] > 0)
-                dat2 <- getRows(dat, ind)
-                attr(dat2, "weight") <- weights[ind, i]
-                fits[[i]] <- update(fits[[i]], data = dat2)
-                fits[[i]] = optim.pml(fits[[i]], PartNni, PartBf, 
-                    PartQ, PartInv, PartGamma, PartEdge, PartRate, 
-                    control = pml.control(epsilon = 1e-8, maxit = 3, trace-1))
-                lls[, i] = update(fits[[i]], data = dat)$site
-                Gtrees[[i]] = fits[[i]]$tree
-            }
-        }
-        if (AllQ) {
-            Q = fits[[1]]$Q
-            subs = c(1:(length(Q)-1), 0)
-            newQ <- optimPartQGeneral(fits, Q=Q, subs=subs)[[1]]
-            for (i in 1:p) fits[[i]] <- update(fits[[i]], Q = newQ)
-            df2 = df2 + length(unique(newQ)) - 1
-        }
-        if (AllBf) {
-	        bf = fits[[1]]$bf
-            newBf <- optimPartBf(fits, bf=bf)
-            for (i in 1:p) fits[[i]] <- update(fits[[i]], bf = newBf)
-            df2 = df2 + length(unique(newBf)) - 1
-        }
-        if (AllInv) {
-            inv = fits[[1]]$inv
-            newInv <- optimPartInv(fits, inv=inv)
-            for (i in 1:p) fits[[i]] <- update(fits[[i]], inv = newInv) #there was an Error
-            df2 = df2 + 1
-        }
-        if (AllGamma) {
-            shape = fits[[1]]$shape
-            newGamma <- optimPartGamma(fits, shape=shape)[[1]]        
-            for (i in 1:p) fits[[i]] <- update(fits[[i]], shape = newGamma)
-            df2 = df2 + 1
-        }
-        if (AllNNI) {
-            fits <- optimPartNNI(fits, AllEdge)
-            if(trace>0)cat(attr(fits, "swap"), " NNI operations performed")
-            swap <- attr(fits, "swap")
-        }
-        if (AllEdge) {
-            fits <- optimPartEdge(fits)
-            df2 = df2 + length(fits[[1]]$tree$edge.length)
-        }
-        if (PartRate) {
-            tree = fits[[1]]$tree
-            rate = numeric(p)
-            wp = numeric(p)
-            for (i in 1:p) {
-                wp[i] = sum(fits[[i]]$weight)
-                rate[i] <- fits[[i]]$rate
-            }
-            ratemult = sum(wp)/sum(wp * rate)
-            tree$edge.length = tree$edge.length/ratemult
-            for (i in 1:p) fits[[i]] = update(fits[[i]], tree = tree, 
-                rate = rate[i] * ratemult)
-        }
-        for (i in 1:p) lls[, i] = update(fits[[i]], data = dat)$site
-        trees[[m]] = Gtrees
-        LL = t(weight) %*% lls       
-# choose partitions which change        
-        tmp =(LL[cbind(1:ncw,part)] - apply(LL, 1, max))/colSums(weight)
-        fixi = numeric(p)
-        for(i in 1:p){
-            tmpi = which(part == i)
-            fixi[i] = tmpi[which.max(tmp[tmpi])]     
-            }
-        oldpart = part
-# restrict the number of elements changing groups 
-# If more than 25% would change, only the 25% with the highest increase per site change       
-        if( sum(tmp==0)/length(tmp) < .75){
-           medtmp = quantile(tmp, .25)
-           medind = which(tmp<=medtmp)
-           part[medind] = apply(LL[medind,], 1, which.max)
-           }
-        else part = apply(LL, 1, which.max)
-# force groups to have at least one member
-        part[fixi] = 1:p
-        Part = cbind(Part, part)
-        eps = sum(diag(table(part, oldpart)))
-        eps2 = loli
-        loli = sum(apply(LL, 1, max))
-        eps2 = (eps2 - loli)/loli
-        logLik = c(logLik, loli)
-        if(trace>0) print(loli)
-        Part = cbind(Part, part)
-        df2 = df2 + df2
-        if (eps == ncw & swap == 0) 
-            AllNNI = FALSE
-        m = m + 1
-        if (eps == ncw) 
-            iter = iter + 1
-        if (iter == 3) 
-            break
-    }
-    df <- matrix(1, 6, 2)
-    colnames(df) <- c("#df", "group")
-    rownames(df) <- c("Edge", "Shape", "Inv", "Bf", "Q", "Rate")
-    df[1, 1] <- length(fits[[1]]$tree$edge.length)
-    df[2, 1] <- fits[[1]]$k - 1
-    df[3, 1] <- fits[[1]]$inv > 0
-    df[4, 1] <- length(unique(fits[[1]]$bf)) - 1
-    df[5, 1] <- length(unique(fits[[1]]$Q)) - 1
-    df[6, 1] <- 0
-    if (PartEdge) 
-        df[1, 2] = p
-    if (PartGamma) 
-        df[2, 2] = p
-    if (PartInv) 
-        df[3, 2] = p
-    if (PartBf) 
-        df[4, 2] = p
-    if (PartQ) 
-        df[5, 2] = p
-    if (PartRate) 
-        df[6, 1] = p - 1
-    attr(logLik, "df") = sum(df[, 1] * df[, 2])
-    res = list(logLik = logLik, Partition = Part, trees = trees) # intermediate results
-    result <- list(logLik = loli, fits = fits, Partition = part, df = df, res = res, call = call)
-    class(result) <- c("pmlPart")
-    result
-}
-
-
-pmlCluster <- function (formula, fit, weight, p = 1:5, part = NULL, nrep = 10, control = pml.control(epsilon = 1e-08,
-   maxit = 10, trace = 1), ...)
-{
-   call <- match.call()
-   form <- phangornParseFormula(formula)
-   if(any(p==1)){
-       opt2 <- c("nni", "bf", "Q", "inv", "shape", "edge")
-       tmp1 <- opt2 %in% form$left
-       tmp1 <- tmp1 | (opt2 %in% form$right)
-       fit <- optim.pml(fit, tmp1[1], tmp1[2], tmp1[3], tmp1[4],
-       tmp1[5], tmp1[6])
-   }
-
-   p=p[p!=1]
-   if(length(p)==0)return(fit)
-   n = sum(weight)
-   k=2
-
-   BIC = matrix(0, length(p)+1, nrep)
-   BIC[1,] = AIC(fit, k = log(n))
-   LL = matrix(NA, length(p)+1, nrep)
-   LL[1,] = logLik(fit)
-
-   P = array(dim=c(length(p)+1, nrep, dim(weight)[2]))
-   tmpBIC = Inf
-   choice = c(1,1) 
-   for(j in p){
-       tmp=NULL
-       for(i in 1:nrep){
-           tmp = pmlCluster.fit(formula, fit, weight, p=j, part=part, control=control,...)
-           P[k,i,] = tmp$Partition
-           BIC[k,i] = AIC(tmp, k = log(n))
-           LL[k,i] = logLik(tmp)
-           if(BIC[k,i]<tmpBIC){
-                tmpBIC = BIC[k,i]
-                result = tmp
-                choice = c(k,i) 
-           }
-       }
-       k=k+1
-   }      
-
-   p = c(1,p)
-   result$choice = choice 
-   result$BIC = BIC
-   result$AllPartitions = P
-   result$AllLL = LL
-   result$p = p 
-   class(result) = c("pmlCluster", "pmlPart")
-   result
-}
-
-
-plot.pmlCluster <- function(x, which = c(1L:3L), caption = list("BIC", "log-likelihood", "Partitions"), ...){
-   show <- rep(FALSE, 3)
-   show[which] <- TRUE
-   choice = x$choice
-   if(show[1]){
-       X <- x$AllPartitions[choice[1],,]
-       d <- dim(X)
-       ind = order(X[choice[2],])
-       im  = matrix(0, d[2], d[2])
-       for(j in 1:d[1]){for(i in 1:d[2]) im[i,] = im[i,] + (X[j,] == X[j,i]) }
-       image(im[ind, ind], ...)
-   }
-
-   if(show[1])matplot(x$p, x$BIC, ylab="BIC", xlab="number of clusters")
-   if(show[1])matplot(x$p, x$AllLL, ylab="log-likelihood", xlab="number of clusters")
-}
-
-
 readAArate <- function(file){
     tmp <- read.table(system.file(file.path("extdata", file)), col.names = 1:20, fill=TRUE)
     Q <- tmp[1:19,1:19]
@@ -1811,438 +1197,9 @@ update.pml <- function (object, ...)
 }
 
 
-optimMixQ <- function(object, Q=c(1, 1, 1, 1, 1, 1), omega,...){
-    l = length(Q)
-    Q = Q[-l]
-    Q = sqrt(Q)
-    fn = function(Q, object, omega,...) {
-        Q = c(Q^2, 1)
-        weight <- object[[1]]$weight
-        n <- length(omega)
-        p <- length(weight)
-        result <- numeric(p)
-        for(i in 1:n)result <- result + as.numeric(update(object[[i]], Q=Q, ...)$lv) * omega[i]
-        result <- sum(weight %*% log(result))
-        result 
-    }
-    res = optim(par=Q, fn=fn, gr=NULL, method="L-BFGS-B", lower=0, 
-            upper=Inf, control=list(fnscale = -1, maxit=25), 
-            object=object, omega=omega,...)
-    res[[1]] = c(res[[1]]^2, 1)
-    res
-}
-
-
-optimMixBf <- function(object, bf=c(.25,.25,.25,.25), omega,...){
-    l = length(bf)
-    nenner = 1/bf[l]
-    lbf = log(bf * nenner)
-    lbf = lbf[-l]
-    fn = function(lbf, object, omega,...) {
-    bf = exp(c(lbf,0))
-    bf = bf/sum(bf)
-    weight <- object[[1]]$weight
-        n <- length(omega)
-        p <- length(weight)
-        result <- numeric(p)
-        for(i in 1:n)result <- result + as.numeric(update(object[[i]], bf=bf, ...)$lv) * omega[i]
-        result <- sum(weight %*% log(result))
-        result 
-    }
-    res = optim(par=lbf, fn=fn, gr=NULL, method="Nelder-Mead", 
-        control=list(fnscale=-1, maxit=500), object, omega=omega,...)
-#    print(res[[2]])
-    bf = exp(c(res[[1]],0))
-    bf = bf/sum(bf)
-}
-
-
-optimMixInv <- function(object, inv=0.01, omega,...){
-    fn = function(inv, object, omega,...) {
-        n <- length(omega)
-        weight <- object[[1]]$weight
-        p <- length(weight)
-        result <- numeric(p)
-         for(i in 1:n)result <- result + as.numeric(update(object, inv=inv, ...)$lv) * omega[i]
-        result <- sum(weight %*% log(result))
-        result 
-    }
-    res = optimize(f=fn, interval = c(0,1), lower = 0, upper = 1, maximum = TRUE,
-        tol = .0001, object, omega=omega,...)
-#    print(res[[2]]) 
-    res[[1]]
-}
-
-
-optimMixRate <- function (fits, ll, weight, omega, rate=rep(1,length(fits))) 
-{
-    r <- length(fits)
-    rate0 <- rate[-r]   
-
-    fn<-function(rate, fits, ll, weight, omega){
-        r <-  length(fits)
-        rate <- c(rate, (1- sum(rate *omega[-r]))/omega[r])
-        for (i in 1:r) fits[[i]]<-update(fits[[i]], rate = rate[i])
-        for (i in 1:r) ll[, i] <- fits[[i]]$lv
-        sum(weight*log(ll%*%omega)) 
-    }
-    ui=diag(r-1)
-    ui <- rbind(-omega[-r], ui)
-    ci <- c(-1, rep(0, r-1))
-    res <- constrOptim(rate0, fn, grad=NULL, ui=ui, ci=ci, mu = 1e-04, control = list(fnscale=-1),
-        method = "Nelder-Mead", outer.iterations = 50, outer.eps = 1e-05, fits=fits, ll=ll, weight=weight, omega=omega)
-    rate <- res[[1]]
-    res[[1]] <- c(rate, (1- sum(rate *omega[-r]))/omega[r])
-    res
-}
-
-
-optW <- function (ll, weight, omega,...) 
-{
-    k = length(omega)
-    nenner = 1/omega[1]
-    eta = log(omega * nenner)
-    eta = eta[-1]
-    fn = function(eta, ll, weight) {
-        eta = c(0,eta)
-        p = exp(eta)/sum(exp(eta))
-        res = sum(weight * log(ll %*% p)) 
-        res
-    }
-    if(k==2)res = optimize(f =fn , interval =c(-3,3) , lower = -3, upper = 3, maximum = TRUE, tol = .Machine$double.eps^0.25, ll = ll, weight = weight) 
-    else res = optim(eta, fn = fn, method = "L-BFGS-B", lower=-5, upper=5,control = list(fnscale = -1, 
-        maxit=25), gr = NULL, ll = ll, weight = weight)
-
-    p = exp(c(0,res[[1]]))
-    p = p/sum(p)
-    result = list(par = p, value = res[[2]])
-    result
-}
-
-
-optimMixEdge <- function(object, omega, trace=1,...){
-    tree <- object[[1]]$tree
-    theta <- object[[1]]$tree$edge.length
-    weight = as.numeric(attr(object[[1]]$data,"weight"))
-    n <- length(omega)
-    p <- length(weight)
-    q <- length(theta)
-    lv1 = numeric(p)
-    for(i in 1:n) lv1 = lv1 + as.numeric(object[[i]]$lv) * omega[i]
-    ll0 <- sum(weight * log(lv1))
-    eps=1
-    iter <- 0
-    scalep <- 1
-    if(trace>0) cat(ll0)
-    while(abs(eps)>.001 & iter<10){
-        dl <- matrix(0,p,q)
-        for(i in 1:n)dl <- dl + dl(object[[i]],TRUE) * omega[i]
-        dl <- dl/lv1
-        sc = colSums(weight * dl)
-        F = crossprod(dl * weight, dl)+diag(q)*1e-6
-        blub <- TRUE
-        iter2 <- 0
-        while(blub & iter2<10){
-        thetaNew = log(theta) + scalep * solve(F, sc)
-        tree$edge.length = as.numeric(exp(thetaNew))
-        for(i in 1:n)object[[i]] <- update(object[[i]],tree=tree)
-        lv1 = numeric(p)
-        for(i in 1:n) lv1 = lv1 + as.numeric(object[[i]]$lv)  * omega[i]
-        ll1 <- sum(weight * log(lv1))
-        eps <- ll1 - ll0     
-        if (eps < 0 || is.nan(eps)) {
-            scalep = scalep/2
-            eps = 1
-            thetaNew = log(theta)
-            ll1 = ll0
-            iter2 <- iter2+1
-        }
-        else{
-             scalep = 1;
-             theta = exp(thetaNew)  
-             blub=FALSE  
-            }     
-        }             
-        iter <- iter+1
-        ll0 <- ll1
-    }       
-    tree$edge.length <- theta
-    for(i in 1:n)object[[i]] <- update(object[[i]],tree=tree)
-    if(trace>0) cat("->", ll1, "\n")
-    object
-}
-
-
-pmlMix <- function (formula, fit, m = 2, omega = rep(1/m, m), control=pml.control(epsilon=1e-8, maxit=20, trace=1), ...) 
-{
-    call <- match.call()
-    form <- phangornParseFormula(formula)
-    opt <- c("nni", "bf", "Q", "inv", "shape", "edge", "rate")
-    optAll <- match(opt, form$left)
-    optPart <- match(opt, form$right)
-    AllBf <- !is.na(optAll[2])
-    AllQ <- !is.na(optAll[3])
-    AllInv <- !is.na(optAll[4])
-    AllGamma <- !is.na(optAll[5])
-    AllEdge <- !is.na(optAll[6])
-    MixNni <- !is.na(optPart[1])
-    MixBf <- !is.na(optPart[2])
-    MixQ <- !is.na(optPart[3])
-    MixInv <- !is.na(optPart[4])
-    MixGamma <- !is.na(optPart[5])
-    MixEdge <- !is.na(optPart[6])
-    MixRate <- !is.na(optPart[7])
-    if (inherits(fit,"list")) 
-        fits <- fit
-    else {
-        fits <- vector("list", m) 
-        for (i in 1:m) fits[[i]] <- fit
-    }
-    dat <- fits[[1]]$data
-    p = attr(dat, "nr")
-    weight = attr(dat, "weight")
-    r = m
-    ll = matrix(0, p, r)
-    for (i in 1:r) ll[, i] = fits[[i]]$lv
-
-    for (i in 1:r){
-         pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
-         fits[[i]] <- update(fits[[i]], llMix = pl0, wMix = omega[i])
-    }
-
-    if(MixRate) rate <- rep(1,r)
-
-    llstart = sum(weight * log(ll %*% omega))
-    llold <- llstart
-    ll0 <- llstart
-    ll3 <- llstart
-    eps0 <- 1
-    iter0 <- 0
-    trace = control$trace
-    while (eps0 > control$eps & iter0 < control$maxit) {  #while (eps0 > 1e-6 & iter0 < 20) {
-        eps1 <- 100
-        iter1 <- 0
-        
-        if (AllQ) {
-            newQ <- optimMixQ(fits, Q = fits[[1]]$Q, 
-                omega = omega)[[1]]
-            for (i in 1:m) fits[[i]] <- update(fits[[i]], Q = newQ)
-        }
-        if (AllBf) {
-            newBf <- optimMixBf(fits, bf = fits[[1]]$bf, 
-                omega = omega)
-            for (i in 1:m) fits[[i]] <- update(fits[[i]], bf = newBf)
-        }
-        if (AllInv) {
-            newInv <- optimMixInv(fits, inv = fits[[1]]$inv, 
-                omega = omega)
-            for (i in 1:m) fits[[i]] <- update(fits[[i]], Inv = newInv)
-        }
-        if (AllEdge) 
-            fits <- optimMixEdge(fits, omega, trace=trace-1)
-        for (i in 1:r) ll[, i] <- fits[[i]]$lv
-
-        while ( abs(eps1) > 0.001 & iter1 < 3) {
-             if(MixRate){
-                 rate <- optimMixRate(fits, ll, weight, omega, rate)[[1]]
-                 for (i in 1:r) fits[[i]] <- update(fits[[i]], rate=rate[i]) 
-                 for (i in 1:r) ll[, i] <- fits[[i]]$lv
-            }
-            for (i in 1:r){
-                pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
-                fits[[i]] <- update(fits[[i]], llMix = pl0, wMix = omega[i])
-            }
-
-            for (i in 1:r) {
-                pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
-                fits[[i]] <- optim.pml(fits[[i]], MixNni, MixBf, MixQ, MixInv, MixGamma, 
-                    MixEdge, optRate=FALSE, control = pml.control(epsilon = 1e-8, maxit = 3,
-                    trace-1), llMix = pl0, wMix = omega[i])
-                 ll[, i] <- fits[[i]]$lv 
-
-            res = optW(ll, weight, omega)
-               omega = res$p
-            
-            if(MixRate){
-                blub <- sum(rate*omega)
-                rate <- rate / blub 
-                tree <- fits[[1]]$tree
-                tree$edge.length <-   tree$edge.length*blub
-                for (i in 1:r) fits[[i]]<-update(fits[[i]], tree=tree, rate = rate[i])
-                for (i in 1:r) ll[, i] <- fits[[i]]$lv
-             }
-             for (i in 1:r){
-                 pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
-                 fits[[i]] <- update(fits[[i]], llMix = pl0, wMix = omega[i])
-             }
-             
-         }
-         ll1 = sum(weight * log(ll %*% omega))
-         res = optW(ll, weight, omega)
-         omega = res$p
-         if(MixRate){
-                blub <- sum(rate*omega)
-                rate <- rate / blub 
-                tree <- fits[[1]]$tree
-                tree$edge.length <-   tree$edge.length*blub
-                for (i in 1:r) fits[[i]]<-update(fits[[i]], tree=tree, rate = rate[i])
-                     if(trace>0) print(rate)
-                     for (i in 1:r) ll[, i] <- fits[[i]]$lv
-                }
-         for (i in 1:r){
-             pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
-             fits[[i]] <- update(fits[[i]], llMix = pl0, wMix = omega[i])
-        }
-
-        ll2 = sum(weight * log(ll %*% omega)) 
-        eps1 = llold - ll2
-        iter1 <- iter1 + 1
-        llold = ll2
-        }   
-
-        ll1 <- sum(weight * log(ll %*% omega))
-        eps0 <- (ll3 - ll1) / ll1
-        ll3 <- ll1
-        iter0 <- iter0 + 1
-        if(trace>0) print(iter0)
-    }
-    parameter <- c(AllBf=AllBf, AllQ=AllQ, AllInv=AllInv, AllGamma=AllGamma, AllEdge=AllEdge, MixNni=MixNni, 
-       MixBf=MixBf, MixQ=MixQ, MixInv=MixInv, MixGamma=MixGamma, MixEdge=MixEdge, MixRate=MixRate)
-    
-    df <- matrix(1, 6 ,2)
-    colnames(df) <- c("#df", "group")
-    rownames(df) <- c("Edge", "Shape", "Inv", "Bf", "Q", "Rate")
-    df[1,1] <- length(fits[[1]]$tree$edge.length)
-#    df[2,1] <- fits[[1]]$k - 1     
-    df[2,1] <- fits[[1]]$k > 1
-    df[3,1] <- fits[[1]]$inv > 0
-    df[4,1] <- length(unique(fits[[1]]$bf)) - 1
-    df[5,1] <- length(unique(fits[[1]]$Q)) - 1
-    df[6,1] <- 0  
-    if(MixEdge) df[1,2] = r
-    if(MixGamma) df[2,2] = r
-    if(MixInv) df[3,2] = r
-    if(MixBf) df[4,2] = r
-    if(MixQ) df[5,2] = r
-    if(MixRate) df[6,1] = r-1     
-    attr(logLik, "df") = sum(df[,1]*df[,2])
-    converge <- c(iter=iter0, eps=eps0)
-    result <- list(logLik = ll1, omega = omega, fits = fits, call = call, converge=converge, parameter=parameter, df=df)
-    class(result) <- "pmlMix"
-    result
-}
-
-
-print.pmlMix <- function(x,...){
-    nc <- attr(x$fits[[1]]$data, "nc")
-    nr <- attr(x$fits[[1]]$data, "nr")
-    levels <- attr(x$fits[[1]]$data, "levels")
-    r <- length(x$fits)   
-    w <- x$fits[[1]]$weight
-    w <- w[w>0] 
-    type <- attr(x$fits[[1]]$data, "type")
-    nc <- attr(x$fits[[1]]$data, "nc")
-    ll0 = sum(w*log(w/sum(w)))
-
-    
-    bf <- matrix(0,r,nc)
-    dimnames(bf) <- list(1:r, levels)
-    Q <- matrix(0, r, nc*(nc-1)/2)
-    dimnames(Q) <- list(1:r, NULL)
-
-    rate <- numeric(r)
-    inv <- x$fits[[1]]$inv
-    shape <- numeric(r)
-
-    for(i in 1:r){
-        bf[i, ] <- x$fits[[i]]$bf
-        Q[i, ] <- x$fits[[i]]$Q
-        rate[i] <- x$fits[[i]]$rate
-        shape[i] <- x$fits[[i]]$shape
-    }
-    cat("\nloglikelihood:", x$logLik, "\n")
-    cat("\nunconstrained loglikelihood:", ll0, "\n") 
-    cat("AIC: ", AIC(x), " BIC: ", AIC(x, k=log(nr)), "\n\n")
-    cat("\nposterior:", x$omega ,"\n")   
-    if(inv > 0)cat("Proportion of invariant sites:",inv,"\n")
-    cat("\nRates:\n")
-    cat(rate,"\n")
-    cat("\nBase frequencies:  \n")
-    print(bf)
-    cat("\nRate matrix:\n")
-    print(Q)
-}
-
-
-logLik.pmlMix <- function (object, ...) 
-{
-    res <- object$logLik
-    attr(res, "df") <- sum(object$df[,1] * object$df[,2])
-    class(res) <- "logLik"
-    res
-}
- 
-
-print.pmlPart <- function(x,...){
-    df <- x$df
-    nc <- attr(x$fits[[1]]$data, "nc")
-    levels <- attr(x$fits[[1]]$data, "levels")
-    r <- length(x$fits)   
-    nc <- attr(x$fits[[1]]$data, "nc")
-    nr <- attr(x$fits[[1]]$data, "nr")
-    k <- x$fits[[1]]$k    
-
-    lbf=x$df["Bf",2]
-    bf <- matrix(0, lbf, nc)
-    if(lbf>1)dimnames(bf) <- list(1:r, levels)
-    lQ = x$df["Q",2]
-    Q <- matrix(0, lQ, nc*(nc-1)/2)
-    if(lQ>1)dimnames(Q) <- list(1:r, NULL)
-    type <- attr(x$fits[[1]]$data, "type")
-    
-    loli <- numeric(r)
-    rate <- numeric(r)
-    shape <- numeric(r)
-    sizes <- numeric(r)
-    inv <- numeric(r)      
-    for(i in 1:r){
-        loli[i] <- x$fits[[i]]$logLik
-        if(i <= lbf)bf[i, ] <- x$fits[[i]]$bf
-        if(i <= lQ)Q[i, ] <- x$fits[[i]]$Q
-        rate[i] <- x$fits[[i]]$rate
-        shape[i] <- x$fits[[i]]$shape
-        inv[i] <- x$fits[[i]]$inv
-        sizes[i] <- sum(attr(x$fits[[i]]$data,"weight"))
-    }
-    cat("\nloglikelihood:", x$logLik, "\n")
-    cat("\nloglikelihood of partitions:\n ", loli, "\n")
-    cat("AIC: ", AIC(x), " BIC: ", AIC(x, k=log(sum(sizes))), "\n\n")    
-    cat("Proportion of invariant sites:",inv,"\n")
-    cat("\nRates:\n")
-    cat(rate,"\n")
-    if(k>1){
-        cat("\nShape parameter:\n") 
-        cat(shape,"\n")
-    }
-    if(type=="AA") cat("Rate matrix:",x$fits[[1]]$model, "\n")
-    else{
-        cat("\nBase frequencies:  \n")
-        print(bf)
-        cat("\nRate matrix:\n")
-        print(Q)
-    }
-}
-
-
-logLik.pmlPart <- function (object, ...) 
-{
-    res <- object$logLik
-    attr(res, "df") <- sum(object$df[,1] * object$df[,2])
-    class(res) <- "logLik"
-    res
-}
-
-
+#
+# pmlPen penalized ML
+#
 pmlPen <- function(object, lambda, ...){
     if(inherits(object,"pmlPart")) return(pmlPartPen(object, lambda,...))
     if(inherits(object,"pmlMix")) return(pmlMixPen(object, lambda,...))
@@ -2431,118 +1388,6 @@ optWPen = function (ll, weight, omega, pen, ...)
 } 
 
 
-optNNI <- function(fit, INDEX){    
-       tree = fit$tree
-       ll.0 <- fit$ll.0
-       loli <- fit$logLik
-       bf = fit$bf
-       eig = fit$eig
-       k = fit$k
-       w = fit$w
-       g = fit$g
-       rootEdges <- attr(INDEX, "root")
-       .dat <- NULL
-       parent = tree$edge[, 1]
-       child = tree$edge[, 2]
-             
-       data = getCols(fit$data, tree$tip.label)
-       datp <- rnodes(tree, data, w, g, eig, bf)       
-# nicht elegant, spaeter auch raus       
-       tmp = length(tree$tip.label)
-       for(i in 1:length(w)).dat[i,1:tmp]=new2old.phyDat(data)       
-       
-       evector <- numeric(max(parent))
-       evector[child] <- tree$edge.length
-       m <- dim(INDEX)[1]
-       k = min(parent)
-       loglik = numeric(2 * m)
-       edgeMatrix <- matrix(0, 2 * m, 5)
-       for (i in 1:m) {
-           ei = INDEX[i, ]
-           el0 = evector[INDEX[i, ]]
-           l = length(datp[, 1])
-           weight = fit$weight
-           datn = vector("list", 4 * l)
-           attr(datn, "dim") = c(l, 4)
-           datn <- .dat[, ei[1:4], drop = FALSE]
-           if (!(ei[5] %in% rootEdges)) 
-                datn[, 1] = datp[, ei[1], drop = FALSE]
-           new1 <- optim.quartet(el0[c(1, 3, 2, 4, 5)], 
-               eig, bf, datn[, c(1, 3, 2, 4), drop = FALSE], g, 
-               w, weight, ll.0, llcomp = fit$log)
-           new2 <- optim.quartet(el0[c(1, 4, 3, 2, 5)], 
-               eig, bf, datn[, c(1, 4, 3, 2), drop = FALSE], g, 
-               w, weight, ll.0, llcomp = fit$log)
-           loglik[(2 * i) - 1] = new1[[2]]
-           loglik[(2 * i)] = new2[[2]]
-           edgeMatrix[(2 * i) - 1, ] = new1[[1]]
-           edgeMatrix[(2 * i), ] = new2[[1]]
-           }
-       list(loglik=loglik, edges = edgeMatrix)
-       }
-
-
-optimPartNNI <- function (object, AllEdge=TRUE,...) 
-{
-    tree <- object[[1]]$tree
-    INDEX <- indexNNI(tree)   
-    l = length(object)
-    loglik0 = 0
-    for(i in 1:l)loglik0 = loglik0 + logLik(object[[i]])    
-    
-    l = length(object)
-    TMP=vector("list", l)
-    for(i in 1:l){
-        TMP[[i]] = optNNI(object[[i]], INDEX)
-        }
-    loglik=TMP[[1]][[1]] 
-    for(i in 2:l)loglik=loglik+TMP[[i]][[1]]
-
-    swap <- 0
-    candidates <- loglik > loglik0
-
-    while (any(candidates)) {
-        ind = which.max(loglik)
-        loglik[ind] = -Inf
-        if (ind%%2) 
-            swap.edge = c(2, 3)
-        else swap.edge = c(2, 4)
-        tree2 <- changeEdge(tree, INDEX[(ind + 1)%/%2, swap.edge], 
-            INDEX[(ind + 1)%/%2, ], TMP[[1]][[2]][ind, ])
-        tmpll = 0                 
-        for(i in 1:l){
-            if(!AllEdge)tree2 <- changeEdge(object[[i]]$tree, INDEX[(ind + 1)%/%2, swap.edge], 
-                INDEX[(ind + 1)%/%2, ], TMP[[i]][[2]][ind, ]) 
-            tmpll <- tmpll + update(object[[i]], tree = tree2)$logLik
-            }
-
-        if (tmpll < loglik0) 
-            candidates[ind] = FALSE
-        if (tmpll > loglik0) {
-
-            swap = swap + 1
-            tree <- tree2
-            indi <- which(rep(colSums(apply(INDEX, 1, match, 
-                INDEX[(ind + 1)%/%2, ], nomatch = 0)) > 0, each = 2))
-            candidates[indi] <- FALSE
-            loglik[indi] <- -Inf
-
-            for(i in 1:l){
-                if(!AllEdge)tree2 <- changeEdge(object[[i]]$tree, INDEX[(ind + 1)%/%2, swap.edge], 
-                    INDEX[(ind + 1)%/%2, ], TMP[[i]][[2]][ind, ]) 
-                object[[i]] <- update(object[[i]], tree = tree2)
-                }
-            loglik0 = 0
-            for(i in 1:l)loglik0 = loglik0 + logLik(object[[i]])    
-            cat(loglik0, "\n")
-        }
-    }
-    if(AllEdge)object <- optimPartEdge(object)
-    attr(object,"swap") = swap
-    object
-}
-
-
 ### this is the version we want to optimise
 pml.fit4 <- function (tree, data, bf = rep(1/length(levels), length(levels)), 
                           shape = 1, k = 1, Q = rep(1, length(levels) * (length(levels) - 1)/2), 
@@ -2619,6 +1464,48 @@ pml.fit4 <- function (tree, data, bf = rep(1/length(levels), length(levels)),
 
 
 
+
+
+#' Internal maximum likelihood functions.
+#' 
+#' These functions are internally used for the likelihood computations in
+#' \code{pml} or \code{optim.pml}.
+#' 
+#' These functions are exported to be used in different packages so far only in
+#' the package coalescentMCMC, but are not intended for end user. Most of the
+#' functions call C code and are far less forgiving if the import is not what
+#' they expect than \code{pml}.
+#' 
+#' @param tree A phylogenetic \code{tree}, object of class \code{phylo}.
+#' @param data An alignment, object of class \code{phyDat}.
+#' @param bf Base frequencies.
+#' @param shape Shape parameter of the gamma distribution.
+#' @param alpha Shape parameter of the gamma distribution.
+#' @param k Number of intervals of the discrete gamma distribution.
+#' @param Q A vector containing the lower triangular part of the rate matrix.
+#' @param levels The alphabet used e.g. c("a", "c", "g", "t") for DNA
+#' @param inv Proportion of invariable sites.
+#' @param rate Rate.
+#' @param g vector of quantiles (default is NULL)
+#' @param w vector of probabilities (default is NULL)
+#' @param eig Eigenvalue decomposition of Q
+#' @param INV Sparse representation of invariant sites
+#' @param ll.0 default is NULL
+#' @param llMix default is NULL
+#' @param wMix default is NULL
+#' @param \dots Further arguments passed to or from other methods.
+#' @param site return the log-likelihood or vector of sitewise likelihood
+#' values
+#' @return \code{pml.fit} returns the log-likelihood.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{pml}, \link{pmlPart}, \link{pmlMix}}
+#' @references Felsenstein, J. (1981) Evolutionary trees from DNA sequences: a
+#' maximum likelihood approach. \emph{Journal of Molecular Evolution},
+#' \bold{17}, 368--376.
+#' @keywords cluster
+#' 
+#' @rdname pml.fit
+#' @export pml.fit
 pml.fit <- function (tree, data, bf = rep(1/length(levels), length(levels)), 
                      shape = 1, k = 1, Q = rep(1, length(levels) * (length(levels) - 1)/2), 
                      levels = attr(data, "levels"), inv = 0, rate = 1, g = NULL, w = NULL, 
@@ -2705,6 +1592,183 @@ pml.fit <- function (tree, data, bf = rep(1/length(levels), length(levels)),
 }
 
 
+
+
+#' Likelihood of a tree.
+#' 
+#' \code{pml} computes the likelihood of a phylogenetic tree given a sequence
+#' alignment and a model. \code{optim.pml} optimizes the different model
+#' parameters.
+#' 
+#' The topology search uses a nearest neighbor interchange (NNI) and the
+#' implementation is similar to phyML.  The option model in pml is only used
+#' for amino acid models.  The option model defines the nucleotide model which
+#' is getting optimised, all models which are included in modeltest can be
+#' chosen. Setting this option (e.g. "K81" or "GTR") overrules options optBf
+#' and optQ.  Here is a overview how to estimate different phylogenetic models
+#' with \code{pml}: \tabular{lll}{ model \tab optBf \tab optQ \cr Jukes-Cantor
+#' \tab FALSE \tab FALSE \cr F81 \tab TRUE \tab FALSE \cr symmetric \tab FALSE
+#' \tab TRUE \cr GTR \tab TRUE \tab TRUE } Via model in optim.pml the following
+#' nucleotide models can be specified: JC, F81, K80, HKY, TrNe, TrN, TPM1, K81,
+#' TPM1u, TPM2, TPM2u, TPM3, TPM3u, TIM1e, TIM1, TIM2e, TIM2, TIM3e, TIM3,
+#' TVMe, TVM, SYM and GTR.  These models are specified as in Posada (2008).
+#' 
+#' So far 17 amino acid models are supported ("WAG", "JTT", "LG", "Dayhoff",
+#' "cpREV", "mtmam", "mtArt", "MtZoa", "mtREV24", "VT","RtREV", "HIVw", "HIVb",
+#' "FLU", "Blossum62", "Dayhoff_DCMut" and "JTT_DCMut") and additionally rate
+#' matrices and amino acid frequencies can be supplied.
+#' 
+#' It is also possible to estimate codon models (e.g. YN98), for details see
+#' also the chapter in vignette("phangorn-specials").
+#' 
+#' If the option 'optRooted' is set to TRUE than the edge lengths of rooted
+#' tree are optimized. The tree has to be rooted and by now ultrametric!
+#' Optimising rooted trees is generally much slower.
+#' 
+#' \code{pml.control} controls the fitting process. \code{epsilon} and
+#' \code{maxit} are only defined for the most outer loop, this affects
+#' \code{pmlCluster}, \code{pmlPart} and \code{pmlMix}.  \code{epsilon} is
+#' defined as (logLik(k)-logLik(k+1))/logLik(k+1), this seems to be a good
+#' heuristics which works reasonably for small and large trees or alignments.
+#' If \code{trace} is set to zero than no out put is shown, if functions are
+#' called internally than the trace is decreased by one, so a higher of trace
+#' produces more feedback.
+#' 
+#' If \code{rearrangement} is set to \code{stochastic} a stochastic search
+#' algorithm similar to Nguyen et al. (2015). and for \code{ratchet} the
+#' likelihood ratchet as in Vos (2003).  This should helps often to find better
+#' tree topologies, especially for larger trees.
+#' 
+#' @aliases pml 
+#' @param tree A phylogenetic \code{tree}, object of class \code{phylo}.
+#' @param data An alignment, object of class \code{phyDat}.
+#' @param bf Base frequencies.
+#' @param Q A vector containing the lower triangular part of the rate matrix.
+#' @param inv Proportion of invariable sites.
+#' @param k Number of intervals of the discrete gamma distribution.
+#' @param shape Shape parameter of the gamma distribution.
+#' @param rate Rate.
+#' @param model allows to choose an amino acid models or nucleotide model, see
+#' details.
+#' @param object An object of class \code{pml}.
+#' @param optNni Logical value indicating whether toplogy gets optimized (NNI).
+#' @param optBf Logical value indicating whether base frequencies gets
+#' optimized.
+#' @param optQ Logical value indicating whether rate matrix gets optimized.
+#' @param optInv Logical value indicating whether proportion of variable size
+#' gets optimized.
+#' @param optGamma Logical value indicating whether gamma rate parameter gets
+#' optimized.
+#' @param optEdge Logical value indicating the edge lengths gets optimized.
+#' @param optRate Logical value indicating the overall rate gets optimized.
+#' @param optRooted Logical value indicating if the edge lengths of a rooted
+#' tree get optimized.
+#' @param ratchet.par search parameter for stochastic search
+#' @param rearrangement type of tree tree rearrangements to perform, one of
+#' "none", "NNI", "stochastic" or "ratchet"
+#' @param control A list of parameters for controlling the fitting process.
+#' @param subs A (integer) vector same length as Q to specify the optimization
+#' of Q
+#' @param \dots Further arguments passed to or from other methods.
+#' @param epsilon Stop criterion for optimisation (see details).
+#' @param maxit Maximum number of iterations (see details).
+#' @param trace Show output during optimization (see details).
+#' @return \code{pml} or \code{optim.pml} return a list of class \code{pml},
+#' some are useful for further computations like \item{tree}{the phylogenetic
+#' tree.} \item{data}{the alignment.} \item{logLik}{Log-likelihood of the
+#' tree.} \item{siteLik}{Site log-likelihoods.} \item{weight}{Weight of the
+#' site patterns.}
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{bootstrap.pml}}, \code{\link{modelTest}},
+#' \code{\link{pmlPart}}, \code{\link{pmlMix}}, \code{\link{plot.phylo}},
+#' \code{\link{SH.test}}, \code{\link{ancestral.pml}}
+#' @references Felsenstein, J. (1981) Evolutionary trees from DNA sequences: a
+#' maximum likelihood approach. \emph{Journal of Molecular Evolution},
+#' \bold{17}, 368--376.
+#' 
+#' Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer Associates,
+#' Sunderland.
+#' 
+#' Yang, Z. (2006). \emph{Computational Molecular evolution}. Oxford University
+#' Press, Oxford.
+#' 
+#' Adachi, J., P. J. Waddell, W. Martin, and M. Hasegawa (2000) Plastid genome
+#' phylogeny and a model of amino acid substitution for proteins encoded by
+#' chloroplast DNA.  \emph{Journal of Molecular Evolution}, \bold{50}, 348--358
+#' 
+#' Rota-Stabelli, O., Z. Yang, and M. Telford. (2009) MtZoa: a general
+#' mitochondrial amino acid substitutions model for animal evolutionary
+#' studies. \emph{Mol. Phyl. Evol}, \bold{52(1)}, 268--72
+#' 
+#' Whelan, S. and Goldman, N. (2001) A general empirical model of protein
+#' evolution derived from multiple protein families using a maximum-likelihood
+#' approach. \emph{Molecular Biology and Evolution}, \bold{18}, 691--699
+#' 
+#' Le, S.Q. and Gascuel, O. (2008) LG: An Improved, General Amino-Acid
+#' Replacement Matrix \emph{Molecular Biology and Evolution}, \bold{25(7)},
+#' 1307--1320
+#' 
+#' Yang, Z., R. Nielsen, and M. Hasegawa (1998) Models of amino acid
+#' substitution and applications to Mitochondrial protein evolution.
+#' \emph{Molecular Biology and Evolution}, \bold{15}, 1600--1611
+#' 
+#' Abascal, F., D. Posada, and R. Zardoya (2007) MtArt: A new Model of amino
+#' acid replacement for Arthropoda. \emph{Molecular Biology and Evolution},
+#' \bold{24}, 1--5
+#' 
+#' Kosiol, C, and Goldman, N (2005) Different versions of the Dayhoff rate
+#' matrix - \emph{Molecular Biology and Evolution}, \bold{22}, 193--199
+#' 
+#' L.-T. Nguyen, H.A. Schmidt, A. von Haeseler, and B.Q. Minh (2015) IQ-TREE: A
+#' fast and effective stochastic algorithm for estimating maximum likelihood
+#' phylogenies. \emph{Molecular Biology and Evolution}, \bold{32}, 268--274.
+#' 
+#' Vos, R. A. (2003) Accelerated Likelihood Surface Exploration: The Likelihood
+#' Ratchet. \emph{Systematic Biology}, \bold{52(3)}, 368--373
+#' 
+#' Yang, Z., and R. Nielsen (1998) Synonymous and nonsynonymous rate variation
+#' in nuclear genes of mammals. \emph{Journal of Molecular Evolution},
+#' \bold{46}, 409-418.
+#' 
+#' Lewis, P.O. (2001) A likelihood approach to estimating phylogeny from
+#' discrete morphological character data. \emph{Systematic Biology} \bold{50},
+#' 913--925.
+#' @keywords cluster
+#' @examples
+#' 
+#'   example(NJ)
+#' # Jukes-Cantor (starting tree from NJ)  
+#'   fitJC <- pml(tree, Laurasiatherian)  
+#' # optimize edge length parameter     
+#'   fitJC <- optim.pml(fitJC)
+#'   fitJC 
+#'   
+#' \dontrun{    
+#' # search for a better tree using NNI rearrangements     
+#'   fitJC <- optim.pml(fitJC, optNni=TRUE)
+#'   fitJC   
+#'   plot(fitJC$tree)
+#' 
+#' # JC + Gamma + I - model
+#'   fitJC_GI <- update(fitJC, k=4, inv=.2)
+#' # optimize shape parameter + proportion of invariant sites     
+#'   fitJC_GI <- optim.pml(fitJC_GI, optGamma=TRUE, optInv=TRUE)
+#' # GTR + Gamma + I - model
+#'   fitGTR <- optim.pml(fitJC_GI, rearrangement = "stochastic", 
+#'       optGamma=TRUE, optInv=TRUE, model="GTR") 
+#' }
+#' 
+#' 
+#' # 2-state data (RY-coded)  
+#'   dat <- acgt2ry(Laurasiatherian) 
+#'   fit2ST <- pml(tree, dat) 
+#'   fit2ST <- optim.pml(fit2ST,optNni=TRUE) 
+#'   fit2ST
+#' # show some of the methods available for class pml
+#'   methods(class="pml")  
+#' 
+#' @rdname pml
+#' @export pml
 pml <- function (tree, data, bf = NULL, Q = NULL, inv = 0, k = 1, shape = 1, 
     rate = 1, model=NULL, ...) 
 {
@@ -3324,6 +2388,9 @@ addTips2Tree <- function (tree, tips, where){
 }    
 
 
+#' @rdname pml
+#' @aliases optim.pml
+#' @export
 optim.pml <- function (object, optNni = FALSE, optBf = FALSE, optQ = FALSE, 
                         optInv = FALSE, optGamma = FALSE, optEdge = TRUE, optRate = FALSE, optRooted=FALSE,
                         control = pml.control(epsilon = 1e-8, maxit = 10, trace = 1L), 
@@ -3391,6 +2458,14 @@ optim.pml <- function (object, optNni = FALSE, optBf = FALSE, optQ = FALSE,
             tree = multi2di(tree)
         optEdge = TRUE     
     }
+    if(length(tree$tip.label) < (3 + !optRooted) ){
+        optNni <- FALSE
+        ratchet <- FALSE
+        ratchet2 <- FALSE
+    } 
+    if(length(tree$tip.label) < (2 + !optRooted) ){
+        stop("rooted / unrooted tree needs at least 2 / 3 tips")
+    } 
     if(is.rooted(tree)) {
         if(optRooted==FALSE && optEdge==TRUE){
             tree = unroot(tree)
diff --git a/R/pmlMix.R b/R/pmlMix.R
new file mode 100644
index 0000000..a35fe43
--- /dev/null
+++ b/R/pmlMix.R
@@ -0,0 +1,463 @@
+#
+# pmlMix
+#
+optimMixQ <- function(object, Q=c(1, 1, 1, 1, 1, 1), omega,...){
+    l = length(Q)
+    Q = Q[-l]
+    Q = sqrt(Q)
+    fn = function(Q, object, omega,...) {
+        Q = c(Q^2, 1)
+        weight <- object[[1]]$weight
+        n <- length(omega)
+        p <- length(weight)
+        result <- numeric(p)
+        for(i in 1:n)result <- result + as.numeric(update(object[[i]], Q=Q, ...)$lv) * omega[i]
+        result <- sum(weight %*% log(result))
+        result 
+    }
+    res = optim(par=Q, fn=fn, gr=NULL, method="L-BFGS-B", lower=0, 
+                upper=Inf, control=list(fnscale = -1, maxit=25), 
+                object=object, omega=omega,...)
+    res[[1]] = c(res[[1]]^2, 1)
+    res
+}
+
+
+optimMixBf <- function(object, bf=c(.25,.25,.25,.25), omega,...){
+    l = length(bf)
+    nenner = 1/bf[l]
+    lbf = log(bf * nenner)
+    lbf = lbf[-l]
+    fn = function(lbf, object, omega,...) {
+        bf = exp(c(lbf,0))
+        bf = bf/sum(bf)
+        weight <- object[[1]]$weight
+        n <- length(omega)
+        p <- length(weight)
+        result <- numeric(p)
+        for(i in 1:n)result <- result + as.numeric(update(object[[i]], bf=bf, ...)$lv) * omega[i]
+        result <- sum(weight %*% log(result))
+        result 
+    }
+    res = optim(par=lbf, fn=fn, gr=NULL, method="Nelder-Mead", 
+                control=list(fnscale=-1, maxit=500), object, omega=omega,...)
+    #    print(res[[2]])
+    bf = exp(c(res[[1]],0))
+    bf = bf/sum(bf)
+}
+
+
+optimMixInv <- function(object, inv=0.01, omega,...){
+    fn = function(inv, object, omega,...) {
+        n <- length(omega)
+        weight <- object[[1]]$weight
+        p <- length(weight)
+        result <- numeric(p)
+        for(i in 1:n)result <- result + as.numeric(update(object, inv=inv, ...)$lv) * omega[i]
+        result <- sum(weight %*% log(result))
+        result 
+    }
+    res = optimize(f=fn, interval = c(0,1), lower = 0, upper = 1, maximum = TRUE,
+                   tol = .0001, object, omega=omega,...)
+    #    print(res[[2]]) 
+    res[[1]]
+}
+
+
+optimMixRate <- function (fits, ll, weight, omega, rate=rep(1,length(fits))) 
+{
+    r <- length(fits)
+    rate0 <- rate[-r]   
+    
+    fn<-function(rate, fits, ll, weight, omega){
+        r <-  length(fits)
+        rate <- c(rate, (1- sum(rate *omega[-r]))/omega[r])
+        for (i in 1:r) fits[[i]]<-update(fits[[i]], rate = rate[i])
+        for (i in 1:r) ll[, i] <- fits[[i]]$lv
+        sum(weight*log(ll%*%omega)) 
+    }
+    ui=diag(r-1)
+    ui <- rbind(-omega[-r], ui)
+    ci <- c(-1, rep(0, r-1))
+    res <- constrOptim(rate0, fn, grad=NULL, ui=ui, ci=ci, mu = 1e-04, control = list(fnscale=-1),
+                       method = "Nelder-Mead", outer.iterations = 50, outer.eps = 1e-05, fits=fits, ll=ll, weight=weight, omega=omega)
+    rate <- res[[1]]
+    res[[1]] <- c(rate, (1- sum(rate *omega[-r]))/omega[r])
+    res
+}
+
+
+optW <- function (ll, weight, omega,...) 
+{
+    k = length(omega)
+    nenner = 1/omega[1]
+    eta = log(omega * nenner)
+    eta = eta[-1]
+    fn = function(eta, ll, weight) {
+        eta = c(0,eta)
+        p = exp(eta)/sum(exp(eta))
+        res = sum(weight * log(ll %*% p)) 
+        res
+    }
+    if(k==2)res = optimize(f =fn , interval =c(-3,3) , lower = -3, upper = 3, maximum = TRUE, tol = .Machine$double.eps^0.25, ll = ll, weight = weight) 
+    else res = optim(eta, fn = fn, method = "L-BFGS-B", lower=-5, upper=5,control = list(fnscale = -1, 
+                                                                                         maxit=25), gr = NULL, ll = ll, weight = weight)
+    
+    p = exp(c(0,res[[1]]))
+    p = p/sum(p)
+    result = list(par = p, value = res[[2]])
+    result
+}
+
+
+optimMixEdge <- function(object, omega, trace=1,...){
+    tree <- object[[1]]$tree
+    theta <- object[[1]]$tree$edge.length
+    weight = as.numeric(attr(object[[1]]$data,"weight"))
+    n <- length(omega)
+    p <- length(weight)
+    q <- length(theta)
+    lv1 = numeric(p)
+    for(i in 1:n) lv1 = lv1 + as.numeric(object[[i]]$lv) * omega[i]
+    ll0 <- sum(weight * log(lv1))
+    eps=1
+    iter <- 0
+    scalep <- 1
+    if(trace>0) cat(ll0)
+    while(abs(eps)>.001 & iter<10){
+        dl <- matrix(0,p,q)
+        for(i in 1:n)dl <- dl + dl(object[[i]],TRUE) * omega[i]
+        dl <- dl/lv1
+        sc = colSums(weight * dl)
+        F = crossprod(dl * weight, dl)+diag(q)*1e-6
+        blub <- TRUE
+        iter2 <- 0
+        while(blub & iter2<10){
+            thetaNew = log(theta) + scalep * solve(F, sc)
+            tree$edge.length = as.numeric(exp(thetaNew))
+            for(i in 1:n)object[[i]] <- update(object[[i]],tree=tree)
+            lv1 = numeric(p)
+            for(i in 1:n) lv1 = lv1 + as.numeric(object[[i]]$lv)  * omega[i]
+            ll1 <- sum(weight * log(lv1))
+            eps <- ll1 - ll0     
+            if (eps < 0 || is.nan(eps)) {
+                scalep = scalep/2
+                eps = 1
+                thetaNew = log(theta)
+                ll1 = ll0
+                iter2 <- iter2+1
+            }
+            else{
+                scalep = 1;
+                theta = exp(thetaNew)  
+                blub=FALSE  
+            }     
+        }             
+        iter <- iter+1
+        ll0 <- ll1
+    }       
+    tree$edge.length <- theta
+    for(i in 1:n)object[[i]] <- update(object[[i]],tree=tree)
+    if(trace>0) cat("->", ll1, "\n")
+    object
+}
+
+
+
+
+#' Phylogenetic mixture model
+#' 
+#' Phylogenetic mixture model.
+#' 
+#' The \code{formula} object allows to specify which parameter get optimized.
+#' The formula is generally of the form \code{edge + bf + Q ~ rate + shape +
+#' \dots{}}, on the left side are the parameters which get optimized over all
+#' mixtures, on the right the parameter which are optimized specific to each
+#' mixture. The parameters available are \code{"nni", "bf", "Q", "inv",
+#' "shape", "edge", "rate"}.  Each parameters can be used only once in the
+#' formula.  \code{"rate"} and \code{"nni"} are only available for the right
+#' side of the formula. On the other hand parameters for invariable sites are
+#' only allowed on the left-hand side.  The convergence of the algorithm is
+#' very slow and is likely that the algorithm can get stuck in local optima.
+#' 
+#' @aliases pmlMix pmlPen
+#' @param formula a formula object (see details).
+#' @param fit an object of class \code{pml}.
+#' @param m number of mixtures.
+#' @param omega mixing weights.
+#' @param control A list of parameters for controlling the fitting process.
+#' @param \dots Further arguments passed to or from other methods.
+#' @return \code{pmlMix} returns a list with elements
+#' \item{logLik}{log-likelihood of the fit} \item{omega}{mixing weights.}
+#' \item{fits}{fits for the final mixtures.}
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{pml}},\code{\link{pmlPart}},\code{\link{pmlCluster}}
+#' @keywords cluster
+#' @examples
+#' 
+#' \dontrun{
+#' X <- allSitePattern(5)
+#' tree <- read.tree(text = "((t1:0.3,t2:0.3):0.1,(t3:0.3,t4:0.3):0.1,t5:0.5);")
+#' fit <- pml(tree,X, k=4)
+#' weights <- 1000*exp(fit$site) 
+#' attr(X, "weight") <- weights
+#' fit1 <- update(fit, data=X, k=1)
+#' fit2 <- update(fit, data=X)
+#' 
+#' (fitMixture <- pmlMix(edge~rate, fit1 , m=4))
+#' (fit2 <- optim.pml(fit2, optGamma=TRUE))
+#' 
+#' 
+#' data(Laurasiatherian)
+#' dm <- dist.logDet(Laurasiatherian)
+#' tree <- NJ(dm)
+#' fit=pml(tree, Laurasiatherian)
+#' fit = optim.pml(fit)
+#' 
+#' fit2 <- update(fit, k=4)
+#' fit2 <- optim.pml(fit2, optGamma=TRUE)
+#' 
+#' fitMix = pmlMix(edge ~ rate, fit, m=4)
+#' fitMix
+#' 
+#' 
+#' #
+#' # simulation of mixture models 
+#' #
+#' \dontrun{
+#' X <- allSitePattern(5)
+#' tree1 <- read.tree(text = "((t1:0.1,t2:0.5):0.1,(t3:0.1,t4:0.5):0.1,t5:0.5);")
+#' tree2 <- read.tree(text = "((t1:0.5,t2:0.1):0.1,(t3:0.5,t4:0.1):0.1,t5:0.5);")
+#' tree1 <- unroot(tree1)
+#' tree2 <- unroot(tree2)
+#' fit1 <- pml(tree1,X)
+#' fit2 <- pml(tree2,X)
+#' 
+#' weights <- 2000*exp(fit1$site) + 1000*exp(fit2$site)
+#' attr(X, "weight") <- weights
+#' 
+#' fit1 <- pml(tree1, X)
+#' fit2 <- optim.pml(fit1)
+#' logLik(fit2)
+#' AIC(fit2, k=log(3000))
+#' 
+#' fitMixEdge = pmlMix( ~ edge, fit1, m=2)
+#' logLik(fitMixEdge)
+#' AIC(fitMixEdge, k=log(3000))
+#' 
+#' fit.p <- pmlPen(fitMixEdge, .25)
+#' logLik(fit.p)
+#' AIC(fit.p, k=log(3000))
+#' }
+#' }
+#' 
+#' @export pmlMix
+pmlMix <- function (formula, fit, m = 2, omega = rep(1/m, m), control=pml.control(epsilon=1e-8, maxit=20, trace=1), ...) 
+{
+    call <- match.call()
+    form <- phangornParseFormula(formula)
+    opt <- c("nni", "bf", "Q", "inv", "shape", "edge", "rate")
+    optAll <- match(opt, form$left)
+    optPart <- match(opt, form$right)
+    AllBf <- !is.na(optAll[2])
+    AllQ <- !is.na(optAll[3])
+    AllInv <- !is.na(optAll[4])
+    AllGamma <- !is.na(optAll[5])
+    AllEdge <- !is.na(optAll[6])
+    MixNni <- !is.na(optPart[1])
+    MixBf <- !is.na(optPart[2])
+    MixQ <- !is.na(optPart[3])
+    MixInv <- !is.na(optPart[4])
+    MixGamma <- !is.na(optPart[5])
+    MixEdge <- !is.na(optPart[6])
+    MixRate <- !is.na(optPart[7])
+    if (inherits(fit,"list")) 
+        fits <- fit
+    else {
+        fits <- vector("list", m) 
+        for (i in 1:m) fits[[i]] <- fit
+    }
+    dat <- fits[[1]]$data
+    p = attr(dat, "nr")
+    weight = attr(dat, "weight")
+    r = m
+    ll = matrix(0, p, r)
+    for (i in 1:r) ll[, i] = fits[[i]]$lv
+    
+    for (i in 1:r){
+        pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
+        fits[[i]] <- update(fits[[i]], llMix = pl0, wMix = omega[i])
+    }
+    
+    if(MixRate) rate <- rep(1,r)
+    
+    llstart = sum(weight * log(ll %*% omega))
+    llold <- llstart
+    ll0 <- llstart
+    ll3 <- llstart
+    eps0 <- 1
+    iter0 <- 0
+    trace = control$trace
+    while (eps0 > control$eps & iter0 < control$maxit) {  #while (eps0 > 1e-6 & iter0 < 20) {
+        eps1 <- 100
+        iter1 <- 0
+        
+        if (AllQ) {
+            newQ <- optimMixQ(fits, Q = fits[[1]]$Q, 
+                              omega = omega)[[1]]
+            for (i in 1:m) fits[[i]] <- update(fits[[i]], Q = newQ)
+        }
+        if (AllBf) {
+            newBf <- optimMixBf(fits, bf = fits[[1]]$bf, 
+                                omega = omega)
+            for (i in 1:m) fits[[i]] <- update(fits[[i]], bf = newBf)
+        }
+        if (AllInv) {
+            newInv <- optimMixInv(fits, inv = fits[[1]]$inv, 
+                                  omega = omega)
+            for (i in 1:m) fits[[i]] <- update(fits[[i]], Inv = newInv)
+        }
+        if (AllEdge) 
+            fits <- optimMixEdge(fits, omega, trace=trace-1)
+        for (i in 1:r) ll[, i] <- fits[[i]]$lv
+        
+        while ( abs(eps1) > 0.001 & iter1 < 3) {
+            if(MixRate){
+                rate <- optimMixRate(fits, ll, weight, omega, rate)[[1]]
+                for (i in 1:r) fits[[i]] <- update(fits[[i]], rate=rate[i]) 
+                for (i in 1:r) ll[, i] <- fits[[i]]$lv
+            }
+            for (i in 1:r){
+                pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
+                fits[[i]] <- update(fits[[i]], llMix = pl0, wMix = omega[i])
+            }
+            
+            for (i in 1:r) {
+                pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
+                fits[[i]] <- optim.pml(fits[[i]], MixNni, MixBf, MixQ, MixInv, MixGamma, 
+                                       MixEdge, optRate=FALSE, control = pml.control(epsilon = 1e-8, maxit = 3,
+                                                                                     trace-1), llMix = pl0, wMix = omega[i])
+                ll[, i] <- fits[[i]]$lv 
+                
+                res = optW(ll, weight, omega)
+                omega = res$p
+                
+                if(MixRate){
+                    blub <- sum(rate*omega)
+                    rate <- rate / blub 
+                    tree <- fits[[1]]$tree
+                    tree$edge.length <-   tree$edge.length*blub
+                    for (i in 1:r) fits[[i]]<-update(fits[[i]], tree=tree, rate = rate[i])
+                    for (i in 1:r) ll[, i] <- fits[[i]]$lv
+                }
+                for (i in 1:r){
+                    pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
+                    fits[[i]] <- update(fits[[i]], llMix = pl0, wMix = omega[i])
+                }
+                
+            }
+            ll1 = sum(weight * log(ll %*% omega))
+            res = optW(ll, weight, omega)
+            omega = res$p
+            if(MixRate){
+                blub <- sum(rate*omega)
+                rate <- rate / blub 
+                tree <- fits[[1]]$tree
+                tree$edge.length <-   tree$edge.length*blub
+                for (i in 1:r) fits[[i]]<-update(fits[[i]], tree=tree, rate = rate[i])
+                if(trace>0) print(rate)
+                for (i in 1:r) ll[, i] <- fits[[i]]$lv
+            }
+            for (i in 1:r){
+                pl0 <- ll[, -i, drop = FALSE] %*% omega[-i]
+                fits[[i]] <- update(fits[[i]], llMix = pl0, wMix = omega[i])
+            }
+            
+            ll2 = sum(weight * log(ll %*% omega)) 
+            eps1 = llold - ll2
+            iter1 <- iter1 + 1
+            llold = ll2
+        }   
+        
+        ll1 <- sum(weight * log(ll %*% omega))
+        eps0 <- (ll3 - ll1) / ll1
+        ll3 <- ll1
+        iter0 <- iter0 + 1
+        if(trace>0) print(iter0)
+    }
+    parameter <- c(AllBf=AllBf, AllQ=AllQ, AllInv=AllInv, AllGamma=AllGamma, AllEdge=AllEdge, MixNni=MixNni, 
+                   MixBf=MixBf, MixQ=MixQ, MixInv=MixInv, MixGamma=MixGamma, MixEdge=MixEdge, MixRate=MixRate)
+    
+    df <- matrix(1, 6 ,2)
+    colnames(df) <- c("#df", "group")
+    rownames(df) <- c("Edge", "Shape", "Inv", "Bf", "Q", "Rate")
+    df[1,1] <- length(fits[[1]]$tree$edge.length)
+    #    df[2,1] <- fits[[1]]$k - 1     
+    df[2,1] <- fits[[1]]$k > 1
+    df[3,1] <- fits[[1]]$inv > 0
+    df[4,1] <- length(unique(fits[[1]]$bf)) - 1
+    df[5,1] <- length(unique(fits[[1]]$Q)) - 1
+    df[6,1] <- 0  
+    if(MixEdge) df[1,2] = r
+    if(MixGamma) df[2,2] = r
+    if(MixInv) df[3,2] = r
+    if(MixBf) df[4,2] = r
+    if(MixQ) df[5,2] = r
+    if(MixRate) df[6,1] = r-1     
+    attr(logLik, "df") = sum(df[,1]*df[,2])
+    converge <- c(iter=iter0, eps=eps0)
+    result <- list(logLik = ll1, omega = omega, fits = fits, call = call, converge=converge, parameter=parameter, df=df)
+    class(result) <- "pmlMix"
+    result
+}
+
+
+print.pmlMix <- function(x,...){
+    nc <- attr(x$fits[[1]]$data, "nc")
+    nr <- attr(x$fits[[1]]$data, "nr")
+    levels <- attr(x$fits[[1]]$data, "levels")
+    r <- length(x$fits)   
+    w <- x$fits[[1]]$weight
+    w <- w[w>0] 
+    type <- attr(x$fits[[1]]$data, "type")
+    nc <- attr(x$fits[[1]]$data, "nc")
+    ll0 = sum(w*log(w/sum(w)))
+    
+    
+    bf <- matrix(0,r,nc)
+    dimnames(bf) <- list(1:r, levels)
+    Q <- matrix(0, r, nc*(nc-1)/2)
+    dimnames(Q) <- list(1:r, NULL)
+    
+    rate <- numeric(r)
+    inv <- x$fits[[1]]$inv
+    shape <- numeric(r)
+    
+    for(i in 1:r){
+        bf[i, ] <- x$fits[[i]]$bf
+        Q[i, ] <- x$fits[[i]]$Q
+        rate[i] <- x$fits[[i]]$rate
+        shape[i] <- x$fits[[i]]$shape
+    }
+    cat("\nloglikelihood:", x$logLik, "\n")
+    cat("\nunconstrained loglikelihood:", ll0, "\n") 
+    cat("AIC: ", AIC(x), " BIC: ", AIC(x, k=log(nr)), "\n\n")
+    cat("\nposterior:", x$omega ,"\n")   
+    if(inv > 0)cat("Proportion of invariant sites:",inv,"\n")
+    cat("\nRates:\n")
+    cat(rate,"\n")
+    cat("\nBase frequencies:  \n")
+    print(bf)
+    cat("\nRate matrix:\n")
+    print(Q)
+}
+
+
+logLik.pmlMix <- function (object, ...) 
+{
+    res <- object$logLik
+    attr(res, "df") <- sum(object$df[,1] * object$df[,2])
+    class(res) <- "logLik"
+    res
+}
+
diff --git a/R/pmlPart.R b/R/pmlPart.R
new file mode 100644
index 0000000..b6d388f
--- /dev/null
+++ b/R/pmlPart.R
@@ -0,0 +1,933 @@
+#
+# pmlPart + pmlCluster
+#
+optimPartQGeneral <- function (object, Q = c(1, 1, 1, 1, 1, 1), subs=rep(1,length(Q)), ...) 
+{
+    m = length(Q)
+    n = max(subs)
+    ab = numeric(n)
+    for(i in 1:n) ab[i]=log(Q[which(subs==i)[1]])
+    fn = function(ab, object, m, n, subs, ...) {
+        Q = numeric(m)
+        for(i in 1:n)Q[subs==i] = ab[i]
+        Q = exp(Q)
+        result = 0
+        for (i in 1:length(object)) result <- result + update(object[[i]], Q = Q, ...)$logLik
+        result
+    }
+    res = optim(par = ab, fn = fn, gr = NULL, method = "L-BFGS-B", 
+                lower = -Inf, upper = Inf, control = list(fnscale = -1, 
+                                                          maxit = 25), object = object, m=m, n=n, subs=subs, ...)
+    Q = rep(1, m)
+    for(i in 1:n) Q[subs==i] = exp(res[[1]][i])
+    res[[1]] = Q
+    res
+}
+
+
+optimPartBf <- function (object, bf = c(0.25, 0.25, 0.25, 0.25), ...) 
+{
+    l = length(bf)
+    nenner = 1/bf[l]
+    lbf = log(bf * nenner)
+    lbf = lbf[-l]
+    fn = function(lbf, object, ...) {
+        result <- 0
+        bf = exp(c(lbf, 0))
+        bf = bf/sum(bf)
+        n <- length(object)
+        for (i in 1:n) result <- result + update(object[[i]], 
+                                                 bf = bf, ...)$logLik
+        result
+    }
+    res = optim(par = lbf, fn = fn, gr = NULL, method = "Nelder-Mead", 
+                control = list(fnscale = -1, maxit = 500), object, ...)
+    print(res[[2]])
+    bf = exp(c(res[[1]], 0))
+    bf = bf/sum(bf)
+}
+
+
+optimPartInv <- function (object, inv = 0.01, ...) 
+{
+    fn = function(inv, object, ...) {
+        result <- 0
+        n <- length(object)
+        for (i in 1:n) result <- result + update(object[[i]], inv = inv, 
+                                                 ...)$logLik
+        result
+    }
+    res = optimize(f = fn, interval = c(0, 1), lower = 0, upper = 1, 
+                   maximum = TRUE, tol = 1e-04, object, ...)
+    #    print(res[[2]])
+    res[[1]]
+}
+
+
+optimPartGamma <- function (object, shape = 1, ...) 
+{
+    fn = function(shape, object, ...) {
+        result <- 0
+        n <- length(object)
+        for (i in 1:n) result <- result + update(object[[i]], shape = shape, 
+                                                 ...)$logLik
+        result
+    }    
+    res = optimize(f = fn, interval = c(0, 100), lower = 0, upper = 100, 
+                   maximum = TRUE, tol = 0.01, object, ...)
+    res
+}
+
+
+dltmp <- function (fit, i=1, transform=transform) # i = weights
+{
+    tree = fit$tree 
+    data = getCols(fit$data, tree$tip.label) 
+    if (is.null(attr(tree, "order")) || attr(tree, "order") == 
+        "cladewise") 
+        tree <- reorder(tree, "postorder")
+    q = length(tree$tip.label)
+    node <- tree$edge[, 1]
+    edge <- tree$edge[, 2]
+    m = length(edge) + 1  # max(edge)
+    dat = vector(mode = "list", length = m)
+    eig = fit$eig
+    w = fit$w[i]
+    g = fit$g[i]
+    bf = fit$bf
+    el <- tree$edge.length
+    P <- getP(el, eig, g)
+    nr <- as.integer(attr(data, "nr"))
+    nc <- as.integer(attr(data, "nc"))
+    node = as.integer(node - min(node))
+    edge = as.integer(edge - 1)
+    nTips = as.integer(length(tree$tip.label))
+    mNodes = as.integer(max(node) + 1)
+    contrast = attr(data, "contrast")
+    nco = as.integer(dim(contrast)[1])
+    dat[(q + 1):m] <- .Call("LogLik2", data, P, nr, nc, node, edge, nTips, mNodes, contrast, nco)
+    result = dat[[q+1]] %*% (bf * w)
+    
+    parent <- tree$edge[, 1]
+    child <- tree$edge[, 2]
+    nTips = min(parent) - 1
+    datp = vector("list", m)
+    el = tree$edge.length 
+    if (transform) dP = getdP(tree$edge.length, eig, g)
+    else dP = getdP2(tree$edge.length, eig, g)
+    
+    datp[(nTips + 1)] = dat[(nTips + 1)]
+    l = length(child)
+    dl = matrix(0, nr, l)
+    for (j in (m - 1):1) {
+        # tips have factor format, internal edges are matrices
+        if (child[j] > nTips){
+            tmp2 = (datp[[parent[j]]]/(dat[[child[j]]] %*% P[[j]]))
+            dl[, j] = (tmp2 * (dat[[child[j]]] %*% dP[[j]])) %*% (w * bf)
+            datp[[child[j]]] = (tmp2 %*% P[[j]]) * dat[[child[j]]]  
+        }
+        else{
+            tmp2 = (datp[[parent[j]]]/((contrast %*% P[[j]])[data[[child[j]]],] ))
+            dl[, j] = (tmp2 * ((contrast %*% dP[[j]])[data[[child[j]]],]) ) %*% (w * bf)    
+        }
+    }
+    dl
+}
+
+
+dl <- function(x, transform = TRUE){
+    w = x$w 
+    l=length(x$w)
+    dl = dltmp(x, 1, transform)
+    i=2
+    while(i < (l+1)){
+        dl = dl + dltmp(x, i, transform)
+        i = i + 1
+    } 
+    dl
+}
+
+
+# add control and change edge
+optimPartEdge <- function (object, ...) 
+{
+    tree <- object[[1]]$tree
+    theta <- object[[1]]$tree$edge.length
+    n <- length(object)
+    l <- length(theta)
+    nrv <- numeric(n)
+    for (i in 1:n) nrv[i] = attr(object[[i]]$data, "nr")
+    cnr <- cumsum(c(0, nrv))
+    weight = numeric(sum(nrv))
+    dl <- matrix(NA, sum(nrv), l)
+    for (i in 1:n) weight[(cnr[i] + 1):cnr[i + 1]] = attr(object[[i]]$data, 
+                                                          "weight")
+    ll0 = 0
+    for (i in 1:n) ll0 = ll0 + object[[i]]$logLik
+    eps = 1
+    scalep =1
+    k = 1
+    while (eps > 0.001 & k<50) {
+        if(scalep==1){
+            for (i in 1:n) {
+                lv = drop(exp(object[[i]]$site))
+                dl[(cnr[i] + 1):cnr[i + 1], ] = dl(object[[i]], TRUE)/lv
+            }
+            sc = colSums(weight * dl)
+            F = crossprod(dl * weight, dl) + diag(l)*1e-10
+            # add small ridge penalty for numerical stability 
+        }
+        thetaNew = log(theta) + scalep * solve(F, sc)
+        tree$edge.length = as.numeric(exp(thetaNew))
+        for (i in 1:n) object[[i]] <- update(object[[i]], tree = tree)
+        ll1 = 0
+        for (i in 1:n) ll1 = ll1 + object[[i]]$logLik
+        eps <- ll1 - ll0
+        if (eps < 0 || is.nan(eps)) {
+            scalep = scalep/2
+            eps = 1
+            thetaNew = log(theta)
+            ll1 = ll0
+        }
+        else scalep = 1
+        theta = exp(thetaNew)
+        ll0 <- ll1
+        k=k+1
+    }
+    object
+}
+
+
+makePart <- function(fit, rooted, weight=~index+genes){
+    if(inherits(fit,"phyDat")){
+        x <- fit
+        dm <- dist.ml(x)
+        if(!rooted) tree <- NJ(dm)
+        else tree <- upgma(dm)
+        fit <- pml(tree, x, k=4)
+    }     
+    dat <- fit$data 
+    if(class(weight)[1]=="formula")     
+        weight <- xtabs(weight, data=attr(dat, "index"))
+    fits <- NULL 
+    for(i in 1:dim(weight)[2]){ 
+        ind <- which(weight[,i] > 0)
+        dat2 <- getRows(dat, ind)
+        attr(dat2, "weight") <- weight[ind,i]
+        fits[[i]] <- update(fit, data = dat2)
+    }
+    names(fits) = colnames(fits)
+    fits    
+}
+
+
+#' @rdname pmlPart
+#' @export
+multiphyDat2pmlPart <- function(x, rooted=FALSE,  ...){
+    shared_tree=TRUE
+    if(shared_tree){
+        concatenate_x <- do.call(cbind.phyDat, x at seq)
+        dm <- dist.ml(concatenate_x)
+        if(!rooted) tree <- NJ(dm)
+        else tree <- upgma(dm)
+    }
+    else tree <- NULL
+    fun <-  function(x, rooted=FALSE, tree, ...){
+        if(is.null(tree)){
+            dm <- dist.ml(x)
+            if(!rooted) tree <- NJ(dm)
+            else tree <- upgma(dm)
+        }
+        fit <- pml(tree, x, ...)
+    }
+    fits <- lapply(x at seq, fun, tree=tree, rooted=rooted, ...)
+    fits
+}
+
+
+#' @rdname pmlPart
+#' @export
+pmlPart2multiPhylo <- function(x){
+    res <- lapply(x$fits, FUN=function(x)x$tree)
+    class(res) <- "multiPhylo"
+    res
+}
+
+
+plot.pmlPart<- function(x, ...){
+    plot(pmlPart2multiPhylo(x), ...)
+}
+
+
+
+#' Partition model.
+#' 
+#' Model to estimate phylogenies for partitioned data.
+#' 
+#' The \code{formula} object allows to specify which parameter get optimized.
+#' The formula is generally of the form \code{edge + bf + Q ~ rate + shape +
+#' \dots{}}, on the left side are the parameters which get optimized over all
+#' partitions, on the right the parameter which are optimized specific to each
+#' partition. The parameters available are \code{"nni", "bf", "Q", "inv",
+#' "shape", "edge", "rate"}.  Each parameters can be used only once in the
+#' formula.  \code{"rate"} and \code{"nni"} are only available for the right
+#' side of the formula.
+#' 
+#' For partitions with different edge weights, but same topology, \code{pmlPen}
+#' can try to find more parsimonious models (see example).
+#' 
+#' \code{pmlPart2multiPhylo} is a convenience function to extract the trees out
+#' of a \code{pmlPart} object.
+#' 
+#' @aliases pmlPart 
+#' @param formula a formula object (see details).
+#' @param object an object of class \code{pml} or a list of objects of class
+#' \code{pml} .
+#' @param control A list of parameters for controlling the fitting process.
+#' @param model A vector containing the models containing a model for each
+#' partition.
+#' @param rooted Are the gene trees rooted (ultrametric) or unrooted.
+#' @param \dots Further arguments passed to or from other methods.
+#' @param x an object of class \code{pmlPart}
+#' @return \code{kcluster} returns a list with elements
+#' \item{logLik}{log-likelihood of the fit} \item{trees}{a list of all trees
+#' during the optimization.} \item{object}{an object of class \code{"pml"} or
+#' \code{"pmlPart"}}
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso
+#' \code{\link{pml}},\code{\link{pmlCluster}},\code{\link{pmlMix}},\code{\link{SH.test}}
+#' @keywords cluster
+#' @examples
+#' 
+#' data(yeast)
+#' dm <- dist.logDet(yeast)
+#' tree <- NJ(dm)
+#' fit <- pml(tree,yeast)
+#' fits <- optim.pml(fit)
+#' 
+#' weight=xtabs(~ index+genes,attr(yeast, "index"))[,1:10]
+#' 
+#' sp <- pmlPart(edge ~ rate + inv, fits, weight=weight)
+#' sp
+#' 
+#' \dontrun{
+#' sp2 <- pmlPart(~ edge + inv, fits, weight=weight)
+#' sp2
+#' AIC(sp2)
+#' 
+#' sp3 <- pmlPen(sp2, lambda = 2) 
+#' AIC(sp3)
+#' }
+#' 
+#' @rdname pmlPart
+#' @export pmlPart
+pmlPart <- function (formula, object, control=pml.control(epsilon=1e-8, maxit=10, trace=1), model=NULL, rooted=FALSE, ...) 
+{
+    call <- match.call()
+    form <- phangornParseFormula(formula)
+    opt <- c("nni", "bf", "Q", "inv", "shape", "edge", "rate")
+    optAll <- match(opt, form$left)
+    optPart <- match(opt, form$right)
+    AllNNI <- !is.na(optAll[1])
+    AllBf <- !is.na(optAll[2])
+    AllQ <- !is.na(optAll[3])
+    AllInv <- !is.na(optAll[4])
+    AllGamma <- !is.na(optAll[5])
+    AllEdge <- !is.na(optAll[6])
+    PartNni <- !is.na(optPart[1])
+    PartBf <- !is.na(optPart[2])
+    PartQ <- !is.na(optPart[3])
+    PartInv <- !is.na(optPart[4])
+    PartGamma <- !is.na(optPart[5])
+    PartEdge <- !is.na(optPart[6])
+    PartRate <- !is.na(optPart[7])
+    
+    if(PartNni) PartEdge <- TRUE
+    
+    if(inherits(object,"multiphyDat")){
+        if(AllNNI || AllEdge) object <- do.call(cbind.phyDat, object at seq)
+        else fits <- multiphyDat2pmlPart(object, rooted=rooted, ...)
+    } 
+    if(inherits(object,"pml")) fits <- makePart(object, rooted=rooted, ...) 
+    if(inherits(object,"phyDat")) fits <- makePart(object, rooted=rooted, ...)
+    if(inherits(object,"pmlPart")) fits <- object$fits
+    if(inherits(object,"list")) fits <- object
+    
+    
+    trace = control$trace
+    epsilon = control$epsilon
+    maxit = control$maxit
+    
+    p <- length(fits)
+    #   if(length(model)<p) model = rep(model, length = p)
+    
+    m = 1
+    logLik = 0
+    for (i in 1:p) logLik = logLik + fits[[i]]$log
+    eps = 10
+    while (eps > epsilon & m < maxit) {
+        loli = 0
+        if(any(c(PartNni, PartBf, PartInv, PartQ, PartGamma, PartEdge, PartRate))){
+            for (i in 1:p) {
+                fits[[i]] = optim.pml(fits[[i]], optNni=PartNni, optBf=PartBf, 
+                                      optQ=PartQ, optInv=PartInv, optGamma=PartGamma,  optEdge=PartEdge, 
+                                      optRate=PartRate, optRooted=rooted,  
+                                      control = pml.control(maxit = 3, epsilon = 1e-8, trace-1), model=model[i])
+            }
+        } 
+        if (AllQ) {
+            Q = fits[[1]]$Q
+            subs = c(1:(length(Q)-1), 0)
+            newQ <- optimPartQGeneral(fits, Q=Q, subs=subs)
+            for (i in 1:p) fits[[i]] <- update(fits[[i]], Q = newQ[[1]])
+        }
+        if (AllBf) {
+            bf = fits[[1]]$bf
+            newBf <- optimPartBf(fits, bf=bf)
+            for (i in 1:p) fits[[i]] <- update(fits[[i]], bf = newBf)
+        }
+        if (AllInv) {
+            inv = fits[[1]]$inv
+            newInv <- optimPartInv(fits, inv=inv)
+            for (i in 1:p) fits[[i]] <- update(fits[[i]], inv = newInv)
+        }
+        if (AllGamma) {
+            shape = fits[[1]]$shape
+            newGamma <- optimPartGamma(fits, shape=shape)[[1]]
+            for (i in 1:p) fits[[i]] <- update(fits[[i]], shape = newGamma)
+        }
+        if (AllNNI){
+            fits <- optimPartNNI(fits,AllEdge)
+            if(trace>0) cat(attr(fits,"swap"), " NNI operations performed")
+        }
+        if (AllEdge) 
+            fits <- optimPartEdge(fits)
+        if (PartRate){
+            tree = fits[[1]]$tree
+            rate=numeric(p)
+            wp =numeric(p) 
+            for(i in 1:p){
+                wp[i]=sum(fits[[i]]$weight)
+                rate[i] <- fits[[i]]$rate
+            }          
+            ratemult = sum(wp) / sum(wp*rate)
+            tree$edge.length = tree$edge.length/ratemult  
+            for(i in 1:p)fits[[i]] = update(fits[[i]], tree=tree, rate=rate[i]*ratemult)   
+        }
+        loli <- 0
+        for (i in 1:p) loli <- loli + fits[[i]]$log
+        eps = (logLik - loli)/loli
+        if(trace>0) cat("loglik:", logLik, "-->", loli, "\n")
+        logLik <- loli
+        m = m + 1
+    }
+    
+    df <- matrix(1, 6 ,2)
+    colnames(df) <- c("#df", "group")
+    rownames(df) <- c("Edge", "Shape", "Inv", "Bf", "Q", "Rate")
+    df[1,1] <- length(fits[[1]]$tree$edge.length)
+    df[2,1] <- fits[[1]]$k > 1
+    df[3,1] <- fits[[1]]$inv > 0
+    df[4,1] <- length(unique(fits[[1]]$bf)) - 1
+    df[5,1] <- length(unique(fits[[1]]$Q)) - 1
+    df[6,1] <- 0 # rates 
+    if(PartEdge) df[1,2] = p
+    if(PartGamma) df[2,2] = p
+    if(PartInv) df[3,2] = p
+    if(PartBf) df[4,2] = p
+    if(PartQ) df[5,2] = p
+    if(PartRate) df[6,1] = p-1     
+    attr(logLik, "df") = sum(df[,1]*df[,2])
+    object <- list(logLik = logLik, fits = fits, call = call, df=df)
+    class(object) <- "pmlPart" 
+    object
+}
+
+
+#
+# pmlCluster
+#
+
+
+pmlCluster.fit <- function (formula, fit, weight, p = 4, part = NULL, control=pml.control(epsilon=1e-8, maxit=10, trace=1), ...) 
+{
+    call <- match.call()
+    form <- phangornParseFormula(formula)
+    opt <- c("nni", "bf", "Q", "inv", "shape", "edge", "rate")
+    optAll <- match(opt, form$left)
+    optPart <- match(opt, form$right)
+    AllNNI <- !is.na(optAll[1])
+    AllBf <- !is.na(optAll[2])
+    AllQ <- !is.na(optAll[3])
+    AllInv <- !is.na(optAll[4])
+    AllGamma <- !is.na(optAll[5])
+    AllEdge <- !is.na(optAll[6])
+    PartNni <- !is.na(optPart[1])
+    PartBf <- !is.na(optPart[2])
+    PartQ <- !is.na(optPart[3])
+    PartInv <- !is.na(optPart[4])
+    PartGamma <- !is.na(optPart[5])
+    PartEdge <- !is.na(optPart[6])
+    PartRate <- !is.na(optPart[7])
+    if(PartNni) PartEdge <- TRUE
+    nrw <- dim(weight)[1]
+    ncw <- dim(weight)[2]
+    if (is.null(part)){ 
+        part = rep(1:p, length=ncw)
+        part = sample(part)
+    }
+    Part = part
+    Gtrees = vector("list", p)
+    dat <- fit$data
+    attr(fit$orig.data, "index") <- attr(dat, "index") <- NULL
+    for (i in 1:p) Gtrees[[i]] = fit$tree
+    fits = vector("list", p)
+    for (i in 1:p) fits[[i]] = fit
+    trace = control$trace
+    eps = 0
+    m = 1
+    logLik = fit$log
+    trees = list()
+    weights = matrix(0, nrw, p)
+    lls = matrix(0, nrw, p)
+    loli = fit$log
+    oldpart = part
+    eps2 = 1
+    iter = 0
+    swap = 1
+    while (eps < ncw || abs(eps2) > control$eps) {
+        df2 = 0
+        
+        if(any(c(PartNni, PartBf, PartInv, PartQ, PartGamma, PartEdge, PartRate))){
+            for (i in 1:p) {
+                weights[, i] = rowSums(weight[, which(part == i), 
+                                              drop = FALSE])
+                ind <- which(weights[, i] > 0)
+                dat2 <- getRows(dat, ind)
+                attr(dat2, "weight") <- weights[ind, i]
+                fits[[i]] <- update(fits[[i]], data = dat2)
+                fits[[i]] = optim.pml(fits[[i]], PartNni, PartBf, 
+                                      PartQ, PartInv, PartGamma, PartEdge, PartRate, 
+                                      control = pml.control(epsilon = 1e-8, maxit = 3, trace-1))
+                lls[, i] = update(fits[[i]], data = dat)$site
+                Gtrees[[i]] = fits[[i]]$tree
+            }
+        }
+        if (AllQ) {
+            Q = fits[[1]]$Q
+            subs = c(1:(length(Q)-1), 0)
+            newQ <- optimPartQGeneral(fits, Q=Q, subs=subs)[[1]]
+            for (i in 1:p) fits[[i]] <- update(fits[[i]], Q = newQ)
+            df2 = df2 + length(unique(newQ)) - 1
+        }
+        if (AllBf) {
+            bf = fits[[1]]$bf
+            newBf <- optimPartBf(fits, bf=bf)
+            for (i in 1:p) fits[[i]] <- update(fits[[i]], bf = newBf)
+            df2 = df2 + length(unique(newBf)) - 1
+        }
+        if (AllInv) {
+            inv = fits[[1]]$inv
+            newInv <- optimPartInv(fits, inv=inv)
+            for (i in 1:p) fits[[i]] <- update(fits[[i]], inv = newInv) #there was an Error
+            df2 = df2 + 1
+        }
+        if (AllGamma) {
+            shape = fits[[1]]$shape
+            newGamma <- optimPartGamma(fits, shape=shape)[[1]]        
+            for (i in 1:p) fits[[i]] <- update(fits[[i]], shape = newGamma)
+            df2 = df2 + 1
+        }
+        if (AllNNI) {
+            fits <- optimPartNNI(fits, AllEdge)
+            if(trace>0)cat(attr(fits, "swap"), " NNI operations performed")
+            swap <- attr(fits, "swap")
+        }
+        if (AllEdge) {
+            fits <- optimPartEdge(fits)
+            df2 = df2 + length(fits[[1]]$tree$edge.length)
+        }
+        if (PartRate) {
+            tree = fits[[1]]$tree
+            rate = numeric(p)
+            wp = numeric(p)
+            for (i in 1:p) {
+                wp[i] = sum(fits[[i]]$weight)
+                rate[i] <- fits[[i]]$rate
+            }
+            ratemult = sum(wp)/sum(wp * rate)
+            tree$edge.length = tree$edge.length/ratemult
+            for (i in 1:p) fits[[i]] = update(fits[[i]], tree = tree, 
+                                              rate = rate[i] * ratemult)
+        }
+        for (i in 1:p) lls[, i] = update(fits[[i]], data = dat)$site
+        trees[[m]] = Gtrees
+        LL = t(weight) %*% lls       
+        # choose partitions which change        
+        tmp =(LL[cbind(1:ncw,part)] - apply(LL, 1, max))/colSums(weight)
+        fixi = numeric(p)
+        for(i in 1:p){
+            tmpi = which(part == i)
+            fixi[i] = tmpi[which.max(tmp[tmpi])]     
+        }
+        oldpart = part
+        # restrict the number of elements changing groups 
+        # If more than 25% would change, only the 25% with the highest increase per site change       
+        if( sum(tmp==0)/length(tmp) < .75){
+            medtmp = quantile(tmp, .25)
+            medind = which(tmp<=medtmp)
+            part[medind] = apply(LL[medind,], 1, which.max)
+        }
+        else part = apply(LL, 1, which.max)
+        # force groups to have at least one member
+        part[fixi] = 1:p
+        Part = cbind(Part, part)
+        eps = sum(diag(table(part, oldpart)))
+        eps2 = loli
+        loli = sum(apply(LL, 1, max))
+        eps2 = (eps2 - loli)/loli
+        logLik = c(logLik, loli)
+        if(trace>0) print(loli)
+        Part = cbind(Part, part)
+        df2 = df2 + df2
+        if (eps == ncw & swap == 0) 
+            AllNNI = FALSE
+        m = m + 1
+        if (eps == ncw) 
+            iter = iter + 1
+        if (iter == 3) 
+            break
+    }
+    df <- matrix(1, 6, 2)
+    colnames(df) <- c("#df", "group")
+    rownames(df) <- c("Edge", "Shape", "Inv", "Bf", "Q", "Rate")
+    df[1, 1] <- length(fits[[1]]$tree$edge.length)
+    df[2, 1] <- fits[[1]]$k - 1
+    df[3, 1] <- fits[[1]]$inv > 0
+    df[4, 1] <- length(unique(fits[[1]]$bf)) - 1
+    df[5, 1] <- length(unique(fits[[1]]$Q)) - 1
+    df[6, 1] <- 0
+    if (PartEdge) 
+        df[1, 2] = p
+    if (PartGamma) 
+        df[2, 2] = p
+    if (PartInv) 
+        df[3, 2] = p
+    if (PartBf) 
+        df[4, 2] = p
+    if (PartQ) 
+        df[5, 2] = p
+    if (PartRate) 
+        df[6, 1] = p - 1
+    attr(logLik, "df") = sum(df[, 1] * df[, 2])
+    res = list(logLik = logLik, Partition = Part, trees = trees) # intermediate results
+    result <- list(logLik = loli, fits = fits, Partition = part, df = df, res = res, call = call)
+    class(result) <- c("pmlPart")
+    result
+}
+
+
+
+
+#' Stochastic Partitioning
+#' 
+#' Stochastic Partitioning of genes into p cluster.
+#' 
+#' The \code{formula} object allows to specify which parameter get optimized.
+#' The formula is generally of the form \code{edge + bf + Q ~ rate + shape +
+#' \dots{}}, on the left side are the parameters which get optimized over all
+#' cluster, on the right the parameter which are optimized specific to each
+#' cluster. The parameters available are \code{"nni", "bf", "Q", "inv",
+#' "shape", "edge", "rate"}.  Each parameter can be used only once in the
+#' formula.  There are also some restriction on the combinations how parameters
+#' can get used. \code{"rate"} is only available for the right side.  When
+#' \code{"rate"} is specified on the left hand side \code{"edge"} has to be
+#' specified (on either side), if \code{"rate"} is specified on the right hand
+#' side it follows directly that \code{edge} is too.
+#' 
+#' @param formula a formula object (see details).
+#' @param fit an object of class \code{pml}.
+#' @param weight \code{weight} is matrix of frequency of site patterns for all
+#' genes.
+#' @param p number of clusters.
+#' @param part starting partition, otherwise a random partition is generated.
+#' @param nrep number of replicates for each p.
+#' @param control A list of parameters for controlling the fitting process.
+#' @param \dots Further arguments passed to or from other methods.
+#' @return \code{pmlCluster} returns a list with elements
+#' \item{logLik}{log-likelihood of the fit} \item{trees}{a list of all trees
+#' during the optimization.} \item{fits}{fits for the final partitions}
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso
+#' \code{\link{pml}},\code{\link{pmlPart}},\code{\link{pmlMix}},\code{\link{SH.test}}
+#' @references K. P. Schliep (2009). Some Applications of statistical
+#' phylogenetics (PhD Thesis)
+#' 
+#' Lanfear, R., Calcott, B., Ho, S.Y.W. and Guindon, S. (2012) PartitionFinder:
+#' Combined Selection of Partitioning Schemes and Substitution Models for
+#' Phylogenetic Analyses. \emph{Molecular Biology and Evolution}, \bold{29(6)},
+#' 1695-1701
+#' @keywords cluster
+#' @examples
+#' 
+#' \dontrun{
+#' data(yeast)
+#' dm <- dist.logDet(yeast)
+#' tree <- NJ(dm)
+#' fit=pml(tree,yeast)
+#' fit = optim.pml(fit)
+#' 
+#' weight=xtabs(~ index+genes,attr(yeast, "index"))
+#' set.seed(1)
+#' 
+#' sp <- pmlCluster(edge~rate, fit, weight, p=1:4)
+#' sp
+#' SH.test(sp)
+#' }
+#' 
+#' @export pmlCluster
+pmlCluster <- function (formula, fit, weight, p = 1:5, part = NULL, nrep = 10, control = pml.control(epsilon = 1e-08,
+                                                                                                     maxit = 10, trace = 1), ...)
+{
+    call <- match.call()
+    form <- phangornParseFormula(formula)
+    if(any(p==1)){
+        opt2 <- c("nni", "bf", "Q", "inv", "shape", "edge")
+        tmp1 <- opt2 %in% form$left
+        tmp1 <- tmp1 | (opt2 %in% form$right)
+        fit <- optim.pml(fit, tmp1[1], tmp1[2], tmp1[3], tmp1[4],
+                         tmp1[5], tmp1[6])
+    }
+    
+    p=p[p!=1]
+    if(length(p)==0)return(fit)
+    n = sum(weight)
+    k=2
+    
+    BIC = matrix(0, length(p)+1, nrep)
+    BIC[1,] = AIC(fit, k = log(n))
+    LL = matrix(NA, length(p)+1, nrep)
+    LL[1,] = logLik(fit)
+    
+    P = array(dim=c(length(p)+1, nrep, dim(weight)[2]))
+    tmpBIC = Inf
+    choice = c(1,1) 
+    for(j in p){
+        tmp=NULL
+        for(i in 1:nrep){
+            tmp = pmlCluster.fit(formula, fit, weight, p=j, part=part, control=control,...)
+            P[k,i,] = tmp$Partition
+            BIC[k,i] = AIC(tmp, k = log(n))
+            LL[k,i] = logLik(tmp)
+            if(BIC[k,i]<tmpBIC){
+                tmpBIC = BIC[k,i]
+                result = tmp
+                choice = c(k,i) 
+            }
+        }
+        k=k+1
+    }      
+    
+    p = c(1,p)
+    result$choice = choice 
+    result$BIC = BIC
+    result$AllPartitions = P
+    result$AllLL = LL
+    result$p = p 
+    class(result) = c("pmlCluster", "pmlPart")
+    result
+}
+
+
+plot.pmlCluster <- function(x, which = c(1L:3L), caption = list("BIC", "log-likelihood", "Partitions"), ...){
+    show <- rep(FALSE, 3)
+    show[which] <- TRUE
+    choice = x$choice
+    if(show[1]){
+        X <- x$AllPartitions[choice[1],,]
+        d <- dim(X)
+        ind = order(X[choice[2],])
+        im  = matrix(0, d[2], d[2])
+        for(j in 1:d[1]){for(i in 1:d[2]) im[i,] = im[i,] + (X[j,] == X[j,i]) }
+        image(im[ind, ind], ...)
+    }
+    
+    if(show[1])matplot(x$p, x$BIC, ylab="BIC", xlab="number of clusters")
+    if(show[1])matplot(x$p, x$AllLL, ylab="log-likelihood", xlab="number of clusters")
+}
+
+
+
+print.pmlPart <- function(x,...){
+    df <- x$df
+    nc <- attr(x$fits[[1]]$data, "nc")
+    levels <- attr(x$fits[[1]]$data, "levels")
+    r <- length(x$fits)   
+    nc <- attr(x$fits[[1]]$data, "nc")
+    nr <- attr(x$fits[[1]]$data, "nr")
+    k <- x$fits[[1]]$k    
+    
+    lbf=x$df["Bf",2]
+    bf <- matrix(0, lbf, nc)
+    if(lbf>1)dimnames(bf) <- list(1:r, levels)
+    lQ = x$df["Q",2]
+    Q <- matrix(0, lQ, nc*(nc-1)/2)
+    if(lQ>1)dimnames(Q) <- list(1:r, NULL)
+    type <- attr(x$fits[[1]]$data, "type")
+    
+    loli <- numeric(r)
+    rate <- numeric(r)
+    shape <- numeric(r)
+    sizes <- numeric(r)
+    inv <- numeric(r)      
+    for(i in 1:r){
+        loli[i] <- x$fits[[i]]$logLik
+        if(i <= lbf)bf[i, ] <- x$fits[[i]]$bf
+        if(i <= lQ)Q[i, ] <- x$fits[[i]]$Q
+        rate[i] <- x$fits[[i]]$rate
+        shape[i] <- x$fits[[i]]$shape
+        inv[i] <- x$fits[[i]]$inv
+        sizes[i] <- sum(attr(x$fits[[i]]$data,"weight"))
+    }
+    cat("\nloglikelihood:", x$logLik, "\n")
+    cat("\nloglikelihood of partitions:\n ", loli, "\n")
+    cat("AIC: ", AIC(x), " BIC: ", AIC(x, k=log(sum(sizes))), "\n\n")    
+    cat("Proportion of invariant sites:",inv,"\n")
+    cat("\nRates:\n")
+    cat(rate,"\n")
+    if(k>1){
+        cat("\nShape parameter:\n") 
+        cat(shape,"\n")
+    }
+    if(type=="AA") cat("Rate matrix:",x$fits[[1]]$model, "\n")
+    else{
+        cat("\nBase frequencies:  \n")
+        print(bf)
+        cat("\nRate matrix:\n")
+        print(Q)
+    }
+}
+
+
+logLik.pmlPart <- function (object, ...) 
+{
+    res <- object$logLik
+    attr(res, "df") <- sum(object$df[,1] * object$df[,2])
+    class(res) <- "logLik"
+    res
+}
+
+
+
+optNNI <- function(fit, INDEX){    
+    tree = fit$tree
+    ll.0 <- fit$ll.0
+    loli <- fit$logLik
+    bf = fit$bf
+    eig = fit$eig
+    k = fit$k
+    w = fit$w
+    g = fit$g
+    rootEdges <- attr(INDEX, "root")
+    .dat <- NULL
+    parent = tree$edge[, 1]
+    child = tree$edge[, 2]
+    
+    data = getCols(fit$data, tree$tip.label)
+    datp <- rnodes(tree, data, w, g, eig, bf)       
+    # nicht elegant, spaeter auch raus       
+    tmp = length(tree$tip.label)
+    for(i in 1:length(w)).dat[i,1:tmp]=new2old.phyDat(data)       
+    
+    evector <- numeric(max(parent))
+    evector[child] <- tree$edge.length
+    m <- dim(INDEX)[1]
+    k = min(parent)
+    loglik = numeric(2 * m)
+    edgeMatrix <- matrix(0, 2 * m, 5)
+    for (i in 1:m) {
+        ei = INDEX[i, ]
+        el0 = evector[INDEX[i, ]]
+        l = length(datp[, 1])
+        weight = fit$weight
+        datn = vector("list", 4 * l)
+        attr(datn, "dim") = c(l, 4)
+        datn <- .dat[, ei[1:4], drop = FALSE]
+        if (!(ei[5] %in% rootEdges)) 
+            datn[, 1] = datp[, ei[1], drop = FALSE]
+        new1 <- optim.quartet(el0[c(1, 3, 2, 4, 5)], 
+                              eig, bf, datn[, c(1, 3, 2, 4), drop = FALSE], g, 
+                              w, weight, ll.0, llcomp = fit$log)
+        new2 <- optim.quartet(el0[c(1, 4, 3, 2, 5)], 
+                              eig, bf, datn[, c(1, 4, 3, 2), drop = FALSE], g, 
+                              w, weight, ll.0, llcomp = fit$log)
+        loglik[(2 * i) - 1] = new1[[2]]
+        loglik[(2 * i)] = new2[[2]]
+        edgeMatrix[(2 * i) - 1, ] = new1[[1]]
+        edgeMatrix[(2 * i), ] = new2[[1]]
+    }
+    list(loglik=loglik, edges = edgeMatrix)
+}
+
+
+optimPartNNI <- function (object, AllEdge=TRUE,...) 
+{
+    tree <- object[[1]]$tree
+    INDEX <- indexNNI(tree)   
+    l = length(object)
+    loglik0 = 0
+    for(i in 1:l)loglik0 = loglik0 + logLik(object[[i]])    
+    
+    l = length(object)
+    TMP=vector("list", l)
+    for(i in 1:l){
+        TMP[[i]] = optNNI(object[[i]], INDEX)
+    }
+    loglik=TMP[[1]][[1]] 
+    for(i in 2:l)loglik=loglik+TMP[[i]][[1]]
+    
+    swap <- 0
+    candidates <- loglik > loglik0
+    
+    while (any(candidates)) {
+        ind = which.max(loglik)
+        loglik[ind] = -Inf
+        if (ind%%2) 
+            swap.edge = c(2, 3)
+        else swap.edge = c(2, 4)
+        tree2 <- changeEdge(tree, INDEX[(ind + 1)%/%2, swap.edge], 
+                            INDEX[(ind + 1)%/%2, ], TMP[[1]][[2]][ind, ])
+        tmpll = 0                 
+        for(i in 1:l){
+            if(!AllEdge)tree2 <- changeEdge(object[[i]]$tree, INDEX[(ind + 1)%/%2, swap.edge], 
+                                            INDEX[(ind + 1)%/%2, ], TMP[[i]][[2]][ind, ]) 
+            tmpll <- tmpll + update(object[[i]], tree = tree2)$logLik
+        }
+        
+        if (tmpll < loglik0) 
+            candidates[ind] = FALSE
+        if (tmpll > loglik0) {
+            
+            swap = swap + 1
+            tree <- tree2
+            indi <- which(rep(colSums(apply(INDEX, 1, match, 
+                                            INDEX[(ind + 1)%/%2, ], nomatch = 0)) > 0, each = 2))
+            candidates[indi] <- FALSE
+            loglik[indi] <- -Inf
+            
+            for(i in 1:l){
+                if(!AllEdge)tree2 <- changeEdge(object[[i]]$tree, INDEX[(ind + 1)%/%2, swap.edge], 
+                                                INDEX[(ind + 1)%/%2, ], TMP[[i]][[2]][ind, ]) 
+                object[[i]] <- update(object[[i]], tree = tree2)
+            }
+            loglik0 = 0
+            for(i in 1:l)loglik0 = loglik0 + logLik(object[[i]])    
+            cat(loglik0, "\n")
+        }
+    }
+    if(AllEdge)object <- optimPartEdge(object)
+    attr(object,"swap") = swap
+    object
+}
+
+
diff --git a/R/read.nexus.splits.R b/R/read.nexus.splits.R
new file mode 100644
index 0000000..8f9556e
--- /dev/null
+++ b/R/read.nexus.splits.R
@@ -0,0 +1,483 @@
+## @aliases read.nexus.splits write.nexus.splits write.splits
+## read.nexus.networx write.nexus.networx
+
+#' Function to import and export splits and networks
+#' 
+#' \code{read.nexus.splits}, \code{write.nexus.splits}, \code{read.nexus.networx}, \code{write.nexus.networx} 
+#' can be used to import and export splits and networks with nexus format
+#' and allow to exchange these object with other software like Splitstree. 
+#' \code{write.splits} returns a human readable output. 
+#' 
+#' @param file a file name.
+#' @param obj An object of class splits.
+#' @param weights Edge weights.
+#' @param taxa logical. If TRUE a taxa block is added
+#' @param append logical. If TRUE the nexus blocks will be added to a file.
+#' @param splits logical. If TRUE the nexus blocks will be added to a file. 
+#' @param x An object of class splits.
+#' @param zero.print character which should be printed for zeros.
+#' @param one.print character which should be printed for ones.
+#' @param print.labels logical. If TRUE labels are printed.
+#' @param \dots Further arguments passed to or from other methods.
+#' @param labels names of taxa.
+#' @return \code{write.nexus.splits} and \code{write.nexus.networx} write out the  \code{splits} and \code{networx} object to read with
+#' other software like Splitstree.
+#' \code{read.nexus.splits} and \code{read.nexus.networx} return an \code{splits} and \code{networx} object. 
+#' @note \code{read.nexus.splits} reads in the splits block of a nexus file. It
+#' assumes that different co-variables are tab delimited and the bipartition
+#' are separated with white-space. Comments in square brackets are ignored.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{prop.part}}, \code{\link{lento}},
+#' \code{\link{as.splits}}, \code{\link{as.networx}}
+#' @keywords cluster
+#' @examples
+#' 
+#' (sp <- as.splits(rtree(5)))
+#' write.nexus.splits(sp)
+#' spl <- allCircularSplits(5)
+#' plot(as.networx(spl), "2D")
+#' write.splits(spl, print.labels = FALSE)
+#' 
+#' @rdname read.nexus.splits
+#' @export
+read.nexus.splits <- function(file)
+{
+    X <- scan(file = file, what = "", sep = "\n", quiet = TRUE)
+    semico <- grep(";", X)
+    X=gsub("\\[(.*?)\\]", "", X) # get rid of comments
+    i1 <- grep("TAXLABELS", X, ignore.case = TRUE)    
+    taxlab <- ifelse(length(i1)>0, TRUE, FALSE) 
+    if (taxlab) {
+        end <- semico[semico >= i1][1]
+        x <- X[(i1):end] # assumes not a 'new line' after "TRANSLATE"
+        x <- gsub("TAXLABELS", "", x, ignore.case = TRUE)
+        x <- unlist(strsplit(x, "[,; \t]"))   
+        x <- x[nzchar(x)]
+        x <- gsub("['\"]", "", x)
+        xntaxa <- length(x)
+    }
+    sp <- grep("SPLITS;", X, ignore.case = TRUE)
+    spEnd <- grep("END;", X, ignore.case = TRUE)
+    spEnd <- spEnd[spEnd>sp][1]
+    dims <- grep("DIMENSION", X, ignore.case = TRUE)
+    cyc <- grep("CYCLE", X, ignore.case = TRUE)
+    matr <- grep("MATRIX", X, ignore.case = TRUE)
+    format <- grep("FORMAT", X, ignore.case = TRUE)
+    start <- matr[matr>sp][1] + 1
+    end <- semico[semico>start][1] -1
+    format <- format[(format>sp) & (format<spEnd)]
+    
+    res <- vector("list", end - start + 1)
+    weights = numeric(end - start + 1)
+    j=1
+    
+    flab = fwei = fcon = fint = FALSE
+    
+    if(length(format)>0){
+        tmp = X[format]    
+        tmp = gsub("\\;", "", tmp)
+        tmp = gsub("\\s+", "", tmp)
+        flab = grepl("labels=left", tmp, ignore.case = TRUE) 
+        fwei = grepl("weights=yes", tmp, ignore.case = TRUE) 
+        fcon = grepl("confidences=yes", tmp, ignore.case = TRUE) 
+        fint = grepl("intervals=yes", tmp, ignore.case = TRUE) 
+        # = as.numeric(na.omit(as.numeric(strsplit(tmp, " ")[[1]])))        
+        ind = cumsum(c(flab, fwei, fcon, fint))
+        mformat = sum(c(flab, fwei, fcon, fint))
+    }
+    
+    if(fint)intervals = numeric(end - start + 1)
+    if(fcon)confidences = numeric(end - start + 1)
+    if(flab)labels = vector("character", end - start + 1)
+    
+    for(i in start:end){
+        tmp = X[i]
+        tmp = sub("\\s+", "", tmp) 
+        tmp = strsplit(tmp, "\t")[[1]]
+        if(flab){
+            labels[j] <- gsub("'", "", tmp[ind[1]]) %>% as.numeric
+            #            labels[j] = as.numeric(tmp[ind[1]])
+        }    
+        if(fwei)weights[j] = as.numeric(tmp[ind[2]])
+        if(fcon)confidences[j] = as.numeric(tmp[ind[3]])
+        if(fint)intervals[j] = as.numeric(tmp[ind[4]])
+        tmp = tmp[length(tmp)]
+        tmp = gsub("\\,", "", tmp)
+        res[[j]] = as.integer(na.omit(as.numeric(strsplit(tmp, " ")[[1]])))
+        j=j+1
+    }
+    if(length(cyc)>0){
+        tmp = X[cyc]    
+        tmp = gsub("\\;", "", tmp)
+        tmp = gsub("CYCLE", "", tmp, ignore.case = TRUE)
+        tmp = sub("\\s+", "", tmp)
+        cyc = as.integer(na.omit(as.numeric(strsplit(tmp, " ")[[1]])))
+    }
+    attr(res, "labels") = x
+    if(fwei)attr(res, "weights") = weights
+    if(fint)attr(res, "intervals") = intervals
+    if(fcon)attr(res, "confidences") = confidences
+    if(flab)attr(res, "splitlabels") = labels
+    attr(res, "cycle") = cyc 
+    class(res) = "splits"
+    res
+}
+
+
+
+#' @rdname read.nexus.splits
+#' @export
+write.nexus.splits <- function (obj, file = "", weights=NULL, taxa=TRUE, append=FALSE) 
+{
+    taxa.labels <- attr(obj, "labels")
+    ntaxa <- length(taxa.labels)
+    obj <- oneWise(obj, ntaxa)
+    ind <- which(lengths(obj)==ntaxa)
+    #    ind <- which(sapply(obj, length)==ntaxa)
+    if(length(ind))obj <- obj[-ind] 
+    nsplits <- length(obj)    
+    if(is.null(weights))weight <- attr(obj, "weights") 
+    if (is.null(weight)) fwei <- FALSE
+    else fwei <- TRUE
+    #    if (is.null(weight)) weight = numeric(nsplits) + 100
+    if(!append){cat("#NEXUS\n\n", file = file)
+        cat("[Splits block for Spectronet or Splitstree]\n", file = file, append = TRUE)
+        cat("[generated by phangorn:\n", file = file, append = TRUE)
+        cat(format(citation("phangorn"), "text"), "]\n\n",
+            file = file, append = TRUE)}
+    # TAXON BLOCK    
+    if(taxa){
+        cat(paste("BEGIN TAXA;\n\tDIMENSIONS ntax=", ntaxa, ";\n", 
+                  sep = ""), file = file, append = TRUE)
+        cat("\tTAXLABELS", paste(taxa.labels, sep = " "), ";\nEND;\n\n", 
+            file = file, append = TRUE)
+    }
+    # SPLITS BLOCK      
+    cat(paste("BEGIN SPLITS;\n\tDIMENSIONS ntax=", ntaxa, " nsplits=", nsplits,
+              ";\n", sep = ""), file = file, append = TRUE)     
+    format = "\tFORMAT labels=left" 
+    # weights=yes
+    if(fwei) format = paste(format, "weights=yes") 
+    else format = paste(format, "weights=no") 
+    fcon = fint = flab = FALSE
+    if(!is.null(attr(obj, "confidences"))){ 
+        format = paste(format, "confidences=yes")
+        fcon=TRUE
+        conf = attr(obj, "confidences")
+        if(any(is.na(conf))){ 
+            conf[is.na(conf)] = 0
+            attr(obj, "confidences") = conf
+        }
+        if(storage.mode(conf) == "character"){ 
+            conf[conf==""] = "0"
+            attr(obj, "confidences") = conf
+        }
+    }
+    else format = paste(format, "confidences=no") 
+    if(!is.null(attr(obj, "intervals"))){ 
+        format = paste(format, "intervals=yes")
+        fint=TRUE
+    }
+    else format = paste(format, "intervals=no") 
+    if(!is.null(attr(obj, "splitlabels"))) flab=TRUE
+    format = paste(format, ";\n",  sep = "")
+    cat(format, file = file, append = TRUE)
+    if(!is.null(attr(obj, "cycle"))){
+        cycle <- paste(attr(obj, "cycle"), collapse = " ")
+        cat("\tCYCLE\t", cycle, ";\n", sep="", file = file, append = TRUE)
+    }
+    cat("\tMATRIX\n", file = file, append = TRUE)    
+    
+    for (i in 1:nsplits){
+        slab <- ifelse(flab, attr(obj, "splitlabels")[i], i)
+        swei <- ifelse(fwei, paste(weight[i], "\t"), "")
+        scon <- ifelse(fcon, paste(attr(obj, "confidences")[i], "\t"), "")
+        sint <- ifelse(fint, paste(attr(obj, "intervals")[i], "\t"), "")
+        #        cat("\t\t", slab, "\t", weight[i], "\t", scon, sint, paste(obj[[i]], collapse=" "), 
+        #            ",\n", file = file, append = TRUE, sep = "") 
+        cat("\t\t", slab, "\t", swei, scon, sint, paste(obj[[i]], collapse=" "), 
+            ",\n", file = file, append = TRUE, sep = "")      
+    }
+    cat("\t;\nEND;\n", file = file, append = TRUE)
+}
+
+
+#' @rdname read.nexus.splits
+#' @export
+write.nexus.networx <- function(obj, file = "", taxa=TRUE, splits=TRUE, append=FALSE){
+    if(!append){
+        cat("#NEXUS\n\n", file = file)
+        cat("[Network block for Spectronet or Splitstree]\n", file = file, append = TRUE)
+        cat("[generated by phangorn:\n", file = file, append = TRUE)
+        cat(format(citation("phangorn"), "text"), "]\n\n",
+            file = file, append = TRUE)
+    }
+    ntaxa <- length(obj$tip.label)
+    # TAXON BLOCK    
+    if(taxa){
+        cat(paste("BEGIN TAXA;\n\tDIMENSIONS NTAX=", ntaxa, ";\n", 
+                  sep = ""), file = file, append = TRUE)
+        if(splits)taxalabel <- attr(obj$splits, "labels")
+        else taxalabel <- obj$tip.label
+        cat("\tTAXLABELS", paste(taxalabel, sep = " "), ";\nEND;\n\n", 
+            file = file, append = TRUE)
+    }
+    # SPLITS BLOCK    
+    spl <- obj$splits
+    if(splits){
+        #        spl <- changeOrder(spl, obj$tip.label) # orderSplitLabel
+        write.nexus.splits(spl, file = file, weights=NULL, append = TRUE, taxa=FALSE) 
+    }
+    nvertices <- max(obj$edge)
+    
+    #    if(is.null(attr(obj, "coords")))   
+    if(is.null(obj$.plot$vertices)) vertices <- coords(obj, "2D")
+    else vertices <- obj$.plot$vertices
+    
+    # y-axis differs between R and SplitsTree
+    vertices[,2] <- -vertices[,2]
+    
+    if(is.null(obj$.plot)) edge.col <- obj$.plot$edge.color 
+    else edge.col=NULL 
+    nedges <- nrow(obj$edge)
+    # NETWORK BLOCK
+    cat(paste("BEGIN NETWORK;\nDIMENSIONS ntax=", ntaxa,
+              "\tnvertices=", nvertices, "\tnedges=", nedges,";\n", sep = ""), file = file, append = TRUE)  
+    cat("DRAW to_scale;\n", file = file, append = TRUE)
+    cat("TRANSLATE\n", file = file, append = TRUE)
+    if(is.null(obj$translate)){
+        for(i in 1:ntaxa){
+            cat(i, " ", obj$tip.label[i], ",\n", sep="", file = file, append = TRUE)
+        }
+    }
+    else {
+        translate <- obj$translate
+        for(i in 1:length(translate$label)){
+            cat(translate$node[i], " ", translate$label[i], ",\n", sep="", file = file, append = TRUE)
+        }        
+    }
+    cat(";\nVERTICES\n", file = file, append = TRUE)
+    for(i in 1:nvertices){
+        cat(i, "\t", vertices[i,1], "\t", vertices[i,2], ",\n", sep="", file = file, append = TRUE)
+    }
+    if(!is.null(obj$tip.label)){
+        cat(";\nVLABELS\n", file = file, append = TRUE)
+        if(is.null(obj$translate)){    
+            for(i in 1:ntaxa){
+                cat(i, "\t", obj$tip.label[i], ",\n", sep="", file = file, append = TRUE)
+            }
+        }
+        else{
+            for(i in 1:length(translate$node)){
+                cat(translate$node[i], " ", translate$label[i], ",\n", sep="", file = file, append = TRUE)
+            }           
+        }     
+    }    
+    # cnet$splitIndex if splits = TRUE    
+    cat(";\nEDGES\n", file = file, append = TRUE)
+    
+    if(is.null(obj$.plot$edge.color)) edge.col="black"
+    else edge.col <- obj$.plot$edge.color
+    if(length(edge.col)<nedges) edge.col <- rep(edge.col, length=nedges) 
+    
+    splI <- TRUE
+    if(is.null(obj$splitIndex))splI <- FALSE
+    for(i in 1:nedges){
+        ecoli = edge.col[i]
+        spInd <- ifelse(splI, paste("\ts=", obj$splitIndex[i], sep=""), "")
+        edgeCol <- ifelse(ecoli=="black", "", paste("\tfg=", paste(col2rgb(ecoli), collapse=" "), sep=""))
+        cat(i, "\t", obj$edge[i,1], "\t", obj$edge[i,2], spInd, edgeCol, ",\n", sep="", file = file, append = TRUE)
+    }
+    cat(";\n", file = file, append = TRUE)
+    cat("END;\n", file = file, append = TRUE)
+    # force SplitsTree to accept the file    
+    cat("\nBEGIN st_Assumptions;\n    uptodate;\nEND; [st_Assumptions]\n", file = file, append = TRUE)
+}
+
+
+#' @rdname read.nexus.splits
+#' @export
+read.nexus.networx <- function(file, splits=TRUE){
+    spl <- NULL
+    if(splits)spl <-read.nexus.splits(file)
+    
+    X <- scan(file = file, what = "", sep = "\n", quiet = TRUE)
+    semico <- grep(";", X)
+    X=gsub("\\[(.*?)\\]", "", X) # get rid of comments
+    
+    netStart <- grep("BEGIN NETWORK;", X, ignore.case = TRUE)
+    netEnd <- grep("END;", X, ignore.case = TRUE)
+    netEnd <- netEnd[netEnd>netStart][1]
+    dims <- grep("DIMENSION", X, ignore.case = TRUE)
+    dims <- dims[(dims>netStart) & (dims<netEnd)]
+    
+    ntaxa = 0
+    nvertices = 0 
+    nedges = 0
+    
+    if(length(dims)>0){
+        tmp = X[dims]    
+        tmp = gsub("\\s+", "", tmp)
+        
+        ntaxa <- as.numeric(sub("(.+?)(ntax\\s*\\=\\s*)(\\d+)(.+)", 
+                                "\\3", tmp, perl = TRUE, ignore.case = TRUE))
+        nvertices  <- as.numeric(sub("(.+?)(nvertices\\s*\\=\\s*)(\\d+)(.+)", 
+                                     "\\3", tmp, perl = TRUE, ignore.case = TRUE))
+        nedges <- as.numeric(sub("(.+?)(nedges\\s*\\=\\s*)(\\d+)(.+)", 
+                                 "\\3", tmp, perl = TRUE, ignore.case = TRUE))
+    }
+    transl <- grep("TRANSLATE", X, ignore.case = TRUE)
+    translation <- if (length(transl) == 1 && transl > netStart) TRUE
+    else FALSE
+    translate.nodes <- FALSE
+    if (translation) {
+        end <- semico[semico > transl][1]
+        x <- X[(transl + 1):end]
+        x <- unlist(strsplit(x, "[,; \t]"))
+        x <- x[nzchar(x)]
+        x <- gsub("['\']", "", x)
+        if(length(x) == 2*ntaxa){
+            TRANS <- matrix(x, ncol = 2, byrow = TRUE)
+            TRANS[, 2] <- gsub("['\"]", "", TRANS[, 2])
+            TRANS <- list(node=as.numeric(TRANS[,1]), label=TRANS[,2])
+            #            translate.nodes <- TRUE
+        }
+        else{
+            #            TRANS <- matrix(NA, nrow = ntaxa, ncol = 2)
+            y <- as.numeric(x)
+            node <- numeric(ntaxa)
+            label <- character(ntaxa)
+            k=1
+            for(i in 1:length(x)){
+                if(!is.na(y[i])) tmp <- y[i]
+                else{
+                    node[k] <- tmp
+                    label[k] <- x[i]
+                    #                    TRANS[k, ] <- c(tmp, x[i])
+                    k=k+1
+                }
+                
+            }
+            TRANS <- list(node=node, label=label)
+        }    
+        #        n <- dim(TRANS)[1]
+    }
+    
+    
+    vert <- grep("VERTICES", X, ignore.case = TRUE)
+    start <- vert[vert>max(dims, netStart)][1] + 1
+    end <- semico[semico>start][1] -1
+    VERT <- matrix(0, nvertices, 3, dimnames = list(NULL, c("id", "x", "y")))
+    j=1
+    for(i in start:end){
+        tmp <- X[i]
+        #        tmp <- sub("\\s+", "", tmp) 
+        tmp <- gsub("\\,", "", tmp)  
+        tmp <- strsplit(tmp, "[[:space:]]")[[1]]
+        VERT[j,1] <- as.numeric(tmp[1]) 
+        VERT[j,2] <- as.numeric(tmp[2])
+        VERT[j,3] <- as.numeric(tmp[3])
+        j=j+1
+    }
+    
+    edges <- grep("EDGES", X, ignore.case = TRUE)
+    start <- edges[edges>max(dims, netStart)][1] + 1
+    end <- semico[semico>start][1] -1
+    EDGE <- NULL
+    if(splits) EDGE <- matrix(0, nedges, 4, dimnames = list(NULL, c("id", "vert_id_2", "vert_id_2", "splits_id")))
+    else EDGE <- matrix(0, nedges, 3, dimnames = list(NULL, c("id", "vert_id_2", "vert_id_2")))
+    j=1
+    for(i in start:end){
+        tmp <- X[i]
+        tmp <- gsub("\\,", "", tmp)
+        #        tmp <- sub("\\s+", "", tmp) 
+        tmp <- strsplit(tmp, "[[:space:]]")[[1]]
+        EDGE[j,1] <- as.numeric(tmp[1]) 
+        EDGE[j,2] <- as.numeric(tmp[2])
+        EDGE[j,3] <- as.numeric(tmp[3])
+        if(splits){
+            EDGE[j,4] <- as.numeric(sub("s=", "", tmp[4], ignore.case = TRUE))
+        }    
+        j=j+1
+    }
+    
+    swapEdge <- function(x, old, new) {
+        x[x==new] <- -1L
+        x[x==old] <- new
+        x[x==-1L] <- old
+        x     
+    }
+    swapRow <- function(x, old, new) {
+        tmp <- x[old,]
+        x[old,] <- x[new,]
+        x[new,] <- tmp
+        x     
+    }
+    splitIndex <- if(ncol(EDGE)==4) EDGE[,4]
+    else NULL
+    # quick and dirty   
+    el = sqrt(rowSums((VERT[EDGE[,2],c(2:3)] - VERT[EDGE[,3],c(2:3)])^2))
+    edge <- EDGE[,c(2:3)]
+    vert <- VERT[,c(2:3)]
+    
+    
+    if(translate.nodes){
+        #        oldLabel <- as.integer(as.numeric(TRANS[,1]))
+        oldLabel <- as.integer(TRANS$node)
+        for(i in 1:ntaxa){
+            edge <- swapEdge(edge, oldLabel[i], i) 
+            vert <- swapRow(vert, oldLabel[i], i)
+        }
+    }
+    dimnames(edge) <- NULL
+    # y-axis differs between in R and SplitsTree
+    vert[,2] <- -vert[,2]  
+    #    translate=data.frame(as.numeric(TRANS[,1]), TRANS[,2], stringsAsFactors=FALSE)
+    plot <- list(vertices=vert)        
+    obj <- list(edge=edge, tip.label=TRANS$label, edge.length=el, Nnode=max(edge)-ntaxa,
+                splitIndex=splitIndex, splits=spl, translate=TRANS) 
+    obj$.plot <- list(vertices = vert, edge.color="black", edge.width=3, edge.lty = 1)
+    class(obj) <- c("networx", "phylo")
+    reorder(obj)
+    obj
+}
+
+
+#' @rdname read.nexus.splits
+#' @export
+write.splits = function (x, file = "", zero.print = ".", one.print = "|", print.labels = TRUE, ...) 
+{
+    labels = attr(x, "labels")
+    x.orig <- x
+    cx <- as.matrix(x, zero.print = zero.print, one.print = one.print)
+    w = FALSE
+    if (!is.null(attr(x, "names"))) {
+        nam = TRUE
+        vnames = format(attr(x, "names"))
+    }
+    nam = FALSE
+    if (!is.null(attr(x, "weights"))) {
+        w = TRUE
+        weight = format(attr(x, "weights"))
+    }
+    d = FALSE
+    if (!is.null(attr(x, "data"))) {
+        d = TRUE
+        data = attr(x, "data")
+    }
+    if(print.labels){for(i in 1:length(labels)) cat(labels[i], "\n", file = file, append = TRUE)}
+    if (w) 
+        cat("weight", "\t", file = file, append = TRUE)
+    if (d) 
+        cat(paste(colnames(data), "\t"), file = file, append = TRUE)
+    cat("\n", file = file, append = TRUE) #"Matrix", 
+    for (i in 1:length(x)) {
+        if (nam) 
+            cat(vnames[i], "\t", file = file, append = TRUE)
+        if (d) 
+            cat(paste(data[i, ], "\t"), file = file, append = TRUE)
+        if (w) 
+            cat(weight[i], "\t", file = file)
+        cat("\n", paste(cx[i, ], collapse = ""),"\n",  file = file, append = TRUE)
+    }
+}
\ No newline at end of file
diff --git a/R/simSeq.R b/R/simSeq.R
index 8c9cb71..d73d0e3 100644
--- a/R/simSeq.R
+++ b/R/simSeq.R
@@ -1,14 +1,88 @@
-
 #
 # add codon models, change to phyDat statt 3* 
 #
+
+
+#' Simulate sequences.
+#' 
+#' Simulate sequences for a given evolutionary tree.
+#' 
+#' \code{simSeq} is now a generic function to simulate sequence alignments.  It
+#' is quite flexible and allows to generate DNA, RNA, amino acids or binary
+#' sequences.  It is possible to give a \code{pml} object as input simSeq
+#' return a \code{phyDat} from these model.  There is also a more low level
+#' version, which lacks rate variation, but one can combine different
+#' alignments having their own rate (see example). The rate parameter acts like
+#' a scaler for the edge lengths.
+#' 
+#' @param x a phylogenetic tree \code{tree}, i.e. an object of class
+#' \code{phylo} or and object of class \code{pml}.
+#' @param l length of the sequence to simulate.
+#' @param Q the rate matrix.
+#' @param bf base frequencies.
+#' @param rootseq a vector of length l containing the root sequence, other root
+#' sequence is randomly generated.
+#' @param type Type of sequences ("DNA", "AA" or "USER").
+#' @param model Amino acid models: e.g. "WAG", "JTT", "Dayhoff" or "LG"
+#' @param levels \code{levels} takes a character vector of the different bases,
+#' default is for nucleotide sequences, only used when type = "USER".
+#' @param rate mutation rate or scaler for the edge length, a numerical value
+#' greater than zero.
+#' @param ancestral Return ancestral sequences?
+#' @param \dots Further arguments passed to or from other methods.
+#' @return \code{simSeq} returns an object of class phyDat.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{phyDat}}, \code{\link{pml}}, \code{\link{SOWH.test}}
+#' @keywords cluster
+#' @examples
+#' 
+#' \dontrun{
+#' data(Laurasiatherian)
+#' tree = nj(dist.ml(Laurasiatherian))
+#' fit = pml(tree, Laurasiatherian, k=4)
+#' fit = optim.pml(fit, optNni=TRUE, model="GTR", optGamma=TRUE)
+#' data = simSeq(fit)
+#' }
+#' 
+#' tree = rtree(5)
+#' plot(tree)
+#' nodelabels()
+#' 
+#' # Example for simple DNA alignment
+#' data = simSeq(tree, l = 10, type="DNA", bf=c(.1,.2,.3,.4), Q=1:6)
+#' as.character(data)
+#' 
+#' # Example to simulate discrete Gamma rate variation
+#' rates = discrete.gamma(1,4)
+#' data1 = simSeq(tree, l = 100, type="AA", model="WAG", rate=rates[1])
+#' data2 = simSeq(tree, l = 100, type="AA", model="WAG", rate=rates[2])
+#' data3 = simSeq(tree, l = 100, type="AA", model="WAG", rate=rates[3])
+#' data4 = simSeq(tree, l = 100, type="AA", model="WAG", rate=rates[4])
+#' data <- c(data1,data2, data3, data4)
+#' 
+#' write.phyDat(data, file="temp.dat", format="sequential",nbcol = -1, colsep = "")
+#' unlink("temp.dat") 
+#' 
+#' @rdname simSeq
+#' @export simSeq
 simSeq <- function (x, ...) 
     UseMethod("simSeq")
 
 
-simSeq.phylo = function(x, l=1000, Q=NULL, bf=NULL, rootseq=NULL, type = "DNA", model="USER",
+#' @rdname simSeq
+#' @method simSeq phylo
+#' @export
+simSeq.phylo = function(x, l=1000, Q=NULL, bf=NULL, rootseq=NULL, type = "DNA", model=NULL,
                   levels = NULL, rate=1, ancestral=FALSE, ...){
+   
     
+    if (!is.null(model)) {
+        #        model <- match.arg(model, c("USER", "WAG", "JTT", "LG", "Dayhoff", "cpREV", "mtmam", "mtArt", "MtZoa", "mtREV24"))
+        model <- match.arg(model, .aamodels) #match.arg(model, c("USER", .aamodels)) 
+        getModelAA(model, bf=is.null(bf), Q=is.null(Q))
+        type = "AA"
+    }
+     
     pt <- match.arg(type, c("DNA", "AA", "USER", "CODON"))
     if (pt == "DNA") 
         levels <- c("a", "c", "g", "t")
@@ -31,11 +105,7 @@ simSeq.phylo = function(x, l=1000, Q=NULL, bf=NULL, rootseq=NULL, type = "DNA",
     
     lbf = length(levels)
     
-    if (type == "AA" & !is.null(model)) {
-        #        model <- match.arg(model, c("USER", "WAG", "JTT", "LG", "Dayhoff", "cpREV", "mtmam", "mtArt", "MtZoa", "mtREV24"))
-        model <- match.arg(model, c("USER", .aamodels))
-        if(model!="USER")getModelAA(model, bf=is.null(bf), Q=is.null(Q))
-    }
+
     
     if(is.null(bf)) bf = rep(1/lbf,lbf)
     if(is.null(Q)) Q = rep(1,lbf*(lbf-1)/2)
@@ -77,7 +147,9 @@ simSeq.phylo = function(x, l=1000, Q=NULL, bf=NULL, rootseq=NULL, type = "DNA",
 }        
 
 
-
+#' @rdname simSeq
+#' @method simSeq pml
+#' @export
 simSeq.pml <- function(x, ancestral=FALSE, ...){
     g = x$g
     w = x$w
diff --git a/R/splits.R b/R/splits.R
new file mode 100644
index 0000000..42dd4c8
--- /dev/null
+++ b/R/splits.R
@@ -0,0 +1,542 @@
+#' Splits representation of graphs and trees.
+#' 
+#' \code{as.splits} produces a list of splits or bipartitions.
+#' 
+#' @aliases splits as.Matrix distinct.splits as.phylo.splits
+#' addTrivialSplits removeTrivialSplits matchSplits
+#' @param x An object of class phylo or multiPhylo.
+#' @param maxp integer, default from \code{options(max.print)}, influences how
+#' many entries of large matrices are printed at all.
+#' @param zero.print character which should be printed for zeros.
+#' @param one.print character which should be printed for ones.
+#' @param incomparables	only for compatibility so far.
+#' @param unrooted todo.
+#' @param \dots Further arguments passed to or from other methods.
+#' @param recursive	logical. If recursive = TRUE, the function recursively descends 
+#' through lists (and pairlists) combining all their elements into a vector.
+#' @param obj an object of class splits.
+#' @param k number of taxa.
+#' @param labels names of taxa.
+#' @return \code{as.splits} returns an object of class splits, which is mainly
+#' a list of splits and some attributes. Often a \code{splits} object will
+#' contain attributes \code{confidences} for bootstrap or Bayesian support
+#' values and \code{weight} storing edge weights.  
+#' \code{compatible} return a lower triangular matrix where an 1 indicates that
+#' two splits are incompatible.
+#' @note The internal representation is likely to change.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{prop.part}}, \code{\link{lento}}, \code{\link{as.networx}}, 
+#' \code{\link{distanceHadamard}}, \code{\link{read.nexus.splits}}
+#' @keywords cluster
+#' @examples
+#' 
+#' (sp <- as.splits(rtree(5)))
+#' write.nexus.splits(sp)
+#' spl <- allCircularSplits(5)
+#' plot(as.networx(spl), "2D")
+#' 
+#' @rdname as.splits
+#' @export
+as.splits <- function (x, ...){
+    if(inherits(x, "splits")) return(x)
+    UseMethod("as.splits")
+}
+
+
+as.Matrix <- function (x, ...){
+    if (inherits(x,"Matrix")) return(x)
+    UseMethod("as.Matrix")
+}
+
+
+#' @rdname as.splits
+#' @method as.matrix splits
+#' @export
+as.matrix.splits <- function(x, zero.print = 0L, one.print=1L, ...){
+    m = length(x)
+    labels = attr(x, "labels")
+    n = length(labels)    
+    res = matrix(zero.print, m, n)
+    for(i in 1:m)res[i,x[[i]]]=one.print
+    dimnames(res) = list(names(x), labels)
+    res
+}
+
+
+#' @rdname as.splits
+#' @method as.Matrix splits
+#' @export
+as.Matrix.splits <- function(x, ...){
+    labels = attr(x, "labels")
+    l = length(x)
+    j = unlist(x)
+    #    i = rep(1:l, sapply(x, length))
+    i = rep(1:l, lengths(x))
+    sparseMatrix(i,j, x = rep(1L, length(i)), dimnames = list(NULL, labels)) # included x und labels
+}
+
+
+#' @rdname as.splits
+#' @method print splits
+#' @export
+print.splits <- function(x, maxp = getOption("max.print"), 
+                         zero.print = ".", one.print="|", ...)
+{
+    x.orig <- x
+    cx <- as.matrix(x, zero.print = zero.print, one.print=one.print)
+    print(cx, quote = FALSE, right = TRUE, max = maxp)
+    invisible(x.orig)
+}
+
+
+"[.splits" = function(x, i){
+    tmp = attributes(x)
+    result = unclass(x)[i]
+    if(!is.null(tmp$weights)) tmp$weights = tmp$weights[i] 
+    if(!is.null(tmp$confidences)) tmp$confidences = tmp$confidences[i]
+    if(!is.null(tmp$intervals)) tmp$intervals = tmp$intervals[i] 
+    if(!is.null(tmp$data)) tmp$data = tmp$data[i,, drop=FALSE] 
+    attributes(result) = tmp
+    result
+}
+
+
+changeOrder <- function(x, labels){
+    oldL <- attr(x, "labels")
+    ind <- match(oldL,labels)
+    for(i in 1:length(x))
+        x[[i]] <- sort(ind[x[[i]]])
+    if(!is.null(attr(x, "cycle")))
+        attr(x, "cycle") <- ind[attr(x, "cycle")]
+    attr(x, "labels") <- labels
+    x    
+}
+
+
+#orderSplitLabel = function(x, order){
+#    label = attr(x, "labels")
+#    nTips = length(label)
+#    ord = match(label, order)
+#    for(i in 1:length(x))
+#        x[[i]] = sort(ord[x[[i]]])
+#    attr(x, "labels") = order
+#    x
+#}
+
+
+
+## @rdname as.splits
+## @export
+matchSplits <- function(x, y, as.in=TRUE){
+    tiplabel <- attr(x, "label")
+    if(any(is.na(match(tiplabel, attr(y, "label"))))) stop("x and y have different labels!")
+    nTips <- length(tiplabel)
+    y <- changeOrder(y, tiplabel)
+    y <- SHORTwise(y, nTips)
+    if(as.in) return(match(SHORTwise(x, nTips), y, nomatch = 0L) > 0L)
+    match(SHORTwise(x, nTips), y)
+}
+
+
+optCycle <- function(splits, tree){
+    tips = tree$tip.label
+    tree = reorder(tree)
+    nodes = sort(unique(tree$edge[,1]))
+    
+    M = as.matrix(splits)
+    
+    l = as.integer(nrow(M))
+    m = as.integer(ncol(M))
+    
+    tmp = tree$edge[,2]
+    tmp = tmp[tmp<=m]
+    
+    start <- .C("countCycle", M[, tmp], l, m, integer(1))[[4]]
+    best = start
+    eps = 1
+    if(eps>0){
+        for(i in 1:length(nodes)){
+            tmptree = rotate(tree, nodes[i])
+            tmp = tmptree$edge[,2]
+            tmp = tmp[tmp<=m]
+            tmpC <- .C("countCycle", M[, tmp], l, m, integer(1))[[4]]
+            if(tmpC < best){
+                best <- tmpC
+                tree = tmptree
+            }
+        }
+        eps = start - best
+    }
+    tree # list(best, tree)
+}
+
+
+countCycles <- function(splits, tree=NULL, ord=NULL){
+    M = as.matrix(splits)
+    l = as.integer(nrow(M))
+    m = as.integer(ncol(M))
+    if(!is.null(tree))  ord  = getOrdering(tree)
+    res <- .C("countCycle2", M[, ord], l, m, integer(l))[[4]]
+    res
+}
+
+
+#' @rdname as.splits
+#' @method c splits
+#' @export
+c.splits <- function (..., recursive=FALSE) 
+{
+    x <- list(...)
+    if (length(x) == 1 && !inherits(x[[1]], "splits")) x <- x[[1]]
+    n <- length(x)
+    match.names <- function(a, b) {
+        if (any(!(a %in% b))) 
+            stop("names do not match previous names")
+    }
+    if (n == 1) 
+        return(x[[1]])
+    
+    labels <- attr(x[[1]], "labels")
+    cycle <- attr(x[[1]], "cycle")
+    for (i in 2:n) {
+        match.names(labels, attr(x[[i]], "labels"))
+        x[[i]] <- changeOrder(x[[i]], labels)
+    }
+    w <- as.vector(unlist(lapply(x, attr, "weights")))
+    x <- lapply(x, unclass)
+    res <- structure(do.call("c", x), class=c("splits", "prop.part"))
+    names(res) <- NULL
+    #        res <- structure(NextMethod("c"), class=c("splits", "prop.part"))
+    attr(res, "labels") <- labels
+    attr(res, "weights") <- w
+    attr(res, "cycle") <- cycle
+    res
+}
+
+
+#' @rdname as.splits
+#' @method unique splits
+#' @export
+unique.splits <- function(x, incomparables = FALSE, unrooted=TRUE, ...){
+    nTips <- length(attr(x, "labels"))
+    x <- SHORTwise(x, nTips)
+    x[!duplicated(x)]
+}
+
+
+distinct.splits <- function(...){
+    tmp <- c(...)
+    res <- unique(tmp)
+    attributes(res) <-  attributes(tmp)
+    attr(res, "weights") <- tabulate(match(tmp, res))
+    res
+}
+
+
+
+# computes splits from phylo
+#' @rdname as.splits
+#' @method as.splits phylo
+#' @export
+as.splits.phylo <- function(x, ...){
+    if (hasArg(as.is)) 
+        as.is <- list(...)$as.is
+    else as.is <- TRUE
+    result <- bip(x)
+    if(!is.null(x$edge.length)){
+        edge.weights <- numeric(max(x$edge))
+        edge.weights[x$edge[,2]] <- x$edge.length
+        attr(result, "weights") <- edge.weights
+    }
+    if(!is.null(x$node.label)){
+        conf <- x$node.label
+        if(is.character(conf)) conf <- as.numeric(conf)
+        if(!as.is) if(max(na.omit(conf)) > (1 + 1e-8))conf <- conf / 100
+        #if(!is.null(scale)) conf <- conf / scale
+        attr(result, "confidences") <- c(rep(NA_real_, length(x$tip.label)), conf)
+        #        attr(result, "confidences") <- c(rep("", length(x$tip.label)), x$node.label)
+    }    
+    attr(result, "labels") <- x$tip.label
+    class(result) <- c('splits', 'prop.part')
+    result 
+}
+
+
+# computes splits from multiPhylo object (e.g. bootstrap, MCMC etc.)
+#' @rdname as.splits
+#' @method as.splits multiPhylo
+#' @export
+as.splits.multiPhylo <- function(x, ...){
+    #    if(inherits(x,"multiPhylo"))x = .uncompressTipLabel(x)
+    #    if(inherits(x,"multiPhylo"))class(x)='list'  # prop.part allows not yet multiPhylo
+    #    firstTip = x[[1]]$tip[1]
+    #    x = lapply(x, root, firstTip) # old trick 
+    lx <-  length(x)
+    x <- unroot(x)  
+    #    lapply(x, unroot)
+    #    class(x) <- "multiPhylo"
+    splits <- prop.part(x)
+    class(splits)='list'
+    weights = attr(splits, 'number')    
+    lab = attr(splits,'labels')
+    attr(splits,'labels') <- attr(splits, 'number') <- NULL
+    l = length(lab)
+    splitTips = vector('list', l)
+    for(i in 1:l) splitTips[[i]] = i
+    result = c(splitTips,splits)
+    attr(result, "weights") = c(rep(lx, l), weights)
+    attr(result, "confidences") <- attr(result, "weights") / lx
+    attr(result, "summary") <- list(confidences="ratio", ntrees=l, clades=FALSE) 
+    attr(result, "labels") <- lab
+    class(result) = c('splits', 'prop.part')
+    result  
+}
+
+
+as.splits.prop.part <- function(x, ...){
+    if(is.null(attr(x, "number")))  
+        attr(x, "weights") = rep(1, length(x)) 
+    else{ 
+        attr(x, "weights") = attr(x, "number")
+        attr(x, "confidences") = attr(x, "number") / attr(x, "number")[1] 
+    }    
+    class(x) = c('splits', 'prop.part')	
+    x
+}
+
+
+#' @rdname as.splits
+#' @method as.splits networx
+#' @export
+as.splits.networx <- function(x, ...){
+    #    if(!is.null(attr(x, "splits")))attr(x, "splits")
+    if(!is.null(x$splits)) x$splits
+    else warning("No split object included!")    
+}
+
+
+#' @rdname as.splits
+#' @method as.prop.part splits
+#' @export
+as.prop.part.splits <- function(x, ...){
+    attr(x, "number") = attr(x, "weights")
+    attr(x, "weights") = NULL
+    class(x) = c('prop.part')	
+    x
+}
+
+## as.splits.phylo
+## @rdname as.splits
+## @method as.phylo splits
+## @export
+as.phylo.splits <- function (x, result = "phylo", ...) 
+{
+    result <- match.arg(result, c("phylo", "all"))
+    labels = attr(x, "labels")
+    nTips = length(labels)
+    weights = attr(x, "weights")
+    nTips = length(labels)
+    x = SHORTwise(x, nTips)
+    dm = as.matrix(compatible(x))
+    rs = rowSums(dm)
+    ind = which(rs == 0)
+    if (any(rs > 0)) {
+        tmp = which(rs > 0)
+        candidates = tmp[order(rs[tmp])]
+        for (i in candidates) {
+            if (sum(dm[ind, i]) == 0) 
+                ind = c(ind, i)
+        }
+    }
+    splits = x[ind]
+    weights = weights[ind]
+    l = length(ind)
+    res = matrix(0L, l, nTips)
+    for (i in 1:l) res[i, splits[[i]]] = 1L
+    dm2 = (crossprod(res * weights, 1 - res))
+    dm2 = dm2 + t(dm2)
+    dimnames(dm2) = list(labels, labels)
+    tree <- di2multi(NJ(dm2), tol = 1e-08)
+    attr(tree, "order") = NULL
+    tree <- reorder(tree)    
+    tree <- optCycle(x, tree)
+    tree <- reorder(tree, "postorder")
+    if (result == "phylo") 
+        return(tree)  
+    #    tree = reroot(tree, Ancestors(tree, 1, "parent")) 
+    spl = as.splits(tree)
+    spl = SHORTwise(spl, nTips)
+    spl <- spl[tree$edge[,2]]
+    list(tree = tree, index = tree$edge[, 2], split = spl, rest = x[-ind])
+}
+
+
+#' @rdname as.splits
+#' @method as.bitsplits splits
+#' @export
+as.bitsplits.splits <- function (x){
+    foo <- function(vect, RAWVECT) {
+        res <- RAWVECT
+        for (y in vect) {
+            i <- ceiling(y/8)
+            res[i] <- res[i] | as.raw(2^(8 - ((y - 1)%%8) - 1))
+        }
+        res
+    }
+    N <- length(x)
+    n <- length(attr(x, "labels")) 
+    nr <- ceiling(n/8)
+    mat <- raw(N * nr)
+    dim(mat) <- c(nr, N)
+    RAWVECT <- raw(nr)
+    for (i in 1:N) mat[, i] <- foo(x[[i]], RAWVECT)
+    freq <- attr(x, "weights")
+    if(is.null(freq)) freq <- rep(1, N)
+    structure(list(matsplit = mat, labels = attr(x, "labels"), 
+                   freq = freq), class = "bitsplits")
+}
+
+
+# computes compatible splits
+#' @rdname as.splits
+#' @export
+compatible <- function(obj){
+    labels = attr(obj, "labels")
+    if(!inherits(obj, "splits"))stop("obj needs to be of class splits")
+    
+    l = length(labels)
+    n = length(obj)
+    
+    bp = matrix(0L, n, l)
+    for(i in 1:n)bp[i,obj[[i]]] = 1L
+    bp[bp[, 1] == 0L, ] = 1L - bp[bp[, 1] == 0L, ]
+    k=1
+    res = matrix(0L, n, n) 
+    
+    tmp1 = tcrossprod(bp) #sum(bp[i,]* bp[j,])
+    tmp2 = tcrossprod(1L - bp) #sum((1L - bp[i,])*(1L - bp[j,]))
+    tmp3 = tcrossprod(bp, 1L - bp) #sum(bp[i,]*(1L - bp[j,]))
+    tmp4 = tcrossprod(1L - bp, bp) #sum((1L - bp[i,])*bp[j,]) 
+    res[(tmp1 * tmp2 * tmp3 * tmp4)>0]=1L
+    k = k+1
+    
+    res = res[lower.tri(res)]
+    attr(res, "Size") <- n
+    attr(res, "Diag") <- FALSE
+    attr(res, "Upper") <- FALSE
+    class(res) <- "dist"
+    return(res)
+}
+
+
+compatible2 <- function (obj1, obj2=NULL) 
+{   
+    if (!inherits(obj1, "splits")) 
+        stop("obj needs to be of class splits")
+    labels = attr(obj1, "labels")    
+    l = length(labels)
+    n = length(obj1)
+    bp1 = as.matrix(obj1)
+    bp1[bp1[, 1] == 0L, ] = 1L - bp1[bp1[, 1] == 0L, ] 
+    if(!is.null(obj2)){
+        m = length(obj2) 
+        bp2 = as.matrix(obj2)
+        labels2 = attr(obj2, "labels")
+        bp2 = bp2[, match(labels2, labels), drop=FALSE]
+        bp2[bp2[, 1] == 0L, ] = 1L - bp2[bp2[, 1] == 0L, ]
+    }
+    else bp2 = bp1
+    
+    if(is.null(obj2)) res = matrix(0L, n, n)
+    else res = matrix(0L, n, m)
+    
+    tmp1 = tcrossprod(bp1, bp2)
+    tmp2 = tcrossprod(1L - bp1, 1L - bp2)
+    tmp3 = tcrossprod(bp1, 1L - bp2)
+    tmp4 = tcrossprod(1L - bp1, bp2)
+    res[(tmp1 * tmp2 * tmp3 * tmp4) > 0] = 1L
+    if(is.null(obj2)){
+        res = res[lower.tri(res)]
+        attr(res, "Size") <- n
+        attr(res, "Diag") <- FALSE
+        attr(res, "Upper") <- FALSE
+        class(res) <- "dist"
+    }
+    return(res)
+}
+
+
+compatible3 <- function(x, y=NULL) 
+{
+    if (!inherits(x, "splits")) 
+        stop("x needs to be of class splits")
+    if(is.null(y)) y <- x
+    
+    if (!inherits(y, "splits")) 
+        stop("y needs to be of class splits")
+    xlabels = attr(x, "labels")
+    ylabels = attr(y, "labels")
+    if(identical(xlabels, ylabels)) labels = xlabels 
+    else labels = intersect(xlabels, ylabels)
+    nx = length(x)
+    ny = length(y)   
+    bp1 = as.matrix(x)[,labels, drop=FALSE]
+    bp2 = as.matrix(y)[,labels, drop=FALSE]
+    rs1 = rowSums(bp1)
+    rs2 = rowSums(bp2)
+    res = matrix(0L, nx, ny)
+    tmp1 = tcrossprod(bp1, bp2)
+    res = matrix(0L, nx, ny)
+    for(i in 1:nx){
+        for(j in 1:ny){            
+            if(tmp1[i, j]==rs1[i]) res[i,j] = 1
+            if(tmp1[i, j]==rs2[j]) res[i,j] = 2
+            if(tmp1[i, j]==rs1[i] & tmp1[i, j]==rs2[j])res[i,j] = 3
+        }
+    }      
+    if(is.null(y)){
+        res = res[lower.tri(res)]
+        attr(res, "Size") <- length(x)
+        attr(res, "Diag") <- FALSE
+        attr(res, "Upper") <- FALSE
+        class(res) <- "dist"
+    }
+    return(res)
+}
+
+
+
+compatible_2 <- function(obj1, obj2) 
+{
+    ntaxa <- length(obj1$labels)
+    msk <- !as.raw(2^(8 - (ntaxa%%8)) - 1)
+    r0 <- as.raw(0)
+    arecompatible2 <- function (x, y, msk, r0) {
+        foo <- function(v) {
+            lv <- length(v)
+            v[lv] <- v[lv] & msk
+            as.integer(all(v == r0))
+        }
+        nE <- foo(x & y) + foo(x & !y) + foo(!x & y) + foo(!x & !y)
+        if (nE > 0) TRUE
+        else FALSE
+    }  
+    m1 <- obj1$matsplit
+    m2 <- obj2$matsplit
+    n1 <- ncol(m1)
+    n2 <- ncol(m2)
+    res <- rep(TRUE, n1)
+    for (i in 1:n1){
+        j=1
+        while(j <= n2){
+            if (!arecompatible2(m1[, i], m2[, j], msk, r0)){
+                res[i]=FALSE
+                break()
+            }
+            j=j+1L
+        } 
+    }    
+    res
+}          
+
+
diff --git a/R/superTree.R b/R/superTree.R
index 90b97f6..d9917b1 100644
--- a/R/superTree.R
+++ b/R/superTree.R
@@ -79,6 +79,52 @@ dist.superTree <- function(tree, trace=0, fun, start=NULL, multicore=FALSE, mc.c
 
 
 # we want a rooted supertree
+
+
+#' Super Tree methods
+#' 
+#' These function \code{superTree} allows the estimation of a supertree from a
+#' set of trees using either Matrix representation parsimony, Robinson-Foulds
+#' or SPR as criterion.
+#' 
+#' The function \code{superTree} extends the function mrp.supertree from Liam
+#' Revells, with artificial adding an outgroup on the root of the trees.  This
+#' allows to root the supertree afterwards. The functions is internally used in
+#' DensiTree. The implementation for the RF- and SPR-supertree are very basic
+#' so far and assume that all trees share the same set of taxa.
+#' 
+#' @param tree an object of class \code{multiPhylo}
+#' @param method An argument defining which algorithm is used to optimize the
+#' tree.  Possible are "MRP", "NNI", and "SPR".
+#' @param rooted should the resulting supertrees be rooted.
+#' @param trace defines how much information is printed during optimization.
+#' @param \dots further arguments passed to or from other methods.
+#' @return The function returns an object of class \code{phylo}.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com} Liam Revell
+#' @seealso \code{mrp.supertree}, \code{\link{densiTree}},
+#' \code{\link{RF.dist}}, \code{\link{SPR.dist}}
+#' @references Baum, B. R., (1992) Combining trees as a way of combining data
+#' sets for phylogenetic inference, and the desirability of combining gene
+#' trees. \emph{Taxon}, \bold{41}, 3-10.
+#' 
+#' Ragan, M. A. (1992) Phylogenetic inference based on matrix representation of
+#' trees. \emph{Molecular Phylogenetics and Evolution}, \bold{1}, 53-58.
+#' @keywords cluster
+#' @examples
+#' 
+#' data(Laurasiatherian)
+#' set.seed(1)
+#' bs <- bootstrap.phyDat(Laurasiatherian, FUN = function(x)upgma(dist.hamming(x)), bs=50)
+#' class(bs) <- 'multiPhylo'
+#' 
+#' mrp_st <- superTree(bs, rooted=TRUE)
+#' plot(superTree(mrp_st))
+#' \dontrun{
+#' rf_st <- superTree(bs, method = "RF")
+#' spr_st <- superTree(bs, method = "SPR")
+#' }
+#' 
+#' @export superTree
 superTree = function(tree, method="MRP", rooted=FALSE, trace=0, ...){
     fun = function(x){
         x=reorder(x, "postorder")
diff --git a/R/treeManipulation.R b/R/treeManipulation.R
index 18cab99..3f97fdf 100644
--- a/R/treeManipulation.R
+++ b/R/treeManipulation.R
@@ -4,6 +4,8 @@
 
 
 # no checks for postorder
+#' @rdname midpoint
+#' @export
 getRoot <- function (tree) 
 {
     if(!is.null(attr(tree, "order")) && attr(tree, "order") == 
@@ -69,8 +71,53 @@ changeEdgeLength = function (tree, edge, edge.length)
 }
 
 
-# O(n) statt O(n^2) Speicher und Geschwindigkeit
-midpoint <- function(tree, node.labels = "support"){
+## @aliases midpoint pruneTree getRoot
+#' Tree manipulation
+#' 
+#' \code{midpoint} performs midpoint rooting of a tree.  \code{pruneTree}
+#' produces a consensus tree.
+#' 
+#' \code{pruneTree} prunes back a tree and produces a consensus tree, for trees
+#' already containing nodelabels.  It assumes that nodelabels are numerical or
+#' character that allows conversion to numerical, it uses
+#' as.numeric(as.character(tree$node.labels)) to convert them.  \code{midpoint}
+#' so far does not transform node.labels properly.
+#' 
+
+#' @param tree an object of class \code{phylo}
+#' @param FUN a function evaluated on the nodelabels, result must be logical.
+#' @param node.labels are nodel labels 'support' values, 'label' or should be
+#' 'deleted'
+#' @param \dots further arguments, passed to other methods.
+#' @return \code{pruneTree} and \code{midpoint} a tree. \code{getRoot} returns
+#' the root node.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link[ape]{consensus}}, \code{\link[ape]{root}},
+#' \code{\link[ape]{di2multi}}
+#' @keywords cluster
+#' @examples
+#' 
+#' tree = unroot(rtree(10))
+#' tree$node.label = c("", round(runif(tree$Nnode-1), 3))
+#' 
+#' tree2 = midpoint(tree)
+#' tree3 = pruneTree(tree, .5)
+#' 
+#' par(mfrow = c(3,1))
+#' plot(tree, show.node.label=TRUE)
+#' plot(tree2, show.node.label=TRUE)
+#' plot(tree3, show.node.label=TRUE)
+#' 
+#' @rdname midpoint
+#' @export midpoint
+midpoint <- function(tree, node.labels = "support", ...)
+    UseMethod("midpoint")
+
+
+#' @rdname midpoint
+#' @method midpoint phylo
+#' @export
+midpoint.phylo <- function(tree, node.labels = "support", ...){
 # distance from node to root
 node2root <- function(x){
     x = reorder(x, "postorder")
@@ -151,6 +198,21 @@ node2root <- function(x){
 }
 
 
+#' @rdname midpoint
+#' @method midpoint multiPhylo
+#' @export
+midpoint.multiPhylo <- function(tree, node.labels = "support", ...){
+    if(!is.null(attr(tree, "TipLabel"))) compress <- TRUE
+    else compress <- FALSE
+    tree <- lapply(tree, midpoint.phylo, node.labels = node.labels)
+    class(tree) <- "multiPhylo"
+    if(compress) tree <- .compressTipLabel(tree)
+    tree
+}
+        
+    
+#' @rdname midpoint
+#' @export
 pruneTree = function(tree, ..., FUN = ">="){
      if(is.null(tree$node)) stop("no node labels")
      if(is.rooted(tree)) tree = unroot(tree)
@@ -406,6 +468,34 @@ nnin <- function (tree, n)
 } 
 
 
+
+## @aliases nni rNNI rSPR
+#' Tree rearrangements.
+#' 
+#' \code{nni} returns a list of all trees which are one nearest neighbor
+#' interchange away. \code{rNNI} and \code{rSPR} are two methods which simulate
+#' random trees which are a specified number of rearrangement apart from the
+#' input tree. Both methods assume that the input tree is bifurcating. These
+#' methods may be useful in simulation studies.
+#' 
+#' 
+#' @param tree A phylogenetic \code{tree}, object of class \code{phylo}.
+#' @param moves Number of tree rearrangements to be transformed on a tree.  Can
+#' be a vector
+#' @param n Number of trees to be simulated.
+#' @param k If defined just SPR of distance k are performed.
+#' @return an object of class multiPhylo.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link{allTrees}}, \code{\link{SPR.dist}}
+#' @keywords cluster
+#' @examples
+#' 
+#' tree = unroot(rtree(20))
+#' trees1 <- nni(tree)
+#' trees2 <- rSPR(tree, 2, 10)
+#' 
+#' @rdname nni
+#' @export nni
 nni <- function (tree) 
 {
     tip.label <- tree$tip.label
@@ -426,6 +516,28 @@ nni <- function (tree)
 }
 
 
+
+
+#' Compute all trees topologies.
+#' 
+#' \code{allTrees} computes all tree topologies for rooted or unrooted trees
+#' with up to 10 tips. \code{allTrees} returns bifurcating trees.
+#' 
+#' 
+#' @param n Number of tips (<=10).
+#' @param rooted Rooted or unrooted trees (default: rooted).
+#' @param tip.label Tip labels.
+#' @return an object of class \code{multiPhylo}.
+#' @author Klaus Schliep \email{klaus.schliep@@gmail.com}
+#' @seealso \code{\link[ape]{rtree}}, \code{\link{nni}}
+#' @keywords cluster
+#' @examples
+#' 
+#' trees <- allTrees(5)
+#' par(mfrow = c(3,5))
+#' for(i in 1:15)plot(trees[[i]])
+#' 
+#' @export allTrees
 allTrees <- function (n, rooted = FALSE, tip.label = NULL) 
 {
 	n <- as.integer(n)  
@@ -520,6 +632,8 @@ dn <- function(x){
 }
 
 
+#' @rdname nni
+#' @export
 rSPR = function (tree, moves = 1, n = length(moves), k=NULL) 
 {
     if (n == 1) {
@@ -726,6 +840,8 @@ sprMove <- function(tree, m){
 }
  
 
+#' @rdname nni
+#' @export
 rNNI <- function (tree, moves = 1, n = length(moves)) 
 {
     k = length(na.omit(match(tree$edge[, 2], tree$edge[, 1])))
@@ -771,6 +887,45 @@ allAncestors <- function(x){
 }
 
 
+
+## @aliases Ancestors Children Descendants Siblings mrca.phylo
+#' tree utility function
+#' 
+#' Functions for describing relationships among phylogenetic nodes.
+#' 
+#' These functions are inspired by \code{treewalk} in phylobase package, but
+#' work on the S3 \code{phylo} objects.  The nodes are the indices as given in
+#' edge matrix of an phylo object. From taxon labels these indices can be
+#' easily derived matching against the \code{tip.label} argument of an phylo
+#' object, see example below.  All the functions allow \code{node} to be either
+#' a scalar or vector.  \code{mrca} is a faster version of the mrca in ape, in
+#' phangorn only because of dependencies.
+#' 
+#' @param x a tree (a phylo object).
+#' @param node an integer or a vector of integers corresponding to a node ID
+#' @param type specify whether to return just direct children / parents or all
+#' @param include.self whether to include self in list of siblings
+#' @return a vector or a list containing the indices of the nodes.
+#' @seealso \code{treewalk}, \code{\link[ape]{phylo}},
+#' \code{\link[ape]{nodelabels}}
+#' @keywords misc
+#' @examples
+#' 
+#' tree = rtree(10)
+#' plot(tree, show.tip.label = FALSE)
+#' nodelabels()
+#' tiplabels()
+#' Ancestors(tree, 1:3, "all")
+#' Children(tree, 11)
+#' Descendants(tree, 11, "tips")
+#' Siblings(tree, 3)
+#' mrca.phylo(tree, 1:3)
+#' mrca.phylo(tree, match(c("t1", "t2", "t3"), tree$tip))
+#' mrca.phylo(tree)
+#' # same as mrca(tree), but faster for large trees
+#' 
+#' @export 
+#' @rdname Ancestors
 Ancestors <- function (x, node, type = c("all", "parent")) 
 {
     parents <- x$edge[, 1]
@@ -841,12 +996,16 @@ allDescendants <- function(x){
 }
 
 
+#' @rdname Ancestors
+#' @export
 Children <- function(x, node){
    if(length(node)==1)return(x$edge[x$edge[,1]==node,2])
    allChildren(x)[node]
 }
 
 
+#' @rdname Ancestors
+#' @export
 Descendants = function(x, node, type=c("tips","children","all")){
   type <- match.arg(type)
   if(type=="children") return(Children(x, node))
@@ -871,6 +1030,8 @@ Descendants = function(x, node, type=c("tips","children","all")){
 }
 
 
+#' @rdname Ancestors
+#' @export
 Siblings = function (x, node, include.self = FALSE) 
 {
     l = length(node)
@@ -902,7 +1063,8 @@ Siblings = function (x, node, include.self = FALSE)
 }
 
 
-
+#' @rdname Ancestors
+#' @export
 mrca.phylo <- function(x, node=NULL){
     if(is.null(node)) return(mrca2(x))
     anc <- Ancestors(x, node, type = "all")
diff --git a/R/treedist.R b/R/treedist.R
index 772630b..c797472 100644
--- a/R/treedist.R
+++ b/R/treedist.R
@@ -46,6 +46,22 @@ cophenetic.splits <- function(x){
 }
 
 
+
+
+#' Pairwise Distances from a Phylogenetic Network
+#' 
+#' \code{cophenetic.networx} computes the pairwise distances between the pairs
+#' of tips from a phylogenetic network using its branch lengths.
+#' 
+#' 
+#' @aliases cophenetic.networx cophenetic.splits
+#' @param x an object of class \code{networx}.
+#' @return an object of class \code{dist}, names are set according to the tip
+#' labels (as given by the element \code{tip.label} of the argument \code{x}).
+#' @author Klaus Schliep
+#' @seealso \code{\link[stats]{cophenetic}} for the generic function,
+#' \code{neighborNet} to construct a network from a distance matrix
+#' @keywords manip
 cophenetic.networx <- function(x){
 #    spl <- attr(x, "splits")
     spl <- x$splits
@@ -81,7 +97,7 @@ oneWise <- function (x, nTips=NULL)
 {
     if(is.null(nTips))nTips <- length(x[[1L]])
     v <- 1:nTips
-    for (i in 2:length(x)) {
+    for (i in 1:length(x)) {
         y <- x[[i]]
         if (y[1] != 1) 
             y <- v[-y]
@@ -93,7 +109,173 @@ oneWise <- function (x, nTips=NULL)
 }
 
 
+## @aliases treedist RF.dist wRF.dist KF.dist path.dist sprdist SPR.dist
+
+#' Distances between trees
+#' 
+#' \code{treedist} computes different tree distance methods and \code{RF.dist}
+#' the Robinson-Foulds or symmetric distance. The Robinson-Foulds distance only 
+#' depends on the toplogy of the trees. If edge weights should be considered
+#' \code{wRF.dist} calculates the weighted RF distance (Robinson & Foulds
+#' 1981). and \code{KF.dist} calculates the branch score distance (Kuhner &
+#' Felsenstein 1994).  \code{path.dist} computes the path difference metric as
+#' described in Steel and Penny 1993).
+#' \code{sprdist} computes the approximate SPR distance (Oliveira Martins et
+#' al. 2008, de Oliveira Martins 2016). 
+#' 
+#' @details The Robinson-Foulds distance between two trees \eqn{T_1} and \eqn{T_2} with
+#' \eqn{n} tips is defined as (following the notation Steel and Penny 1993):
+#' \deqn{d(T_1, T_2) = i(T_1) + i(T_2) - 2v_s(T_1, T_2)} where \eqn{i(T_1)}
+#' denotes the number of internal edges and \eqn{v_s(T_1, T_2)} denotes the
+#' number of internal splits shared by the two trees. The normalized
+#' Robinson-Foulds distance is derived by dividing \eqn{d(T_1, T_2)} by the
+#' maximal possible distance \eqn{i(T_1) + i(T_2)}. If both trees are unrooted
+#' and binary this value is \eqn{2n-6}.
+#' 
+#' Functions like \code{RF.dist} returns the Robinson-Foulds distance (Robinson and Foulds 1981)
+#' between either 2 trees or computes a matrix of all pairwise distances if a
+#' \code{multiPhylo} object is given. 
+#' 
+#' For large number of trees the distance functions can use a lot of memory!
+#' 
+#' @param tree1 A phylogenetic tree (class \code{phylo}) or vector of trees (an
+#' object of class \code{multiPhylo}). See details
+#' @param tree2 A phylogenetic tree.
+#' @param normalize compute normalized RF-distance, see details.
+#' @param check.labels compares labels of the trees.
+#' @param rooted take bipartitions for rooted trees into account, default is
+#' unrooting the trees.
+#' @param use.weight use edge.length argument or just count number of edges on
+#' the path (default)
+#' @return \code{treedist} returns a vector containing the following tree
+#' distance methods \item{symmetric.difference}{symmetric.difference or
+#' Robinson-Foulds distance}
+#' \item{branch.score.difference}{branch.score.difference}
+#' \item{path.difference}{path.difference}
+#' \item{weighted.path.difference}{weighted.path.difference}
+#' @author Klaus P. Schliep \email{klaus.schliep@@gmail.com},
+#' Leonardo de Oliveira Martins
+#' @seealso \code{\link[ape]{dist.topo}}, \code{\link{nni}},
+#' \code{\link{superTree}}
+#' @references de Oliveira Martins L., Leal E., Kishino H. (2008)
+#' \emph{Phylogenetic Detection of Recombination with a Bayesian Prior on the
+#' Distance between Trees}. PLoS ONE \bold{3(7)}. e2651. doi:
+#' 10.1371/journal.pone.0002651
+#' 
+#' de Oliveira Martins L., Mallo D., Posada D. (2016) \emph{A Bayesian
+#' Supertree Model for Genome-Wide Species Tree Reconstruction}. Syst. Biol.
+#' \bold{65(3)}: 397-416, doi:10.1093/sysbio/syu082
+#' 
+#' Steel M. A. and Penny P. (1993) \emph{Distributions of tree comparison
+#' metrics - some new results}, Syst. Biol., \bold{42(2)}, 126--141
+#' 
+#' Kuhner, M. K. and Felsenstein, J. (1994) \emph{A simulation comparison of
+#' phylogeny algorithms under equal and unequal evolutionary rates}, Molecular
+#' Biology and Evolution, \bold{11(3)}, 459--468
+#' 
+#' D.F. Robinson and L.R. Foulds (1981) \emph{Comparison of phylogenetic
+#' trees}, Mathematical Biosciences, \bold{53(1)}, 131--147
+#' 
+#' D.F. Robinson and L.R. Foulds (1979) Comparison of weighted labelled trees.
+#' In Horadam, A. F. and Wallis, W. D. (Eds.), \emph{Combinatorial Mathematics
+#' VI: Proceedings of the Sixth Australian Conference on Combinatorial
+#' Mathematics, Armidale, Australia}, 119--126
+#' @keywords classif
+#' @examples
+#' 
+#' tree1 <- rtree(100, rooted=FALSE)
+#' tree2 <- rSPR(tree1, 3)
+#' RF.dist(tree1, tree2)
+#' treedist(tree1, tree2)
+#' sprdist(tree1, tree2)
+#' trees <- rSPR(tree1, 1:5)
+#' SPR.dist(tree1, trees)
+#' 
+#' @rdname treedist
+#' @export treedist
+treedist <- function (tree1, tree2, check.labels=TRUE) 
+{
+    tree1 = unroot(tree1)
+    tree2 = unroot(tree2)
+    
+    if (check.labels) {
+        ind <- match(tree1$tip.label, tree2$tip.label)
+        if (any(is.na(ind)) | length(tree1$tip.label) !=
+            length(tree2$tip.label))
+            stop("trees have different labels")
+        tree2$tip.label <- tree2$tip.label[ind]
+        ind2 <- match(1:length(ind), tree2$edge[, 2])
+        tree2$edge[ind2, 2] <- order(ind)
+    }
+    
+    tree1 = reorder(tree1, "postorder")
+    tree2 = reorder(tree2, "postorder")
+    
+    symmetric.difference = NULL
+    branch.score.difference = NULL
+    path.difference = NULL
+    quadratic.path.difference = NULL
+    if(!is.binary.tree(tree1) | !is.binary.tree(tree2))message("Trees are not binary!")
+    
+    bp1 = bip(tree1)
+    bp2 = bip(tree2)
+    bp1 <- SHORTwise(bp1, length(tree1$tip.label))
+    bp2 <- SHORTwise(bp2, length(tree2$tip.label))
+    bp1 <- sapply(bp1, paste, collapse = "_")
+    bp2 <- sapply(bp2, paste, collapse = "_")
+    
+    l = length(tree1$tip.label)
+    
+    if (!is.null(tree1$edge.length) & !is.null(tree2$edge.length)) {      
+        dv1 = coph(tree1)
+        dv2 = coph(tree2)
+        quadratic.path.difference = sqrt(sum((dv1 - dv2)^2))
+        
+    }
+    
+    RF = sum(match(bp1, bp2, nomatch=0L)==0L) + sum(match(bp2, bp1, nomatch=0L)==0L)
+    
+    symmetric.difference = RF #2 * (p - sum(r1))
+    if (!is.null(tree1$edge.length) & !is.null(tree2$edge.length)) {
+        w1 = numeric(max(tree1$edge))
+        w2 = numeric(max(tree2$edge))
+        w1[tree1$edge[,2]] = tree1$edge.length
+        w2[tree2$edge[,2]] = tree2$edge.length
+        
+        v1 = tree1$edge.length
+        v2 = tree2$edge.length
+        
+        ind3 = match(bp1, bp2, nomatch=0L)
+        ind4 = ind3[ind3>0]
+        ind3 = which(ind3>0)
+        
+        s1 = sum((w1[ind3] - w2[ind4])^2)
+        
+        s2 = sum(w1[-ind3]^2)
+        s3 = sum(w2[-ind4]^2)
+        branch.score.difference = sqrt(s1 + s2 + s3)
+    }
+    
+    tree1$edge.length = rep(1, nrow(tree1$edge))
+    tree2$edge.length = rep(1, nrow(tree2$edge))
+    
+    dt1 = coph(tree1)
+    dt2 = coph(tree2)  
+    path.difference = sqrt(sum((dt1 - dt2)^2))
+    
+    result = c(symmetric.difference = symmetric.difference, 
+               branch.score.difference = branch.score.difference, 
+               path.difference = path.difference, 
+               quadratic.path.difference = quadratic.path.difference)
+    result              
+}
+
+
+
+
 # leomrtns addition
+#' @rdname treedist
+#' @export
 sprdist <- function (tree1, tree2) 
 {
     tree1 = unroot(tree1)
@@ -190,6 +372,8 @@ SPR2 <- function(tree, trees){
 }
 
 
+#' @rdname treedist
+#' @export
 SPR.dist <- function(tree1, tree2=NULL){
     if(inherits(tree1, "multiPhylo") && is.null(tree2))return(SPR1(tree1)) 
     if(inherits(tree1, "phylo") && inherits(tree2, "phylo"))return(sprdist(tree1, tree2)[1])
@@ -199,84 +383,6 @@ SPR.dist <- function(tree1, tree2=NULL){
 }
 
 
-treedist <- function (tree1, tree2, check.labels=TRUE) 
-{
-    tree1 = unroot(tree1)
-    tree2 = unroot(tree2)
-    
-    if (check.labels) {
-        ind <- match(tree1$tip.label, tree2$tip.label)
-        if (any(is.na(ind)) | length(tree1$tip.label) !=
-                length(tree2$tip.label))
-            stop("trees have different labels")
-        tree2$tip.label <- tree2$tip.label[ind]
-        ind2 <- match(1:length(ind), tree2$edge[, 2])
-        tree2$edge[ind2, 2] <- order(ind)
-    }
-    
-    tree1 = reorder(tree1, "postorder")
-    tree2 = reorder(tree2, "postorder")
-    
-    symmetric.difference = NULL
-    branch.score.difference = NULL
-    path.difference = NULL
-    quadratic.path.difference = NULL
-    if(!is.binary.tree(tree1) | !is.binary.tree(tree2))message("Trees are not binary!")
-    
-    bp1 = bip(tree1)
-    bp2 = bip(tree2)
-    bp1 <- SHORTwise(bp1, length(tree1$tip.label))
-    bp2 <- SHORTwise(bp2, length(tree2$tip.label))
-    bp1 <- sapply(bp1, paste, collapse = "_")
-    bp2 <- sapply(bp2, paste, collapse = "_")
-    
-    l = length(tree1$tip.label)
-
-    if (!is.null(tree1$edge.length) & !is.null(tree2$edge.length)) {      
-        dv1 = coph(tree1)
-        dv2 = coph(tree2)
-        quadratic.path.difference = sqrt(sum((dv1 - dv2)^2))
-        
-    }
-   
-    RF = sum(match(bp1, bp2, nomatch=0L)==0L) + sum(match(bp2, bp1, nomatch=0L)==0L)
-
-    symmetric.difference = RF #2 * (p - sum(r1))
-    if (!is.null(tree1$edge.length) & !is.null(tree2$edge.length)) {
-        w1 = numeric(max(tree1$edge))
-        w2 = numeric(max(tree2$edge))
-        w1[tree1$edge[,2]] = tree1$edge.length
-        w2[tree2$edge[,2]] = tree2$edge.length
-        
-        v1 = tree1$edge.length
-        v2 = tree2$edge.length
-     
-        ind3 = match(bp1, bp2, nomatch=0L)
-        ind4 = ind3[ind3>0]
-        ind3 = which(ind3>0)
-
-        s1 = sum((w1[ind3] - w2[ind4])^2)
-
-        s2 = sum(w1[-ind3]^2)
-        s3 = sum(w2[-ind4]^2)
-        branch.score.difference = sqrt(s1 + s2 + s3)
-    }
-    
-    tree1$edge.length = rep(1, nrow(tree1$edge))
-    tree2$edge.length = rep(1, nrow(tree2$edge))
-
-    dt1 = coph(tree1)
-    dt2 = coph(tree2)  
-    path.difference = sqrt(sum((dt1 - dt2)^2))
-    
-    result = c(symmetric.difference = symmetric.difference, 
-               branch.score.difference = branch.score.difference, 
-               path.difference = path.difference, 
-               quadratic.path.difference = quadratic.path.difference)
-    result              
-}
-
-
 wRF0 <- function(tree1, tree2, normalize=FALSE, check.labels=TRUE, rooted = FALSE){    
     r1 = is.rooted(tree1)
     r2 = is.rooted(tree2)
@@ -586,6 +692,8 @@ RF0 <- function(tree1, tree2=NULL, normalize=FALSE, check.labels = TRUE, rooted=
 }
 
 
+#' @rdname treedist
+#' @export
 RF.dist <- function(tree1, tree2=NULL, normalize=FALSE, check.labels = TRUE, rooted=FALSE)
 {
     if(class(tree1)=="phylo" && class(tree2)=="phylo")return(RF0(tree1, tree2, normalize, check.labels, rooted))
@@ -596,6 +704,8 @@ RF.dist <- function(tree1, tree2=NULL, normalize=FALSE, check.labels = TRUE, roo
 }
 
 
+#' @rdname treedist
+#' @export
 wRF.dist <- function(tree1, tree2=NULL, normalize=FALSE, check.labels = TRUE, rooted=FALSE){
     if(class(tree1)=="phylo" && class(tree2)=="phylo")return(wRF0(tree1, tree2, normalize, check.labels, rooted))
     if(class(tree1)=="multiPhylo" && is.null(tree2))return(wRF1(tree1, normalize, check.labels))
@@ -739,7 +849,8 @@ kf2 <- function(trees, check.labels = TRUE){
 }
 
 
-# TODO distance matrices
+#' @rdname treedist
+#' @export
 KF.dist <- function(tree1, tree2=NULL, check.labels = TRUE, rooted=FALSE){
     if(inherits(tree1, "multiPhylo") && is.null(tree2))return(kf2(tree1)) 
     if(inherits(tree1, "phylo") && inherits(tree2, "phylo"))return(kf0(tree1, tree2, check.labels))
@@ -749,6 +860,8 @@ KF.dist <- function(tree1, tree2=NULL, check.labels = TRUE, rooted=FALSE){
 }
 
 
+#' @rdname treedist
+#' @export
 path.dist <- function(tree1, tree2=NULL, check.labels = TRUE, use.weight=FALSE){
     if(inherits(tree1, "phylo") && inherits(tree2, "phylo"))
          return(pd0(tree1, tree2, check.labels, !use.weight))
diff --git a/README.md b/README.md
index f532211..08ccc3e 100644
--- a/README.md
+++ b/README.md
@@ -15,10 +15,10 @@ You can install
 - the latest released version `install.packages("phangorn")`
 - the latest development version `devtools::install_github("KlausVigo/phangorn")`
 
-You may need to install first the Biostrings package from bioconductor 
+To install the development version you may need to install the Biostrings and seqLogo package from bioconductor first:
 ```
 source("https://bioconductor.org/biocLite.R")
-biocLite("Biostrings")
+biocLite("Biostrings", "seqLogo")
 ```
 
 If you use phangorn please cite:
diff --git a/build/vignette.rds b/build/vignette.rds
index 5baba21..61e5391 100644
Binary files a/build/vignette.rds and b/build/vignette.rds differ
diff --git a/inst/doc/Ancestral.R b/inst/doc/Ancestral.R
index 4eaa3a6..cb00a8a 100644
--- a/inst/doc/Ancestral.R
+++ b/inst/doc/Ancestral.R
@@ -9,17 +9,18 @@ foo <- packageDescription("phangorn")
 
 
 ###################################################
-### code chunk number 2: Ancestral.Rnw:62-67
+### code chunk number 2: Ancestral.Rnw:62-68
 ###################################################
 library(phangorn)
-primates = read.phyDat("primates.dna", format = "phylip", type = "DNA")
-tree = pratchet(primates, trace=0)
-tree = acctran(tree, primates) 
+library(magrittr)
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip", type = "DNA")
+tree <- pratchet(primates, trace=0) %>% acctran(primates) 
 parsimony(tree, primates)
 
 
 ###################################################
-### code chunk number 3: Ancestral.Rnw:73-75
+### code chunk number 3: Ancestral.Rnw:74-76
 ###################################################
 anc.acctran = ancestral.pars(tree, primates, "ACCTRAN")
 anc.mpr = ancestral.pars(tree, primates, "MPR")
@@ -41,7 +42,7 @@ if(tmp) seqLogo( t(subset(anc.mpr, getRoot(tree), 1:20)[[1]]), ic.scale=FALSE)
 
 
 ###################################################
-### code chunk number 6: Ancestral.Rnw:94-96
+### code chunk number 6: Ancestral.Rnw:95-97
 ###################################################
 options(SweaveHooks=list(fig=function()
 par(mar=c(2.1, 4.1, 2.1, 2.1))))
@@ -69,14 +70,14 @@ title("ACCTRAN")
 
 
 ###################################################
-### code chunk number 9: Ancestral.Rnw:123-125
+### code chunk number 9: Ancestral.Rnw:124-126
 ###################################################
 fit = pml(tree, primates)
 fit = optim.pml(fit, model="F81", control = pml.control(trace=0))
 
 
 ###################################################
-### code chunk number 10: Ancestral.Rnw:137-139
+### code chunk number 10: Ancestral.Rnw:138-140
 ###################################################
 anc.ml = ancestral.pml(fit, "ml")
 anc.bayes = ancestral.pml(fit, "bayes")
@@ -104,7 +105,7 @@ title("Bayes")
 
 
 ###################################################
-### code chunk number 13: Ancestral.Rnw:163-164
+### code chunk number 13: Ancestral.Rnw:164-165
 ###################################################
 toLatex(sessionInfo())
 
diff --git a/inst/doc/Ancestral.Rnw b/inst/doc/Ancestral.Rnw
index 8b29ab7..824bbe6 100644
--- a/inst/doc/Ancestral.Rnw
+++ b/inst/doc/Ancestral.Rnw
@@ -56,14 +56,15 @@ foo <- packageDescription("phangorn")
 \nocite{Paradis2006}
 \section{Introduction}
 
-These notes describe the ancestral sequence reconstruction using the \phangorn{} package \cite{Schliep2011}. \phangorn{} provides several methods to estimate ancestral character states with either Maximum Parsimony (MP) or Maximum Likelihood (ML). %For more background on all the methods see e.g. \cite{Felsenstein2004, Yang2006}. 
+These notes describe the ancestral sequence reconstruction using the \phangorn{} package \cite{Schliep2011}. \phangorn{} provides several methods to estimatea ancestral character states with either Maximum Parsimony (MP) or Maximum Likelihood (ML). %For more background on all the methods see e.g. \cite{Felsenstein2004, Yang2006}. 
 \section{Parsimony reconstructions}
 To reconstruct ancestral sequences we first load some data and reconstruct a tree:
 <<echo=TRUE>>=
 library(phangorn)
-primates = read.phyDat("primates.dna", format = "phylip", type = "DNA")
-tree = pratchet(primates, trace=0)
-tree = acctran(tree, primates) 
+library(magrittr)
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip", type = "DNA")
+tree <- pratchet(primates, trace=0) %>% acctran(primates) 
 parsimony(tree, primates)
 @
 
diff --git a/inst/doc/Ancestral.pdf b/inst/doc/Ancestral.pdf
index ad558fc..5e583be 100644
Binary files a/inst/doc/Ancestral.pdf and b/inst/doc/Ancestral.pdf differ
diff --git a/inst/doc/IntertwiningTreesAndNetworks.R b/inst/doc/IntertwiningTreesAndNetworks.R
index 6314db4..f4f1a60 100644
--- a/inst/doc/IntertwiningTreesAndNetworks.R
+++ b/inst/doc/IntertwiningTreesAndNetworks.R
@@ -1,8 +1,13 @@
 ## ----setup, echo=FALSE---------------------------------------------------
 # set global chunk options: images will be bigger
-knitr::opts_chunk$set(fig.width=7, fig.height=7) 
+  knitr::opts_chunk$set(fig.width=6, fig.height=6)
+#, global.par=TRUE
 options(digits = 4)
 
+knitr::knit_hooks$set(small.mar=function(before, options, envir){
+   if (before && options$fig.show!='none') par(mar=c(.5,.5,.5,.5))
+})
+
 ## ---- eval=FALSE---------------------------------------------------------
 #  install.packages("phangorn", dependencies=TRUE)
 #  # install latest development version needs devtools
@@ -12,6 +17,7 @@ options(digits = 4)
 
 ## ------------------------------------------------------------------------
 library(phangorn)    # load the phangorn library
+library(magrittr)  
 
 ## ------------------------------------------------------------------------
 ## automatically set the correct working directory for the examples below
@@ -41,7 +47,7 @@ mrbayes.trees <- c(run1[251:1001],run2[251:1001])
 Nnet <- read.nexus.networx(file.path(fdir,"woodmouse.nxs"))
 
 ## ------------------------------------------------------------------------
-par(mfrow=c(1,2), mar=c(2,2,2,2)) # Setting plot parameters
+par(mfrow=c(1,2), mar=c(1,1,1,1)) # Setting plot parameters
 ### Plotting trees with support values:
 ##  RAxML
 plot(raxml.tree)
@@ -52,21 +58,20 @@ nodelabels(mrbayes.tree$node.label, adj = c(1, 0), frame = "none")
 
 par(mfrow=c(1,1)) # Setting plot parameters
 # NeighbourNet
-plot.networx(Nnet,"2D")
+plot(Nnet,"2D")
 ## alternatively,
 # plot(Nnet,"2D")
 
 
-## ------------------------------------------------------------------------
+## ---- fig.width=7, fig.height=4, small.mar=TRUE--------------------------
 # create a vector of labels for the network corresponding to edges in the tree
 edge.lab <- createLabel(Nnet, raxml.tree, raxml.tree$edge[,2], "edge")
 # could be also 1:27 instead of raxml.tree$edge[,2]
 
 # Show the correspondingly labelled tree and network in R
-par(mfrow=c(1,2), mar=c(1,1,1,1))
-#plotBS(raxml.tree, rotate.tree = 180) 
-plot(raxml.tree, "u", rotate.tree = 180) 
-edgelabels(raxml.tree$edge[,2],col="blue", frame="none")
+par(mfrow=c(1,2))  
+plot(raxml.tree, "u", rotate.tree = 180, cex=.7) 
+edgelabels(raxml.tree$edge[,2],col="blue", frame="none", cex=.7)
 
 # find edges that are in the network but not in the tree
 edge.col <- rep("black", nrow(Nnet$edge))
@@ -74,14 +79,16 @@ edge.col[ is.na(edge.lab) ] <- "red"
 # or a simpler alternative...
 edge.col <- createLabel(Nnet, raxml.tree, "black", nomatch="red")
 
-x <- plot.networx(Nnet, edge.label = edge.lab, show.edge.label = T, "2D", edge.color = edge.col,
-                  col.edge.label = "blue")
+x <- plot(Nnet, edge.label = edge.lab, show.edge.label = T, "2D", edge.color = edge.col,
+                  col.edge.label = "blue", cex=.7)
 # the above plot function returns an invisible networx object and this object also  
 # contains the colors for the edges.
 
 
-## ------------------------------------------------------------------------
-x <- addConfidences(Nnet,raxml.tree)
+## ---- small.mar=TRUE-----------------------------------------------------
+# the scaler argument multiplies the confidence values. This is useful to switch
+# confidences values between total, percentage or ratios.   
+x <- addConfidences(Nnet,raxml.tree, scaler = .01)
 # find splits that are in the network but not in the tree
 split.col <- rep("black", length(x$splits))
 split.col[ !matchSplits(as.splits(x), as.splits(raxml.tree)) ] <- "red"
@@ -90,15 +97,14 @@ split.col[ !matchSplits(as.splits(x), as.splits(raxml.tree)) ] <- "red"
 split.col2 <- createLabel(x, raxml.tree, label="black", "split", nomatch="red")
 
 # Plotting in R
-par(mfrow=c(1,1))
-out.x <- plot.networx(x,"2D",show.edge.label=TRUE, split.color=split.col, col.edge.label = "blue")
+out.x <- plot(x,"2D",show.edge.label=TRUE, split.color=split.col, col.edge.label = "blue")
 
 ## ------------------------------------------------------------------------
 # write.nexus.networx(out.x,"woodmouse.tree.support.nxs")
 ## or we can also export the splits alone (for usage in software other than SplitsTree)
 # write.nexus.splits(as.splits(out.x),"woodmouse.splits.support.nxs")
 
-## ------------------------------------------------------------------------
+## ---- small.mar=TRUE-----------------------------------------------------
 y <- addConfidences(Nnet, as.splits(raxml.bootstrap))
 edge.col <- createLabel(y, raxml.tree, label="black", "edge", nomatch="grey")
 
@@ -107,17 +113,78 @@ y <- plot(y,"2D",show.edge.label=TRUE, edge.color=edge.col)
 ## Write to SplitsTree for viewing
 # write.nexus.networx(y,"NN.with.bs.support.nxs")
 
-## ------------------------------------------------------------------------
+## ---- small.mar=TRUE-----------------------------------------------------
 cnet <- consensusNet(raxml.bootstrap,prob=0.10)
 edge.col <- createLabel(cnet, Nnet, label="black", "edge", nomatch="grey")
-cnet <- plot.networx(cnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
+cnet <- plot(cnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
 
 edge.col <- createLabel(Nnet, cnet, label="black", "edge", nomatch="grey")
-z <- plot.networx(Nnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
+z <- plot(Nnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
 
 obj <- addConfidences(Nnet,cnet)
-plot.networx(obj,"2D",show.edge.label=T, edge.color=edge.col, col.edge.label = "blue")
+plot(obj,"2D",show.edge.label=T, edge.color=edge.col, col.edge.label = "blue")
 
 ## Write to SplitsTree for viewing
 # write.nexus.networx(obj,"Nnet.with.ML.Cnet.Bootstrap.nxs")
 
+## ---- fig.width=7, fig.height=6------------------------------------------
+Nnet <- read.nexus.networx(file.path(fdir,"RAxML_distances.Wang.nxs"))
+raxml.tree <- read.tree(file.path(fdir,"RAxML_bestTree.Wang.out")) %>% unroot
+raxml.bootstrap <- read.tree(file.path(fdir,"RAxML_bootstrap.Wang.out"))
+
+bs_splits <- as.splits(raxml.bootstrap)
+tree_splits <- as.splits(raxml.tree) %>% unique %>% removeTrivialSplits
+# we overwrite bootstrap values and set the weights 
+# to 1e-6 (almost zero), as we plot them on a log scale later on
+attr(bs_splits, "weights")[] <- 1e-6
+# combine the splits from the bootstrap and neighbor net
+# and delete duplicates and add the confidence values
+# we get rid of trivial splits
+all_splits <- c(Nnet$splits, bs_splits) %>% unique %>% removeTrivialSplits %>% addConfidences(bs_splits, scaler=100)
+
+# For easier plotting we create a matrix with the confidences and 
+# weights as columns
+tab <- data.frame(SplitWeight = attr(all_splits, "weights"), Bootstrap=attr(all_splits, "confidences"), Tree=FALSE)
+# we add a logical variable pto indicate which splits are in the RAxML tree
+tab$Tree[matchSplits(tree_splits, all_splits, FALSE)] = TRUE
+
+tab[is.na(tab[,"Bootstrap"]),"Bootstrap"] <- 0
+tab[,"Bootstrap"] <- round(tab[,"Bootstrap"])
+rownames(tab) <- apply(as.matrix(all_splits, zero.print = ".", one.print = "|"), 1, paste0, collapse="")
+tab[1:10,]
+
+col <- rep("blue", nrow(tab))
+col[tab[,"Bootstrap"]==0] <- "green"
+col[tab[,"SplitWeight"]==1e-6] <- "red"
+
+pch = rep(19, nrow(tab))
+pch[tab$Tree] <- 17
+
+par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)
+plot(tab[,"SplitWeight"], tab[,"Bootstrap"], log="x", col=col, pch=pch,  
+     xlab="Split weight (log scale)", ylab="Bootstrap (%)")
+legend("topright", inset=c(-0.35,0), c("Pattern 1", "Pattern 2", "Pattern 3", "Pattern in the\nbest tree"), pch=c(19,19,19,17), col=c("blue", "green", "red", "black"), bty="n")
+
+## ------------------------------------------------------------------------
+YCh <- read.tree(file.path(fdir, "RAxML_bestTree.YCh")) 
+mtG <- read.tree(file.path(fdir, "RAxML_bestTree.mtG")) 
+ncAI <- read.tree(file.path(fdir, "RAxML_bestTree.AIs")) 
+all_data <- read.tree(file.path(fdir, "RAxML_bestTree.3moles")) 
+YCh_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.YCh")) 
+mtG_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.mtG")) 
+ncAI_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.AIs")) 
+all_data_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.3moles")) 
+
+## ------------------------------------------------------------------------
+par(mfrow=c(2,2), mar = c(2,2,4,2))
+YCh <- plotBS(midpoint(YCh), YCh_boot, "phylogram", p=0, main = "YCh")
+mtG <- plotBS(midpoint(mtG), mtG_boot, "phylogram", p=0, main = "mtG")
+ncAI <- plotBS(midpoint(ncAI), ncAI_boot, "phylogram", p=0, main = "ncAI")
+all_data <- plotBS(midpoint(all_data), all_data_boot, "phylogram", p=0, main = "All data")
+
+## ---- small.mar=TRUE-----------------------------------------------------
+par(mfrow=c(1,1))
+cn <- consensusNet(c(YCh, mtG, ncAI))
+cn <- addConfidences(cn, YCh_boot) %>% addConfidences(mtG_boot, add=TRUE) %>% addConfidences(ncAI_boot, add=TRUE) %>% addConfidences(all_data_boot, add=TRUE)
+plot(cn, "2D", show.edge.label=TRUE)
+
diff --git a/inst/doc/IntertwiningTreesAndNetworks.Rmd b/inst/doc/IntertwiningTreesAndNetworks.Rmd
index 53a147a..a69dd60 100644
--- a/inst/doc/IntertwiningTreesAndNetworks.Rmd
+++ b/inst/doc/IntertwiningTreesAndNetworks.Rmd
@@ -2,21 +2,28 @@
 title: 'Intertwining phylogenetic trees and networks: R Example Script'
 author: "Klaus Schliep, Alastair Potts, David Morrison and Guido Grimm"
 date: "`r format(Sys.time(), '%B %d, %Y')`"
+bibliography: phangorn.bib
 output: rmarkdown::html_vignette
 vignette: >
    %\VignetteIndexEntry{IntertwiningTreesAndNetworks}
    %\VignetteEngine{knitr::rmarkdown}
    %\usepackage[utf8]{inputenc}
 ---
-
+[comment]: # (output: html_document)
 
 ```{r setup, echo=FALSE}
 # set global chunk options: images will be bigger
-knitr::opts_chunk$set(fig.width=7, fig.height=7) 
+  knitr::opts_chunk$set(fig.width=6, fig.height=6)
+#, global.par=TRUE
 options(digits = 4)
+
+knitr::knit_hooks$set(small.mar=function(before, options, envir){
+   if (before && options$fig.show!='none') par(mar=c(.5,.5,.5,.5))
+})
 ```
 
 
+
 *Description:* This script provides examples of the new functions available in the phangorn library to 'intertwine' trees and networks, i.e. compare trees and networks and data transferrance. It also provides a step-by-step guide for users new to R. 
 
 *Methodological advancement:* The major advancement in this phangorn update is the introduction of a generic network object with a wide range of related transfer and analysis functions. These new functions provide the first means to directly transfer information amongst a wide range of phylogenetic trees and networks, as well as means to visualise and further analyse this information. This should provide a platform for individuals to easily conduct tree-network comparisons and stimulate  [...]
@@ -45,12 +52,13 @@ install_github("KlausVigo/phangorn")
 ### Getting started                                                  
 ```{r}
 library(phangorn)    # load the phangorn library
+library(magrittr)  
 ```
 
 ### Set the working directory
 This is often a major stumbling block for new R users. You need to specify where in your folder structure you wish to work. i.e, where are the files stored that you wish to input?
 
-This is done using the setwd() function, e.g. setwd("C:/TreesNetworks/Example Files").
+This is done using the `setwd()` function, e.g. `setwd("C:/TreesNetworks/Example Files")`.
 
 We now set it to the folder of the phangorn package, which contains the files we want to load for this example.
 
@@ -90,7 +98,7 @@ All example files read into R.
 
 ### Viewing the data   
 ```{r}
-par(mfrow=c(1,2), mar=c(2,2,2,2)) # Setting plot parameters
+par(mfrow=c(1,2), mar=c(1,1,1,1)) # Setting plot parameters
 ### Plotting trees with support values:
 ##  RAxML
 plot(raxml.tree)
@@ -101,7 +109,7 @@ nodelabels(mrbayes.tree$node.label, adj = c(1, 0), frame = "none")
 
 par(mfrow=c(1,1)) # Setting plot parameters
 # NeighbourNet
-plot.networx(Nnet,"2D")
+plot(Nnet,"2D")
 ## alternatively,
 # plot(Nnet,"2D")
 
@@ -111,16 +119,15 @@ plot.networx(Nnet,"2D")
 ### 1A: 
 Identification of edge bundles (in black) in a neighbour-net (NN) network that correspond to branches (labelled 1-12) in a tree (a maximum likelihood tree, in this case). 
 
-```{r} 
+```{r, fig.width=7, fig.height=4, small.mar=TRUE} 
 # create a vector of labels for the network corresponding to edges in the tree
 edge.lab <- createLabel(Nnet, raxml.tree, raxml.tree$edge[,2], "edge")
 # could be also 1:27 instead of raxml.tree$edge[,2]
 
 # Show the correspondingly labelled tree and network in R
-par(mfrow=c(1,2), mar=c(1,1,1,1))
-#plotBS(raxml.tree, rotate.tree = 180) 
-plot(raxml.tree, "u", rotate.tree = 180) 
-edgelabels(raxml.tree$edge[,2],col="blue", frame="none")
+par(mfrow=c(1,2))  
+plot(raxml.tree, "u", rotate.tree = 180, cex=.7) 
+edgelabels(raxml.tree$edge[,2],col="blue", frame="none", cex=.7)
 
 # find edges that are in the network but not in the tree
 edge.col <- rep("black", nrow(Nnet$edge))
@@ -128,8 +135,8 @@ edge.col[ is.na(edge.lab) ] <- "red"
 # or a simpler alternative...
 edge.col <- createLabel(Nnet, raxml.tree, "black", nomatch="red")
 
-x <- plot.networx(Nnet, edge.label = edge.lab, show.edge.label = T, "2D", edge.color = edge.col,
-                  col.edge.label = "blue")
+x <- plot(Nnet, edge.label = edge.lab, show.edge.label = T, "2D", edge.color = edge.col,
+                  col.edge.label = "blue", cex=.7)
 # the above plot function returns an invisible networx object and this object also  
 # contains the colors for the edges.
 
@@ -138,8 +145,10 @@ x <- plot.networx(Nnet, edge.label = edge.lab, show.edge.label = T, "2D", edge.c
 
 ### 1B: 
 Bootstrap support for all branches (branch labels) in the ML tree mapped on the corresponding edge bundles of the NN network. The edges in the network which are not found as ML tree branches are highlighted in red.
-```{r}   
-x <- addConfidences(Nnet,raxml.tree)
+```{r, small.mar=TRUE}   
+# the scaler argument multiplies the confidence values. This is useful to switch
+# confidences values between total, percentage or ratios.   
+x <- addConfidences(Nnet,raxml.tree, scaler = .01)
 # find splits that are in the network but not in the tree
 split.col <- rep("black", length(x$splits))
 split.col[ !matchSplits(as.splits(x), as.splits(raxml.tree)) ] <- "red"
@@ -148,9 +157,9 @@ split.col[ !matchSplits(as.splits(x), as.splits(raxml.tree)) ] <- "red"
 split.col2 <- createLabel(x, raxml.tree, label="black", "split", nomatch="red")
 
 # Plotting in R
-par(mfrow=c(1,1))
-out.x <- plot.networx(x,"2D",show.edge.label=TRUE, split.color=split.col, col.edge.label = "blue")
+out.x <- plot(x,"2D",show.edge.label=TRUE, split.color=split.col, col.edge.label = "blue")
 ```
+
 Again we can write to SplitsTree for viewing...
 ```{r}
 # write.nexus.networx(out.x,"woodmouse.tree.support.nxs")
@@ -162,7 +171,7 @@ Again we can write to SplitsTree for viewing...
 Frequencies of bipartitions found in the bootstrap pseudoreplicates mapped on the corresponding edge bundles of the NN network using a threshold of 10% (i.e. any edge is labelled that occurs in at least 
 100 of the 1000 ML-BS pseudoreplicates). Edge bundles not found in the ML tree are labelled using grey edges.
 
-```{r}
+```{r, small.mar=TRUE}
 y <- addConfidences(Nnet, as.splits(raxml.bootstrap))
 edge.col <- createLabel(y, raxml.tree, label="black", "edge", nomatch="grey")
 
@@ -174,17 +183,110 @@ y <- plot(y,"2D",show.edge.label=TRUE, edge.color=edge.col)
 
 ### Extras...
 We can also compare the neighborNet with a consensusNet (Holland BR, Huber KT, Moulton V, Lockhart PJ,2004, Using consensus networks to visualize contradictory evidence for species phylogeny. Molecular Biology and Evolution, 21, 1459-1461). Furthermore, we can extract the support values from the consensus network, and place these on to the NeighbourNet (this is similar to the process explained in 1C above).
-```{r}
+```{r, small.mar=TRUE}
 cnet <- consensusNet(raxml.bootstrap,prob=0.10)
 edge.col <- createLabel(cnet, Nnet, label="black", "edge", nomatch="grey")
-cnet <- plot.networx(cnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
+cnet <- plot(cnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
 
 edge.col <- createLabel(Nnet, cnet, label="black", "edge", nomatch="grey")
-z <- plot.networx(Nnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
+z <- plot(Nnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
 
 obj <- addConfidences(Nnet,cnet)
-plot.networx(obj,"2D",show.edge.label=T, edge.color=edge.col, col.edge.label = "blue")
+plot(obj,"2D",show.edge.label=T, edge.color=edge.col, col.edge.label = "blue")
 
 ## Write to SplitsTree for viewing
 # write.nexus.networx(obj,"Nnet.with.ML.Cnet.Bootstrap.nxs")
 ```
+
+
+### 
+There are four possible data patterns in phylogenetic reconstruction: (1) patterns that are well supported in the network and appear in the bootstapped trees; (2) patterns that are well supported by (part of) the data/network but do not appear in the optimised trees, i.e. they are incompatible with the tree; (3) patterns that are weakly supported by the network but appear in the optimised trees anyway, i.e. they are compatible with the tree. 
+
+Here we demonstrate these patterns by showing the relationships between splits weights, from a NeighborNet splits graph, bootstrap bipartitions support and bootstrap percentages plotted on the optimised tree for a dataset of @Wang2012. 
+
+(An advanced user figure...)
+```{r, fig.width=7, fig.height=6}
+Nnet <- read.nexus.networx(file.path(fdir,"RAxML_distances.Wang.nxs"))
+raxml.tree <- read.tree(file.path(fdir,"RAxML_bestTree.Wang.out")) %>% unroot
+raxml.bootstrap <- read.tree(file.path(fdir,"RAxML_bootstrap.Wang.out"))
+
+bs_splits <- as.splits(raxml.bootstrap)
+tree_splits <- as.splits(raxml.tree) %>% unique %>% removeTrivialSplits
+# we overwrite bootstrap values and set the weights 
+# to 1e-6 (almost zero), as we plot them on a log scale later on
+attr(bs_splits, "weights")[] <- 1e-6
+# combine the splits from the bootstrap and neighbor net
+# and delete duplicates and add the confidence values
+# we get rid of trivial splits
+all_splits <- c(Nnet$splits, bs_splits) %>% unique %>% removeTrivialSplits %>% addConfidences(bs_splits, scaler=100)
+
+# For easier plotting we create a matrix with the confidences and 
+# weights as columns
+tab <- data.frame(SplitWeight = attr(all_splits, "weights"), Bootstrap=attr(all_splits, "confidences"), Tree=FALSE)
+# we add a logical variable pto indicate which splits are in the RAxML tree
+tab$Tree[matchSplits(tree_splits, all_splits, FALSE)] = TRUE
+
+tab[is.na(tab[,"Bootstrap"]),"Bootstrap"] <- 0
+tab[,"Bootstrap"] <- round(tab[,"Bootstrap"])
+rownames(tab) <- apply(as.matrix(all_splits, zero.print = ".", one.print = "|"), 1, paste0, collapse="")
+tab[1:10,]
+
+col <- rep("blue", nrow(tab))
+col[tab[,"Bootstrap"]==0] <- "green"
+col[tab[,"SplitWeight"]==1e-6] <- "red"
+
+pch = rep(19, nrow(tab))
+pch[tab$Tree] <- 17
+
+par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)
+plot(tab[,"SplitWeight"], tab[,"Bootstrap"], log="x", col=col, pch=pch,  
+     xlab="Split weight (log scale)", ylab="Bootstrap (%)")
+legend("topright", inset=c(-0.35,0), c("Pattern 1", "Pattern 2", "Pattern 3", "Pattern in the\nbest tree"), pch=c(19,19,19,17), col=c("blue", "green", "red", "black"), bty="n")
+```
+
+### Figure 4
+
+```{r} 
+YCh <- read.tree(file.path(fdir, "RAxML_bestTree.YCh")) 
+mtG <- read.tree(file.path(fdir, "RAxML_bestTree.mtG")) 
+ncAI <- read.tree(file.path(fdir, "RAxML_bestTree.AIs")) 
+all_data <- read.tree(file.path(fdir, "RAxML_bestTree.3moles")) 
+YCh_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.YCh")) 
+mtG_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.mtG")) 
+ncAI_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.AIs")) 
+all_data_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.3moles")) 
+```
+
+There are several option plotting a co-phylogeny. In the following we use the 
+`cophylo` function of the `phytools` package. 
+
+[comment]: # ({r cophylo, fig.width=7, fig.height=7})
+```
+library(phytools)
+par(mfrow=c(2,1))
+obj <- cophylo(YCh, mtG) 
+plot(obj, mar=c(.1,.1,2,.1),scale.bar=c(.005,.05), ylim=c(-.2,1))  
+title("A. YCh                                    B. mtG")
+obj <-  cophylo(ncAI, all_data)
+plot(obj, mar=c(.1,.1,2,.1),scale.bar=c(.005,.05), ylim=c(-.2,1))
+title("C. ncAI                              D. All data")
+```
+![](cophylo.png)
+Unfortunately this function does not (yet) offer to add confidences 
+to some splits, but we can do this easily with more basic plot functions. 
+```{r}
+par(mfrow=c(2,2), mar = c(2,2,4,2))
+YCh <- plotBS(midpoint(YCh), YCh_boot, "phylogram", p=0, main = "YCh")
+mtG <- plotBS(midpoint(mtG), mtG_boot, "phylogram", p=0, main = "mtG")
+ncAI <- plotBS(midpoint(ncAI), ncAI_boot, "phylogram", p=0, main = "ncAI")
+all_data <- plotBS(midpoint(all_data), all_data_boot, "phylogram", p=0, main = "All data")
+```
+
+We can compare this with consensus network with the different bootstrap values for the different genes. 
+```{r, small.mar=TRUE}
+par(mfrow=c(1,1))
+cn <- consensusNet(c(YCh, mtG, ncAI))
+cn <- addConfidences(cn, YCh_boot) %>% addConfidences(mtG_boot, add=TRUE) %>% addConfidences(ncAI_boot, add=TRUE) %>% addConfidences(all_data_boot, add=TRUE)
+plot(cn, "2D", show.edge.label=TRUE)
+```
+
diff --git a/inst/doc/IntertwiningTreesAndNetworks.html b/inst/doc/IntertwiningTreesAndNetworks.html
index f273268..7ddd5d8 100644
--- a/inst/doc/IntertwiningTreesAndNetworks.html
+++ b/inst/doc/IntertwiningTreesAndNetworks.html
@@ -4,7 +4,7 @@
 
 <head>
 
-<meta charset="utf-8">
+<meta charset="utf-8" />
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="generator" content="pandoc" />
 
@@ -12,7 +12,7 @@
 
 <meta name="author" content="Klaus Schliep, Alastair Potts, David Morrison and Guido Grimm" />
 
-<meta name="date" content="2016-12-03" />
+<meta name="date" content="2017-04-03" />
 
 <title>Intertwining phylogenetic trees and networks: R Example Script</title>
 
@@ -70,7 +70,7 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
 
 <h1 class="title toc-ignore">Intertwining phylogenetic trees and networks: R Example Script</h1>
 <h4 class="author"><em>Klaus Schliep, Alastair Potts, David Morrison and Guido Grimm</em></h4>
-<h4 class="date"><em>December 03, 2016</em></h4>
+<h4 class="date"><em>April 03, 2017</em></h4>
 
 
 
@@ -100,12 +100,13 @@ Select the nearest mirror to your location at <a href="https://cran.r-project.or
 </div>
 <div id="getting-started" class="section level3">
 <h3>Getting started</h3>
-<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(phangorn)    <span class="co"># load the phangorn library</span></code></pre></div>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(phangorn)    <span class="co"># load the phangorn library</span>
+<span class="kw">library</span>(magrittr)  </code></pre></div>
 </div>
 <div id="set-the-working-directory" class="section level3">
 <h3>Set the working directory</h3>
 <p>This is often a major stumbling block for new R users. You need to specify where in your folder structure you wish to work. i.e, where are the files stored that you wish to input?</p>
-<p>This is done using the setwd() function, e.g. setwd(“C:/TreesNetworks/Example Files”).</p>
+<p>This is done using the <code>setwd()</code> function, e.g. <code>setwd("C:/TreesNetworks/Example Files")</code>.</p>
 <p>We now set it to the folder of the phangorn package, which contains the files we want to load for this example.</p>
 </div>
 <div id="read-in-the-example-file-datasets" class="section level3">
@@ -142,7 +143,7 @@ Nnet <-<span class="st"> </span><span class="kw">read.nexus.networx</span>(<s
 </div>
 <div id="viewing-the-data" class="section level3">
 <h3>Viewing the data</h3>
-<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">2</span>), <span class="dt">mar=</span><span class="kw">c</span>(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">2</span>)) <span class="co"># Setting plot parameters</span>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">2</span>), <span class="dt">mar=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>)) <span class="co"># Setting plot parameters</span>
 ### Plotting trees with support values:
 ##  RAxML
 <span class="kw">plot</span>(raxml.tree)
@@ -150,11 +151,11 @@ Nnet <-<span class="st"> </span><span class="kw">read.nexus.networx</span>(<s
 ##  MrBayes
 <span class="kw">plot</span>(mrbayes.tree)
 <span class="kw">nodelabels</span>(mrbayes.tree$node.label, <span class="dt">adj =</span> <span class="kw">c</span>(<span class="dv">1</span>, <span class="dv">0</span>), <span class="dt">frame =</span> <span class="st">"none"</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAMAAABz4j/3AAAC/VBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAMAAABSRCkEAAAC/VBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>)) <span class="co"># Setting plot parameters</span>
 <span class="co"># NeighbourNet</span>
-<span class="kw">plot.networx</span>(Nnet,<span class="st">"2D"</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAMAAABz4j/3AAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<span class="kw">plot</span>(Nnet,<span class="st">"2D"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAMAAABSRCkEAAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">## alternatively,
 <span class="co"># plot(Nnet,"2D")</span></code></pre></div>
 </div>
@@ -169,10 +170,9 @@ edge.lab <-<span class="st"> </span><span class="kw">createLabel</span>(Nnet,
 <span class="co"># could be also 1:27 instead of raxml.tree$edge[,2]</span>
 
 <span class="co"># Show the correspondingly labelled tree and network in R</span>
-<span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">2</span>), <span class="dt">mar=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>))
-<span class="co">#plotBS(raxml.tree, rotate.tree = 180) </span>
-<span class="kw">plot</span>(raxml.tree, <span class="st">"u"</span>, <span class="dt">rotate.tree =</span> <span class="dv">180</span>) 
-<span class="kw">edgelabels</span>(raxml.tree$edge[,<span class="dv">2</span>],<span class="dt">col=</span><span class="st">"blue"</span>, <span class="dt">frame=</span><span class="st">"none"</span>)
+<span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">2</span>))  
+<span class="kw">plot</span>(raxml.tree, <span class="st">"u"</span>, <span class="dt">rotate.tree =</span> <span class="dv">180</span>, <span class="dt">cex=</span>.<span class="dv">7</span>) 
+<span class="kw">edgelabels</span>(raxml.tree$edge[,<span class="dv">2</span>],<span class="dt">col=</span><span class="st">"blue"</span>, <span class="dt">frame=</span><span class="st">"none"</span>, <span class="dt">cex=</span>.<span class="dv">7</span>)
 
 <span class="co"># find edges that are in the network but not in the tree</span>
 edge.col <-<span class="st"> </span><span class="kw">rep</span>(<span class="st">"black"</span>, <span class="kw">nrow</span>(Nnet$edge))
@@ -180,16 +180,18 @@ edge.col[ <span class="kw">is.na</span>(edge.lab) ] <-<span class="st"> &quot
 <span class="co"># or a simpler alternative...</span>
 edge.col <-<span class="st"> </span><span class="kw">createLabel</span>(Nnet, raxml.tree, <span class="st">"black"</span>, <span class="dt">nomatch=</span><span class="st">"red"</span>)
 
-x <-<span class="st"> </span><span class="kw">plot.networx</span>(Nnet, <span class="dt">edge.label =</span> edge.lab, <span class="dt">show.edge.label =</span> T, <span class="st">"2D"</span>, <span class="dt">edge.color =</span> edge.col,
-                  <span class="dt">col.edge.label =</span> <span class="st">"blue"</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAIAAADLXliSAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAgAElEQVR4nOzdZ1wU194H8P/Qy9KLotSgiIiKImIApYgNkgcEjfeKV6MmMUZNLKhR8QomsYG9BBITE0CU2EvwKpYYNYpA1IgSxYIFQRRBqQK753kxcTKCEqLEleH3/fhi55w9s7Or7m/nzJlzOMYYAQAAgLSoKPsAAAAAoOkh4AEAACQIAQ8AACBBCHgAAAAJQsADAABIEAIeAABAghDwAAAAEoSABwAAkCAEPAAAgAQh4AEAACQIAQ8AACBBCHgAAAAJQsADAABIEAIeAABAghDwAAAAEoSABwAAkCAEPAAAgAQh4AEAACQIAQ8AACBBCHgAAAAJQsADAABIEAIeAABAghDwAAAAEoSABwAAkCAEPAAAgAQh4AEAACQIA [...]
+x <-<span class="st"> </span><span class="kw">plot</span>(Nnet, <span class="dt">edge.label =</span> edge.lab, <span class="dt">show.edge.label =</span> T, <span class="st">"2D"</span>, <span class="dt">edge.color =</span> edge.col,
+                  <span class="dt">col.edge.label =</span> <span class="st">"blue"</span>, <span class="dt">cex=</span>.<span class="dv">7</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAGACAIAAAD9Gkc5AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAgAElEQVR4nOzdd1gU1/o48HdpS1Fw6QKC4C4KRKUXacZorgoKsZcLGEiUa9QAFuIVsZByoygb8zWCiho1iKhBBVFjBBVRmmADkSKIrFIM0llgd8/vj4n7I2AMKjKwvJ/H58nM4czZdzaw787MKQxCCCCEEEJIskjRHQBCCCGEeh8meIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCYYJHCCGEJBAmeIQQQkgCY [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># the above plot function returns an invisible networx object and this object also  </span>
 <span class="co"># contains the colors for the edges.</span></code></pre></div>
 </div>
 <div id="b" class="section level3">
 <h3>1B:</h3>
 <p>Bootstrap support for all branches (branch labels) in the ML tree mapped on the corresponding edge bundles of the NN network. The edges in the network which are not found as ML tree branches are highlighted in red.</p>
-<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">x <-<span class="st"> </span><span class="kw">addConfidences</span>(Nnet,raxml.tree)
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># the scaler argument multiplies the confidence values. This is useful to switch</span>
+<span class="co"># confidences values between total, percentage or ratios.   </span>
+x <-<span class="st"> </span><span class="kw">addConfidences</span>(Nnet,raxml.tree, <span class="dt">scaler =</span> .<span class="dv">01</span>)
 <span class="co"># find splits that are in the network but not in the tree</span>
 split.col <-<span class="st"> </span><span class="kw">rep</span>(<span class="st">"black"</span>, <span class="kw">length</span>(x$splits))
 split.col[ !<span class="kw">matchSplits</span>(<span class="kw">as.splits</span>(x), <span class="kw">as.splits</span>(raxml.tree)) ] <-<span class="st"> "red"</span>
@@ -198,9 +200,9 @@ split.col[ !<span class="kw">matchSplits</span>(<span class="kw">as.splits</span
 split.col2 <-<span class="st"> </span><span class="kw">createLabel</span>(x, raxml.tree, <span class="dt">label=</span><span class="st">"black"</span>, <span class="st">"split"</span>, <span class="dt">nomatch=</span><span class="st">"red"</span>)
 
 <span class="co"># Plotting in R</span>
-<span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>))
-out.x <-<span class="st"> </span><span class="kw">plot.networx</span>(x,<span class="st">"2D"</span>,<span class="dt">show.edge.label=</span><span class="ot">TRUE</span>, <span class="dt">split.color=</span>split.col, <span class="dt">col.edge.label =</span> <span class="st">"blue"</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAIAAADLXliSAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAgAElEQVR4nOzde1wU9f4/8NcACivLTUABBUUUUDRRREpQQfRY0lFQ03PC9GjnpGQWpubR9CfYQ830KGoX6HL65gWl8JphgpmVZgikJkqKclMugiByF2Hm98fkuIHHLIFdttfz0R877898Zj87j/C1MzvzGUGSJBAREZF+MdD2AIiIiKjlMeCJiIj0EAOeiIhIDzHgiYiI9BADnoiISA8x4ImIiPQQA56IiEgPMeCJiIj0EAOeiIhIDzHgiYiI9BADnoiISA8x4ImIiPQQA56IiEgPMeCJiIj0EAOeiIhIDzHgiYiI9BADnoiISA8x4ImIiPQQA56IiEgPMeCJiIj0EAOeiIhIDzHgiYiI9BADnoiISA8x4ImIiPQQA56Ii [...]
+out.x <-<span class="st"> </span><span class="kw">plot</span>(x,<span class="st">"2D"</span>,<span class="dt">show.edge.label=</span><span class="ot">TRUE</span>, <span class="dt">split.color=</span>split.col, <span class="dt">col.edge.label =</span> <span class="st">"blue"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAIAAADq+E5hAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAgAElEQVR4nOzde1wVdf4/8NcAAkfuAgoqGKJcvASKSAkoiK0lbYLXNlDT9rtqdtG03LwE2GpqrqJWQlvbLyWFQkUzd+WYd9cUyEpcQlRAl4soiFwOiJwzvz9Gp+PBvIEcD7yeDx+PZt5zOZ+ZxBcz5zOfEURRBBERkaEx0ncDiIiIHgYDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiIDBIDjIiID [...]
+<p>Again we can write to SplitsTree for viewing…</p>
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># write.nexus.networx(out.x,"woodmouse.tree.support.nxs")</span>
 ## or we can also export the splits alone (for usage in software other than SplitsTree)
 <span class="co"># write.nexus.splits(as.splits(out.x),"woodmouse.splits.support.nxs")</span></code></pre></div>
@@ -212,7 +214,7 @@ out.x <-<span class="st"> </span><span class="kw">plot.networx</span>(x,<span
 edge.col <-<span class="st"> </span><span class="kw">createLabel</span>(y, raxml.tree, <span class="dt">label=</span><span class="st">"black"</span>, <span class="st">"edge"</span>, <span class="dt">nomatch=</span><span class="st">"grey"</span>)
 
 y <-<span class="st"> </span><span class="kw">plot</span>(y,<span class="st">"2D"</span>,<span class="dt">show.edge.label=</span><span class="ot">TRUE</span>, <span class="dt">edge.color=</span>edge.col)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAMAAABz4j/3AAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAMAAABSRCkEAAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">## Write to SplitsTree for viewing
 <span class="co"># write.nexus.networx(y,"NN.with.bs.support.nxs")</span></code></pre></div>
 </div>
@@ -221,17 +223,108 @@ y <-<span class="st"> </span><span class="kw">plot</span>(y,<span class="st">
 <p>We can also compare the neighborNet with a consensusNet (Holland BR, Huber KT, Moulton V, Lockhart PJ,2004, Using consensus networks to visualize contradictory evidence for species phylogeny. Molecular Biology and Evolution, 21, 1459-1461). Furthermore, we can extract the support values from the consensus network, and place these on to the NeighbourNet (this is similar to the process explained in 1C above).</p>
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">cnet <-<span class="st"> </span><span class="kw">consensusNet</span>(raxml.bootstrap,<span class="dt">prob=</span><span class="fl">0.10</span>)
 edge.col <-<span class="st"> </span><span class="kw">createLabel</span>(cnet, Nnet, <span class="dt">label=</span><span class="st">"black"</span>, <span class="st">"edge"</span>, <span class="dt">nomatch=</span><span class="st">"grey"</span>)
-cnet <-<span class="st"> </span><span class="kw">plot.networx</span>(cnet, <span class="st">"2D"</span>, <span class="dt">show.edge.label =</span> <span class="ot">TRUE</span>, <span class="dt">edge.color=</span>edge.col)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAMAAABz4j/3AAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+cnet <-<span class="st"> </span><span class="kw">plot</span>(cnet, <span class="st">"2D"</span>, <span class="dt">show.edge.label =</span> <span class="ot">TRUE</span>, <span class="dt">edge.color=</span>edge.col)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAMAAABSRCkEAAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">edge.col <-<span class="st"> </span><span class="kw">createLabel</span>(Nnet, cnet, <span class="dt">label=</span><span class="st">"black"</span>, <span class="st">"edge"</span>, <span class="dt">nomatch=</span><span class="st">"grey"</span>)
-z <-<span class="st"> </span><span class="kw">plot.networx</span>(Nnet, <span class="st">"2D"</span>, <span class="dt">show.edge.label =</span> <span class="ot">TRUE</span>, <span class="dt">edge.color=</span>edge.col)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAMAAABz4j/3AAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+z <-<span class="st"> </span><span class="kw">plot</span>(Nnet, <span class="st">"2D"</span>, <span class="dt">show.edge.label =</span> <span class="ot">TRUE</span>, <span class="dt">edge.color=</span>edge.col)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAMAAABSRCkEAAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">obj <-<span class="st"> </span><span class="kw">addConfidences</span>(Nnet,cnet)
-<span class="kw">plot.networx</span>(obj,<span class="st">"2D"</span>,<span class="dt">show.edge.label=</span>T, <span class="dt">edge.color=</span>edge.col, <span class="dt">col.edge.label =</span> <span class="st">"blue"</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAIAAADLXliSAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAgAElEQVR4nOzdeVQUV8I28KcBhZZmE1BQaUUUUDAiiKiggppXI5mISzQZTRzNosaYYNzi9gqZ4+4oamLETN58cUGIuI6SCMYYE+NANxpHjAsugLKIgsjSINBd3x+lZQvGOBHppn1+x3PSfW/d27frRJ+uqlu3ZIIggIiIiEyLmaEHQERERA2PAU9ERGSCGPBEREQmiAFPRERkghjwREREJogBT0REZIIY8ERERCaIAU9ERGSCGPBEREQmiAFPRERkghjwREREJogBT0REZIIY8ERERCaIAU9ERGSCGPBEREQmiAFPRERkghjwREREJogBT0REZIIY8ERERCaIAU9ERGSCGPBEREQmiAFPRERkghjwREREJogBT0REZIIY8 [...]
+<span class="kw">plot</span>(obj,<span class="st">"2D"</span>,<span class="dt">show.edge.label=</span>T, <span class="dt">edge.color=</span>edge.col, <span class="dt">col.edge.label =</span> <span class="st">"blue"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAIAAADq+E5hAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAgAElEQVR4nOzde1xN+f4/8NeqVFu7my4q2iS6uEbSIHRhzMhQcjlnMkzmdw7GZXLcjjCVOe4OyTBlxsz30KQIcWhObcdgNIZqzIxtmkQ3p4so6bJL2vvz+2Ox7NkZ99p2vZ8Pf+z9WbfPWuTVWuuz3otjjIEQQgjRNjqa7gAhhBDyIijACCGEaCUKMEIIIVqJAowQQohWogAjhBCilSjACCGEaCUKMEIIIVqJAowQQohWogAjhBCilSjACCGEaCUKMEIIIVqJAowQQohWogAjhBCilSjACCGEaCUKMEIIIVqJAowQQohWogAjhBCilSjACCGEaCUKMEIIIVqJAowQQohWogAjhBCilSjACCGEaCUKMEIIIVqJAowQQohWo [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">## Write to SplitsTree for viewing
 <span class="co"># write.nexus.networx(obj,"Nnet.with.ML.Cnet.Bootstrap.nxs")</span></code></pre></div>
 </div>
+<div id="section" class="section level3">
+<h3></h3>
+<p>There are four possible data patterns in phylogenetic reconstruction: (1) patterns that are well supported in the network and appear in the bootstapped trees; (2) patterns that are well supported by (part of) the data/network but do not appear in the optimised trees, i.e. they are incompatible with the tree; (3) patterns that are weakly supported by the network but appear in the optimised trees anyway, i.e. they are compatible with the tree.</p>
+<p>Here we demonstrate these patterns by showing the relationships between splits weights, from a NeighborNet splits graph, bootstrap bipartitions support and bootstrap percentages plotted on the optimised tree for a dataset of <span class="citation">Wang, Braun, and Kimball (2012)</span>.</p>
+<p>(An advanced user figure…)</p>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">Nnet <-<span class="st"> </span><span class="kw">read.nexus.networx</span>(<span class="kw">file.path</span>(fdir,<span class="st">"RAxML_distances.Wang.nxs"</span>))
+raxml.tree <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir,<span class="st">"RAxML_bestTree.Wang.out"</span>)) %>%<span class="st"> </span>unroot
+raxml.bootstrap <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir,<span class="st">"RAxML_bootstrap.Wang.out"</span>))
+
+bs_splits <-<span class="st"> </span><span class="kw">as.splits</span>(raxml.bootstrap)
+tree_splits <-<span class="st"> </span><span class="kw">as.splits</span>(raxml.tree) %>%<span class="st"> </span>unique %>%<span class="st"> </span>removeTrivialSplits
+<span class="co"># we overwrite bootstrap values and set the weights </span>
+<span class="co"># to 1e-6 (almost zero), as we plot them on a log scale later on</span>
+<span class="kw">attr</span>(bs_splits, <span class="st">"weights"</span>)[] <-<span class="st"> </span><span class="fl">1e-6</span>
+<span class="co"># combine the splits from the bootstrap and neighbor net</span>
+<span class="co"># and delete duplicates and add the confidence values</span>
+<span class="co"># we get rid of trivial splits</span>
+all_splits <-<span class="st"> </span><span class="kw">c</span>(Nnet$splits, bs_splits) %>%<span class="st"> </span>unique %>%<span class="st"> </span>removeTrivialSplits %>%<span class="st"> </span><span class="kw">addConfidences</span>(bs_splits, <span class="dt">scaler=</span><span class="dv">100</span>)
+
+<span class="co"># For easier plotting we create a matrix with the confidences and </span>
+<span class="co"># weights as columns</span>
+tab <-<span class="st"> </span><span class="kw">data.frame</span>(<span class="dt">SplitWeight =</span> <span class="kw">attr</span>(all_splits, <span class="st">"weights"</span>), <span class="dt">Bootstrap=</span><span class="kw">attr</span>(all_splits, <span class="st">"confidences"</span>), <span class="dt">Tree=</span><span class="ot">FALSE</span>)
+<span class="co"># we add a logical variable pto indicate which splits are in the RAxML tree</span>
+tab$Tree[<span class="kw">matchSplits</span>(tree_splits, all_splits, <span class="ot">FALSE</span>)] =<span class="st"> </span><span class="ot">TRUE</span>
+
+tab[<span class="kw">is.na</span>(tab[,<span class="st">"Bootstrap"</span>]),<span class="st">"Bootstrap"</span>] <-<span class="st"> </span><span class="dv">0</span>
+tab[,<span class="st">"Bootstrap"</span>] <-<span class="st"> </span><span class="kw">round</span>(tab[,<span class="st">"Bootstrap"</span>])
+<span class="kw">rownames</span>(tab) <-<span class="st"> </span><span class="kw">apply</span>(<span class="kw">as.matrix</span>(all_splits, <span class="dt">zero.print =</span> <span class="st">"."</span>, <span class="dt">one.print =</span> <span class="st">"|"</span>), <span class="dv">1</span>, paste0, <span class="dt">collapse=</span><span class="st">""</span>)
+tab[<span class="dv">1</span>:<span class="dv">10</span>,]</code></pre></div>
+<pre><code>##                              SplitWeight Bootstrap  Tree
+## ..||........................   0.0171433       100  TRUE
+## ..||||......................   0.0013902        14 FALSE
+## ..||||......|||||...........   0.0001589         0 FALSE
+## ||.........................|   0.0027691         1 FALSE
+## ||..........................   0.0840367       100  TRUE
+## ...|||......................   0.0001773         0 FALSE
+## ...|||........|.|...........   0.0003663         0 FALSE
+## |.|.........................   0.0060907         0 FALSE
+## ....||......................   0.0385909       100  TRUE
+## ||||........................   0.0018195        34  TRUE</code></pre>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">col <-<span class="st"> </span><span class="kw">rep</span>(<span class="st">"blue"</span>, <span class="kw">nrow</span>(tab))
+col[tab[,<span class="st">"Bootstrap"</span>]==<span class="dv">0</span>] <-<span class="st"> "green"</span>
+col[tab[,<span class="st">"SplitWeight"</span>]==<span class="fl">1e-6</span>] <-<span class="st"> "red"</span>
+
+pch =<span class="st"> </span><span class="kw">rep</span>(<span class="dv">19</span>, <span class="kw">nrow</span>(tab))
+pch[tab$Tree] <-<span class="st"> </span><span class="dv">17</span>
+
+<span class="kw">par</span>(<span class="dt">mar=</span><span class="kw">c</span>(<span class="fl">5.1</span>, <span class="fl">4.1</span>, <span class="fl">4.1</span>, <span class="fl">8.1</span>), <span class="dt">xpd=</span><span class="ot">TRUE</span>)
+<span class="kw">plot</span>(tab[,<span class="st">"SplitWeight"</span>], tab[,<span class="st">"Bootstrap"</span>], <span class="dt">log=</span><span class="st">"x"</span>, <span class="dt">col=</span>col, <span class="dt">pch=</span>pch,  
+     <span class="dt">xlab=</span><span class="st">"Split weight (log scale)"</span>, <span class="dt">ylab=</span><span class="st">"Bootstrap (%)"</span>)
+<span class="kw">legend</span>(<span class="st">"topright"</span>, <span class="dt">inset=</span><span class="kw">c</span>(-<span class="fl">0.35</span>,<span class="dv">0</span>), <span class="kw">c</span>(<span class="st">"Pattern 1"</span>, <span class="st">"Pattern 2"</span>, <span class="st">"Pattern 3"</span>, <span class="st">"Pattern in the</span><span class="ch">\n</span><span class="st">best tree"</span>), <span class="dt">pch=< [...]
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAJACAIAAADdGkMQAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAgAElEQVR4nOzdeVxU5f4H8O8BWYaBWCYIFAEFRUcFV9JcUa9ZiKapIMIrKbRQNDPQ1DJwX0BQs/SGXjMRcMFELZcETLw/ESQ1IRXETFkkWQQUYRjO74+5TTDMsI6zHD/vV69eZ54z5zzfAeHDc5bnMCzLEgAAAHCLjroLAAAAAOVDwAMAAHAQAh4AAICDEPAAAAAchIAHAADgIAQ8AAAAByHgAQAAOAgBDwAAwEEIeAAAAA5CwAMAAHAQAh4AAICDEPAAAAAchIAHAADgIAQ8AAAAByHgAQAAOAgBDwAAwEEIeAAAAA5CwAMAAHAQAh4AAICDEPAAAAAchIAHAADgIAQ8AAAAByHgAQAAOAgBDwAAwEEIeAAAAA5CwAMAA [...]
+</div>
+<div id="figure-4" class="section level3">
+<h3>Figure 4</h3>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">YCh <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir, <span class="st">"RAxML_bestTree.YCh"</span>)) 
+mtG <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir, <span class="st">"RAxML_bestTree.mtG"</span>)) 
+ncAI <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir, <span class="st">"RAxML_bestTree.AIs"</span>)) 
+all_data <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir, <span class="st">"RAxML_bestTree.3moles"</span>)) 
+YCh_boot <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir, <span class="st">"RAxML_bootstrap.YCh"</span>)) 
+mtG_boot <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir, <span class="st">"RAxML_bootstrap.mtG"</span>)) 
+ncAI_boot <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir, <span class="st">"RAxML_bootstrap.AIs"</span>)) 
+all_data_boot <-<span class="st"> </span><span class="kw">read.tree</span>(<span class="kw">file.path</span>(fdir, <span class="st">"RAxML_bootstrap.3moles"</span>)) </code></pre></div>
+<p>There are several option plotting a co-phylogeny. In the following we use the <code>cophylo</code> function of the <code>phytools</code> package.</p>
+<pre><code>library(phytools)
+par(mfrow=c(2,1))
+obj <- cophylo(YCh, mtG) 
+plot(obj, mar=c(.1,.1,2,.1),scale.bar=c(.005,.05), ylim=c(-.2,1))  
+title("A. YCh                                    B. mtG")
+obj <-  cophylo(ncAI, all_data)
+plot(obj, mar=c(.1,.1,2,.1),scale.bar=c(.005,.05), ylim=c(-.2,1))
+title("C. ncAI                              D. All data")</code></pre>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAKgCAMAAABz4j/3AAAC/VBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">2</span>,<span class="dv">2</span>), <span class="dt">mar =</span> <span class="kw">c</span>(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">4</span>,<span class="dv">2</span>))
+YCh <-<span class="st"> </span><span class="kw">plotBS</span>(<span class="kw">midpoint</span>(YCh), YCh_boot, <span class="st">"phylogram"</span>, <span class="dt">p=</span><span class="dv">0</span>, <span class="dt">main =</span> <span class="st">"YCh"</span>)
+mtG <-<span class="st"> </span><span class="kw">plotBS</span>(<span class="kw">midpoint</span>(mtG), mtG_boot, <span class="st">"phylogram"</span>, <span class="dt">p=</span><span class="dv">0</span>, <span class="dt">main =</span> <span class="st">"mtG"</span>)
+ncAI <-<span class="st"> </span><span class="kw">plotBS</span>(<span class="kw">midpoint</span>(ncAI), ncAI_boot, <span class="st">"phylogram"</span>, <span class="dt">p=</span><span class="dv">0</span>, <span class="dt">main =</span> <span class="st">"ncAI"</span>)
+all_data <-<span class="st"> </span><span class="kw">plotBS</span>(<span class="kw">midpoint</span>(all_data), all_data_boot, <span class="st">"phylogram"</span>, <span class="dt">p=</span><span class="dv">0</span>, <span class="dt">main =</span> <span class="st">"All data"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAMAAABSRCkEAAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<p>We can compare this with consensus network with the different bootstrap values for the different genes.</p>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>))
+cn <-<span class="st"> </span><span class="kw">consensusNet</span>(<span class="kw">c</span>(YCh, mtG, ncAI))
+cn <-<span class="st"> </span><span class="kw">addConfidences</span>(cn, YCh_boot) %>%<span class="st"> </span><span class="kw">addConfidences</span>(mtG_boot, <span class="dt">add=</span><span class="ot">TRUE</span>) %>%<span class="st"> </span><span class="kw">addConfidences</span>(ncAI_boot, <span class="dt">add=</span><span class="ot">TRUE</span>) %>%<span class="st"> </span><span class="kw">addConfidences</span>(all_data_boot, <span class="dt">add=</span><span class="ot" [...]
+<span class="kw">plot</span>(cn, <span class="st">"2D"</span>, <span class="dt">show.edge.label=</span><span class="ot">TRUE</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAJACAMAAABSRCkEAAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<div id="refs" class="references">
+<div id="ref-Wang2012">
+<p>Wang, Ning, Edward L. Braun, and Rebecca T. Kimball. 2012. “Testing Hypotheses About the Sister Group of the Passeriformes Using an Independent 30-Locus Data Set.” <em>Molecular Biology and Evolution</em> 29 (2): 737–50. doi:<a href="https://doi.org/10.1093/molbev/msr230">10.1093/molbev/msr230</a>.</p>
+</div>
+</div>
+</div>
 
 
 
diff --git a/inst/doc/Networx.html b/inst/doc/Networx.html
index c020946..407876f 100644
--- a/inst/doc/Networx.html
+++ b/inst/doc/Networx.html
@@ -4,7 +4,7 @@
 
 <head>
 
-<meta charset="utf-8">
+<meta charset="utf-8" />
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta name="generator" content="pandoc" />
 
@@ -12,7 +12,7 @@
 
 <meta name="author" content="Klaus Schliep" />
 
-<meta name="date" content="2016-12-03" />
+<meta name="date" content="2017-04-03" />
 
 <title>Splits and Networx</title>
 
@@ -70,7 +70,7 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
 
 <h1 class="title toc-ignore">Splits and Networx</h1>
 <h4 class="author"><em>Klaus Schliep</em></h4>
-<h4 class="date"><em>December 03, 2016</em></h4>
+<h4 class="date"><em>April 03, 2017</em></h4>
 
 
 
@@ -93,7 +93,7 @@ tree <-<span class="st"> </span><span class="kw">plotBS</span>(tree, bs, <spa
 <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAAC91BMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZGRlZ [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">cnet <-<span class="st"> </span><span class="kw">consensusNet</span>(bs, .<span class="dv">3</span>)
 <span class="kw">plot</span>(cnet, <span class="st">"2D"</span>, <span class="dt">show.edge.label=</span><span class="ot">TRUE</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAAC/VBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAAC+lBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
 <p>In many cases, <code>consensusNet</code> will return more than two incompatible (competing) splits. This cannot be plotted as a planar (2-dimensional) graph. Such as situation requires a n-dimensional graph, where the maximum number of dimensions equals the maximum number of incompatible splits. For example, if we have three alternative incompatible splits: (A,B)|(C,D) vs. (A,C)|(B,D) vs. (A,D)|(B,C), we need a 3-dimensional graph to show all three alternatives. A nice way to get stil [...]
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">plot</span>(cnet)
 <span class="co"># rotate 3d plot</span>
@@ -122,14 +122,14 @@ nnet <-<span class="st"> </span><span class="kw">neighborNet</span>(dm)
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">nnet <-<span class="st"> </span><span class="kw">addConfidences</span>(nnet, tree)
 <span class="kw">par</span>(<span class="st">"mar"</span> =<span class="st"> </span><span class="kw">rep</span>(<span class="dv">1</span>, <span class="dv">4</span>))
 <span class="kw">plot</span>(nnet, <span class="st">"2D"</span>, <span class="dt">show.edge.label=</span><span class="ot">TRUE</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAAC/VBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAAC/VBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
 <p>Analogously, we can also add support values to a tree:</p>
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">tree2 <-<span class="st"> </span><span class="kw">rNNI</span>(tree, <span class="dv">2</span>)
 tree2 <-<span class="st"> </span><span class="kw">addConfidences</span>(tree2, tree)
 <span class="co"># several support values are missing</span>
 <span class="kw">par</span>(<span class="st">"mar"</span> =<span class="st"> </span><span class="kw">rep</span>(<span class="dv">1</span>, <span class="dv">4</span>))
 <span class="kw">plot</span>(tree2, <span class="dt">show.node.label=</span><span class="ot">TRUE</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAAC7lBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJERERFRUVGRkZISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZGRlZWVnZ [...]
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAAC61BMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJERERFRUVGRkZISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZGRlZWVnZ2doa [...]
 </div>
 <div id="estimating-edge-weights-nnls" class="section level2">
 <h2>Estimating edge weights (nnls)</h2>
@@ -137,7 +137,7 @@ tree2 <-<span class="st"> </span><span class="kw">addConfidences</span>(tree2
 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">cnet <-<span class="st"> </span><span class="kw">nnls.networx</span>(cnet, dm)
 <span class="kw">par</span>(<span class="st">"mar"</span> =<span class="st"> </span><span class="kw">rep</span>(<span class="dv">1</span>, <span class="dv">4</span>))
 <span class="kw">plot</span>(cnet, <span class="st">"2D"</span>, <span class="dt">show.edge.label=</span><span class="ot">TRUE</span>)</code></pre></div>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAMAAAAjXV6yAAADAFBMVEUAAAABAQECAgIDAwMEBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1eXl5fX19gYGBhYWFiYmJjY2NkZ [...]
 <div id="import-and-export-networks-advanced-functions-for-networx-objects" class="section level3">
 <h3>Import and export networks, advanced functions for networx objects</h3>
 <p>The functions <code>read.nexus.networx</code> and <code>write.nexus.networx</code> can read and write nexus files for or from SplitsTree <span class="citation">(Huson and Bryant 2006)</span>. Check-out the new vignette IntertwiningTreesAndNetworks for additional functions, examples, and advanced applications.</p>
diff --git a/inst/doc/Trees.R b/inst/doc/Trees.R
index bfac4da..079fdcc 100644
--- a/inst/doc/Trees.R
+++ b/inst/doc/Trees.R
@@ -12,8 +12,8 @@ options("show.signif.stars" = FALSE)
 ### code chunk number 2: Trees.Rnw:68-71
 ###################################################
 library(phangorn)
-primates <- read.phyDat("primates.dna", format="phylip", 
-    type="DNA")
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip")
 
 
 ###################################################
diff --git a/inst/doc/Trees.Rnw b/inst/doc/Trees.Rnw
index a77f5d4..7449492 100644
--- a/inst/doc/Trees.Rnw
+++ b/inst/doc/Trees.Rnw
@@ -67,8 +67,8 @@ The first thing we have to do is to read in an alignment. Unfortunately there ex
 We start our analysis loading the \phangorn{} package and then reading in an alignment.  
 <<echo=TRUE>>=
 library(phangorn)
-primates <- read.phyDat("primates.dna", format="phylip", 
-    type="DNA")
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip")
 @
 \section{Distance based methods}
 After reading in the alignment we can build a first tree with distance based methods. The function dist.dna from the ape package computes distances for many DNA substitution models. To use the function dist.dna we have to transform the data to class DNAbin. For amino acids the function \Rfunction{dist.ml} offers common substitution models (for example "WAG", "JTT", "LG", "Dayhoff", "cpREV", "mtmam", "mtArt", "MtZoa" or "mtREV24").  
diff --git a/inst/doc/Trees.pdf b/inst/doc/Trees.pdf
index 40c819c..7981e2d 100644
Binary files a/inst/doc/Trees.pdf and b/inst/doc/Trees.pdf differ
diff --git a/inst/doc/phangorn-specials.R b/inst/doc/phangorn-specials.R
index e2d28e6..4492415 100644
--- a/inst/doc/phangorn-specials.R
+++ b/inst/doc/phangorn-specials.R
@@ -65,10 +65,11 @@ fit
 
 
 ###################################################
-### code chunk number 7: phangorn-specials.Rnw:233-243
+### code chunk number 7: phangorn-specials.Rnw:233-244
 ###################################################
 library(phangorn)
-primates = read.phyDat("primates.dna", format="phylip", type="DNA")
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip", type = "DNA")
 tree <- NJ(dist.ml(primates))
 dat <- phyDat(as.character(primates), "CODON")
 fit <- pml(tree, dat)
@@ -97,13 +98,13 @@ for(i in 1:15)plot(trees[[i]], cex=1, type="u")
 
 
 ###################################################
-### code chunk number 10: phangorn-specials.Rnw:271-272
+### code chunk number 10: phangorn-specials.Rnw:272-273
 ###################################################
 trees = nni(trees[[1]])
 
 
 ###################################################
-### code chunk number 11: phangorn-specials.Rnw:283-284
+### code chunk number 11: phangorn-specials.Rnw:284-285
 ###################################################
 toLatex(sessionInfo())
 
diff --git a/inst/doc/phangorn-specials.Rnw b/inst/doc/phangorn-specials.Rnw
index 53b99b4..8d36b50 100644
--- a/inst/doc/phangorn-specials.Rnw
+++ b/inst/doc/phangorn-specials.Rnw
@@ -232,7 +232,8 @@ There are four models available:
 We compute the $d_N/d_S$ for some sequences given a tree using the ML functions \Rfunction{pml} and \Rfunction{optim.pml}. First we have to transform the the nucleotide sequences into codons (so far the algorithms always takes triplets). 
 <<echo=TRUE>>=
 library(phangorn)
-primates = read.phyDat("primates.dna", format="phylip", type="DNA")
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip", type = "DNA")
 tree <- NJ(dist.ml(primates))
 dat <- phyDat(as.character(primates), "CODON")
 fit <- pml(tree, dat)
diff --git a/inst/doc/phangorn-specials.pdf b/inst/doc/phangorn-specials.pdf
index 7ec2b88..4b6300e 100644
Binary files a/inst/doc/phangorn-specials.pdf and b/inst/doc/phangorn-specials.pdf differ
diff --git a/inst/extdata/trees/RAxML_bestTree.3moles b/inst/extdata/trees/RAxML_bestTree.3moles
new file mode 100644
index 0000000..01c2939
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bestTree.3moles
@@ -0,0 +1 @@
+((((Hma:0.03262045163347984666,Mur:0.03886458455630492637):0.00225499947410235475,Uth:0.02580682933153511174):0.00059392541543651757,(Uam:0.02931596331419318927,(Uar:0.00602522464221224522,Uma:0.00593640374580924231):0.02934241311799383120):0.00269684120306867619):0.06379221863907107160,Tor:0.09747395533792581335,Ame:0.24240784786309346743):0.0;
diff --git a/inst/extdata/trees/RAxML_bestTree.AIs b/inst/extdata/trees/RAxML_bestTree.AIs
new file mode 100644
index 0000000..ce18bc3
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bestTree.AIs
@@ -0,0 +1 @@
+(((Hma:0.00312706379726812329,(Uth:0.00121026052477198292,Mur:0.00312046250563168155):0.00087036069658183684):0.00122506270256386740,((Uar:0.00052373856518729458,Uma:0.00247018618187345041):0.00167792487939210548,Uam:0.00184159984063642979):0.00107249327886021345):0.00382497683824970002,Tor:0.00848622429823414105,Ame:0.02681059329595153473):0.0;
diff --git a/inst/extdata/trees/RAxML_bestTree.Wang.out b/inst/extdata/trees/RAxML_bestTree.Wang.out
new file mode 100644
index 0000000..1f4bfb3
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bestTree.Wang.out
@@ -0,0 +1 @@
+(((t2:0.14211731987709066982,t3:0.06053783689898680626):0.01915320533263515854,(((t26:0.10076663346788350406,t27:0.09012377576079726171):0.00617748657056873228,(((t24:0.05083401775033660058,t25:0.04968730003684527358):0.12390520932858628544,(((t18:0.22659556680242753934,t17:0.09828171476802796680):0.01533921899764495791,((t19:0.10129875525132767122,t20:0.12134488266574683379):0.00849558744650705938,(t21:0.14505926027183771443,t22:0.17551017119642836617):0.00877793060138474905):0.00308912 [...]
diff --git a/inst/extdata/trees/RAxML_bestTree.YCh b/inst/extdata/trees/RAxML_bestTree.YCh
new file mode 100644
index 0000000..19d0227
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bestTree.YCh
@@ -0,0 +1 @@
+((((Mur:0.00215666997155560154,Uth:0.00192023592185219349):0.00016696946772137622,Hma:0.00368686670740361357):0.00018687639400160564,(Uam:0.00135720565202207934,(Uma:0.00118651800822575332,Uar:0.00101739764390293918):0.00033775695210929856):0.00157503466397103213):0.00634369057289599098,Tor:0.00989995418842323435,Ame:0.02707461606876413254):0.0;
diff --git a/inst/extdata/trees/RAxML_bestTree.mtG b/inst/extdata/trees/RAxML_bestTree.mtG
new file mode 100644
index 0000000..74d1a76
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bestTree.mtG
@@ -0,0 +1 @@
+((Mur:0.07919097361296209558,((Uar:0.01286960617186264609,Uma:0.01148014536527527073):0.05944338095871280064,((Uam:0.06376626308156593814,Uth:0.05419104627017570786):0.00666893477206217944,Hma:0.06896198930015005890):0.00974981555038798714):0.00145717534115081442):0.13909717574901725445,Tor:0.19825987246617926552,Ame:0.42623829669506568818):0.0;
diff --git a/inst/extdata/trees/RAxML_bipartitions.3moles b/inst/extdata/trees/RAxML_bipartitions.3moles
new file mode 100644
index 0000000..deb7c34
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bipartitions.3moles
@@ -0,0 +1 @@
+(Ame:0.24240784786309346743,(((Hma:0.03262045163347984666,Mur:0.03886458455630492637)36:0.00225499947410235475,Uth:0.02580682933153511174)30:0.00059392541543651757,(Uam:0.02931596331419318927,(Uar:0.00602522464221224522,Uma:0.00593640374580924231)100:0.02934241311799383120)60:0.00269684120306867619)100:0.06379221863907107160,Tor:0.09747395533792581335);
diff --git a/inst/extdata/trees/RAxML_bipartitions.AIs b/inst/extdata/trees/RAxML_bipartitions.AIs
new file mode 100644
index 0000000..931982d
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bipartitions.AIs
@@ -0,0 +1 @@
+(Ame:0.02681059329595153473,((Hma:0.00312706379726812329,(Uth:0.00121026052477198292,Mur:0.00312046250563168155)39:0.00087036069658183684)42:0.00122506270256386740,((Uar:0.00052373856518729458,Uma:0.00247018618187345041)83:0.00167792487939210548,Uam:0.00184159984063642979)41:0.00107249327886021345)100:0.00382497683824970002,Tor:0.00848622429823414105);
diff --git a/inst/extdata/trees/RAxML_bipartitions.YCh b/inst/extdata/trees/RAxML_bipartitions.YCh
new file mode 100644
index 0000000..9e1fcf8
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bipartitions.YCh
@@ -0,0 +1 @@
+(Ame:0.02707461606876413254,(((Mur:0.00215666997155560154,Uth:0.00192023592185219349)63:0.00016696946772137622,Hma:0.00368686670740361357)81:0.00018687639400160564,(Uam:0.00135720565202207934,(Uma:0.00118651800822575332,Uar:0.00101739764390293918)94:0.00033775695210929856)100:0.00157503466397103213)100:0.00634369057289599098,Tor:0.00989995418842323435);
diff --git a/inst/extdata/trees/RAxML_bipartitions.mtG b/inst/extdata/trees/RAxML_bipartitions.mtG
new file mode 100644
index 0000000..5471955
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bipartitions.mtG
@@ -0,0 +1 @@
+(Ame:0.42623829669506568818,(Mur:0.07919097361296209558,((Uar:0.01286960617186264609,Uma:0.01148014536527527073)100:0.05944338095871280064,((Uam:0.06376626308156593814,Uth:0.05419104627017570786)92:0.00666893477206217944,Hma:0.06896198930015005890)100:0.00974981555038798714)66:0.00145717534115081442)100:0.13909717574901725445,Tor:0.19825987246617926552);
diff --git a/inst/extdata/trees/RAxML_bipartitionsBranchLabels.3moles b/inst/extdata/trees/RAxML_bipartitionsBranchLabels.3moles
new file mode 100644
index 0000000..01d3c07
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bipartitionsBranchLabels.3moles
@@ -0,0 +1 @@
+(Ame:0.24240784786309346743,(((Hma:0.03262045163347984666,Mur:0.03886458455630492637):0.00225499947410235475[36],Uth:0.02580682933153511174):0.00059392541543651757[30],(Uam:0.02931596331419318927,(Uar:0.00602522464221224522,Uma:0.00593640374580924231):0.02934241311799383120[100]):0.00269684120306867619[60]):0.06379221863907107160[100],Tor:0.09747395533792581335);
diff --git a/inst/extdata/trees/RAxML_bipartitionsBranchLabels.AIs b/inst/extdata/trees/RAxML_bipartitionsBranchLabels.AIs
new file mode 100644
index 0000000..f239841
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bipartitionsBranchLabels.AIs
@@ -0,0 +1 @@
+(Ame:0.02681059329595153473,((Hma:0.00312706379726812329,(Uth:0.00121026052477198292,Mur:0.00312046250563168155):0.00087036069658183684[39]):0.00122506270256386740[42],((Uar:0.00052373856518729458,Uma:0.00247018618187345041):0.00167792487939210548[83],Uam:0.00184159984063642979):0.00107249327886021345[41]):0.00382497683824970002[100],Tor:0.00848622429823414105);
diff --git a/inst/extdata/trees/RAxML_bipartitionsBranchLabels.YCh b/inst/extdata/trees/RAxML_bipartitionsBranchLabels.YCh
new file mode 100644
index 0000000..0dcf31a
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bipartitionsBranchLabels.YCh
@@ -0,0 +1 @@
+(Ame:0.02707461606876413254,(((Mur:0.00215666997155560154,Uth:0.00192023592185219349):0.00016696946772137622[63],Hma:0.00368686670740361357):0.00018687639400160564[81],(Uam:0.00135720565202207934,(Uma:0.00118651800822575332,Uar:0.00101739764390293918):0.00033775695210929856[94]):0.00157503466397103213[100]):0.00634369057289599098[100],Tor:0.00989995418842323435);
diff --git a/inst/extdata/trees/RAxML_bipartitionsBranchLabels.mtG b/inst/extdata/trees/RAxML_bipartitionsBranchLabels.mtG
new file mode 100644
index 0000000..29a0097
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bipartitionsBranchLabels.mtG
@@ -0,0 +1 @@
+(Ame:0.42623829669506568818,(Mur:0.07919097361296209558,((Uar:0.01286960617186264609,Uma:0.01148014536527527073):0.05944338095871280064[100],((Uam:0.06376626308156593814,Uth:0.05419104627017570786):0.00666893477206217944[92],Hma:0.06896198930015005890):0.00974981555038798714[100]):0.00145717534115081442[66]):0.13909717574901725445[100],Tor:0.19825987246617926552);
diff --git a/inst/extdata/trees/RAxML_bootstrap.3moles b/inst/extdata/trees/RAxML_bootstrap.3moles
new file mode 100644
index 0000000..b442afc
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bootstrap.3moles
@@ -0,0 +1,1000 @@
+((((Hma,Mur),Uth),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uar,Uma),(Mur,(Uth,Uam))),Hma),Tor,Ame);
+((Hma,((Uth,(Uam,(Uar,Uma))),Mur)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+((Hma,((Uth,(Uam,(Uar,Uma))),Mur)),Tor,Ame);
+((((Uar,Uma),Hma),((Uth,Uam),Mur)),Tor,Ame);
+((Hma,((Uth,Mur),(Uam,(Uar,Uma)))),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uar,Uma),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((((Uar,Uma),Uam),(Uth,Mur)),Hma),Tor,Ame);
+((((Uar,Uma),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uar,Uma),(((Uam,Uth),Mur),Hma)),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Tor,Ame);
+((((Uam,Uth),(Uar,Uma)),(Hma,Mur)),Tor,Ame);
+(((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Tor,Ame);
+((Mur,((Hma,Uth),(Uam,(Uar,Uma)))),Tor,Ame);
+(Tor,((Uma,Uar),((Mur,(Uth,Uam)),Hma)),Ame);
+(Tor,((Hma,Mur),((Uam,(Uma,Uar)),Uth)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Mur,(Uma,Uar)),((Uam,Uth),Hma)),Ame);
+(Tor,((Uth,(Hma,Mur)),((Uma,Uar),Uam)),Ame);
+(Tor,(((Uth,Hma),((Uma,Uar),Uam)),Mur),Ame);
+(Tor,(((Uma,Uar),Uam),((Mur,Uth),Hma)),Ame);
+(Tor,((Uth,((Uma,Uar),Uam)),(Mur,Hma)),Ame);
+(Tor,(Hma,((Uth,((Uma,Uar),Uam)),Mur)),Ame);
+(Tor,((Uth,((Uma,Uar),Uam)),(Mur,Hma)),Ame);
+((((Uam,(Uma,Uar)),(Mur,Uth)),Hma),Tor,Ame);
+(((Uma,Uar),(Hma,(Mur,(Uam,Uth)))),Tor,Ame);
+((Hma,(Mur,(((Uma,Uar),Uam),Uth))),Tor,Ame);
+(((((Uma,Uar),Uam),Uth),(Hma,Mur)),Tor,Ame);
+((((Uma,Uar),(Uam,Uth)),(Hma,Mur)),Tor,Ame);
+((((Uth,(Uam,(Uma,Uar))),Mur),Hma),Tor,Ame);
+(((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Tor,Ame);
+((Hma,((Uth,(Uam,(Uma,Uar))),Mur)),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Mur,Hma),((Uma,Uar),(Uth,Uam))),Tor,Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,(Mur,((Uar,Uma),((Uth,Uam),Hma))),Ame);
+(Tor,((Uar,Uma),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,((Uth,((Uar,Uma),Uam)),(Hma,Mur)),Ame);
+(Tor,((Hma,(Uar,Uma)),((Uam,Uth),Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Hma,Uth),Mur)),Ame);
+(Tor,((Uar,Uma),(Mur,(Uth,(Hma,Uam)))),Ame);
+(Tor,((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Mur,(Uam,Uth)),((Uar,Uma),Hma)),Ame);
+(Tor,(Mur,((Uam,Uth),(Hma,(Uar,Uma)))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Mur,(Hma,Uth))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,(((Uar,Uma),(Hma,(Uth,Uam))),Mur),Ame);
+(Tor,((Uar,Uma),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,((Uar,Uma),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Uth,Hma),Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Uth,Hma),Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uar,Uma),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Ame);
+(Tor,(Hma,(Mur,(Uth,(Uam,(Uma,Uar))))),Ame);
+(Tor,((Uth,Uam),((Hma,Mur),(Uma,Uar))),Ame);
+(Tor,((Mur,(Uth,Uam)),((Uma,Uar),Hma)),Ame);
+(Tor,((Mur,(Hma,(Uth,Uam))),(Uma,Uar)),Ame);
+(Tor,((Mur,(Hma,Uth)),(Uam,(Uma,Uar))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+((((Hma,Mur),Uth),((Uma,Uar),Uam)),Tor,Ame);
+(((Mur,(Uth,Uam)),((Uma,Uar),Hma)),Tor,Ame);
+((Uth,((Uam,(Uma,Uar)),(Hma,Mur))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+((Hma,(Mur,(Uth,(Uam,(Uma,Uar))))),Tor,Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+((Hma,((Uth,((Uma,Uar),Uam)),Mur)),Tor,Ame);
+(((Uth,((Uma,Uar),Uam)),(Mur,Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Hma,(Mur,(((Uar,Uma),Uam),Uth))),Ame);
+(Tor,(((Uar,Uma),Uam),(Uth,(Hma,Mur))),Ame);
+(Tor,(((Uar,Uma),Uam),(Hma,(Mur,Uth))),Ame);
+(Tor,(((Uth,(Uam,(Uar,Uma))),Hma),Mur),Ame);
+(Tor,((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Ame);
+(Tor,((((Uam,Uth),Hma),Mur),(Uar,Uma)),Ame);
+(Tor,((((Uam,Uth),Hma),Mur),(Uar,Uma)),Ame);
+(Tor,(Mur,((Uar,Uma),((Uam,Uth),Hma))),Ame);
+(Tor,((Uar,Uma),(((Uam,Uth),Hma),Mur)),Ame);
+((((Uth,Uam),Hma),(Mur,(Uar,Uma))),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Mur),Uth)),Tor,Ame);
+(((Mur,(Uth,((Uar,Uma),Uam))),Hma),Tor,Ame);
+(((Uth,((Uar,Uma),Uam)),(Hma,Mur)),Tor,Ame);
+(((Uth,((Uar,Uma),Uam)),(Hma,Mur)),Tor,Ame);
+((((Uar,Uma),(Uam,Uth)),(Hma,Mur)),Tor,Ame);
+((((Uar,Uma),(Hma,(Uam,Uth))),Mur),Tor,Ame);
+((Hma,(Mur,(Uth,(Uam,(Uar,Uma))))),Tor,Ame);
+(((Mur,(Hma,(Uth,Uam))),(Uar,Uma)),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uar,Uma),((Uam,Uth),Hma)),Mur),Tor,Ame);
+(((Uar,Uma),(Uam,(Uth,(Hma,Mur)))),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Tor,Ame);
+(((Hma,Mur),(((Uar,Uma),Uam),Uth)),Tor,Ame);
+(((Hma,Mur),(((Uar,Uma),Uam),Uth)),Tor,Ame);
+((Hma,(Mur,(((Uar,Uma),Uam),Uth))),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Tor,Ame);
+(((Uth,(Mur,Hma)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uth,(Mur,Hma)),(Uam,(Uar,Uma))),Tor,Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Hma,Uth),Mur)),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,(((Uth,Hma),Mur),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Ame);
+(Tor,((Hma,(Uth,Uam)),((Uar,Uma),Mur)),Ame);
+(Tor,((Uar,Uma),(Hma,(Mur,(Uth,Uam)))),Ame);
+(Tor,((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Ame);
+(Tor,((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Ame);
+(Tor,((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Ame);
+(Tor,((Uar,Uma),((Hma,(Uam,Uth)),Mur)),Ame);
+(Tor,((Uar,Uma),((Hma,(Uam,Uth)),Mur)),Ame);
+(Tor,(((Uam,(Uar,Uma)),Uth),(Mur,Hma)),Ame);
+(Tor,(((Uam,(Uar,Uma)),Uth),(Mur,Hma)),Ame);
+(Tor,(((Uar,Uma),(Uth,Uam)),(Mur,Hma)),Ame);
+(Tor,(((Uar,Uma),(Uth,Uam)),(Mur,Hma)),Ame);
+(Tor,((Mur,Uth),((Uam,(Uar,Uma)),Hma)),Ame);
+(Tor,(((Hma,Mur),Uth),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Mur,(Uam,Uth)),((Uar,Uma),Hma)),Ame);
+(Tor,((Uma,Uar),(((Uam,Uth),Hma),Mur)),Ame);
+(Tor,((Uma,Uar),(((Uam,Uth),Hma),Mur)),Ame);
+(Tor,((Uma,Uar),(((Uam,Uth),Hma),Mur)),Ame);
+(Tor,((((Uma,Uar),Uam),Uth),(Hma,Mur)),Ame);
+(Tor,(((Uma,Uar),Uam),((Mur,Uth),Hma)),Ame);
+(Tor,((Mur,(Uth,Uam)),(Hma,(Uma,Uar))),Ame);
+(Tor,((Uth,(Mur,Hma)),(Uam,(Uma,Uar))),Ame);
+(Tor,(((Uth,Uam),Hma),((Uma,Uar),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uth,Uam),(Hma,((Uma,Uar),Mur))),Ame);
+(Tor,(Mur,(Hma,(Uth,(Uam,(Uma,Uar))))),Ame);
+(Tor,(Hma,((Uth,(Uam,(Uma,Uar))),Mur)),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Ame);
+(Tor,(Hma,((Mur,(Uth,Uam)),(Uma,Uar))),Ame);
+(Tor,(Hma,((Uth,(Uam,(Uma,Uar))),Mur)),Ame);
+(Tor,((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(Tor,(((Uth,Uam),Mur),((Uma,Uar),Hma)),Ame);
+(Tor,(((Hma,(Uth,Uam)),Mur),(Uma,Uar)),Ame);
+(Tor,(((Hma,(Uth,Uam)),Mur),(Uma,Uar)),Ame);
+(Tor,(((Uma,Uar),(Hma,(Uam,Uth))),Mur),Ame);
+(Tor,((Uma,Uar),((Mur,Hma),(Uam,Uth))),Ame);
+(Tor,((Mur,Hma),(Uth,(Uam,(Uma,Uar)))),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uma,Uar))),Ame);
+(Tor,((Hma,((Uam,(Uma,Uar)),Uth)),Mur),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Ame);
+(Tor,(Hma,(Mur,((Uam,(Uma,Uar)),Uth))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uth,((Uma,Uar),Uam)),(Mur,Hma)),Ame);
+(Tor,(((Uma,Uar),Uam),(Mur,(Uth,Hma))),Ame);
+(Tor,(Hma,((Uma,Uar),((Uth,Uam),Mur))),Ame);
+(Tor,((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Mur,Hma))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Mur,Hma))),Ame);
+(Tor,((((Uam,(Uma,Uar)),Hma),Uth),Mur),Ame);
+(Tor,(((Uma,Uar),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,((Hma,(Mur,Uth)),(Uam,(Uma,Uar))),Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+(((Mur,(Uth,(Uam,(Uma,Uar)))),Hma),Tor,Ame);
+(((Mur,(Uth,(Uam,(Uma,Uar)))),Hma),Tor,Ame);
+(((Uma,Uar),(((Uth,Uam),Hma),Mur)),Tor,Ame);
+(((Hma,Mur),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uam,Uth),((Uma,Uar),(Mur,Hma))),Tor,Ame);
+(((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Tor,Ame);
+(((Uma,Uar),(Mur,((Uam,Uth),Hma))),Tor,Ame);
+((((Uam,Uth),Hma),((Uma,Uar),Mur)),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+((((Uth,Uam),Mur),((Uar,Uma),Hma)),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uam,Uth),Mur),((Uar,Uma),Hma)),Tor,Ame);
+((((Hma,(Uam,Uth)),Mur),(Uar,Uma)),Tor,Ame);
+(((((Uar,Uma),Uam),Uth),(Mur,Hma)),Tor,Ame);
+(((Uar,Uma),((Uth,Uam),(Mur,Hma))),Tor,Ame);
+(Tor,((Hma,(Uth,Uam)),((Uar,Uma),Mur)),Ame);
+(Tor,((Mur,(Uth,Uam)),((Uar,Uma),Hma)),Ame);
+(Tor,(Mur,((Uar,Uma),((Uth,Uam),Hma))),Ame);
+(Tor,(Mur,((Uar,Uma),((Uth,Uam),Hma))),Ame);
+(Tor,(((Hma,Mur),Uth),((Uar,Uma),Uam)),Ame);
+(Tor,(((Uth,Mur),Uam),(Hma,(Uar,Uma))),Ame);
+(Tor,(Hma,((Uar,Uma),((Uth,Uam),Mur))),Ame);
+(Tor,((Uar,Uma),(Hma,((Uth,Uam),Mur))),Ame);
+(Tor,((Uar,Uma),((Hma,(Uam,Uth)),Mur)),Ame);
+(Tor,((Uam,Uth),((Mur,Hma),(Uar,Uma))),Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Tor,Ame);
+(((Mur,(Uth,(Uam,(Uar,Uma)))),Hma),Tor,Ame);
+(((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Tor,Ame);
+((((Hma,(Uam,Uth)),(Uar,Uma)),Mur),Tor,Ame);
+(((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Uth,Mur),Hma)),Tor,Ame);
+((((Uar,Uma),(Hma,(Uth,Uam))),Mur),Tor,Ame);
+(((Uar,Uma),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+(Tor,((Mur,(Uam,Uth)),(Hma,(Uma,Uar))),Ame);
+(Tor,((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Ame);
+(Tor,((((Uam,Uth),Hma),Mur),(Uma,Uar)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Ame);
+(Tor,((Mur,(Uam,Uth)),((Uma,Uar),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Hma,Mur)),Ame);
+(Tor,((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Mur,((Uam,(Uar,Uma)),Uth)),Hma),Tor,Ame);
+((((Mur,Hma),Uth),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((Hma,((Uam,(Uar,Uma)),(Mur,Uth))),Tor,Ame);
+((((Uth,Uam),(Uar,Uma)),(Hma,Mur)),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Tor,Ame);
+((Mur,((Hma,(Uth,Uam)),(Uar,Uma))),Tor,Ame);
+((((Uma,Uar),(Hma,Mur)),(Uam,Uth)),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Tor,Ame);
+((Uam,((Uma,Uar),((Mur,Hma),Uth))),Tor,Ame);
+((Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Tor,Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+((Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Tor,Ame);
+(((Mur,(Uth,Uam)),((Uma,Uar),Hma)),Tor,Ame);
+(((((Uth,Uam),Hma),Mur),(Uma,Uar)),Tor,Ame);
+((((Hma,Uth),Mur),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+((Mur,(((Uam,(Uma,Uar)),Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uam,(Uma,Uar)),Uth),(Hma,Mur)),Tor,Ame);
+((((Uam,(Uma,Uar)),(Mur,Uth)),Hma),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uma,Uar)),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uma,Uar),(((Uam,Uth),Hma),Mur)),Tor,Ame);
+(Tor,((Mur,(Uth,(Uam,(Uma,Uar)))),Hma),Ame);
+(Tor,(((Mur,(Uth,Uam)),Hma),(Uma,Uar)),Ame);
+(Tor,((Uma,Uar),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,(((Uma,Uar),(Uth,Uam)),(Mur,Hma)),Ame);
+(Tor,((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,((Hma,Mur),((Uma,Uar),(Uth,Uam))),Ame);
+(Tor,(Hma,(((Uam,(Uma,Uar)),Uth),Mur)),Ame);
+(Tor,(Mur,(Hma,((Uam,(Uma,Uar)),Uth))),Ame);
+(Tor,(((Mur,Uth),(Uam,(Uma,Uar))),Hma),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,(Mur,(Hma,(Uth,(Uam,(Uar,Uma))))),Ame);
+(Tor,(((Uam,Uth),Mur),(Hma,(Uar,Uma))),Ame);
+(Tor,(((Uar,Uma),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,((Uar,Uma),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,((Uth,((Uar,Uma),Uam)),(Mur,Hma)),Ame);
+(Tor,(((Uar,Uma),(Uth,Uam)),(Mur,Hma)),Ame);
+(Tor,((Mur,Hma),(((Uar,Uma),Uam),Uth)),Ame);
+(Tor,((Hma,Mur),((Uth,Uam),(Uar,Uma))),Ame);
+(Tor,((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Ame);
+(Tor,(((Uar,Uma),(Mur,(Uth,Uam))),Hma),Ame);
+(Tor,(((Mur,Hma),Uth),((Uar,Uma),Uam)),Ame);
+(Tor,(((Uar,Uma),Uam),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Mur,(Hma,Uth))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Mur,Hma))),Ame);
+(Tor,((((Uam,Uth),Hma),(Uar,Uma)),Mur),Ame);
+((((Uar,Uma),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+((((Uar,Uma),(Uth,Uam)),(Mur,Hma)),Tor,Ame);
+(((Uar,Uma),(Mur,((Uth,Uam),Hma))),Tor,Ame);
+((((Uth,Uam),Hma),((Uar,Uma),Mur)),Tor,Ame);
+((Mur,((Uth,Hma),(Uam,(Uar,Uma)))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Hma,((Uth,Uam),Mur)),(Uar,Uma)),Tor,Ame);
+(((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Tor,Ame);
+((Mur,(((Uam,(Uar,Uma)),Uth),Hma)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+((Hma,((Uth,(Uam,(Uar,Uma))),Mur)),Tor,Ame);
+(((Uar,Uma),((Mur,Hma),(Uam,Uth))),Tor,Ame);
+(((Hma,(Uar,Uma)),(Mur,(Uam,Uth))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((((Uam,Uth),Mur),(Hma,(Uar,Uma))),Tor,Ame);
+((((Uar,Uma),Uam),(Uth,(Mur,Hma))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Mur,((Uam,(Uma,Uar)),Uth)),Hma),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Hma,Mur),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+(((Hma,(Uam,(Uma,Uar))),(Uth,Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uma,Uar),(((Uth,Uam),Hma),Mur)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+((((Uth,Hma),Mur),(Uam,(Uma,Uar))),Tor,Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Uth,Hma),Mur)),Ame);
+(Tor,((Uar,Uma),(((Uam,Uth),Mur),Hma)),Ame);
+(Tor,((Uar,Uma),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,(((Uam,(Uar,Uma)),Uth),(Hma,Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uar,Uma),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uar,Uma),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,((Uar,Uma),(((Uth,Uam),Hma),Mur)),Ame);
+(((Uar,Uma),((Mur,(Uth,Uam)),Hma)),Tor,Ame);
+((((Mur,Uth),Hma),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uar,Uma),(Hma,(Uth,Uam))),Mur),Tor,Ame);
+((((Hma,Mur),Uth),((Uar,Uma),Uam)),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Tor,Ame);
+(((((Uar,Uma),Uam),Uth),(Mur,Hma)),Tor,Ame);
+(((Mur,(Uth,Uam)),(Hma,(Uar,Uma))),Tor,Ame);
+((((Mur,Uth),Hma),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uth,Uam),Hma),((Uar,Uma),Mur)),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Hma,Uth),(Uam,(Uma,Uar))),Mur),Tor,Ame);
+((((Uma,Uar),(Uth,Uam)),(Hma,Mur)),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Uth,Mur))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Uth,Mur))),Tor,Ame);
+((Hma,((Uth,Mur),((Uma,Uar),Uam))),Tor,Ame);
+((Hma,(Mur,(((Uma,Uar),Uam),Uth))),Tor,Ame);
+((((Mur,Hma),(Uma,Uar)),(Uam,Uth)),Tor,Ame);
+((((Uma,Uar),Uam),((Mur,Uth),Hma)),Tor,Ame);
+(((((Uth,Uam),Hma),Mur),(Uma,Uar)),Tor,Ame);
+((Mur,((Uth,((Uma,Uar),Uam)),Hma)),Tor,Ame);
+(((Mur,(Uth,Uam)),((Uma,Uar),Hma)),Tor,Ame);
+(((Uma,Uar),(Hma,(Mur,(Uth,Uam)))),Tor,Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+(((Hma,(Uth,Uam)),(Mur,(Uma,Uar))),Tor,Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+((((Uth,Uam),(Uma,Uar)),(Mur,Hma)),Tor,Ame);
+((Hma,(((Uam,(Uma,Uar)),Uth),Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Uth),Mur)),Tor,Ame);
+(Tor,((Hma,Mur),(((Uma,Uar),Uam),Uth)),Ame);
+(Tor,(((Uma,Uar),Uam),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uma,Uar),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Ame);
+(Tor,((Mur,(Uth,(Uam,(Uma,Uar)))),Hma),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Ame);
+(Tor,((Mur,(Uam,Uth)),(Hma,(Uma,Uar))),Ame);
+(Tor,(Hma,((Uth,(Uam,(Uma,Uar))),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Ame);
+(Tor,(((Uar,Uma),Uam),(Uth,(Hma,Mur))),Ame);
+(Tor,(((Uar,Uma),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,((Uth,Uam),((Hma,Mur),(Uar,Uma))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,(Hma,(Mur,((Uam,(Uar,Uma)),Uth))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uar,Uma),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,((Mur,(Uth,Uam)),((Uar,Uma),Hma)),Ame);
+(Tor,((((Uth,Uam),Hma),Mur),(Uar,Uma)),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,(((Uam,(Uar,Uma)),(Mur,Uth)),Hma),Ame);
+(Tor,((Uar,Uma),((Mur,(Uam,Uth)),Hma)),Ame);
+(Tor,(((Uar,Uma),((Uam,Uth),Hma)),Mur),Ame);
+(Tor,(((Uar,Uma),((Uam,Uth),Hma)),Mur),Ame);
+(Tor,((Uma,Uar),(Mur,((Uth,Uam),Hma))),Ame);
+(Tor,(Mur,(Uth,((Uam,(Uma,Uar)),Hma))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uth,Mur),(Hma,(Uam,(Uma,Uar)))),Ame);
+(Tor,((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Ame);
+(Tor,((Uth,Uam),((Uma,Uar),(Hma,Mur))),Ame);
+(Tor,((Hma,Mur),((Uth,Uam),(Uar,Uma))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Mur,(Hma,Uth))),Ame);
+(Tor,(Mur,(Hma,(Uth,(Uam,(Uar,Uma))))),Ame);
+(Tor,((Uth,Uam),((Uar,Uma),(Mur,Hma))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uar,Uma),((Mur,(Uth,Uam)),Hma)),Ame);
+(Tor,((Uar,Uma),(Mur,((Uam,Uth),Hma))),Ame);
+(Tor,(((Uam,Uth),Hma),((Uar,Uma),Mur)),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Uam,Uth),((Uar,Uma),(Hma,Mur))),Ame);
+(Tor,(Mur,((Hma,(Uam,Uth)),(Uar,Uma))),Ame);
+(Tor,(Hma,((Uth,(Uam,(Uar,Uma))),Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,(Hma,(Mur,((Uam,(Uar,Uma)),Uth))),Ame);
+(Tor,((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Mur,Hma))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Mur,Hma))),Ame);
+(Tor,((Mur,Hma),((Uam,(Uar,Uma)),Uth)),Ame);
+(Tor,((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Ame);
+(Tor,(Hma,(Mur,(Uth,(Uam,(Uar,Uma))))),Ame);
+(((Mur,(Hma,Uth)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uth,(Uam,(Uar,Uma))),Mur),Hma),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Tor,Ame);
+((Hma,((Uth,(Uam,(Uar,Uma))),Mur)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+((((Uth,Uam),Hma),((Uar,Uma),Mur)),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Tor,Ame);
+(((Uma,Uar),((Mur,Hma),(Uth,Uam))),Tor,Ame);
+(((Uth,(Mur,Hma)),(Uam,(Uma,Uar))),Tor,Ame);
+((((Uth,Mur),(Uam,(Uma,Uar))),Hma),Tor,Ame);
+(((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uma,Uar),(Mur,((Uam,Uth),Hma))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uma,Uar),(Mur,(Uam,(Hma,Uth)))),Tor,Ame);
+(Tor,(Mur,((Uar,Uma),((Uam,Uth),Hma))),Ame);
+(Tor,((((Uar,Uma),Uam),Uth),(Hma,Mur)),Ame);
+(Tor,(((Uar,Uma),((Uam,Uth),Hma)),Mur),Ame);
+(Tor,((Uar,Uma),(((Uam,Uth),Hma),Mur)),Ame);
+(Tor,(Hma,((((Uar,Uma),Uam),Uth),Mur)),Ame);
+(Tor,(((Uar,Uma),Uam),(Uth,(Mur,Hma))),Ame);
+(Tor,(((Uth,Mur),((Uar,Uma),Uam)),Hma),Ame);
+(Tor,(((Mur,Uth),Hma),((Uar,Uma),Uam)),Ame);
+(Tor,(((Mur,Uth),Hma),((Uar,Uma),Uam)),Ame);
+(Tor,((Mur,Hma),((Uar,Uma),(Uth,Uam))),Ame);
+(((Uma,Uar),((Uam,(Hma,Uth)),Mur)),Tor,Ame);
+((((Uth,Mur),(Uam,(Uma,Uar))),Hma),Tor,Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+(((Mur,Hma),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+(((Mur,(Uma,Uar)),(Hma,(Uam,Uth))),Tor,Ame);
+((Hma,((((Uma,Uar),Uam),Uth),Mur)),Tor,Ame);
+((((Uma,Uar),Uam),((Mur,Hma),Uth)),Tor,Ame);
+((((Uma,Uar),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uma,Uar),(Uth,Uam)),(Mur,Hma)),Tor,Ame);
+((((Uma,Uar),(Uth,Uam)),(Mur,Hma)),Tor,Ame);
+(Tor,((Hma,Mur),(((Uar,Uma),Uam),Uth)),Ame);
+(Tor,(Hma,((Mur,Uth),((Uar,Uma),Uam))),Ame);
+(Tor,((Mur,(Uth,Uam)),(Hma,(Uar,Uma))),Ame);
+(Tor,((Mur,(Hma,(Uth,Uam))),(Uar,Uma)),Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,(((Uar,Uma),(Hma,(Uth,Uam))),Mur),Ame);
+(Tor,((Uth,((Uar,Uma),Uam)),(Hma,Mur)),Ame);
+(Tor,((Uth,((Uar,Uma),Uam)),(Hma,Mur)),Ame);
+(((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+((((Uam,Uth),Mur),(Hma,(Uar,Uma))),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Tor,Ame);
+((((Uam,(Uar,Uma)),Uth),(Mur,Hma)),Tor,Ame);
+((((Uar,Uma),(Uth,Uam)),(Mur,Hma)),Tor,Ame);
+(((Mur,(Uth,((Uar,Uma),Uam))),Hma),Tor,Ame);
+((((Uar,Uma),(Uam,Uth)),(Hma,Mur)),Tor,Ame);
+(((Mur,(Uam,Uth)),(Hma,(Uar,Uma))),Tor,Ame);
+((Hma,(((Uar,Uma),Uam),(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),(Hma,(Uth,Uam))),Mur),Tor,Ame);
+(Tor,((Uth,Uam),((Hma,Mur),(Uma,Uar))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Uth),Mur)),Ame);
+(Tor,((Hma,(Uma,Uar)),((Uth,Uam),Mur)),Ame);
+(Tor,((Hma,Mur),((Uma,Uar),(Uth,Uam))),Ame);
+(Tor,(((Uma,Uar),(Hma,(Uth,Uam))),Mur),Ame);
+(Tor,(Hma,((Mur,Uth),(Uam,(Uma,Uar)))),Ame);
+(Tor,(Hma,(Mur,(Uth,(Uam,(Uma,Uar))))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uma,Uar),(Mur,((Uam,Uth),Hma))),Ame);
+(Tor,((Uma,Uar),(Mur,((Uam,Uth),Hma))),Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((((Uam,Uth),Hma),(Mur,(Uar,Uma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Tor,Ame);
+(((Hma,Mur),(((Uar,Uma),Uam),Uth)),Tor,Ame);
+((((Uar,Uma),Uam),((Uth,Mur),Hma)),Tor,Ame);
+((Hma,(((Uar,Uma),Uam),(Uth,Mur))),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((Mur,(((Uth,Uam),Hma),(Uar,Uma))),Tor,Ame);
+(Tor,(((Uth,Mur),Hma),((Uma,Uar),Uam)),Ame);
+(Tor,(Hma,((Uth,((Uma,Uar),Uam)),Mur)),Ame);
+(Tor,(Hma,((Uth,((Uma,Uar),Uam)),Mur)),Ame);
+(Tor,(((Uma,Uar),(Uth,Uam)),(Mur,Hma)),Ame);
+(Tor,(Hma,((Mur,(Uth,Uam)),(Uma,Uar))),Ame);
+(Tor,((Mur,(Hma,Uth)),(Uam,(Uma,Uar))),Ame);
+(Tor,(Mur,(Hma,(Uth,(Uam,(Uma,Uar))))),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Ame);
+(Tor,(((Uth,Mur),Hma),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,(((Uar,Uma),Uam),Uth)),Mur),Ame);
+(Tor,((Uar,Uma),(Mur,((Uam,Uth),Hma))),Ame);
+(Tor,((Uar,Uma),(Mur,((Uam,Uth),Hma))),Ame);
+(Tor,((Hma,(Uar,Uma)),(Mur,(Uam,Uth))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Mur,Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Mur,(Uth,Hma))),Ame);
+(Tor,((Hma,(Uar,Uma)),(Mur,(Uth,Uam))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Mur,((Uam,(Uma,Uar)),Uth)),Hma),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,(Hma,((Uth,(Uam,(Uma,Uar))),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Mur,(Hma,Uth))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(Tor,(((Uth,Uam),Hma),(Mur,(Uma,Uar))),Ame);
+(Tor,((Hma,Mur),((Uam,(Uma,Uar)),Uth)),Ame);
+(Tor,(Hma,(((Uam,Uth),Mur),(Uma,Uar))),Ame);
+(Tor,(((Uma,Uar),Mur),(Hma,(Uam,Uth))),Ame);
+(Tor,(((Uth,Uam),Hma),(Mur,(Uar,Uma))),Ame);
+(Tor,((Hma,Mur),(((Uar,Uma),Uam),Uth)),Ame);
+(Tor,(Mur,(((Uar,Uma),(Uth,Uam)),Hma)),Ame);
+(Tor,(((Uth,Mur),((Uar,Uma),Uam)),Hma),Ame);
+(Tor,((Mur,(((Uar,Uma),Uam),Uth)),Hma),Ame);
+(Tor,(((Uar,Uma),(Uam,Uth)),(Hma,Mur)),Ame);
+(Tor,(((Uar,Uma),(Hma,(Uam,Uth))),Mur),Ame);
+(Tor,((Uar,Uma),((Hma,(Uam,Uth)),Mur)),Ame);
+(Tor,((Hma,(Uar,Uma)),((Uam,Uth),Mur)),Ame);
+(Tor,((Hma,(Uar,Uma)),((Uam,Uth),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Mur,Hma))),Ame);
+(Tor,((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uma,Uar))),Ame);
+(Tor,(Hma,((Uam,(Uma,Uar)),(Uth,Mur))),Ame);
+(Tor,(Hma,((Uam,(Uma,Uar)),(Uth,Mur))),Ame);
+(Tor,(((Uth,Uam),(Uma,Uar)),(Hma,Mur)),Ame);
+(Tor,(((Uth,Uam),Mur),((Uma,Uar),Hma)),Ame);
+(Tor,((Hma,(Uth,Uam)),(Mur,(Uma,Uar))),Ame);
+(Tor,(Hma,((Uth,Mur),(Uam,(Uma,Uar)))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+(((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+(((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+(((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+((((Uma,Uar),(Hma,(Uth,Uam))),Mur),Tor,Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+(((Uma,Uar),(((Uam,Uth),Mur),Hma)),Tor,Ame);
+(((Uma,Uar),(((Uam,Uth),Hma),Mur)),Tor,Ame);
+((Mur,((Uma,Uar),((Uam,Uth),Hma))),Tor,Ame);
+(((Hma,Mur),((Uma,Uar),(Uam,Uth))),Tor,Ame);
+(Tor,((Uma,Uar),(Mur,(Hma,(Uth,Uam)))),Ame);
+(Tor,((Uma,Uar),(Mur,(Hma,(Uth,Uam)))),Ame);
+(Tor,((Uth,((Uma,Uar),Uam)),(Mur,Hma)),Ame);
+(Tor,(((Uma,Uar),Uam),((Uth,Mur),Hma)),Ame);
+(Tor,(Hma,(((Uma,Uar),Uam),(Uth,Mur))),Ame);
+(Tor,(Hma,(((Uma,Uar),Uam),(Uth,Mur))),Ame);
+(Tor,((Uth,Mur),(Hma,((Uma,Uar),Uam))),Ame);
+(Tor,(((Uma,Uar),(Hma,(Uam,Uth))),Mur),Ame);
+(Tor,(((Uma,Uar),Uam),(Uth,(Hma,Mur))),Ame);
+(Tor,(((Uma,Uar),Uam),(Mur,(Uth,Hma))),Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+((Hma,(Mur,(((Uma,Uar),Uam),Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+((Mur,((((Uma,Uar),Uam),Uth),Hma)),Tor,Ame);
+((((Uma,Uar),Uam),((Uth,Hma),Mur)),Tor,Ame);
+(((Uma,Uar),((Uth,Uam),(Hma,Mur))),Tor,Ame);
+((Mur,((Uma,Uar),((Uth,Uam),Hma))),Tor,Ame);
+((Mur,((Uma,Uar),((Uth,Uam),Hma))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uma,Uar),(((Uam,Uth),Hma),Mur)),Tor,Ame);
+(Tor,(((Uar,Uma),(Hma,Mur)),(Uth,Uam)),Ame);
+(Tor,(((Uar,Uma),Hma),(Mur,(Uth,Uam))),Ame);
+(Tor,((Hma,(Uth,(Uam,(Uar,Uma)))),Mur),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Ame);
+(Tor,(((Uam,(Uar,Uma)),(Uth,Mur)),Hma),Ame);
+(Tor,(Mur,((Uth,(Uam,(Uar,Uma))),Hma)),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,(((Uar,Uma),((Uth,Uam),Hma)),Mur),Ame);
+(Tor,(((Uar,Uma),(Hma,Mur)),(Uth,Uam)),Ame);
+(Tor,((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uth,(Mur,Hma)),(Uam,(Uar,Uma))),Ame);
+(Tor,(Hma,((Uth,(Uam,(Uar,Uma))),Mur)),Ame);
+(Tor,(((Uar,Uma),(Hma,(Uam,Uth))),Mur),Ame);
+(((Uth,((Uar,Uma),Uam)),(Hma,Mur)),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Uth,Mur))),Tor,Ame);
+(((((Uar,Uma),Uam),Uth),(Hma,Mur)),Tor,Ame);
+((Mur,((((Uar,Uma),Uam),Uth),Hma)),Tor,Ame);
+((((Uar,Uma),(Uam,Uth)),(Hma,Mur)),Tor,Ame);
+(((Uar,Uma),((Hma,(Uam,Uth)),Mur)),Tor,Ame);
+((Hma,(Mur,((Uam,(Uar,Uma)),Uth))),Tor,Ame);
+((((Uam,(Uar,Uma)),Uth),(Hma,Mur)),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uma,Uar),(Mur,((Uam,Uth),Hma))),Tor,Ame);
+((Mur,(((Uam,Uth),Hma),(Uma,Uar))),Tor,Ame);
+(((Hma,((Uam,Uth),Mur)),(Uma,Uar)),Tor,Ame);
+((Hma,(((Uam,(Uma,Uar)),Uth),Mur)),Tor,Ame);
+((((Hma,(Uam,(Uma,Uar))),Uth),Mur),Tor,Ame);
+((((Hma,(Uam,Uth)),(Uma,Uar)),Mur),Tor,Ame);
+((Hma,((((Uma,Uar),Uam),Uth),Mur)),Tor,Ame);
+((((Uma,Uar),Uam),((Uth,Mur),Hma)),Tor,Ame);
+(((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((((((Uma,Uar),Uam),Uth),Mur),Hma),Tor,Ame);
+(Tor,(((Mur,(Uam,Uth)),Hma),(Uar,Uma)),Ame);
+(Tor,(((Uam,Uth),(Uar,Uma)),(Hma,Mur)),Ame);
+(Tor,((Mur,(Uam,Uth)),((Uar,Uma),Hma)),Ame);
+(Tor,((Mur,(Uam,Uth)),((Uar,Uma),Hma)),Ame);
+(Tor,((Mur,(Uam,Uth)),((Uar,Uma),Hma)),Ame);
+(Tor,(Mur,((Hma,(Uam,Uth)),(Uar,Uma))),Ame);
+(Tor,((Hma,Mur),(Uth,((Uar,Uma),Uam))),Ame);
+(Tor,(((Uar,Uma),Uam),((Uth,Mur),Hma)),Ame);
+(Tor,((((Uar,Uma),Uam),Uth),(Mur,Hma)),Ame);
+(Tor,((((Uar,Uma),Uam),Uth),(Mur,Hma)),Ame);
+((Hma,((Uma,Uar),(Mur,(Uth,Uam)))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Mur,(Hma,Uth))),Tor,Ame);
+(((Mur,(Uth,(Uam,(Uma,Uar)))),Hma),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+((((Uma,Uar),((Uam,Uth),Hma)),Mur),Tor,Ame);
+(((Uma,Uar),((Uth,(Hma,Uam)),Mur)),Tor,Ame);
+(((Hma,Mur),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+((Hma,(Mur,((Uam,(Uma,Uar)),Uth))),Tor,Ame);
+((((Uam,Uth),Hma),(Mur,(Uma,Uar))),Tor,Ame);
+((((Mur,(Uam,Uth)),Hma),(Uma,Uar)),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+(((Mur,(Uam,Uth)),(Hma,(Uma,Uar))),Tor,Ame);
+((((Mur,Uth),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((((Uma,Uar),Uam),((Uth,Mur),Hma)),Tor,Ame);
+((((Uma,Uar),Uam),(Mur,(Hma,Uth))),Tor,Ame);
+(((Uth,(Mur,Hma)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Mur,Hma),((Uam,(Uar,Uma)),Uth)),Tor,Ame);
+((((Uam,Uth),Hma),(Mur,(Uar,Uma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+(((Hma,(Uth,Mur)),((Uar,Uma),Uam)),Tor,Ame);
+(((((Uar,Uma),Uam),Uth),(Hma,Mur)),Tor,Ame);
+(((((Uar,Uma),Uam),Uth),(Hma,Mur)),Tor,Ame);
+(((((Uar,Uma),Uam),Uth),(Hma,Mur)),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Uth),Mur)),Tor,Ame);
+(Tor,((Uma,Uar),(Mur,((Uth,Uam),Hma))),Ame);
+(Tor,((Uth,((Uma,Uar),Uam)),(Hma,Mur)),Ame);
+(Tor,((Uma,Uar),((Uam,Uth),(Hma,Mur))),Ame);
+(Tor,((Mur,(Uma,Uar)),((Uam,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Ame);
+(Tor,(((Uth,Uam),Mur),((Uma,Uar),Hma)),Ame);
+(Tor,(Hma,((Mur,Uth),(Uam,(Uma,Uar)))),Ame);
+(Tor,(((Uam,(Uma,Uar)),Uth),(Hma,Mur)),Ame);
+(Tor,(((Uma,Uar),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,(Mur,((Uar,Uma),((Uam,Uth),Hma))),Ame);
+(Tor,(((Uar,Uma),Uam),((Hma,Mur),Uth)),Ame);
+(Tor,(((Uar,Uma),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,(((Uar,Uma),Uam),(Uth,(Hma,Mur))),Ame);
+(Tor,((Hma,Mur),(((Uar,Uma),Uam),Uth)),Ame);
+(Tor,((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Ame);
+(Tor,((Uth,(Mur,Hma)),(Uam,(Uar,Uma))),Ame);
+(Tor,(((Uth,Mur),(Uam,(Uar,Uma))),Hma),Ame);
+(Tor,(((Hma,Mur),Uth),(Uam,(Uar,Uma))),Ame);
+(Tor,(((Hma,Mur),Uth),(Uam,(Uar,Uma))),Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((((Uam,Uth),Mur),(Uar,Uma)),Hma),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uar,Uma),(((Uth,Uam),Hma),Mur)),Tor,Ame);
+((((Uth,((Uar,Uma),Uam)),Hma),Mur),Tor,Ame);
+((((Uar,Uma),(Uam,Uth)),(Hma,Mur)),Tor,Ame);
+(((Uar,Uma),(Hma,(Mur,(Uam,Uth)))),Tor,Ame);
+(((Uar,Uma),((Hma,(Uam,Uth)),Mur)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Uth),Mur)),Tor,Ame);
+(Tor,((Hma,((Uam,Uth),Mur)),(Uma,Uar)),Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Ame);
+(Tor,(Hma,(Mur,(Uth,(Uam,(Uma,Uar))))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Ame);
+(Tor,(((Uam,(Uma,Uar)),(Mur,Uth)),Hma),Ame);
+(Tor,(((Uma,Uar),Hma),((Uth,Uam),Mur)),Ame);
+(Tor,((((Uma,Uar),Hma),(Uth,Mur)),Uam),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uam,Uth)))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(((((Uar,Uma),Uam),(Mur,Uth)),Hma),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Hma,(Uth,Uam)),(Uar,Uma)),Mur),Tor,Ame);
+(((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+(((((Uth,Uam),Hma),Mur),(Uar,Uma)),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uth,Mur),(Uam,(Uar,Uma))),Hma),Tor,Ame);
+(((Uar,Uma),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+(Tor,((Hma,Mur),(((Uma,Uar),Uam),Uth)),Ame);
+(Tor,(((Uma,Uar),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Uth),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Ame);
+(Tor,(((Uth,Uam),(Uma,Uar)),(Hma,Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(Tor,(Hma,(((Uam,(Uma,Uar)),Uth),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Mur,Hma))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Tor,Ame);
+(((Hma,Mur),((Uar,Uma),(Uth,Uam))),Tor,Ame);
+((Hma,((Mur,Uth),((Uar,Uma),Uam))),Tor,Ame);
+((Hma,(Mur,(Uth,((Uar,Uma),Uam)))),Tor,Ame);
+((Hma,(Mur,(Uth,((Uar,Uma),Uam)))),Tor,Ame);
+((((Mur,Hma),Uth),((Uar,Uma),Uam)),Tor,Ame);
+((Hma,((Uth,((Uar,Uma),Uam)),Mur)),Tor,Ame);
+(((Mur,(Uth,Hma)),((Uar,Uma),Uam)),Tor,Ame);
+((Mur,((Uma,Uar),(Hma,(Uam,Uth)))),Tor,Ame);
+(((Uma,Uar),((Hma,(Uam,Uth)),Mur)),Tor,Ame);
+(((((Uma,Uar),Uam),Uth),(Mur,Hma)),Tor,Ame);
+(((Mur,(Uam,Uth)),(Hma,(Uma,Uar))),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uma,Uar)),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+(((Hma,Mur),((Uam,Uth),(Uma,Uar))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+((Hma,((Uam,(Uma,Uar)),(Mur,Uth))),Tor,Ame);
+((Mur,((Hma,Uth),(Uam,(Uma,Uar)))),Tor,Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Uth),Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Uth),Mur)),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Hma,Mur)),Ame);
+(Tor,((Hma,(Uam,(Uma,Uar))),(Mur,Uth)),Ame);
+(Tor,(Mur,((Hma,(Uth,Uam)),(Uma,Uar))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Ame);
+(Tor,((Mur,(Uth,(Uam,(Uma,Uar)))),Hma),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uma,Uar),(Hma,(Mur,(Uth,Uam)))),Ame);
+(Tor,(((Uam,(Uma,Uar)),(Uth,Mur)),Hma),Ame);
+(((Hma,(Uth,Uam)),(Mur,(Uar,Uma))),Tor,Ame);
+(((Uth,Uam),((Hma,Mur),(Uar,Uma))),Tor,Ame);
+(((Mur,(Uth,Uam)),(Hma,(Uar,Uma))),Tor,Ame);
+(((Mur,Hma),(Uth,((Uar,Uma),Uam))),Tor,Ame);
+(((Mur,Hma),(Uth,((Uar,Uma),Uam))),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Hma),Uth)),Tor,Ame);
+((((Uar,Uma),(Hma,(Uam,Uth))),Mur),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Tor,Ame);
+(Tor,((Mur,(Uam,Uth)),((Uar,Uma),Hma)),Ame);
+(Tor,((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Ame);
+(Tor,((Uar,Uma),(Hma,((Uth,Uam),Mur))),Ame);
+(Tor,(((Uth,Uam),Mur),((Uar,Uma),Hma)),Ame);
+(Tor,(((Hma,(Uth,Uam)),Mur),(Uar,Uma)),Ame);
+(Tor,(((Uar,Uma),Uam),((Mur,Hma),Uth)),Ame);
+(Tor,((Mur,Hma),(Uth,((Uar,Uma),Uam))),Ame);
+(Tor,((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Ame);
+(Tor,((Hma,(Uam,Uth)),((Uar,Uma),Mur)),Ame);
+(Tor,(Hma,(Mur,(((Uma,Uar),Uam),Uth))),Ame);
+(Tor,(((Uma,Uar),Uam),(Uth,(Hma,Mur))),Ame);
+(Tor,(((Uma,Uar),Uam),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uth,((Uma,Uar),Uam)),(Mur,Hma)),Ame);
+(Tor,(Hma,((Uth,((Uma,Uar),Uam)),Mur)),Ame);
+(Tor,((Uma,Uar),(Mur,(Hma,(Uth,Uam)))),Ame);
+(Tor,(((Uth,Uam),(Uma,Uar)),(Mur,Hma)),Ame);
+(Tor,((Hma,(Uam,(Uma,Uar))),(Mur,Uth)),Ame);
+(Tor,((Mur,((Uth,Uam),Hma)),(Uma,Uar)),Ame);
+(Tor,(((Uma,Uar),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,((Mur,(Uth,Hma)),(Uam,(Uma,Uar))),Ame);
+(Tor,((((Uma,Uar),Uam),Uth),(Mur,Hma)),Ame);
+(Tor,((Mur,(Uam,Uth)),(Hma,(Uma,Uar))),Ame);
+(Tor,((Mur,(Uam,Uth)),(Hma,(Uma,Uar))),Ame);
+(Tor,((Mur,(Hma,(Uam,Uth))),(Uma,Uar)),Ame);
+(Tor,(Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Ame);
+(Tor,(Hma,(Mur,(Uth,((Uma,Uar),Uam)))),Ame);
+(Tor,(Mur,((Uma,Uar),((Uth,Uam),Hma))),Ame);
+(Tor,((Hma,(Mur,Uth)),(Uam,(Uma,Uar))),Ame);
+(Tor,((Hma,(Mur,Uth)),(Uam,(Uma,Uar))),Ame);
+(Tor,((Hma,(Uam,Uth)),((Uar,Uma),Mur)),Ame);
+(Tor,((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,(((Uar,Uma),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,(Mur,Uth)),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,Mur),(Uth,((Uar,Uma),Uam))),Ame);
+(((Uth,(Hma,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((Hma,((Uma,Uar),Uam)),(Uth,Mur)),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+((Hma,(Mur,(((Uma,Uar),Uam),Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uth,Uam),((Hma,Mur),(Uma,Uar))),Tor,Ame);
+(((Uar,Uma),((Mur,(Uth,Uam)),Hma)),Tor,Ame);
+(((Uar,Uma),(Mur,((Uam,Uth),Hma))),Tor,Ame);
+(((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Tor,Ame);
+(((Uth,Uam),((Hma,Mur),(Uar,Uma))),Tor,Ame);
+((((Uth,Uam),(Uar,Uma)),(Mur,Hma)),Tor,Ame);
+(((Uth,Mur),(Hma,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uar,Uma),(Mur,(Uam,(Uth,Hma)))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uth,(Uam,(Uar,Uma))),(Mur,Hma)),Tor,Ame);
+(((Uma,Uar),((Hma,(Uam,Uth)),Mur)),Tor,Ame);
+(((Uma,Uar),((Hma,(Uam,Uth)),Mur)),Tor,Ame);
+(((Hma,(Uam,(Uma,Uar))),(Uth,Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Tor,Ame);
+((((Uam,Uth),Mur),(Hma,(Uma,Uar))),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uma,Uar)),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uma,Uar)),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+((((Uth,Uam),Hma),(Mur,(Uma,Uar))),Tor,Ame);
+((Mur,((Uth,((Uma,Uar),Uam)),Hma)),Tor,Ame);
+(Tor,(((Uam,Uth),(Uar,Uma)),(Mur,Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Mur,Hma))),Ame);
+(Tor,((Uar,Uma),(((Uam,Uth),Mur),Hma)),Ame);
+(Tor,((Hma,((Uam,(Uar,Uma)),Uth)),Mur),Ame);
+(Tor,((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Ame);
+(Tor,((Uar,Uma),((Uam,Uth),(Mur,Hma))),Ame);
+(Tor,((Hma,(Uar,Uma)),((Uam,Uth),Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,((((Uth,Uam),Hma),(Uar,Uma)),Mur),Ame);
+(Tor,((Mur,(Uth,Uam)),(Hma,(Uar,Uma))),Ame);
+((((Hma,Mur),Uth),((Uma,Uar),Uam)),Tor,Ame);
+(((Hma,Mur),(Uth,((Uma,Uar),Uam))),Tor,Ame);
+(((Hma,(Uth,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+(((Hma,(Uth,((Uma,Uar),Uam))),Mur),Tor,Ame);
+(((Uma,Uar),(((Uam,Uth),Hma),Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uma,Uar),(((Uam,Uth),Hma),Mur)),Tor,Ame);
+(((Mur,Hma),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Mur,Hma))),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Mur,Hma))),Tor,Ame);
+(Tor,(Mur,((Uam,(Uar,Uma)),(Hma,Uth))),Ame);
+(Tor,(((Hma,(Uth,Uam)),(Uar,Uma)),Mur),Ame);
+(Tor,(Hma,(Mur,(Uth,(Uam,(Uar,Uma))))),Ame);
+(Tor,(Hma,((Uam,(Uar,Uma)),(Mur,Uth))),Ame);
+(Tor,(Mur,((Uar,Uma),((Uam,Uth),Hma))),Ame);
+(Tor,(((Uam,Uth),Hma),(Mur,(Uar,Uma))),Ame);
+(Tor,(Mur,((Uar,Uma),((Uam,Uth),Hma))),Ame);
+(Tor,((Hma,Mur),(Uth,((Uar,Uma),Uam))),Ame);
+(Tor,(((Uar,Uma),Uam),(Hma,(Mur,Uth))),Ame);
+(Tor,(((Uar,Uma),((Uth,Uam),Hma)),Mur),Ame);
+((Hma,((Uar,Uma),(Mur,(Uam,Uth)))),Tor,Ame);
+((Hma,(Mur,(Uth,(Uam,(Uar,Uma))))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Tor,Ame);
+(((Mur,Hma),((Uam,(Uar,Uma)),Uth)),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uar,Uma),(Hma,(Uth,Uam))),Mur),Tor,Ame);
+(((Hma,Mur),(((Uar,Uma),Uam),Uth)),Tor,Ame);
+((Hma,(Mur,(((Uar,Uma),Uam),Uth))),Tor,Ame);
+((Hma,(((Uar,Uma),Uam),(Uth,Mur))),Tor,Ame);
+((Hma,(((Uar,Uma),Uam),(Uth,Mur))),Tor,Ame);
+(Tor,((Hma,Mur),((Uam,(Uma,Uar)),Uth)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,(((Uth,Uam),Mur),(Hma,(Uma,Uar))),Ame);
+(Tor,((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Ame);
+(Tor,(((Uth,Mur),(Uam,(Uma,Uar))),Hma),Ame);
+(Tor,((Hma,Mur),((Uth,Uam),(Uma,Uar))),Ame);
+(Tor,(Hma,(Mur,(Uth,(Uam,(Uma,Uar))))),Ame);
+(Tor,((Hma,(Mur,(Uth,Uam))),(Uma,Uar)),Ame);
+(Tor,((Uth,Uam),((Uma,Uar),(Hma,Mur))),Ame);
+(((Uam,(Uar,Uma)),((Uth,Hma),Mur)),Tor,Ame);
+((((Uth,Uam),Mur),(Hma,(Uar,Uma))),Tor,Ame);
+((((Uth,Uam),Mur),(Hma,(Uar,Uma))),Tor,Ame);
+((((Hma,(Uth,Uam)),Mur),(Uar,Uma)),Tor,Ame);
+(((Uth,Uam),((Mur,Hma),(Uar,Uma))),Tor,Ame);
+((Hma,(Mur,(Uth,((Uar,Uma),Uam)))),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Mur),Uth)),Tor,Ame);
+(((((Uam,Uth),Hma),(Uar,Uma)),Mur),Tor,Ame);
+(((((Uam,Uth),Hma),(Uar,Uma)),Mur),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(Tor,(((Hma,Mur),Uth),((Uar,Uma),Uam)),Ame);
+(Tor,((((Uth,Uam),Hma),Mur),(Uar,Uma)),Ame);
+(Tor,(((Uth,(Uam,(Uar,Uma))),Mur),Hma),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Mur,Hma)),Ame);
+(Tor,((Mur,((Uam,(Uar,Uma)),Uth)),Hma),Ame);
+(Tor,(((Uam,(Uar,Uma)),Uth),(Hma,Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,(Hma,((Uth,(Uam,(Uar,Uma))),Mur)),Ame);
+(Tor,(((Uar,Uma),Hma),((Uth,Uam),Mur)),Ame);
+(Tor,(Mur,(((Uar,Uma),Hma),(Uth,Uam))),Ame);
+((((Uth,Mur),Hma),((Uar,Uma),Uam)),Tor,Ame);
+(((Mur,(Hma,Uth)),((Uar,Uma),Uam)),Tor,Ame);
+((((Mur,Uth),((Uar,Uma),Uam)),Hma),Tor,Ame);
+((((Hma,Mur),Uth),((Uar,Uma),Uam)),Tor,Ame);
+(((Uar,Uma),(Hma,(Mur,(Uam,Uth)))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Uth,Hma),Mur)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+((Mur,((Uth,(Uam,(Uar,Uma))),Hma)),Tor,Ame);
+((Hma,(Mur,(Uth,(Uam,(Uma,Uar))))),Tor,Ame);
+((((Mur,Hma),Uth),(Uam,(Uma,Uar))),Tor,Ame);
+(((Mur,(Hma,Uth)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+((((Hma,(Uth,Uam)),Mur),(Uma,Uar)),Tor,Ame);
+((Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Tor,Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+((((Uth,Uam),(Uma,Uar)),(Hma,Mur)),Tor,Ame);
+(((Uth,Uam),((Uma,Uar),(Hma,Mur))),Tor,Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,(((Uam,(Uar,Uma)),Uth),(Hma,Mur)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,(((Uar,Uma),(Mur,(Uth,Uam))),Hma),Ame);
+(Tor,((Mur,(Uth,Uam)),(Hma,(Uar,Uma))),Ame);
+(Tor,((Mur,(Hma,(Uth,Uam))),(Uar,Uma)),Ame);
+(Tor,((Mur,(Hma,Uth)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Mur,Hma),(Uar,Uma)),(Uam,Uth)),Tor,Ame);
+((Uam,(Uth,(Mur,(Hma,(Uar,Uma))))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uam,(Uar,Uma)),Uth),(Hma,Mur)),Tor,Ame);
+((((Uam,(Uar,Uma)),Uth),(Hma,Mur)),Tor,Ame);
+(((Mur,(Uam,Uth)),(Hma,(Uar,Uma))),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Tor,Ame);
+(((Mur,(Hma,(Uam,Uth))),(Uar,Uma)),Tor,Ame);
+(((Mur,(Uam,Uth)),(Hma,(Uar,Uma))),Tor,Ame);
+(((Uar,Uma),(Hma,(Mur,(Uth,Uam)))),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uth,Uam)))),Tor,Ame);
+(((Uar,Uma),((Mur,(Uth,Uam)),Hma)),Tor,Ame);
+((((Uth,(Uam,(Uar,Uma))),Hma),Mur),Tor,Ame);
+(((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Mur,(((Uma,Uar),Uam),Uth)),Hma),Tor,Ame);
+(((((Uma,Uar),Uam),Uth),(Hma,Mur)),Tor,Ame);
+((Mur,((((Uma,Uar),Uam),Uth),Hma)),Tor,Ame);
+(((Mur,(((Uma,Uar),Uam),Uth)),Hma),Tor,Ame);
+((((Uma,Uar),(Uam,Uth)),(Hma,Mur)),Tor,Ame);
+((((Mur,Uth),(Uam,(Uma,Uar))),Hma),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+((Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Tor,Ame);
+(((Uth,((Uma,Uar),Uam)),(Mur,Hma)),Tor,Ame);
+(((Uma,Uar),(((Uam,Uth),Mur),Hma)),Tor,Ame);
+(Tor,(Hma,((Uam,(Uma,Uar)),(Mur,Uth))),Ame);
+(Tor,(Hma,((Mur,(Uth,Uam)),(Uma,Uar))),Ame);
+(Tor,(Hma,(Mur,(Uth,(Uam,(Uma,Uar))))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,(Hma,((Uth,(Uam,(Uma,Uar))),Mur)),Ame);
+(Tor,(((Uma,Uar),(Uam,(Uth,Hma))),Mur),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,(Mur,(Uth,(Hma,(Uam,(Uma,Uar))))),Ame);
+(Tor,(Mur,(((Uth,Uam),Hma),(Uma,Uar))),Ame);
+(Tor,(((Hma,Mur),Uth),(Uam,(Uma,Uar))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Ame);
+(Tor,(((Uma,Uar),((Uth,Uam),Mur)),Hma),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Hma),Mur)),Ame);
+(Tor,(((Uam,(Uma,Uar)),Uth),(Mur,Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Mur,Hma))),Ame);
+(Tor,((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Ame);
+(Tor,(Hma,(((Uam,(Uma,Uar)),Uth),Mur)),Ame);
+(Tor,(((Uth,Uam),(Uma,Uar)),(Mur,Hma)),Ame);
+(Tor,(((Mur,(Uth,Uam)),(Uma,Uar)),Hma),Ame);
+(Tor,(Hma,(Mur,(((Uar,Uma),Uam),Uth))),Ame);
+(Tor,(((Uar,Uma),Uam),(Hma,(Uth,Mur))),Ame);
+(Tor,(((Uar,Uma),Uam),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uth,((Uar,Uma),Uam)),(Hma,Mur)),Ame);
+(Tor,((Uar,Uma),((Uam,Uth),(Mur,Hma))),Ame);
+(Tor,(((Uam,(Uar,Uma)),(Uth,Mur)),Hma),Ame);
+(Tor,(((Uam,(Uar,Uma)),(Uth,Hma)),Mur),Ame);
+(Tor,((Uth,Mur),(Hma,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Ame);
+((Hma,((Uam,(Uar,Uma)),(Uth,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Tor,Ame);
+(((Hma,(Uam,(Uar,Uma))),(Mur,Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Mur,(Uth,Uam)),((Uar,Uma),Hma)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uma,Uar),(Mur,(Hma,(Uth,Uam)))),Tor,Ame);
+(((Uth,Uam),((Mur,Hma),(Uma,Uar))),Tor,Ame);
+(((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Uth),Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Mur,(Hma,Uth)),(Uam,(Uma,Uar))),Tor,Ame);
+((((Uma,Uar),(Uth,Uam)),(Mur,Hma)),Tor,Ame);
+((Uam,((Uth,(Mur,Hma)),(Uma,Uar))),Tor,Ame);
+((((Uma,Uar),Hma),((Uam,Uth),Mur)),Tor,Ame);
diff --git a/inst/extdata/trees/RAxML_bootstrap.AIs b/inst/extdata/trees/RAxML_bootstrap.AIs
new file mode 100644
index 0000000..07e4d88
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bootstrap.AIs
@@ -0,0 +1,550 @@
+(((Hma,Mur),((Uar,Uma),(Uth,Uam))),Tor,Ame);
+(((Hma,Mur),((Uar,Uma),(Uth,Uam))),Tor,Ame);
+(((Hma,Mur),(((Uar,Uma),Uam),Uth)),Tor,Ame);
+(((Uma,((Mur,Uth),Hma)),(Uar,Uam)),Tor,Ame);
+(((Uth,(Mur,Hma)),((Uma,Uar),Uam)),Tor,Ame);
+(((Mur,Hma),((Uma,Uar),(Uth,Uam))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uth,Uam),((Uma,Uar),(Mur,Hma))),Tor,Ame);
+(((Uth,(Mur,Uam)),((Uma,Uar),Hma)),Tor,Ame);
+((Hma,((Uam,(Uth,(Uma,Uar))),Mur)),Tor,Ame);
+(Tor,(((Uma,Uar),Uam),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uth,Uam),((Uma,(Hma,Mur)),Uar)),Ame);
+(Tor,(((Hma,Mur),Uth),(Uam,(Uma,Uar))),Ame);
+(Tor,(((Hma,Mur),Uth),((Uam,Uar),Uma)),Ame);
+(Tor,(Uam,((Uth,(Uar,Uma)),(Hma,Mur))),Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Ame);
+(Tor,((Uam,(Uth,Mur)),((Uar,Uma),Hma)),Ame);
+(Tor,((Hma,Mur),(((Uar,Uma),Uam),Uth)),Ame);
+(Tor,((Hma,(Uar,Uma)),((Uth,Mur),Uam)),Ame);
+(Tor,(Hma,(Mur,(Uth,(Uam,(Uar,Uma))))),Ame);
+(Tor,((((Hma,Mur),Uma),Uar),(Uam,Uth)),Ame);
+(Tor,((Hma,((Uam,Uth),Mur)),(Uma,Uar)),Ame);
+(Tor,(Uam,((Mur,Hma),((Uma,Uar),Uth))),Ame);
+(Tor,((Hma,(Uma,Uar)),(Uth,(Uam,Mur))),Ame);
+(Tor,((Mur,((Hma,(Uma,Uar)),Uth)),Uam),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,(((Uth,Uam),(Uma,Uar)),(Mur,Hma)),Ame);
+(Tor,((Uar,(Uma,(Hma,Mur))),(Uth,Uam)),Ame);
+(Tor,((Uar,(Uma,(Hma,(Uth,Mur)))),Uam),Ame);
+(Tor,(((Uth,(Uar,Uma)),(Hma,Mur)),Uam),Ame);
+(Tor,((Hma,Mur),((Uth,Uam),(Uar,Uma))),Ame);
+(Tor,(((Mur,Uth),Uam),((Uar,Uma),Hma)),Ame);
+(Tor,(((Mur,Hma),Uth),(Uam,(Uar,Uma))),Ame);
+(Tor,((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Hma,(Uar,Uma)),(Mur,(Uam,Uth))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Ame);
+(Tor,((Mur,(Uth,Uam)),((Uar,Uma),Hma)),Ame);
+(Tor,(((Hma,Uma),(Uam,(Mur,Uth))),Uar),Ame);
+(Tor,(((Uar,Uma),((Mur,Uth),Hma)),Uam),Ame);
+(Tor,((Mur,Hma),(Uam,(Uth,(Uar,Uma)))),Ame);
+(Tor,((Uth,Mur),(Hma,(Uam,(Uar,Uma)))),Ame);
+(Tor,(Hma,((Mur,(Uth,Uam)),(Uar,Uma))),Ame);
+(Tor,(Hma,((Uam,(Mur,Uth)),(Uar,Uma))),Ame);
+(Tor,((Uam,Uth),(Uar,(Uma,(Hma,Mur)))),Ame);
+(Tor,(Uam,(Uar,(Uma,(Hma,(Uth,Mur))))),Ame);
+(Tor,((Uth,((Uma,Uar),Uam)),(Hma,Mur)),Ame);
+(Tor,((Mur,(Uam,Uth)),((Uma,Uar),Hma)),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uar,Uma))),Ame);
+(Tor,((Mur,(Uam,Uth)),(Hma,(Uar,Uma))),Ame);
+(Tor,(Hma,((Uar,Uma),(Mur,(Uam,Uth)))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,(((Uth,Uam),(Uar,Uma)),(Hma,Mur)),Ame);
+(Tor,(((Uma,Uar),Uam),(Hma,(Uth,Mur))),Ame);
+(Tor,((Hma,(Uma,Uar)),((Uth,Mur),Uam)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,(Uam,((Uma,((Uth,Mur),Hma)),Uar)),Ame);
+(Tor,(Uam,((Uth,Mur),(Hma,(Uar,Uma)))),Ame);
+(Tor,((Uth,Uam),(((Hma,Mur),Uma),Uar)),Ame);
+(Tor,(Uam,(((Hma,(Uth,Mur)),Uma),Uar)),Ame);
+(Tor,(Uam,((Hma,Mur),(Uth,(Uar,Uma)))),Ame);
+(Tor,((Uth,Uam),(((Hma,Mur),Uma),Uar)),Ame);
+(Tor,(((Mur,Uth),Uam),(Hma,(Uma,Uar))),Ame);
+(Tor,(((Uth,Hma),Mur),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,(Mur,Uth)),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,(Mur,Uth)),((Uar,Uma),Uam)),Ame);
+(Tor,(((Mur,Uth),Uam),(Hma,(Uar,Uma))),Ame);
+(Tor,((((Hma,Mur),Uth),Uam),(Uar,Uma)),Ame);
+(Tor,((Uth,Uam),((Mur,Hma),(Uar,Uma))),Ame);
+(Tor,((Mur,((Hma,(Uar,Uma)),Uth)),Uam),Ame);
+(Tor,((Hma,Mur),((Uth,Uam),(Uar,Uma))),Ame);
+(Tor,((Hma,(Uth,Mur)),((Uam,Uar),Uma)),Ame);
+(Tor,((Hma,(Uth,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,(Uth,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,Mur),((Uar,Uma),(Uth,Uam))),Ame);
+(Tor,((Hma,(Uth,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,(Uma,Uar)),((Mur,Uth),Uam)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Mur,(Uth,Hma))),Ame);
+(Tor,((Uth,Uam),((Uma,Uar),(Mur,Hma))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Mur,Hma))),Ame);
+(Tor,(Uam,((Uth,(Uar,Uma)),(Mur,Hma))),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uar,Uma))),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uar,Uma))),Ame);
+(Tor,((((Uth,Mur),Uam),(Uar,Uma)),Hma),Ame);
+(Tor,(((Uth,(Mur,Uam)),(Uar,Uma)),Hma),Ame);
+(((Uam,(Uth,(Uar,Uma))),(Hma,Mur)),Tor,Ame);
+((((Uar,Uam),Uma),(Hma,(Uth,Mur))),Tor,Ame);
+((((Uth,Mur),((Uar,Uma),Hma)),Uam),Tor,Ame);
+(((Uth,(Uar,((Hma,Mur),Uma))),Uam),Tor,Ame);
+(((Hma,(Uma,(Uam,Uar))),(Uth,Mur)),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+((Hma,((Uth,(Uam,(Uma,Uar))),Mur)),Tor,Ame);
+(((Hma,(Uar,Uma)),(Uam,(Uth,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Tor,Ame);
+(((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Tor,Ame);
+((((Uar,Uma),(Uth,Uam)),(Hma,Mur)),Tor,Ame);
+((Uar,(Uma,(((Mur,Uth),Uam),Hma))),Tor,Ame);
+((Uam,((Hma,(Uar,Uma)),(Mur,Uth))),Tor,Ame);
+(((Uth,Uam),((Uar,Uma),(Hma,Mur))),Tor,Ame);
+((((Uam,Uar),Uma),(Hma,(Uth,Mur))),Tor,Ame);
+(((Uam,(Mur,Uth)),((Uma,Uar),Hma)),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+((((Uma,((Hma,Mur),Uth)),Uar),Uam),Tor,Ame);
+(((Hma,(Mur,Uth)),((Uar,Uma),Uam)),Tor,Ame);
+((Uam,((Hma,(Mur,Uth)),(Uar,Uma))),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Uar,((Hma,Mur),Uma)),(Uth,Uam)),Tor,Ame);
+((((Hma,Mur),Uth),(Uam,(Uma,Uar))),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uam,(Uth,Mur)),(Hma,(Uma,Uar))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Uth,Mur))),Tor,Ame);
+((((Uma,Uar),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uma,Uar),(Uam,(Mur,Uth))),Hma),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+((Mur,((Uth,Uam),((Uar,Uma),Hma))),Tor,Ame);
+((Uam,((Uth,Mur),((Uma,Uar),Hma))),Tor,Ame);
+((((Uma,Uar),Hma),((Uth,Uam),Mur)),Tor,Ame);
+((((Uma,(Uam,Uar)),Hma),(Mur,Uth)),Tor,Ame);
+(Tor,((((Uma,Uar),Uth),(Mur,Hma)),Uam),Ame);
+(Tor,((((Uth,Mur),Hma),Uma),(Uam,Uar)),Ame);
+(Tor,((Mur,Hma),(Uth,(Uam,(Uma,Uar)))),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uma,Uar))),Ame);
+(Tor,((Mur,Hma),((Uth,(Uam,Uar)),Uma)),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uar,Uma))),Ame);
+(Tor,((Hma,(Uar,Uma)),(Mur,(Uth,Uam))),Ame);
+(Tor,((Uar,(Uma,((Mur,Uth),Hma))),Uam),Ame);
+(Tor,(((Mur,Hma),(Uar,Uma)),(Uth,Uam)),Ame);
+(Tor,((Hma,(Uth,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,(((Uma,Uar),Uam),((Mur,Uth),Hma)),Ame);
+(Tor,(((Uth,(Uma,Uar)),Uam),(Mur,Hma)),Ame);
+(Tor,(Uam,(((Uth,Mur),Hma),(Uar,Uma))),Ame);
+(Tor,((Uth,((Uar,Uma),Uam)),(Mur,Hma)),Ame);
+(Tor,(((Uar,Uma),Hma),((Uth,Uam),Mur)),Ame);
+(Tor,((Hma,Mur),((Uar,Uma),(Uth,Uam))),Ame);
+(Tor,((Hma,(Uth,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,((((Uar,Uma),Uth),(Mur,Hma)),Uam),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uar,Uma))),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uar,Uma))),Ame);
+((((Mur,Hma),((Uar,Uma),Uth)),Uam),Tor,Ame);
+((((Uth,Uam),(Uar,Uma)),(Mur,Hma)),Tor,Ame);
+((((Mur,Uth),Uam),(Hma,(Uar,Uma))),Tor,Ame);
+(((Uth,(Uam,Mur)),(Hma,(Uar,Uma))),Tor,Ame);
+(((Uth,Uam),((Mur,Hma),(Uar,Uma))),Tor,Ame);
+(((Uth,Uam),(Mur,(Hma,(Uar,Uma)))),Tor,Ame);
+((((Uar,Uma),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+((((Hma,(Uar,Uma)),(Uth,Uam)),Mur),Tor,Ame);
+((((Uam,Uar),Uma),((Mur,Uth),Hma)),Tor,Ame);
+((((Mur,Hma),((Uma,Uar),Uth)),Uam),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+((((Uth,Mur),Hma),(Uma,(Uam,Uar))),Tor,Ame);
+(((Uth,Mur),(Hma,(Uma,(Uam,Uar)))),Tor,Ame);
+(((Uam,Uth),(Uar,((Mur,Hma),Uma))),Tor,Ame);
+(((Uth,(Mur,Hma)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uth,Mur),(Hma,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uma,(Uar,Uam))),Tor,Ame);
+(((Uth,Mur),(((Uam,Uma),Uar),Hma)),Tor,Ame);
+((((Uth,(Hma,Mur)),(Uma,Uar)),Uam),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+(((Uth,Uam),(Uar,((Hma,Mur),Uma))),Tor,Ame);
+((((Mur,Uth),Hma),((Uma,Uar),Uam)),Tor,Ame);
+((Uam,((Uma,((Mur,Uth),Hma)),Uar)),Tor,Ame);
+((Uam,((Uth,(Hma,Mur)),(Uar,Uma))),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Tor,Ame);
+(((Uam,Uar),(Uma,(Uth,(Hma,Mur)))),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Tor,Ame);
+((Uam,((Uar,Uma),(Hma,(Mur,Uth)))),Tor,Ame);
+(((Uar,(Hma,Uma)),((Mur,Uth),Uam)),Tor,Ame);
+((((Mur,Uth),Hma),((Uma,Uar),Uam)),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+((Uam,(((Uar,Uma),Uth),(Mur,Hma))),Tor,Ame);
+(((Uam,(Mur,Uth)),(Hma,(Uar,Uma))),Tor,Ame);
+((Uam,((Hma,Mur),((Uar,Uma),Uth))),Tor,Ame);
+((Uam,((Hma,Mur),((Uar,Uma),Uth))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Hma,Mur),((Uar,Uma),Uth)),Uam),Tor,Ame);
+(((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Tor,Ame);
+((((Uth,Uam),(Uar,Uma)),(Hma,Mur)),Tor,Ame);
+((((Uth,Uam),(Uar,Uma)),(Hma,Mur)),Tor,Ame);
+(Tor,((Uma,(((Uth,Mur),Hma),Uar)),Uam),Ame);
+(Tor,(Uam,(Uar,(Uma,(Uth,(Mur,Hma))))),Ame);
+(Tor,(((Mur,Hma),((Uar,Uma),Uth)),Uam),Ame);
+(Tor,((Hma,((Uar,Uma),(Mur,Uth))),Uam),Ame);
+(Tor,((Mur,Hma),((Uma,Uar),(Uth,Uam))),Ame);
+(Tor,(((Mur,Uth),Hma),((Uma,Uar),Uam)),Ame);
+(Tor,(((Uam,(Mur,Uth)),Hma),(Uma,Uar)),Ame);
+(Tor,(((Hma,Mur),Uth),(Uam,(Uma,Uar))),Ame);
+(Tor,((Uth,Uam),(((Hma,Mur),Uma),Uar)),Ame);
+(Tor,((Hma,(Uth,Mur)),((Uma,Uar),Uam)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Ame);
+(Tor,((Uam,(Mur,Uth)),((Uma,Uar),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Ame);
+(Tor,(((Uth,Uam),(Uar,Uma)),(Hma,Mur)),Ame);
+(Tor,(((Mur,Uth),Uam),((Uar,Uma),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,(((Uth,Uam),(Uar,Uma)),(Mur,Hma)),Ame);
+(Tor,(((Mur,Uth),Uam),((Uar,Uma),Hma)),Ame);
+((Hma,((Uam,(Uth,Mur)),(Uma,Uar))),Tor,Ame);
+(((Uam,(Uth,Mur)),(Hma,(Uma,Uar))),Tor,Ame);
+(((((Uma,Uar),Uth),(Hma,Mur)),Uam),Tor,Ame);
+((((Uma,Uar),Hma),((Uth,Mur),Uam)),Tor,Ame);
+(((Hma,Mur),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uma,Uar))),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uma,Uar))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uth,(Uam,(Uma,Uar))),(Hma,Mur)),Tor,Ame);
+(((Uam,(Uth,Mur)),((Uma,Uar),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Uth,(Uam,(Uma,Uar))),(Hma,Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Mur,Hma))),Tor,Ame);
+(((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+(((Mur,Hma),((Uth,Uam),(Uma,Uar))),Tor,Ame);
+(((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+(((((Uma,Uar),Uth),(Mur,Hma)),Uam),Tor,Ame);
+(((Uma,Uar),((Uth,(Mur,Hma)),Uam)),Tor,Ame);
+(((Uth,(Mur,Hma)),(Uam,(Uma,Uar))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Uth,Mur))),Tor,Ame);
+((((Uth,Mur),Uam),(Hma,(Uma,Uar))),Tor,Ame);
+(((Uth,Uam),((Mur,Hma),(Uma,Uar))),Tor,Ame);
+(((Uth,Uam),((Hma,(Uma,Uar)),Mur)),Tor,Ame);
+((((Uma,Uar),Hma),((Mur,Uth),Uam)),Tor,Ame);
+((Uam,((Hma,Mur),((Uma,Uar),Uth))),Tor,Ame);
+(((Hma,(Uth,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+((((Uma,Uar),Uam),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,(Uma,Uar)),(Uam,(Mur,Uth))),Tor,Ame);
+(((Hma,(Uma,Uar)),(Mur,(Uth,Uam))),Tor,Ame);
+(((Uam,(Uth,Mur)),((Uma,Uar),Hma)),Tor,Ame);
+((Uth,(Uam,(((Hma,Mur),Uma),Uar))),Tor,Ame);
+((Hma,(Mur,((Uam,(Uma,Uar)),Uth))),Tor,Ame);
+((Uam,((Hma,Mur),((Uma,Uar),Uth))),Tor,Ame);
+(((Uma,(Uar,(Hma,(Uth,Mur)))),Uam),Tor,Ame);
+((((Uth,(Mur,Hma)),(Uma,Uar)),Uam),Tor,Ame);
+(((Mur,Hma),((Uam,(Uma,Uar)),Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uth,(Uam,(Uma,Uar))),(Mur,Hma)),Tor,Ame);
+((Hma,((Uam,(Uth,Mur)),(Uma,Uar))),Tor,Ame);
+(Tor,((Uth,(Mur,Hma)),((Uma,Uar),Uam)),Ame);
+(Tor,((Uma,Uar),(Uam,(Uth,(Mur,Hma)))),Ame);
+(Tor,((Uma,Uar),((Mur,(Uam,Uth)),Hma)),Ame);
+(Tor,(((Mur,Uth),Hma),(Uam,(Uma,Uar))),Ame);
+(Tor,(Uam,((Uma,Uar),(Uth,(Hma,Mur)))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,(Uam,((Uar,Uma),(Hma,(Mur,Uth)))),Ame);
+(Tor,(Uam,(Mur,(Uth,((Uar,Uma),Hma)))),Ame);
+(Tor,(Uam,((Hma,Mur),(Uth,(Uar,Uma)))),Ame);
+(Tor,((Hma,Mur),(Uth,((Uma,Uar),Uam))),Ame);
+(Tor,(Uam,((Mur,Hma),((Uma,Uar),Uth))),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uma,Uar))),Ame);
+(Tor,((Uma,((Uth,Mur),Hma)),(Uam,Uar)),Ame);
+(Tor,((Mur,Hma),((Uth,Uam),(Uar,Uma))),Ame);
+(Tor,((Uth,Uam),((Uar,Uma),(Mur,Hma))),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,(Uam,((Uar,Uma),(Hma,(Uth,Mur)))),Ame);
+(Tor,(Uam,((Uth,(Uar,Uma)),(Hma,Mur))),Ame);
+(Tor,(((Uam,Uth),(Uar,Uma)),(Hma,Mur)),Ame);
+((((Uma,Uar),Uam),((Uth,Mur),Hma)),Tor,Ame);
+((((Uma,Uar),Uam),((Mur,Hma),Uth)),Tor,Ame);
+(((Mur,Uth),(Hma,((Uma,Uar),Uam))),Tor,Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+(((Hma,(Uth,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+((Uam,(((Hma,Mur),Uth),(Uma,Uar))),Tor,Ame);
+((Uam,((Mur,Uth),(Hma,(Uma,Uar)))),Tor,Ame);
+(((Uth,Uam),(((Hma,Mur),Uma),Uar)),Tor,Ame);
+((((Uma,Uar),Uam),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Mur,((Uma,Uar),Uth))),Hma),Tor,Ame);
+(((((Uma,Uar),Uam),Uth),(Mur,Hma)),Tor,Ame);
+((((Uma,Uar),Uam),(Mur,(Uth,Hma))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uam,Mur),Uth),((Uma,Uar),Hma)),Tor,Ame);
+(((Mur,Hma),((Uar,(Uam,Uth)),Uma)),Tor,Ame);
+(((Mur,Hma),((Uam,Uth),(Uma,Uar))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Hma,(Uma,Uar)),((Uam,Uth),Mur)),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(Tor,(((Uma,Uar),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,(((Uma,Uar),Uam),(Hma,(Uth,Mur))),Ame);
+(Tor,(Uam,(Mur,((Hma,(Uma,Uar)),Uth))),Ame);
+(Tor,((Mur,Hma),((Uma,Uar),(Uam,Uth))),Ame);
+(Tor,(((Uth,Uma),(Mur,Hma)),(Uar,Uam)),Ame);
+(Tor,(Hma,(Mur,((Uma,Uar),(Uam,Uth)))),Ame);
+(Tor,((Uth,((Uma,Uar),Uam)),(Hma,Mur)),Ame);
+(Tor,(((Uam,Uth),Mur),((Uma,Uar),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,(Uam,(((Uar,Uma),Hma),(Uth,Mur))),Ame);
+(Tor,(((Uma,Uar),(Uth,Uam)),(Hma,Mur)),Ame);
+(Tor,(Uam,((Uma,Uar),(Hma,(Mur,Uth)))),Ame);
+(Tor,((((Uam,(Uma,Uar)),Uth),Mur),Hma),Ame);
+(Tor,(((Uth,Uam),Uar),(Uma,(Hma,Mur))),Ame);
+(Tor,(Uam,((Uar,Uma),(Uth,(Hma,Mur)))),Ame);
+(Tor,((Hma,Mur),((Uth,Uam),(Uar,Uma))),Ame);
+(Tor,(((Hma,Mur),(Uth,(Uar,Uma))),Uam),Ame);
+(Tor,(((Hma,Mur),(Uth,(Uar,Uma))),Uam),Ame);
+(Tor,((Hma,(Uth,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,(((Uar,Uma),Hma),((Uam,Uth),Mur)),Ame);
+((Uam,((Uth,(Uar,Uma)),(Mur,Hma))),Tor,Ame);
+((Uam,((Hma,(Uar,Uma)),(Mur,Uth))),Tor,Ame);
+((Uam,(((Hma,Mur),Uth),(Uar,Uma))),Tor,Ame);
+((Uam,((Hma,Mur),(Uth,(Uar,Uma)))),Tor,Ame);
+(((Uar,(Uth,Uam)),((Hma,Mur),Uma)),Tor,Ame);
+(((Hma,Mur),((Uar,Uma),(Uth,Uam))),Tor,Ame);
+(((Uth,(Uma,(Hma,Mur))),(Uar,Uam)),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+((Uam,((Uth,Mur),((Uar,Uma),Hma))),Tor,Ame);
+((Uam,(Uma,((Hma,(Uth,Mur)),Uar))),Tor,Ame);
+(((Mur,Hma),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+((((Uam,Mur),Uth),(Hma,(Uar,Uma))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+(((Mur,((Uam,(Uar,Uma)),Uth)),Hma),Tor,Ame);
+((Uam,(Uar,(Uma,((Hma,Mur),Uth)))),Tor,Ame);
+(((Uth,Uam),(Uar,((Hma,Mur),Uma))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uma,(Hma,Mur)),((Uth,Uam),Uar)),Tor,Ame);
+((((Uma,(Hma,(Uth,Mur))),Uar),Uam),Tor,Ame);
+((((Uth,(Mur,Hma)),(Uar,Uma)),Uam),Tor,Ame);
+((Uam,(((Hma,(Uth,Mur)),Uma),Uar)),Tor,Ame);
+((Hma,((Uma,Uar),((Uth,Mur),Uam))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((((Hma,Mur),Uth),Uam),(Uar,Uma)),Tor,Ame);
+((Uam,(((Hma,(Mur,Uth)),Uar),Uma)),Tor,Ame);
+(((Hma,Mur),(Uma,(Uth,(Uar,Uam)))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Uma,Uar),(((Uth,Hma),Mur),Uam)),Tor,Ame);
+(((Mur,(Hma,(Uma,Uar))),(Uth,Uam)),Tor,Ame);
+(((((Hma,(Mur,Uth)),Uma),Uar),Uam),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uth,(Uma,(Uar,Uam))),(Hma,Mur)),Tor,Ame);
+(((Hma,(Uth,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+((((Uma,Uar),Uam),((Hma,Mur),Uth)),Tor,Ame);
+(Tor,((Uth,Uam),((Uar,Uma),(Mur,Hma))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,(((Uth,Uam),(Uar,Uma)),(Mur,Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Mur,Hma))),Ame);
+(Tor,(Uam,((Uth,(Uar,Uma)),(Mur,Hma))),Ame);
+(Tor,((Mur,Hma),((Uth,Uam),(Uar,Uma))),Ame);
+(Tor,(((Mur,Hma),((Uar,Uma),Uth)),Uam),Ame);
+(Tor,((Mur,Hma),((Uar,Uma),(Uth,Uam))),Ame);
+(Tor,((Mur,Hma),((Uar,Uma),(Uth,Uam))),Ame);
+(Tor,(((Uth,Mur),Hma),((Uar,Uma),Uam)),Ame);
+(Tor,((Uth,(Uam,(Uar,Uma))),(Hma,Mur)),Ame);
+(Tor,(Uam,(((Hma,(Uth,Mur)),Uar),Uma)),Ame);
+(Tor,((Mur,Hma),((Uam,(Uar,Uma)),Uth)),Ame);
+(Tor,(Uam,(Uar,(((Mur,Uth),Hma),Uma))),Ame);
+(Tor,(Uam,((Uth,(Hma,Mur)),(Uma,Uar))),Ame);
+(Tor,((Uam,(Uth,(Hma,Mur))),(Uma,Uar)),Ame);
+(Tor,((Hma,(Mur,Uth)),(Uma,(Uam,Uar))),Ame);
+(Tor,(((Hma,Mur),Uth),(Uam,(Uma,Uar))),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Ame);
+(Tor,(((Uma,Uar),((Hma,Mur),Uth)),Uam),Ame);
+(((Uth,Uam),(Uar,(Uma,(Mur,Hma)))),Tor,Ame);
+((((Mur,Hma),Uth),(Uam,(Uar,Uma))),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uam,(Uth,Mur)),(Hma,(Uar,Uma))),Tor,Ame);
+(((Uth,(Mur,Uam)),(Hma,(Uar,Uma))),Tor,Ame);
+(((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Tor,Ame);
+(((Hma,Mur),(((Uar,Uma),Uam),Uth)),Tor,Ame);
+(((Uar,(((Mur,Uth),Hma),Uma)),Uam),Tor,Ame);
+((((Mur,Uth),Hma),(Uma,(Uam,Uar))),Tor,Ame);
+(((Mur,Hma),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uth,Uam),((Uma,Uar),(Hma,Mur))),Tor,Ame);
+((((Mur,Uth),Uam),((Uma,Uar),Hma)),Tor,Ame);
+(((Uth,Uam),(Uar,((Mur,Hma),Uma))),Tor,Ame);
+((Uam,(Uar,(((Uth,Mur),Hma),Uma))),Tor,Ame);
+((Uam,(((Uma,Uar),Uth),(Mur,Hma))),Tor,Ame);
+((Uam,(((Uma,Uar),Uth),(Mur,Hma))),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+((((Hma,(Uma,Uar)),(Mur,Uth)),Uam),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+((Uam,(Uar,(Uma,(Hma,(Mur,Uth))))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+((Uam,(Mur,((Uth,Hma),(Uar,Uma)))),Tor,Ame);
+((Uam,(Mur,((Uth,Hma),(Uar,Uma)))),Tor,Ame);
+((((Uam,Uar),Uma),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),(Hma,Mur)),(Uth,Uam)),Tor,Ame);
+(((Uth,Uam),((Uma,(Hma,Mur)),Uar)),Tor,Ame);
+(((Uth,(Mur,Uam)),(Hma,(Uar,Uma))),Tor,Ame);
+((Uam,((Mur,Hma),(Uth,(Uma,Uar)))),Tor,Ame);
+(((Mur,Hma),((Uam,Uth),(Uma,Uar))),Tor,Ame);
+(((Uam,Uth),(Uar,(Uma,(Mur,Hma)))),Tor,Ame);
+((Hma,((Uar,Uma),(Uam,(Mur,Uth)))),Tor,Ame);
+(((Uar,Uma),(Uam,((Hma,Mur),Uth))),Tor,Ame);
+(((Uam,Uar),(Uma,(Hma,(Mur,Uth)))),Tor,Ame);
+((Uam,((Uar,Uma),(Hma,(Mur,Uth)))),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+((((Uar,Uma),(Hma,Mur)),(Uth,Uam)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(Tor,((Hma,(Uth,Mur)),((Uam,Uar),Uma)),Ame);
+(Tor,(((Uth,Mur),(Hma,(Uar,Uma))),Uam),Ame);
+(Tor,((Mur,(Hma,(Uar,Uma))),(Uth,Uam)),Ame);
+(Tor,((Uth,Uam),((Mur,Hma),(Uar,Uma))),Ame);
+(Tor,((Mur,(Uth,Uam)),(Hma,(Uar,Uma))),Ame);
+(Tor,(Uam,((Hma,Mur),((Uar,Uma),Uth))),Ame);
+(Tor,(Uam,((Hma,Mur),((Uar,Uma),Uth))),Ame);
+(Tor,((Hma,(Uar,Uma)),((Uth,Mur),Uam)),Ame);
+(Tor,((Hma,Mur),((Uam,Uth),(Uar,Uma))),Ame);
+(Tor,((Hma,Mur),((Uam,Uth),(Uar,Uma))),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,(Uam,((Uar,Uma),(Uth,(Hma,Mur)))),Ame);
+(Tor,((Uar,Uma),((Uth,(Hma,Mur)),Uam)),Ame);
+(Tor,((((Uar,Uma),Uth),(Hma,Mur)),Uam),Ame);
+(Tor,((Hma,(Mur,Uth)),((Uar,Uma),Uam)),Ame);
+(Tor,((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,((Hma,Mur),((Uar,Uma),(Uth,Uam))),Ame);
+(Tor,(((Hma,Mur),((Uar,Uma),Uth)),Uam),Ame);
+(Tor,((Hma,Mur),((Uam,(Uar,Uma)),Uth)),Ame);
+(((Uam,(Uma,Uar)),(Uth,(Mur,Hma))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Tor,Ame);
+((Uam,((Uth,Mur),((Uma,Uar),Hma))),Tor,Ame);
+(((Hma,Mur),((Uma,Uar),(Uth,Uam))),Tor,Ame);
+(((Uth,Uam),((Hma,Mur),(Uma,Uar))),Tor,Ame);
+(((Uth,(Mur,Uam)),(Hma,(Uma,Uar))),Tor,Ame);
+(((Mur,Hma),((Uma,Uar),(Uth,Uam))),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+(((Mur,Hma),((Uth,Uam),(Uma,Uar))),Tor,Ame);
+((Hma,(((Uam,Uth),Mur),(Uma,Uar))),Tor,Ame);
+(((Uth,Mur),((Uma,(Uam,Uar)),Hma)),Tor,Ame);
+((Hma,((Uth,(Uam,Mur)),(Uma,Uar))),Tor,Ame);
+(((Mur,Hma),(Uam,((Uma,Uar),Uth))),Tor,Ame);
+(((Mur,((Uma,Uar),Hma)),(Uam,Uth)),Tor,Ame);
+((((Uma,(Uam,Uar)),Uth),(Hma,Mur)),Tor,Ame);
+(((Mur,(Uth,Uam)),((Uar,Uma),Hma)),Tor,Ame);
+(((Uma,(Uam,Uar)),(Hma,(Uth,Mur))),Tor,Ame);
+((((Uam,Uth),Mur),((Uma,Uar),Hma)),Tor,Ame);
+((((Uam,Uth),Mur),((Uma,Uar),Hma)),Tor,Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,(Uam,((Uth,Mur),((Uar,Uma),Hma))),Ame);
+(Tor,((Uar,Uma),(Uam,(Uth,(Hma,Mur)))),Ame);
+(Tor,((Mur,Hma),((Uar,Uma),(Uam,Uth))),Ame);
+(Tor,((Mur,Hma),((Uar,Uma),(Uam,Uth))),Ame);
+(Tor,((Mur,(Uam,Uth)),(Hma,(Uar,Uma))),Ame);
+(Tor,((Uam,(Uth,Mur)),(Hma,(Uar,Uma))),Ame);
+(Tor,((Uth,(Hma,Mur)),((Uar,Uma),Uam)),Ame);
+(Tor,(Uam,((Hma,Mur),(Uth,(Uar,Uma)))),Ame);
+(Tor,((Uar,(Hma,Uma)),(Uth,(Uam,Mur))),Ame);
+(Tor,((Uam,(Mur,Uth)),(Hma,(Uar,Uma))),Ame);
+(Tor,(Uam,((Hma,(Mur,Uth)),(Uar,Uma))),Ame);
+(Tor,((Hma,(Mur,Uth)),((Uar,Uma),Uam)),Ame);
+(Tor,(Hma,(Mur,(((Uar,Uma),Uam),Uth))),Ame);
+(Tor,(Uam,(Uar,((Hma,(Mur,Uth)),Uma))),Ame);
+(Tor,(Uam,(Uar,((Hma,(Mur,Uth)),Uma))),Ame);
+(Tor,(((Uth,(Hma,Mur)),Uma),(Uam,Uar)),Ame);
+(Tor,(((Uth,Mur),Hma),(Uam,(Uma,Uar))),Ame);
+(Tor,(((Uam,(Uth,Mur)),Hma),(Uma,Uar)),Ame);
+(((Uma,(Uth,(Hma,Mur))),(Uam,Uar)),Tor,Ame);
+((((Uth,Mur),Hma),(Uam,(Uar,Uma))),Tor,Ame);
+(((Mur,Hma),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+((Uam,(Uar,(((Uth,Mur),Hma),Uma))),Tor,Ame);
+(((Mur,(Uam,Uth)),(Hma,(Uma,Uar))),Tor,Ame);
+(((Uam,Uth),(Uar,((Hma,Mur),Uma))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Tor,Ame);
+((Uam,(Uar,(Uma,((Uth,Mur),Hma)))),Tor,Ame);
+((Uam,(Uar,(Uma,((Uth,Mur),Hma)))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Uth,Mur),Hma)),Tor,Ame);
+(((Uam,(Mur,Uth)),((Uma,Uar),Hma)),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uma,Uar))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uth,Uam),((Uma,Uar),(Hma,Mur))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+((Uam,(((Hma,(Mur,Uth)),Uma),Uar)),Tor,Ame);
+((((Uma,Uar),Hma),((Uth,Uam),Mur)),Tor,Ame);
+((((Hma,Mur),((Uma,Uar),Uth)),Uam),Tor,Ame);
+(((Hma,Mur),((Uma,Uar),(Uth,Uam))),Tor,Ame);
+(((Hma,((Uma,Uar),(Mur,Uth))),Uam),Tor,Ame);
+(((Mur,(Uam,Uth)),(Hma,(Uma,Uar))),Tor,Ame);
+((((Uma,Uar),Uam),((Mur,Hma),Uth)),Tor,Ame);
+((((Uma,Uar),(Uth,Uam)),(Mur,Hma)),Tor,Ame);
+(((Mur,Hma),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+((((Mur,Hma),((Uma,Uar),Uth)),Uam),Tor,Ame);
+(((Mur,Hma),((Uma,Uar),(Uth,Uam))),Tor,Ame);
+(((Mur,Hma),((Uma,Uar),(Uth,Uam))),Tor,Ame);
+(((Uth,(Mur,Hma)),((Uma,Uar),Uam)),Tor,Ame);
+(((Uma,Uar),(Uam,(Uth,(Mur,Hma)))),Tor,Ame);
+(((Hma,(Uth,Mur)),((Uma,Uar),Uam)),Tor,Ame);
+(((Uth,Uam),((Uar,Uma),(Hma,Mur))),Tor,Ame);
+(((Uth,Uam),((Uar,Uma),(Hma,Mur))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+((Uam,(Uar,(Uma,(Uth,(Mur,Hma))))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Uth,Mur),Hma)),Tor,Ame);
+(((Uma,(Uam,Uar)),((Uth,Mur),Hma)),Tor,Ame);
+(((Uth,Mur),(Hma,(Uma,(Uam,Uar)))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(Tor,(Uam,(Uar,(Uma,(Hma,(Uth,Mur))))),Ame);
+(Tor,((Hma,((Uth,Mur),Uma)),(Uam,Uar)),Ame);
+(Tor,(Uam,(((Hma,(Uma,Uar)),Mur),Uth)),Ame);
+(Tor,(((Uma,Uar),(Mur,Hma)),(Uth,Uam)),Ame);
+(Tor,((Uth,(Mur,Hma)),(Uam,(Uma,Uar))),Ame);
+(Tor,(((Uma,Uar),(Mur,Hma)),(Uam,Uth)),Ame);
+(Tor,(((Uma,Uar),Hma),(Mur,(Uam,Uth))),Ame);
+(Tor,((Uth,(Uam,(Uma,Uar))),(Hma,Mur)),Ame);
+(Tor,((Uam,(Uth,Mur)),((Uma,Uar),Hma)),Ame);
+(Tor,((Hma,(Uth,Mur)),(Uam,(Uma,Uar))),Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+((((Uar,Uma),((Hma,Mur),Uth)),Uam),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+((Uam,((Uar,Uma),(Hma,(Uth,Mur)))),Tor,Ame);
+((((Uam,Uar),Uma),(Hma,(Uth,Mur))),Tor,Ame);
+(((Mur,Hma),((Uam,(Uar,Uma)),Uth)),Tor,Ame);
+(((Hma,(Uam,(Uar,Uma))),(Uth,Mur)),Tor,Ame);
+((((Uth,(Mur,Uam)),(Uar,Uma)),Hma),Tor,Ame);
+((((Uar,Uma),(Hma,Mur)),(Uam,Uth)),Tor,Ame);
+((((Uar,Uma),Hma),((Mur,Uam),Uth)),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,(Uth,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,Mur),((Uth,Uam),(Uar,Uma))),Tor,Ame);
+(((Uar,(Uma,(Hma,(Uth,Mur)))),Uam),Tor,Ame);
+(((Mur,Hma),(((Uar,Uma),Uam),Uth)),Tor,Ame);
+(((Mur,Hma),((Uar,Uma),(Uam,Uth))),Tor,Ame);
+(((Mur,Hma),((Uar,Uma),(Uam,Uth))),Tor,Ame);
+(((Uar,((Mur,Hma),Uma)),(Uam,Uth)),Tor,Ame);
+((((Mur,Hma),Uma),((Uam,Uar),Uth)),Tor,Ame);
+(((Uth,((Uma,Uar),Uam)),(Hma,Mur)),Tor,Ame);
+((((Uma,Uar),(Uth,Uam)),(Hma,Mur)),Tor,Ame);
+(((Uar,Uam),(Uma,(Uth,(Hma,Mur)))),Tor,Ame);
+((((Uam,Uth),(Uar,Uma)),(Hma,Mur)),Tor,Ame);
+(((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Tor,Ame);
+((((Uth,Mur),Hma),((Uar,Uma),Uam)),Tor,Ame);
+((((Uth,Mur),Hma),((Uar,Uma),Uam)),Tor,Ame);
+(((Uth,((Uar,Uma),Uam)),(Mur,Hma)),Tor,Ame);
+((((Uar,Uma),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((Hma,Mur),((Uma,(Uam,Uar)),Uth)),Tor,Ame);
diff --git a/inst/extdata/trees/RAxML_bootstrap.Wang.out b/inst/extdata/trees/RAxML_bootstrap.Wang.out
new file mode 100644
index 0000000..842232a
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bootstrap.Wang.out
@@ -0,0 +1,1000 @@
+(t1,((((((t14,t15),(t13,t12)),((t11,(((t6,t7),t8),(t9,t10))),(t24,t25))),t16),(((t17,t18),((t22,t21),(t20,t19))),t23)),((t2,t3),((t4,t5),(t27,t26)))),t0);
+(t1,((t2,t3),((t4,t5),((((((t14,t15),(t13,t12)),(t11,(((t6,t7),t8),(t9,t10)))),t16),((t24,t25),(((t17,t18),((t22,t21),(t20,t19))),t23))),(t27,t26)))),t0);
+(t1,((((((t11,(((t6,t7),t8),(t9,t10))),(t16,(t14,t15))),(t13,t12)),((t24,t25),(((t17,t18),((t22,t21),(t20,t19))),t23))),(t27,t26)),((t2,t3),(t4,t5))),t0);
+(t1,(((((t16,(t14,t15)),((t13,t12),(t11,(((t6,t7),t8),(t9,t10))))),((t24,t25),((((t17,t18),(t21,(t20,t19))),t22),t23))),(t27,t26)),((t2,t3),(t4,t5))),t0);
+(t1,(((t27,t26),(t2,t3)),((t4,t5),(t16,((t14,t15),(((t13,t12),(t11,(((t6,t7),t8),(t9,t10)))),((t24,t25),(((t17,t18),((t20,t19),(t21,t22))),t23))))))),t0);
+(t1,(((t2,t3),(t4,t5)),((((t24,t25),(((t17,t18),((t20,t19),(t21,t22))),t23)),((t16,(t14,t15)),((t13,t12),(t11,(((t6,t7),t8),(t9,t10)))))),(t27,t26))),t0);
+(t1,((t2,t3),((((((t17,t18),((t20,t19),(t21,t22))),t23),((t13,t12),(((t24,t25),(t11,(((t6,t7),t8),(t9,t10)))),(t14,t15)))),t16),((t27,t26),(t4,t5)))),t0);
+(t1,(((t2,t3),(t4,t5)),(((((t17,t18),((t20,t19),(t21,t22))),t23),((((t13,t12),(t24,t25)),(t11,(((t6,t7),t8),(t9,t10)))),((t14,t15),t16))),(t27,t26))),t0);
+(t1,(((t2,t3),(t4,t5)),((((((t24,t25),((t17,t18),((t20,t19),(t21,t22)))),t23),((t13,t12),((t11,(((t6,t7),t8),(t9,t10))),(t14,t15)))),t16),(t27,t26))),t0);
+(t1,((t2,t3),((t4,t5),(((((t17,t18),((t20,t19),(t21,t22))),t23),((t14,t15),(t16,(((t24,t25),(t13,t12)),(t11,(((t6,t7),t8),(t9,t10))))))),(t27,t26)))),t0);
+(((t2,t3),((t5,t4),((t26,t27),(((t16,(t15,t14)),(((t12,t13),(t24,t25)),(t11,((t9,t10),(t8,(t7,t6)))))),(((t18,t17),((t19,t20),(t22,t21))),t23))))),t1,t0);
+(((t2,t3),((t5,t4),((t26,t27),((((((t12,t13),(t24,t25)),(t11,((t9,t10),(t8,(t7,t6))))),(t15,t14)),(((t18,t17),((t19,t20),(t22,t21))),t23)),t16)))),t1,t0);
+(((t5,t4),(((t26,t27),(((t11,((t9,t10),(t8,(t7,t6)))),(((t12,t13),t16),(t15,t14))),((t24,t25),(((t18,t17),((t19,t20),(t22,t21))),t23)))),(t2,t3))),t1,t0);
+(((((((t15,t14),(t11,((t9,t10),(t8,(t7,t6))))),t16),(t12,t13)),((t24,t25),(((t22,(t18,t17)),((t19,t20),t21)),t23))),(((t2,t3),(t5,t4)),(t26,t27))),t1,t0);
+((((t26,t27),(t5,t4)),(((((t15,t14),((t24,t25),(t11,((t9,t10),(t8,(t7,t6)))))),(t16,(t12,t13))),(((t18,t17),((t19,t20),(t21,t22))),t23)),(t2,t3))),t1,t0);
+((((((t15,t14),((t24,t25),(t11,((t9,t10),(t8,(t7,t6)))))),(t16,(t12,t13))),(((t18,t17),((t19,t20),(t21,t22))),t23)),((t2,t3),(t27,((t5,t4),t26)))),t1,t0);
+(((t2,t3),((t5,t4),(((((t15,t14),((t24,t25),(t11,((t9,t10),(t8,(t7,t6)))))),((t12,t13),t16)),(((t18,t17),((t19,t20),(t21,t22))),t23)),(t26,t27)))),t1,t0);
+(((t2,t3),((t5,t4),(((((t15,t14),((t24,t25),(t11,((t9,t10),(t8,(t7,t6)))))),((t12,t13),t16)),(((t18,t17),((t19,t20),(t21,t22))),t23)),(t26,t27)))),t1,t0);
+((((t26,t27),(t2,t3)),((t5,t4),(((t16,(t15,t14)),((t11,((t9,t10),(t8,(t7,t6)))),(t12,t13))),((t24,t25),(((t18,t17),((t19,t20),(t21,t22))),t23))))),t1,t0);
+((((t5,t4),(((((t18,t17),((t19,t20),(t21,t22))),t23),(((t11,((t9,t10),(t8,(t7,t6)))),((t12,t13),(t15,t14))),(t16,(t24,t25)))),(t26,t27))),(t2,t3)),t1,t0);
+(((t2,t3),(((t26,t27),((((((t9,t10),((t6,t7),t8)),t11),((t12,t13),(t25,t24))),((t15,t14),t16)),(((t18,t17),((t22,t21),(t20,t19))),t23))),(t4,t5))),t1,t0);
+(((t4,t5),((((t2,t3),((((((t9,t10),((t6,t7),t8)),t11),((t12,t13),(t25,t24))),((t15,t14),t16)),(((t20,t19),((t18,t17),(t22,t21))),t23))),t27),t26)),t1,t0);
+((((t27,t26),((((((t22,t21),(t20,t19)),(t18,t17)),((t25,t24),t23)),(((((t9,t10),((t6,t7),t8)),t11),((t12,t13),(t15,t14))),t16)),(t4,t5))),(t2,t3)),t1,t0);
+(((t4,t5),(((t27,t26),(((((t22,t21),(t20,t19)),(t18,t17)),((t25,t24),t23)),(((t12,t13),(((t9,t10),((t6,t7),t8)),t11)),(t16,(t15,t14))))),(t2,t3))),t1,t0);
+(((t4,t5),((t16,((t15,t14),(((t25,t24),(t23,(((t22,t21),(t20,t19)),(t18,t17)))),((t12,t13),(((t9,t10),((t6,t7),t8)),t11))))),((t27,t26),(t2,t3)))),t1,t0);
+((((t4,t5),(((t23,(((t22,t21),(t20,t19)),(t18,t17))),(((t16,(t15,t14)),(((t9,t10),((t6,t7),t8)),t11)),((t25,t24),(t12,t13)))),(t27,t26))),(t2,t3)),t1,t0);
+(((t4,t5),(((t23,(((t22,t21),(t20,t19)),(t18,t17))),(((t16,(t15,t14)),(((t9,t10),((t6,t7),t8)),t11)),((t25,t24),(t12,t13)))),((t2,t3),(t27,t26)))),t1,t0);
+(((t2,t3),((((((t25,t24),t23),(((t22,t21),(t20,t19)),(t18,t17))),((t16,(t15,t14)),((((t9,t10),((t6,t7),t8)),t11),(t12,t13)))),(t27,t26)),(t4,t5))),t1,t0);
+(((t2,t3),((((t23,(((t22,t21),(t20,t19)),(t18,t17))),(((t12,t13),t16),(((((t9,t10),((t6,t7),t8)),t11),(t25,t24)),(t15,t14)))),(t27,t26)),(t4,t5))),t1,t0);
+(((t2,t3),(((t23,(((t22,t21),(t20,t19)),(t18,t17))),((((((t9,t10),((t6,t7),t8)),t11),(t25,t24)),((t15,t14),(t12,t13))),t16)),((t27,t26),(t4,t5)))),t1,t0);
+(t1,((t3,t2),(((t5,t4),(t27,t26)),((((t25,t24),(t23,((t17,t18),((t22,t21),(t19,t20))))),((t12,t13),((t15,t14),(((t10,t9),(t8,(t6,t7))),t11)))),t16))),t0);
+(t1,(((t27,t26),(t3,t2)),((t5,t4),(((t25,t24),(t23,((t17,t18),((t22,t21),(t19,t20))))),((t16,(t15,t14)),((((t10,t9),(t8,(t6,t7))),t11),(t12,t13)))))),t0);
+(t1,((t5,t4),((((t23,((t17,t18),((t22,t21),(t19,t20)))),((t16,(t15,t14)),((((t10,t9),(t8,(t6,t7))),t11),((t25,t24),(t12,t13))))),(t27,t26)),(t3,t2))),t0);
+(t1,((((t25,t24),(t23,((t17,t18),((t22,t21),(t19,t20))))),((t16,(t15,t14)),((((t10,t9),(t8,(t6,t7))),t11),(t12,t13)))),(((t5,t4),(t27,t26)),(t3,t2))),t0);
+(t1,((t3,t2),((t5,t4),(((t23,((t17,t18),((t22,t21),(t19,t20)))),((t16,(((t25,t24),(((t10,t9),(t8,(t6,t7))),t11)),(t15,t14))),(t12,t13))),(t27,t26)))),t0);
+(t1,((t3,t2),((t5,t4),((((t25,t24),(t23,((t17,t18),((t22,t21),(t19,t20))))),(((((t10,t9),(t8,(t6,t7))),t11),(t15,t14)),(t16,(t12,t13)))),(t27,t26)))),t0);
+(t1,((t3,t2),((((t25,t24),(t23,((t17,t18),((t22,t21),(t19,t20))))),((t15,t14),(t16,((t12,t13),(((t10,t9),(t8,(t6,t7))),t11))))),((t27,t26),(t5,t4)))),t0);
+(t1,((t3,t2),((((t23,((t17,t18),((t22,t21),(t19,t20)))),(((t12,t13),(((((t10,t9),(t8,(t6,t7))),t11),(t15,t14)),t16)),(t25,t24))),(t27,t26)),(t5,t4))),t0);
+(t1,((t5,t4),((t3,t2),((((t16,(t15,t14)),((((t10,t9),(t8,(t6,t7))),t11),(t12,t13))),((t25,t24),(t23,((t17,t18),((t22,t21),(t19,t20)))))),(t27,t26)))),t0);
+(t1,((t3,t2),((((t16,(t15,t14)),((((t10,t9),(t8,(t6,t7))),t11),(t12,t13))),((t25,t24),(t23,((t17,t18),((t22,t21),(t19,t20)))))),((t27,t26),(t5,t4)))),t0);
+(t1,(((t4,t5),(t27,t26)),((t3,t2),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((t16,(t15,t14)),((t12,t13),((t25,t24),(t11,((t10,t9),(t8,(t7,t6)))))))))),t0);
+(t1,((t3,t2),(((((((t22,t21),(t19,t20)),(t18,t17)),t23),(t16,((t15,t14),((t11,((t10,t9),(t8,(t7,t6)))),((t12,t13),(t25,t24)))))),(t27,t26)),(t4,t5))),t0);
+(t1,((t3,t2),((t16,((t15,t14),(((t11,((t10,t9),(t8,(t7,t6)))),(t12,t13)),((t25,t24),((((t22,t21),(t19,t20)),(t18,t17)),t23))))),(((t4,t5),t26),t27))),t0);
+(t1,((t3,t2),(((((((t22,t21),(t19,t20)),(t18,t17)),t23),(t16,((t15,t14),(((t25,t24),(t12,t13)),(t11,((t10,t9),(t8,(t7,t6)))))))),(t26,t27)),(t4,t5))),t0);
+(t1,((t3,t2),(((((t25,t24),((((t21,(t19,t20)),(t18,t17)),t22),t23)),(((t12,t13),(t11,((t10,t9),(t8,(t7,t6))))),(t16,(t15,t14)))),(t26,t27)),(t4,t5))),t0);
+(t1,((t3,t2),((t4,t5),(((((t18,t17),((t21,t22),(t19,t20))),t23),(t16,((t15,t14),(((t25,t24),(t12,t13)),(t11,((t10,t9),(t8,(t7,t6)))))))),(t26,t27)))),t0);
+(t1,((t4,t5),(((((t21,(t19,t20)),((t18,t17),t22)),t23),(t16,(((t15,t14),((t11,((t10,t9),(t8,(t7,t6)))),(t25,t24))),(t12,t13)))),((t3,t2),(t26,t27)))),t0);
+(t1,((t3,t2),(((t26,t27),(((t25,t24),((((t22,t21),(t19,t20)),(t18,t17)),t23)),(((t11,((t10,t9),(t8,(t7,t6)))),(t12,t13)),((t15,t14),t16)))),(t4,t5))),t0);
+(t1,((t3,t2),(((t26,t27),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((((t15,t14),((t25,t24),(t11,((t10,t9),(t8,(t7,t6)))))),(t12,t13)),t16))),(t4,t5))),t0);
+(t1,((t3,t2),(((t26,t27),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((((t12,t13),(t25,t24)),(t11,((t10,t9),(t8,(t7,t6))))),(t16,(t15,t14))))),(t4,t5))),t0);
+(((((t23,((t21,(t18,t17)),(t22,(t20,t19)))),(t16,((t15,t14),(((t25,t24),(t12,t13)),(t11,((t8,(t6,t7)),(t10,t9))))))),(t26,t27)),((t4,t5),(t3,t2))),t1,t0);
+(((t3,t2),((t16,(((t15,t14),((t12,t13),(t11,((t8,(t6,t7)),(t10,t9))))),(t23,((t25,t24),((t18,t17),((t21,t22),(t20,t19))))))),((t26,t27),(t4,t5)))),t1,t0);
+((((t26,t27),(t4,t5)),((t3,t2),(((t25,t24),(((t18,t17),((t21,t22),(t20,t19))),t23)),((t16,(t15,t14)),((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))))))),t1,t0);
+(((t3,t2),((((t25,t24),(((t18,t17),((t21,t22),(t20,t19))),t23)),((t16,(t15,t14)),((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))))),((t26,t27),(t4,t5)))),t1,t0);
+((((t26,t27),(((t15,t14),(((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))),((t25,t24),(((t18,t17),((t21,t22),(t20,t19))),t23)))),t16)),((t3,t2),(t4,t5))),t1,t0);
+(((t4,t5),(((t26,t27),((((t18,t17),((t21,t22),(t20,t19))),(t23,(t25,t24))),((t16,(t15,t14)),((t12,t13),(t11,((t8,(t6,t7)),(t10,t9))))))),(t3,t2))),t1,t0);
+(((t3,t2),(((t4,t5),(t26,t27)),(((t23,((t25,t24),((t18,t17),((t21,t22),(t20,t19))))),((t15,t14),((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))))),t16))),t1,t0);
+((((t3,t2),(t26,t27)),(((((t18,t17),((t21,t22),(t20,t19))),t23),((t15,t14),((((t25,t24),(t12,t13)),(t11,((t8,(t6,t7)),(t10,t9)))),t16))),(t4,t5))),t1,t0);
+(((t4,t5),(((t3,t2),(t26,t27)),(((t25,t24),(((t18,t17),((t21,t22),(t20,t19))),t23)),(((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))),(t16,(t15,t14)))))),t1,t0);
+(((t3,t2),(((t26,t27),((((t18,t17),((t21,t22),(t20,t19))),t23),((t16,((t15,t14),((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))))),(t25,t24)))),(t4,t5))),t1,t0);
+(t1,((t5,t4),((t3,t2),(t27,(t26,((t23,((t18,t17),((t19,t20),(t22,t21)))),(t16,(((t15,t14),((t25,t24),(t11,((t9,t10),(t8,(t6,t7)))))),(t13,t12)))))))),t0);
+(t1,((t3,t2),((t5,t4),((t27,t26),((t23,((t25,t24),((t18,t17),((t19,t20),(t22,t21))))),(((t11,((t9,t10),(t8,(t6,t7)))),(t15,t14)),((t13,t12),t16)))))),t0);
+(t1,((t5,t4),(((t3,t2),(t27,t26)),((((t18,t17),((t19,t20),(t22,t21))),t23),(((t13,t12),(t15,t14)),(((t25,t24),(t11,((t9,t10),(t8,(t6,t7))))),t16))))),t0);
+(t1,((t3,t2),((t5,t4),((t27,t26),((((t25,t24),((t18,t17),((t19,t20),(t22,t21)))),t23),(t16,(((t15,t14),(t13,t12)),(t11,((t9,t10),(t8,(t6,t7)))))))))),t0);
+(t1,(((t27,t26),((((t18,t17),((t19,t20),(t22,t21))),(t23,(t25,t24))),(((t13,t12),(t11,((t9,t10),(t8,(t6,t7))))),(t16,(t15,t14))))),((t3,t2),(t5,t4))),t0);
+(t1,(((t27,t26),((((t18,t17),((t19,t20),(t22,t21))),t23),(t16,((t15,t14),((t13,t12),((t25,t24),(t11,((t9,t10),(t8,(t6,t7)))))))))),((t3,t2),(t5,t4))),t0);
+(t1,((t5,t4),(((t27,t26),((((t18,t17),((t19,t20),(t22,t21))),t23),((((t13,t12),(t25,t24)),(t11,((t9,t10),(t8,(t6,t7))))),((t15,t14),t16)))),(t3,t2))),t0);
+(t1,(((t3,t2),(((t25,t24),(((t18,t17),((t19,t20),(t22,t21))),t23)),((t13,t12),((t11,((t9,t10),(t8,(t6,t7)))),((t15,t14),t16))))),((t27,t26),(t5,t4))),t0);
+(t1,((t3,t2),((t5,t4),((((t25,t24),(((t18,t17),((t19,t20),(t22,t21))),t23)),(((t13,t12),((t11,((t9,t10),(t8,(t6,t7)))),(t15,t14))),t16)),(t27,t26)))),t0);
+(t1,((t5,t4),((((((t18,t17),((t19,t20),(t22,t21))),t23),(((t11,((t9,t10),(t8,(t6,t7)))),(t25,t24)),((t16,(t15,t14)),(t13,t12)))),(t27,t26)),(t3,t2))),t0);
+(((t2,t3),((t4,t5),(((t16,(((t14,t15),(t11,(((t7,t6),t8),(t9,t10)))),((t13,t12),(t25,t24)))),(t23,((t18,t17),((t22,t21),(t19,t20))))),(t26,t27)))),t1,t0);
+((((((t11,(((t7,t6),t8),(t9,t10))),((t13,t12),(t25,t24))),(t16,(t14,t15))),(t23,((t18,t17),((t22,t21),(t19,t20))))),((t26,t27),((t2,t3),(t4,t5)))),t1,t0);
+(((t4,t5),(((((t13,t12),((t25,t24),(t11,(((t7,t6),t8),(t9,t10))))),(t16,(t14,t15))),(t23,((t18,t17),((t22,t21),(t19,t20))))),((t2,t3),(t26,t27)))),t1,t0);
+((((t16,((t14,t15),(((t25,t24),(t23,((t18,t17),((t22,t21),(t19,t20))))),((t11,(((t7,t6),t8),(t9,t10))),(t13,t12))))),(t2,t3)),((t4,t5),(t26,t27))),t1,t0);
+((((t4,t5),((t26,t27),((t23,((t18,t17),((t22,t21),(t19,t20)))),(t16,((t14,t15),(((t25,t24),(t11,(((t7,t6),t8),(t9,t10)))),(t13,t12))))))),(t2,t3)),t1,t0);
+(((((t25,t24),(t23,((t18,t17),((t22,t21),(t19,t20))))),((t16,(t14,t15)),((t11,(((t7,t6),t8),(t9,t10))),(t13,t12)))),((t4,t5),((t2,t3),(t26,t27)))),t1,t0);
+(((t2,t3),((t4,t5),((t26,t27),(((t25,t24),(t23,((t18,t17),((t22,t21),(t19,t20))))),((t16,(t14,t15)),((t11,(((t7,t6),t8),(t9,t10))),(t13,t12))))))),t1,t0);
+((((t26,t27),(((t25,t24),(t23,((t18,t17),((t22,t21),(t19,t20))))),((t16,(t14,t15)),((t11,(((t7,t6),t8),(t9,t10))),(t13,t12))))),((t2,t3),(t4,t5))),t1,t0);
+(((t4,t5),(((t26,t27),(t2,t3)),((t23,(((t18,t17),((t22,t21),(t19,t20))),(t25,t24))),((t16,(t14,t15)),((t11,(((t7,t6),t8),(t9,t10))),(t13,t12)))))),t1,t0);
+((((t2,t3),(t4,t5)),((t26,t27),(((t23,(((t18,t17),((t22,t21),(t19,t20))),(t25,t24))),((t13,t12),((t14,t15),(t11,(((t7,t6),t8),(t9,t10)))))),t16))),t1,t0);
+((((t4,t5),(t27,t26)),((t3,t2),((t23,((t18,t17),((t22,t21),(t20,t19)))),((((t12,t13),(t24,t25)),(t11,((t8,(t6,t7)),(t9,t10)))),(t16,(t14,t15)))))),t1,t0);
+((((t3,t2),(t4,t5)),((t27,t26),(t16,((t23,((t18,t17),((t22,t21),(t20,t19)))),(((t24,t25),(t12,t13)),((t14,t15),(t11,((t8,(t6,t7)),(t9,t10))))))))),t1,t0);
+(((t4,t5),(((t27,t26),((t23,((t18,t17),((t22,t21),(t20,t19)))),((((t12,t13),t16),(t14,t15)),((t11,((t8,(t6,t7)),(t9,t10))),(t24,t25))))),(t3,t2))),t1,t0);
+(((((t3,t2),(t27,t26)),((t23,((t18,t17),((t22,t21),(t20,t19)))),((((t12,t13),t16),((t14,t15),(t11,((t8,(t6,t7)),(t9,t10))))),(t24,t25)))),(t4,t5)),t1,t0);
+(((((t3,t2),(t27,t26)),((t23,((t18,t17),((t22,t21),(t20,t19)))),(((t14,t15),(((t12,t13),(t24,t25)),(t11,((t8,(t6,t7)),(t9,t10))))),t16))),(t4,t5)),t1,t0);
+(((((t3,t2),(t27,t26)),((t16,(t14,t15)),(((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19))))),((t11,((t8,(t6,t7)),(t9,t10))),(t12,t13))))),(t4,t5)),t1,t0);
+(((t3,t2),(((t27,t26),(t4,t5)),((t23,((t18,t17),((t22,t21),(t20,t19)))),((t16,((t14,t15),(t11,((t8,(t6,t7)),(t9,t10))))),((t24,t25),(t12,t13)))))),t1,t0);
+(((t3,t2),((t4,t5),((((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19))))),((t16,((t14,t15),(t11,((t8,(t6,t7)),(t9,t10))))),(t12,t13))),(t27,t26)))),t1,t0);
+((((((t16,(t14,t15)),((t24,t25),((t12,t13),(t11,((t8,(t6,t7)),(t9,t10)))))),(t23,((t18,t17),((t22,t21),(t20,t19))))),(t27,t26)),((t3,t2),(t4,t5))),t1,t0);
+(((t3,t2),((t4,t5),((((t16,(t14,t15)),((t11,((t8,(t6,t7)),(t9,t10))),((t24,t25),(t12,t13)))),(t23,((t18,t17),((t22,t21),(t20,t19))))),(t27,t26)))),t1,t0);
+((((t27,t26),((t16,(t15,t14)),(((t24,t25),(t23,((t17,t18),((t19,t20),(t21,t22))))),((t13,t12),(t11,((t8,(t6,t7)),(t9,t10))))))),((t5,t4),(t2,t3))),t1,t0);
+((((t27,t26),(t5,t4)),((t2,t3),((t23,((t17,t18),((t19,t20),(t21,t22)))),((t16,(t15,t14)),(((t11,((t8,(t6,t7)),(t9,t10))),(t24,t25)),(t13,t12)))))),t1,t0);
+((((t5,t4),((t27,t26),((t23,((t17,t18),((t19,t20),(t21,t22)))),((t15,t14),(((t13,t12),(t11,((t8,(t6,t7)),(t9,t10)))),((t24,t25),t16)))))),(t2,t3)),t1,t0);
+(((t5,t4),(((t2,t3),(t27,t26)),((t23,((t17,t18),((t19,t20),(t21,t22)))),((t24,t25),((t16,(t15,t14)),((t13,t12),(t11,((t8,(t6,t7)),(t9,t10))))))))),t1,t0);
+((((t27,t26),((t23,((t17,t18),((t19,t20),(t21,t22)))),((t16,(t15,t14)),((t13,t12),((t24,t25),(t11,((t8,(t6,t7)),(t9,t10)))))))),((t5,t4),(t2,t3))),t1,t0);
+(((t5,t4),(((t2,t3),(t27,t26)),((t23,((t17,t18),((t19,t20),(t21,t22)))),((t16,(t15,t14)),((t13,t12),((t24,t25),(t11,((t8,(t6,t7)),(t9,t10))))))))),t1,t0);
+(((t2,t3),(((t27,t26),((t23,((t17,t18),((t19,t20),(t21,t22)))),(t16,(((t24,t25),(t13,t12)),((t15,t14),(t11,((t8,(t6,t7)),(t9,t10)))))))),(t5,t4))),t1,t0);
+(((t2,t3),(((t27,t26),((t23,((t17,t18),((t19,t20),(t21,t22)))),((((t24,t25),(t11,((t8,(t6,t7)),(t9,t10)))),(t15,t14)),((t13,t12),t16)))),(t5,t4))),t1,t0);
+(((t5,t4),((t2,t3),((t27,t26),((t23,((t17,t18),((t19,t20),(t21,t22)))),((t16,(t15,t14)),((t13,t12),((t24,t25),(t11,((t8,(t6,t7)),(t9,t10)))))))))),t1,t0);
+(((t2,t3),(((t26,((t23,((t22,(t17,t18)),((t19,t20),t21))),(((t11,((t8,(t6,t7)),(t9,t10))),(t16,(t15,t14))),((t13,t12),(t24,t25))))),(t5,t4)),t27)),t1,t0);
+(((((t5,t4),(t27,t26)),(((t16,(t14,t15)),((t12,t13),((t24,t25),(t11,((t8,(t6,t7)),(t10,t9)))))),(t23,((t17,t18),((t19,t20),(t22,t21)))))),(t3,t2)),t1,t0);
+(((t5,t4),((t27,t26),(((t16,(((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))),(t14,t15))),((t24,t25),(t23,((t17,t18),(t22,(t21,(t19,t20))))))),(t3,t2)))),t1,t0);
+((((((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))),((t14,t15),t16)),((t24,t25),(t23,((t17,t18),((t19,t20),(t22,t21)))))),((t3,t2),((t5,t4),(t26,t27)))),t1,t0);
+(((t3,t2),((t5,t4),((t26,t27),((t16,((((t24,t25),(t12,t13)),(t11,((t8,(t6,t7)),(t10,t9)))),(t14,t15))),(t23,((t17,t18),((t19,t20),(t22,t21)))))))),t1,t0);
+((((t16,((((t23,((t17,t18),((t19,t20),(t22,t21)))),(t24,t25)),((t14,t15),(t12,t13))),(t11,((t8,(t6,t7)),(t10,t9))))),((t3,t2),(t26,t27))),(t5,t4)),t1,t0);
+(((t3,t2),(((t26,t27),(((t16,(t14,t15)),(((t24,t25),(t11,((t8,(t6,t7)),(t10,t9)))),(t12,t13))),(t23,((t17,t18),((t19,t20),(t22,t21)))))),(t5,t4))),t1,t0);
+(((t3,t2),(((t26,t27),((((t11,((t8,(t6,t7)),(t10,t9))),((t14,t15),t16)),((t12,t13),(t24,t25))),(t23,((t17,t18),((t19,t20),(t22,t21)))))),(t5,t4))),t1,t0);
+(((t3,t2),(((t26,t27),((((t14,t15),t16),((t12,t13),(t11,((t8,(t6,t7)),(t10,t9))))),(((t24,t25),t23),((t17,t18),((t19,t20),(t22,t21)))))),(t5,t4))),t1,t0);
+(((t3,t2),(((t26,t27),((t16,(((t11,((t8,(t6,t7)),(t10,t9))),((t24,t25),(t12,t13))),(t14,t15))),((t22,((t17,t18),(t21,(t19,t20)))),t23))),(t5,t4))),t1,t0);
+((((((t12,t13),((t11,((t8,(t6,t7)),(t10,t9))),(t24,t25))),((t14,t15),t16)),(((t17,t18),((t22,t21),(t19,t20))),t23)),(((t26,(t5,t4)),(t3,t2)),t27)),t1,t0);
+(((t2,t3),((((t23,((t24,t25),(((t21,t22),(t19,t20)),(t17,t18)))),((t12,t13),((t16,(t15,t14)),(t11,((t8,(t6,t7)),(t9,t10)))))),(t27,t26)),(t4,t5))),t1,t0);
+(((t2,t3),((((((t21,t22),(t19,t20)),(t17,t18)),t23),(((t15,t14),((t12,t13),((t11,((t8,(t6,t7)),(t9,t10))),(t24,t25)))),t16)),((t4,t5),(t26,t27)))),t1,t0);
+((((t4,t5),(t26,t27)),((t2,t3),(((((t21,t22),(t19,t20)),(t17,t18)),t23),(((t12,t13),((t11,((t8,(t6,t7)),(t9,t10))),(t24,t25))),(t16,(t15,t14)))))),t1,t0);
+(((t4,t5),((((t24,t25),((((t21,t22),(t19,t20)),(t17,t18)),t23)),(((t11,((t8,(t6,t7)),(t9,t10))),(t12,t13)),(t16,(t15,t14)))),((t26,t27),(t2,t3)))),t1,t0);
+(((t2,t3),(((((((t21,t22),(t19,t20)),(t17,t18)),t23),(t16,(((t15,t14),((t24,t25),(t11,((t8,(t6,t7)),(t9,t10))))),(t12,t13)))),(t26,t27)),(t4,t5))),t1,t0);
+(((t2,t3),(((((((t21,t22),(t19,t20)),(t17,t18)),t23),((t16,(t15,t14)),(((t24,t25),(t11,((t8,(t6,t7)),(t9,t10)))),(t12,t13)))),(t26,t27)),(t4,t5))),t1,t0);
+(((t2,t3),(((((((t21,t22),(t19,t20)),(t17,t18)),t23),(t16,((t15,t14),((t11,((t8,(t6,t7)),(t9,t10))),((t12,t13),(t24,t25)))))),(t26,t27)),(t4,t5))),t1,t0);
+(((t2,t3),(((((((t21,t22),(t19,t20)),(t17,t18)),t23),(((t12,t13),((t24,t25),(t11,((t8,(t6,t7)),(t9,t10))))),(t16,(t15,t14)))),(t26,t27)),(t4,t5))),t1,t0);
+(((((((t24,t25),(((t21,t22),(t19,t20)),(t17,t18))),t23),((t12,t13),(((t15,t14),(t11,((t8,(t6,t7)),(t9,t10)))),t16))),((t2,t3),(t26,t27))),(t4,t5)),t1,t0);
+((((t26,t27),((((t22,(t19,t20)),(t21,(t17,t18))),t23),((((t12,t13),(t11,((t8,(t6,t7)),(t9,t10)))),(t16,(t15,t14))),(t24,t25)))),((t4,t5),(t2,t3))),t1,t0);
+(((t4,t5),(((((t15,t14),((((t10,t9),((t6,t7),t8)),t11),((t24,t25),(t13,t12)))),((((t19,t20),(t21,t22)),(t17,t18)),t23)),t16),((t26,t27),(t3,t2)))),t1,t0);
+((((t26,t27),(t3,t2)),((t4,t5),(((t15,t14),(((((t10,t9),((t6,t7),t8)),t11),(t24,t25)),(t16,(t13,t12)))),((((t19,t20),(t21,t22)),(t17,t18)),t23)))),t1,t0);
+((((t26,t27),(t4,t5)),((((((t10,t9),((t6,t7),t8)),t11),(t16,((t13,t12),(t15,t14)))),(((((t19,t20),(t21,t22)),(t17,t18)),t23),(t24,t25))),(t3,t2))),t1,t0);
+(((t3,t2),(((t26,t27),(t4,t5)),(((((t19,t20),(t21,t22)),(t17,t18)),t23),(t16,((t15,t14),(((t24,t25),(((t10,t9),((t6,t7),t8)),t11)),(t13,t12))))))),t1,t0);
+(((t4,t5),((((((t19,t20),(t21,t22)),(t17,t18)),t23),((((t24,t25),(((t10,t9),((t6,t7),t8)),t11)),(t15,t14)),((t13,t12),t16))),((t3,t2),(t26,t27)))),t1,t0);
+(((t4,t5),((t26,t27),((((t24,t25),((((t19,t20),(t21,t22)),(t17,t18)),t23)),((t16,(t15,t14)),((t13,t12),(((t10,t9),((t6,t7),t8)),t11)))),(t3,t2)))),t1,t0);
+(((t4,t5),((t3,t2),((t26,t27),(((t24,t25),((((t19,t20),(t21,t22)),(t17,t18)),t23)),((((t10,t9),((t6,t7),t8)),t11),(t16,((t15,t14),(t13,t12)))))))),t1,t0);
+(((((t3,t2),(t26,t27)),(((((t19,t20),(t21,t22)),(t17,t18)),t23),((t16,(t15,t14)),(((((t10,t9),((t6,t7),t8)),t11),(t24,t25)),(t13,t12))))),(t4,t5)),t1,t0);
+(((((t3,t2),(t26,t27)),(((((t19,t20),(t21,t22)),(t17,t18)),t23),(t16,((t15,t14),((((t10,t9),((t6,t7),t8)),t11),((t24,t25),(t13,t12))))))),(t4,t5)),t1,t0);
+((((t3,t2),((t26,t27),(((((t19,t20),(t21,t22)),(t17,t18)),t23),(((t13,t12),((((t10,t9),((t6,t7),t8)),t11),(t24,t25))),(t16,(t15,t14)))))),(t4,t5)),t1,t0);
+(t1,((t5,t4),((((t24,t25),((((t22,t21),(t19,t20)),(t18,t17)),t23)),(((t12,t13),(t11,((t9,t10),((t7,t6),t8)))),((t15,t14),t16))),((t26,t27),(t3,t2)))),t0);
+(t1,((t5,t4),((t26,t27),((t3,t2),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((t11,((t9,t10),((t7,t6),t8))),((t15,t14),(((t24,t25),(t12,t13)),t16))))))),t0);
+(t1,(((t3,t2),(((t24,t25),((((t22,t21),(t19,t20)),(t18,t17)),t23)),(((t12,t13),(t11,((t9,t10),((t7,t6),t8)))),(t16,(t15,t14))))),((t5,t4),(t26,t27))),t0);
+(t1,((t3,t2),((t5,t4),((t26,t27),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((((t24,t25),(t12,t13)),(t11,((t9,t10),((t7,t6),t8)))),(t16,(t15,t14))))))),t0);
+(t1,((t5,t4),((t26,t27),((t3,t2),(((((t22,t21),(t19,t20)),(t18,t17)),t23),(((t24,t25),(t12,t13)),(t16,((t15,t14),(t11,((t9,t10),((t7,t6),t8)))))))))),t0);
+(t1,(((t3,t2),(t5,t4)),((((((t22,t21),(t19,t20)),(t18,t17)),t23),((((t24,t25),(t12,t13)),(t11,((t9,t10),((t7,t6),t8)))),(t16,(t15,t14)))),(t26,t27))),t0);
+(t1,(t27,(((t26,(t3,t2)),(t5,t4)),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((((t12,t13),(t11,((t9,t10),((t7,t6),t8)))),(t16,(t15,t14))),(t24,t25))))),t0);
+(t1,((t5,t4),((t27,t26),((t3,t2),(((t12,t13),(t16,((t15,t14),(t11,((t9,t10),((t7,t6),t8)))))),((t24,t25),((((t22,t21),(t19,t20)),(t18,t17)),t23)))))),t0);
+(t1,((t3,t2),(((((((t22,t21),(t19,t20)),(t18,t17)),t23),(((t12,t13),((t24,t25),(t11,((t9,t10),((t7,t6),t8))))),((t15,t14),t16))),(t27,t26)),(t5,t4))),t0);
+(t1,((t3,t2),((t27,t26),((t5,t4),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((t24,t25),(((t12,t13),(t11,((t9,t10),((t7,t6),t8)))),(t16,(t15,t14)))))))),t0);
+(t1,(((t5,t4),(t27,t26)),((t16,((t14,t15),(((t24,t25),(t23,((t21,(t18,t17)),(t22,(t19,t20))))),((t11,((t10,t9),(t8,(t7,t6)))),(t12,t13))))),(t2,t3))),t0);
+(t1,(((t2,t3),(t26,t27)),((t5,t4),(((t24,t25),(t23,((t18,t17),((t21,t22),(t19,t20))))),(((t11,((t10,t9),(t8,(t7,t6)))),(t14,t15)),((t12,t13),t16))))),t0);
+(t1,(((t2,t3),(t26,t27)),((t5,t4),((((t18,t17),((t21,t22),(t19,t20))),((t24,t25),t23)),((t16,(t14,t15)),((t12,t13),(t11,((t10,t9),(t8,(t7,t6))))))))),t0);
+(t1,((t2,t3),((((t24,t25),(t23,((t21,(t18,t17)),(t22,(t19,t20))))),(((t11,((t10,t9),(t8,(t7,t6)))),(t14,t15)),((t12,t13),t16))),((t5,t4),(t26,t27)))),t0);
+(t1,((t5,t4),(((t2,t3),(t26,t27)),(((t24,t25),(t23,((t18,t17),((t21,t22),(t19,t20))))),(((t11,((t10,t9),(t8,(t7,t6)))),(t14,t15)),((t12,t13),t16))))),t0);
+(t1,((((t23,(((t18,t17),((t21,t22),(t19,t20))),(t24,t25))),((t14,t15),(((t12,t13),t16),(t11,((t10,t9),(t8,(t7,t6))))))),(t2,t3)),((t5,t4),(t26,t27))),t0);
+(t1,((((t23,((t18,t17),((t21,t22),(t19,t20)))),((t16,(t14,t15)),(((t24,t25),(t12,t13)),(t11,((t10,t9),(t8,(t7,t6))))))),(t5,t4)),((t26,t27),(t2,t3))),t0);
+(t1,((((t23,((t18,t17),((t21,t22),(t19,t20)))),((t11,((t10,t9),(t8,(t7,t6)))),((t16,(t14,t15)),((t24,t25),(t12,t13))))),(t5,t4)),((t26,t27),(t2,t3))),t0);
+(t1,((t5,t4),(((t26,t27),(t2,t3)),(t16,(((t14,t15),((t12,t13),(t11,((t10,t9),(t8,(t7,t6)))))),((t24,t25),(t23,((t18,t17),((t21,t22),(t19,t20))))))))),t0);
+(t1,((t5,t4),(((t26,t27),(t2,t3)),((t23,((t18,t17),((t21,t22),(t19,t20)))),((t16,((t12,t13),((t11,((t10,t9),(t8,(t7,t6)))),(t24,t25)))),(t14,t15))))),t0);
+(t1,(((t2,t3),((t26,t27),((t23,((t17,t18),((t19,t20),(t22,t21)))),(((t14,t15),t16),((t11,((t9,t10),(t8,(t7,t6)))),((t12,t13),(t25,t24))))))),(t5,t4)),t0);
+(t1,((t2,t3),(((t26,t27),((((t25,t24),(t23,((t17,t18),(((t19,t20),t21),t22)))),((t11,((t9,t10),(t8,(t7,t6)))),((t14,t15),(t12,t13)))),t16)),(t5,t4))),t0);
+(t1,(((t26,t27),((t23,(((t17,t18),((t19,t20),(t21,t22))),(t25,t24))),(((t14,t15),(t11,((t9,t10),(t8,(t7,t6))))),(t16,(t12,t13))))),((t5,t4),(t2,t3))),t0);
+(t1,((t27,((((t25,t24),(t23,((t17,t18),((t19,t20),(t21,t22))))),((t16,(t14,t15)),((t11,((t9,t10),(t8,(t7,t6)))),(t12,t13)))),t26)),((t5,t4),(t2,t3))),t0);
+(t1,((t2,t3),((((t23,((t17,t18),((t19,t20),(t21,t22)))),(((t16,(t14,t15)),((t11,((t9,t10),(t8,(t7,t6)))),(t12,t13))),(t25,t24))),(t26,t27)),(t5,t4))),t0);
+(t1,((t2,t3),((((t23,((t17,t18),(t21,(t22,(t19,t20))))),((t16,(t14,t15)),((t11,((t9,t10),(t8,(t7,t6)))),((t25,t24),(t12,t13))))),(t26,t27)),(t5,t4))),t0);
+(t1,(((t2,t3),(t26,t27)),((t5,t4),((t23,((t17,t18),((t19,t20),(t21,t22)))),(t16,((t14,t15),((t11,((t9,t10),(t8,(t7,t6)))),((t25,t24),(t12,t13)))))))),t0);
+(t1,((t27,((t2,t3),t26)),((t5,t4),((((t23,(((t19,t20),t21),(t22,(t17,t18)))),(t25,t24)),((t12,t13),(t11,((t9,t10),(t8,(t7,t6)))))),(t16,(t14,t15))))),t0);
+(t1,(((((t23,(((t19,t20),(t22,t21)),(t17,t18))),(t25,t24)),((t12,t13),((t11,((t9,t10),(t8,(t7,t6)))),(t14,t15)))),t16),(((t2,t3),(t26,t27)),(t5,t4))),t0);
+(t1,((t2,t3),((((((t19,t20),(t22,t21)),(t17,t18)),((t25,t24),t23)),((t16,(t14,t15)),((t12,t13),(t11,((t9,t10),(t8,(t7,t6))))))),((t5,t4),(t26,t27)))),t0);
+((((((t24,t25),(t11,((t9,t10),(t8,(t6,t7))))),((t15,t14),(t16,(t12,t13)))),(t23,(((t22,t21),(t19,t20)),(t18,t17)))),((t5,t4),((t26,t27),(t2,t3)))),t1,t0);
+((((t26,t27),(((t16,(t12,t13)),((t11,((t9,t10),(t8,(t6,t7)))),(t15,t14))),((t24,t25),(t23,(((t22,t21),(t19,t20)),(t18,t17)))))),((t2,t3),(t5,t4))),t1,t0);
+(((t2,t3),((t5,t4),((t26,t27),((t23,((t21,(t19,t20)),(t22,(t18,t17)))),(((t16,(t15,t14)),((t12,t13),(t11,((t9,t10),(t8,(t6,t7)))))),(t24,t25)))))),t1,t0);
+(((t5,t4),(((t2,t3),(t26,t27)),((t23,((t18,t17),((t19,t20),(t21,t22)))),((t15,t14),(t16,(((t11,((t9,t10),(t8,(t6,t7)))),(t24,t25)),(t12,t13))))))),t1,t0);
+(((t5,t4),(((t2,t3),(t26,t27)),((t23,((t18,t17),((t19,t20),(t21,t22)))),((((t11,((t9,t10),(t8,(t6,t7)))),(t24,t25)),(t15,t14)),(t16,(t12,t13)))))),t1,t0);
+((((t26,t27),(((t24,t25),(((t18,t17),((t19,t20),(t21,t22))),t23)),(((t15,t14),t16),((t12,t13),(t11,((t9,t10),(t8,(t6,t7)))))))),((t5,t4),(t2,t3))),t1,t0);
+(((t2,t3),((((t24,t25),(((t18,t17),((t19,t20),(t21,t22))),t23)),((t12,t13),((t11,((t9,t10),(t8,(t6,t7)))),((t15,t14),t16)))),((t26,t27),(t5,t4)))),t1,t0);
+((((t26,t27),((((t24,t25),(((t18,t17),((t19,t20),(t21,t22))),t23)),((t15,t14),((t12,t13),(t11,((t9,t10),(t8,(t6,t7))))))),t16)),((t5,t4),(t2,t3))),t1,t0);
+(((t2,t3),(((t26,t27),((((t18,t17),((t19,t20),(t21,t22))),t23),((t16,(t12,t13)),((t15,t14),((t24,t25),(t11,((t9,t10),(t8,(t6,t7))))))))),(t5,t4))),t1,t0);
+(((t2,t3),(((t26,t27),((((t18,t17),((t19,t20),(t21,t22))),t23),(((t24,t25),(t11,((t9,t10),(t8,(t6,t7))))),((t16,(t12,t13)),(t15,t14))))),(t5,t4))),t1,t0);
+(((t2,t3),(t27,((t5,t4),(t26,((t16,((t14,t15),((t24,t25),((t12,t13),(t11,((t9,t10),(t8,(t7,t6)))))))),(t23,((t18,t17),((t22,t21),(t19,t20))))))))),t1,t0);
+((((((t12,t13),t16),((t11,((t9,t10),(t8,(t7,t6)))),(t14,t15))),((t24,t25),(t23,((t18,t17),(t22,(t21,(t19,t20))))))),(((t2,t3),(t26,t27)),(t5,t4))),t1,t0);
+(((t2,t3),(((t26,t27),(((((t12,t13),t16),((t11,((t9,t10),(t8,(t7,t6)))),(t14,t15))),(t24,t25)),(t23,((t18,t17),((t19,t20),(t22,t21)))))),(t5,t4))),t1,t0);
+(((t2,t3),(((t26,t27),(((t16,(t14,t15)),((t11,((t9,t10),(t8,(t7,t6)))),((t24,t25),(t12,t13)))),(t23,((t18,t17),((t19,t20),(t22,t21)))))),(t5,t4))),t1,t0);
+(((t2,t3),(((t26,t27),((((t12,t13),(t11,((t9,t10),(t8,(t7,t6))))),((t14,t15),t16)),((t24,t25),(t23,((t18,t17),((t19,t20),(t22,t21))))))),(t5,t4))),t1,t0);
+(((t2,t3),(((t26,t27),((t23,((t18,t17),((t19,t20),(t22,t21)))),((((t11,((t9,t10),(t8,(t7,t6)))),((t12,t13),(t24,t25))),(t14,t15)),t16))),(t5,t4))),t1,t0);
+(((t2,t3),(((t26,t27),((t23,((t18,t17),((t19,t20),(t22,t21)))),(((t14,t15),((t11,((t9,t10),(t8,(t7,t6)))),(t24,t25))),((t12,t13),t16)))),(t5,t4))),t1,t0);
+((((t26,t27),((t23,((t24,t25),((t18,t17),((t19,t20),(t22,t21))))),(t16,((t11,((t9,t10),(t8,(t7,t6)))),((t14,t15),(t12,t13)))))),((t5,t4),(t2,t3))),t1,t0);
+((((t26,t27),(t2,t3)),((((t24,t25),(((t18,t17),((t19,t20),(t22,t21))),t23)),((t11,((t9,t10),(t8,(t7,t6)))),((t14,t15),(t16,(t12,t13))))),(t5,t4))),t1,t0);
+((((t5,t4),((t26,t27),(((t24,t25),(((t18,t17),(t22,(t21,(t19,t20)))),t23)),((t12,t13),((t16,(t11,((t9,t10),(t8,(t7,t6))))),(t14,t15)))))),(t2,t3)),t1,t0);
+((((t27,t26),((t23,((t18,t17),((t20,t19),(t22,t21)))),((t16,(t14,t15)),((t12,t13),((t11,((t10,t9),(t8,(t7,t6)))),(t24,t25)))))),((t5,t4),(t2,t3))),t1,t0);
+(((((t2,t3),(t27,t26)),(((t24,t25),(t23,((t18,t17),((t20,t19),(t22,t21))))),((t16,(t14,t15)),((t12,t13),(t11,((t10,t9),(t8,(t7,t6)))))))),(t5,t4)),t1,t0);
+((((((t24,t25),(t23,((t18,t17),((t20,t19),(t22,t21))))),((t11,((t10,t9),(t8,(t7,t6)))),((t14,t15),(t12,t13)))),t16),(((t5,t4),(t2,t3)),(t27,t26))),t1,t0);
+(((t5,t4),((t2,t3),((t27,t26),((t23,((t18,t17),((t20,t19),(t22,t21)))),(((t12,t13),((t24,t25),(t11,((t10,t9),(t8,(t7,t6)))))),(t16,(t14,t15))))))),t1,t0);
+(((((t23,((t18,t17),((t20,t19),(t22,t21)))),(t16,((t14,t15),((t11,((t10,t9),(t8,(t7,t6)))),((t12,t13),(t24,t25)))))),(t5,t4)),((t2,t3),(t27,t26))),t1,t0);
+((((((t24,t25),(t23,((t18,t17),((t20,t19),(t22,t21))))),(((t11,((t10,t9),(t8,(t7,t6)))),(t12,t13)),(t16,(t14,t15)))),(t5,t4)),(t27,(t26,(t2,t3)))),t1,t0);
+((((t27,t26),((t16,(t14,t15)),((((t18,t17),((t20,t19),(t22,t21))),((t24,t25),t23)),((t11,((t10,t9),(t8,(t7,t6)))),(t12,t13))))),((t2,t3),(t5,t4))),t1,t0);
+((((t27,t26),((((t24,t25),(t23,((t18,t17),((t20,t19),(t22,t21))))),(((t11,((t10,t9),(t8,(t7,t6)))),(t12,t13)),(t14,t15))),t16)),((t2,t3),(t5,t4))),t1,t0);
+(((((t2,t3),(t27,t26)),(((t14,t15),(((t24,t25),(t23,((t18,t17),((t20,t19),(t22,t21))))),((t11,((t10,t9),(t8,(t7,t6)))),(t12,t13)))),t16)),(t5,t4)),t1,t0);
+((((((t23,((t18,t17),((t20,t19),(t22,t21)))),((t14,t15),(t16,((t11,((t10,t9),(t8,(t7,t6)))),((t24,t25),(t12,t13)))))),(t2,t3)),(t27,t26)),(t5,t4)),t1,t0);
+(((t2,t3),(((((t25,t24),(((t20,t19),(t21,t22)),(t17,t18))),t23),((t26,t27),(t5,t4))),((t13,t12),((t16,(t14,t15)),(((t8,(t6,t7)),(t9,t10)),t11))))),t1,t0);
+(((t2,t3),((t5,t4),((((((t13,t12),(((t8,(t6,t7)),(t9,t10)),t11)),(t14,t15)),((t25,t24),((((t20,t19),(t21,t22)),(t17,t18)),t23))),t16),(t26,t27)))),t1,t0);
+(((((((t13,t12),(((t8,(t6,t7)),(t9,t10)),t11)),(t16,(t14,t15))),(t23,((t25,t24),(((t20,t19),(t21,t22)),(t17,t18))))),(t26,t27)),((t2,t3),(t5,t4))),t1,t0);
+((((((t16,((((t8,(t6,t7)),(t9,t10)),t11),((t13,t12),(t25,t24)))),(t14,t15)),((((t20,t19),(t21,t22)),(t17,t18)),t23)),(t26,t27)),((t2,t3),(t5,t4))),t1,t0);
+((((t2,t3),((((t13,t12),(((t8,(t6,t7)),(t9,t10)),t11)),((t14,t15),t16)),((t25,t24),(((t20,t19),((t21,t22),(t17,t18))),t23)))),((t26,t27),(t5,t4))),t1,t0);
+((((t2,t3),(t5,t4)),((((((t8,(t6,t7)),(t9,t10)),t11),((t14,t15),((t13,t12),t16))),((t25,t24),((((t22,t21),(t20,t19)),(t17,t18)),t23))),(t26,t27))),t1,t0);
+((((t2,t3),((((t14,t15),(((t25,t24),(t13,t12)),(((t8,(t6,t7)),(t9,t10)),t11))),t16),((((t22,t21),(t20,t19)),(t17,t18)),t23))),((t26,t27),(t5,t4))),t1,t0);
+((((t2,t3),((((t13,t12),(((t8,(t6,t7)),(t9,t10)),t11)),(t16,(t14,t15))),(((t25,t24),((t21,((t20,t19),t22)),(t17,t18))),t23))),(t27,((t5,t4),t26))),t1,t0);
+(((t5,t4),(((t26,t27),(t2,t3)),((t16,((t14,t15),(((t25,t24),(t13,t12)),(((t8,(t6,t7)),(t9,t10)),t11)))),((((t20,t19),(t22,t21)),(t17,t18)),t23)))),t1,t0);
+((t27,(((t2,t3),t26),(((((((t8,(t6,t7)),(t9,t10)),t11),(t25,t24)),(((t13,t12),t16),(t14,t15))),((((t20,t19),(t22,t21)),(t17,t18)),t23)),(t5,t4)))),t1,t0);
+(t1,(((t23,((t18,t17),((t21,t22),(t20,t19)))),(((t14,t15),((t11,((t8,(t6,t7)),(t10,t9))),((t25,t24),(t13,t12)))),t16)),((t5,t4),(t27,((t3,t2),t26)))),t0);
+(t1,((t5,t4),(((t3,t2),(t26,t27)),((t23,((t18,t17),((t21,t22),(t20,t19)))),(((t11,((t8,(t6,t7)),(t10,t9))),((t13,t12),(t14,t15))),((t25,t24),t16))))),t0);
+(t1,(((t5,t4),(t3,t2)),((t26,t27),((t23,((t18,t17),((t21,t22),(t20,t19)))),(t16,((t14,t15),((t11,((t8,(t6,t7)),(t10,t9))),((t25,t24),(t13,t12)))))))),t0);
+(t1,((t3,t2),(((t26,t27),(((t25,t24),(t23,((t18,t17),((t21,t22),(t20,t19))))),(((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),(t16,(t14,t15))))),(t5,t4))),t0);
+(t1,((t5,t4),((t3,t2),((t26,t27),((((t18,t17),((t21,t22),(t20,t19))),((t25,t24),t23)),(((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),(t16,(t14,t15))))))),t0);
+(t1,((t3,t2),(((t5,t4),(t26,t27)),(((t25,t24),(t23,((t18,t17),((t21,t22),(t20,t19))))),(((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),(t16,(t14,t15)))))),t0);
+(t1,(((t23,((t18,t17),((t21,t22),(t20,t19)))),((t14,t15),(((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),((t25,t24),t16)))),((t5,t4),((t3,t2),(t26,t27)))),t0);
+(t1,((t16,((((t23,((t18,t17),((t21,t22),(t20,t19)))),(t25,t24)),((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12))),(t14,t15))),((t3,t2),((t26,t27),(t5,t4)))),t0);
+(t1,((t16,((t23,((t18,t17),((t21,t22),(t20,t19)))),(((t11,((t8,(t6,t7)),(t10,t9))),((t25,t24),(t13,t12))),(t14,t15)))),((t5,t4),((t3,t2),(t26,t27)))),t0);
+(t1,(((t3,t2),(t26,t27)),(((t23,((t18,t17),((t21,t22),(t20,t19)))),(((t25,t24),(t13,t12)),((t16,(t14,t15)),(t11,((t8,(t6,t7)),(t10,t9)))))),(t5,t4))),t0);
+(t1,((t2,t3),((((t23,((t17,t18),((t22,t21),(t20,t19)))),(((t12,t13),(((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),(t15,t14))),t16)),(t27,t26)),(t5,t4))),t0);
+(t1,((((t23,((t17,t18),((t22,t21),(t20,t19)))),((t15,t14),((((t24,t25),(t12,t13)),(t11,((t8,(t7,t6)),(t10,t9)))),t16))),(t27,t26)),((t5,t4),(t2,t3))),t0);
+(t1,(((t2,t3),(t27,t26)),((t5,t4),((t23,((t17,t18),((t22,t21),(t20,t19)))),((((t24,t25),(t12,t13)),(t11,((t8,(t7,t6)),(t10,t9)))),(t16,(t15,t14)))))),t0);
+(t1,((((t24,t25),(t23,((t17,t18),((t22,t21),(t20,t19))))),((t12,t13),((t11,((t8,(t7,t6)),(t10,t9))),(t16,(t15,t14))))),(((t2,t3),(t27,t26)),(t5,t4))),t0);
+(t1,(((((t24,t25),(t23,((t17,t18),((t22,t21),(t20,t19))))),((t16,(t15,t14)),((t12,t13),(t11,((t8,(t7,t6)),(t10,t9)))))),(t27,t26)),((t5,t4),(t2,t3))),t0);
+(t1,(((((t24,t25),(t23,((t17,t18),((t22,t21),(t20,t19))))),((t16,(t15,t14)),((t12,t13),(t11,((t8,(t7,t6)),(t10,t9)))))),(t27,t26)),((t5,t4),(t2,t3))),t0);
+(t1,(((((t24,t25),(t23,((t17,t18),((t22,t21),(t20,t19))))),(((t12,t13),t16),((t15,t14),(t11,((t8,(t7,t6)),(t10,t9)))))),(t27,t26)),((t5,t4),(t2,t3))),t0);
+(t1,((((t23,((t17,t18),((t22,t21),(t20,t19)))),(((t12,t13),t16),((t15,t14),((t24,t25),(t11,((t8,(t7,t6)),(t10,t9))))))),(t27,t26)),((t5,t4),(t2,t3))),t0);
+(t1,((t5,t4),(((t2,t3),((t23,((t17,t18),((t22,t21),(t20,t19)))),(((t15,t14),t16),(((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),(t12,t13))))),(t27,t26))),t0);
+(t1,(((t2,t3),((t23,((t17,t18),((t22,t21),(t20,t19)))),((((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),((t12,t13),(t15,t14))),t16))),((t27,t26),(t5,t4))),t0);
+(t1,((((((t18,t17),((t20,t19),(t21,t22))),t23),(t16,(((t24,t25),(((((t7,t6),t8),(t9,t10)),t11),(t13,t12))),(t14,t15)))),(t27,t26)),((t4,t5),(t2,t3))),t0);
+(t1,((((((t18,t17),(t22,((t20,t19),t21))),t23),(((t13,t12),(t24,t25)),((((((t7,t6),t8),(t9,t10)),t11),(t14,t15)),t16))),(t27,t26)),((t4,t5),(t2,t3))),t0);
+(t1,((t2,t3),((((((t18,t17),((t20,t19),(t21,t22))),t23),((t14,t15),(t16,(((((t7,t6),t8),(t9,t10)),t11),((t24,t25),(t13,t12)))))),(t27,t26)),(t4,t5))),t0);
+(t1,((t4,t5),((((t24,t25),(((t18,t17),((t20,t19),(t21,t22))),t23)),(((t13,t12),t16),(((((t7,t6),t8),(t9,t10)),t11),(t14,t15)))),((t2,t3),(t27,t26)))),t0);
+(t1,(((t4,t5),(t2,t3)),((t27,t26),((((t18,t17),((t20,t19),(t21,t22))),t23),(((t24,t25),(t13,t12)),(((((t7,t6),t8),(t9,t10)),t11),(t16,(t14,t15))))))),t0);
+(t1,((((t24,t25),(((t18,t17),((t20,t19),(t21,t22))),t23)),((t16,(t14,t15)),((t13,t12),((((t7,t6),t8),(t9,t10)),t11)))),((t4,t5),((t2,t3),(t27,t26)))),t0);
+(t1,((t4,t5),(((t2,t3),(t27,t26)),((t23,((t24,t25),((t18,t17),((t20,t19),(t21,t22))))),((t16,(t14,t15)),((t13,t12),((((t7,t6),t8),(t9,t10)),t11)))))),t0);
+(t1,((t2,t3),(((t27,t26),(t4,t5)),(((t24,t25),(((t18,t17),((t20,t19),(t21,t22))),t23)),(((((t7,t6),t8),(t9,t10)),t11),(t16,((t14,t15),(t13,t12))))))),t0);
+(t1,(((t26,(t4,t5)),(((((t24,t25),(((t18,t17),((t20,t19),(t21,t22))),t23)),(((((t7,t6),t8),(t9,t10)),t11),((t14,t15),(t13,t12)))),t16),(t2,t3))),t27),t0);
+(t1,((((((t18,t17),((t20,t19),(t21,t22))),t23),(((t14,t15),((t24,t25),((((t7,t6),t8),(t9,t10)),t11))),(t16,(t13,t12)))),(t2,t3)),((t26,t27),(t4,t5))),t0);
+(t1,(((t26,t27),(((((t21,t22),(t19,t20)),(t17,t18)),t23),(((t12,t13),((t24,t25),(t11,((t10,t9),(t8,(t6,t7)))))),((t14,t15),t16)))),((t3,t2),(t5,t4))),t0);
+(t1,((t3,t2),((t5,t4),((t26,t27),((((t24,t25),((((t21,t22),(t19,t20)),(t17,t18)),t23)),((t11,((t10,t9),(t8,(t6,t7)))),((t14,t15),(t12,t13)))),t16)))),t0);
+(t1,(((t3,t2),(((t24,t25),(((t22,((t19,t20),t21)),(t17,t18)),t23)),((t11,((t10,t9),(t8,(t6,t7)))),((t14,t15),(t16,(t12,t13)))))),((t5,t4),(t26,t27))),t0);
+(t1,((t5,t4),((t26,t27),((t3,t2),(((((t19,t20),(t21,t22)),(t17,t18)),t23),((t16,(t12,t13)),(((t24,t25),(t11,((t10,t9),(t8,(t6,t7))))),(t14,t15))))))),t0);
+(t1,((t3,t2),((t5,t4),((((t24,t25),((((t19,t20),(t21,t22)),(t17,t18)),t23)),(((t14,t15),t16),((t12,t13),(t11,((t10,t9),(t8,(t6,t7))))))),(t26,t27)))),t0);
+(t1,(((t3,t2),(t26,t27)),((t5,t4),((((((t19,t20),(t21,t22)),(t17,t18)),t23),((t14,t15),(((t24,t25),(t12,t13)),(t11,((t10,t9),(t8,(t6,t7))))))),t16))),t0);
+(t1,((t3,t2),((((t24,t25),((((t19,t20),(t21,t22)),(t17,t18)),t23)),((t16,(t14,t15)),((t12,t13),(t11,((t10,t9),(t8,(t6,t7))))))),((t26,t27),(t5,t4)))),t0);
+(t1,(((t3,t2),(t26,t27)),((t5,t4),(((t24,t25),((((t19,t20),(t21,t22)),(t17,t18)),t23)),(((t12,t13),t16),((t14,t15),(t11,((t10,t9),(t8,(t6,t7))))))))),t0);
+(t1,(((t26,t27),((t3,t2),(t5,t4))),(((t24,t25),((((t19,t20),(t21,t22)),(t17,t18)),t23)),(((t11,((t10,t9),(t8,(t6,t7)))),(t12,t13)),((t14,t15),t16)))),t0);
+(t1,((t5,t4),((((((t19,t20),(t21,t22)),(t17,t18)),t23),((((t24,t25),(t11,((t10,t9),(t8,(t6,t7))))),(t12,t13)),((t14,t15),t16))),((t3,t2),(t26,t27)))),t0);
+((((((t24,t25),(((t18,t17),((t22,t21),(t19,t20))),t23)),((t13,t12),(((t14,t15),t16),(t11,(((t6,t7),t8),(t10,t9)))))),(t27,t26)),((t2,t3),(t4,t5))),t1,t0);
+((((t27,t26),(t4,t5)),((((t24,t25),(((t18,t17),((t22,t21),(t19,t20))),t23)),(((t14,t15),t16),((t11,(((t6,t7),t8),(t10,t9))),(t13,t12)))),(t2,t3))),t1,t0);
+(((t2,t3),(((((t24,t25),(((t18,t17),((t22,t21),(t19,t20))),t23)),(((t14,t15),t16),((t11,(((t6,t7),t8),(t10,t9))),(t13,t12)))),(t26,t27)),(t4,t5))),t1,t0);
+(((t4,t5),((t2,t3),((((t14,t15),t16),(((t11,(((t6,t7),t8),(t10,t9))),(t13,t12)),((t24,t25),(((t18,t17),((t22,t21),(t19,t20))),t23)))),(t26,t27)))),t1,t0);
+(((t2,t3),(((((t24,t25),(((t18,t17),((t22,t21),(t19,t20))),t23)),((t14,t15),(t16,((t11,(((t6,t7),t8),(t10,t9))),(t13,t12))))),(t26,t27)),(t4,t5))),t1,t0);
+(((t4,t5),((t2,t3),(((((t18,t17),((t22,t21),(t19,t20))),t23),(((t14,t15),t16),((t13,t12),((t11,(((t6,t7),t8),(t10,t9))),(t24,t25))))),(t26,t27)))),t1,t0);
+((((((t16,(t13,t12)),((t14,t15),(t11,(((t6,t7),t8),(t10,t9))))),((((t18,t17),((t22,t21),(t19,t20))),t23),(t24,t25))),(t26,t27)),((t4,t5),(t2,t3))),t1,t0);
+(((t2,t3),(((((t18,t17),((t22,t21),(t19,t20))),t23),((t14,t15),(t16,((t13,t12),((t11,(((t6,t7),t8),(t10,t9))),(t24,t25)))))),((t26,t27),(t4,t5)))),t1,t0);
+((((t4,t5),((((t24,t25),(t23,((t18,t17),((t22,t21),(t19,t20))))),(((t14,t15),(t16,(t13,t12))),(t11,(((t6,t7),t8),(t10,t9))))),t26)),(t27,(t2,t3))),t1,t0);
+(((t4,t5),((((t23,(((t18,t17),((t22,t21),(t19,t20))),(t24,t25))),(((t13,t12),(t11,(((t6,t7),t8),(t10,t9)))),(t16,(t14,t15)))),(t26,t27)),(t2,t3))),t1,t0);
+(t1,((t3,t2),((((t25,t24),(((t18,t17),((t21,t22),(t19,t20))),t23)),((t16,(t13,t12)),((((t9,t10),(t8,(t6,t7))),t11),(t15,t14)))),((t4,t5),(t27,t26)))),t0);
+(t1,((((((t18,t17),((t21,t22),(t19,t20))),t23),((t16,(t13,t12)),(((t25,t24),(((t9,t10),(t8,(t6,t7))),t11)),(t15,t14)))),(t27,t26)),((t3,t2),(t4,t5))),t0);
+(t1,((t4,t5),((((t25,t24),(((t18,t17),((t21,t22),(t19,t20))),t23)),(((t13,t12),(((t9,t10),(t8,(t6,t7))),t11)),((t15,t14),t16))),((t27,t26),(t3,t2)))),t0);
+(t1,(((t4,t5),(t3,t2)),((((t25,t24),(((t18,t17),((t21,t22),(t19,t20))),t23)),(((t13,t12),(((t9,t10),(t8,(t6,t7))),t11)),((t15,t14),t16))),(t27,t26))),t0);
+(t1,((t4,t5),((((t25,t24),(((t18,t17),((t21,t22),(t19,t20))),t23)),(((t13,t12),(((t9,t10),(t8,(t6,t7))),t11)),((t15,t14),t16))),((t3,t2),(t27,t26)))),t0);
+(t1,((t4,t5),((t27,(t26,((((t18,t17),((t21,t22),(t19,t20))),t23),(((t25,t24),t16),((((t9,t10),(t8,(t6,t7))),t11),((t13,t12),(t15,t14))))))),(t3,t2))),t0);
+(t1,((t3,t2),((t4,t5),((((t16,(t13,t12)),((t15,t14),(((t9,t10),(t8,(t6,t7))),t11))),((((t18,t17),((t21,t22),(t19,t20))),t23),(t25,t24))),(t27,t26)))),t0);
+(t1,((t4,t5),(((((t15,t14),((((t9,t10),(t8,(t6,t7))),t11),((t25,t24),(t13,t12)))),(((t18,t17),((t21,t22),(t19,t20))),t23)),t16),((t27,t26),(t3,t2)))),t0);
+(t1,(((((t25,t24),(t13,t12)),((t16,(t15,t14)),(((t9,t10),(t8,(t6,t7))),t11))),(((t18,t17),((t21,t22),(t19,t20))),t23)),(((t27,t26),(t3,t2)),(t4,t5))),t0);
+(t1,(((((t16,(t15,t14)),((((t9,t10),(t8,(t6,t7))),t11),(t13,t12))),((t25,t24),(((t18,t17),((t21,t22),(t19,t20))),t23))),(t3,t2)),((t4,t5),(t27,t26))),t0);
+(((t5,t4),((((t25,t24),(t23,((t18,t17),((t19,t20),(t22,t21))))),((t16,(t15,t14)),((t12,t13),(t11,((t10,t9),((t7,t6),t8)))))),((t3,t2),(t26,t27)))),t1,t0);
+(((t3,t2),(((t5,t4),(t26,t27)),((t16,(t15,t14)),(((t12,t13),(t11,((t10,t9),((t7,t6),t8)))),((t25,t24),(t23,((t18,t17),((t19,t20),(t22,t21))))))))),t1,t0);
+(((t5,t4),(((t3,t2),(t26,t27)),(((t25,t24),(t23,(((t18,t17),((t19,t20),t21)),t22))),((t16,((t15,t14),(t11,((t10,t9),((t7,t6),t8))))),(t12,t13))))),t1,t0);
+((((t3,t2),(t26,t27)),((((t25,t24),(t23,((t18,t17),((t19,t20),(t22,t21))))),((t11,((t10,t9),((t7,t6),t8))),(((t12,t13),t16),(t15,t14)))),(t5,t4))),t1,t0);
+((((t3,t2),(t5,t4)),((t26,t27),((t23,((t18,t17),((t19,t20),(t22,t21)))),((((t11,((t10,t9),((t7,t6),t8))),(t12,t13)),(t16,(t15,t14))),(t25,t24))))),t1,t0);
+(((t5,t4),(((t3,t2),(t26,t27)),((t23,((t18,t17),((t19,t20),(t22,t21)))),(((t15,t14),((t11,((t10,t9),((t7,t6),t8))),((t25,t24),(t12,t13)))),t16)))),t1,t0);
+((((t26,t27),((t23,((t18,t17),((t19,t20),(t22,t21)))),(((t25,t24),(t12,t13)),((t16,(t15,t14)),(t11,((t10,t9),((t7,t6),t8))))))),((t5,t4),(t3,t2))),t1,t0);
+((((t26,((t23,((t18,t17),((t19,t20),(t22,t21)))),(((t25,t24),(t12,t13)),((t16,(t15,t14)),(t11,((t10,t9),((t7,t6),t8))))))),((t5,t4),(t3,t2))),t27),t1,t0);
+((((((t23,((t18,t17),((t19,t20),(t22,t21)))),(t25,t24)),((t12,t13),((t16,(t15,t14)),(t11,((t10,t9),((t7,t6),t8)))))),((t27,t26),(t3,t2))),(t5,t4)),t1,t0);
+((((t5,t4),(t3,t2)),(((t23,((t18,t17),((t19,t20),(t22,t21)))),((t25,t24),((t12,t13),((t16,(t15,t14)),(t11,((t10,t9),((t7,t6),t8))))))),(t27,t26))),t1,t0);
+(((t5,t4),((t26,t27),(((((((t9,t10),((t6,t7),t8)),t11),(t12,t13)),(t16,(t14,t15))),((((t18,t17),((t20,t19),(t22,t21))),t23),(t25,t24))),(t2,t3)))),t1,t0);
+(((t2,t3),(((t5,t4),(t26,t27)),(t16,((t14,t15),(((((t18,t17),((t20,t19),(t22,t21))),t23),(t25,t24)),((((t9,t10),((t6,t7),t8)),t11),(t12,t13))))))),t1,t0);
+(((t5,t4),(((((t25,t24),(((t9,t10),((t6,t7),t8)),t11)),(((t12,t13),(t14,t15)),t16)),(((t18,t17),((t20,t19),(t22,t21))),t23)),((t26,t27),(t2,t3)))),t1,t0);
+((((t5,t4),((t27,t26),((((t18,t17),((t20,t19),(t22,t21))),t23),((((t25,t24),(((t9,t10),((t6,t7),t8)),t11)),(t12,t13)),(t16,(t14,t15)))))),(t2,t3)),t1,t0);
+((((t5,t4),((t27,t26),((((t18,t17),((t20,t19),(t22,t21))),t23),(t16,((t14,t15),(((t25,t24),(((t9,t10),((t6,t7),t8)),t11)),(t12,t13))))))),(t2,t3)),t1,t0);
+(((t5,t4),((t27,t26),((t2,t3),((((t18,t17),((t20,t19),(t22,t21))),t23),(((t14,t15),((t25,t24),(((t9,t10),((t6,t7),t8)),t11))),(t16,(t12,t13))))))),t1,t0);
+((((t2,t3),((((t18,t17),((t20,t19),(t22,t21))),t23),((t16,(t14,t15)),(((t12,t13),(t25,t24)),(((t9,t10),((t6,t7),t8)),t11))))),((t5,t4),(t27,t26))),t1,t0);
+((((t5,t4),((t27,t26),((((t18,t17),((t20,t19),(t22,t21))),t23),((t16,(t14,t15)),(((t12,t13),(t25,t24)),(((t9,t10),((t6,t7),t8)),t11)))))),(t2,t3)),t1,t0);
+((((t5,t4),((((t18,t17),((t20,t19),(t22,t21))),t23),(((t16,(t14,t15)),((((t9,t10),((t6,t7),t8)),t11),(t12,t13))),(t25,t24)))),((t27,t26),(t2,t3))),t1,t0);
+(((t5,t4),(((((t18,t17),(t22,(t21,(t20,t19)))),t23),(t16,((t14,t15),((((t9,t10),((t6,t7),t8)),t11),((t25,t24),(t12,t13)))))),((t27,t26),(t2,t3)))),t1,t0);
+((((t26,((t4,t5),(((((t24,t25),(t12,t13)),((t15,t14),(t11,((t8,(t7,t6)),(t10,t9))))),(t23,((t18,t17),((t22,t21),(t20,t19))))),t16))),t27),(t3,t2)),t1,t0);
+(((t4,t5),(((t16,(((t12,t13),(t15,t14)),(t11,((t8,(t7,t6)),(t10,t9))))),((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19)))))),((t27,t26),(t3,t2)))),t1,t0);
+((((t16,((t15,t14),((t11,((t8,(t7,t6)),(t10,t9))),(t12,t13)))),((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19)))))),(((t27,t26),(t3,t2)),(t4,t5))),t1,t0);
+((((t27,t26),(t3,t2)),((t4,t5),((t16,(((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),((t12,t13),(t15,t14)))),(t23,((t18,t17),((t22,t21),(t20,t19))))))),t1,t0);
+((((t4,t5),((((t16,(t15,t14)),(((t11,((t8,(t7,t6)),(t10,t9))),(t12,t13)),(t24,t25))),(t23,((t18,t17),((t22,t21),(t20,t19))))),(t27,t26))),(t3,t2)),t1,t0);
+(((t4,t5),(((t16,((t15,t14),((t11,((t8,(t7,t6)),(t10,t9))),(t12,t13)))),((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19)))))),((t3,t2),(t27,t26)))),t1,t0);
+(((t3,t2),(((t27,t26),(((t15,t14),(((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),((t12,t13),t16))),(t23,((t18,t17),((t22,t21),(t20,t19)))))),(t4,t5))),t1,t0);
+(((t3,t2),((t27,(t26,((((t11,((t8,(t7,t6)),(t10,t9))),(t12,t13)),(t16,(t15,t14))),((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19)))))))),(t4,t5))),t1,t0);
+(((t4,t5),((t3,t2),(((t23,((t18,t17),((t22,t21),(t20,t19)))),(((t12,t13),((t11,((t8,(t7,t6)),(t10,t9))),(t24,t25))),(t16,(t15,t14)))),(t27,t26)))),t1,t0);
+(((t3,t2),(((t23,((t18,t17),((t22,t21),(t20,t19)))),(((((t12,t13),(t11,((t8,(t7,t6)),(t10,t9)))),t16),(t15,t14)),(t24,t25))),((t4,t5),(t27,t26)))),t1,t0);
+(t1,(((t5,t4),(t26,t27)),((t3,t2),(((t25,t24),((((t22,t21),(t20,t19)),(t18,t17)),t23)),((t16,(t15,t14)),((t12,t13),(t11,((t8,(t7,t6)),(t10,t9)))))))),t0);
+(t1,(((t5,t4),(t26,t27)),((t3,t2),(((((t22,t21),(t20,t19)),(t18,t17)),t23),((t16,(t15,t14)),((t12,t13),((t25,t24),(t11,((t8,(t7,t6)),(t10,t9))))))))),t0);
+(t1,(((t5,t4),((((t11,((t8,(t7,t6)),(t10,t9))),(t16,(t15,t14))),(t12,t13)),(((((t22,t21),(t20,t19)),(t18,t17)),t23),(t25,t24)))),((t26,t27),(t3,t2))),t0);
+(t1,((t3,t2),((t5,t4),(t27,(t26,(((t15,t14),(((t11,((t8,(t7,t6)),(t10,t9))),((t25,t24),(t12,t13))),t16)),((((t22,t21),(t20,t19)),(t18,t17)),t23)))))),t0);
+(t1,((t5,t4),((((((t11,((t8,(t7,t6)),(t10,t9))),(t12,t13)),(t16,(t15,t14))),((t25,t24),((((t22,t21),(t20,t19)),(t18,t17)),t23))),(t27,t26)),(t3,t2))),t0);
+(t1,((t3,t2),((t5,t4),((((((t22,t21),(t20,t19)),(t18,t17)),t23),((t16,((t15,t14),((t11,((t8,(t7,t6)),(t10,t9))),(t12,t13)))),(t25,t24))),(t27,t26)))),t0);
+(t1,(((t3,t2),(t27,t26)),((t5,t4),((((t12,t13),((t15,t14),(t11,((t8,(t7,t6)),(t10,t9))))),((t25,t24),((((t22,t21),(t20,t19)),(t18,t17)),t23))),t16))),t0);
+(t1,((((((t12,t13),(t11,((t8,(t7,t6)),(t10,t9)))),(t16,(t15,t14))),((t25,t24),((((t22,t21),(t20,t19)),(t18,t17)),t23))),((t27,t26),(t5,t4))),(t3,t2)),t0);
+(t1,((t5,t4),((((((t25,t24),(t12,t13)),(t11,((t8,(t7,t6)),(t10,t9)))),(t16,(t15,t14))),((((t22,t21),(t20,t19)),(t18,t17)),t23)),((t3,t2),(t27,t26)))),t0);
+(t1,((((((t25,t24),(t12,t13)),(t11,((t8,(t7,t6)),(t10,t9)))),(t16,(t15,t14))),((((t22,t21),(t20,t19)),(t18,t17)),t23)),(((t3,t2),(t27,t26)),(t5,t4))),t0);
+(((t5,t4),((((t16,(t14,t15)),((t13,t12),(t11,((t8,(t7,t6)),(t9,t10))))),(((t25,t24),(((t19,t20),(t22,t21)),(t17,t18))),t23)),((t3,t2),(t27,t26)))),t1,t0);
+(((((t16,((t25,t24),(t13,t12))),((t11,((t8,(t7,t6)),(t9,t10))),(t14,t15))),((((t19,t20),(t22,t21)),(t17,t18)),t23)),((t3,t2),((t27,t26),(t5,t4)))),t1,t0);
+(((t5,t4),((t3,t2),(((t16,(((t13,t12),(t11,((t8,(t7,t6)),(t9,t10)))),(t14,t15))),((t25,t24),((((t19,t20),(t22,t21)),(t17,t18)),t23))),(t27,t26)))),t1,t0);
+(((t5,t4),((t16,((((t25,t24),((((t19,t20),(t22,t21)),(t17,t18)),t23)),((t13,t12),(t11,((t8,(t7,t6)),(t9,t10))))),(t14,t15))),((t27,t26),(t3,t2)))),t1,t0);
+(((t3,t2),(((((((t19,t20),(t22,t21)),(t17,t18)),t23),(((t13,t12),((t11,((t8,(t7,t6)),(t9,t10))),(t25,t24))),((t14,t15),t16))),(t27,t26)),(t5,t4))),t1,t0);
+(((t5,t4),((((((t19,t20),(t22,t21)),(t17,t18)),t23),(t16,(((t25,t24),(t13,t12)),((t14,t15),(t11,((t8,(t7,t6)),(t9,t10))))))),((t3,t2),(t27,t26)))),t1,t0);
+(((((((t19,t20),(t22,t21)),(t17,t18)),t23),(t16,((t14,t15),((t25,t24),((t11,((t8,(t7,t6)),(t9,t10))),(t13,t12)))))),((t3,t2),((t27,t26),(t5,t4)))),t1,t0);
+(((t3,t2),(((t27,t26),(((t25,t24),((((t19,t20),(t22,t21)),(t17,t18)),t23)),(((t13,t12),(t11,((t8,(t7,t6)),(t9,t10)))),(t16,(t14,t15))))),(t5,t4))),t1,t0);
+((((t27,t26),(((((t25,t24),(((t19,t20),(t22,t21)),(t17,t18))),(((t13,t12),(t11,((t8,(t7,t6)),(t9,t10)))),(t14,t15))),t23),t16)),((t5,t4),(t3,t2))),t1,t0);
+(((((t3,t2),(t27,t26)),(t16,((t14,t15),(((t25,t24),(t23,(((t19,t20),(t22,t21)),(t17,t18)))),((t13,t12),(t11,((t8,(t7,t6)),(t9,t10)))))))),(t5,t4)),t1,t0);
+(t1,((t5,t4),(((t27,t26),((t16,((t14,t15),((t13,t12),(t11,((t10,t9),(t8,(t6,t7))))))),(t23,(((t17,t18),((t22,t21),(t20,t19))),(t25,t24))))),(t3,t2))),t0);
+(t1,((((t16,(t14,t15)),(((t25,t24),(t23,((t17,t18),((t22,t21),(t20,t19))))),((t13,t12),(t11,((t10,t9),(t8,(t6,t7))))))),(t3,t2)),((t5,t4),(t27,t26))),t0);
+(t1,((((t23,((t17,t18),((t22,t21),(t20,t19)))),(((t11,((t10,t9),(t8,(t6,t7)))),((t25,t24),(t13,t12))),(t16,(t14,t15)))),(t3,t2)),(t27,(t26,(t5,t4)))),t0);
+(t1,((((t23,((t17,t18),((t22,t21),(t20,t19)))),(((t25,t24),((t11,((t10,t9),(t8,(t6,t7)))),(t13,t12))),(t16,(t14,t15)))),((t27,t26),(t3,t2))),(t5,t4)),t0);
+(t1,((((t23,((t17,t18),((t22,t21),(t20,t19)))),((((t13,t12),((t25,t24),(t11,((t10,t9),(t8,(t6,t7)))))),(t14,t15)),t16)),(t27,t26)),((t5,t4),(t3,t2))),t0);
+(t1,(((((t25,t24),(t23,((t17,t18),((t22,t21),(t20,t19))))),((t16,(t13,t12)),((t11,((t10,t9),(t8,(t6,t7)))),(t14,t15)))),((t27,t26),(t3,t2))),(t5,t4)),t0);
+(t1,(((((t25,t24),(t23,((t17,t18),((t22,t21),(t20,t19))))),((t16,(t13,t12)),((t11,((t10,t9),(t8,(t6,t7)))),(t14,t15)))),((t27,t26),(t3,t2))),(t5,t4)),t0);
+(t1,((t3,t2),((((t23,((t17,t18),((t22,t21),(t20,t19)))),((t16,(t13,t12)),(((t25,t24),(t11,((t10,t9),(t8,(t6,t7))))),(t14,t15)))),(t27,t26)),(t5,t4))),t0);
+(t1,(((((t25,t24),(t23,((t17,t18),((t22,t21),(t20,t19))))),(((t11,((t10,t9),(t8,(t6,t7)))),((t14,t15),t16)),(t13,t12))),(t27,t26)),((t5,t4),(t3,t2))),t0);
+(t1,(((((t25,t24),(t23,((t17,t18),((t22,t21),(t20,t19))))),(((t13,t12),t16),((t11,((t10,t9),(t8,(t6,t7)))),(t14,t15)))),(t27,t26)),((t5,t4),(t3,t2))),t0);
+((((t26,t27),(((t24,t25),(t23,(((t21,t22),(t19,t20)),(t18,t17)))),(((t14,t15),t16),((t13,t12),(((t10,t9),(t8,(t6,t7))),t11))))),((t5,t4),(t2,t3))),t1,t0);
+((((t26,t27),(((t24,t25),(t23,(((t21,t22),(t19,t20)),(t18,t17)))),((((t10,t9),(t8,(t6,t7))),t11),((t14,t15),(t16,(t13,t12)))))),((t5,t4),(t2,t3))),t1,t0);
+(((t2,t3),(((t26,t27),((t23,((t19,t20),((t18,t17),(t21,t22)))),(((t13,t12),((t24,t25),(((t10,t9),(t8,(t6,t7))),t11))),(t16,(t14,t15))))),(t5,t4))),t1,t0);
+((((t2,t3),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(((t13,t12),((t24,t25),(((t10,t9),(t8,(t6,t7))),t11))),(t16,(t14,t15))))),((t5,t4),(t26,t27))),t1,t0);
+(((((t23,(((t22,t21),(t19,t20)),(t18,t17))),(((t24,t25),((((t10,t9),(t8,(t6,t7))),t11),(t13,t12))),(t16,(t14,t15)))),(t26,t27)),((t2,t3),(t5,t4))),t1,t0);
+(((((((t24,t25),t23),(((t22,t21),(t19,t20)),(t18,t17))),((t13,t12),((t16,(t14,t15)),(((t10,t9),(t8,(t6,t7))),t11)))),((t26,t27),(t2,t3))),(t5,t4)),t1,t0);
+((((((t24,t25),(t23,(((t22,t21),(t19,t20)),(t18,t17)))),((t16,(t13,t12)),((t14,t15),(((t10,t9),(t8,(t6,t7))),t11)))),(t26,t27)),((t5,t4),(t2,t3))),t1,t0);
+(((t2,t3),((((t23,(((t22,t21),(t19,t20)),(t18,t17))),(((((t10,t9),(t8,(t6,t7))),t11),((t16,(t13,t12)),(t14,t15))),(t24,t25))),(t26,t27)),(t5,t4))),t1,t0);
+((((((t24,t25),(t23,(((t22,t21),(t19,t20)),(t18,t17)))),(((t14,t15),(((t10,t9),(t8,(t6,t7))),t11)),((t13,t12),t16))),(t26,t27)),((t5,t4),(t2,t3))),t1,t0);
+(((t2,t3),((((t23,(((t22,t21),(t19,t20)),(t18,t17))),((t16,(t14,t15)),((t13,t12),((((t10,t9),(t8,(t6,t7))),t11),(t24,t25))))),(t26,t27)),(t5,t4))),t1,t0);
+(((((t23,(((t20,t19),t22),(t21,(t18,t17)))),((t24,t25),((t13,t12),((((t10,t9),(t8,(t6,t7))),t11),(t16,(t15,t14)))))),(t27,t26)),((t5,t4),(t2,t3))),t1,t0);
+(((t2,t3),((((((t13,t12),((((t10,t9),(t8,(t6,t7))),t11),(t15,t14))),((t23,(((t20,t19),(t21,t22)),(t18,t17))),(t24,t25))),t16),(t27,t26)),(t5,t4))),t1,t0);
+(((((t23,(((t20,t19),(t21,t22)),(t18,t17))),((t24,t25),((t16,(t15,t14)),((t13,t12),(((t10,t9),(t8,(t6,t7))),t11))))),((t2,t3),(t27,t26))),(t5,t4)),t1,t0);
+(((((t23,(((t20,t19),(t21,t22)),(t18,t17))),((t24,t25),(((t15,t14),(t16,(t13,t12))),(((t10,t9),(t8,(t6,t7))),t11)))),((t2,t3),(t27,t26))),(t5,t4)),t1,t0);
+(((t2,t3),(((t26,t27),(t5,t4)),(t16,((t15,t14),(((t13,t12),(((t10,t9),(t8,(t6,t7))),t11)),((t23,(((t20,t19),(t21,t22)),(t18,t17))),(t24,t25))))))),t1,t0);
+(((t5,t4),((((t23,(((t20,t19),(t21,t22)),(t18,t17))),((t15,t14),(((t13,t12),(t24,t25)),(t16,(((t10,t9),(t8,(t6,t7))),t11))))),(t2,t3)),(t26,t27))),t1,t0);
+((((t26,t27),(t2,t3)),((t5,t4),(((t24,t25),(t23,(((t20,t19),(t21,t22)),(t18,t17)))),((t16,(t15,t14)),((t13,t12),(((t10,t9),(t8,(t6,t7))),t11)))))),t1,t0);
+(((t5,t4),(((t23,(((t20,t19),(t21,t22)),(t18,t17))),((((t24,t25),(((t10,t9),(t8,(t6,t7))),t11)),((t15,t14),(t13,t12))),t16)),(t27,((t2,t3),t26)))),t1,t0);
+((((t2,t3),(t26,t27)),((t5,t4),((t23,(((t20,t19),(t21,t22)),(t18,t17))),((t24,t25),(((t13,t12),(((t10,t9),(t8,(t6,t7))),t11)),((t15,t14),t16)))))),t1,t0);
+(((t5,t4),(((((t13,t12),(((t10,t9),(t8,(t6,t7))),t11)),((t15,t14),t16)),((t23,((t21,(t22,(t20,t19))),(t18,t17))),(t24,t25))),((t2,t3),(t26,t27)))),t1,t0);
+(((t3,t2),(((t27,t26),(((((t22,t21),(t20,t19)),(t18,t17)),t23),((((t24,t25),(t13,t12)),(t11,((t8,(t6,t7)),(t10,t9)))),(t16,(t14,t15))))),(t4,t5))),t1,t0);
+(((((((t22,t21),(t20,t19)),(t18,t17)),t23),(((t13,t12),((t11,((t8,(t6,t7)),(t10,t9))),(t24,t25))),(t16,(t14,t15)))),((t4,t5),((t3,t2),(t27,t26)))),t1,t0);
+((((((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23)),(((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),(t16,(t14,t15)))),(t27,t26)),((t4,t5),(t3,t2))),t1,t0);
+((((((t24,t25),(((t20,t19),((t18,t17),(t22,t21))),t23)),(((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),(t16,(t14,t15)))),((t3,t2),(t27,t26))),(t4,t5)),t1,t0);
+(((t4,t5),((((((t24,t25),(t11,((t8,(t6,t7)),(t10,t9)))),((((t18,t17),((t22,t21),(t20,t19))),t23),((t13,t12),(t14,t15)))),t16),(t27,t26)),(t3,t2))),t1,t0);
+(((t3,t2),((t4,t5),(((((t18,t17),((t22,t21),(t20,t19))),((t24,t25),t23)),((t13,t12),((t11,((t8,(t6,t7)),(t10,t9))),(t16,(t14,t15))))),(t27,t26)))),t1,t0);
+(((t3,t2),((t4,t5),(((((t18,t17),((t22,t21),(t20,t19))),((t24,t25),t23)),(((t14,t15),((t13,t12),(t11,((t8,(t6,t7)),(t10,t9))))),t16)),(t27,t26)))),t1,t0);
+((((t3,t2),(t16,((t11,((t8,(t6,t7)),(t10,t9))),(((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19))))),((t14,t15),(t13,t12)))))),((t27,t26),(t4,t5))),t1,t0);
+(((t4,t5),(((t23,((t18,t17),((t22,t21),(t20,t19)))),((((t24,t25),(t11,((t8,(t6,t7)),(t10,t9)))),(t14,t15)),(t16,(t13,t12)))),((t3,t2),(t27,t26)))),t1,t0);
+((((t4,t5),(((t23,((t18,t17),((t22,t21),(t20,t19)))),((t14,t15),(t16,((t13,t12),((t24,t25),(t11,((t8,(t6,t7)),(t10,t9)))))))),(t27,t26))),(t3,t2)),t1,t0);
+(t1,(((t2,t3),((t16,(t15,t14)),(((t11,((t8,(t7,t6)),(t10,t9))),(t13,t12)),((t24,t25),((((t22,t21),(t19,t20)),(t18,t17)),t23))))),((t5,t4),(t27,t26))),t0);
+(t1,((((t27,t26),(t2,t3)),(((t24,t25),((((t22,t21),(t19,t20)),(t18,t17)),t23)),((t16,(t15,t14)),((t11,((t8,(t7,t6)),(t10,t9))),(t13,t12))))),(t5,t4)),t0);
+(t1,(((t27,t26),(t2,t3)),((((t24,t25),((((t22,t21),(t19,t20)),(t18,t17)),t23)),((t13,t12),((t16,(t15,t14)),(t11,((t8,(t7,t6)),(t10,t9)))))),(t5,t4))),t0);
+(t1,((t5,t4),(((t27,t26),(t2,t3)),(((t24,t25),((((t22,t21),(t19,t20)),(t18,t17)),t23)),((t16,(t15,t14)),((t11,((t8,(t7,t6)),(t10,t9))),(t13,t12)))))),t0);
+(t1,(((t27,t26),(t2,t3)),((((((t22,t21),(t19,t20)),(t18,t17)),t23),(((t15,t14),((t11,((t8,(t7,t6)),(t10,t9))),(t16,(t13,t12)))),(t24,t25))),(t5,t4))),t0);
+(t1,((((t27,t26),(((((t22,t21),(t19,t20)),(t18,t17)),t23),(t16,((t15,t14),(((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),(t13,t12)))))),(t5,t4)),(t2,t3)),t0);
+(t1,((((t27,t26),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),(t13,t12)),(t16,(t15,t14))))),(t5,t4)),(t2,t3)),t0);
+(t1,((((t27,t26),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),(t13,t12)),(t16,(t15,t14))))),(t5,t4)),(t2,t3)),t0);
+(t1,((((t27,t26),(((((t22,t21),(t19,t20)),(t18,t17)),t23),(((t13,t12),(t24,t25)),((t16,(t15,t14)),(t11,((t8,(t7,t6)),(t10,t9))))))),(t5,t4)),(t2,t3)),t0);
+(t1,((t5,t4),((t2,t3),((t27,t26),(((((t22,t21),(t19,t20)),(t18,t17)),t23),((t16,(t15,t14)),(((t11,((t8,(t7,t6)),(t10,t9))),(t24,t25)),(t13,t12))))))),t0);
+(t1,((t2,t3),((t4,t5),((t27,t26),(((((t25,t24),(t12,t13)),(t11,((t9,t10),(t8,(t6,t7))))),(t16,(t15,t14))),(((t18,t17),((t22,t21),(t19,t20))),t23))))),t0);
+(t1,((t2,t3),((t4,t5),((t27,t26),(((t15,t14),((((t25,t24),(t12,t13)),(t11,((t9,t10),(t8,(t6,t7))))),t16)),(((t18,t17),((t22,t21),(t19,t20))),t23))))),t0);
+(t1,((t2,t3),((t4,t5),(t27,(t26,((t16,((t15,t14),(((t25,t24),(t12,t13)),(t11,((t9,t10),(t8,(t6,t7))))))),(((t18,t17),((t22,t21),(t19,t20))),t23)))))),t0);
+(t1,((t2,t3),((t4,t5),(((((t12,t13),((t11,((t9,t10),(t8,(t6,t7)))),(t25,t24))),(t16,(t15,t14))),(((t18,t17),((t22,t21),(t19,t20))),t23)),(t27,t26)))),t0);
+(t1,(((t27,t26),(t2,t3)),((t4,t5),((t16,(((t15,t14),(t12,t13)),(t11,((t9,t10),(t8,(t6,t7)))))),(((t25,t24),((t18,t17),((t22,t21),(t19,t20)))),t23)))),t0);
+(t1,((t2,t3),((t4,t5),((t27,t26),(((t12,t13),((t11,((t9,t10),(t8,(t6,t7)))),(t16,(t15,t14)))),((t25,t24),(((t18,t17),((t22,t21),(t19,t20))),t23)))))),t0);
+(t1,((t4,t5),(((t2,t3),(t27,t26)),(((t16,(t15,t14)),((t12,t13),(t11,((t9,t10),(t8,(t6,t7)))))),((t25,t24),(((t18,t17),((t21,(t19,t20)),t22)),t23))))),t0);
+(t1,((((t16,(t15,t14)),((t12,t13),(t11,((t9,t10),(t8,(t6,t7)))))),((t25,t24),(((t18,t17),((t19,t20),(t22,t21))),t23))),((t4,t5),((t2,t3),(t27,t26)))),t0);
+(t1,((t4,t5),(((((((t25,t24),(t11,((t9,t10),(t8,(t6,t7))))),((t15,t14),(t12,t13))),(((t18,t17),((t19,t20),(t22,t21))),t23)),t16),(t2,t3)),(t27,t26))),t0);
+(t1,((t2,t3),(((t27,t26),(((t15,t14),(((t12,t13),(t11,((t9,t10),(t8,(t6,t7))))),((t25,t24),(((t18,t17),((t19,t20),(t22,t21))),t23)))),t16)),(t4,t5))),t0);
+((((((t24,t25),((((t22,t21),(t19,t20)),(t17,t18)),t23)),(((t13,t12),(((t9,t10),((t7,t6),t8)),t11)),((t15,t14),t16))),((t5,t4),(t26,t27))),(t3,t2)),t1,t0);
+((((t5,t4),((t26,t27),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(t16,((t13,t12),(((t24,t25),(((t9,t10),((t7,t6),t8)),t11)),(t15,t14))))))),(t3,t2)),t1,t0);
+((((t5,t4),((t26,t27),(((t16,(t15,t14)),((((t9,t10),((t7,t6),t8)),t11),(t13,t12))),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(t24,t25))))),(t3,t2)),t1,t0);
+(((t27,(t26,(t5,t4))),((((t16,(t15,t14)),((((t9,t10),((t7,t6),t8)),t11),(t13,t12))),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(t24,t25))),(t3,t2))),t1,t0);
+((((t5,t4),(t27,t26)),(((((t15,t14),((((t9,t10),((t7,t6),t8)),t11),(t13,t12))),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(t24,t25))),t16),(t3,t2))),t1,t0);
+(((((t3,t2),(t5,t4)),(t27,t26)),(((t15,t14),((((t24,t25),(((t9,t10),((t7,t6),t8)),t11)),(t13,t12)),((((t22,t21),(t19,t20)),(t17,t18)),t23))),t16)),t1,t0);
+(((t3,t2),((t5,t4),((t27,t26),(((((t22,t21),(t19,t20)),(t17,t18)),t23),((t16,(t15,t14)),((((t9,t10),((t7,t6),t8)),t11),((t13,t12),(t24,t25)))))))),t1,t0);
+(((t3,t2),((t5,t4),((t27,t26),(((t24,t25),((((t22,t21),(t19,t20)),(t17,t18)),t23)),((t16,(t15,t14)),((((t9,t10),((t7,t6),t8)),t11),(t13,t12))))))),t1,t0);
+((((t27,t26),(t5,t4)),((((((t22,t21),(t19,t20)),(t17,t18)),t23),((((t13,t12),t16),(t15,t14)),((t24,t25),(((t9,t10),((t7,t6),t8)),t11)))),(t3,t2))),t1,t0);
+(((t5,t4),((((((t22,t21),(t19,t20)),(t17,t18)),t23),(((t15,t14),((((t9,t10),((t7,t6),t8)),t11),((t13,t12),(t24,t25)))),t16)),((t3,t2),(t27,t26)))),t1,t0);
+(t1,((t5,t4),((t26,t27),((t2,t3),((t23,(((t18,t17),t22),((t21,t19),t20))),(((t15,t14),t16),((t13,t12),((t25,t24),(((t9,t10),((t7,t6),t8)),t11)))))))),t0);
+(t1,((t5,t4),((t2,t3),((t27,t26),(((t25,t24),(t23,((t18,t17),(t22,(t21,(t19,t20)))))),((((t9,t10),((t7,t6),t8)),t11),(((t15,t14),t16),(t13,t12))))))),t0);
+(t1,((t2,t3),(((t27,t26),(t5,t4)),(((t25,t24),(t23,((t18,t17),((t19,t20),(t22,t21))))),((((t9,t10),((t7,t6),t8)),t11),(((t13,t12),t16),(t15,t14)))))),t0);
+(t1,((((t25,t24),(t23,((t18,t17),((t19,t20),(t22,t21))))),((((t9,t10),((t7,t6),t8)),t11),((t13,t12),(t16,(t15,t14))))),(((t2,t3),(t27,t26)),(t5,t4))),t0);
+(t1,((((t23,((t18,t17),((t19,t20),(t22,t21)))),(((t15,t14),(((t25,t24),(((t9,t10),((t7,t6),t8)),t11)),(t13,t12))),t16)),(t27,t26)),((t5,t4),(t2,t3))),t0);
+(t1,((((t23,((t18,t17),((t19,t20),(t22,t21)))),(((((t9,t10),((t7,t6),t8)),t11),((t13,t12),(t25,t24))),(t16,(t15,t14)))),(t2,t3)),(t27,(t26,(t5,t4)))),t0);
+(t1,((t2,t3),((t5,t4),((t27,t26),((t23,((t18,t17),((t19,t20),(t22,t21)))),(t16,((t15,t14),(((((t9,t10),((t7,t6),t8)),t11),(t13,t12)),(t25,t24)))))))),t0);
+(t1,(((t27,t26),((t23,((t18,t17),((t19,t20),(t22,t21)))),((t15,t14),(((((t9,t10),((t7,t6),t8)),t11),(t13,t12)),(t16,(t25,t24)))))),((t2,t3),(t5,t4))),t0);
+(t1,(((t27,t26),((t2,t3),((((t23,((t18,t17),((t19,t20),(t22,t21)))),(t25,t24)),((t15,t14),((((t9,t10),((t7,t6),t8)),t11),(t13,t12)))),t16))),(t5,t4)),t0);
+(t1,(((((t23,((t18,t17),((t19,t20),(t22,t21)))),(t25,t24)),((t13,t12),((t16,(t15,t14)),(((t9,t10),((t7,t6),t8)),t11)))),((t27,t26),(t2,t3))),(t5,t4)),t0);
+((((((((t20,t19),t21),t22),(t17,t18)),t23),((t16,(t14,t15)),((t11,((t8,(t6,t7)),(t10,t9))),((t25,t24),(t12,t13))))),((t5,t4),((t3,t2),(t27,t26)))),t1,t0);
+(((t5,t4),(((t3,t2),(t27,t26)),((((((t20,t19),(t21,t22)),(t17,t18)),t23),(((t25,t24),(t12,t13)),((t14,t15),(t11,((t8,(t6,t7)),(t10,t9)))))),t16))),t1,t0);
+(((t5,t4),((t3,t2),((t27,t26),(((((t20,t19),(t21,t22)),(t17,t18)),t23),(((t12,t13),(t16,(t14,t15))),((t11,((t8,(t6,t7)),(t10,t9))),(t25,t24))))))),t1,t0);
+(((((t25,t24),(((((t20,t19),t21),(t17,t18)),t22),t23)),(((t14,t15),((t11,((t8,(t6,t7)),(t10,t9))),(t12,t13))),t16)),(((t5,t4),(t3,t2)),(t27,t26))),t1,t0);
+(((((t3,t2),(t27,t26)),(t16,(((((t20,t19),(t22,t21)),(t17,t18)),t23),(((t25,t24),(t11,((t8,(t6,t7)),(t10,t9)))),((t12,t13),(t14,t15)))))),(t5,t4)),t1,t0);
+((((t3,t2),(t27,((((t25,t24),((((t20,t19),(t22,t21)),(t17,t18)),t23)),((t16,(t14,t15)),((t11,((t8,(t6,t7)),(t10,t9))),(t12,t13)))),t26))),(t5,t4)),t1,t0);
+((((t3,t2),(((t23,((t25,t24),(((t20,t19),(t22,t21)),(t17,t18)))),((t16,(t14,t15)),((t11,((t8,(t6,t7)),(t10,t9))),(t12,t13)))),(t26,t27))),(t5,t4)),t1,t0);
+((((t3,t2),(((((((t20,t19),(t22,t21)),(t17,t18)),t23),(((t25,t24),(t11,((t8,(t6,t7)),(t10,t9)))),((t12,t13),(t14,t15)))),t16),(t26,t27))),(t5,t4)),t1,t0);
+((((t3,t2),((((((t20,t19),(t22,t21)),(t17,t18)),t23),((((t12,t13),(t25,t24)),(t11,((t8,(t6,t7)),(t10,t9)))),(t16,(t14,t15)))),(t26,t27))),(t5,t4)),t1,t0);
+(((t3,t2),(((((((t20,t19),(t22,t21)),(t17,t18)),t23),((t25,t24),((t12,t13),((t16,(t14,t15)),(t11,((t8,(t6,t7)),(t10,t9))))))),(t26,t27)),(t5,t4))),t1,t0);
+(((t3,t2),(((t27,t26),((t16,((t14,t15),((t11,((t10,t9),((t6,t7),t8))),((t24,t25),(t13,t12))))),((((t20,t19),(t21,t22)),(t18,t17)),t23))),(t4,t5))),t1,t0);
+(((((t3,t2),(t27,t26)),(((t14,t15),(((t11,((t10,t9),((t6,t7),t8))),((t24,t25),(t13,t12))),t16)),((((t20,t19),(t21,t22)),(t18,t17)),t23))),(t4,t5)),t1,t0);
+(((t3,t2),(((t27,t26),(((t13,t12),((t16,(t14,t15)),(t11,((t10,t9),((t6,t7),t8))))),(((t21,(t22,(t20,t19))),(t18,t17)),((t24,t25),t23)))),(t4,t5))),t1,t0);
+(((t3,t2),(((t27,t26),((t23,(((t20,t19),(t21,t22)),(t18,t17))),((t16,(t14,t15)),(((t24,t25),(t13,t12)),(t11,((t10,t9),((t6,t7),t8))))))),(t4,t5))),t1,t0);
+(((t4,t5),(((t27,t26),(t3,t2)),(((t24,t25),(t23,(((t20,t19),(t21,t22)),(t18,t17)))),((t13,t12),((t11,((t10,t9),((t6,t7),t8))),(t16,(t14,t15))))))),t1,t0);
+(((t3,t2),((((t24,t25),(t23,(((t20,t19),(t21,t22)),(t18,t17)))),((t16,(t14,t15)),((t13,t12),(t11,((t10,t9),((t6,t7),t8)))))),((t27,t26),(t4,t5)))),t1,t0);
+(((t4,t5),(((t27,t26),(t3,t2)),(((t24,t25),(t23,(((t20,t19),(t21,t22)),(t18,t17)))),(((t13,t12),t16),((t14,t15),(t11,((t10,t9),((t6,t7),t8)))))))),t1,t0);
+(((t3,t2),((((t24,t25),(t23,(((t20,t19),t22),(t21,(t18,t17))))),((t13,t12),((t11,((t10,t9),((t6,t7),t8))),(t16,(t14,t15))))),((t27,t26),(t4,t5)))),t1,t0);
+(((t4,t5),(((t23,((((t20,t19),t21),(t22,(t18,t17))),(t24,t25))),((t16,(t13,t12)),((t11,((t10,t9),((t6,t7),t8))),(t14,t15)))),((t3,t2),(t27,t26)))),t1,t0);
+(((t3,t2),(((t4,t5),(t27,t26)),(((t24,t25),(t23,((t18,t17),((t20,t19),(t21,t22))))),(((t14,t15),((t13,t12),(t11,((t10,t9),((t6,t7),t8))))),t16)))),t1,t0);
+(((t4,t5),((((t25,t24),(t23,((t18,t17),((t22,t21),(t19,t20))))),(((t14,t15),(t11,((t9,t10),(t8,(t7,t6))))),(t16,(t12,t13)))),((t2,t3),(t26,t27)))),t1,t0);
+(((t2,t3),((t4,t5),((t26,t27),(((t25,t24),(t23,((t18,t17),(t22,(t21,(t19,t20)))))),(((t16,(t14,t15)),(t11,((t9,t10),(t8,(t7,t6))))),(t12,t13)))))),t1,t0);
+(((t2,t3),(((t23,((t18,t17),((t19,t20),(t22,t21)))),(((t14,t15),((t25,t24),(t11,((t9,t10),(t8,(t7,t6)))))),(t16,(t12,t13)))),((t4,t5),(t26,t27)))),t1,t0);
+((((t2,t3),(t4,t5)),((t26,t27),((t23,((t18,t17),((t19,t20),(t22,t21)))),(t16,((t12,t13),((t14,t15),((t25,t24),(t11,((t9,t10),(t8,(t7,t6))))))))))),t1,t0);
+(((t2,t3),((t4,t5),((t26,t27),((t23,((t18,t17),((t19,t20),(t22,t21)))),((t16,(t14,t15)),(((t12,t13),(t25,t24)),(t11,((t9,t10),(t8,(t7,t6)))))))))),t1,t0);
+((((((t25,t24),(t23,((t18,t17),((t19,t20),(t22,t21))))),((t14,t15),((t11,((t9,t10),(t8,(t7,t6)))),(t12,t13)))),t16),(((t4,t5),(t26,t27)),(t2,t3))),t1,t0);
+(((t2,t3),((t4,t5),(((t23,((t18,t17),((t19,t20),(t22,t21)))),(t16,(((t11,((t9,t10),(t8,(t7,t6)))),((t25,t24),(t12,t13))),(t14,t15)))),(t26,t27)))),t1,t0);
+((((t2,t3),(t26,t27)),((t4,t5),(((t25,t24),(((t18,t17),((t19,t20),(t22,t21))),t23)),(((t11,((t9,t10),(t8,(t7,t6)))),(t12,t13)),((t14,t15),t16))))),t1,t0);
+(((t2,t3),(t27,(((t23,((t18,t17),((t19,t20),(t22,t21)))),((((t25,t24),(t11,((t9,t10),(t8,(t7,t6))))),(t16,(t12,t13))),(t14,t15))),((t4,t5),t26)))),t1,t0);
+(((t2,t3),(((t27,t26),(((t25,t24),(t23,((t21,(t22,(t18,t17))),(t19,t20)))),(((t14,t15),t16),((t12,t13),(t11,((t9,t10),(t8,(t7,t6)))))))),(t4,t5))),t1,t0);
+(((t3,t2),(((t27,t26),(((((t20,t19),(t22,t21)),(t17,t18)),t23),(((t15,t14),((t13,t12),((t25,t24),(t11,((t10,t9),(t8,(t6,t7))))))),t16))),(t5,t4))),t1,t0);
+((((t27,t26),((((t21,((t20,t19),t22)),(t17,t18)),t23),(((t11,((t10,t9),(t8,(t6,t7)))),((t13,t12),(t25,t24))),(t16,(t15,t14))))),((t5,t4),(t3,t2))),t1,t0);
+(((t3,t2),(((t27,t26),(((((t21,(t20,t19)),(t17,t18)),t22),t23),((((t13,t12),((t25,t24),(t11,((t10,t9),(t8,(t6,t7)))))),(t15,t14)),t16))),(t5,t4))),t1,t0);
+(((t16,((((t17,t18),((t21,t22),(t20,t19))),t23),(((t11,((t10,t9),(t8,(t6,t7)))),((t13,t12),(t25,t24))),(t15,t14)))),((t3,t2),((t27,t26),(t5,t4)))),t1,t0);
+(((((t3,t2),(t27,t26)),(t5,t4)),(((t25,t24),(((t17,t18),((t21,t22),(t20,t19))),t23)),(((t13,t12),(t11,((t10,t9),(t8,(t6,t7))))),(t16,(t15,t14))))),t1,t0);
+(((t5,t4),((t3,t2),((((t25,t24),(((t17,t18),((t21,t22),(t20,t19))),t23)),(((t13,t12),(t11,((t10,t9),(t8,(t6,t7))))),(t16,(t15,t14)))),(t27,t26)))),t1,t0);
+(((t5,t4),((t27,t26),((t3,t2),(((t25,t24),(((t17,t18),((t21,t22),(t20,t19))),t23)),((t13,t12),(t16,((t15,t14),(t11,((t10,t9),(t8,(t6,t7))))))))))),t1,t0);
+((((t5,t4),(t3,t2)),(((((t17,t18),((t21,t22),(t20,t19))),t23),(((t11,((t10,t9),(t8,(t6,t7)))),(t16,(t15,t14))),((t25,t24),(t13,t12)))),(t27,t26))),t1,t0);
+((((((t25,t24),(((t17,t18),((t21,t22),(t20,t19))),t23)),((t16,(t15,t14)),((t13,t12),(t11,((t10,t9),(t8,(t6,t7))))))),((t3,t2),(t27,t26))),(t5,t4)),t1,t0);
+((((t27,t26),((((t17,t18),((t21,t22),(t20,t19))),t23),(((t25,t24),(t13,t12)),((t11,((t10,t9),(t8,(t6,t7)))),(t16,(t15,t14)))))),((t5,t4),(t3,t2))),t1,t0);
+(((t4,t5),(((t26,t27),(t3,t2)),((t16,(((t12,t13),(t15,t14)),(t11,((t10,t9),(t8,(t6,t7)))))),((t25,t24),(t23,((t21,(t20,t19)),(t22,(t17,t18)))))))),t1,t0);
+((((t3,t2),(((t16,(t15,t14)),((t11,((t10,t9),(t8,(t6,t7)))),(t12,t13))),((t25,t24),(t23,(((t22,t21),(t20,t19)),(t17,t18)))))),((t4,t5),(t26,t27))),t1,t0);
+(((t4,t5),((t26,t27),((t3,t2),((((t25,t24),(t11,((t10,t9),(t8,(t6,t7))))),((t23,(((t22,t21),(t20,t19)),(t17,t18))),((t12,t13),(t15,t14)))),t16)))),t1,t0);
+((((t3,t2),((((t25,t24),(t23,(((t22,t21),(t20,t19)),(t17,t18)))),(((t11,((t10,t9),(t8,(t6,t7)))),(t12,t13)),(t15,t14))),t16)),((t4,t5),(t26,t27))),t1,t0);
+((((t3,t2),((t26,t27),((t23,(((t22,t21),(t20,t19)),(t17,t18))),((t16,(((t25,t24),(t12,t13)),(t11,((t10,t9),(t8,(t6,t7)))))),(t15,t14))))),(t4,t5)),t1,t0);
+((((t3,t2),((t26,t27),(((t23,(((t22,t21),(t20,t19)),(t17,t18))),((((t11,((t10,t9),(t8,(t6,t7)))),(t12,t13)),(t25,t24)),(t15,t14))),t16))),(t4,t5)),t1,t0);
+(((t3,t2),(((t26,((t23,((t25,t24),(((t22,t21),(t20,t19)),(t17,t18)))),(((t11,((t10,t9),(t8,(t6,t7)))),(t15,t14)),((t12,t13),t16)))),(t4,t5)),t27)),t1,t0);
+(((t4,t5),((t3,t2),((t26,t27),((t23,(((t22,t21),(t20,t19)),(t17,t18))),((((t25,t24),(t11,((t10,t9),(t8,(t6,t7))))),(t15,t14)),((t12,t13),t16)))))),t1,t0);
+(((t3,t2),(((t26,t27),((t23,(((t22,t21),(t20,t19)),(t17,t18))),(((t15,t14),((t12,t13),((t25,t24),(t11,((t10,t9),(t8,(t6,t7))))))),t16))),(t4,t5))),t1,t0);
+(((t3,t2),(((t26,t27),((t23,((t17,t18),(t22,(t21,(t20,t19))))),(((t12,t13),(t25,t24)),((t11,((t10,t9),(t8,(t6,t7)))),(t16,(t15,t14)))))),(t4,t5))),t1,t0);
+(t1,((t3,t2),(((t26,t27),(((((t21,(t19,t20)),t22),(t17,t18)),t23),((t25,t24),(((t13,t12),(t11,((t9,t10),((t6,t7),t8)))),(t16,(t14,t15)))))),(t5,t4))),t0);
+(t1,((t5,t4),((t3,t2),((t26,t27),(((t25,t24),((((t19,t20),(t22,t21)),(t17,t18)),t23)),(t16,((t11,((t9,t10),((t6,t7),t8))),((t14,t15),(t13,t12)))))))),t0);
+(t1,(((t26,t27),((t23,((t25,t24),(((t19,t20),(t22,t21)),(t17,t18)))),(t16,((t13,t12),((t11,((t9,t10),((t6,t7),t8))),(t14,t15)))))),((t5,t4),(t3,t2))),t0);
+(t1,((t5,t4),((t3,t2),((t26,t27),(((t25,t24),((((t19,t20),(t22,t21)),(t17,t18)),t23)),((t11,((t9,t10),((t6,t7),t8))),((t16,(t14,t15)),(t13,t12))))))),t0);
+(t1,((t3,t2),(((t26,t27),((t23,(((t19,t20),(t22,t21)),(t17,t18))),(((t14,t15),((t13,t12),((t25,t24),(t11,((t9,t10),((t6,t7),t8)))))),t16))),(t5,t4))),t0);
+(t1,((t3,t2),(((t23,(((t19,t20),(t22,t21)),(t17,t18))),(((t14,t15),((t25,t24),(t11,((t9,t10),((t6,t7),t8))))),((t13,t12),t16))),((t5,t4),(t26,t27)))),t0);
+(t1,((t3,t2),((t5,t4),((t26,t27),(((t25,t24),(t23,(((t19,t20),(t22,t21)),(t17,t18)))),(((t13,t12),(t11,((t9,t10),((t6,t7),t8)))),(t16,(t14,t15))))))),t0);
+(t1,((((t3,t2),(t26,t27)),(((t25,t24),(t23,(((t19,t20),(t22,t21)),(t17,t18)))),(((t13,t12),(t11,((t9,t10),((t6,t7),t8)))),(t16,(t14,t15))))),(t5,t4)),t0);
+(t1,(((t26,(t27,(t3,t2))),((t23,(((t19,t20),(t22,t21)),(t17,t18))),((((t13,t12),(t11,((t9,t10),((t6,t7),t8)))),(t16,(t14,t15))),(t25,t24)))),(t5,t4)),t0);
+(t1,((t3,t2),(((t26,t27),((t23,(((t19,t20),(t22,t21)),(t17,t18))),(((t14,t15),(((t25,t24),(t13,t12)),(t11,((t9,t10),((t6,t7),t8))))),t16))),(t5,t4))),t0);
+(t1,((t2,t3),((t5,t4),((((t12,t13),((t11,((t8,(t6,t7)),(t10,t9))),(t16,(t15,t14)))),((t24,t25),(((t18,t17),((t21,t22),(t20,t19))),t23))),(t26,t27)))),t0);
+(t1,((t2,t3),(((((((t24,t25),(t12,t13)),(t11,((t8,(t6,t7)),(t10,t9)))),((t15,t14),t16)),(((t20,t19),((t18,t17),(t21,t22))),t23)),(t26,(t5,t4))),t27)),t0);
+(t1,((t2,t3),((t5,t4),((t26,t27),((((t24,t25),(t11,((t8,(t6,t7)),(t10,t9)))),((t15,t14),((t12,t13),t16))),(((t18,t17),((t21,t22),(t20,t19))),t23))))),t0);
+(t1,((t2,t3),((t5,t4),((t26,t27),(((t24,t25),(((t12,t13),t16),((t11,((t8,(t6,t7)),(t10,t9))),(t15,t14)))),(((t18,t17),((t21,t22),(t20,t19))),t23))))),t0);
+(t1,(((t2,t3),((((t15,t14),(((t24,t25),(t12,t13)),(t11,((t8,(t6,t7)),(t10,t9))))),t16),(((t21,t22),(t20,t19)),(t23,(t18,t17))))),((t5,t4),(t26,t27))),t0);
+(t1,(((t2,t3),(t5,t4)),((t26,t27),((((t15,t14),((t12,t13),(t11,((t8,(t6,t7)),(t10,t9))))),t16),((t24,t25),(((t20,t19),((t18,t17),(t21,t22))),t23))))),t0);
+(t1,((t2,t3),((t5,t4),((t26,t27),((((t18,t17),((t21,t22),(t20,t19))),t23),((((t12,t13),(t11,((t8,(t6,t7)),(t10,t9)))),(t16,(t15,t14))),(t24,t25)))))),t0);
+(t1,((t5,t4),(((t2,t3),(t26,t27)),((((t12,t13),t16),((t15,t14),(t11,((t8,(t6,t7)),(t10,t9))))),((t24,t25),(((t18,t17),((t21,t22),(t20,t19))),t23))))),t0);
+(t1,((t5,t4),((t26,t27),((((t16,((t12,t13),(t15,t14))),(t11,((t8,(t6,t7)),(t10,t9)))),((t24,t25),(((t18,t17),((t21,t22),(t20,t19))),t23))),(t2,t3)))),t0);
+(t1,(((((t15,t14),(t16,(t12,t13))),(t11,((t8,(t6,t7)),(t10,t9)))),((t24,t25),(((t18,t17),((t21,t22),(t20,t19))),t23))),(((t26,t27),(t2,t3)),(t5,t4))),t0);
+(((((((t15,t14),t16),((t11,((t10,t9),(t8,(t6,t7)))),(t12,t13))),((t24,t25),(((t17,t18),((t22,t21),(t20,t19))),t23))),(t27,t26)),((t4,t5),(t3,t2))),t1,t0);
+(((t3,t2),((t16,((((t11,((t10,t9),(t8,(t6,t7)))),(t12,t13)),((t24,t25),(((t17,t18),((t22,t21),(t20,t19))),t23))),(t15,t14))),((t27,t26),(t4,t5)))),t1,t0);
+(((t3,t2),((t4,t5),(((((t17,t18),(t19,((t22,t21),t20))),(t23,(t24,t25))),(((t15,t14),t16),((t11,((t10,t9),(t8,(t6,t7)))),(t12,t13)))),(t27,t26)))),t1,t0);
+(((t4,t5),((((((t17,t18),((t22,t21),(t20,t19))),t23),(((t15,t14),t16),(((t24,t25),(t11,((t10,t9),(t8,(t6,t7))))),(t12,t13)))),(t27,t26)),(t3,t2))),t1,t0);
+(((t4,t5),((t27,t26),((t3,t2),((((t12,t13),((((t17,t18),((t22,t21),(t20,t19))),t23),(t24,t25))),(t11,((t10,t9),(t8,(t6,t7))))),((t15,t14),t16))))),t1,t0);
+(((t4,t5),((t3,t2),((((((t17,t18),((t22,t21),(t20,t19))),t23),(t24,t25)),(((t11,((t10,t9),(t8,(t6,t7)))),(t15,t14)),(t16,(t12,t13)))),(t27,t26)))),t1,t0);
+((((((((t17,t18),((t22,t21),(t20,t19))),t23),(t24,t25)),(((t11,((t10,t9),(t8,(t6,t7)))),(t16,(t15,t14))),(t12,t13))),((t3,t2),(t27,t26))),(t4,t5)),t1,t0);
+((((t4,t5),(t3,t2)),((t27,t26),((((t17,t18),((t22,t21),(t20,t19))),t23),((((t24,t25),(t11,((t10,t9),(t8,(t6,t7))))),(t15,t14)),(t16,(t12,t13)))))),t1,t0);
+(((t4,t5),((t3,t2),((t27,t26),((((t17,t18),((t22,t21),(t20,t19))),t23),((t15,t14),(((t12,t13),(t11,((t10,t9),(t8,(t6,t7))))),(t16,(t24,t25)))))))),t1,t0);
+(((t3,t2),(((t4,t5),(t27,t26)),((((t17,t18),((t22,t21),(t20,t19))),t23),((t16,(t15,t14)),(((t24,t25),(t12,t13)),(t11,((t10,t9),(t8,(t6,t7))))))))),t1,t0);
+((((((((t25,t24),t23),((t18,t17),((t21,t22),(t19,t20)))),((t14,t15),((t12,t13),(t11,((t9,t10),((t7,t6),t8)))))),t16),(t26,t27)),((t2,t3),(t4,t5))),t1,t0);
+((((((t16,(t14,t15)),((t12,t13),((t25,t24),(t11,((t9,t10),((t7,t6),t8)))))),(t23,((t18,t17),((t21,t22),(t19,t20))))),(t26,t27)),((t2,t3),(t4,t5))),t1,t0);
+(((((t2,t3),(((t12,t13),((t16,(t14,t15)),(t11,((t9,t10),((t7,t6),t8))))),((t25,t24),(t23,((t18,t17),((t21,t22),(t19,t20))))))),(t26,t27)),(t4,t5)),t1,t0);
+((((t2,t3),((((t16,(t14,t15)),((t11,((t9,t10),((t7,t6),t8))),(t12,t13))),((t25,t24),(t23,((t18,t17),((t21,t22),(t19,t20)))))),(t26,t27))),(t4,t5)),t1,t0);
+((((t26,t27),(t2,t3)),((t4,t5),(((t11,((t9,t10),((t7,t6),t8))),((t12,t13),(t16,(t14,t15)))),((t25,t24),(t23,((t18,t17),((t21,t22),(t19,t20)))))))),t1,t0);
+((((t2,t3),(((t16,(t14,t15)),((t11,((t9,t10),((t7,t6),t8))),(t12,t13))),(t23,(((t18,t17),((t21,t22),(t19,t20))),(t25,t24))))),((t26,t27),(t4,t5))),t1,t0);
+(((t2,t3),((t4,t5),((((t16,(t14,t15)),((t11,((t9,t10),((t7,t6),t8))),(t12,t13))),((t25,t24),(t23,((t18,t17),((t21,t22),(t19,t20)))))),(t26,t27)))),t1,t0);
+(((t4,t5),(((((t16,(t14,t15)),((t11,((t9,t10),((t7,t6),t8))),((t25,t24),(t12,t13)))),(t23,((t18,t17),((t21,t22),(t19,t20))))),(t26,t27)),(t2,t3))),t1,t0);
+((((t26,t27),(t2,t3)),((t4,t5),((t16,((t14,t15),((t12,t13),((t11,((t9,t10),((t7,t6),t8))),(t25,t24))))),(t23,((t18,t17),((t21,t22),(t19,t20))))))),t1,t0);
+((((t26,t27),(t4,t5)),(((((t12,t13),(t11,((t9,t10),((t7,t6),t8)))),(t16,(t14,t15))),((t25,t24),(t23,((t18,t17),((t21,t22),(t19,t20)))))),(t2,t3))),t1,t0);
+(((t4,t5),(((t23,(((t19,t20),(t22,t21)),(t18,t17))),((((t13,t12),(t11,((t9,t10),(t8,(t6,t7))))),(t16,(t15,t14))),(t25,t24))),((t3,t2),(t26,t27)))),t1,t0);
+((((t26,t27),(t4,t5)),(((((t13,t12),(t11,((t9,t10),(t8,(t6,t7))))),(t16,(t15,t14))),((t25,t24),(t23,(((t19,t20),(t22,t21)),(t18,t17))))),(t3,t2))),t1,t0);
+((((t4,t5),(t3,t2)),((t26,t27),(((t11,((t9,t10),(t8,(t6,t7)))),((t16,(t15,t14)),(t13,t12))),((t25,t24),(t23,(((t19,t20),(t22,t21)),(t18,t17))))))),t1,t0);
+(((t3,t2),(((t26,t27),(t4,t5)),(((t13,t12),((t11,((t9,t10),(t8,(t6,t7)))),(t16,(t15,t14)))),((t25,t24),(t23,(((t19,t20),(t22,t21)),(t18,t17))))))),t1,t0);
+(((t3,t2),((t4,t5),(((t23,(((t19,t20),(t22,t21)),(t18,t17))),((((t11,((t9,t10),(t8,(t6,t7)))),((t15,t14),(t13,t12))),(t25,t24)),t16)),(t26,t27)))),t1,t0);
+((((t26,t27),(t4,t5)),(((((t11,((t9,t10),(t8,(t6,t7)))),((t13,t12),(t15,t14))),((t25,t24),(t23,(((t19,t20),(t22,t21)),(t18,t17))))),t16),(t3,t2))),t1,t0);
+(((t3,t2),((t26,t27),(((((t13,t12),((t15,t14),(t11,((t9,t10),(t8,(t6,t7)))))),((t25,t24),(t23,(((t19,t20),(t22,t21)),(t18,t17))))),t16),(t4,t5)))),t1,t0);
+(((t3,t2),(((t23,(((t19,t20),(t22,t21)),(t18,t17))),(t16,(((t25,t24),(t13,t12)),((t15,t14),(t11,((t9,t10),(t8,(t6,t7)))))))),((t4,t5),(t26,t27)))),t1,t0);
+(((t4,t5),((t26,t27),((t3,t2),((t23,(((t19,t20),(t22,t21)),(t18,t17))),(((t15,t14),((t25,t24),(t11,((t9,t10),(t8,(t6,t7)))))),(t16,(t13,t12))))))),t1,t0);
+(((t3,t2),((t4,t5),(((t23,(((t19,t20),(t22,t21)),(t18,t17))),((t15,t14),(t16,((t11,((t9,t10),(t8,(t6,t7)))),((t25,t24),(t13,t12)))))),(t26,t27)))),t1,t0);
+(t1,(((t5,t4),(t27,t26)),((((t12,t13),(t16,((t11,((t10,t9),(t8,(t6,t7)))),(t15,t14)))),(((t21,(t19,t20)),(t22,(t18,t17))),((t25,t24),t23))),(t2,t3))),t0);
+(t1,(((t5,t4),(t27,t26)),((((t16,(t12,t13)),(((t25,t24),(t11,((t10,t9),(t8,(t6,t7))))),(t15,t14))),(t23,((t18,t17),((t19,t20),(t21,t22))))),(t2,t3))),t0);
+(t1,((t2,t3),(((t27,t26),((((t12,t13),(t11,((t10,t9),(t8,(t6,t7))))),((t15,t14),t16)),((t25,t24),(t23,((t18,t17),((t19,t20),(t21,t22))))))),(t5,t4))),t0);
+(t1,((t5,t4),(((t2,t3),(t27,t26)),((t23,((t18,t17),((t19,t20),(t21,t22)))),((((t12,t13),(t11,((t10,t9),(t8,(t6,t7))))),((t15,t14),t16)),(t25,t24))))),t0);
+(t1,(((t5,t4),(t2,t3)),((t27,t26),((((t16,(t12,t13)),(t11,((t10,t9),(t8,(t6,t7))))),(t15,t14)),((t25,t24),(t23,((t18,t17),((t19,t20),(t21,t22)))))))),t0);
+(t1,((t5,t4),((t2,t3),((t27,t26),((((t12,t13),(t11,((t10,t9),(t8,(t6,t7))))),(t16,(t15,t14))),((t25,t24),(t23,((t18,t17),((t19,t20),(t21,t22))))))))),t0);
+(t1,((t5,t4),((t27,t26),((((t11,((t10,t9),(t8,(t6,t7)))),((t16,(t15,t14)),(t12,t13))),((t25,t24),(t23,((t18,t17),((t19,t20),(t21,t22)))))),(t2,t3)))),t0);
+(t1,((t5,t4),((t2,t3),((t27,t26),(((t16,(t15,t14)),((t12,t13),(t11,((t10,t9),(t8,(t6,t7)))))),((t25,t24),(t23,((t18,t17),((t19,t20),(t21,t22))))))))),t0);
+(t1,(((t2,t3),(t5,t4)),((t26,((t23,((t18,t17),((t19,t20),(t21,t22)))),(((t16,(t15,t14)),((t12,t13),(t11,((t10,t9),(t8,(t6,t7)))))),(t25,t24)))),t27)),t0);
+(t1,((t5,t4),(((((t11,((t10,t9),(t8,(t6,t7)))),((t16,(t15,t14)),(t12,t13))),((t25,t24),(t23,((t18,t17),((t19,t20),(t21,t22)))))),(t27,t26)),(t2,t3))),t0);
+(((t3,t2),((t5,t4),((((t15,t14),(t16,((t12,t13),((t24,t25),(t11,(((t7,t6),t8),(t9,t10))))))),(((t17,t18),((t22,t21),(t20,t19))),t23)),(t26,t27)))),t1,t0);
+(((t5,t4),(((t3,t2),(((t15,t14),(((t24,t25),(t11,(((t7,t6),t8),(t9,t10)))),(t16,(t12,t13)))),(((t17,t18),((t22,t21),(t20,t19))),t23))),(t26,t27))),t1,t0);
+(((t5,t4),(((((t15,t14),(t11,(((t7,t6),t8),(t9,t10)))),((t12,t13),t16)),((t24,t25),(((t20,t19),((t17,t18),(t22,t21))),t23))),((t26,t27),(t3,t2)))),t1,t0);
+((((t5,t4),(t27,t26)),((((t11,(((t7,t6),t8),(t9,t10))),(((t12,t13),t16),(t15,t14))),((t24,t25),(((t17,t18),((t22,t21),(t20,t19))),t23))),(t3,t2))),t1,t0);
+(((t3,t2),(((t27,t26),(((t11,(((t7,t6),t8),(t9,t10))),(((t12,t13),t16),(t15,t14))),((t24,t25),(((t17,t18),((t22,t21),(t20,t19))),t23)))),(t5,t4))),t1,t0);
+(((t3,t2),((((((t11,(((t7,t6),t8),(t9,t10))),(t12,t13)),t16),(t15,t14)),((t24,t25),(((t17,t18),((t22,t21),(t20,t19))),t23))),((t5,t4),(t27,t26)))),t1,t0);
+(((t3,t2),(((((t11,(((t7,t6),t8),(t9,t10))),((t12,t13),((t24,t25),(((t17,t18),((t22,t21),(t20,t19))),t23)))),(t16,(t15,t14))),(t27,t26)),(t5,t4))),t1,t0);
+((((t3,t2),(t16,((t15,t14),((((t17,t18),((t22,t21),(t20,t19))),t23),(((t24,t25),(t11,(((t7,t6),t8),(t9,t10)))),(t12,t13)))))),((t27,t26),(t5,t4))),t1,t0);
+((((((t17,t18),((t22,t21),(t20,t19))),t23),((((t24,t25),(t11,(((t7,t6),t8),(t9,t10)))),(t12,t13)),(t16,(t15,t14)))),(((t3,t2),(t27,t26)),(t5,t4))),t1,t0);
+(((t3,t2),((((((t17,t18),((t22,t21),(t20,t19))),t23),((((t11,(((t7,t6),t8),(t9,t10))),(t12,t13)),(t16,(t15,t14))),(t24,t25))),(t27,t26)),(t5,t4))),t1,t0);
+(t1,((t4,t5),(((t3,t2),(t26,t27)),(((t16,(t15,t14)),((((t9,t10),(t8,(t6,t7))),t11),((t25,t24),(t12,t13)))),(((t18,t17),((t19,t20),(t21,t22))),t23)))),t0);
+(t1,((t4,t5),(((t3,t2),(t26,t27)),(((((((t9,t10),(t8,(t6,t7))),t11),(t25,t24)),(t12,t13)),(t16,(t15,t14))),(((t18,t17),((t19,t20),(t21,t22))),t23)))),t0);
+(t1,(((t3,t2),(t26,t27)),(((((t25,t24),(t12,t13)),(t16,((((t9,t10),(t8,(t6,t7))),t11),(t15,t14)))),(((t18,t17),((t19,t20),(t21,t22))),t23)),(t4,t5))),t0);
+(t1,((t4,t5),(((t3,t2),(t26,t27)),((((t12,t13),(((t9,t10),(t8,(t6,t7))),t11)),((t15,t14),t16)),((t25,t24),(((t18,t17),((t19,t20),(t21,t22))),t23))))),t0);
+(t1,((t4,t5),((t3,t2),((t26,t27),((t16,(((((t9,t10),(t8,(t6,t7))),t11),(t25,t24)),((t12,t13),(t15,t14)))),(t23,((t18,t17),((t19,t20),(t21,t22)))))))),t0);
+(t1,((((t16,(t15,t14)),(((((t9,t10),(t8,(t6,t7))),t11),(t25,t24)),(t12,t13))),(t23,((t18,t17),((t19,t20),(t21,t22))))),((t26,t27),((t3,t2),(t4,t5)))),t0);
+(t1,((((t15,t14),(((t12,t13),(((t9,t10),(t8,(t6,t7))),t11)),t16)),((t25,t24),(((t4,t5),(t26,t27)),(((t18,t17),((t19,t20),(t21,t22))),t23)))),(t3,t2)),t0);
+(t1,(((t4,t5),(t26,t27)),((((t15,t14),(((t12,t13),(((t9,t10),(t8,(t6,t7))),t11)),((t25,t24),(((t18,t17),(((t19,t20),t22),t21)),t23)))),t16),(t3,t2))),t0);
+(t1,((t3,t2),((t4,t5),((t26,t27),((((t18,t17),((t19,t20),(t22,t21))),t23),(((t16,(t15,t14)),((t12,t13),(((t9,t10),(t8,(t6,t7))),t11))),(t25,t24)))))),t0);
+(t1,((t3,t2),((t4,t5),(t27,((((t16,(t15,t14)),(((t25,t24),(t12,t13)),(((t9,t10),(t8,(t6,t7))),t11))),(((t18,t17),((t19,t20),(t22,t21))),t23)),t26)))),t0);
+(((t3,t2),((t5,t4),(((t16,(((t12,t13),((((t10,t9),(t8,(t6,t7))),t11),(t24,t25))),(t15,t14))),((((t20,t19),(t22,t21)),(t17,t18)),t23)),(t26,t27)))),t1,t0);
+(((t3,t2),((t5,t4),(((t16,(((t24,t25),(t12,t13)),((t15,t14),(((t10,t9),(t8,(t6,t7))),t11)))),((((t20,t19),(t22,t21)),(t17,t18)),t23)),(t26,t27)))),t1,t0);
+(((t3,t2),((t5,t4),((((t16,(t15,t14)),(((((t10,t9),(t8,(t6,t7))),t11),(t12,t13)),(t24,t25))),((((t20,t19),t22),(t21,(t17,t18))),t23)),(t26,t27)))),t1,t0);
+((((((t24,t25),((t16,(t15,t14)),((((t10,t9),(t8,(t6,t7))),t11),(t12,t13)))),((((t20,t19),(t21,t22)),(t17,t18)),t23)),((t3,t2),(t26,t27))),(t5,t4)),t1,t0);
+(((t3,t2),((((t5,t4),t26),t27),((((t15,t14),((((t10,t9),(t8,(t6,t7))),t11),((t24,t25),(t12,t13)))),t16),((((t20,t19),(t21,t22)),(t17,t18)),t23)))),t1,t0);
+(((t3,t2),(((t5,t4),(t26,t27)),((((((t10,t9),(t8,(t6,t7))),t11),(t12,t13)),(t16,(t15,t14))),((((t20,t19),(t21,t22)),(t17,t18)),((t24,t25),t23))))),t1,t0);
+(((t3,t2),(((((t12,t13),(t16,((t15,t14),(((t10,t9),(t8,(t6,t7))),t11)))),((t24,t25),(t23,(((t20,t19),(t21,t22)),(t17,t18))))),(t26,t27)),(t5,t4))),t1,t0);
+(((t5,t4),((t3,t2),(((((t15,t14),t16),((((t10,t9),(t8,(t6,t7))),t11),(t12,t13))),((t24,t25),(t23,(((t20,t19),(t21,t22)),(t17,t18))))),(t26,t27)))),t1,t0);
+(((((t5,t4),(t16,((((((t10,t9),(t8,(t6,t7))),t11),(t12,t13)),((t24,t25),(t23,(((t20,t19),(t21,t22)),(t17,t18))))),(t15,t14)))),(t26,t27)),(t3,t2)),t1,t0);
+(((t5,t4),(((t23,(((t20,t19),(t21,t22)),(t17,t18))),((((t15,t14),t16),((((t10,t9),(t8,(t6,t7))),t11),(t12,t13))),(t24,t25))),((t26,t27),(t3,t2)))),t1,t0);
+(t1,((t5,t4),((t26,t27),((((t24,t25),(t23,(((t22,t21),(t19,t20)),(t18,t17)))),((t13,t12),(t16,((((t9,t10),(t8,(t6,t7))),t11),(t15,t14))))),(t2,t3)))),t0);
+(t1,((t5,t4),((t26,t27),(((t23,(((t22,t21),(t19,t20)),(t18,t17))),(((t13,t12),(t15,t14)),(t16,((t24,t25),(((t9,t10),(t8,(t6,t7))),t11))))),(t2,t3)))),t0);
+(t1,((((t23,(((t22,t21),(t19,t20)),(t18,t17))),(((t13,t12),(t16,(t15,t14))),((t24,t25),(((t9,t10),(t8,(t6,t7))),t11)))),((t26,t27),(t2,t3))),(t5,t4)),t0);
+(t1,(((t26,t27),(t2,t3)),((t5,t4),((t23,(((t22,t21),(t19,t20)),(t18,t17))),((t15,t14),((((t24,t25),(((t9,t10),(t8,(t6,t7))),t11)),(t13,t12)),t16))))),t0);
+(t1,((t2,t3),(((t23,(((t22,t21),(t19,t20)),(t18,t17))),((((t13,t12),(t24,t25)),((t15,t14),(((t9,t10),(t8,(t6,t7))),t11))),t16)),((t5,t4),(t26,t27)))),t0);
+(t1,((t2,t3),(((t23,(((t22,t21),(t19,t20)),(t18,t17))),((t24,t25),((t16,((t13,t12),(t15,t14))),(((t9,t10),(t8,(t6,t7))),t11)))),((t5,t4),(t26,t27)))),t0);
+(t1,(((t2,t3),(((t23,(((t22,t21),(t19,t20)),(t18,t17))),((t15,t14),(((((t9,t10),(t8,(t6,t7))),t11),(t24,t25)),((t13,t12),t16)))),(t26,t27))),(t5,t4)),t0);
+(t1,((t2,t3),((((t23,(((t22,t21),(t19,t20)),(t18,t17))),((((t24,t25),(t13,t12)),((t15,t14),(((t9,t10),(t8,(t6,t7))),t11))),t16)),(t26,t27)),(t5,t4))),t0);
+(t1,(((t2,t3),(t16,((t15,t14),(((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t24,t25)),((((t9,t10),(t8,(t6,t7))),t11),(t13,t12)))))),((t26,t27),(t5,t4))),t0);
+(t1,((((t26,t27),(t2,t3)),((t23,(((t22,t21),(t19,t20)),(t18,t17))),((((t24,t25),(((t9,t10),(t8,(t6,t7))),t11)),((t15,t14),(t13,t12))),t16))),(t5,t4)),t0);
+(((t5,t4),(((((t15,t14),t16),((t13,t12),(t11,(((t7,t6),t8),(t10,t9))))),((((t21,t22),(t20,t19)),(t18,t17)),((t25,t24),t23))),((t3,t2),(t27,t26)))),t1,t0);
+(((t5,t4),(((t3,t2),(t27,t26)),(((t11,(((t7,t6),t8),(t10,t9))),(((t15,t14),t16),(t13,t12))),((t25,t24),(t23,(((t21,t22),(t20,t19)),(t18,t17))))))),t1,t0);
+(((((t5,t4),(t27,t26)),(((t11,(((t7,t6),t8),(t10,t9))),((t15,t14),(t16,(t13,t12)))),((t25,t24),(t23,(((t21,t22),(t20,t19)),(t18,t17)))))),(t3,t2)),t1,t0);
+(((t5,t4),(((t3,t2),(t27,t26)),((((t15,t14),((t13,t12),(t11,(((t7,t6),t8),(t10,t9))))),t16),(((t22,((t20,t19),t21)),(t18,t17)),((t25,t24),t23))))),t1,t0);
+((((t3,t2),(t27,t26)),((t16,((((t13,t12),(t11,(((t7,t6),t8),(t10,t9)))),((t25,t24),(t23,(((t20,t19),(t21,t22)),(t18,t17))))),(t15,t14))),(t5,t4))),t1,t0);
+(((t5,t4),(((t3,t2),(((t25,t24),(t23,(((t20,t19),(t21,t22)),(t18,t17)))),((((t13,t12),(t15,t14)),(t11,(((t7,t6),t8),(t10,t9)))),t16))),(t27,t26))),t1,t0);
+(((t3,t2),(((t23,(((t20,t19),(t21,t22)),(t18,t17))),(t16,(((t13,t12),(t11,(((t7,t6),t8),(t10,t9)))),((t25,t24),(t15,t14))))),((t27,t26),(t5,t4)))),t1,t0);
+((((t5,t4),(((t23,((t18,t17),(((t20,t19),t21),t22))),(t16,((t13,t12),((t15,t14),((t11,(((t7,t6),t8),(t10,t9))),(t25,t24)))))),(t27,t26))),(t3,t2)),t1,t0);
+((((t5,t4),(((t23,((t18,t17),((t20,t19),(t21,t22)))),((((t13,t12),(t11,(((t7,t6),t8),(t10,t9)))),(t25,t24)),(t16,(t15,t14)))),(t27,t26))),(t3,t2)),t1,t0);
+((((t16,(((t11,(((t7,t6),t8),(t10,t9))),(t15,t14)),((t13,t12),((t23,((t18,t17),((t20,t19),(t21,t22)))),(t25,t24))))),(t27,t26)),((t3,t2),(t5,t4))),t1,t0);
+(((t2,t3),((((t16,(((t11,((t10,t9),((t7,t6),t8))),(t13,t12)),(t14,t15))),(((t19,t20),((t18,t17),t21)),((t23,t22),(t24,t25)))),(t27,t26)),(t4,t5))),t1,t0);
+(((t2,t3),((((((t18,t17),((t21,t22),(t19,t20))),t23),((t16,(t14,t15)),((t11,((t10,t9),((t7,t6),t8))),((t24,t25),(t13,t12))))),(t27,t26)),(t4,t5))),t1,t0);
+(((((((t18,t17),((t21,t22),(t19,t20))),t23),((t16,(t14,t15)),((t11,((t10,t9),((t7,t6),t8))),((t24,t25),(t13,t12))))),(t27,t26)),((t4,t5),(t2,t3))),t1,t0);
+((((((((t24,t25),(((t18,t17),((t21,t22),(t19,t20))),t23)),((t13,t12),(t11,((t10,t9),((t7,t6),t8))))),(t14,t15)),t16),(t27,t26)),((t4,t5),(t2,t3))),t1,t0);
+((((((((t11,((t10,t9),((t7,t6),t8))),(t24,t25)),(t13,t12)),((t14,t15),t16)),(((t18,t17),((t21,t22),(t19,t20))),t23)),(t2,t3)),((t27,t26),(t4,t5))),t1,t0);
+((((((t11,((t10,t9),((t7,t6),t8))),(t16,((t13,t12),(t14,t15)))),((t24,t25),(((t18,t17),((t21,t22),(t19,t20))),t23))),(t2,t3)),((t27,t26),(t4,t5))),t1,t0);
+(((t2,t3),(((((t14,t15),(t16,((t11,((t10,t9),((t7,t6),t8))),(t13,t12)))),((t24,t25),(((t18,t17),((t21,t22),(t19,t20))),t23))),(t27,t26)),(t4,t5))),t1,t0);
+(((t2,t3),((((((t18,t17),((t21,t22),(t19,t20))),t23),((((t11,((t10,t9),((t7,t6),t8))),(t13,t12)),(t14,t15)),(t16,(t24,t25)))),(t27,t26)),(t4,t5))),t1,t0);
+(((t4,t5),((t2,t3),(((((t18,t17),((t21,t22),(t19,t20))),t23),((((t11,((t10,t9),((t7,t6),t8))),((t24,t25),(t13,t12))),(t14,t15)),t16)),(t27,t26)))),t1,t0);
+(((t4,t5),(((((t19,t20),((t18,t17),(t21,t22))),(t23,(t24,t25))),((t16,(t13,t12)),((t14,t15),(t11,((t10,t9),((t7,t6),t8)))))),((t27,t26),(t2,t3)))),t1,t0);
+(t1,(((t5,t4),(t27,t26)),((t2,t3),(((t25,t24),(t23,((t17,t18),((t21,t22),(t19,t20))))),((t16,(t14,t15)),((t12,t13),(t11,(((t6,t7),t8),(t9,t10)))))))),t0);
+(t1,(((t23,((t17,t18),((t21,t22),(t19,t20)))),(((t25,t24),(t12,t13)),((t11,(((t6,t7),t8),(t9,t10))),(t16,(t14,t15))))),(((t5,t4),(t27,t26)),(t2,t3))),t0);
+(t1,((t2,t3),((t5,t4),(((t23,((t17,t18),((t21,t22),(t19,t20)))),((t16,(t14,t15)),((t12,t13),((t11,(((t6,t7),t8),(t9,t10))),(t25,t24))))),(t27,t26)))),t0);
+(t1,((((t23,((t17,t18),((t21,t22),(t19,t20)))),(((t11,(((t6,t7),t8),(t9,t10))),((t12,t13),(t25,t24))),((t14,t15),t16))),((t2,t3),(t27,t26))),(t5,t4)),t0);
+(t1,((((t25,t24),(t23,((t17,t18),((t21,t22),(t19,t20))))),((t12,t13),(((t14,t15),t16),(t11,(((t6,t7),t8),(t9,t10)))))),(((t2,t3),(t27,t26)),(t5,t4))),t0);
+(t1,(((t2,t3),(t5,t4)),(t27,(t26,((t23,((t17,t18),((t21,t22),(t19,t20)))),((t16,(t12,t13)),((t14,t15),((t25,t24),(t11,(((t6,t7),t8),(t9,t10)))))))))),t0);
+(t1,((t5,t4),((((((t12,t13),(t11,(((t6,t7),t8),(t9,t10)))),(t16,(t14,t15))),((t23,((t17,t18),((t21,t22),(t19,t20)))),(t25,t24))),(t27,t26)),(t2,t3))),t0);
+(t1,((t5,t4),(((t2,t3),(t27,t26)),(((t11,(((t6,t7),t8),(t9,t10))),(t16,((t14,t15),(t12,t13)))),((t23,((t17,t18),((t21,t22),(t19,t20)))),(t25,t24))))),t0);
+(t1,((t2,t3),((((t16,(t14,t15)),((t11,(((t6,t7),t8),(t9,t10))),(t12,t13))),((t23,((t17,t18),((t21,t22),(t19,t20)))),(t25,t24))),(t27,(t26,(t5,t4))))),t0);
+(t1,((t5,t4),((t27,(((t16,(((t14,t15),((t25,t24),(t11,(((t6,t7),t8),(t9,t10))))),(t12,t13))),(t23,((t17,t18),((t21,t22),(t19,t20))))),t26)),(t2,t3))),t0);
+(((t4,t5),((t27,t26),((((t24,t25),(t23,((t18,t17),((t19,t20),(t21,t22))))),((t13,t12),((t11,((t9,t10),(t8,(t7,t6)))),((t15,t14),t16)))),(t2,t3)))),t1,t0);
+(((((t27,t26),((t23,((t18,t17),((t19,t20),(t21,t22)))),(((t13,t12),(((t24,t25),(t11,((t9,t10),(t8,(t7,t6))))),(t15,t14))),t16))),(t2,t3)),(t4,t5)),t1,t0);
+(((t2,t3),((t4,t5),((t27,t26),((t23,((t18,t17),((t19,t20),(t21,t22)))),((((t24,t25),((t13,t12),(t11,((t9,t10),(t8,(t7,t6)))))),(t15,t14)),t16))))),t1,t0);
+((((t2,t3),(((t23,((t18,t17),((t19,t20),(t21,t22)))),(t24,t25)),(((t13,t12),(t11,((t9,t10),(t8,(t7,t6))))),((t15,t14),t16)))),((t4,t5),(t27,t26))),t1,t0);
+((((t2,t3),((t23,((t18,t17),((t19,t20),(t21,t22)))),((((t24,t25),(t13,t12)),(t11,((t9,t10),(t8,(t7,t6))))),((t15,t14),t16)))),((t4,t5),(t27,t26))),t1,t0);
+((((t23,((t18,t17),((t19,t20),(t21,t22)))),(((t24,t25),(t13,t12)),((t11,((t9,t10),(t8,(t7,t6)))),((t15,t14),t16)))),(((t4,t5),(t27,t26)),(t2,t3))),t1,t0);
+(((t4,t5),(((((t13,t12),t16),((t11,((t9,t10),(t8,(t7,t6)))),(t15,t14))),((t23,((t18,t17),((t19,t20),(t21,t22)))),(t24,t25))),((t2,t3),(t27,t26)))),t1,t0);
+(((t2,t3),(t27,((((t23,((t18,t17),((t19,t20),(t21,t22)))),(((t15,t14),((t24,t25),(t11,((t9,t10),(t8,(t7,t6)))))),((t13,t12),t16))),t26),(t4,t5)))),t1,t0);
+(((t4,t5),((t2,t3),((t26,t27),((t23,((t18,t17),((t19,t20),(t21,t22)))),((t16,(t15,t14)),(((t24,t25),(t11,((t9,t10),(t8,(t7,t6))))),(t13,t12))))))),t1,t0);
+(((t4,t5),((t2,t3),((t26,t27),(((t24,t25),(t23,((t18,t17),((t19,t20),(t21,t22))))),((t16,(t15,t14)),((t11,((t9,t10),(t8,(t7,t6)))),(t13,t12))))))),t1,t0);
+(t1,((t5,t4),((t3,t2),((t26,t27),((((((t9,t10),(t8,(t6,t7))),t11),((t25,t24),(t13,t12))),((t15,t14),t16)),(((t18,t17),((t21,t22),(t19,t20))),t23))))),t0);
+(t1,((t3,t2),(((t26,t27),((((t25,t24),(t13,t12)),(((t15,t14),t16),(((t9,t10),(t8,(t6,t7))),t11))),(((t18,t17),((t21,t22),(t19,t20))),t23))),(t5,t4))),t0);
+(t1,(((t26,t27),(((t25,t24),(((((t9,t10),(t8,(t6,t7))),t11),(t13,t12)),(t16,(t15,t14)))),(((t18,t17),((t21,t22),(t19,t20))),t23))),((t5,t4),(t3,t2))),t0);
+(t1,((t3,t2),(((t26,t27),(((t25,t24),(((((t9,t10),(t8,(t6,t7))),t11),(t13,t12)),(t16,(t15,t14)))),((t22,(((t19,t20),t21),(t18,t17))),t23))),(t5,t4))),t0);
+(t1,((((t3,t2),(t26,t27)),((t16,((t15,t14),((((t9,t10),(t8,(t6,t7))),t11),((t25,t24),(t13,t12))))),((((t19,t20),(t22,t21)),(t18,t17)),t23))),(t5,t4)),t0);
+(t1,(((t3,t2),((t26,t27),(((t15,t14),(t16,((t13,t12),((t25,t24),(((t9,t10),(t8,(t6,t7))),t11))))),((((t19,t20),(t22,t21)),(t18,t17)),t23)))),(t5,t4)),t0);
+(t1,(((t3,t2),((t26,t27),((((t15,t14),((t13,t12),((t25,t24),(((t9,t10),(t8,(t6,t7))),t11)))),((((t19,t20),(t22,t21)),(t18,t17)),t23)),t16))),(t5,t4)),t0);
+(t1,((((t3,t2),(t26,t27)),(((((t9,t10),(t8,(t6,t7))),t11),((t16,(t15,t14)),(t13,t12))),((t25,t24),(t23,(((t19,t20),(t22,t21)),(t18,t17)))))),(t5,t4)),t0);
+(t1,(((t3,t2),((t26,t27),(((((t13,t12),t16),(t15,t14)),(((t9,t10),(t8,(t6,t7))),t11)),((t25,t24),(t23,((t19,t20),((t22,t21),(t18,t17)))))))),(t5,t4)),t0);
+(t1,(((t26,t27),((t23,((t18,t17),((t19,t20),(t22,t21)))),((((t13,t12),(t25,t24)),((t15,t14),(((t9,t10),(t8,(t6,t7))),t11))),t16))),((t5,t4),(t3,t2))),t0);
+(t1,(((((t24,t25),(t23,(((t21,t22),(t20,t19)),(t18,t17)))),((t16,(t15,t14)),((t11,(((t6,t7),t8),(t9,t10))),(t13,t12)))),(t27,t26)),((t2,t3),(t4,t5))),t0);
+(t1,(((t4,t5),(t27,t26)),((t2,t3),(((t24,t25),(t23,(((t21,t22),(t20,t19)),(t18,t17)))),((t11,(((t6,t7),t8),(t9,t10))),((t16,(t13,t12)),(t15,t14)))))),t0);
+(t1,((((t23,((((t21,t22),(t20,t19)),(t18,t17)),(t24,t25))),((t16,(t13,t12)),((t15,t14),(t11,(((t6,t7),t8),(t9,t10)))))),((t27,t26),(t2,t3))),(t4,t5)),t0);
+(t1,((t2,t3),((((t23,(((t21,t22),(t20,t19)),(t18,t17))),(((t24,t25),(t11,(((t6,t7),t8),(t9,t10)))),((t16,(t13,t12)),(t15,t14)))),(t27,t26)),(t4,t5))),t0);
+(t1,((t2,t3),((t26,((t4,t5),((t23,(((t21,t22),(t20,t19)),(t18,t17))),((t16,(t15,t14)),((t11,(((t6,t7),t8),(t9,t10))),((t24,t25),(t13,t12))))))),t27)),t0);
+(t1,(((t4,t5),((t23,(((t21,t22),(t20,t19)),(t18,t17))),((t16,(t15,t14)),((t11,(((t6,t7),t8),(t9,t10))),((t24,t25),(t13,t12)))))),((t2,t3),(t27,t26))),t0);
+(t1,(((t4,t5),(((t23,((((t21,t22),(t20,t19)),(t18,t17)),(t24,t25))),(((t13,t12),t16),((t15,t14),(t11,(((t6,t7),t8),(t9,t10)))))),(t27,t26))),(t2,t3)),t0);
+(t1,(((((t24,t25),(t23,(((t21,t22),(t20,t19)),(t18,t17)))),(((t13,t12),t16),((t15,t14),(t11,(((t6,t7),t8),(t9,t10)))))),(t27,t26)),((t2,t3),(t4,t5))),t0);
+(t1,((((t24,t25),(t23,(((t21,t22),(t20,t19)),(t18,t17)))),((t13,t12),((t16,(t15,t14)),(t11,(((t6,t7),t8),(t9,t10)))))),(((t27,t26),(t4,t5)),(t2,t3))),t0);
+(t1,(((t4,t5),((t27,t26),(((t24,t25),((t18,t17),(t23,((t21,t22),(t20,t19))))),(((t13,t12),t16),((t15,t14),(t11,(((t6,t7),t8),(t9,t10)))))))),(t2,t3)),t0);
+(((t2,t3),((t5,t4),((t27,t26),(((t15,t14),(((t25,t24),(t23,(((t20,t19),(t21,t22)),(t17,t18)))),((t13,t12),(t11,((t9,t10),((t7,t6),t8)))))),t16)))),t1,t0);
+((((t27,t26),(((t23,(((t20,t19),(t21,t22)),(t17,t18))),(((t25,t24),(t13,t12)),(t11,((t9,t10),((t7,t6),t8))))),(t16,(t15,t14)))),((t2,t3),(t5,t4))),t1,t0);
+((((((t25,t24),(t23,(((t20,t19),(t21,t22)),(t17,t18)))),((t15,t14),((t16,(t13,t12)),(t11,((t9,t10),((t7,t6),t8)))))),((t27,t26),(t2,t3))),(t5,t4)),t1,t0);
+((((t27,t26),((t2,t3),((t23,(((t20,t19),(t21,t22)),(t17,t18))),(t16,(((t15,t14),(t13,t12)),((t25,t24),(t11,((t9,t10),((t7,t6),t8))))))))),(t5,t4)),t1,t0);
+(((t2,t3),((((t23,(((t20,t19),(t21,t22)),(t17,t18))),((t16,(t13,t12)),(((t25,t24),(t11,((t9,t10),((t7,t6),t8)))),(t15,t14)))),(t27,t26)),(t5,t4))),t1,t0);
+(((t2,t3),((((t23,(((t20,t19),(t21,t22)),(t17,t18))),(((t25,t24),(t11,((t9,t10),((t7,t6),t8)))),((t15,t14),(t16,(t13,t12))))),(t27,t26)),(t5,t4))),t1,t0);
+(((t2,t3),((((t23,((t25,t24),(((t20,t19),(t21,t22)),(t17,t18)))),(((t11,((t9,t10),((t7,t6),t8))),((t15,t14),(t13,t12))),t16)),(t27,t26)),(t5,t4))),t1,t0);
+(((((t25,t24),((((t20,t19),(t21,t22)),(t17,t18)),t23)),(((t15,t14),t16),((t13,t12),(t11,((t9,t10),((t7,t6),t8)))))),((t27,((t5,t4),t26)),(t2,t3))),t1,t0);
+(((t2,t3),(((((((t20,t19),(t21,t22)),(t17,t18)),t23),(t16,(((t25,t24),(t11,((t9,t10),((t7,t6),t8)))),((t15,t14),(t13,t12))))),(t26,t27)),(t5,t4))),t1,t0);
+(((((((t22,((t20,t19),t21)),(t17,t18)),t23),(((t11,((t9,t10),((t7,t6),t8))),((t13,t12),(t25,t24))),((t15,t14),t16))),((t2,t3),(t26,t27))),(t5,t4)),t1,t0);
+(((((t27,t26),(t5,t4)),(((t24,t25),(t23,((t18,t17),((t21,t22),(t19,t20))))),(((t13,t12),t16),((t15,t14),(((t9,t10),((t6,t7),t8)),t11))))),(t3,t2)),t1,t0);
+((((t5,t4),((((t24,t25),(t23,((t18,t17),((t21,t22),(t19,t20))))),(((t13,t12),t16),((t15,t14),(((t9,t10),((t6,t7),t8)),t11)))),(t27,t26))),(t3,t2)),t1,t0);
+(((((t23,((t18,t17),((t21,t22),(t19,t20)))),(((t16,(t15,t14)),(((t9,t10),((t6,t7),t8)),t11)),((t13,t12),(t24,t25)))),((t27,t26),(t5,t4))),(t3,t2)),t1,t0);
+(((((t5,t4),(((t23,((t18,t17),((t21,t22),(t19,t20)))),(((t15,t14),((((t9,t10),((t6,t7),t8)),t11),(t24,t25))),(t16,(t13,t12)))),t26)),(t3,t2)),t27),t1,t0);
+(((((t23,((t18,t17),((t21,t22),(t19,t20)))),((t16,(t15,t14)),(((t13,t12),(((t9,t10),((t6,t7),t8)),t11)),(t24,t25)))),((t27,t26),(t5,t4))),(t3,t2)),t1,t0);
+((((t3,t2),(t5,t4)),(t27,(((t23,((t18,t17),((t21,t22),(t19,t20)))),((((t13,t12),(((t9,t10),((t6,t7),t8)),t11)),((t15,t14),t16)),(t24,t25))),t26))),t1,t0);
+(((t3,t2),((t5,t4),(((t23,((t18,t17),((t21,t22),(t19,t20)))),((((t13,t12),(((t9,t10),((t6,t7),t8)),t11)),((t15,t14),t16)),(t24,t25))),(t26,t27)))),t1,t0);
+(((t5,t4),((((t23,((t18,t17),((t21,t22),(t19,t20)))),(((t15,t14),t16),(((t24,t25),(t13,t12)),(((t9,t10),((t6,t7),t8)),t11)))),(t26,t27)),(t3,t2))),t1,t0);
+(((t5,t4),((((((t9,t10),((t6,t7),t8)),t11),((t15,t14),(t16,(t13,t12)))),((t24,t25),(t23,((t18,t17),((t21,t22),(t19,t20)))))),((t3,t2),(t26,t27)))),t1,t0);
+(((((t23,((t19,t20),((t18,t17),(t21,t22)))),((t13,t12),((t24,t25),((t15,t14),(((t9,t10),((t6,t7),t8)),t11))))),t16),((t3,t2),((t5,t4),(t26,t27)))),t1,t0);
+((((t4,t5),(t26,t27)),((t2,t3),(((t15,t14),((t23,(((t22,t21),(t19,t20)),(t18,t17))),((t11,((t8,(t7,t6)),(t9,t10))),((t24,t25),(t13,t12))))),t16))),t1,t0);
+(((t2,t3),((t4,t5),((t26,t27),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(((t11,((t8,(t7,t6)),(t9,t10))),((t24,t25),(t13,t12))),(t16,(t15,t14))))))),t1,t0);
+(((t4,t5),(((t26,t27),(((t23,(((t22,t21),(t19,t20)),(t18,t17))),((t24,t25),(((t13,t12),(t11,((t8,(t7,t6)),(t9,t10)))),(t15,t14)))),t16)),(t2,t3))),t1,t0);
+(((t4,t5),((t26,t27),((t2,t3),(((t11,((t8,(t7,t6)),(t9,t10))),((t16,(t15,t14)),(t13,t12))),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t24,t25)))))),t1,t0);
+(((t4,t5),((t26,t27),((t2,t3),(((((t13,t12),(t11,((t8,(t7,t6)),(t9,t10)))),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t24,t25))),(t15,t14)),t16)))),t1,t0);
+(((t4,t5),((t26,t27),((t2,t3),(((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t24,t25)),(((t11,((t8,(t7,t6)),(t9,t10))),(t15,t14)),(t16,(t13,t12))))))),t1,t0);
+(((t2,t3),((t4,t5),((((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t24,t25)),((((t13,t12),(t11,((t8,(t7,t6)),(t9,t10)))),(t15,t14)),t16)),(t26,t27)))),t1,t0);
+(((t2,t3),((t4,t5),(((t23,((((t22,t21),(t19,t20)),(t18,t17)),(t24,t25))),(((t13,t12),(t11,((t8,(t7,t6)),(t9,t10)))),((t15,t14),t16))),(t26,t27)))),t1,t0);
+(((t4,t5),(((t23,(((t22,t21),(t19,t20)),(t18,t17))),(((t15,t14),((t24,t25),(t11,((t8,(t7,t6)),(t9,t10))))),(t16,(t13,t12)))),((t2,t3),(t26,t27)))),t1,t0);
+((((t26,t27),(t4,t5)),((((t24,t25),(t23,(((t22,t21),(t19,t20)),(t18,t17)))),((t16,(t15,t14)),((t11,((t8,(t7,t6)),(t9,t10))),(t13,t12)))),(t2,t3))),t1,t0);
+(t1,((t2,t3),((((t23,((t22,(t21,(t20,t19))),(t18,t17))),((t16,((t14,t15),((t12,t13),(((t9,t10),((t7,t6),t8)),t11)))),(t25,t24))),(t26,t27)),(t4,t5))),t0);
+(t1,((t2,t3),(((((t12,t13),((((t9,t10),((t7,t6),t8)),t11),((t14,t15),t16))),((t25,t24),(t23,(((t20,t19),(t22,t21)),(t18,t17))))),(t26,t27)),(t4,t5))),t0);
+(t1,((t2,t3),((((((t14,t15),t16),((t12,t13),(((t9,t10),((t7,t6),t8)),t11))),((t25,t24),(t23,(((t20,t19),(t22,t21)),(t18,t17))))),(t26,t27)),(t4,t5))),t0);
+(t1,(((t14,t15),((((t12,t13),(((t9,t10),((t7,t6),t8)),t11)),t16),(t23,((((t20,t19),(t22,t21)),(t18,t17)),(t25,t24))))),(((t2,t3),(t26,t27)),(t4,t5))),t0);
+(t1,(((((t25,t24),(t23,(((t20,t19),(t22,t21)),(t18,t17)))),(((t14,t15),(t12,t13)),(((t9,t10),((t7,t6),t8)),t11))),t16),(((t26,t27),(t4,t5)),(t2,t3))),t0);
+(t1,(((((t23,(((t20,t19),(t22,t21)),(t18,t17))),((t14,t15),(((t12,t13),((t25,t24),(((t9,t10),((t7,t6),t8)),t11))),t16))),(t26,t27)),(t4,t5)),(t2,t3)),t0);
+(t1,((((t23,(((t20,t19),(t22,t21)),(t18,t17))),((((t14,t15),((t25,t24),(((t9,t10),((t7,t6),t8)),t11))),(t12,t13)),t16)),(t26,t27)),((t4,t5),(t2,t3))),t0);
+(t1,((t4,t5),((t26,t27),((t2,t3),((t23,(((t20,t19),(t22,t21)),(t18,t17))),(((t14,t15),(((t12,t13),(t25,t24)),(((t9,t10),((t7,t6),t8)),t11))),t16))))),t0);
+(t1,(((t2,t3),((t23,(((t20,t19),(t22,t21)),(t18,t17))),((((((t9,t10),((t7,t6),t8)),t11),(t12,t13)),(t16,(t14,t15))),(t25,t24)))),((t4,t5),(t26,t27))),t0);
+(t1,((((t2,t3),((t23,(((t20,t19),(t22,t21)),(t18,t17))),((t16,(t14,t15)),((t12,t13),((((t9,t10),((t7,t6),t8)),t11),(t25,t24)))))),((t4,t5),t27)),t26),t0);
+(t1,((t2,t3),(((((((t21,t22),(t19,t20)),(t18,t17)),t23),(t16,((((t25,t24),(t13,t12)),(t11,((t9,t10),((t7,t6),t8)))),(t15,t14)))),(t26,t27)),(t4,t5))),t0);
+(t1,((t2,t3),((t16,(((((((t21,t22),(t19,t20)),(t18,t17)),t23),(t25,t24)),((t13,t12),(t11,((t9,t10),((t7,t6),t8))))),(t15,t14))),((t4,t5),(t26,t27)))),t0);
+(t1,((t2,t3),((t26,((((((t21,t22),(t19,t20)),(t18,t17)),t23),(((t13,t12),((t25,t24),(t11,((t9,t10),((t7,t6),t8))))),((t15,t14),t16))),(t4,t5))),t27)),t0);
+(t1,((t2,t3),((t4,t5),((t27,t26),(((t25,t24),((((t21,t22),(t19,t20)),(t18,t17)),t23)),(((t11,((t9,t10),((t7,t6),t8))),(t13,t12)),((t15,t14),t16)))))),t0);
+(t1,((t2,t3),((t4,t5),((t27,t26),(((t25,t24),((((t21,t22),(t19,t20)),(t18,t17)),t23)),(((t11,((t9,t10),((t7,t6),t8))),(t16,(t13,t12))),(t15,t14)))))),t0);
+(t1,((((t25,t24),((((t21,t22),(t19,t20)),(t18,t17)),t23)),((t11,((t9,t10),((t7,t6),t8))),((t13,t12),(t16,(t15,t14))))),((t4,t5),((t2,t3),(t27,t26)))),t0);
+(t1,(((t2,t3),(t27,t26)),((((t25,t24),((((t21,t22),(t19,t20)),(t18,t17)),t23)),((t13,t12),((t16,(t15,t14)),(t11,((t9,t10),((t7,t6),t8)))))),(t4,t5))),t0);
+(t1,((t2,t3),(((t27,t26),((((t21,(t22,(t19,t20))),(t18,t17)),t23),(((t25,t24),(t13,t12)),((t16,(t15,t14)),(t11,((t9,t10),((t7,t6),t8))))))),(t4,t5))),t0);
+(t1,((((t2,t3),(t27,t26)),((((t21,(t22,(t19,t20))),(t18,t17)),t23),((t16,(t15,t14)),((t11,((t9,t10),((t7,t6),t8))),((t25,t24),(t13,t12)))))),(t4,t5)),t0);
+(t1,(((t27,t26),(((t25,t24),((((t19,t20),(t21,t22)),(t18,t17)),t23)),((t16,(t15,t14)),((t11,((t9,t10),((t7,t6),t8))),(t13,t12))))),((t4,t5),(t2,t3))),t0);
+(((t3,t2),((((t5,t4),t26),((t23,((t18,t17),((t20,t19),(t21,t22)))),((t16,(t25,t24)),(((((t8,(t6,t7)),(t10,t9)),t11),(t12,t13)),(t14,t15))))),t27)),t1,t0);
+((((t5,t4),(t26,t27)),((t3,t2),(((((t8,(t6,t7)),(t10,t9)),t11),((t12,t13),(t16,(t14,t15)))),((t23,((t18,t17),((t20,t19),(t21,t22)))),(t25,t24))))),t1,t0);
+(((t3,t2),(((((t14,t15),(((((t8,(t6,t7)),(t10,t9)),t11),(t12,t13)),((t23,((t18,t17),((t20,t19),(t21,t22)))),(t25,t24)))),t16),(t26,t27)),(t5,t4))),t1,t0);
+(((((t23,((t18,t17),((t20,t19),(t21,t22)))),((t16,((((t8,(t6,t7)),(t10,t9)),t11),(t14,t15))),((t12,t13),(t25,t24)))),(t26,t27)),((t5,t4),(t3,t2))),t1,t0);
+(((t3,t2),((((t23,((t18,t17),((t20,t19),(t21,t22)))),((((((t8,(t6,t7)),(t10,t9)),t11),(t25,t24)),((t12,t13),(t14,t15))),t16)),(t26,t27)),(t5,t4))),t1,t0);
+((((t3,t2),(t26,t27)),((t5,t4),(t16,((t23,((t18,t17),((t20,t19),(t21,t22)))),(((((t8,(t6,t7)),(t10,t9)),t11),(t25,t24)),((t12,t13),(t14,t15))))))),t1,t0);
+((((t5,t4),(((t23,((t18,t17),((t20,t19),(t21,t22)))),((t14,t15),((((((t8,(t6,t7)),(t10,t9)),t11),(t25,t24)),(t12,t13)),t16))),(t26,t27))),(t3,t2)),t1,t0);
+(((t5,t4),(((t23,((t18,t17),(t22,((t20,t19),t21)))),(((((t8,(t6,t7)),(t10,t9)),t11),((t25,t24),(t12,t13))),(t16,(t14,t15)))),((t3,t2),(t26,t27)))),t1,t0);
+(((t5,t4),((t3,t2),((t26,t27),((t16,(t14,t15)),(((t25,t24),(t23,((t18,t17),((t20,t19),(t21,t22))))),((((t8,(t6,t7)),(t10,t9)),t11),(t12,t13))))))),t1,t0);
+(((t3,t2),(((t26,t27),((t23,((t18,t17),((t20,t19),(t21,t22)))),((((t25,t24),(((t8,(t6,t7)),(t10,t9)),t11)),(t12,t13)),(t16,(t14,t15))))),(t5,t4))),t1,t0);
+(t1,(((((t24,t25),(t23,((t18,t17),((t22,t21),(t19,t20))))),(((t14,t15),t16),((t12,t13),(t11,((t10,t9),((t6,t7),t8)))))),(t26,t27)),((t5,t4),(t2,t3))),t0);
+(t1,(((t26,t27),(t2,t3)),(((t23,((t18,t17),((t22,t21),(t19,t20)))),(t16,(((t24,t25),(t12,t13)),((t11,((t10,t9),((t6,t7),t8))),(t14,t15))))),(t5,t4))),t0);
+(t1,(((t5,t4),((t26,t27),(((t23,((t18,t17),((t22,t21),(t19,t20)))),(t24,t25)),((t16,(t12,t13)),((t11,((t10,t9),((t6,t7),t8))),(t14,t15)))))),(t2,t3)),t0);
+(t1,(((((t23,((t18,t17),(t22,(t21,(t19,t20))))),(t24,t25)),(((t11,((t10,t9),((t6,t7),t8))),((t14,t15),(t12,t13))),t16)),((t5,t4),(t26,t27))),(t2,t3)),t0);
+(t1,((t5,t4),(((t2,t3),(t26,t27)),(t16,(((t23,((t18,t17),((t19,t20),(t22,t21)))),(t24,t25)),((t14,t15),((t12,t13),(t11,((t10,t9),((t6,t7),t8))))))))),t0);
+(t1,(((t23,((t21,(t18,t17)),((t19,t20),t22))),((t16,(t14,t15)),((t12,t13),((t24,t25),(t11,((t10,t9),((t6,t7),t8))))))),((t5,t4),((t2,t3),(t26,t27)))),t0);
+(t1,((t5,t4),((t2,t3),((t27,t26),(((t24,t25),(t23,((t18,t17),((t19,t20),(t21,t22))))),((t16,(t14,t15)),((t11,((t10,t9),((t6,t7),t8))),(t12,t13))))))),t0);
+(t1,((((t2,t3),(t27,t26)),((t23,((t18,t17),((t19,t20),(t21,t22)))),(((t24,t25),(t12,t13)),((t16,(t14,t15)),(t11,((t10,t9),((t6,t7),t8))))))),(t5,t4)),t0);
+(t1,(((t16,((t14,t15),(((t11,((t10,t9),((t6,t7),t8))),(t12,t13)),((t24,t25),(t23,((t18,t17),((t19,t20),(t21,t22)))))))),(t2,t3)),((t5,t4),(t27,t26))),t0);
+(t1,((t5,t4),(((t23,((t18,t17),((t19,t20),(t21,t22)))),((((t14,t15),((t11,((t10,t9),((t6,t7),t8))),(t24,t25))),(t12,t13)),t16)),((t2,t3),(t27,t26)))),t0);
+((((t27,t26),(((t23,((t18,t17),((t21,t22),(t20,t19)))),(t16,(((t24,t25),(((t9,t10),(t8,(t6,t7))),t11)),((t12,t13),(t15,t14))))),(t2,t3))),(t4,t5)),t1,t0);
+(((t2,t3),((t27,t26),((t4,t5),(((t24,t25),(t23,((t18,t17),((t21,t22),(t20,t19))))),(((t15,t14),t16),((((t9,t10),(t8,(t6,t7))),t11),(t12,t13))))))),t1,t0);
+(((t4,t5),(((t2,t3),((t23,((t18,t17),((t21,t22),(t20,t19)))),(((t15,t14),t16),((((t9,t10),(t8,(t6,t7))),t11),((t24,t25),(t12,t13)))))),(t27,t26))),t1,t0);
+(((t4,t5),((t2,t3),(((((t24,t25),t23),(((t18,t17),(t21,(t20,t19))),t22)),(((t15,t14),t16),((((t9,t10),(t8,(t6,t7))),t11),(t12,t13)))),(t27,t26)))),t1,t0);
+(((t2,t3),((((t24,t25),(t23,((t18,t17),((t20,t19),(t21,t22))))),((((t9,t10),(t8,(t6,t7))),t11),((t12,t13),((t15,t14),t16)))),((t4,t5),(t27,t26)))),t1,t0);
+(((t2,t3),(((((t18,t17),((t20,t19),(t21,t22))),t23),(((t15,t14),(t12,t13)),(t16,((t24,t25),(((t9,t10),(t8,(t6,t7))),t11))))),((t4,t5),(t27,t26)))),t1,t0);
+(((t4,t5),(((((t18,t17),((t20,t19),(t21,t22))),t23),(t16,(((t24,t25),((t12,t13),(((t9,t10),(t8,(t6,t7))),t11))),(t15,t14)))),((t2,t3),(t26,t27)))),t1,t0);
+(((t4,t5),((((((t18,t17),((t20,t19),(t21,t22))),t23),(t24,t25)),(t16,((((t9,t10),(t8,(t6,t7))),t11),((t12,t13),(t15,t14))))),((t2,t3),(t26,t27)))),t1,t0);
+(((t4,t5),((t2,t3),((t26,t27),(((t15,t14),(t16,((t12,t13),((t24,t25),(((t9,t10),(t8,(t6,t7))),t11))))),(t23,((t18,t17),((t20,t19),(t21,t22)))))))),t1,t0);
+((((t4,t5),(t26,t27)),((((((t9,t10),(t8,(t6,t7))),t11),((t16,(t12,t13)),(t15,t14))),((t24,t25),(t23,((t18,t17),((t20,t19),(t21,t22)))))),(t2,t3))),t1,t0);
+(t1,((t5,t4),((t26,t27),((((t25,t24),(t23,(((t22,t21),(t19,t20)),(t18,t17)))),((t16,(t15,t14)),((t12,t13),((((t7,t6),t8),(t9,t10)),t11)))),(t2,t3)))),t0);
+(t1,(((t16,((t15,t14),(((t12,t13),((((t7,t6),t8),(t9,t10)),t11)),((t25,t24),(t23,(((t22,t21),(t19,t20)),(t18,t17))))))),(t2,t3)),((t5,t4),(t26,t27))),t0);
+(t1,((t2,t3),(((t26,t27),(t16,((t23,(((t22,t21),(t19,t20)),(t18,t17))),(((t25,t24),(t12,t13)),((t15,t14),((((t7,t6),t8),(t9,t10)),t11)))))),(t5,t4))),t0);
+(t1,((t2,t3),((((t12,t13),(t16,((t15,t14),((((t7,t6),t8),(t9,t10)),t11)))),((((t22,t21),(t19,t20)),((t18,t17),t23)),(t25,t24))),((t26,t27),(t5,t4)))),t0);
+(t1,((((((((t7,t6),t8),(t9,t10)),t11),(t12,t13)),(t16,(t15,t14))),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t25,t24))),(((t26,t27),(t5,t4)),(t2,t3))),t0);
+(t1,(((((t12,t13),((t16,(t15,t14)),((((t7,t6),t8),(t9,t10)),t11))),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t25,t24))),((t2,t3),(t26,t27))),(t5,t4)),t0);
+(t1,(((t26,t27),((((t15,t14),(((((t7,t6),t8),(t9,t10)),t11),(t12,t13))),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t25,t24))),t16)),((t5,t4),(t2,t3))),t0);
+(t1,(((t26,t27),(((t16,(t15,t14)),(((((t7,t6),t8),(t9,t10)),t11),(t12,t13))),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t25,t24)))),((t5,t4),(t2,t3))),t0);
+(t1,((((t2,t3),(t26,t27)),((t23,(((t22,t21),(t19,t20)),(t18,t17))),((t25,t24),(((((t7,t6),t8),(t9,t10)),t11),(((t12,t13),t16),(t15,t14)))))),(t5,t4)),t0);
+(t1,((((t26,t27),((t23,(((t22,t21),(t19,t20)),(t18,t17))),(t16,((t15,t14),((t12,t13),((t25,t24),((((t7,t6),t8),(t9,t10)),t11))))))),(t5,t4)),(t2,t3)),t0);
+(t1,((t3,t2),(((t26,(((((t22,t21),(t19,t20)),(t17,t18)),t23),(((t24,t25),(t12,t13)),((((t8,(t6,t7)),(t9,t10)),t11),((t14,t15),t16))))),(t4,t5)),t27)),t0);
+(t1,((t4,t5),(((t26,t27),(t3,t2)),(((t14,t15),(((t24,t25),((((t22,t21),(t19,t20)),(t17,t18)),t23)),((t12,t13),(((t8,(t6,t7)),(t9,t10)),t11)))),t16))),t0);
+(t1,((t3,t2),(((t26,t27),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(((t24,t25),(((t8,(t6,t7)),(t9,t10)),t11)),(((t12,t13),t16),(t14,t15))))),(t4,t5))),t0);
+(t1,(((t26,t27),((t3,t2),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(((t24,t25),(t12,t13)),(((t14,t15),t16),(((t8,(t6,t7)),(t9,t10)),t11)))))),(t4,t5)),t0);
+(t1,(((((t14,t15),((((t24,t25),(((t8,(t6,t7)),(t9,t10)),t11)),(t12,t13)),((((t22,t21),(t19,t20)),(t17,t18)),t23))),t16),((t26,t27),(t3,t2))),(t4,t5)),t0);
+(t1,((t3,t2),((((t24,t25),((((t22,t21),(t19,t20)),(t17,t18)),t23)),((t12,t13),((t16,(t14,t15)),(((t8,(t6,t7)),(t9,t10)),t11)))),((t4,t5),(t26,t27)))),t0);
+(t1,((t4,t5),(((t3,t2),(t26,t27)),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(((t24,t25),(t12,t13)),((t16,(t14,t15)),(((t8,(t6,t7)),(t9,t10)),t11)))))),t0);
+(t1,((t27,((t3,t2),t26)),((((t12,t13),((((t8,(t6,t7)),(t9,t10)),t11),(t16,(t14,t15)))),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(t24,t25))),(t4,t5))),t0);
+(t1,((t27,(t26,(((((t22,t21),(t19,t20)),(t17,t18)),t23),((t24,t25),((t16,(t14,t15)),((t12,t13),(((t8,(t6,t7)),(t9,t10)),t11))))))),((t4,t5),(t3,t2))),t0);
+(t1,((t3,t2),((((((t24,t25),(((t22,t21),(t19,t20)),(t17,t18))),t23),(t16,((t14,t15),((t12,t13),(((t8,(t6,t7)),(t9,t10)),t11))))),(t27,t26)),(t4,t5))),t0);
+((((t26,((t5,t4),(t3,t2))),t27),(((t16,(t14,t15)),(((t24,t25),(t13,t12)),(t11,((t8,(t6,t7)),(t9,t10))))),(((t18,t17),((t19,t20),(t22,t21))),t23))),t1,t0);
+(((t3,t2),(((t27,t26),(t5,t4)),(((t13,t12),((t16,(t14,t15)),(t11,((t8,(t6,t7)),(t9,t10))))),((t24,t25),(((t18,t17),((t19,t20),(t22,t21))),t23))))),t1,t0);
+(((t3,t2),((t5,t4),(((((t18,t17),((t19,t20),(t22,t21))),t23),((t16,(t14,t15)),(((t24,t25),(t11,((t8,(t6,t7)),(t9,t10)))),(t13,t12)))),(t27,t26)))),t1,t0);
+(((t5,t4),((((((t18,t17),((t19,t20),(t22,t21))),t23),(((t13,t12),(t24,t25)),((t16,(t14,t15)),(t11,((t8,(t6,t7)),(t9,t10)))))),(t27,t26)),(t3,t2))),t1,t0);
+(((((((t18,t17),((t19,t20),(t22,t21))),t23),((((t14,t15),((t11,((t8,(t6,t7)),(t9,t10))),(t24,t25))),(t13,t12)),t16)),(t27,t26)),((t3,t2),(t5,t4))),t1,t0);
+((((t3,t2),((((t18,t17),((t19,t20),(t22,t21))),t23),((t24,t25),(((t14,t15),(t11,((t8,(t6,t7)),(t9,t10)))),((t13,t12),t16))))),((t27,t26),(t5,t4))),t1,t0);
+((((t27,t26),(((t16,(t14,t15)),(((t24,t25),(t11,((t8,(t6,t7)),(t9,t10)))),(t13,t12))),(((t18,t17),((t19,t20),(t22,t21))),t23))),((t5,t4),(t3,t2))),t1,t0);
+(((((t11,((t8,(t6,t7)),(t9,t10))),(((t13,t12),t16),(t14,t15))),(((t18,t17),((t19,t20),(t22,t21))),((t24,t25),t23))),(((t3,t2),(t27,t26)),(t5,t4))),t1,t0);
+(((((t14,t15),t16),(((t24,t25),(t23,((t18,t17),((t19,t20),(t22,t21))))),((t13,t12),(t11,((t8,(t6,t7)),(t9,t10)))))),((t3,t2),((t27,t26),(t5,t4)))),t1,t0);
+(((t3,t2),(((((t24,t25),(t23,((t18,t17),((t19,t20),(t22,t21))))),(((t13,t12),(t11,((t8,(t6,t7)),(t9,t10)))),((t14,t15),t16))),(t27,t26)),(t5,t4))),t1,t0);
+(t1,((((((t11,((t10,t9),((t7,t6),t8))),(t12,t13)),(t16,(t14,t15))),((t24,t25),(((t21,(t20,t19)),((t18,t17),t22)),t23))),((t2,t3),(t27,t26))),(t4,t5)),t0);
+(t1,((t2,t3),(((t27,t26),(((((t24,t25),(t11,((t10,t9),((t7,t6),t8)))),(t12,t13)),(t16,(t14,t15))),((((t22,t21),(t20,t19)),(t18,t17)),t23))),(t4,t5))),t0);
+(t1,((t4,t5),(((t2,t3),(t27,t26)),(((t16,(t12,t13)),((t14,t15),(t11,((t10,t9),((t7,t6),t8))))),((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23))))),t0);
+(t1,(((t2,t3),(t4,t5)),((t27,t26),(((t16,(t14,t15)),((t11,((t10,t9),((t7,t6),t8))),(t12,t13))),((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23))))),t0);
+(t1,((t4,t5),(((((t24,t25),(t12,t13)),((t16,(t14,t15)),(t11,((t10,t9),((t7,t6),t8))))),((((t22,t21),(t20,t19)),(t18,t17)),t23)),((t2,t3),(t27,t26)))),t0);
+(t1,((t2,t3),((t4,t5),((t27,t26),(((t16,((t12,t13),(t14,t15))),(t11,((t10,t9),((t7,t6),t8)))),((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23)))))),t0);
+(t1,(((((t11,((t10,t9),((t7,t6),t8))),(t12,t13)),(t16,(t14,t15))),((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23))),((t4,t5),((t2,t3),(t27,t26)))),t0);
+(t1,((t2,t3),(((t27,t26),((((t16,(t12,t13)),(t11,((t10,t9),((t7,t6),t8)))),(t14,t15)),((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23)))),(t4,t5))),t0);
+(t1,(((t2,t3),((((t11,((t10,t9),((t7,t6),t8))),(t12,t13)),((t14,t15),t16)),((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23)))),((t4,t5),(t27,t26))),t0);
+(t1,((t2,t3),(((((t16,(t12,t13)),((t14,t15),(t11,((t10,t9),((t7,t6),t8))))),((((t22,t21),(t20,t19)),(t18,t17)),(t23,(t24,t25)))),(t27,t26)),(t4,t5))),t0);
+(t1,((t4,t5),((t26,t27),((t3,t2),((((t18,t17),((t22,t21),(t20,t19))),t23),(t16,((t14,t15),((t24,t25),((t12,t13),((((t6,t7),t8),(t10,t9)),t11))))))))),t0);
+(t1,((t4,t5),(((((t18,t17),((t22,t21),(t20,t19))),t23),((t16,(t14,t15)),(((t24,t25),(t12,t13)),((((t6,t7),t8),(t10,t9)),t11)))),((t26,t27),(t3,t2)))),t0);
+(t1,((t3,t2),((((((t18,t17),((t22,t21),(t20,t19))),t23),(((t12,t13),t16),((t14,t15),(((((t6,t7),t8),(t10,t9)),t11),(t24,t25))))),(t26,t27)),(t4,t5))),t0);
+(t1,((((t3,t2),(((t24,t25),(((t18,t17),((t22,t21),(t20,t19))),t23)),(((t12,t13),t16),((t14,t15),((((t6,t7),t8),(t10,t9)),t11))))),(t26,(t4,t5))),t27),t0);
+(t1,((t4,t5),(((t3,t2),(((t14,t15),((((((t6,t7),t8),(t10,t9)),t11),(t12,t13)),((t24,t25),(((t18,t17),((t22,t21),(t20,t19))),t23)))),t16)),(t27,t26))),t0);
+(t1,(((t3,t2),(((t24,t25),(((t18,t17),((t22,t21),(t20,t19))),t23)),((t16,((t14,t15),((((t6,t7),t8),(t10,t9)),t11))),(t12,t13)))),((t27,t26),(t4,t5))),t0);
+(t1,((t4,t5),(((t3,t2),((((t24,t25),(((t20,t19),((t18,t17),(t22,t21))),t23)),(((((t6,t7),t8),(t10,t9)),t11),(t12,t13))),(t16,(t14,t15)))),(t27,t26))),t0);
+(t1,((t3,t2),((t4,t5),(((((t18,t17),((t22,t21),(t20,t19))),t23),((((t14,t15),((((t6,t7),t8),(t10,t9)),t11)),((t24,t25),(t12,t13))),t16)),(t27,t26)))),t0);
+(t1,((t3,t2),((t4,t5),((((t24,t25),(((t18,t17),((t22,t21),(t20,t19))),t23)),((t16,(t14,t15)),(((((t6,t7),t8),(t10,t9)),t11),(t12,t13)))),(t27,t26)))),t0);
+(t1,((t4,t5),((((((t18,t17),((t22,t21),(t20,t19))),t23),(((t24,t25),(t12,t13)),((t14,t15),(((((t6,t7),t8),(t10,t9)),t11),t16)))),(t27,t26)),(t3,t2))),t0);
+((((t27,t26),(((((t24,t25),t23),((t17,t18),((t21,t22),(t19,t20)))),((t16,(t14,t15)),((t12,t13),(t11,((t9,t10),(t8,(t6,t7))))))),(t3,t2))),(t5,t4)),t1,t0);
+(((t5,t4),(((t27,t26),(t3,t2)),((((t14,t15),(((t24,t25),(t12,t13)),(t11,((t9,t10),(t8,(t6,t7)))))),(t23,((t17,t18),((t21,t22),(t19,t20))))),t16))),t1,t0);
+((((t27,t26),(t3,t2)),((((t16,(t14,t15)),((t12,t13),(t11,((t9,t10),(t8,(t6,t7)))))),((t24,t25),(t23,((t17,t18),((t21,t22),(t19,t20)))))),(t5,t4))),t1,t0);
+((((t27,t26),(t3,t2)),((((t16,((t12,t13),(t14,t15))),(t11,((t9,t10),(t8,(t6,t7))))),((t24,t25),(t23,((t17,t18),((t21,t22),(t19,t20)))))),(t5,t4))),t1,t0);
+(((t27,(t3,t2)),((t26,((t16,((t12,t13),((t14,t15),((t24,t25),(t11,((t9,t10),(t8,(t6,t7)))))))),(t23,((t17,t18),((t21,t22),(t19,t20)))))),(t5,t4))),t1,t0);
+(((((t16,(((t12,t13),(t11,((t9,t10),(t8,(t6,t7))))),(t14,t15))),(t23,((t24,t25),((t17,t18),((t21,t22),(t19,t20)))))),(t3,t2)),((t26,t27),(t5,t4))),t1,t0);
+(((((((t24,t25),(t12,t13)),((t11,((t9,t10),(t8,(t6,t7)))),((t14,t15),t16))),(t23,(((t21,t22),(t19,t20)),(t17,t18)))),(t26,t27)),((t5,t4),(t3,t2))),t1,t0);
+((((((t14,t15),t16),((t12,t13),(t11,((t9,t10),(t8,(t6,t7)))))),((t24,t25),(t23,(((t21,t22),(t19,t20)),(t17,t18))))),((t26,t27),((t5,t4),(t3,t2)))),t1,t0);
+(((t3,t2),(((((t12,t13),((t11,((t9,t10),(t8,(t6,t7)))),((t14,t15),t16))),((t24,t25),(t23,(((t21,t22),(t19,t20)),(t17,t18))))),(t26,t27)),(t5,t4))),t1,t0);
+(((((((t14,t15),t16),(((t24,t25),(t12,t13)),(t11,((t9,t10),(t8,(t6,t7)))))),(t23,(((t21,t22),(t19,t20)),(t17,t18)))),((t3,t2),(t26,t27))),(t5,t4)),t1,t0);
+(((t4,t5),((t27,t26),(((t16,(((t13,t12),(t14,t15)),((t24,t25),(t11,((t10,t9),(t8,(t6,t7))))))),(((t20,t19),((t22,t21),(t18,t17))),t23)),(t2,t3)))),t1,t0);
+(((t16,((t14,t15),(((t11,((t10,t9),(t8,(t6,t7)))),(t13,t12)),((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23))))),(((t4,t5),(t2,t3)),(t27,t26))),t1,t0);
+((((t4,t5),(t2,t3)),(t27,((((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23)),((t13,t12),((t16,(t14,t15)),(t11,((t10,t9),(t8,(t6,t7))))))),t26))),t1,t0);
+((((t4,t5),(((((t22,t21),(t20,t19)),(t18,t17)),(t23,(t24,t25))),((((t13,t12),t16),(t14,t15)),(t11,((t10,t9),(t8,(t6,t7))))))),((t26,t27),(t2,t3))),t1,t0);
+(((t4,t5),((((((t22,t21),(t20,t19)),(t18,t17)),(t23,(t24,t25))),(((t11,((t10,t9),(t8,(t6,t7)))),(t13,t12)),(t16,(t14,t15)))),(t27,((t2,t3),t26)))),t1,t0);
+((((t4,t5),((((((t22,t21),(t20,t19)),(t18,t17)),t23),((t14,t15),(((t24,t25),((t11,((t10,t9),(t8,(t6,t7)))),(t13,t12))),t16))),(t26,t27))),(t2,t3)),t1,t0);
+((((((((t22,t21),(t20,t19)),(t18,t17)),t23),((t14,t15),((t11,((t10,t9),(t8,(t6,t7)))),((t13,t12),(t24,t25))))),t16),((t2,t3),((t4,t5),(t26,t27)))),t1,t0);
+((((t2,t3),(t26,t27)),((t4,t5),((((((t22,t21),(t20,t19)),(t18,t17)),t23),((t13,t12),((t14,t15),((t24,t25),(t11,((t10,t9),(t8,(t6,t7)))))))),t16))),t1,t0);
+(((t4,t5),((((((t22,t21),(t20,t19)),(t18,t17)),t23),(t16,((t13,t12),(((t24,t25),(t11,((t10,t9),(t8,(t6,t7))))),(t14,t15))))),((t2,t3),(t26,t27)))),t1,t0);
+(((t2,t3),((((t4,t5),t26),t27),(((t24,t25),((((t22,t21),(t20,t19)),(t18,t17)),t23)),((t11,((t10,t9),(t8,(t6,t7)))),(((t13,t12),t16),(t14,t15)))))),t1,t0);
+(t1,((t2,t3),(((t26,t27),((((t13,t12),(t11,((t8,(t7,t6)),(t10,t9)))),(t16,(t14,t15))),(((t25,t24),(((t22,t21),(t20,t19)),(t18,t17))),t23))),(t5,t4))),t0);
+(t1,((t2,t3),(((t26,t27),((((t14,t15),((t11,((t8,(t7,t6)),(t10,t9))),((t25,t24),(t13,t12)))),t16),(((t18,t17),((t22,t21),(t20,t19))),t23))),(t5,t4))),t0);
+(t1,((((t2,t3),(t26,t27)),((((t14,t15),((t13,t12),((t11,((t8,(t7,t6)),(t10,t9))),(t25,t24)))),t16),(((t18,t17),((t22,t21),(t20,t19))),t23))),(t5,t4)),t0);
+(t1,(((t26,t27),((((((t11,((t8,(t7,t6)),(t10,t9))),(t25,t24)),(t14,t15)),(t16,(t13,t12))),(((t18,t17),((t22,t21),(t20,t19))),t23)),(t2,t3))),(t5,t4)),t0);
+(t1,((((t26,t27),(((t14,t15),(t16,((t13,t12),(t11,((t8,(t7,t6)),(t10,t9)))))),(((t18,t17),((t22,t21),(t20,t19))),((t25,t24),t23)))),(t2,t3)),(t5,t4)),t0);
+(t1,((((t16,(((t13,t12),((t25,t24),(t11,((t8,(t7,t6)),(t10,t9))))),(t14,t15))),(((t18,t17),((t22,t21),(t20,t19))),t23)),((t2,t3),(t26,t27))),(t5,t4)),t0);
+(t1,(((t26,t27),((((t13,t12),(t11,((t8,(t7,t6)),(t10,t9)))),((t14,t15),t16)),((t25,t24),(((t18,t17),((t22,t21),(t20,t19))),t23)))),((t5,t4),(t2,t3))),t0);
+(t1,((t2,t3),((t27,(((((t18,t17),((t22,t21),(t20,t19))),t23),((((t13,t12),(t11,((t8,(t7,t6)),(t10,t9)))),((t14,t15),t16)),(t25,t24))),t26)),(t5,t4))),t0);
+(t1,(((t2,t3),(((t14,t15),(((t25,t24),(((t18,t17),((t22,t21),(t20,t19))),t23)),((t13,t12),(t11,((t8,(t7,t6)),(t10,t9)))))),t16)),((t26,t27),(t5,t4))),t0);
+(t1,(((t26,t27),(((t25,t24),(((t18,t17),((t22,t21),(t20,t19))),t23)),((t13,t12),((t16,(t14,t15)),(t11,((t8,(t7,t6)),(t10,t9))))))),((t5,t4),(t2,t3))),t0);
+(t1,((t2,t3),(((t26,t27),(t5,t4)),((((t24,t25),(t12,t13)),((t11,((t8,(t7,t6)),(t10,t9))),(t16,(t15,t14)))),(t23,((t18,t17),((t22,t21),(t19,t20))))))),t0);
+(t1,((t5,t4),((t2,t3),(((((t12,t13),(((t11,((t8,(t7,t6)),(t10,t9))),(t24,t25)),(t15,t14))),t16),(t23,((t18,t17),((t22,t21),(t19,t20))))),(t26,t27)))),t0);
+(t1,((t2,t3),((((((t15,t14),t16),((t12,t13),(t11,((t8,(t7,t6)),(t10,t9))))),((t23,((t18,t17),((t22,t21),(t19,t20)))),(t24,t25))),(t26,t27)),(t5,t4))),t0);
+(t1,((t16,((((t12,t13),(t11,((t8,(t7,t6)),(t10,t9)))),((t23,((t18,t17),((t22,t21),(t19,t20)))),(t24,t25))),(t15,t14))),((t5,t4),((t26,t27),(t2,t3)))),t0);
+(t1,((t5,t4),((((t23,((t18,t17),((t22,t21),(t19,t20)))),((t24,t25),(((t15,t14),t16),((t12,t13),(t11,((t8,(t7,t6)),(t10,t9))))))),(t26,t27)),(t2,t3))),t0);
+(t1,((t2,t3),((t5,t4),((((t16,(t15,t14)),((t12,t13),((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))))),(t23,((t18,t17),((t22,t21),(t19,t20))))),(t26,t27)))),t0);
+(t1,((t5,t4),((t26,t27),((t2,t3),(((t16,((t11,((t8,(t7,t6)),(t10,t9))),(t15,t14))),((t12,t13),(t24,t25))),(t23,((t18,t17),((t22,t21),(t19,t20)))))))),t0);
+(t1,(t27,(((t2,t3),(t26,((((t11,((t8,(t7,t6)),(t10,t9))),((t15,t14),(t12,t13))),t16),(((t24,t25),t23),((t18,t17),((t22,t21),(t19,t20))))))),(t5,t4))),t0);
+(t1,((t5,t4),(((t26,t27),(t2,t3)),(((t16,(t15,t14)),((t12,t13),((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))))),(t23,((t18,t17),((t22,t21),(t19,t20))))))),t0);
+(t1,((t5,t4),(((t26,t27),(t2,t3)),((((t24,t25),(t11,((t8,(t7,t6)),(t10,t9)))),((t15,t14),((t12,t13),t16))),(t23,((t18,t17),((t22,t21),(t19,t20))))))),t0);
+(t1,((t4,t5),((((t11,((t10,t9),(t8,(t6,t7)))),((t16,(t12,t13)),(t14,t15))),((t24,t25),(t23,((t18,t17),(t22,((t19,t20),t21)))))),((t2,t3),(t27,t26)))),t0);
+(t1,(((t4,t5),(t27,t26)),(((t16,((t14,t15),(((t24,t25),(t12,t13)),(t11,((t10,t9),(t8,(t6,t7))))))),(t23,(((t22,t21),(t18,t17)),(t19,t20)))),(t2,t3))),t0);
+(t1,((t2,t3),(((t27,t26),((((t12,t13),((t11,((t10,t9),(t8,(t6,t7)))),(t24,t25))),(t16,(t14,t15))),(t23,((t18,t17),((t19,t20),(t22,t21)))))),(t4,t5))),t0);
+(t1,((t2,t3),(((t27,t26),((((t11,((t10,t9),(t8,(t6,t7)))),((t24,t25),(t12,t13))),(t16,(t14,t15))),(t23,((t18,t17),((t19,t20),(t22,t21)))))),(t4,t5))),t0);
+(t1,((t2,t3),(((((t12,t13),((t11,((t10,t9),(t8,(t6,t7)))),(t24,t25))),(t16,(t14,t15))),(t23,((t18,t17),((t19,t20),(t22,t21))))),((t4,t5),(t27,t26)))),t0);
+(t1,((t4,t5),((t2,t3),((t27,t26),(((t12,t13),((t11,((t10,t9),(t8,(t6,t7)))),(t16,(t14,t15)))),((t24,t25),(t23,((t18,t17),((t19,t20),(t22,t21))))))))),t0);
+(t1,((((t2,t3),(t27,t26)),(((t12,t13),(t16,((t14,t15),(t11,((t10,t9),(t8,(t6,t7))))))),((t24,t25),((t18,t17),(((t19,t20),(t22,t21)),t23))))),(t4,t5)),t0);
+(t1,((((t2,t3),(t27,t26)),((((t18,t17),((t19,t20),(t22,t21))),(t23,(t24,t25))),((t11,((t10,t9),(t8,(t6,t7)))),(t16,((t12,t13),(t14,t15)))))),(t4,t5)),t0);
+(t1,((((t27,t26),((((t18,t17),((t19,t20),(t22,t21))),t23),(((t16,(t14,t15)),((t12,t13),(t11,((t10,t9),(t8,(t6,t7)))))),(t24,t25)))),(t4,t5)),(t2,t3)),t0);
+(t1,((t4,t5),((t2,t3),((t27,t26),(((t16,(t14,t15)),((t12,t13),(t11,((t10,t9),(t8,(t6,t7)))))),((t24,t25),(((t18,t17),((t19,t20),(t22,t21))),t23)))))),t0);
+(((t3,t2),(((t5,t4),(t26,t27)),(((t24,t25),(t23,((t19,t20),((t21,t22),(t18,t17))))),((t16,(t15,t14)),((t13,t12),(t11,((t10,t9),((t7,t6),t8)))))))),t1,t0);
+(((t5,t4),((t26,t27),((((t15,t14),(((t13,t12),(t11,((t10,t9),((t7,t6),t8)))),((t24,t25),(t23,(((t22,t21),(t19,t20)),(t18,t17)))))),t16),(t3,t2)))),t1,t0);
+((((t5,t4),(((t24,t25),(t23,(((t22,t21),(t19,t20)),(t18,t17)))),((t16,(t15,t14)),((t13,t12),(t11,((t10,t9),((t7,t6),t8))))))),((t26,t27),(t3,t2))),t1,t0);
+((((t5,t4),(t26,t27)),((t3,t2),((t23,(((t22,t21),(t19,t20)),(t18,t17))),((t16,(t15,t14)),(((t24,t25),(t13,t12)),(t11,((t10,t9),((t7,t6),t8)))))))),t1,t0);
+(((t5,t4),(((t26,t27),((t23,((t22,(t19,t20)),(t21,(t18,t17)))),(((t13,t12),t16),((t15,t14),((t11,((t10,t9),((t7,t6),t8))),(t24,t25)))))),(t3,t2))),t1,t0);
+(((t5,t4),((t26,t27),((((t24,t25),(t23,(((t21,t22),(t19,t20)),(t18,t17)))),((t16,(t15,t14)),((t11,((t10,t9),((t7,t6),t8))),(t13,t12)))),(t3,t2)))),t1,t0);
+((((t26,t27),(t3,t2)),((t5,t4),((t23,((t22,(t19,t20)),(t21,(t18,t17)))),((((t24,t25),(t11,((t10,t9),((t7,t6),t8)))),(t13,t12)),((t15,t14),t16))))),t1,t0);
+(((t5,t4),((t26,t27),((t3,t2),(((t24,t25),((((t21,t22),(t19,t20)),(t18,t17)),t23)),(((t13,t12),(t15,t14)),(t16,(t11,((t10,t9),((t7,t6),t8))))))))),t1,t0);
+((((t26,t27),(t3,t2)),(((((((t21,t22),(t19,t20)),(t18,t17)),t23),((t15,t14),((t11,((t10,t9),((t7,t6),t8))),((t13,t12),(t24,t25))))),t16),(t5,t4))),t1,t0);
+((((t26,t27),(t3,t2)),(((((((t21,t22),(t19,t20)),(t18,t17)),t23),((t24,t25),(((t13,t12),(t15,t14)),(t11,((t10,t9),((t7,t6),t8)))))),t16),(t5,t4))),t1,t0);
+(t1,((t3,t2),(((t26,t27),((t23,(((t20,t19),(t22,t21)),(t18,t17))),(((t12,t13),((t25,t24),(((t9,t10),((t6,t7),t8)),t11))),(t16,(t15,t14))))),(t4,t5))),t0);
+(t1,(((t26,t27),(((t25,t24),(t23,(((t20,t19),(t22,t21)),(t18,t17)))),((((t9,t10),((t6,t7),t8)),t11),((t16,(t15,t14)),(t12,t13))))),((t4,t5),(t3,t2))),t0);
+(t1,(((((t25,t24),(t23,(((t20,t19),(t22,t21)),(t18,t17)))),((t16,((t12,t13),(t15,t14))),(((t9,t10),((t6,t7),t8)),t11))),(t3,t2)),((t26,t27),(t4,t5))),t0);
+(t1,(((((t23,(((t20,t19),(t22,t21)),(t18,t17))),((t12,t13),((t25,t24),((t15,t14),(((t9,t10),((t6,t7),t8)),t11))))),t16),((t3,t2),(t26,t27))),(t4,t5)),t0);
+(t1,((t3,t2),((t26,(((t23,(((t20,t19),(t22,t21)),(t18,t17))),((t16,(t15,t14)),((((t9,t10),((t6,t7),t8)),t11),((t12,t13),(t25,t24))))),t27)),(t4,t5))),t0);
+(t1,((t27,(t3,t2)),((t26,((t23,(((t20,t19),(t22,t21)),(t18,t17))),((t16,(t15,t14)),((t25,t24),((((t9,t10),((t6,t7),t8)),t11),(t12,t13)))))),(t4,t5))),t0);
+(t1,((t4,t5),(((t26,t27),(t3,t2)),((((t16,(t15,t14)),(((t9,t10),((t6,t7),t8)),t11)),(t12,t13)),((t23,(((t20,t19),(t22,t21)),(t18,t17))),(t25,t24))))),t0);
+(t1,((t4,t5),((t26,t27),((t3,t2),((t23,(((t20,t19),(t22,t21)),(t18,t17))),(((t15,t14),((((t9,t10),((t6,t7),t8)),t11),(t25,t24))),(t16,(t12,t13))))))),t0);
+(t1,(((t3,t2),(((t25,t24),(t23,(((t20,t19),(t22,t21)),(t18,t17)))),((t16,(t15,t14)),((t12,t13),(((t9,t10),((t6,t7),t8)),t11))))),((t4,t5),(t26,t27))),t0);
+(t1,(((t3,t2),((t23,(((t20,t19),(t22,t21)),(t18,t17))),((((t25,t24),(((t9,t10),((t6,t7),t8)),t11)),(t12,t13)),(t16,(t15,t14))))),((t4,t5),(t26,t27))),t0);
+(((((t16,((t14,t15),((t11,(((t7,t6),t8),(t9,t10))),((t24,t25),(t13,t12))))),(((t18,t17),((t22,t21),(t19,t20))),t23)),(t27,t26)),((t2,t3),(t4,t5))),t1,t0);
+(((((((t14,t15),t16),((t13,t12),(t11,(((t7,t6),t8),(t9,t10))))),((t24,t25),(t23,((t18,t17),((t22,t21),(t19,t20)))))),(t27,t26)),((t2,t3),(t4,t5))),t1,t0);
+((((t16,(((t13,t12),(t11,(((t7,t6),t8),(t9,t10)))),(t14,t15))),((t24,t25),(t23,((t18,t17),((t22,t21),(t19,t20)))))),((t4,t5),((t27,t26),(t2,t3)))),t1,t0);
+((((t27,t26),(t2,t3)),((t16,((((t13,t12),((t24,t25),(t11,(((t7,t6),t8),(t9,t10))))),(t14,t15)),(t23,((t18,t17),((t22,t21),(t19,t20)))))),(t4,t5))),t1,t0);
+(((((t16,((t14,t15),(t11,(((t7,t6),t8),(t9,t10))))),((t13,t12),(t24,t25))),(t23,((t18,t17),((t22,t21),(t19,t20))))),((t4,t5),((t27,t26),(t2,t3)))),t1,t0);
+((((t27,t26),(((((t14,t15),((t11,(((t7,t6),t8),(t9,t10))),((t13,t12),(t24,t25)))),(t23,((t18,t17),((t22,t21),(t19,t20))))),t16),(t2,t3))),(t4,t5)),t1,t0);
+((((t27,t26),((((t14,t15),(t16,((t11,(((t7,t6),t8),(t9,t10))),((t13,t12),(t24,t25))))),(t23,((t18,t17),((t22,t21),(t19,t20))))),(t2,t3))),(t4,t5)),t1,t0);
+((((t27,t26),((t23,((t18,t17),((t22,t21),(t19,t20)))),(((t13,t12),t16),((t24,t25),((t14,t15),(t11,(((t7,t6),t8),(t9,t10)))))))),((t2,t3),(t4,t5))),t1,t0);
+(((t2,t3),((t4,t5),((t27,t26),((t23,((t18,t17),((t22,t21),(t19,t20)))),((((t24,t25),(t13,t12)),(t11,(((t7,t6),t8),(t9,t10)))),(t16,(t14,t15))))))),t1,t0);
+(((t2,t3),((t4,t5),((t27,t26),((t16,(t14,t15)),((t23,((t18,t17),((t22,t21),(t19,t20)))),((t13,t12),((t11,(((t7,t6),t8),(t9,t10))),(t24,t25)))))))),t1,t0);
+(t1,((((t25,t24),(t23,((t18,t17),((t21,t22),(t20,t19))))),(((t11,((t9,t10),(t8,(t6,t7)))),(t13,t12)),(t16,(t14,t15)))),((t5,t4),((t2,t3),(t27,t26)))),t0);
+(t1,((t5,t4),(((t2,t3),(t27,t26)),(t16,((t14,t15),(((t25,t24),(t23,((t18,t17),((t21,t22),(t20,t19))))),((t11,((t9,t10),(t8,(t6,t7)))),(t13,t12))))))),t0);
+(t1,((t2,t3),(((t27,t26),((t23,((t21,(t20,t19)),(t22,(t18,t17)))),((t14,t15),(((t11,((t9,t10),(t8,(t6,t7)))),(t25,t24)),((t13,t12),t16))))),(t5,t4))),t0);
+(t1,((t2,t3),(((t27,t26),(((t25,t24),(t23,(((t22,t21),(t20,t19)),(t18,t17)))),((t16,(t14,t15)),((t11,((t9,t10),(t8,(t6,t7)))),(t13,t12))))),(t5,t4))),t0);
+(t1,((t5,t4),((t27,t26),((t2,t3),((t23,(((t22,t21),(t20,t19)),(t18,t17))),((t16,(t14,t15)),((t11,((t9,t10),(t8,(t6,t7)))),((t25,t24),(t13,t12)))))))),t0);
+(t1,(((t23,(((t22,t21),(t20,t19)),(t18,t17))),(t16,((t14,t15),((t11,((t9,t10),(t8,(t6,t7)))),((t25,t24),(t13,t12)))))),((t27,t26),((t5,t4),(t2,t3)))),t0);
+(t1,((((t23,(((t22,t21),(t20,t19)),(t18,t17))),(((t13,t12),((t11,((t9,t10),(t8,(t6,t7)))),(t25,t24))),(t16,(t14,t15)))),((t27,t26),(t2,t3))),(t5,t4)),t0);
+(t1,(((t2,t3),((((t25,t24),(t23,(((t22,t21),(t20,t19)),(t18,t17)))),(((t13,t12),(t11,((t9,t10),(t8,(t6,t7))))),(t16,(t14,t15)))),(t27,t26))),(t5,t4)),t0);
+(t1,((((t23,((((t22,t21),(t20,t19)),(t18,t17)),(t25,t24))),((t11,((t9,t10),(t8,(t6,t7)))),(t16,((t14,t15),(t13,t12))))),(t27,t26)),((t5,t4),(t2,t3))),t0);
+(t1,(((t5,t4),((t23,(((t22,t21),(t20,t19)),(t18,t17))),(((t25,t24),(t13,t12)),((t11,((t9,t10),(t8,(t6,t7)))),(t16,(t14,t15)))))),((t27,t26),(t2,t3))),t0);
+(t1,((t5,t4),(((t27,t26),(((((t13,t12),(t24,t25)),(t16,(t11,(((t6,t7),t8),(t9,t10))))),(t15,t14)),((((t20,t19),(t21,t22)),(t17,t18)),t23))),(t3,t2))),t0);
+(t1,(((t27,t26),(t3,t2)),((t5,t4),(((((t13,t12),(t24,t25)),((t11,(((t6,t7),t8),(t9,t10))),(t15,t14))),((((t20,t19),(t21,t22)),(t17,t18)),t23)),t16))),t0);
+(t1,((t3,t2),((((((t24,t25),(t11,(((t6,t7),t8),(t9,t10)))),((t15,t14),(t13,t12))),t16),((((t20,t19),(t21,t22)),(t17,t18)),t23)),((t5,t4),(t26,t27)))),t0);
+(t1,((t5,t4),(((t26,t27),(t3,t2)),(t16,(((((t20,t19),(t21,t22)),(t17,t18)),t23),(((t24,t25),(t11,(((t6,t7),t8),(t9,t10)))),((t15,t14),(t13,t12))))))),t0);
+(t1,((((((t20,t19),(t21,t22)),(t17,t18)),t23),((((t15,t14),t16),((t11,(((t6,t7),t8),(t9,t10))),(t13,t12))),(t24,t25))),((t26,t27),((t5,t4),(t3,t2)))),t0);
+(t1,(((((((t20,t19),(t21,t22)),(t17,t18)),t23),(((t16,(t13,t12)),((t15,t14),(t11,(((t6,t7),t8),(t9,t10))))),(t24,t25))),((t3,t2),(t26,t27))),(t5,t4)),t0);
+(t1,(((t3,t2),(t26,t27)),((t5,t4),(((t11,(((t6,t7),t8),(t9,t10))),((t16,(t13,t12)),(t15,t14))),((t24,t25),((((t20,t19),(t21,t22)),(t17,t18)),t23))))),t0);
+(t1,(((t3,t2),(((t11,(((t6,t7),t8),(t9,t10))),(((t24,t25),(t13,t12)),((t15,t14),t16))),((((t20,t19),(t21,t22)),(t17,t18)),t23))),((t26,t27),(t5,t4))),t0);
+(t1,(((t26,t27),(t3,t2)),(((t16,(((t13,t12),(t11,(((t6,t7),t8),(t9,t10)))),(t15,t14))),((t24,t25),((((t20,t19),(t21,t22)),(t17,t18)),t23))),(t5,t4))),t0);
+(t1,(((t5,t4),(t3,t2)),((t26,((((t13,t12),t16),((t11,(((t6,t7),t8),(t9,t10))),(t15,t14))),((((t20,t19),(t21,t22)),(t17,t18)),(t23,(t24,t25))))),t27)),t0);
+(t1,((t27,(t3,t2)),((t4,t5),(t26,((t23,(((t22,t21),(t19,t20)),(t17,t18))),(((t14,t15),t16),((t12,t13),((t25,t24),(((t8,(t7,t6)),(t10,t9)),t11)))))))),t0);
+(t1,(((t26,t27),((t3,t2),(t4,t5))),((t23,(((t22,t21),(t19,t20)),(t17,t18))),(((t14,t15),t16),((t12,t13),((t25,t24),(((t8,(t7,t6)),(t10,t9)),t11)))))),t0);
+(t1,((t3,t2),((t4,t5),(((((t25,t24),t23),(((t22,t21),(t19,t20)),(t17,t18))),((((t14,t15),t16),(((t8,(t7,t6)),(t10,t9)),t11)),(t12,t13))),(t26,t27)))),t0);
+(t1,((t3,t2),((t4,t5),((((t25,t24),(t23,(((t22,t21),(t19,t20)),(t17,t18)))),(((t14,t15),t16),((((t8,(t7,t6)),(t10,t9)),t11),(t12,t13)))),(t26,t27)))),t0);
+(t1,((t4,t5),((((t25,t24),(t23,(((t22,t21),(t19,t20)),(t17,t18)))),(((t14,t15),t16),((((t8,(t7,t6)),(t10,t9)),t11),(t12,t13)))),((t3,t2),(t26,t27)))),t0);
+(t1,((t3,t2),((t4,t5),((t26,t27),((t23,((t22,(t21,(t19,t20))),(t17,t18))),((((((t8,(t7,t6)),(t10,t9)),t11),((t25,t24),(t12,t13))),(t14,t15)),t16))))),t0);
+(t1,(((t3,t2),(((t25,t24),(t23,(((t19,t20),(t22,t21)),(t17,t18)))),(((t14,t15),t16),((((t8,(t7,t6)),(t10,t9)),t11),(t12,t13))))),((t4,t5),(t26,t27))),t0);
+(t1,((t4,t5),((((t14,t15),(((((t8,(t7,t6)),(t10,t9)),t11),(t12,t13)),((((t19,t20),(t22,t21)),(t17,t18)),((t25,t24),t23)))),t16),((t26,t27),(t3,t2)))),t0);
+(t1,(((t26,t27),((t23,(((t19,t20),(t22,t21)),(t17,t18))),((t16,(t12,t13)),(((t25,t24),(((t8,(t7,t6)),(t10,t9)),t11)),(t14,t15))))),((t3,t2),(t4,t5))),t0);
+(t1,((t3,t2),((t4,t5),((t26,t27),((((((t8,(t7,t6)),(t10,t9)),t11),(t14,t15)),(((t12,t13),(t25,t24)),(t23,((t21,((t19,t20),t22)),(t17,t18))))),t16)))),t0);
+(((t2,t3),(((t23,((t17,t18),((t19,t20),(t21,t22)))),(t16,((t14,t15),(((t24,t25),(t13,t12)),(t11,((t8,(t6,t7)),(t10,t9))))))),((t4,t5),(t26,t27)))),t1,t0);
+((((t4,t5),((t26,t27),(((t24,t25),((t17,t18),(((t19,t20),(t21,t22)),t23))),(t16,(((t13,t12),(t14,t15)),(t11,((t8,(t6,t7)),(t10,t9)))))))),(t2,t3)),t1,t0);
+((((t4,t5),((t26,t27),(((((t17,t18),((t19,t20),t21)),t22),t23),(((t24,t25),(t13,t12)),((t16,(t14,t15)),(t11,((t8,(t6,t7)),(t10,t9)))))))),(t2,t3)),t1,t0);
+(((t4,t5),(((t26,t27),(((t24,t25),(((t17,t18),((t19,t20),(t22,t21))),t23)),((t16,(t14,t15)),((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12))))),(t2,t3))),t1,t0);
+(((t2,t3),(((t4,t5),(t26,t27)),((((t24,t25),(((t19,t20),((t22,t21),(t17,t18))),t23)),((t13,t12),((t14,t15),(t11,((t8,(t6,t7)),(t10,t9)))))),t16))),t1,t0);
+(((t2,t3),(((t4,t5),(t26,t27)),(((t24,t25),(((t17,t18),((t19,t20),(t22,t21))),t23)),(t16,(((t13,t12),(t14,t15)),(t11,((t8,(t6,t7)),(t10,t9)))))))),t1,t0);
+(((((t24,t25),(((t17,t18),((t19,t20),(t22,t21))),t23)),(((t16,(t13,t12)),(t14,t15)),(t11,((t8,(t6,t7)),(t10,t9))))),((t2,t3),((t4,t5),(t26,t27)))),t1,t0);
+(((t2,t3),((t4,t5),(((((t17,t18),((t19,t20),(t22,t21))),t23),((t16,(t14,t15)),((t11,((t8,(t6,t7)),(t10,t9))),((t13,t12),(t24,t25))))),(t26,t27)))),t1,t0);
+(((((((t17,t18),((t19,t20),(t22,t21))),t23),(((t16,(t24,t25)),((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12))),(t14,t15))),(t26,t27)),((t2,t3),(t4,t5))),t1,t0);
+((((((t24,t25),(t23,((t17,t18),((t19,t20),(t22,t21))))),((t13,t12),((t16,(t14,t15)),(t11,((t8,(t6,t7)),(t10,t9)))))),(t26,t27)),((t2,t3),(t4,t5))),t1,t0);
+((((t26,t27),((t23,((t18,t17),((t22,t21),(t20,t19)))),(((t14,t15),t16),((((t9,t10),(t8,(t6,t7))),t11),((t12,t13),(t24,t25)))))),((t5,t4),(t3,t2))),t1,t0);
+((((t3,t2),((t23,((t18,t17),((t22,t21),(t20,t19)))),((t14,t15),(t16,((((t9,t10),(t8,(t6,t7))),t11),((t12,t13),(t24,t25))))))),((t5,t4),(t26,t27))),t1,t0);
+(((t5,t4),(((t26,t27),(((t24,t25),(t23,((t22,(t18,t17)),(t21,(t20,t19))))),(((((t9,t10),(t8,(t6,t7))),t11),(t12,t13)),((t14,t15),t16)))),(t3,t2))),t1,t0);
+((((t26,t27),(((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19))))),(((((t9,t10),(t8,(t6,t7))),t11),(t12,t13)),((t14,t15),t16)))),((t3,t2),(t5,t4))),t1,t0);
+((((t26,t27),(t3,t2)),((t5,t4),((((t14,t15),t16),((((t9,t10),(t8,(t6,t7))),t11),((t24,t25),(t12,t13)))),(t23,((t18,t17),((t22,t21),(t20,t19))))))),t1,t0);
+(((t5,t4),(((((((t9,t10),(t8,(t6,t7))),t11),(t24,t25)),((t14,t15),((t12,t13),t16))),(t23,((t18,t17),((t22,t21),(t20,t19))))),((t26,t27),(t3,t2)))),t1,t0);
+(((t5,t4),(((((((t9,t10),(t8,(t6,t7))),t11),((t24,t25),(t12,t13))),(t16,(t14,t15))),(t23,((t18,t17),((t22,t21),(t20,t19))))),(t26,(t27,(t3,t2))))),t1,t0);
+(((((t16,((t14,t15),((((t9,t10),(t8,(t6,t7))),t11),((t24,t25),(t12,t13))))),(t23,((t18,t17),((t22,t21),(t20,t19))))),(t26,t27)),((t5,t4),(t3,t2))),t1,t0);
+(((t3,t2),((((t16,((t14,t15),((((t9,t10),(t8,(t6,t7))),t11),((t24,t25),(t12,t13))))),(t23,((t18,t17),((t22,t21),(t20,t19))))),(t26,t27)),(t5,t4))),t1,t0);
+(((t5,t4),(((((t12,t13),((((t9,t10),(t8,(t6,t7))),t11),(t24,t25))),(t16,(t14,t15))),(t23,((t18,t17),((t22,t21),(t20,t19))))),((t3,t2),(t26,t27)))),t1,t0);
+(t1,(((((t16,(t14,t15)),((t11,((t9,t10),((t6,t7),t8))),(t12,t13))),((t25,t24),(t23,((t17,t18),((t19,t20),(t21,t22)))))),(t26,t27)),((t3,t2),(t4,t5))),t0);
+(t1,(((((t16,(t14,t15)),((t11,((t9,t10),((t6,t7),t8))),(t12,t13))),((t25,t24),(((t19,t20),(t21,t22)),(t23,(t17,t18))))),((t4,t5),(t26,t27))),(t3,t2)),t0);
+(t1,((t4,t5),((((t11,((t9,t10),((t6,t7),t8))),((t12,t13),(t16,(t14,t15)))),((t25,t24),((((t19,t20),(t21,t22)),(t17,t18)),t23))),((t26,t27),(t3,t2)))),t0);
+(t1,(((((t16,(t14,t15)),(((t25,t24),(t11,((t9,t10),((t6,t7),t8)))),(t12,t13))),((((t19,t20),(t21,t22)),(t17,t18)),t23)),(t26,t27)),((t4,t5),(t3,t2))),t0);
+(t1,((t4,t5),((((t11,((t9,t10),((t6,t7),t8))),(((t25,t24),((((t19,t20),(t21,t22)),(t17,t18)),t23)),((t14,t15),(t12,t13)))),t16),((t26,t27),(t3,t2)))),t0);
+(t1,(((t16,(t14,t15)),(((t11,((t9,t10),((t6,t7),t8))),((t25,t24),(t12,t13))),((((t19,t20),(t21,t22)),(t17,t18)),t23))),(((t4,t5),(t26,t27)),(t3,t2))),t0);
+(t1,((t4,t5),((t16,((t14,t15),(((t12,t13),(t11,((t9,t10),((t6,t7),t8)))),((t25,t24),((((t19,t20),(t21,t22)),(t17,t18)),t23))))),((t26,t27),(t3,t2)))),t0);
+(t1,((t4,t5),((t3,t2),((((t25,t24),((((t19,t20),(t21,t22)),(t17,t18)),t23)),((t16,(t14,t15)),((t12,t13),(t11,((t9,t10),((t6,t7),t8)))))),(t26,t27)))),t0);
+(t1,((t4,t5),((((((t19,t20),(t21,t22)),(t17,t18)),t23),((t16,(t14,t15)),(((t25,t24),(t12,t13)),(t11,((t9,t10),((t6,t7),t8)))))),((t26,t27),(t3,t2)))),t0);
+(t1,((t4,t5),((((t14,t15),(((t12,t13),(t11,((t9,t10),((t6,t7),t8)))),((t25,t24),((((t19,t20),(t21,t22)),(t17,t18)),t23)))),t16),((t26,t27),(t3,t2)))),t0);
+(t1,((t4,t5),((((((((t7,t6),t8),(t9,t10)),t11),((t24,t25),(t12,t13))),(t16,(t15,t14))),(t23,(t22,(((t20,t19),t21),(t18,t17))))),((t2,t3),(t27,t26)))),t0);
+(t1,(((t4,t5),((t27,t26),(((t12,t13),(t16,(((((t7,t6),t8),(t9,t10)),t11),(t15,t14)))),((t24,t25),(t23,(((t20,t19),(t22,t21)),(t18,t17))))))),(t2,t3)),t0);
+(t1,((((t4,t5),(t26,((t23,(((t20,t19),(t22,t21)),(t18,t17))),((((t12,t13),((((t7,t6),t8),(t9,t10)),t11)),((t15,t14),t16)),(t24,t25))))),(t2,t3)),t27),t0);
+(t1,((((t23,(((t20,t19),(t22,t21)),(t18,t17))),(((t16,(t12,t13)),((t24,t25),((((t7,t6),t8),(t9,t10)),t11))),(t15,t14))),((t4,t5),(t27,t26))),(t2,t3)),t0);
+(t1,((t4,t5),(((t27,t26),(((t23,(((t20,t19),(t22,t21)),(t18,t17))),((((t12,t13),(t24,t25)),((((t7,t6),t8),(t9,t10)),t11)),(t15,t14))),t16)),(t2,t3))),t0);
+(t1,(((t23,(((t20,t19),(t22,t21)),(t18,t17))),((t16,(((t12,t13),(t24,t25)),((((t7,t6),t8),(t9,t10)),t11))),(t15,t14))),((t2,t3),((t4,t5),(t27,t26)))),t0);
+(t1,((t2,t3),((t27,(t26,(t4,t5))),((t23,((((t20,t19),(t22,t21)),(t18,t17)),(t24,t25))),((((((t7,t6),t8),(t9,t10)),t11),(t12,t13)),((t15,t14),t16))))),t0);
+(t1,((t2,t3),(((t27,t26),((t23,(((t20,t19),(t22,t21)),(t18,t17))),(((t24,t25),((((t7,t6),t8),(t9,t10)),t11)),((t16,(t12,t13)),(t15,t14))))),(t4,t5))),t0);
+(t1,(((t27,t26),((t23,(((t20,t19),(t22,t21)),(t18,t17))),((t16,(t24,t25)),((((((t7,t6),t8),(t9,t10)),t11),(t15,t14)),(t12,t13))))),((t4,t5),(t2,t3))),t0);
+(t1,((t4,t5),((t2,t3),((t27,t26),(((((((t7,t6),t8),(t9,t10)),t11),(t16,(t15,t14))),((t24,t25),(t12,t13))),(t23,(((t20,t19),(t22,t21)),(t18,t17))))))),t0);
+(t1,(((t23,((t18,t17),((t22,t21),(t20,t19)))),((((t24,t25),(t11,(((t7,t6),t8),(t9,t10)))),(t15,t14)),((t13,t12),t16))),(((t26,t27),(t3,t2)),(t5,t4))),t0);
+(t1,((t5,t4),((((t11,(((t7,t6),t8),(t9,t10))),((t15,t14),((t13,t12),t16))),((t23,((t18,t17),((t22,t21),(t20,t19)))),(t24,t25))),((t26,t27),(t3,t2)))),t0);
+(t1,(((t5,t4),(t26,t27)),((t3,t2),((((t13,t12),(t11,(((t7,t6),t8),(t9,t10)))),(t16,(t15,t14))),((t23,((t18,t17),((t22,t21),(t20,t19)))),(t24,t25))))),t0);
+(t1,(((t3,t2),(t26,t27)),((t5,t4),(((t11,(((t7,t6),t8),(t9,t10))),((t16,(t15,t14)),((t24,t25),(t13,t12)))),(t23,((t18,t17),((t22,t21),(t20,t19))))))),t0);
+(t1,(((t3,t2),(t5,t4)),((((t16,(t15,t14)),((t11,(((t7,t6),t8),(t9,t10))),(t13,t12))),((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19)))))),(t26,t27))),t0);
+(t1,(((t3,t2),(t5,t4)),((((t16,(t15,t14)),((t11,(((t7,t6),t8),(t9,t10))),(t13,t12))),((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19)))))),(t26,t27))),t0);
+(t1,((((t16,(t15,t14)),((t11,(((t7,t6),t8),(t9,t10))),(t13,t12))),((t24,t25),(((t22,t21),(t20,t19)),(t23,(t18,t17))))),((t5,t4),((t26,t27),(t3,t2)))),t0);
+(t1,((t5,t4),((t3,t2),((t27,t26),(((t16,(t15,t14)),((t11,(((t7,t6),t8),(t9,t10))),((t24,t25),(t13,t12)))),((((t22,t21),(t20,t19)),(t18,t17)),t23))))),t0);
+(t1,(((t27,t26),(t3,t2)),(((t16,((t15,t14),((t11,(((t7,t6),t8),(t9,t10))),((t24,t25),(t13,t12))))),((((t22,t21),(t20,t19)),(t18,t17)),t23)),(t5,t4))),t0);
+(t1,(((t3,t2),((((t11,(((t7,t6),t8),(t9,t10))),((t24,t25),(t13,t12))),(t16,(t15,t14))),(((t21,(t22,(t20,t19))),(t18,t17)),t23))),((t5,t4),(t27,t26))),t0);
+(t1,(((t16,((((t24,t25),(t13,t12)),(t11,((t9,t10),(t8,(t7,t6))))),(t15,t14))),(((t17,t18),(t22,(t21,(t19,t20)))),t23)),((t5,t4),((t27,t26),(t2,t3)))),t0);
+(t1,((t2,t3),((t5,t4),(((((t13,t12),(t11,((t9,t10),(t8,(t7,t6))))),((t15,t14),t16)),((t24,t25),(((t17,t18),((t19,t20),(t22,t21))),t23))),(t27,t26)))),t0);
+(t1,((t5,t4),((((((t17,t18),((t19,t20),(t22,t21))),t23),(((t16,(t13,t12)),((t11,((t9,t10),(t8,(t7,t6)))),(t15,t14))),(t24,t25))),(t27,t26)),(t2,t3))),t0);
+(t1,((t5,t4),((((t11,((t9,t10),(t8,(t7,t6)))),((t15,t14),(t16,(t13,t12)))),((t24,t25),(((t17,t18),((t19,t20),(t22,t21))),t23))),((t27,t26),(t2,t3)))),t0);
+(t1,((t2,t3),((t5,t4),(((((t15,t14),t16),((t11,((t9,t10),(t8,(t7,t6)))),((t24,t25),(t13,t12)))),(((t17,t18),((t19,t20),(t22,t21))),t23)),(t27,t26)))),t0);
+(t1,(((((t15,t14),t16),((t13,t12),((t11,((t9,t10),(t8,(t7,t6)))),(t24,t25)))),(((t17,t18),((t19,t20),(t22,t21))),t23)),((t2,t3),((t27,t26),(t5,t4)))),t0);
+(t1,((((((t15,t14),t16),((t11,((t9,t10),(t8,(t7,t6)))),(t13,t12))),((t24,t25),(((t17,t18),((t19,t20),(t22,t21))),t23))),((t2,t3),(t27,t26))),(t5,t4)),t0);
+(t1,(((t2,t3),(t27,t26)),((t5,t4),((((t17,t18),((t19,t20),(t22,t21))),t23),(t16,(((t11,((t9,t10),(t8,(t7,t6)))),(t15,t14)),((t13,t12),(t24,t25))))))),t0);
+(t1,((t16,(((t13,t12),((t11,((t9,t10),(t8,(t7,t6)))),(t15,t14))),((t24,t25),(((t17,t18),((t19,t20),(t22,t21))),t23)))),(((t2,t3),(t27,t26)),(t5,t4))),t0);
+(t1,((t5,t4),((((((t17,t18),((t19,t20),(t22,t21))),t23),((t16,((t11,((t9,t10),(t8,(t7,t6)))),(t24,t25))),((t13,t12),(t15,t14)))),(t2,t3)),(t27,t26))),t0);
+(t1,(((t16,((t15,t14),((t12,t13),((((t10,t9),(t8,(t6,t7))),t11),(t25,t24))))),(((t18,t17),((t20,t19),(t22,t21))),t23)),(((t5,t4),(t27,t26)),(t2,t3))),t0);
+(t1,((((((t16,(t12,t13)),(((t10,t9),(t8,(t6,t7))),t11)),(t15,t14)),((t25,t24),(((t18,t17),((t20,t19),(t22,t21))),t23))),(t5,t4)),((t2,t3),(t26,t27))),t0);
+(t1,(((((t12,t13),(((t10,t9),(t8,(t6,t7))),t11)),(t16,(t15,t14))),((t25,t24),(((t18,t17),((t20,t19),(t22,t21))),t23))),((t5,t4),((t2,t3),(t26,t27)))),t0);
+(t1,((((((t12,t13),(((t10,t9),(t8,(t6,t7))),t11)),(t16,(t15,t14))),((t25,t24),(((t18,t17),((t20,t19),(t22,t21))),t23))),(t2,t3)),((t26,t27),(t5,t4))),t0);
+(t1,(((t26,t27),(((((t10,t9),(t8,(t6,t7))),t11),(t16,((t15,t14),(t12,t13)))),((t25,t24),(((t18,t17),((t20,t19),(t22,t21))),t23)))),((t2,t3),(t5,t4))),t0);
+(t1,((t2,t3),(((((t18,t17),((t20,t19),(t22,t21))),t23),(t16,(((t12,t13),(t15,t14)),((((t10,t9),(t8,(t6,t7))),t11),(t25,t24))))),((t5,t4),(t26,t27)))),t0);
+(t1,((t5,t4),((t2,t3),((t26,t27),((((t18,t17),((t20,t19),(t22,t21))),t23),(t16,((t15,t14),((((t10,t9),(t8,(t6,t7))),t11),((t25,t24),(t12,t13))))))))),t0);
+(t1,((t2,t3),((t16,(((t15,t14),((t12,t13),((((t10,t9),(t8,(t6,t7))),t11),(t25,t24)))),(((t18,t17),((t20,t19),(t22,t21))),t23))),((t5,t4),(t26,t27)))),t0);
+(t1,((t2,t3),((t5,t4),((t26,t27),(((((t10,t9),(t8,(t6,t7))),t11),((t16,(t12,t13)),(t15,t14))),((t25,t24),(((t18,t17),((t20,t19),(t22,t21))),t23)))))),t0);
+(t1,((t5,t4),(((t2,t3),(t26,t27)),(((t16,(t12,t13)),((t15,t14),(((t10,t9),(t8,(t6,t7))),t11))),((t25,t24),(((t18,t17),((t20,t19),(t22,t21))),t23))))),t0);
+((((t27,t26),(t4,t5)),((t2,t3),((t23,((t18,t17),((t22,t21),(t20,t19)))),(t16,((((t24,t25),(t12,t13)),(t11,((t10,t9),((t7,t6),t8)))),(t14,t15)))))),t1,t0);
+(((t2,t3),((((t23,((t18,t17),((t22,t21),(t20,t19)))),((t14,t15),(t16,(((t24,t25),(t12,t13)),(t11,((t10,t9),((t7,t6),t8))))))),(t27,t26)),(t4,t5))),t1,t0);
+(((t2,t3),(((((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19))))),(((t11,((t10,t9),((t7,t6),t8))),(t12,t13)),((t14,t15),t16))),(t27,t26)),(t4,t5))),t1,t0);
+(((t2,t3),((((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19))))),(t16,(((t11,((t10,t9),((t7,t6),t8))),(t12,t13)),(t14,t15)))),((t27,t26),(t4,t5)))),t1,t0);
+(((((t24,t25),(t23,((t18,t17),((t22,t21),(t20,t19))))),((t11,((t10,t9),((t7,t6),t8))),((t14,t15),((t12,t13),t16)))),(((t27,t26),(t4,t5)),(t2,t3))),t1,t0);
+(((t4,t5),(((t23,(((t18,t17),((t22,t21),(t20,t19))),(t24,t25))),((t12,t13),(t16,((t11,((t10,t9),((t7,t6),t8))),(t14,t15))))),((t2,t3),(t27,t26)))),t1,t0);
+(((t4,t5),(((t23,((t21,(t18,t17)),(t22,(t20,t19)))),(((t24,t25),(t12,t13)),((t11,((t10,t9),((t7,t6),t8))),((t14,t15),t16)))),((t2,t3),(t27,t26)))),t1,t0);
+(((t4,t5),((((t24,t25),(t23,((t18,t17),((t21,t22),(t20,t19))))),((((t11,((t10,t9),((t7,t6),t8))),(t12,t13)),(t14,t15)),t16)),((t2,t3),(t27,t26)))),t1,t0);
+(((t4,t5),((((((t18,t17),((t21,t22),(t20,t19))),((t24,t25),t23)),(((t11,((t10,t9),((t7,t6),t8))),(t12,t13)),((t14,t15),t16))),(t27,t26)),(t2,t3))),t1,t0);
+(((t4,t5),(((t2,t3),((t23,((t18,t17),((t21,t22),(t20,t19)))),(((t24,t25),(t12,t13)),(((t14,t15),t16),(t11,((t10,t9),((t7,t6),t8))))))),(t27,t26))),t1,t0);
+(((t3,t2),(((((((t25,t24),(t11,((t8,(t6,t7)),(t10,t9)))),(t13,t12)),((t15,t14),t16)),((((t22,t21),(t20,t19)),(t17,t18)),t23)),(t27,t26)),(t5,t4))),t1,t0);
+((((((t25,t24),((t11,((t8,(t6,t7)),(t10,t9))),((t15,t14),((t13,t12),t16)))),((((t22,t21),(t20,t19)),(t17,t18)),t23)),((t3,t2),(t27,t26))),(t5,t4)),t1,t0);
+(((t3,t2),(((t27,t26),((t16,(((t11,((t8,(t6,t7)),(t10,t9))),((t13,t12),(t25,t24))),(t15,t14))),((((t22,t21),(t20,t19)),(t17,t18)),t23))),(t5,t4))),t1,t0);
+((((t27,t26),((((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),((t15,t14),t16)),((t25,t24),((((t22,t21),(t20,t19)),(t17,t18)),t23)))),((t5,t4),(t3,t2))),t1,t0);
+(((t3,t2),(((t27,t26),((((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),((t15,t14),t16)),((t25,t24),((((t22,t21),(t20,t19)),(t17,t18)),t23)))),(t5,t4))),t1,t0);
+(((t5,t4),(((t27,t26),(t3,t2)),((((t15,t14),(t11,((t8,(t6,t7)),(t10,t9)))),((t13,t12),t16)),((t25,t24),((((t22,t21),(t20,t19)),(t17,t18)),t23))))),t1,t0);
+(((((((t15,t14),((t25,t24),(t11,((t8,(t6,t7)),(t10,t9))))),(t16,(t13,t12))),((((t22,t21),(t20,t19)),(t17,t18)),t23)),(t27,t26)),((t5,t4),(t3,t2))),t1,t0);
+(((t5,t4),(((t3,t2),(t16,((t15,t14),(((t11,((t8,(t6,t7)),(t10,t9))),(t13,t12)),((t25,t24),((((t22,t21),(t20,t19)),(t17,t18)),t23)))))),(t27,t26))),t1,t0);
+(((t3,t2),((((t25,t24),((((t22,t21),(t20,t19)),(t17,t18)),t23)),(((t11,((t8,(t6,t7)),(t10,t9))),((t15,t14),(t13,t12))),t16)),((t27,t26),(t5,t4)))),t1,t0);
+((((t27,t26),(t5,t4)),((t3,t2),(((((t22,t21),(t20,t19)),(t17,t18)),t23),((((t11,((t8,(t6,t7)),(t10,t9))),(t15,t14)),t16),((t25,t24),(t13,t12)))))),t1,t0);
+(t1,(((t4,t5),((((t14,t15),t16),((t11,((t10,t9),((t7,t6),t8))),(t13,t12))),((t24,t25),(t23,((t17,t18),((t22,t21),(t19,t20))))))),((t26,t27),(t3,t2))),t0);
+(t1,((t4,t5),(((((t24,t25),(t13,t12)),(((t14,t15),t16),(t11,((t10,t9),((t7,t6),t8))))),(t23,((t17,t18),((t22,t21),(t19,t20))))),((t26,t27),(t3,t2)))),t0);
+(t1,((t3,t2),((((((t14,t15),t16),((t11,((t10,t9),((t7,t6),t8))),((t24,t25),(t13,t12)))),(t23,((t17,t18),((t22,t21),(t19,t20))))),(t26,t27)),(t4,t5))),t0);
+(t1,((((((t11,((t10,t9),((t7,t6),t8))),(t24,t25)),((t13,t12),((t14,t15),t16))),(t23,((t17,t18),((t22,t21),(t19,t20))))),((t3,t2),(t26,t27))),(t4,t5)),t0);
+(t1,((((((t14,t15),t16),(((t11,((t10,t9),((t7,t6),t8))),(t24,t25)),(t13,t12))),(t23,((t17,t18),((t22,t21),(t19,t20))))),(t3,t2)),((t4,t5),(t26,t27))),t0);
+(t1,((((((t11,((t10,t9),((t7,t6),t8))),((t13,t12),(t14,t15))),t16),(((t24,t25),t23),((t17,t18),((t22,t21),(t19,t20))))),((t27,t26),(t3,t2))),(t4,t5)),t0);
+(t1,((t3,t2),((((((t11,((t10,t9),((t7,t6),t8))),(t13,t12)),(t16,(t14,t15))),((((t17,t18),((t22,t21),(t19,t20))),t23),(t24,t25))),(t27,t26)),(t4,t5))),t0);
+(t1,(((t3,t2),((((t17,t18),((t22,t21),(t19,t20))),t23),((t14,t15),(t16,(((t24,t25),(t11,((t10,t9),((t7,t6),t8)))),(t13,t12)))))),((t27,t26),(t4,t5))),t0);
+(t1,((t4,t5),((((((t17,t18),((t22,t21),(t19,t20))),t23),(((t11,((t10,t9),((t7,t6),t8))),((t13,t12),(t24,t25))),((t14,t15),t16))),(t27,t26)),(t3,t2))),t0);
+(t1,((t3,t2),((t4,t5),(((((t17,t18),((t22,t21),(t19,t20))),t23),(((t13,t12),((t24,t25),(t11,((t10,t9),((t7,t6),t8))))),((t14,t15),t16))),(t27,t26)))),t0);
+(((t4,t5),(((t23,((t17,t18),((t22,t21),(t20,t19)))),(((t15,t14),(((((t6,t7),t8),(t10,t9)),t11),(t25,t24))),((t13,t12),t16))),((t2,t3),(t26,t27)))),t1,t0);
+(((t2,t3),(((t26,t27),(t4,t5)),((t23,((t17,t18),((t22,t21),(t20,t19)))),(((t15,t14),(((((t6,t7),t8),(t10,t9)),t11),((t13,t12),(t25,t24)))),t16)))),t1,t0);
+(((t4,t5),((((t23,((t17,t18),((t22,t21),(t20,t19)))),((t15,t14),(((t25,t24),(((((t6,t7),t8),(t10,t9)),t11),(t13,t12))),t16))),(t2,t3)),(t26,t27))),t1,t0);
+(((t2,t3),((t4,t5),((t26,t27),((t23,((t17,t18),((t22,t21),(t20,t19)))),((t25,t24),((((((t6,t7),t8),(t10,t9)),t11),(t13,t12)),(t16,(t15,t14)))))))),t1,t0);
+(((t4,t5),(((t2,t3),(t26,t27)),((((t15,t14),(((((t6,t7),t8),(t10,t9)),t11),((t25,t24),(t13,t12)))),(t23,((t17,t18),((t22,t21),(t20,t19))))),t16))),t1,t0);
+((((t2,t3),(t26,t27)),(((((t13,t12),(((((t6,t7),t8),(t10,t9)),t11),(t25,t24))),(t16,(t15,t14))),(t23,((t17,t18),((t22,t21),(t20,t19))))),(t4,t5))),t1,t0);
+((((t2,t3),((((((((t6,t7),t8),(t10,t9)),t11),((t25,t24),(t13,t12))),(t15,t14)),(t23,((t17,t18),((t22,t21),(t20,t19))))),t16)),((t4,t5),(t26,t27))),t1,t0);
+(((t2,t3),(((((t25,t24),(((t15,t14),t16),((t13,t12),((((t6,t7),t8),(t10,t9)),t11)))),(t23,((t17,t18),((t22,t21),(t20,t19))))),(t26,t27)),(t4,t5))),t1,t0);
+(((t2,t3),((((t16,(((t13,t12),((((t6,t7),t8),(t10,t9)),t11)),(t15,t14))),((t23,((t17,t18),((t22,t21),(t20,t19)))),(t25,t24))),(t26,t27)),(t4,t5))),t1,t0);
+(((t2,t3),(((((t13,t12),(((((t6,t7),t8),(t10,t9)),t11),((t15,t14),t16))),((t23,((t17,t18),((t22,t21),(t20,t19)))),(t25,t24))),(t26,t27)),(t4,t5))),t1,t0);
+(t1,((t2,t3),((t4,t5),((((((t13,t12),(t24,t25)),(((t8,(t7,t6)),(t10,t9)),t11)),((t15,t14),t16)),((((t22,t21),(t19,t20)),(t17,t18)),t23)),(t26,t27)))),t0);
+(t1,((t2,t3),((t4,t5),((((t15,t14),(t16,(((t13,t12),(t24,t25)),(((t8,(t7,t6)),(t10,t9)),t11)))),((((t22,t21),(t19,t20)),(t17,t18)),t23)),(t26,t27)))),t0);
+(t1,((t2,t3),((t4,t5),((((t16,(t15,t14)),((t13,t12),((t24,t25),(((t8,(t7,t6)),(t10,t9)),t11)))),((((t22,t21),(t19,t20)),(t17,t18)),t23)),(t26,t27)))),t0);
+(t1,(((t2,t3),(t16,((t15,t14),(((((t8,(t7,t6)),(t10,t9)),t11),(t13,t12)),((t24,t25),((((t22,t21),(t19,t20)),(t17,t18)),t23)))))),((t26,t27),(t4,t5))),t0);
+(t1,((((t24,t25),(((t8,(t7,t6)),(t10,t9)),t11)),(((t15,t14),(t13,t12)),(t16,((((t22,t21),(t19,t20)),(t17,t18)),t23)))),(((t2,t3),(t26,t27)),(t4,t5))),t0);
+(t1,((t2,t3),(((t26,t27),(t4,t5)),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(((t16,(t15,t14)),(((t8,(t7,t6)),(t10,t9)),t11)),((t24,t25),(t13,t12)))))),t0);
+(t1,(((t26,t27),(t4,t5)),((((((t22,t21),(t19,t20)),(t17,t18)),t23),(((t16,(t15,t14)),(((t8,(t7,t6)),(t10,t9)),t11)),((t24,t25),(t13,t12)))),(t2,t3))),t0);
+(t1,(((t26,t27),(((t24,t25),((((t22,t21),(t19,t20)),(t17,t18)),t23)),((t16,((t15,t14),(((t8,(t7,t6)),(t10,t9)),t11))),(t13,t12)))),((t2,t3),(t4,t5))),t0);
+(t1,((t4,t5),(((t26,t27),(((((t22,t21),(t19,t20)),(t17,t18)),t23),(((((t8,(t7,t6)),(t10,t9)),t11),((t16,(t15,t14)),(t13,t12))),(t24,t25)))),(t2,t3))),t0);
+(t1,((t2,t3),((t4,t5),((t26,t27),(((t16,(t15,t14)),((t13,t12),(((t8,(t7,t6)),(t10,t9)),t11))),((t24,t25),(((t19,t20),((t17,t18),(t22,t21))),t23)))))),t0);
+(t1,((((((t17,t18),((t21,t22),(t20,t19))),t23),(((t11,((t10,t9),((t7,t6),t8))),(((t14,t15),t16),(t13,t12))),(t24,t25))),(t26,t27)),((t3,t2),(t4,t5))),t0);
+(t1,((t4,t5),((((((t17,t18),((t21,t22),(t20,t19))),t23),((((t14,t15),t16),((t13,t12),(t11,((t10,t9),((t7,t6),t8))))),(t24,t25))),(t26,t27)),(t3,t2))),t0);
+(t1,((t4,t5),(((t26,t27),(t3,t2)),((((t11,((t10,t9),((t7,t6),t8))),(t14,t15)),(t16,(t13,t12))),((t24,t25),(((t17,t18),((t21,t22),(t20,t19))),t23))))),t0);
+(t1,((((((t11,((t10,t9),((t7,t6),t8))),(t14,t15)),(t13,t12)),((t24,t25),(((t20,t19),((t17,t18),(t21,t22))),t23))),t16),((t3,t2),((t4,t5),(t26,t27)))),t0);
+(t1,(((t4,t5),(t26,t27)),(((((t17,t18),((t21,t22),(t20,t19))),t23),((t16,(t14,t15)),(((t13,t12),(t24,t25)),(t11,((t10,t9),((t7,t6),t8)))))),(t3,t2))),t0);
+(t1,((t3,t2),(((t26,t27),((((t17,t18),((t21,t22),(t20,t19))),t23),(((t13,t12),(t24,t25)),((t14,t15),((t11,((t10,t9),((t7,t6),t8))),t16))))),(t4,t5))),t0);
+(t1,((((t24,t25),(((t17,t18),((t21,t22),(t20,t19))),t23)),((t11,((t10,t9),((t7,t6),t8))),(t16,((t13,t12),(t14,t15))))),((t4,t5),((t26,t27),(t3,t2)))),t0);
+(t1,((t3,t2),((t4,t5),((((((t17,t18),((t21,t22),(t20,t19))),t23),((((t11,((t10,t9),((t7,t6),t8))),(t16,(t13,t12))),(t14,t15)),(t24,t25))),t26),t27))),t0);
+(t1,((t4,t5),((((((t17,t18),((t21,t22),(t20,t19))),t23),((t16,(t14,t15)),(((t24,t25),(t11,((t10,t9),((t7,t6),t8)))),(t13,t12)))),(t26,t27)),(t3,t2))),t0);
+(t1,((((((t17,t18),((t21,t22),(t20,t19))),t23),((t14,t15),(((t11,((t10,t9),((t7,t6),t8))),((t13,t12),(t24,t25))),t16))),(t26,t27)),((t3,t2),(t4,t5))),t0);
+(t1,((t2,t3),(((t27,t26),((((t15,t14),t16),((((t9,t10),(t8,(t7,t6))),t11),((t25,t24),(t12,t13)))),(((t18,t17),((t19,t20),(t22,t21))),t23))),(t4,t5))),t0);
+(t1,((t2,t3),(((t27,t26),((t16,(((t12,t13),((((t9,t10),(t8,(t7,t6))),t11),(t25,t24))),(t15,t14))),(((t18,t17),((t19,t20),(t22,t21))),t23))),(t4,t5))),t0);
+(t1,((t2,t3),(((t27,t26),((((((t9,t10),(t8,(t7,t6))),t11),((t25,t24),(t12,t13))),((t15,t14),t16)),(((t18,t17),((t19,t20),(t22,t21))),t23))),(t4,t5))),t0);
+(t1,((t4,t5),((t2,t3),((t27,t26),((((((t9,t10),(t8,(t7,t6))),t11),(t12,t13)),((t15,t14),t16)),((t25,t24),(((t18,t17),((t19,t20),(t22,t21))),t23)))))),t0);
+(t1,((t2,t3),(((t4,t5),(t27,t26)),((((t18,t17),((t19,t20),(t22,t21))),t23),(t16,(((((t9,t10),(t8,(t7,t6))),t11),((t25,t24),(t12,t13))),(t15,t14)))))),t0);
+(t1,((t2,t3),((t4,t5),((t27,t26),((((t18,t17),((t19,t20),(t22,t21))),t23),(((t12,t13),((((t9,t10),(t8,(t7,t6))),t11),(t25,t24))),((t15,t14),t16)))))),t0);
+(t1,(((t2,t3),((((t18,t17),((t19,t20),(t22,t21))),t23),((t12,t13),((((((t9,t10),(t8,(t7,t6))),t11),(t25,t24)),(t15,t14)),t16)))),((t4,t5),(t27,t26))),t0);
+(t1,((t4,t5),((t27,t26),((t2,t3),(((t15,t14),(((((t9,t10),(t8,(t7,t6))),t11),((t12,t13),(t25,t24))),(((t18,t17),((t19,t20),(t22,t21))),t23))),t16)))),t0);
+(t1,((t2,t3),(((((t18,t17),((t19,t20),(t22,t21))),t23),((((t25,t24),(((t9,t10),(t8,(t7,t6))),t11)),((t15,t14),(t12,t13))),t16)),((t4,t5),(t27,t26)))),t0);
+(t1,((t4,t5),(((t2,t3),(t27,t26)),((((t18,t17),(t22,(t21,(t19,t20)))),t23),(((t25,t24),(((t9,t10),(t8,(t7,t6))),t11)),((t15,t14),(t16,(t12,t13))))))),t0);
+(((t3,t2),((t5,t4),(((t23,((t17,t18),(t22,(t21,(t19,t20))))),((t24,t25),(t16,(((((t6,t7),t8),(t10,t9)),t11),((t14,t15),(t13,t12)))))),(t26,t27)))),t1,t0);
+((((t3,t2),(t26,t27)),((t5,t4),((t23,((t17,t18),((t19,t20),(t22,t21)))),((t24,t25),(((t13,t12),((((t6,t7),t8),(t10,t9)),t11)),((t14,t15),t16)))))),t1,t0);
+((((t3,t2),(t5,t4)),(((t23,((t17,t18),((t19,t20),(t22,t21)))),((t24,t25),((t16,(t13,t12)),(((((t6,t7),t8),(t10,t9)),t11),(t14,t15))))),(t26,t27))),t1,t0);
+(((t3,t2),((t5,t4),(((((t14,t15),(((t24,t25),(t13,t12)),((((t6,t7),t8),(t10,t9)),t11))),(t23,((t17,t18),((t19,t20),(t22,t21))))),t16),(t26,t27)))),t1,t0);
+(((t3,t2),(((t16,((t14,t15),((t13,t12),((((t6,t7),t8),(t10,t9)),t11)))),((t24,t25),(t23,((t17,t18),((t19,t20),(t22,t21)))))),((t26,t27),(t5,t4)))),t1,t0);
+((((t5,t4),((t23,((t17,t18),((t19,t20),(t22,t21)))),((t14,t15),(t16,(((((t6,t7),t8),(t10,t9)),t11),((t13,t12),(t24,t25))))))),((t3,t2),(t26,t27))),t1,t0);
+((((t5,t4),((t26,t27),(((t24,t25),(t23,((t17,t18),((t19,t20),(t22,t21))))),(((((t6,t7),t8),(t10,t9)),t11),(t16,((t13,t12),(t14,t15))))))),(t3,t2)),t1,t0);
+(((t5,t4),(((t3,t2),(t26,t27)),((t23,((t19,t20),((t22,t21),(t17,t18)))),(((t24,t25),(t13,t12)),(((((t6,t7),t8),(t10,t9)),t11),((t14,t15),t16)))))),t1,t0);
+((((t23,(((t22,t21),(t19,t20)),(t17,t18))),(((t14,t15),((t13,t12),t16)),((t24,t25),((((t6,t7),t8),(t10,t9)),t11)))),((t3,t2),((t5,t4),(t26,t27)))),t1,t0);
+((((t3,t2),(t5,t4)),((t26,t27),((((t24,t25),t23),(((t22,t21),(t19,t20)),(t17,t18))),(((t13,t12),((((t6,t7),t8),(t10,t9)),t11)),((t14,t15),t16))))),t1,t0);
+(((t5,t4),((((t25,t24),(t23,((t17,t18),((t19,t20),(t22,t21))))),(((t11,((t8,(t7,t6)),(t10,t9))),((t14,t15),t16)),(t13,t12))),((t3,t2),(t26,t27)))),t1,t0);
+(((t3,t2),((t5,t4),((t26,t27),((t23,((t17,t18),((t19,t20),(t22,t21)))),(((t14,t15),((t13,t12),((t25,t24),(t11,((t8,(t7,t6)),(t10,t9)))))),t16))))),t1,t0);
+(((t5,t4),(((t3,t2),(t26,t27)),((t23,((t17,t18),((t19,t20),(t22,t21)))),(((t13,t12),(t25,t24)),(((t14,t15),(t11,((t8,(t7,t6)),(t10,t9)))),t16))))),t1,t0);
+(((t3,t2),(((t26,t27),((t23,((t17,t18),(t21,((t19,t20),t22)))),((t25,t24),(((t13,t12),(t11,((t8,(t7,t6)),(t10,t9)))),(t16,(t14,t15)))))),(t5,t4))),t1,t0);
+(((t5,t4),((t26,t27),((t3,t2),((((t14,t15),((t13,t12),((t25,t24),(t11,((t8,(t7,t6)),(t10,t9)))))),(t23,((t17,t18),((t19,t20),(t22,t21))))),t16)))),t1,t0);
+(((t3,t2),((((((t11,((t8,(t7,t6)),(t10,t9))),(t13,t12)),(t14,t15)),((t25,t24),(t23,((t17,t18),((t19,t20),(t22,t21)))))),t16),((t5,t4),(t26,t27)))),t1,t0);
+((((t5,t4),((t26,t27),((t23,((t17,t18),((t19,t20),(t22,t21)))),((((t11,((t8,(t7,t6)),(t10,t9))),(t13,t12)),(t16,(t14,t15))),(t25,t24))))),(t3,t2)),t1,t0);
+(((t5,t4),(((t26,t27),((t23,((t17,t18),((t19,t20),(t22,t21)))),((((t11,((t8,(t7,t6)),(t10,t9))),(t13,t12)),(t16,(t14,t15))),(t25,t24)))),(t3,t2))),t1,t0);
+(((t3,t2),((t5,t4),((t26,t27),((t23,(((t17,t18),((t19,t20),t21)),t22)),((((t11,((t8,(t7,t6)),(t10,t9))),(t14,t15)),((t25,t24),(t13,t12))),t16))))),t1,t0);
+(((t3,t2),((t5,t4),((t26,t27),((t23,((t17,t18),((t19,t20),(t21,t22)))),((((t11,((t8,(t7,t6)),(t10,t9))),(t14,t15)),((t25,t24),(t13,t12))),t16))))),t1,t0);
diff --git a/inst/extdata/trees/RAxML_bootstrap.YCh b/inst/extdata/trees/RAxML_bootstrap.YCh
new file mode 100644
index 0000000..f660e60
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bootstrap.YCh
@@ -0,0 +1,250 @@
+((((Mur,Uth),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+((((Mur,Uth),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+((((Mur,Uth),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uth,Mur),(Hma,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uma,Uar))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+((((Mur,Uth),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+((((Mur,Uth),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+((((Mur,Uth),Hma),(Uam,(Uma,Uar))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+((((Uam,(Uma,Uar)),(Mur,Uth)),Hma),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,(Uam,(Uma,Uar))),(Mur,Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uma,Uar))),Tor,Ame);
+((((Uam,(Uma,Uar)),Hma),(Uth,Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Uth,Hma),Mur)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uar,(Uam,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,(Uam,(Uma,Uar))),(Mur,Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,(Uam,(Uma,Uar))),(Mur,Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uma,Uar)))),Tor,Ame);
+(((Uam,(Uma,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,(Uam,(Uma,Uar))),(Mur,Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,(Uam,(Uar,Uma))),(Mur,Uth)),Tor,Ame);
+(((Hma,(Uam,(Uar,Uma))),(Mur,Uth)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uar,(Uma,Uam)))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Uth,(Mur,Hma))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Uth,Mur),Hma)),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Mur,Uth),((Uam,(Uar,Uma)),Hma)),Tor,Ame);
+((((Hma,Mur),Uth),(Uam,(Uar,Uma))),Tor,Ame);
+((((Hma,Mur),Uth),(Uam,(Uar,Uma))),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uar,(Uma,Uam))),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uar,(Uma,Uam))),Tor,Ame);
+(((Uma,(Uam,Uar)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,(Mur,Uth)),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uth,(Hma,Mur)),(Uam,(Uar,Uma))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+(((Hma,Mur),(Uth,((Uma,Uar),Uam))),Tor,Ame);
+(((Uma,(Uar,Uam)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uma,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uma,Uar),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((Hma,((Uma,Uar),Uam)),(Uth,Mur)),Tor,Ame);
+(((Hma,Mur),(((Uma,Uar),Uam),Uth)),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((Hma,((Uma,Uar),Uam)),(Uth,Mur)),Tor,Ame);
+((((Uma,Uar),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+((((Uma,Uar),Uam),((Uth,Mur),Hma)),Tor,Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Mur,Uth),((Uam,(Uar,Uma)),Hma)),Ame);
+(Tor,((Mur,Uth),((Uam,(Uar,Uma)),Hma)),Ame);
+(Tor,(((Hma,Mur),Uth),(Uam,(Uar,Uma))),Ame);
+(Tor,((Mur,Uth),(Hma,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Mur,Uth),(Hma,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Hma,(Mur,Uth)),(Uma,(Uam,Uar))),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Hma,Mur),(Uth,(Uma,(Uam,Uar)))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uar,(Uma,Uam)),((Hma,Mur),Uth)),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Ame);
+(Tor,((Uam,(Uar,Uma)),((Mur,Uth),Hma)),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Ame);
+(Tor,((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Ame);
+(Tor,((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+(((Hma,Mur),(Uth,((Uar,Uma),Uam))),Tor,Ame);
+(((Hma,(Uth,Mur)),((Uar,Uma),Uam)),Tor,Ame);
+(((Hma,Mur),(Uth,((Uar,Uma),Uam))),Tor,Ame);
+(((Hma,Mur),(Uth,((Uar,Uma),Uam))),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+(((Hma,Mur),(Uth,((Uar,Uma),Uam))),Tor,Ame);
+((((Uth,Mur),Hma),((Uar,Uma),Uam)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uar,(Uma,Uam)))),Tor,Ame);
+(((Uma,(Uam,Uar)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Hma,(Uam,(Uar,Uma))),(Uth,Mur)),Tor,Ame);
+(((Hma,(Uam,(Uar,Uma))),(Uth,Mur)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uma,(Uam,Uar)))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+((((Uam,(Uar,Uma)),Hma),(Mur,Uth)),Tor,Ame);
+((((Hma,Mur),Uth),(Uam,(Uar,Uma))),Tor,Ame);
+((((Hma,Mur),Uth),(Uam,(Uar,Uma))),Tor,Ame);
+(((Uar,(Uma,Uam)),((Mur,Uth),Hma)),Tor,Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Hma,(Uam,(Uma,Uar))),(Uth,Mur)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Hma,Mur))),Ame);
+(Tor,((Uar,(Uam,Uma)),((Uth,Mur),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Uth,(Mur,Hma))),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uma,(Uar,Uam)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Uth),Hma)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uam,(Uma,Uar)),((Mur,Hma),Uth)),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(Tor,((Uam,(Uma,Uar)),(Hma,(Uth,Mur))),Ame);
+(((Hma,Mur),(Uth,((Uar,Uma),Uam))),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+(((((Uar,Uma),Uam),(Uth,Mur)),Hma),Tor,Ame);
+((((Uar,Uma),Uam),(Uth,(Hma,Mur))),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uar,(Uma,Uam)))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Uam,(Uar,Uma)),((Hma,Mur),Uth)),Tor,Ame);
+(((Hma,Mur),(Uth,(Uam,(Uar,Uma)))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Hma,(Mur,Uth))),Tor,Ame);
+(((Uam,(Uar,Uma)),(Uth,(Hma,Mur))),Tor,Ame);
+(((Uam,(Uar,Uma)),((Uth,Mur),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),Uam),(Hma,(Mur,Uth))),Tor,Ame);
+((((Uar,Uma),Uam),((Hma,Mur),Uth)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
+((((Uar,Uma),Uam),((Mur,Uth),Hma)),Tor,Ame);
diff --git a/inst/extdata/trees/RAxML_bootstrap.mtG b/inst/extdata/trees/RAxML_bootstrap.mtG
new file mode 100644
index 0000000..35d4f78
--- /dev/null
+++ b/inst/extdata/trees/RAxML_bootstrap.mtG
@@ -0,0 +1,100 @@
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Ame);
+(((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+(((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+(((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Tor,Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uam,Uth)))),Ame);
+(Tor,((Uth,(Hma,Uam)),(Mur,(Uma,Uar))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uam,Uth)))),Ame);
+(Tor,((Uma,Uar),((Hma,(Uam,Uth)),Mur)),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uam,Uth)))),Ame);
+(Tor,((Uma,Uar),((Hma,(Uam,Uth)),Mur)),Ame);
+(Tor,((Uma,Uar),((Hma,(Uam,Uth)),Mur)),Ame);
+(Tor,((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Ame);
+(Tor,((Hma,(Uth,Uam)),(Mur,(Uma,Uar))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Ame);
+(Tor,((Uth,(Uam,Hma)),(Mur,(Uma,Uar))),Ame);
+(Tor,((Uma,Uar),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,(Mur,((Uma,Uar),((Uth,Uam),Hma))),Ame);
+(Tor,(Mur,((Uma,Uar),((Uth,Uam),Hma))),Ame);
+(Tor,((Uma,Uar),(((Uth,Uam),Hma),Mur)),Ame);
+(Tor,((Uma,Uar),(((Uth,Uam),Hma),Mur)),Ame);
+(((Uar,Uma),(Mur,((Hma,Uam),Uth))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uar,Uma))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((Mur,((Uth,(Hma,Uam)),(Uar,Uma))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uar,Uma))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uar,Uma))),Tor,Ame);
+(((Uar,Uma),(Mur,(Hma,(Uam,Uth)))),Tor,Ame);
+((Mur,((Hma,(Uam,Uth)),(Uar,Uma))),Tor,Ame);
+(Tor,(Mur,((Uth,(Hma,Uam)),(Uma,Uar))),Ame);
+(Tor,((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Ame);
+(Tor,((Hma,(Uam,Uth)),((Uma,Uar),Mur)),Ame);
+(Tor,((Uma,Uar),(Mur,(Uth,(Hma,Uam)))),Ame);
+(Tor,((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Ame);
+(Tor,((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Ame);
+(Tor,((Uma,Uar),(Mur,(Hma,(Uam,Uth)))),Ame);
+(Tor,(Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Ame);
+(Tor,(Mur,((Hma,(Uam,Uth)),(Uma,Uar))),Ame);
+(Tor,(((Uma,Uar),(Hma,(Uth,Uam))),Mur),Ame);
+(Tor,(((Uma,Uar),(Hma,(Uth,Uam))),Mur),Ame);
+(Tor,(((Uma,Uar),(Hma,(Uth,Uam))),Mur),Ame);
+(Tor,((Uma,Uar),((Hma,(Uth,Uam)),Mur)),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Ame);
+(Tor,((Hma,(Uth,Uam)),(Mur,(Uma,Uar))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Ame);
+(Tor,(Mur,((Uma,Uar),(Hma,(Uth,Uam)))),Ame);
+(((Uar,Uma),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uth,Uam)))),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uth,Uam)))),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uth,Uam)))),Tor,Ame);
+(((Uar,Uma),((Hma,(Uth,Uam)),Mur)),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uth,Uam)))),Tor,Ame);
+(((Hma,(Uth,Uam)),(Mur,(Uar,Uma))),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uth,Uam)))),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uth,Uam)))),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uth,Uam)))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+(((Uar,Uma),(((Uam,Uth),Hma),Mur)),Tor,Ame);
+((Mur,((Uar,Uma),(Uth,(Hma,Uam)))),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Tor,Ame);
+(((Uar,Uma),((Hma,(Uam,Uth)),Mur)),Tor,Ame);
+(((Uar,Uma),((Hma,(Uam,Uth)),Mur)),Tor,Ame);
+(((Uar,Uma),(((Uam,Uth),Hma),Mur)),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+(((Uar,Uma),(((Uam,Uth),Hma),Mur)),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),((Uam,Uth),Hma))),Tor,Ame);
+((Mur,((Uar,Uma),(Uth,(Hma,Uam)))),Tor,Ame);
+((Mur,((Uar,Uma),(Hma,(Uam,Uth)))),Tor,Ame);
diff --git a/inst/extdata/trees/RAxML_distances.Wang.nxs b/inst/extdata/trees/RAxML_distances.Wang.nxs
new file mode 100644
index 0000000..d8cee65
--- /dev/null
+++ b/inst/extdata/trees/RAxML_distances.Wang.nxs
@@ -0,0 +1,1193 @@
+#nexus
+
+BEGIN Taxa;
+DIMENSIONS ntax=28;
+TAXLABELS
+[1] 't0'
+[2] 't1'
+[3] 't2'
+[4] 't3'
+[5] 't4'
+[6] 't5'
+[7] 't6'
+[8] 't7'
+[9] 't8'
+[10] 't9'
+[11] 't10'
+[12] 't11'
+[13] 't12'
+[14] 't13'
+[15] 't14'
+[16] 't15'
+[17] 't16'
+[18] 't17'
+[19] 't18'
+[20] 't19'
+[21] 't20'
+[22] 't21'
+[23] 't22'
+[24] 't23'
+[25] 't24'
+[26] 't25'
+[27] 't26'
+[28] 't27'
+;
+END; [Taxa]
+
+BEGIN Distances;
+DIMENSIONS ntax=28;
+FORMAT labels=no diagonal triangle=both;
+MATRIX
+ 0.0 0.258843 0.409325 0.343611 0.386997 0.415368 0.467334 0.473925 0.408069 0.420966 0.43411 0.394818 0.389391 0.391833 0.378215 0.350729 0.345639 0.384907 0.508726 0.36965 0.401646 0.425956 0.475112 0.398581 0.446356 0.436988 0.369089 0.354247
+ 0.258843 0.0 0.323278 0.239842 0.290738 0.303712 0.355727 0.361451 0.303126 0.328877 0.330235 0.305238 0.287997 0.28925 0.273233 0.243648 0.237544 0.285948 0.408866 0.273934 0.300483 0.316453 0.371314 0.289605 0.336424 0.335047 0.274434 0.251616
+ 0.409325 0.323278 0.0 0.192319 0.275137 0.292431 0.35189 0.362158 0.296773 0.310806 0.326997 0.296513 0.272283 0.273158 0.265655 0.23153 0.229852 0.269492 0.391463 0.269358 0.28426 0.330917 0.349753 0.285794 0.307787 0.311625 0.257636 0.248276
+ 0.343611 0.239842 0.192319 0.0 0.198776 0.213667 0.27468 0.280565 0.218724 0.241622 0.240754 0.218819 0.204383 0.202528 0.189195 0.15777 0.149061 0.201101 0.313442 0.193414 0.209843 0.237999 0.269041 0.214494 0.250222 0.253596 0.178383 0.171646
+ 0.386997 0.290738 0.275137 0.198776 0.0 0.18134 0.319484 0.333494 0.263994 0.288442 0.294154 0.26471 0.243803 0.240583 0.227367 0.205057 0.198308 0.234238 0.355626 0.239961 0.25183 0.273172 0.3179 0.251589 0.285163 0.292887 0.221681 0.211134
+ 0.415368 0.303712 0.292431 0.213667 0.18134 0.0 0.333731 0.340654 0.278111 0.300698 0.31011 0.28522 0.256139 0.258498 0.242481 0.221987 0.217595 0.24785 0.376793 0.252101 0.265266 0.293642 0.330253 0.272678 0.301029 0.302205 0.236378 0.229261
+ 0.467334 0.355727 0.35189 0.27468 0.319484 0.333731 0.0 0.134287 0.168048 0.234852 0.24194 0.242607 0.30195 0.305477 0.288246 0.259075 0.256117 0.302991 0.41738 0.288657 0.317827 0.340062 0.383568 0.3144 0.350638 0.345894 0.292802 0.279407
+ 0.473925 0.361451 0.362158 0.280565 0.333494 0.340654 0.134287 0.0 0.168357 0.231526 0.237933 0.239547 0.309204 0.307881 0.30116 0.27246 0.262342 0.317714 0.443878 0.299024 0.320617 0.343873 0.390457 0.316104 0.350009 0.345356 0.296305 0.28984
+ 0.408069 0.303126 0.296773 0.218724 0.263994 0.278111 0.168048 0.168357 0.0 0.18008 0.181142 0.185641 0.244912 0.248834 0.236322 0.207572 0.201513 0.24871 0.372027 0.240296 0.259989 0.292156 0.320957 0.261104 0.294639 0.291276 0.240866 0.224824
+ 0.420966 0.328877 0.310806 0.241622 0.288442 0.300698 0.234852 0.231526 0.18008 0.0 0.188549 0.209353 0.26783 0.265944 0.259007 0.231976 0.232078 0.276663 0.390486 0.266511 0.289918 0.309126 0.350459 0.278135 0.310626 0.303923 0.262268 0.254853
+ 0.43411 0.330235 0.326997 0.240754 0.294154 0.31011 0.24194 0.237933 0.181142 0.188549 0.0 0.200935 0.276708 0.271141 0.260416 0.23615 0.238456 0.275479 0.390198 0.26919 0.289665 0.316638 0.352527 0.291514 0.320199 0.321656 0.269881 0.254806
+ 0.394818 0.305238 0.296513 0.218819 0.26471 0.28522 0.242607 0.239547 0.185641 0.209353 0.200935 0.0 0.254629 0.248918 0.238901 0.214572 0.209137 0.247335 0.362256 0.244905 0.267859 0.289265 0.340281 0.26744 0.293766 0.290507 0.242726 0.227337
+ 0.389391 0.287997 0.272283 0.204383 0.243803 0.256139 0.30195 0.309204 0.244912 0.26783 0.276708 0.254629 0.0 0.106404 0.215913 0.18846 0.188488 0.229021 0.350267 0.227728 0.243568 0.27675 0.298806 0.241919 0.279501 0.27594 0.228754 0.217302
+ 0.391833 0.28925 0.273158 0.202528 0.240583 0.258498 0.305477 0.307881 0.248834 0.265944 0.271141 0.248918 0.106404 0.0 0.215622 0.188337 0.187822 0.231728 0.359961 0.226188 0.246065 0.271509 0.301748 0.242827 0.27931 0.272526 0.223715 0.214143
+ 0.378215 0.273233 0.265655 0.189195 0.227367 0.242481 0.288246 0.30116 0.236322 0.259007 0.260416 0.238901 0.215913 0.215622 0.0 0.105689 0.170273 0.214167 0.335401 0.21004 0.227981 0.248821 0.290917 0.229404 0.267494 0.265412 0.20581 0.199473
+ 0.350729 0.243648 0.23153 0.15777 0.205057 0.221987 0.259075 0.27246 0.207572 0.231976 0.23615 0.214572 0.18846 0.188337 0.105689 0.0 0.143812 0.184106 0.311927 0.183622 0.201611 0.220634 0.253471 0.201767 0.235578 0.234455 0.175537 0.16857
+ 0.345639 0.237544 0.229852 0.149061 0.198308 0.217595 0.256117 0.262342 0.201513 0.232078 0.238456 0.209137 0.188488 0.187822 0.170273 0.143812 0.0 0.184446 0.309875 0.181246 0.200167 0.221079 0.254232 0.201279 0.233194 0.23272 0.174841 0.166217
+ 0.384907 0.285948 0.269492 0.201101 0.234238 0.24785 0.302991 0.317714 0.24871 0.276663 0.275479 0.247335 0.229021 0.231728 0.214167 0.184106 0.184446 0.0 0.30631 0.205173 0.220753 0.263666 0.288162 0.231847 0.273379 0.270824 0.212613 0.200892
+ 0.508726 0.408866 0.391463 0.313442 0.355626 0.376793 0.41738 0.443878 0.372027 0.390486 0.390198 0.362256 0.350267 0.359961 0.335401 0.311927 0.309875 0.30631 0.0 0.328767 0.345767 0.375018 0.413708 0.353073 0.377324 0.383577 0.326556 0.324104
+ 0.36965 0.273934 0.269358 0.193414 0.239961 0.252101 0.288657 0.299024 0.240296 0.266511 0.26919 0.244905 0.227728 0.226188 0.21004 0.183622 0.181246 0.205173 0.328767 0.0 0.20445 0.244817 0.276658 0.231816 0.269496 0.272141 0.210992 0.20783
+ 0.401646 0.300483 0.28426 0.209843 0.25183 0.265266 0.317827 0.320617 0.259989 0.289918 0.289665 0.267859 0.243568 0.246065 0.227981 0.201611 0.200167 0.220753 0.345767 0.20445 0.0 0.26742 0.303242 0.250707 0.278888 0.278873 0.227446 0.228395
+ 0.425956 0.316453 0.330917 0.237999 0.273172 0.293642 0.340062 0.343873 0.292156 0.309126 0.316638 0.289265 0.27675 0.271509 0.248821 0.220634 0.221079 0.263666 0.375018 0.244817 0.26742 0.0 0.317486 0.270538 0.308484 0.306739 0.264346 0.244066
+ 0.475112 0.371314 0.349753 0.269041 0.3179 0.330253 0.383568 0.390457 0.320957 0.350459 0.352527 0.340281 0.298806 0.301748 0.290917 0.253471 0.254232 0.288162 0.413708 0.276658 0.303242 0.317486 0.0 0.305015 0.339609 0.342366 0.282416 0.276724
+ 0.398581 0.289605 0.285794 0.214494 0.251589 0.272678 0.3144 0.316104 0.261104 0.278135 0.291514 0.26744 0.241919 0.242827 0.229404 0.201767 0.201279 0.231847 0.353073 0.231816 0.250707 0.270538 0.305015 0.0 0.285912 0.284949 0.228325 0.220458
+ 0.446356 0.336424 0.307787 0.250222 0.285163 0.301029 0.350638 0.350009 0.294639 0.310626 0.320199 0.293766 0.279501 0.27931 0.267494 0.235578 0.233194 0.273379 0.377324 0.269496 0.278888 0.308484 0.339609 0.285912 0.0 0.097874 0.268769 0.255562
+ 0.436988 0.335047 0.311625 0.253596 0.292887 0.302205 0.345894 0.345356 0.291276 0.303923 0.321656 0.290507 0.27594 0.272526 0.265412 0.234455 0.23272 0.270824 0.383577 0.272141 0.278873 0.306739 0.342366 0.284949 0.097874 0.0 0.270444 0.256659
+ 0.369089 0.274434 0.257636 0.178383 0.221681 0.236378 0.292802 0.296305 0.240866 0.262268 0.269881 0.242726 0.228754 0.223715 0.20581 0.175537 0.174841 0.212613 0.326556 0.210992 0.227446 0.264346 0.282416 0.228325 0.268769 0.270444 0.0 0.183681
+ 0.354247 0.251616 0.248276 0.171646 0.211134 0.229261 0.279407 0.28984 0.224824 0.254853 0.254806 0.227337 0.217302 0.214143 0.199473 0.16857 0.166217 0.200892 0.324104 0.20783 0.228395 0.244066 0.276724 0.220458 0.255562 0.256659 0.183681 0.0
+;
+END; [Distances]
+
+BEGIN Splits;
+DIMENSIONS ntax=28 nsplits=90;
+FORMAT labels=no weights=yes confidences=no intervals=no;
+PROPERTIES fit=98.91263210217491 cyclic;
+CYCLE 1 3 4 5 6 17 15 16 13 14 12 10 11 9 8 7 26 25 19 18 21 20 23 22 24 27 28 2;
+MATRIX
+[1, size=1] 	 0.1279713 	  1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[2, size=2] 	 0.017143281 	  1 2 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[3, size=4] 	 0.0013902244 	  1 2 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[4, size=9] 	 1.5893235E-4 	  1 2 7 8 9 10 11 12 18 19 20 21 22 23 24 25 26 27 28,
+[5, size=3] 	 0.002769119 	  1 2 28,
+[6, size=2] 	 0.08403672 	  1 2,
+[7, size=1] 	 0.17367192 	  1,
+[8, size=1] 	 0.057841897 	  1 2 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[9, size=3] 	 1.7729466E-4 	  1 2 3 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[10, size=5] 	 3.662799E-4 	  1 2 3 7 8 9 10 11 12 13 14 16 18 19 20 21 22 23 24 25 26 27 28,
+[11, size=2] 	 0.0060906718 	  1 3,
+[12, size=1] 	 0.08134686 	  1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[13, size=2] 	 0.038590923 	  1 2 3 4 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[14, size=4] 	 0.0018195357 	  1 2 3 4,
+[15, size=1] 	 0.09856205 	  1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[16, size=8] 	 4.167727E-4 	  1 2 3 4 5 24 27 28,
+[17, size=4] 	 0.0012588556 	  1 3 4 5,
+[18, size=1] 	 0.0688266 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 28,
+[19, size=3] 	 8.21237E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 18 19 20 21 22 23 24 25 26 27 28,
+[20, size=12] 	 8.992125E-4 	  1 2 3 4 5 6 18 19 20 21 22 23 24 25 27 28,
+[21, size=8] 	 0.0022681346 	  1 2 3 4 5 6 27 28,
+[22, size=1] 	 0.0665534 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[23, size=2] 	 0.03262534 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 17 18 19 20 21 22 23 24 25 26 27 28,
+[24, size=3] 	 4.7089203E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 14 17 18 19 20 21 22 23 24 25 26 27 28,
+[25, size=4] 	 4.685271E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 17 18 19 20 21 22 23 24 25 26 27 28,
+[26, size=9] 	 0.0010168224 	  1 2 3 4 5 6 17 27 28,
+[27, size=1] 	 0.03859058 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 18 19 20 21 22 23 24 25 26 27 28,
+[28, size=3] 	 3.5754856E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 15 17 18 19 20 21 22 23 24 25 26 27 28,
+[29, size=1] 	 0.052748006 	  1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[30, size=2] 	 0.06064433 	  1 2 3 4 5 6 7 8 9 10 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[31, size=7] 	 0.0010652957 	  1 2 3 4 5 6 7 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[32, size=9] 	 7.895848E-4 	  1 2 3 4 5 6 15 16 17 18 19 20 21 22 23 24 25 27 28,
+[33, size=1] 	 0.05142635 	  1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[34, size=4] 	 0.0011806624 	  1 2 3 4 5 6 7 8 9 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[35, size=8] 	 1.787175E-4 	  1 2 3 4 5 6 13 15 16 17 18 19 20 21 22 23 24 25 27 28,
+[36, size=9] 	 8.855418E-4 	  1 2 3 4 5 6 13 15 16 17 18 19 20 21 22 23 24 27 28,
+[37, size=1] 	 0.0914247 	  1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[38, size=5] 	 0.0012966593 	  1 2 3 4 5 6 7 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[39, size=6] 	 0.038550336 	  1 2 3 4 5 6 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[40, size=9] 	 0.001203692 	  1 2 3 4 5 6 13 14 15 16 17 18 20 21 22 23 24 27 28,
+[41, size=1] 	 0.092642605 	  1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[42, size=2] 	 0.0044335932 	  1 2 3 4 5 6 7 8 9 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[43, size=4] 	 0.0014246248 	  1 2 3 4 5 6 7 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[44, size=5] 	 0.012698617 	  1 2 3 4 5 6 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[45, size=7] 	 2.5534217E-4 	  1 2 3 4 5 6 12 13 14 15 16 17 18 19 20 21 22 23 24 27 28,
+[46, size=1] 	 0.09702029 	  1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[47, size=4] 	 0.0010406735 	  1 2 3 4 5 6 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[48, size=1] 	 0.05344081 	  1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[49, size=3] 	 0.021949023 	  1 2 3 4 5 6 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[50, size=14] 	 3.9997647E-4 	  1 2 3 4 5 6 10 11 12 13 14 15 16 17,
+[51, size=1] 	 0.06783958 	  1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[52, size=2] 	 0.04591966 	  1 2 3 4 5 6 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[53, size=3] 	 2.8627258E-4 	  1 2 3 4 5 6 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28,
+[54, size=4] 	 4.0487162E-4 	  1 2 3 4 5 6 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 27 28,
+[55, size=1] 	 0.064194575 	  1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+[56, size=1] 	 0.047182973 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28,
+[57, size=2] 	 0.10500158 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 27 28,
+[58, size=3] 	 0.0014762296 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 27 28,
+[59, size=5] 	 0.001466786 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 20 22 23 24 27 28,
+[60, size=8] 	 8.702291E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 24 27 28,
+[61, size=9] 	 0.0010516174 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 27 28,
+[62, size=1] 	 0.044313457 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 28,
+[63, size=2] 	 0.004750093 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 26 27 28,
+[64, size=6] 	 1.337294E-5 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 22 24 26 27 28,
+[65, size=1] 	 0.20566262 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28,
+[66, size=2] 	 0.013317523 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 28,
+[67, size=4] 	 0.0021476466 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 22 23 24 25 26 27 28,
+[68, size=8] 	 0.0015038507 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 25 26 28,
+[69, size=1] 	 0.09029672 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28,
+[70, size=2] 	 1.5751319E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 22 23 24 25 26 27 28,
+[71, size=4] 	 0.0019187863 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 22 24 25 26 27 28,
+[72, size=1] 	 0.109228075 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28,
+[73, size=2] 	 0.006326371 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 22 23 24 25 26 27 28,
+[74, size=4] 	 0.0023116763 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 24 25 26 27 28,
+[75, size=1] 	 0.089916565 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28,
+[76, size=2] 	 1.050739E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 24 25 26 27 28,
+[77, size=3] 	 0.0016833246 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 24 25 26 27 28,
+[78, size=1] 	 0.17474917 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 25 26 27 28,
+[79, size=2] 	 0.0022174222 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 24 25 26 27 28,
+[80, size=3] 	 0.001391344 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 25 26 27 28,
+[81, size=5] 	 4.242624E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 25 26,
+[82, size=1] 	 0.13961297 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 23 24 25 26 27 28,
+[83, size=2] 	 0.0013124112 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 23 25 26 27 28,
+[84, size=1] 	 0.1194786 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 25 26 27 28,
+[85, size=2] 	 4.8682792E-4 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 25 26 28,
+[86, size=1] 	 0.09366718 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28,
+[87, size=2] 	 0.0045568696 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26,
+[88, size=1] 	 0.08093566 	  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27,
+[89, size=2] 	 0.0015117239 	  1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27,
+[90, size=1] 	 0.076351464 	  1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28,
+;
+END; [Splits]
+
+BEGIN Network;
+DIMENSIONS ntax=28 nvertices=346 nedges=600;
+DRAW to_scale;
+TRANSLATE
+2 't0',
+3 't2',
+4 't3',
+5 't4',
+6 't5',
+7 't16',
+8 't14',
+9 't15',
+10 't12',
+11 't13',
+12 't11',
+13 't9',
+14 't10',
+15 't8',
+16 't7',
+17 't6',
+18 't25',
+19 't24',
+20 't18',
+21 't17',
+22 't20',
+23 't19',
+24 't22',
+25 't21',
+26 't23',
+27 't26',
+28 't27',
+29 't1',
+;
+VERTICES
+1 -0.17367192 0.0 w=2 h=2 s=n,
+2 0.0 0.0 w=2 h=2 s=n,
+3 -0.11768977 0.045046512 w=2 h=2 s=n,
+4 -0.19602421 0.041381847 w=2 h=2 s=n,
+5 -0.17523988 0.08842624 w=2 h=2 s=n,
+6 -0.17898935 0.1143971 w=2 h=2 s=n,
+7 -0.24188966 0.07239327 w=2 h=2 s=n,
+8 -0.2543338 0.10839781 w=2 h=2 s=n,
+9 -0.26945123 0.082165845 w=2 h=2 s=n,
+10 -0.30659822 0.12002788 w=2 h=2 s=n,
+11 -0.31904063 0.11555596 w=2 h=2 s=n,
+12 -0.3723963 0.09579757 w=2 h=2 s=n,
+13 -0.40555912 0.08773562 w=2 h=2 s=n,
+14 -0.4215746 0.07218595 w=2 h=2 s=n,
+15 -0.40375552 0.03841092 w=2 h=2 s=n,
+16 -0.46578634 0.021180429 w=2 h=2 s=n,
+17 -0.457186 0.0051984675 w=2 h=2 s=n,
+18 -0.4112275 -0.0713001 w=2 h=2 s=n,
+19 -0.40493098 -0.082802355 w=2 h=2 s=n,
+20 -0.41573197 -0.17496379 w=2 h=2 s=n,
+21 -0.32123187 -0.093300976 w=2 h=2 s=n,
+22 -0.29972327 -0.1157434 w=2 h=2 s=n,
+23 -0.27406484 -0.09962054 w=2 h=2 s=n,
+24 -0.23216128 -0.17543635 w=2 h=2 s=n,
+25 -0.2095651 -0.12994294 w=2 h=2 s=n,
+26 -0.19596717 -0.09110639 w=2 h=2 s=n,
+27 -0.19119321 -0.05464892 w=2 h=2 s=n,
+28 -0.1878907 -0.030641899 w=2 h=2 s=n,
+29 -0.10504844 -0.018586801 w=2 h=2 s=n,
+30 -0.25718024 0.009409128 w=2 h=2 s=n,
+31 -0.26323262 0.008727189 w=2 h=2 s=n,
+32 -0.17972429 -6.819389E-4 w=2 h=2 s=n,
+33 -0.25987992 0.010025315 w=2 h=2 s=n,
+34 -0.2659323 0.009343375 w=2 h=2 s=n,
+35 -0.2677404 0.009139652 w=2 h=2 s=n,
+36 -0.2650407 0.008523465 w=2 h=2 s=n,
+37 -0.26892862 0.008723878 w=2 h=2 s=n,
+38 -0.2662289 0.008107692 w=2 h=2 s=n,
+39 -0.2644208 0.008311415 w=2 h=2 s=n,
+40 -0.18091251 -0.0010977125 w=2 h=2 s=n,
+41 -0.26934275 0.008770542 w=2 h=2 s=n,
+42 -0.27159664 0.008516592 w=2 h=2 s=n,
+43 -0.27118248 0.008469928 w=2 h=2 s=n,
+44 -0.27258795 0.008290328 w=2 h=2 s=n,
+45 -0.27217382 0.008243664 w=2 h=2 s=n,
+46 -0.27272007 0.007912797 w=2 h=2 s=n,
+47 -0.2723059 0.007866133 w=2 h=2 s=n,
+48 -0.2713146 0.008092397 w=2 h=2 s=n,
+49 -0.2690607 0.008346348 w=2 h=2 s=n,
+50 -0.26636103 0.007730161 w=2 h=2 s=n,
+51 -0.27223247 0.009152431 w=2 h=2 s=n,
+52 -0.2732238 0.008926167 w=2 h=2 s=n,
+53 -0.2733559 0.008548636 w=2 h=2 s=n,
+54 -0.25981095 0.010168508 w=2 h=2 s=n,
+55 -0.26586333 0.009486569 w=2 h=2 s=n,
+56 -0.26767144 0.009282845 w=2 h=2 s=n,
+57 -0.26885965 0.008867072 w=2 h=2 s=n,
+58 -0.2692738 0.008913736 w=2 h=2 s=n,
+59 -0.27152768 0.008659785 w=2 h=2 s=n,
+60 -0.2721635 0.009295625 w=2 h=2 s=n,
+61 -0.27315485 0.00906936 w=2 h=2 s=n,
+62 -0.27386624 0.009411948 w=2 h=2 s=n,
+63 -0.2739352 0.009268755 w=2 h=2 s=n,
+64 -0.27406728 0.008891224 w=2 h=2 s=n,
+65 -0.27472958 0.009609 w=2 h=2 s=n,
+66 -0.27479854 0.009465806 w=2 h=2 s=n,
+67 -0.27493063 0.009088275 w=2 h=2 s=n,
+68 -0.27421924 0.008745687 w=2 h=2 s=n,
+69 -0.2735834 0.008109848 w=2 h=2 s=n,
+70 -0.27600223 0.009465806 w=2 h=2 s=n,
+71 -0.27613434 0.009088275 w=2 h=2 s=n,
+72 -0.27542293 0.008745687 w=2 h=2 s=n,
+73 -0.2747871 0.008109848 w=2 h=2 s=n,
+74 -0.27392375 0.007912797 w=2 h=2 s=n,
+75 -0.27636832 0.008063024 w=2 h=2 s=n,
+76 -0.27565694 0.0077204364 w=2 h=2 s=n,
+77 -0.2750211 0.007084597 w=2 h=2 s=n,
+78 -0.27415776 0.0068875453 w=2 h=2 s=n,
+79 -0.27295408 0.0068875453 w=2 h=2 s=n,
+80 -0.2725399 0.0068408814 w=2 h=2 s=n,
+81 -0.27489826 0.009668026 w=2 h=2 s=n,
+82 -0.27496722 0.009524833 w=2 h=2 s=n,
+83 -0.2761709 0.009524833 w=2 h=2 s=n,
+84 -0.27630302 0.009147302 w=2 h=2 s=n,
+85 -0.27653703 0.008122051 w=2 h=2 s=n,
+86 -0.27682444 0.0073006563 w=2 h=2 s=n,
+87 -0.27665576 0.0072416295 w=2 h=2 s=n,
+88 -0.27594435 0.0068990416 w=2 h=2 s=n,
+89 -0.27530852 0.006263202 w=2 h=2 s=n,
+90 -0.27444518 0.0060661505 w=2 h=2 s=n,
+91 -0.2732415 0.0060661505 w=2 h=2 s=n,
+92 -0.2742768 0.004571756 w=2 h=2 s=n,
+93 -0.2730731 0.004571756 w=2 h=2 s=n,
+94 -0.2727857 0.0053931507 w=2 h=2 s=n,
+95 -0.27237153 0.005346487 w=2 h=2 s=n,
+96 -0.27213752 0.006371738 w=2 h=2 s=n,
+97 -0.2711462 0.0065980023 w=2 h=2 s=n,
+98 -0.26889235 0.006851953 w=2 h=2 s=n,
+99 -0.27469912 0.010076149 w=2 h=2 s=n,
+100 -0.27556247 0.0102732 w=2 h=2 s=n,
+101 -0.27573115 0.010332228 w=2 h=2 s=n,
+102 -0.2758001 0.010189034 w=2 h=2 s=n,
+103 -0.2770038 0.010189034 w=2 h=2 s=n,
+104 -0.2771359 0.009811503 w=2 h=2 s=n,
+105 -0.27725914 0.010189034 w=2 h=2 s=n,
+106 -0.27739123 0.009811503 w=2 h=2 s=n,
+107 -0.27655837 0.009147302 w=2 h=2 s=n,
+108 -0.27679238 0.008122051 w=2 h=2 s=n,
+109 -0.2770798 0.0073006563 w=2 h=2 s=n,
+110 -0.2769111 0.0072416295 w=2 h=2 s=n,
+111 -0.2761997 0.0068990416 w=2 h=2 s=n,
+112 -0.27556387 0.006263202 w=2 h=2 s=n,
+113 -0.31339082 0.022921404 w=2 h=2 s=n,
+114 -0.31364617 0.022921404 w=2 h=2 s=n,
+115 -0.31377825 0.022543872 w=2 h=2 s=n,
+116 -0.31294537 0.021879671 w=2 h=2 s=n,
+117 -0.27556828 0.00625058 w=2 h=2 s=n,
+118 -0.27531293 0.00625058 w=2 h=2 s=n,
+119 -0.2744496 0.0060535283 w=2 h=2 s=n,
+120 -0.27428123 0.004559133 w=2 h=2 s=n,
+121 -0.27307752 0.004559133 w=2 h=2 s=n,
+122 -0.26563498 0.009772938 w=2 h=2 s=n,
+123 -0.26744306 0.009569215 w=2 h=2 s=n,
+124 -0.26863128 0.009153441 w=2 h=2 s=n,
+125 -0.26904544 0.0092001045 w=2 h=2 s=n,
+126 -0.2712993 0.008946154 w=2 h=2 s=n,
+127 -0.27193514 0.009581993 w=2 h=2 s=n,
+128 -0.27292648 0.009355729 w=2 h=2 s=n,
+129 -0.31455907 0.023484003 w=2 h=2 s=n,
+130 -0.31481442 0.023484003 w=2 h=2 s=n,
+131 -0.3149465 0.02310647 w=2 h=2 s=n,
+132 -0.32719463 0.02630971 w=2 h=2 s=n,
+133 -0.32732674 0.02593218 w=2 h=2 s=n,
+134 -0.3261585 0.02536958 w=2 h=2 s=n,
+135 -0.3253256 0.024705378 w=2 h=2 s=n,
+136 -0.2779943 0.0061538764 w=2 h=2 s=n,
+137 -0.27782562 0.00609485 w=2 h=2 s=n,
+138 -0.27711424 0.005752262 w=2 h=2 s=n,
+139 -0.27647838 0.0051164227 w=2 h=2 s=n,
+140 -0.27648282 0.0051038004 w=2 h=2 s=n,
+141 -0.27622747 0.0051038004 w=2 h=2 s=n,
+142 -0.27536413 0.004906749 w=2 h=2 s=n,
+143 -0.27519575 0.0034123538 w=2 h=2 s=n,
+144 -0.27399206 0.0034123538 w=2 h=2 s=n,
+145 -0.272813 0.0042274315 w=2 h=2 s=n,
+146 -0.27280858 0.004240054 w=2 h=2 s=n,
+147 -0.27252117 0.005061449 w=2 h=2 s=n,
+148 -0.272107 0.005014785 w=2 h=2 s=n,
+149 -0.271873 0.006040036 w=2 h=2 s=n,
+150 -0.27088168 0.0062663006 w=2 h=2 s=n,
+151 -0.26862782 0.0065202513 w=2 h=2 s=n,
+152 -0.26879618 0.008014646 w=2 h=2 s=n,
+153 -0.2660965 0.007398459 w=2 h=2 s=n,
+154 -0.25863382 0.010908152 w=2 h=2 s=n,
+155 -0.2646862 0.010226212 w=2 h=2 s=n,
+156 -0.26445782 0.010512582 w=2 h=2 s=n,
+157 -0.26626593 0.010308859 w=2 h=2 s=n,
+158 -0.26745415 0.009893085 w=2 h=2 s=n,
+159 -0.26786828 0.009939749 w=2 h=2 s=n,
+160 -0.27297893 0.009821311 w=2 h=2 s=n,
+161 -0.2732073 0.009534941 w=2 h=2 s=n,
+162 -0.2739187 0.009877529 w=2 h=2 s=n,
+163 -0.27475157 0.010541731 w=2 h=2 s=n,
+164 -0.27561492 0.010738782 w=2 h=2 s=n,
+165 -0.2757836 0.010797808 w=2 h=2 s=n,
+166 -0.27661845 0.011632663 w=2 h=2 s=n,
+167 -0.276566 0.011167082 w=2 h=2 s=n,
+168 -0.27663496 0.011023888 w=2 h=2 s=n,
+169 -0.27783865 0.011023888 w=2 h=2 s=n,
+170 -0.31422567 0.023756258 w=2 h=2 s=n,
+171 -0.31539392 0.024318857 w=2 h=2 s=n,
+172 -0.31564927 0.024318857 w=2 h=2 s=n,
+173 -0.32802948 0.027144564 w=2 h=2 s=n,
+174 -0.32937416 0.027615089 w=2 h=2 s=n,
+175 -0.3285393 0.026780235 w=2 h=2 s=n,
+176 -0.32867143 0.026402703 w=2 h=2 s=n,
+177 -0.3304083 0.027731607 w=2 h=2 s=n,
+178 -0.32957345 0.026896752 w=2 h=2 s=n,
+179 -0.32970557 0.026519222 w=2 h=2 s=n,
+180 -0.3283609 0.026048698 w=2 h=2 s=n,
+181 -0.32719263 0.025486099 w=2 h=2 s=n,
+182 -0.32635975 0.024821898 w=2 h=2 s=n,
+183 -0.3300877 0.026385501 w=2 h=2 s=n,
+184 -0.32874304 0.025914976 w=2 h=2 s=n,
+185 -0.3275748 0.025352377 w=2 h=2 s=n,
+186 -0.3267419 0.024688177 w=2 h=2 s=n,
+187 -0.32570776 0.024571659 w=2 h=2 s=n,
+188 -0.31332752 0.02174595 w=2 h=2 s=n,
+189 -0.2769405 0.009013581 w=2 h=2 s=n,
+190 -0.2771745 0.00798833 w=2 h=2 s=n,
+191 -0.27746195 0.0071669356 w=2 h=2 s=n,
+192 -0.27837646 0.006020156 w=2 h=2 s=n,
+193 -0.27820778 0.0059611294 w=2 h=2 s=n,
+194 -0.27749637 0.0056185415 w=2 h=2 s=n,
+195 -0.27686054 0.004982702 w=2 h=2 s=n,
+196 -0.27686495 0.0049700798 w=2 h=2 s=n,
+197 -0.27590507 0.001385226 w=2 h=2 s=n,
+198 -0.2747014 0.001385226 w=2 h=2 s=n,
+199 -0.27378684 0.0025320055 w=2 h=2 s=n,
+200 -0.2749162 -5.2149536E-4 w=2 h=2 s=n,
+201 -0.2740017 6.252841E-4 w=2 h=2 s=n,
+202 -0.27329236 0.002652412 w=2 h=2 s=n,
+203 -0.27302784 0.0023207103 w=2 h=2 s=n,
+204 -0.2746574 -0.0028186364 w=2 h=2 s=n,
+205 -0.27374285 -0.0016718569 w=2 h=2 s=n,
+206 -0.27303353 3.55271E-4 w=2 h=2 s=n,
+207 -0.272769 2.3569324E-5 w=2 h=2 s=n,
+208 -0.2725542 0.0019302907 w=2 h=2 s=n,
+209 -0.27254978 0.0019429132 w=2 h=2 s=n,
+210 -0.2643192 0.0106231235 w=2 h=2 s=n,
+211 -0.26612732 0.0104194 w=2 h=2 s=n,
+212 -0.26731554 0.010003626 w=2 h=2 s=n,
+213 -0.26772967 0.01005029 w=2 h=2 s=n,
+214 -0.2717524 0.01038264 w=2 h=2 s=n,
+215 -0.27274373 0.010156376 w=2 h=2 s=n,
+216 -0.27279618 0.0106219575 w=2 h=2 s=n,
+217 -0.27302456 0.010335588 w=2 h=2 s=n,
+218 -0.27279618 0.011092849 w=2 h=2 s=n,
+219 -0.27302456 0.01080648 w=2 h=2 s=n,
+220 -0.2732073 0.010005834 w=2 h=2 s=n,
+221 -0.2739187 0.0103484215 w=2 h=2 s=n,
+222 -0.27475157 0.011012622 w=2 h=2 s=n,
+223 -0.27310413 0.011155064 w=2 h=2 s=n,
+224 -0.27328685 0.010354417 w=2 h=2 s=n,
+225 -0.27399826 0.010697005 w=2 h=2 s=n,
+226 -0.27483115 0.011361206 w=2 h=2 s=n,
+227 -0.27483115 0.010890314 w=2 h=2 s=n,
+228 -0.2756945 0.011087365 w=2 h=2 s=n,
+229 -0.27586317 0.011146393 w=2 h=2 s=n,
+230 -0.27669802 0.011981247 w=2 h=2 s=n,
+231 -0.3516546 0.026519222 w=2 h=2 s=n,
+232 -0.3520367 0.026385501 w=2 h=2 s=n,
+233 -0.35069206 0.025914976 w=2 h=2 s=n,
+234 -0.3495238 0.025352377 w=2 h=2 s=n,
+235 -0.34869093 0.024688177 w=2 h=2 s=n,
+236 -0.3523158 0.026321799 w=2 h=2 s=n,
+237 -0.35097113 0.025851276 w=2 h=2 s=n,
+238 -0.34980288 0.025288677 w=2 h=2 s=n,
+239 -0.34897003 0.024624474 w=2 h=2 s=n,
+240 -0.327021 0.024624474 w=2 h=2 s=n,
+241 -0.32598686 0.024507957 w=2 h=2 s=n,
+242 -0.31360662 0.02168225 w=2 h=2 s=n,
+243 -0.2772196 0.00894988 w=2 h=2 s=n,
+244 -0.2774536 0.007924628 w=2 h=2 s=n,
+245 -0.27774104 0.007103234 w=2 h=2 s=n,
+246 -0.27865556 0.005956454 w=2 h=2 s=n,
+247 -0.2798097 0.00503604 w=2 h=2 s=n,
+248 -0.2795306 0.0050997417 w=2 h=2 s=n,
+249 -0.27936193 0.0050407154 w=2 h=2 s=n,
+250 -0.27865055 0.004698127 w=2 h=2 s=n,
+251 -0.27801472 0.004062288 w=2 h=2 s=n,
+252 -0.27801913 0.0040496653 w=2 h=2 s=n,
+253 -0.27763698 0.004183386 w=2 h=2 s=n,
+254 -0.27738163 0.004183386 w=2 h=2 s=n,
+255 -0.2765183 0.0039863344 w=2 h=2 s=n,
+256 -0.2763499 0.0024919398 w=2 h=2 s=n,
+257 -0.27705923 4.648119E-4 w=2 h=2 s=n,
+258 -0.2733683 -0.003312977 w=2 h=2 s=n,
+259 -0.27265897 -0.0012858491 w=2 h=2 s=n,
+260 -0.27239445 -0.0016175507 w=2 h=2 s=n,
+261 -0.2721796 2.891706E-4 w=2 h=2 s=n,
+262 -0.2721752 3.017931E-4 w=2 h=2 s=n,
+263 -0.27179077 -0.0028711085 w=2 h=2 s=n,
+264 -0.27157593 -9.64387E-4 w=2 h=2 s=n,
+265 -0.27157152 -9.517645E-4 w=2 h=2 s=n,
+266 -0.27194607 6.893556E-4 w=2 h=2 s=n,
+267 -0.2722049 0.0029864965 w=2 h=2 s=n,
+268 -0.2719175 0.0038078912 w=2 h=2 s=n,
+269 -0.27150333 0.0037612275 w=2 h=2 s=n,
+270 -0.24245258 0.016570218 w=2 h=2 s=n,
+271 -0.24850495 0.01588828 w=2 h=2 s=n,
+272 -0.24827658 0.016174648 w=2 h=2 s=n,
+273 -0.24813797 0.01628519 w=2 h=2 s=n,
+274 -0.23883942 0.037707303 w=2 h=2 s=n,
+275 -0.24002762 0.03729153 w=2 h=2 s=n,
+276 -0.24044177 0.037338194 w=2 h=2 s=n,
+277 -0.2691433 0.04351305 w=2 h=2 s=n,
+278 -0.2693717 0.043226678 w=2 h=2 s=n,
+279 -0.26945123 0.043575265 w=2 h=2 s=n,
+280 -0.2948607 0.068602376 w=2 h=2 s=n,
+281 -0.2948607 0.068131484 w=2 h=2 s=n,
+282 -0.29572403 0.06832854 w=2 h=2 s=n,
+283 -0.29589272 0.06838756 w=2 h=2 s=n,
+284 -0.29672757 0.06922242 w=2 h=2 s=n,
+285 -0.3331282 0.029973902 w=2 h=2 s=n,
+286 -0.33416232 0.030090421 w=2 h=2 s=n,
+287 -0.39794675 0.021180429 w=2 h=2 s=n,
+288 -0.39660206 0.020709904 w=2 h=2 s=n,
+289 -0.3954338 0.020147305 w=2 h=2 s=n,
+290 -0.39460093 0.019483104 w=2 h=2 s=n,
+291 -0.3687171 -0.05082817 w=2 h=2 s=n,
+292 -0.368438 -0.050764468 w=2 h=2 s=n,
+293 -0.36826932 -0.050823495 w=2 h=2 s=n,
+294 -0.3675579 -0.051166084 w=2 h=2 s=n,
+295 -0.36692208 -0.051801924 w=2 h=2 s=n,
+296 -0.3669265 -0.051814545 w=2 h=2 s=n,
+297 -0.37028533 -0.055173367 w=2 h=2 s=n,
+298 -0.28137794 6.908425E-4 w=2 h=2 s=n,
+299 -0.2809958 8.2456315E-4 w=2 h=2 s=n,
+300 -0.28074044 8.2456315E-4 w=2 h=2 s=n,
+301 -0.27987713 6.275116E-4 w=2 h=2 s=n,
+302 -0.27970874 -8.668832E-4 w=2 h=2 s=n,
+303 -0.28041807 -0.002894011 w=2 h=2 s=n,
+304 -0.2875034 -0.01417028 w=2 h=2 s=n,
+305 -0.28414458 -0.0108114565 w=2 h=2 s=n,
+306 -0.28299043 -0.0098910425 w=2 h=2 s=n,
+307 -0.28178674 -0.0098910425 w=2 h=2 s=n,
+308 -0.28200155 -0.011797764 w=2 h=2 s=n,
+309 -0.2820536 -0.011946438 w=2 h=2 s=n,
+310 -0.27496824 -6.701694E-4 w=2 h=2 s=n,
+311 -0.2747094 -0.0029673104 w=2 h=2 s=n,
+312 -0.27541775 -0.009253902 w=2 h=2 s=n,
+313 -0.2753657 -0.009105228 w=2 h=2 s=n,
+314 -0.2744512 -0.0079584485 w=2 h=2 s=n,
+315 -0.2740766 -0.009599569 w=2 h=2 s=n,
+316 -0.27406484 -0.009703982 w=2 h=2 s=n,
+317 -0.27335653 -0.0034173902 w=2 h=2 s=n,
+318 -0.2726472 -0.0013902623 w=2 h=2 s=n,
+319 -0.27238268 -0.001721964 w=2 h=2 s=n,
+320 -0.271779 -0.0029755216 w=2 h=2 s=n,
+321 -0.27104664 -0.0050685094 w=2 h=2 s=n,
+322 -0.27105838 -0.0049640965 w=2 h=2 s=n,
+323 -0.27084357 -0.0030573749 w=2 h=2 s=n,
+324 -0.27083912 -0.0030447524 w=2 h=2 s=n,
+325 -0.2701409 -0.004156003 w=2 h=2 s=n,
+326 -0.27087325 -0.0020630148 w=2 h=2 s=n,
+327 -0.27124783 -4.218947E-4 w=2 h=2 s=n,
+328 -0.27150667 0.0018752463 w=2 h=2 s=n,
+329 -0.27121925 0.002696641 w=2 h=2 s=n,
+330 -0.2708051 0.0026499773 w=2 h=2 s=n,
+331 -0.27046084 0.002305738 w=2 h=2 s=n,
+332 -0.2711591 0.0034169883 w=2 h=2 s=n,
+333 -0.2717628 0.004670546 w=2 h=2 s=n,
+334 -0.27152878 0.005695797 w=2 h=2 s=n,
+335 -0.27053744 0.0059220614 w=2 h=2 s=n,
+336 -0.26828358 0.0061760116 w=2 h=2 s=n,
+337 -0.26442516 0.003751611 w=2 h=2 s=n,
+338 -0.2647694 0.0040958505 w=2 h=2 s=n,
+339 -0.2649378 0.005590245 w=2 h=2 s=n,
+340 -0.2622381 0.0049740584 w=2 h=2 s=n,
+341 -0.26081118 0.0044747675 w=2 h=2 s=n,
+342 -0.2646696 0.0068991682 w=2 h=2 s=n,
+343 -0.26493412 0.00723087 w=2 h=2 s=n,
+344 -0.26480204 0.007608401 w=2 h=2 s=n,
+345 -0.26299393 0.007812124 w=2 h=2 s=n,
+346 -0.17948562 -0.0015970032 w=2 h=2 s=n,
+;
+VLABELS
+2 't0' x=12 y=6 f='Dialog-PLAIN-10',
+3 't2' x=12 y=9,
+4 't3' x=11 y=11,
+5 't4' x=9 y=13,
+6 't5' x=3 y=20,
+7 't16' x=-3 y=22,
+8 't14' x=-5 y=23,
+9 't15' x=-8 y=23,
+10 't12' x=-11 y=23,
+11 't13' x=-13 y=17,
+12 't11' x=-16 y=20,
+13 't9' x=-19 y=13,
+14 't10' x=-27 y=11,
+15 't8' x=-22 y=9,
+16 't7' x=-22 y=6,
+17 't6' x=-22 y=3,
+18 't25' x=-27 y=1,
+19 't24' x=-25 y=-1,
+20 't18' x=-15 y=-13,
+21 't17' x=-13 y=-15,
+22 't20' x=-11 y=-16,
+23 't19' x=-8 y=-16,
+24 't22' x=-5 y=-16,
+25 't21' x=-3 y=-15,
+26 't23' x=-1 y=-13,
+27 't26' x=9 y=-1,
+28 't27' x=11 y=1,
+29 't1' x=12 y=3,
+;
+EDGES
+1 1 2 s=7 w=0.17367192,
+2 30 1 s=6 w=0.08403672,
+3 31 30 s=11 w=0.0060906718,
+4 32 1 s=11 w=0.0060906718,
+5 32 31 s=6 w=0.08403672,
+6 33 30 s=5 w=0.002769119,
+7 34 31 s=5 w=0.002769119,
+8 34 33 s=11 w=0.0060906718,
+9 35 34 s=14 w=0.0018195357,
+10 36 31 s=14 w=0.0018195357,
+11 36 35 s=5 w=0.002769119,
+12 37 35 s=17 w=0.0012588556,
+13 38 36 s=17 w=0.0012588556,
+14 38 37 s=5 w=0.002769119,
+15 39 31 s=17 w=0.0012588556,
+16 39 38 s=14 w=0.0018195357,
+17 40 32 s=17 w=0.0012588556,
+18 40 39 s=6 w=0.08403672,
+19 41 37 s=16 w=4.167727E-4,
+20 42 41 s=21 w=0.0022681346,
+21 43 37 s=21 w=0.0022681346,
+22 43 42 s=16 w=4.167727E-4,
+23 44 42 s=26 w=0.0010168224,
+24 45 43 s=26 w=0.0010168224,
+25 45 44 s=16 w=4.167727E-4,
+26 46 44 s=50 w=3.9997647E-4,
+27 47 45 s=50 w=3.9997647E-4,
+28 47 46 s=16 w=4.167727E-4,
+29 48 43 s=50 w=3.9997647E-4,
+30 48 47 s=26 w=0.0010168224,
+31 49 37 s=50 w=3.9997647E-4,
+32 49 48 s=21 w=0.0022681346,
+33 50 38 s=50 w=3.9997647E-4,
+34 50 49 s=5 w=0.002769119,
+35 51 42 s=20 w=8.992125E-4,
+36 52 44 s=20 w=8.992125E-4,
+37 52 51 s=26 w=0.0010168224,
+38 53 46 s=20 w=8.992125E-4,
+39 53 52 s=50 w=3.9997647E-4,
+40 54 33 s=4 w=1.5893235E-4,
+41 55 34 s=4 w=1.5893235E-4,
+42 55 54 s=11 w=0.0060906718,
+43 56 35 s=4 w=1.5893235E-4,
+44 56 55 s=14 w=0.0018195357,
+45 57 37 s=4 w=1.5893235E-4,
+46 57 56 s=17 w=0.0012588556,
+47 58 41 s=4 w=1.5893235E-4,
+48 58 57 s=16 w=4.167727E-4,
+49 59 42 s=4 w=1.5893235E-4,
+50 59 58 s=21 w=0.0022681346,
+51 60 51 s=4 w=1.5893235E-4,
+52 60 59 s=20 w=8.992125E-4,
+53 61 52 s=4 w=1.5893235E-4,
+54 61 60 s=26 w=0.0010168224,
+55 62 61 s=32 w=7.895848E-4,
+56 63 52 s=32 w=7.895848E-4,
+57 63 62 s=4 w=1.5893235E-4,
+58 64 53 s=32 w=7.895848E-4,
+59 64 63 s=50 w=3.9997647E-4,
+60 65 62 s=36 w=8.855418E-4,
+61 66 63 s=36 w=8.855418E-4,
+62 66 65 s=4 w=1.5893235E-4,
+63 67 64 s=36 w=8.855418E-4,
+64 67 66 s=50 w=3.9997647E-4,
+65 68 53 s=36 w=8.855418E-4,
+66 68 67 s=32 w=7.895848E-4,
+67 69 46 s=36 w=8.855418E-4,
+68 69 68 s=20 w=8.992125E-4,
+69 70 66 s=40 w=0.001203692,
+70 71 67 s=40 w=0.001203692,
+71 71 70 s=50 w=3.9997647E-4,
+72 72 68 s=40 w=0.001203692,
+73 72 71 s=32 w=7.895848E-4,
+74 73 69 s=40 w=0.001203692,
+75 73 72 s=20 w=8.992125E-4,
+76 74 46 s=40 w=0.001203692,
+77 74 73 s=36 w=8.855418E-4,
+78 75 71 s=61 w=0.0010516174,
+79 76 72 s=61 w=0.0010516174,
+80 76 75 s=32 w=7.895848E-4,
+81 77 73 s=61 w=0.0010516174,
+82 77 76 s=20 w=8.992125E-4,
+83 78 74 s=61 w=0.0010516174,
+84 78 77 s=36 w=8.855418E-4,
+85 79 46 s=61 w=0.0010516174,
+86 79 78 s=40 w=0.001203692,
+87 80 47 s=61 w=0.0010516174,
+88 80 79 s=16 w=4.167727E-4,
+89 81 65 s=35 w=1.787175E-4,
+90 82 66 s=35 w=1.787175E-4,
+91 82 81 s=4 w=1.5893235E-4,
+92 83 70 s=35 w=1.787175E-4,
+93 83 82 s=40 w=0.001203692,
+94 84 71 s=35 w=1.787175E-4,
+95 84 83 s=50 w=3.9997647E-4,
+96 85 75 s=35 w=1.787175E-4,
+97 85 84 s=61 w=0.0010516174,
+98 86 85 s=60 w=8.702291E-4,
+99 87 75 s=60 w=8.702291E-4,
+100 87 86 s=35 w=1.787175E-4,
+101 88 76 s=60 w=8.702291E-4,
+102 88 87 s=32 w=7.895848E-4,
+103 89 77 s=60 w=8.702291E-4,
+104 89 88 s=20 w=8.992125E-4,
+105 90 78 s=60 w=8.702291E-4,
+106 90 89 s=36 w=8.855418E-4,
+107 91 79 s=60 w=8.702291E-4,
+108 91 90 s=40 w=0.001203692,
+109 92 90 s=68 w=0.0015038507,
+110 93 91 s=68 w=0.0015038507,
+111 93 92 s=40 w=0.001203692,
+112 94 79 s=68 w=0.0015038507,
+113 94 93 s=60 w=8.702291E-4,
+114 95 80 s=68 w=0.0015038507,
+115 95 94 s=16 w=4.167727E-4,
+116 96 47 s=68 w=0.0015038507,
+117 96 95 s=61 w=0.0010516174,
+118 97 48 s=68 w=0.0015038507,
+119 97 96 s=26 w=0.0010168224,
+120 98 49 s=68 w=0.0015038507,
+121 98 97 s=21 w=0.0022681346,
+122 99 62 s=31 w=0.0010652957,
+123 100 65 s=31 w=0.0010652957,
+124 100 99 s=36 w=8.855418E-4,
+125 101 81 s=31 w=0.0010652957,
+126 101 100 s=35 w=1.787175E-4,
+127 102 82 s=31 w=0.0010652957,
+128 102 101 s=4 w=1.5893235E-4,
+129 103 83 s=31 w=0.0010652957,
+130 103 102 s=40 w=0.001203692,
+131 104 84 s=31 w=0.0010652957,
+132 104 103 s=50 w=3.9997647E-4,
+133 105 103 s=45 w=2.5534217E-4,
+134 106 104 s=45 w=2.5534217E-4,
+135 106 105 s=50 w=3.9997647E-4,
+136 107 84 s=45 w=2.5534217E-4,
+137 107 106 s=31 w=0.0010652957,
+138 108 85 s=45 w=2.5534217E-4,
+139 108 107 s=61 w=0.0010516174,
+140 109 86 s=45 w=2.5534217E-4,
+141 109 108 s=60 w=8.702291E-4,
+142 110 87 s=45 w=2.5534217E-4,
+143 110 109 s=35 w=1.787175E-4,
+144 111 88 s=45 w=2.5534217E-4,
+145 111 110 s=32 w=7.895848E-4,
+146 112 89 s=45 w=2.5534217E-4,
+147 112 111 s=20 w=8.992125E-4,
+148 113 103 s=39 w=0.038550336,
+149 114 105 s=39 w=0.038550336,
+150 114 113 s=45 w=2.5534217E-4,
+151 115 106 s=39 w=0.038550336,
+152 115 114 s=50 w=3.9997647E-4,
+153 116 107 s=39 w=0.038550336,
+154 116 115 s=31 w=0.0010652957,
+155 117 112 s=64 w=1.337294E-5,
+156 118 89 s=64 w=1.337294E-5,
+157 118 117 s=45 w=2.5534217E-4,
+158 119 90 s=64 w=1.337294E-5,
+159 119 118 s=36 w=8.855418E-4,
+160 120 92 s=64 w=1.337294E-5,
+161 120 119 s=68 w=0.0015038507,
+162 121 93 s=64 w=1.337294E-5,
+163 121 120 s=40 w=0.001203692,
+164 122 55 s=10 w=3.662799E-4,
+165 123 56 s=10 w=3.662799E-4,
+166 123 122 s=14 w=0.0018195357,
+167 124 57 s=10 w=3.662799E-4,
+168 124 123 s=17 w=0.0012588556,
+169 125 58 s=10 w=3.662799E-4,
+170 125 124 s=16 w=4.167727E-4,
+171 126 59 s=10 w=3.662799E-4,
+172 126 125 s=21 w=0.0022681346,
+173 127 60 s=10 w=3.662799E-4,
+174 127 126 s=20 w=8.992125E-4,
+175 128 61 s=10 w=3.662799E-4,
+176 128 127 s=26 w=0.0010168224,
+177 129 113 s=38 w=0.0012966593,
+178 130 114 s=38 w=0.0012966593,
+179 130 129 s=45 w=2.5534217E-4,
+180 131 115 s=38 w=0.0012966593,
+181 131 130 s=50 w=3.9997647E-4,
+182 132 130 s=44 w=0.012698617,
+183 133 131 s=44 w=0.012698617,
+184 133 132 s=50 w=3.9997647E-4,
+185 134 115 s=44 w=0.012698617,
+186 134 133 s=38 w=0.0012966593,
+187 135 116 s=44 w=0.012698617,
+188 135 134 s=31 w=0.0010652957,
+189 136 109 s=59 w=0.001466786,
+190 137 110 s=59 w=0.001466786,
+191 137 136 s=35 w=1.787175E-4,
+192 138 111 s=59 w=0.001466786,
+193 138 137 s=32 w=7.895848E-4,
+194 139 112 s=59 w=0.001466786,
+195 139 138 s=20 w=8.992125E-4,
+196 140 117 s=59 w=0.001466786,
+197 140 139 s=64 w=1.337294E-5,
+198 141 118 s=59 w=0.001466786,
+199 141 140 s=45 w=2.5534217E-4,
+200 142 119 s=59 w=0.001466786,
+201 142 141 s=36 w=8.855418E-4,
+202 143 120 s=59 w=0.001466786,
+203 143 142 s=68 w=0.0015038507,
+204 144 121 s=59 w=0.001466786,
+205 144 143 s=40 w=0.001203692,
+206 145 121 s=81 w=4.242624E-4,
+207 146 93 s=81 w=4.242624E-4,
+208 146 145 s=64 w=1.337294E-5,
+209 147 94 s=81 w=4.242624E-4,
+210 147 146 s=60 w=8.702291E-4,
+211 148 95 s=81 w=4.242624E-4,
+212 148 147 s=16 w=4.167727E-4,
+213 149 96 s=81 w=4.242624E-4,
+214 149 148 s=61 w=0.0010516174,
+215 150 97 s=81 w=4.242624E-4,
+216 150 149 s=26 w=0.0010168224,
+217 151 98 s=81 w=4.242624E-4,
+218 151 150 s=21 w=0.0022681346,
+219 152 49 s=81 w=4.242624E-4,
+220 152 151 s=68 w=0.0015038507,
+221 153 50 s=81 w=4.242624E-4,
+222 153 152 s=5 w=0.002769119,
+223 154 54 s=3 w=0.0013902244,
+224 155 55 s=3 w=0.0013902244,
+225 155 154 s=11 w=0.0060906718,
+226 156 122 s=3 w=0.0013902244,
+227 156 155 s=10 w=3.662799E-4,
+228 157 123 s=3 w=0.0013902244,
+229 157 156 s=14 w=0.0018195357,
+230 158 124 s=3 w=0.0013902244,
+231 158 157 s=17 w=0.0012588556,
+232 159 125 s=3 w=0.0013902244,
+233 159 158 s=16 w=4.167727E-4,
+234 160 128 s=25 w=4.685271E-4,
+235 161 61 s=25 w=4.685271E-4,
+236 161 160 s=10 w=3.662799E-4,
+237 162 62 s=25 w=4.685271E-4,
+238 162 161 s=32 w=7.895848E-4,
+239 163 99 s=25 w=4.685271E-4,
+240 163 162 s=31 w=0.0010652957,
+241 164 100 s=25 w=4.685271E-4,
+242 164 163 s=36 w=8.855418E-4,
+243 165 101 s=25 w=4.685271E-4,
+244 165 164 s=35 w=1.787175E-4,
+245 166 165 s=34 w=0.0011806624,
+246 167 101 s=34 w=0.0011806624,
+247 167 166 s=25 w=4.685271E-4,
+248 168 102 s=34 w=0.0011806624,
+249 168 167 s=4 w=1.5893235E-4,
+250 169 103 s=34 w=0.0011806624,
+251 169 168 s=40 w=0.001203692,
+252 170 113 s=34 w=0.0011806624,
+253 170 169 s=39 w=0.038550336,
+254 171 129 s=34 w=0.0011806624,
+255 171 170 s=38 w=0.0012966593,
+256 171 12 s=37 w=0.0914247,
+257 172 130 s=34 w=0.0011806624,
+258 172 171 s=45 w=2.5534217E-4,
+259 173 132 s=34 w=0.0011806624,
+260 173 172 s=44 w=0.012698617,
+261 174 173 s=43 w=0.0014246248,
+262 175 132 s=43 w=0.0014246248,
+263 175 174 s=34 w=0.0011806624,
+264 176 133 s=43 w=0.0014246248,
+265 176 175 s=50 w=3.9997647E-4,
+266 177 174 s=47 w=0.0010406735,
+267 178 175 s=47 w=0.0010406735,
+268 178 177 s=34 w=0.0011806624,
+269 179 176 s=47 w=0.0010406735,
+270 179 178 s=50 w=3.9997647E-4,
+271 180 133 s=47 w=0.0010406735,
+272 180 179 s=43 w=0.0014246248,
+273 181 134 s=47 w=0.0010406735,
+274 181 180 s=38 w=0.0012966593,
+275 182 135 s=47 w=0.0010406735,
+276 182 181 s=31 w=0.0010652957,
+277 183 179 s=54 w=4.0487162E-4,
+278 184 180 s=54 w=4.0487162E-4,
+279 184 183 s=43 w=0.0014246248,
+280 185 181 s=54 w=4.0487162E-4,
+281 185 184 s=38 w=0.0012966593,
+282 186 182 s=54 w=4.0487162E-4,
+283 186 185 s=31 w=0.0010652957,
+284 187 135 s=54 w=4.0487162E-4,
+285 187 186 s=47 w=0.0010406735,
+286 188 116 s=54 w=4.0487162E-4,
+287 188 187 s=44 w=0.012698617,
+288 189 107 s=54 w=4.0487162E-4,
+289 189 188 s=39 w=0.038550336,
+290 190 108 s=54 w=4.0487162E-4,
+291 190 189 s=61 w=0.0010516174,
+292 191 109 s=54 w=4.0487162E-4,
+293 191 190 s=60 w=8.702291E-4,
+294 192 136 s=54 w=4.0487162E-4,
+295 192 191 s=59 w=0.001466786,
+296 193 137 s=54 w=4.0487162E-4,
+297 193 192 s=35 w=1.787175E-4,
+298 194 138 s=54 w=4.0487162E-4,
+299 194 193 s=32 w=7.895848E-4,
+300 195 139 s=54 w=4.0487162E-4,
+301 195 194 s=20 w=8.992125E-4,
+302 196 140 s=54 w=4.0487162E-4,
+303 196 195 s=64 w=1.337294E-5,
+304 197 143 s=67 w=0.0021476466,
+305 198 144 s=67 w=0.0021476466,
+306 198 197 s=40 w=0.001203692,
+307 199 121 s=67 w=0.0021476466,
+308 199 198 s=59 w=0.001466786,
+309 200 198 s=71 w=0.0019187863,
+310 201 199 s=71 w=0.0019187863,
+311 201 200 s=59 w=0.001466786,
+312 202 121 s=71 w=0.0019187863,
+313 202 201 s=67 w=0.0021476466,
+314 203 145 s=71 w=0.0019187863,
+315 203 202 s=81 w=4.242624E-4,
+316 204 200 s=74 w=0.0023116763,
+317 205 201 s=74 w=0.0023116763,
+318 205 204 s=59 w=0.001466786,
+319 206 202 s=74 w=0.0023116763,
+320 206 205 s=67 w=0.0021476466,
+321 207 203 s=74 w=0.0023116763,
+322 207 206 s=81 w=4.242624E-4,
+323 208 145 s=74 w=0.0023116763,
+324 208 207 s=71 w=0.0019187863,
+325 209 146 s=74 w=0.0023116763,
+326 209 208 s=64 w=1.337294E-5,
+327 210 156 s=9 w=1.7729466E-4,
+328 211 157 s=9 w=1.7729466E-4,
+329 211 210 s=14 w=0.0018195357,
+330 212 158 s=9 w=1.7729466E-4,
+331 212 211 s=17 w=0.0012588556,
+332 213 159 s=9 w=1.7729466E-4,
+333 213 212 s=16 w=4.167727E-4,
+334 214 127 s=19 w=8.21237E-4,
+335 214 7 s=18 w=0.0688266,
+336 215 128 s=19 w=8.21237E-4,
+337 215 214 s=26 w=0.0010168224,
+338 216 160 s=19 w=8.21237E-4,
+339 216 215 s=25 w=4.685271E-4,
+340 217 161 s=19 w=8.21237E-4,
+341 217 216 s=10 w=3.662799E-4,
+342 218 216 s=24 w=4.7089203E-4,
+343 219 217 s=24 w=4.7089203E-4,
+344 219 218 s=10 w=3.662799E-4,
+345 220 161 s=24 w=4.7089203E-4,
+346 220 219 s=19 w=8.21237E-4,
+347 221 162 s=24 w=4.7089203E-4,
+348 221 220 s=32 w=7.895848E-4,
+349 222 163 s=24 w=4.7089203E-4,
+350 222 221 s=31 w=0.0010652957,
+351 223 219 s=28 w=3.5754856E-4,
+352 224 220 s=28 w=3.5754856E-4,
+353 224 223 s=19 w=8.21237E-4,
+354 225 221 s=28 w=3.5754856E-4,
+355 225 224 s=32 w=7.895848E-4,
+356 226 222 s=28 w=3.5754856E-4,
+357 226 225 s=31 w=0.0010652957,
+358 227 163 s=28 w=3.5754856E-4,
+359 227 226 s=24 w=4.7089203E-4,
+360 228 164 s=28 w=3.5754856E-4,
+361 228 227 s=36 w=8.855418E-4,
+362 229 165 s=28 w=3.5754856E-4,
+363 229 228 s=35 w=1.787175E-4,
+364 230 166 s=28 w=3.5754856E-4,
+365 230 229 s=34 w=0.0011806624,
+366 231 179 s=49 w=0.021949023,
+367 231 15 s=48 w=0.05344081,
+368 232 183 s=49 w=0.021949023,
+369 232 231 s=54 w=4.0487162E-4,
+370 233 184 s=49 w=0.021949023,
+371 233 232 s=43 w=0.0014246248,
+372 234 185 s=49 w=0.021949023,
+373 234 233 s=38 w=0.0012966593,
+374 235 186 s=49 w=0.021949023,
+375 235 234 s=31 w=0.0010652957,
+376 236 232 s=53 w=2.8627258E-4,
+377 237 233 s=53 w=2.8627258E-4,
+378 237 236 s=43 w=0.0014246248,
+379 238 234 s=53 w=2.8627258E-4,
+380 238 237 s=38 w=0.0012966593,
+381 239 235 s=53 w=2.8627258E-4,
+382 239 238 s=31 w=0.0010652957,
+383 240 186 s=53 w=2.8627258E-4,
+384 240 239 s=49 w=0.021949023,
+385 241 187 s=53 w=2.8627258E-4,
+386 241 240 s=47 w=0.0010406735,
+387 242 188 s=53 w=2.8627258E-4,
+388 242 241 s=44 w=0.012698617,
+389 243 189 s=53 w=2.8627258E-4,
+390 243 242 s=39 w=0.038550336,
+391 244 190 s=53 w=2.8627258E-4,
+392 244 243 s=61 w=0.0010516174,
+393 245 191 s=53 w=2.8627258E-4,
+394 245 244 s=60 w=8.702291E-4,
+395 246 192 s=53 w=2.8627258E-4,
+396 246 245 s=59 w=0.001466786,
+397 247 246 s=58 w=0.0014762296,
+398 248 192 s=58 w=0.0014762296,
+399 248 247 s=53 w=2.8627258E-4,
+400 249 193 s=58 w=0.0014762296,
+401 249 248 s=35 w=1.787175E-4,
+402 250 194 s=58 w=0.0014762296,
+403 250 249 s=32 w=7.895848E-4,
+404 251 195 s=58 w=0.0014762296,
+405 251 250 s=20 w=8.992125E-4,
+406 252 196 s=58 w=0.0014762296,
+407 252 251 s=64 w=1.337294E-5,
+408 253 140 s=58 w=0.0014762296,
+409 253 252 s=54 w=4.0487162E-4,
+410 254 141 s=58 w=0.0014762296,
+411 254 253 s=45 w=2.5534217E-4,
+412 255 142 s=58 w=0.0014762296,
+413 255 254 s=36 w=8.855418E-4,
+414 256 143 s=58 w=0.0014762296,
+415 256 255 s=68 w=0.0015038507,
+416 257 197 s=58 w=0.0014762296,
+417 257 256 s=67 w=0.0021476466,
+418 258 205 s=77 w=0.0016833246,
+419 259 206 s=77 w=0.0016833246,
+420 259 258 s=67 w=0.0021476466,
+421 260 207 s=77 w=0.0016833246,
+422 260 259 s=81 w=4.242624E-4,
+423 261 208 s=77 w=0.0016833246,
+424 261 260 s=71 w=0.0019187863,
+425 262 209 s=77 w=0.0016833246,
+426 262 261 s=64 w=1.337294E-5,
+427 263 260 s=80 w=0.001391344,
+428 264 261 s=80 w=0.001391344,
+429 264 263 s=71 w=0.0019187863,
+430 265 262 s=80 w=0.001391344,
+431 265 264 s=64 w=1.337294E-5,
+432 266 209 s=80 w=0.001391344,
+433 266 265 s=77 w=0.0016833246,
+434 267 146 s=80 w=0.001391344,
+435 267 266 s=74 w=0.0023116763,
+436 268 147 s=80 w=0.001391344,
+437 268 267 s=60 w=8.702291E-4,
+438 269 148 s=80 w=0.001391344,
+439 269 268 s=16 w=4.167727E-4,
+440 270 154 s=2 w=0.017143281,
+441 270 3 s=1 w=0.1279713,
+442 271 155 s=2 w=0.017143281,
+443 271 270 s=11 w=0.0060906718,
+444 272 156 s=2 w=0.017143281,
+445 272 271 s=10 w=3.662799E-4,
+446 273 210 s=2 w=0.017143281,
+447 273 272 s=9 w=1.7729466E-4,
+448 273 4 s=8 w=0.057841897,
+449 274 211 s=13 w=0.038590923,
+450 274 5 s=12 w=0.08134686,
+451 275 212 s=13 w=0.038590923,
+452 275 274 s=17 w=0.0012588556,
+453 276 213 s=13 w=0.038590923,
+454 276 275 s=16 w=4.167727E-4,
+455 276 6 s=15 w=0.09856205,
+456 277 218 s=23 w=0.03262534,
+457 277 8 s=22 w=0.0665534,
+458 278 219 s=23 w=0.03262534,
+459 278 277 s=10 w=3.662799E-4,
+460 279 223 s=23 w=0.03262534,
+461 279 278 s=28 w=3.5754856E-4,
+462 279 9 s=27 w=0.03859058,
+463 280 226 s=30 w=0.06064433,
+464 280 10 s=29 w=0.052748006,
+465 281 227 s=30 w=0.06064433,
+466 281 280 s=24 w=4.7089203E-4,
+467 282 228 s=30 w=0.06064433,
+468 282 281 s=36 w=8.855418E-4,
+469 283 229 s=30 w=0.06064433,
+470 283 282 s=35 w=1.787175E-4,
+471 284 230 s=30 w=0.06064433,
+472 284 283 s=34 w=0.0011806624,
+473 284 11 s=33 w=0.05142635,
+474 285 174 s=42 w=0.0044335932,
+475 285 13 s=41 w=0.092642605,
+476 286 177 s=42 w=0.0044335932,
+477 286 285 s=47 w=0.0010406735,
+478 286 14 s=46 w=0.09702029,
+479 287 236 s=52 w=0.04591966,
+480 287 16 s=51 w=0.06783958,
+481 288 237 s=52 w=0.04591966,
+482 288 287 s=43 w=0.0014246248,
+483 289 238 s=52 w=0.04591966,
+484 289 288 s=38 w=0.0012966593,
+485 290 239 s=52 w=0.04591966,
+486 290 289 s=31 w=0.0010652957,
+487 290 17 s=55 w=0.064194575,
+488 291 247 s=57 w=0.10500158,
+489 291 18 s=56 w=0.047182973,
+490 292 248 s=57 w=0.10500158,
+491 292 291 s=53 w=2.8627258E-4,
+492 293 249 s=57 w=0.10500158,
+493 293 292 s=35 w=1.787175E-4,
+494 294 250 s=57 w=0.10500158,
+495 294 293 s=32 w=7.895848E-4,
+496 295 251 s=57 w=0.10500158,
+497 295 294 s=20 w=8.992125E-4,
+498 296 252 s=57 w=0.10500158,
+499 296 295 s=64 w=1.337294E-5,
+500 297 296 s=63 w=0.004750093,
+501 297 19 s=62 w=0.044313457,
+502 298 252 s=63 w=0.004750093,
+503 298 297 s=57 w=0.10500158,
+504 299 253 s=63 w=0.004750093,
+505 299 298 s=54 w=4.0487162E-4,
+506 300 254 s=63 w=0.004750093,
+507 300 299 s=45 w=2.5534217E-4,
+508 301 255 s=63 w=0.004750093,
+509 301 300 s=36 w=8.855418E-4,
+510 302 256 s=63 w=0.004750093,
+511 302 301 s=68 w=0.0015038507,
+512 303 257 s=63 w=0.004750093,
+513 303 302 s=67 w=0.0021476466,
+514 304 303 s=66 w=0.013317523,
+515 304 20 s=65 w=0.20566262,
+516 305 257 s=66 w=0.013317523,
+517 305 304 s=63 w=0.004750093,
+518 306 197 s=66 w=0.013317523,
+519 306 305 s=58 w=0.0014762296,
+520 307 198 s=66 w=0.013317523,
+521 307 306 s=40 w=0.001203692,
+522 308 200 s=66 w=0.013317523,
+523 308 307 s=71 w=0.0019187863,
+524 309 308 s=70 w=1.5751319E-4,
+525 309 21 s=69 w=0.09029672,
+526 310 200 s=70 w=1.5751319E-4,
+527 310 309 s=66 w=0.013317523,
+528 311 204 s=70 w=1.5751319E-4,
+529 311 310 s=74 w=0.0023116763,
+530 312 311 s=73 w=0.006326371,
+531 312 22 s=72 w=0.109228075,
+532 313 204 s=73 w=0.006326371,
+533 313 312 s=70 w=1.5751319E-4,
+534 314 205 s=73 w=0.006326371,
+535 314 313 s=59 w=0.001466786,
+536 315 258 s=73 w=0.006326371,
+537 315 314 s=77 w=0.0016833246,
+538 316 315 s=76 w=1.050739E-4,
+539 316 23 s=75 w=0.089916565,
+540 317 258 s=76 w=1.050739E-4,
+541 317 316 s=73 w=0.006326371,
+542 318 259 s=76 w=1.050739E-4,
+543 318 317 s=67 w=0.0021476466,
+544 319 260 s=76 w=1.050739E-4,
+545 319 318 s=81 w=4.242624E-4,
+546 320 263 s=76 w=1.050739E-4,
+547 320 319 s=80 w=0.001391344,
+548 321 320 s=79 w=0.0022174222,
+549 321 24 s=78 w=0.17474917,
+550 322 263 s=79 w=0.0022174222,
+551 322 321 s=76 w=1.050739E-4,
+552 323 264 s=79 w=0.0022174222,
+553 323 322 s=71 w=0.0019187863,
+554 324 265 s=79 w=0.0022174222,
+555 324 323 s=64 w=1.337294E-5,
+556 325 324 s=83 w=0.0013124112,
+557 325 25 s=82 w=0.13961297,
+558 326 265 s=83 w=0.0013124112,
+559 326 325 s=79 w=0.0022174222,
+560 327 266 s=83 w=0.0013124112,
+561 327 326 s=77 w=0.0016833246,
+562 328 267 s=83 w=0.0013124112,
+563 328 327 s=74 w=0.0023116763,
+564 329 268 s=83 w=0.0013124112,
+565 329 328 s=60 w=8.702291E-4,
+566 330 269 s=83 w=0.0013124112,
+567 330 329 s=16 w=4.167727E-4,
+568 331 330 s=85 w=4.8682792E-4,
+569 331 26 s=84 w=0.1194786,
+570 332 269 s=85 w=4.8682792E-4,
+571 332 331 s=83 w=0.0013124112,
+572 333 148 s=85 w=4.8682792E-4,
+573 333 332 s=80 w=0.001391344,
+574 334 149 s=85 w=4.8682792E-4,
+575 334 333 s=61 w=0.0010516174,
+576 335 150 s=85 w=4.8682792E-4,
+577 335 334 s=26 w=0.0010168224,
+578 336 151 s=85 w=4.8682792E-4,
+579 336 335 s=21 w=0.0022681346,
+580 337 336 s=87 w=0.0045568696,
+581 337 27 s=86 w=0.09366718,
+582 338 151 s=87 w=0.0045568696,
+583 338 337 s=85 w=4.8682792E-4,
+584 339 152 s=87 w=0.0045568696,
+585 339 338 s=68 w=0.0015038507,
+586 340 153 s=87 w=0.0045568696,
+587 340 339 s=5 w=0.002769119,
+588 341 340 s=89 w=0.0015117239,
+589 341 28 s=88 w=0.08093566,
+590 342 153 s=89 w=0.0015117239,
+591 342 341 s=87 w=0.0045568696,
+592 343 50 s=89 w=0.0015117239,
+593 343 342 s=81 w=4.242624E-4,
+594 344 38 s=89 w=0.0015117239,
+595 344 343 s=50 w=3.9997647E-4,
+596 345 39 s=89 w=0.0015117239,
+597 345 344 s=14 w=0.0018195357,
+598 346 40 s=89 w=0.0015117239,
+599 346 345 s=6 w=0.08403672,
+600 346 29 s=90 w=0.076351464,
+;
+END; [Network]
+
+BEGIN st_Assumptions;
+uptodate;
+disttransform=NeighborNet;
+splitstransform=EqualAngle;
+SplitsPostProcess filter=dimension value=4;
+ exclude  no missing;
+autolayoutnodelabels;
+END; [st_Assumptions]
diff --git a/inst/extdata/trees/Splits.txt b/inst/extdata/trees/Splits.txt
new file mode 100644
index 0000000..13e2a73
--- /dev/null
+++ b/inst/extdata/trees/Splits.txt
@@ -0,0 +1,115 @@
+SplitWeight	Bootstrap	Color
+0.07060404	100	Blue
+0.04792795	100	Blue
+0.042704593	100	Blue
+0.030850368	100	Blue
+0.023994952	100	Blue
+0.02331487	100	Blue
+0.012582252	100	Blue
+0.007275392	97	Blue
+0.0051821293	0	Pink
+0.0036041164	99.2	Blue
+0.0032304472	96.4	Blue
+0.0026902487	0	Pink
+0.0022065418	100	Blue
+0.0019132489	81.3	Blue
+0.001341845	0	Pink
+0.0009478839	0	Pink
+0.0008527216	3.2	Blue
+0.0002126253	0	Pink
+0.0001476501	0	Pink
+0.015339644	100	Blue
+0.0023547208	2.6	Blue
+0.0014287664	0	Pink
+0.0008373248	0	Pink
+0.0006076867	2.6	Blue
+0.0006041702	0	Pink
+0.000297436	0	Pink
+0.0002735536	0	Pink
+5.794991E-05	0	Pink
+3.466567E-05	12.1	Blue
+1.5231282E-05	0	Pink
+0.0012366334	41.9	Blue
+0.0009923275	0	Pink
+0.0009782094	0	Pink
+0.0009185735	0	Pink
+0.0007710702	54.9	Blue
+0.0006963874	0	Pink
+0.0006019617	10.4	Blue
+0.0003462597	0	Pink
+0.0089485	100	Blue
+0.0020022863	0	Pink
+0.0010558827	71	Blue
+0.0004692516	0	Pink
+0.0004601492	5.8	Blue
+0.020771	100	Blue
+0.0008540598	0	Pink
+0.000244999	0	Pink
+0.0009483108	0	Pink
+0.0007954276	0	Pink
+0.0003385545	47.9	Blue
+0.0001838823	1.3	Blue
+0.0012166464	55.1	Blue
+0.0008818683	29	Blue
+0.0002556656	0	Pink
+0.000698773	0	Pink
+0.0006747867	1.2	Blue
+0.0006746581	44.1	Blue
+0.0001867169	0	Pink
+0.0008441487	0	Pink
+0.00001	87.1	Green
+0.00001	53.7	Green
+0.00001	45.8	Green
+0.00001	42.6	Green
+0.00001	36.4	Green
+0.00001	36.1	Green
+0.00001	34.7	Green
+0.00001	26.1	Green
+0.00001	24.5	Green
+0.00001	22.3	Green
+0.00001	21	Green
+0.00001	13.8	Green
+0.00001	12.7	Green
+0.00001	11	Green
+0.00001	9.9	Green
+0.00001	9.2	Green
+0.00001	8.1	Green
+0.00001	7.6	Green
+0.00001	6.1	Green
+0.00001	5.6	Green
+0.00001	5.5	Green
+0.00001	4.8	Green
+0.00001	4.6	Green
+0.00001	4.3	Green
+0.00001	4.2	Green
+0.00001	4.2	Green
+0.00001	4.1	Green
+0.00001	4	Green
+0.00001	3.4	Green
+0.00001	3.2	Green
+0.00001	3.2	Green
+0.00001	3	Green
+0.00001	2.9	Green
+0.00001	2.6	Green
+0.00001	2.5	Green
+0.00001	2.5	Green
+0.00001	2.4	Green
+0.00001	2.4	Green
+0.00001	2.1	Green
+0.00001	2.1	Green
+0.00001	2	Green
+0.00001	1.8	Green
+0.00001	1.7	Green
+0.00001	1.6	Green
+0.00001	1.6	Green
+0.00001	1.5	Green
+0.00001	1.5	Green
+0.00001	1.4	Green
+0.00001	1.4	Green
+0.00001	1.3	Green
+0.00001	1.2	Green
+0.00001	1.1	Green
+0.00001	1.1	Green
+0.00001	1	Green
+0.00001	1	Green
+0.00001	1	Green
diff --git a/inst/extdata/trees/primates.dna b/inst/extdata/trees/primates.dna
new file mode 100644
index 0000000..507b365
--- /dev/null
+++ b/inst/extdata/trees/primates.dna
@@ -0,0 +1,61 @@
+   14   232
+Mouse     ACCAAAAAAA CATCCAAACA CCAACCCCAG CCCTTACGCA ATAGCCATAC AAAGAATATT
+Bovine    ACCAAACCTG TCCCCACCAT CTAACACCAA CCCACATATA CAAGCTAAAC CAAAAATACC
+Lemur     ACCAAACTAA CATCTAACAA CTACCTCCAA CTCTAAAAAA GCACTCTTAC CAAACCCATC
+Tarsier   ATCTACCTTA TCTCCCCCAA TCAATACCAA CCTAAAAACT CTACAATTAA AAACCCCACC
+Squir MonkACCCCAGCAA CTCGTTGTGA CCAACATCAA TCCAAAATTA GCAAACGTAC CAACAATCTC
+Jpn Macaq ACTCCACCTG CTCACCTCAT CCACTACTAC TCCTCAAGCA ATACATAAAC TAAAAACTTC
+Rhesus MacACTTCACCCG TTCACCTCAT CCACTACTAC TCCTCAAGCG ATACATAAAT CAAAAACTTC
+Crab-E.MacACCCCACCTA CCCGCCTCGT CCGCTACTGC TTCTCAAACA ATATATAGAC CAACAACTTC
+BarbMacaq ACCCTATCTA TCTACCTCAC CCGCCACCAC CCCCCAAACA ACACACAAAC CAACAACTTT
+Gibbon    ACTATACCCA CCCAACTCGA CCTACACCAA TCCCCACATA GCACACAGAC CAACAACCTC
+Orang     ACCCCACCCG TCTACACCAG CCAACACCAA CCCCCACCTA CTATACCAAC CAATAACCTC
+Gorilla   ACCCCATTTA TCCATAAAAA CCAACACCAA CCCCCATCTA ACACACAAAC TAATGACCCC
+Chimp     ACCCCATCCA CCCATACAAA CCAACATTAC CCTCCATCCA ATATACAAAC TAACAACCTC
+Human     ACCCCACTCA CCCATACAAA CCAACACCAC TCTCCACCTA ATATACAAAT TAATAACCTC
+
+          ATACTACTAA AAACTCAAAT TAACTCTTTA ATCTTTATAC AACATTCCAC CAACCTATCC
+          ATACAACCAT AAATAAGACT AATCTATTAA AATAACCCAT TACGATACAA AATCCCTTTC
+          ACAACTCTAT CAACCTAACC AAACTATCAA CATGCCCTCT CCTAATTAAA AACATTGCCA
+          GCTCAATTAC TAGCAAAAAT AGACATTCAA CTCCTCCCAT CATAACATAA AACATTCCTC
+          CCAAATTTAA AAACACATCC TACCTTTACA ATTAATAACC ATTGTCTAGA TATACCCCTA
+          TCACCTCTAA TACTACACAC CACTCCTGAA ATCAATGCCC TCCACTAAAA AACATCACCA
+          TCACCTCCAA TACTACGCAC CGCTCCTAAA ATCAATGCCC CCCACCAAAA AACATCACCA
+          TCACCTTTAA CACTACATAT CACTCCTGAG CTTAACACCC TCCGCTAAAA AACACCACTA
+          TTATCTTTAG CACCACACAT CACCCCCAAA AGCAATACCC TTCACCAAAA AGCACCATCA
+          CCACCTTCCA TACCAAGCCC CGACTTTACC GCCAACGCAC CTCATCAAAA CATACCTACA
+          TCAACCCCTA AACCAAACAC TATCCCCAAA ACCAACACAC TCTACCAAAA TACACCCCCA
+          CCACCCTCAA AGCCAAACAC CAACCCTATA ATCAATACGC CTTATCAAAA CACACCCCCA
+          CCACTCTTCA GACCGAACAC CAATCTCACA ACCAACACGC CCCGTCAAAA CACCCCTTCA
+          CCACCTTCAG AACTGAACGC CAATCTCATA ACCAACACAC CCCATCAAAG CACCCCTCCA
+
+          ACACAAAAAA ACTCATATTT ATCTAAATAC GAACTTCACA CAACCTTAAC ACATAAACAT
+          GTCTAGATAC AAACCACAAC ACACAATTAA TACACACCAC AATTACAATA CTAAACTCCC
+          CACTAAACCT ACACACCTCA TCACCATTAA CGCATAACTC CTCAGTCATA TCTACTACAC
+          GCTCCAATAA ACACATCACA ATCCCAATAA CGCATATACC TAAATACATC ATTTAATAAT
+          AAATAAATGA ATATAAACCC TCGCCGATAA CATA-ACCCC TAAAATCAAG ACATCCTCTC
+          GCCCAAACAA ACACCTATCT ACCCCCCCGG TCCACGCCCC TAACTCCATC ATTCCCCCTC
+          ACCCAAACAA ACACCTACCC ATCCCCCCGG TTCACGCCTC AAACTCCATC ATTCCCCCTC
+          ACCCAAACAA ACACCTATCT ATCCCCCCGG TCCACGCCCC AAACCCCGCT ATTCCCCCCT
+          AATCAAACAA ACACCTATTT ATTCCCCTAA TTCACGTCCC AAATCCCATT ATCTCTCCCC
+          ACACAAACAA ATGCCCCCCC ACCCTCCTTC TTCAAGCCCA CTAGACCATC CTACCTTCCT
+          ATTCACATCC GCACACCCCC ACCCCCCCTG CCCACGTCCA TCCCATCACC CTCTCCTCCC
+          ACATAAACCC ACGCACCCCC ACCCCTTCCG CCCATGCTCA CCACATCATC TCTCCCCTTC
+          GCACAAATTC ATACACCCCT ACCTTTCCTA CCCACGTTCA CCACATCATC CCCCCCTCTC
+          ACACAAACCC GCACACCTCC ACCCCCCTCG TCTACGCTTA CCACGTCATC CCTCCCTCTC
+
+          ACCCCAGCCC AACACCCTTC CACAAATCCT TAATATACGC ACCATAAATA AC
+          ATCCCACCAA ATCACCCTCC ATCAAATCCA CAAATTACAC AACCATTAAC CC
+          ACCCTAACAA TTTATCCCTC CCATAATCCA AAAACTCCAT AAACACAAAT TC
+          AATACTCCAA CTCCCATAAC ACAGCATACA TAAACTCCAT AAGTTTGAAC AC
+          ACAACGCCAA ACCCCCCTCT CATAACTCTA CAAAATACAC AATCACCAAC AC
+          AATACATCAA ACAATTCCCC CCAATACCCA CAAACTGCAT AAGCAAACAG AC
+          AATACATCAA ACAATTCCCC CCAATACCCA CAAACTACAT AAACAAACAA AC
+          AATACACCAA ACAATTTTCT CCAACACCCA CAAACTGTAT AAACAAACAA AC
+          AACATACCAA ACAATTCTCC CTAATATACA CAAACCACGC AAACAAACAA AC
+          AGCACGCCAA GCTCTCTACC ATCAAACGCA CAACTTACAC ATACAGAACC AC
+          AACACCCTAA GCCACCTTCC TCAAAATCCA AAACCCACAC AACCGAAACA AC
+          AACACCTCAA TCCACCTCCC CCCAAATACA CAATTCACAC AAACAATACC AC
+          AACATCTTGA CTCGCCTCTC TCCAAACACA CAATTCACGC AAACAACGCC AC
+          AACACCTTAA CTCACCTTCT CCCAAACGCA CAATTCGCAC ACACAACGCC AC
+
diff --git a/man/Ancestors.Rd b/man/Ancestors.Rd
index ffca5c9..de925c2 100644
--- a/man/Ancestors.Rd
+++ b/man/Ancestors.Rd
@@ -1,43 +1,49 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/treeManipulation.R
 \name{Ancestors}
 \alias{Ancestors}
 \alias{Children}
 \alias{Descendants}
 \alias{Siblings}
 \alias{mrca.phylo}
-%\alias{mrca}
 \title{tree utility function}
-\description{
-Functions for describing relationships among phylogenetic nodes.
-}
 \usage{
-Ancestors(x, node, type=c("all","parent"))
+Ancestors(x, node, type = c("all", "parent"))
+
 Children(x, node)
-Siblings(x, node, include.self=FALSE)
-Descendants(x, node, type=c("tips","children","all"))
-mrca.phylo(x, node=NULL)
+
+Descendants(x, node, type = c("tips", "children", "all"))
+
+Siblings(x, node, include.self = FALSE)
+
+mrca.phylo(x, node = NULL)
 }
-%mrca(x)
 \arguments{
-  \item{x}{a tree (a phylo object).}
-  \item{node}{an integer or a vector of integers corresponding to a node ID}
-  \item{type}{specify whether to return just direct
-    children / parents or all }
-  \item{include.self}{whether to include self in list of siblings}
-}
-\details{
-These functions are inspired by \code{treewalk} in phylobase package, but work on the 
-S3 \code{phylo} objects.  
-The nodes are the indices as given in edge matrix of an phylo object.
-From taxon labels these indices can be easily derived matching against the \code{tip.label}
-argument of an phylo object, see example below. 
-All the functions allow \code{node} to be either a scalar or vector.  
-\code{mrca} is a faster version of the mrca in ape, in phangorn only because of dependencies. 
+\item{x}{a tree (a phylo object).}
+
+\item{node}{an integer or a vector of integers corresponding to a node ID}
+
+\item{type}{specify whether to return just direct children / parents or all}
+
+\item{include.self}{whether to include self in list of siblings}
 }
 \value{
-   a vector or a list containing the indices of the nodes. 
+a vector or a list containing the indices of the nodes.
+}
+\description{
+Functions for describing relationships among phylogenetic nodes.
+}
+\details{
+These functions are inspired by \code{treewalk} in phylobase package, but
+work on the S3 \code{phylo} objects.  The nodes are the indices as given in
+edge matrix of an phylo object. From taxon labels these indices can be
+easily derived matching against the \code{tip.label} argument of an phylo
+object, see example below.  All the functions allow \code{node} to be either
+a scalar or vector.  \code{mrca} is a faster version of the mrca in ape, in
+phangorn only because of dependencies.
 }
-\seealso{\code{treewalk}, \code{\link[ape]{phylo}}, \code{\link[ape]{nodelabels}} }
 \examples{
+
 tree = rtree(10)
 plot(tree, show.tip.label = FALSE)
 nodelabels()
@@ -50,5 +56,10 @@ mrca.phylo(tree, 1:3)
 mrca.phylo(tree, match(c("t1", "t2", "t3"), tree$tip))
 mrca.phylo(tree)
 # same as mrca(tree), but faster for large trees
+
+}
+\seealso{
+\code{treewalk}, \code{\link[ape]{phylo}},
+\code{\link[ape]{nodelabels}}
 }
 \keyword{misc}
diff --git a/man/CI.Rd b/man/CI.Rd
new file mode 100644
index 0000000..cbc274a
--- /dev/null
+++ b/man/CI.Rd
@@ -0,0 +1,34 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/parsimony.R
+\name{CI}
+\alias{CI}
+\alias{RI}
+\title{Consistency Index and Retention Index}
+\usage{
+CI(tree, data, cost = NULL, sitewise = FALSE)
+
+RI(tree, data, cost = NULL, sitewise = FALSE)
+}
+\arguments{
+\item{tree}{tree to start the nni search from.}
+
+\item{data}{A object of class phyDat containing sequences.}
+
+\item{cost}{A cost matrix for the transitions between two states.}
+
+\item{sitewise}{return CI/RI for alignment or sitewise}
+}
+\description{
+\code{CI} and \code{RI} compute the Consistency Index (CI) and Retention Index (RI).
+}
+\details{
+The Consistency Index is defined as minimum number of changes divided by the 
+number of changes required on the tree (parsimony score). The Consistency 
+Index is equal to one if there is no homoplasy.
+And the Retention Index is defined as
+\deqn{RI = \frac{MaxChanges - ObsChanges}{MaxChanges - MinChanges}}{RI = (MaxChanges - ObsChanges) / (MaxChanges - MinChanges)}
+}
+\seealso{
+\code{\link{parsimony}}, \code{\link{pratchet}}, \code{\link{fitch}}, 
+\code{\link{sankoff}}, \code{\link{bab}}, \code{\link{ancestral.pars}}
+}
diff --git a/man/Laurasiatherian.Rd b/man/Laurasiatherian.Rd
index abc2916..8a45e65 100644
--- a/man/Laurasiatherian.Rd
+++ b/man/Laurasiatherian.Rd
@@ -1,18 +1,20 @@
-\name{Laurasiatherian}
-\alias{Laurasiatherian}
-\docType{data}
-\title{ Laurasiatherian data (AWCMEE)}
-\description{
-  Laurasiatherian RNA sequence data 
-}
-\usage{data(Laurasiatherian)}
-
-\source{
-Data have been taken from \url{http://www.allanwilsoncentre.ac.nz/}
-and were converted to R format by \email{klaus.schliep at gmail.com}.   
-}
-\examples{
-data(Laurasiatherian)
-str(Laurasiatherian)
-}
-\keyword{datasets}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/phangorn-package.R
+\docType{data}
+\name{Laurasiatherian}
+\alias{Laurasiatherian}
+\title{Laurasiatherian data (AWCMEE)}
+\source{
+Data have been taken from \url{http://www.allanwilsoncentre.ac.nz/}
+and were converted to R format by \email{klaus.schliep at gmail.com}.
+}
+\description{
+Laurasiatherian RNA sequence data
+}
+\examples{
+
+data(Laurasiatherian)
+str(Laurasiatherian)
+
+}
+\keyword{datasets}
diff --git a/man/NJ.Rd b/man/NJ.Rd
index 55c33b6..6bcd02b 100644
--- a/man/NJ.Rd
+++ b/man/NJ.Rd
@@ -1,42 +1,52 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/distTree.R
 \name{NJ}
 \alias{NJ}
+\alias{PNJ}
 \alias{UNJ}
-%- Also NEED an '\alias' for EACH other topic documented here.
 \title{Neighbor-Joining}
-\description{
-This function performs the neighbor-joining tree estimation of Saitou
-and Nei (1987). UNJ is the unweighted version from Gascuel (1997).
-}
 \usage{
 NJ(x)
+
 UNJ(x)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{x}{A distance matrix.}
+\item{x}{A distance matrix.}
 }
-
 \value{
- an object of class \code{"phylo"}.
+an object of class \code{"phylo"}.
+}
+\description{
+This function performs the neighbor-joining tree estimation of Saitou and
+Nei (1987). UNJ is the unweighted version from Gascuel (1997).
 }
-\references{Saitou, N. and Nei, M. (1987) The neighbor-joining method: a new
-method for reconstructing phylogenetic trees. \emph{Molecular Biology
-and Evolution}, \bold{4}, 406--425. 
-
-Studier, J. A and Keppler, K. J. (1988) A Note on the Neighbor-Joining
-Algorithm of Saitou and Nei. \emph{Molecular Biology and Evolution}, 
-\bold{6}, 729--731. 
-
-Gascuel, O. (1997) Concerning the NJ algorithm and its unweighted 
-version, UNJ. in Birkin et. al. \emph{Mathematical Hierarchies and Biology}, 
- 149--170.}    
-\author{Klaus P. Schliep \email{klaus.schliep at gmail.com}}
-
-\seealso{  \code{\link[ape]{nj}}, \code{\link[ape]{dist.dna}}, \code{\link[phangorn]{dist.hamming}}, \code{\link[phangorn]{upgma}}, \code{\link[ape]{fastme}}}
 \examples{
+
 data(Laurasiatherian)
 dm <- dist.ml(Laurasiatherian)
 tree <- NJ(dm)
 plot(tree)
+
+}
+\references{
+Saitou, N. and Nei, M. (1987) The neighbor-joining method: a new
+method for reconstructing phylogenetic trees. \emph{Molecular Biology and
+Evolution}, \bold{4}, 406--425.
+
+Studier, J. A and Keppler, K. J. (1988) A Note on the Neighbor-Joining
+Algorithm of Saitou and Nei. \emph{Molecular Biology and Evolution},
+\bold{6}, 729--731.
+
+Gascuel, O. (1997) Concerning the NJ algorithm and its unweighted version,
+UNJ. in Birkin et. al. \emph{Mathematical Hierarchies and Biology},
+149--170.
+}
+\seealso{
+\code{\link[ape]{nj}}, \code{\link[ape]{dist.dna}},
+\code{\link[phangorn]{dist.hamming}}, \code{\link[phangorn]{upgma}},
+\code{\link[ape]{fastme}}
+}
+\author{
+Klaus P. Schliep \email{klaus.schliep at gmail.com}
 }
-\keyword{ cluster }% at least one, from doc/KEYWORDS
+\keyword{cluster}
diff --git a/man/SH.test.Rd b/man/SH.test.Rd
index 6568e0a..d772938 100644
--- a/man/SH.test.Rd
+++ b/man/SH.test.Rd
@@ -1,35 +1,29 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/SH.R
 \name{SH.test}
 \alias{SH.test}
 \title{Shimodaira-Hasegawa Test}
 \usage{
-SH.test(..., B = 10000, data=NULL)
+SH.test(..., B = 10000, data = NULL)
 }
 \arguments{
-  \item{...}{either a series of objects of class \code{"pml"}
-    separated by commas, a list containing such objects
-    or an object  of class \code{"pmlPart"}.}
-  \item{B}{the number of bootstrap replicates.}
-  \item{data}{an object of class  \code{"phyDat"}.}
-}
-\description{
-  This function computes the Shimodaira--Hasegawa test for a set of
-  trees.
+\item{...}{either a series of objects of class \code{"pml"} separated by
+commas, a list containing such objects or an object of class
+\code{"pmlPart"}.}
+
+\item{B}{the number of bootstrap replicates.}
+
+\item{data}{an object of class \code{"phyDat"}.}
 }
 \value{
-  a numeric vector with the P-value associated with each tree given in
-  \code{...}.
-}
-\references{
-  Shimodaira, H. and Hasegawa, M. (1999) Multiple comparisons of
-  log-likelihoods with applications to phylogenetic
-  inference. \emph{Molecular Biology and Evolution}, \bold{16},
-  1114--1116.
+a numeric vector with the P-value associated with each tree given in
+\code{...}.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\seealso{
-  \code{\link{pml}}, \code{\link{pmlPart}}, \code{\link{pmlCluster}}, \code{\link{SOWH.test}}
+\description{
+This function computes the Shimodaira--Hasegawa test for a set of trees.
 }
 \examples{
+
 data(Laurasiatherian)
 dm <- dist.logDet(Laurasiatherian)
 tree1 <- NJ(dm)
@@ -44,5 +38,18 @@ SH.test(fit1, fit2, B=500)
 example(pmlPart)
 SH.test(sp, B=1000)
 }
+
+}
+\references{
+Shimodaira, H. and Hasegawa, M. (1999) Multiple comparisons of
+log-likelihoods with applications to phylogenetic inference. \emph{Molecular
+Biology and Evolution}, \bold{16}, 1114--1116.
+}
+\seealso{
+\code{\link{pml}}, \code{\link{pmlPart}}, \code{\link{pmlCluster}},
+\code{\link{SOWH.test}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
 \keyword{models}
diff --git a/man/SOWH.test.Rd b/man/SOWH.test.Rd
index e061d3e..b3171d1 100644
--- a/man/SOWH.test.Rd
+++ b/man/SOWH.test.Rd
@@ -1,41 +1,44 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/SOWH.R
 \name{SOWH.test}
 \alias{SOWH.test}
 \title{Swofford-Olsen-Waddell-Hillis Test}
 \usage{
-SOWH.test(x, n = 100, restricted = list(optNni=FALSE), optNni=TRUE, trace = 1, ...)
+SOWH.test(x, n = 100, restricted = list(optNni = FALSE), optNni = TRUE,
+  trace = 1, ...)
 }
 \arguments{
-  \item{x}{an object of class  \code{"pml"}.}
-  \item{n}{the number of bootstrap replicates.}
-  \item{restricted}{list of restricted parameter settings.}
-  \item{optNni}{Logical value indicating whether topology gets optimized (NNI).}
-  \item{trace}{Show output during computations.}
-  \item{\dots}{Further arguments passed to \code{"optim.pml"}.}
-}
-\description{
-This function computes the Swofford--Olsen--Waddell--Hillis (SOWH) test, a parametric bootstrap test. The function is computational very demanding and likely to be very slow. 
-}
-\details{
-\code{SOWH.test} performs a parametric bootstrap test to compare two trees. 
-It makes extensive use \code{simSeq} and \code{optim.pml} and can take quite long.  
+\item{x}{an object of class \code{"pml"}.}
+
+\item{n}{the number of bootstrap replicates.}
+
+\item{restricted}{list of restricted parameter settings.}
+
+\item{optNni}{Logical value indicating whether topology gets optimized
+(NNI).}
+
+\item{trace}{Show output during computations.}
+
+\item{\dots}{Further arguments passed to \code{"optim.pml"}.}
 }
 \value{
-  an object of class SOWH. That is a list with three elements, one is a matrix
-  containing for each bootstrap replicate the (log-) likelihood of the restricted and   unrestricted estimate and two pml objects of the restricted and unrestricted model. 
+an object of class SOWH. That is a list with three elements, one is
+a matrix containing for each bootstrap replicate the (log-) likelihood of
+the restricted and unrestricted estimate and two pml objects of the
+restricted and unrestricted model.
 }
-\references{
-Goldman, N., Anderson, J. P., and Rodrigo, A. G. (2000) Likelihood
--based tests of topologies in phylogenetics. \emph{Systematic Biology} \bold{49} 652-670.
-  
-Swofford, D.L., Olsen, G.J.,  Waddell, P.J. and Hillis, D.M. (1996) 
-Phylogenetic Inference in Hillis, D.M., Moritz, C. and Mable, B.K. (Eds.)
-\emph{Molecular Systematics} (2nd ed.) 407-514, Sunderland, MA: Sinauer
+\description{
+This function computes the Swofford--Olsen--Waddell--Hillis (SOWH) test, a
+parametric bootstrap test. The function is computational very demanding and
+likely to be very slow.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\seealso{
-  \code{\link{pml}}, \code{\link{pmlPart}}, \code{\link{pmlCluster}}, \code{\link{simSeq}}, \code{\link{SH.test}}
+\details{
+\code{SOWH.test} performs a parametric bootstrap test to compare two trees.
+It makes extensive use \code{simSeq} and \code{optim.pml} and can take quite
+long.
 }
 \examples{
+
 # in real analysis use larger n, e.g. 500 preferably more
 \dontrun{
 data(Laurasiatherian)
@@ -49,5 +52,22 @@ fit <- update(fit, tree = tree)
 (res <- SOWH.test(fit, n=100))
 summary(res)
 }
+
+}
+\references{
+Goldman, N., Anderson, J. P., and Rodrigo, A. G. (2000)
+Likelihood -based tests of topologies in phylogenetics. \emph{Systematic
+Biology} \bold{49} 652-670.
+
+Swofford, D.L., Olsen, G.J., Waddell, P.J. and Hillis, D.M. (1996)
+Phylogenetic Inference in Hillis, D.M., Moritz, C. and Mable, B.K. (Eds.)
+\emph{Molecular Systematics} (2nd ed.) 407-514, Sunderland, MA: Sinauer
+}
+\seealso{
+\code{\link{pml}}, \code{\link{pmlPart}}, \code{\link{pmlCluster}},
+\code{\link{simSeq}}, \code{\link{SH.test}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
 \keyword{models}
diff --git a/man/addConfidences.Rd b/man/addConfidences.Rd
index b2a23e0..429979f 100644
--- a/man/addConfidences.Rd
+++ b/man/addConfidences.Rd
@@ -1,57 +1,41 @@
-\name{addConfidences}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/networx.R
+\name{createLabel}
+\alias{createLabel}
 \alias{addConfidences}
 \alias{presenceAbsence}
-\alias{createLabel}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Compare splits and add support values to an object
-}
-\description{
-Add support values to a \code{splits}, \code{phylo} or \code{networx} object. 
-}
+\title{Compare splits and add support values to an object}
 \usage{
+createLabel(x, y, label_y, type = "edge", nomatch = NA)
+
 addConfidences(x, y, ...)
+
 presenceAbsence(x, y)
-createLabel(x, y, label_y, type = "edge", nomatch = NA)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{x}{
-an object of class \code{splits}, \code{phylo} or \code{networx}
-}
-  \item{y}{
-an object of class \code{splits}, \code{phylo}, \code{multiPhylo} or \code{networx}
-}
-  \item{...}{
-  Further arguments passed to or from other methods.
-  }
-  \item{label_y}{
-  label of y matched on x. Will be usually of length(as.splits(x)). 
-  }
-  \item{type}{
-  should labels returned for edges (in \code{networx}) or splits. 
-  }
-  \item{nomatch}{
-  default value if no match between x and y is found. 
-  }
+\item{x}{an object of class \code{splits}, \code{phylo} or \code{networx}}
+
+\item{y}{an object of class \code{splits}, \code{phylo}, \code{multiPhylo}
+or \code{networx}}
+
+\item{label_y}{label of y matched on x. Will be usually of
+length(as.splits(x)).}
+
+\item{type}{should labels returned for edges (in \code{networx}) or splits.}
+
+\item{nomatch}{default value if no match between x and y is found.}
+
+\item{...}{Further arguments passed to or from other methods.}
 }
-%%\details{
-%%  ~~ If necessary, more details than the description above ~~
-%%}
 \value{
-The object \code{x} with added bootstrap / MCMC support values. 
+The object \code{x} with added bootstrap / MCMC support values.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-%%\note{
-%%  ~~further notes~~
-%%}
-
-%% ~Make other sections like Warning with \section{Warning }{....} ~
-
-\seealso{
-\code{\link{as.splits}}, \code{\link{as.networx}}, \code{\link{RF.dist}}, \code{\link{plot.phylo}}
+\description{
+Add support values to a \code{splits}, \code{phylo} or \code{networx}
+object.
 }
 \examples{
+
 data(woodmouse)
 woodmouse <- phyDat(woodmouse)
 tmpfile <- normalizePath(system.file("extdata/trees/RAxML_bootstrap.woodmouse", package="phangorn"))
@@ -66,8 +50,13 @@ nnet <- addConfidences(nnet, boot_trees)
 
 plot(tree, show.node.label=TRUE)
 plot(nnet, "2D", show.edge.label=TRUE)
+
+}
+\seealso{
+\code{\link{as.splits}}, \code{\link{as.networx}},
+\code{\link{RF.dist}}, \code{\link{plot.phylo}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
-%%\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
+\keyword{cluster}
diff --git a/man/allTrees.Rd b/man/allTrees.Rd
index fbc82cb..b4bdc09 100644
--- a/man/allTrees.Rd
+++ b/man/allTrees.Rd
@@ -1,30 +1,36 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/treeManipulation.R
 \name{allTrees}
 \alias{allTrees}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{ Compute all trees topologies.}
-\description{
-\code{allTrees} computes all tree topologies for rooted or unrooted trees with up to 10 tips. \code{allTrees}  returns bifurcating trees.
-}
+\title{Compute all trees topologies.}
 \usage{
 allTrees(n, rooted = FALSE, tip.label = NULL)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{n}{Number of tips (<=10).}
-  \item{rooted}{Rooted or unrooted trees (default: rooted).  }
-  \item{tip.label}{Tip labels.}
+\item{n}{Number of tips (<=10).}
+
+\item{rooted}{Rooted or unrooted trees (default: rooted).}
+
+\item{tip.label}{Tip labels.}
 }
 \value{
-   an object of class \code{multiPhylo}. 
+an object of class \code{multiPhylo}.
+}
+\description{
+\code{allTrees} computes all tree topologies for rooted or unrooted trees
+with up to 10 tips. \code{allTrees} returns bifurcating trees.
 }
-\author{ Klaus Schliep \email{klaus.schliep at gmail.com} }
-
-\seealso{\code{\link[ape]{rtree}}, \code{\link{nni}}}
 \examples{
+
 trees <- allTrees(5)
 par(mfrow = c(3,5))
 for(i in 1:15)plot(trees[[i]])
+
+}
+\seealso{
+\code{\link[ape]{rtree}}, \code{\link{nni}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
+\keyword{cluster}
diff --git a/man/ancestral.pml.Rd b/man/ancestral.pml.Rd
index 4ba4a2a..5bf9b5e 100644
--- a/man/ancestral.pml.Rd
+++ b/man/ancestral.pml.Rd
@@ -1,60 +1,63 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/ancestral_pml.R, R/parsimony.R
 \name{ancestral.pml}
 \alias{ancestral.pml}
 \alias{ancestral.pars}
 \alias{pace}
 \alias{plotAnc}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Ancestral character reconstruction. 
-}
-\description{
-Marginal reconstruction of the ancestral character states.
-}
+\title{Ancestral character reconstruction.}
 \usage{
-ancestral.pml(object, type = c("marginal", "ml", "bayes"))
+ancestral.pml(object, type = c("marginal", "ml", "bayes"), return = "prob")
+
 ancestral.pars(tree, data, type = c("MPR", "ACCTRAN"), cost = NULL)
+
 pace(tree, data, type = c("MPR", "ACCTRAN"), cost = NULL)
-plotAnc(tree, data, i, col=NULL, cex.pie=par("cex"), pos="bottomright", ...)
+
+plotAnc(tree, data, i = 1, col = NULL, cex.pie = par("cex"),
+  pos = "bottomright", ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{object}{an object of class pml}
-%  \item{type}{either "ml" or "bayes"}
-  \item{tree}{a tree, i.e. an object of class pml}
-  \item{data}{an object of class phyDat} 
-  \item{type}{method used to assign characters to internal nodes, see details.}  
-  \item{i}{plots the i-th character of the \code{data}.}
-  \item{col}{a vector containing the colors for all possible states.}
-  \item{cex.pie}{a numeric defining the size of the pie graphs}
-  \item{pos}{a character string defining the position of the legend}
-  \item{cost}{A cost matrix for the transitions between two states.} 
-  \item{\dots}{Further arguments passed to or from other methods.}
-}
-%  \item{eps}{a small value to prevent rounding errors}
-\details{
-The argument "type" defines the criterion to assign the internal nodes. For \code{ancestral.pml} so far "ml" and
-(empirical) "bayes" and for \code{ancestral.pars} "MPR" and "ACCTRAN" are possible. 
+\item{object}{an object of class pml}
 
-With parsimony reconstruction one has to keep in mind that there will be often no unique solution.
+\item{type}{method used to assign characters to internal nodes, see details.}
 
-For further details see vignette("Ancestral").
+\item{return}{return a \code{phyDat} object or matrix of probabilities.}
+
+\item{tree}{a tree, i.e. an object of class pml}
+
+\item{data}{an object of class phyDat}
+
+\item{cost}{A cost matrix for the transitions between two states.}
+
+\item{i}{plots the i-th site pattern of the \code{data}.}
+
+\item{col}{a vector containing the colors for all possible states.}
+
+\item{cex.pie}{a numeric defining the size of the pie graphs}
+
+\item{pos}{a character string defining the position of the legend}
+
+\item{\dots}{Further arguments passed to or from other methods.}
 }
 \value{
-%A matrix containing the the estimates character states. 
-An object of class "phyDat", containing the ancestral states of all nodes. 
+%A matrix containing the the estimates character states. An object
+of class "phyDat", containing the ancestral states of all nodes.
 }
-\references{
-Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer Associates, Sunderland.
+\description{
+Marginal reconstruction of the ancestral character states.
+}
+\details{
+The argument "type" defines the criterion to assign the internal nodes. For
+\code{ancestral.pml} so far "ml" and (empirical) "bayes" and for
+\code{ancestral.pars} "MPR" and "ACCTRAN" are possible.
 
-Swofford, D.L., Maddison, W.P. (1987) Reconstructing ancestral character states under Wagner parsimony. \emph{Math. Biosci.} \bold{87}: 199--229
+With parsimony reconstruction one has to keep in mind that there will be
+often no unique solution.
 
-Yang, Z. (2006). \emph{Computational Molecular evolution}. Oxford University Press, Oxford.
-}
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\seealso{
-\code{\link{pml}}, \code{\link{parsimony}}, \code{\link[ape]{ace}}, \code{\link[ape]{root}} 
+For further details see vignette("Ancestral").
 }
 \examples{
+
 example(NJ)
 fit = pml(tree, Laurasiatherian)
 anc.ml = ancestral.pml(fit, type = "ml")
@@ -64,9 +67,28 @@ require(seqLogo)
 seqLogo( t(subset(anc.ml, 48, 1:20)[[1]]), ic.scale=FALSE)
 seqLogo( t(subset(anc.p, 48, 1:20)[[1]]), ic.scale=FALSE)
 }
+# plot the first site pattern
 plotAnc(tree, anc.ml, 1)
+# plot the third character 
+plotAnc(tree, anc.ml, attr(anc.ml, "index")[3])
+
+}
+\references{
+Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer
+Associates, Sunderland.
+
+Swofford, D.L., Maddison, W.P. (1987) Reconstructing ancestral character
+states under Wagner parsimony. \emph{Math. Biosci.} \bold{87}: 199--229
+
+Yang, Z. (2006). \emph{Computational Molecular evolution}. Oxford University
+Press, Oxford.
+}
+\seealso{
+\code{\link{pml}}, \code{\link{parsimony}}, \code{\link[ape]{ace}},
+\code{\link[ape]{root}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ ~kwd1 }
-\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
+\keyword{~kwd1}
+\keyword{~kwd2}
diff --git a/man/as.networx.Rd b/man/as.networx.Rd
new file mode 100644
index 0000000..9ef597f
--- /dev/null
+++ b/man/as.networx.Rd
@@ -0,0 +1,141 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/networx.R
+\name{as.networx}
+\alias{as.networx}
+\alias{networx}
+\alias{as.networx.splits}
+\alias{as.networx.phylo}
+\alias{plot.networx}
+\title{Phylogenetic networks}
+\usage{
+as.networx(x, ...)
+
+\method{as.networx}{splits}(x, planar = FALSE, coord = c("none", "2D",
+  "3D"), ...)
+
+\method{as.networx}{phylo}(x, ...)
+
+\method{plot}{networx}(x, type = "3D", use.edge.length = TRUE,
+  show.tip.label = TRUE, show.edge.label = FALSE, edge.label = NULL,
+  show.node.label = FALSE, node.label = NULL, show.nodes = FALSE,
+  tip.color = "black", edge.color = "black", edge.width = 3,
+  edge.lty = 1, split.color = NULL, split.width = NULL,
+  split.lty = NULL, font = 3, cex = par("cex"), cex.node.label = cex,
+  cex.edge.label = cex, col.node.label = tip.color,
+  col.edge.label = tip.color, font.node.label = font,
+  font.edge.label = font, ...)
+}
+\arguments{
+\item{x}{an object of class \code{"splits"} (as.networx) or \code{"networx"}
+(plot)}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+
+\item{planar}{logical whether to produce a planar graph from only cyclic
+splits (may excludes splits).}
+
+\item{coord}{add coordinates of the nodes, allows to reproduce the plot.}
+
+\item{type}{"3D" to plot using rgl or "2D" in the normal device.}
+
+\item{use.edge.length}{a logical indicating whether to use the edge weights
+of the network to draw the branches (the default) or not.}
+
+\item{show.tip.label}{a logical indicating whether to show the tip labels on
+the graph (defaults to \code{TRUE}, i.e. the labels are shown).}
+
+\item{show.edge.label}{a logical indicating whether to show the tip labels
+on the graph.}
+
+\item{edge.label}{an additional vector of edge labels (normally not needed).}
+
+\item{show.node.label}{a logical indicating whether to show the node labels
+(see example).}
+
+\item{node.label}{an additional vector of node labels (normally not needed).}
+
+\item{show.nodes}{a logical indicating whether to show the nodes (see
+example).}
+
+\item{tip.color}{the colors used for the tip labels.}
+
+\item{edge.color}{the colors used to draw edges.}
+
+\item{edge.width}{the width used to draw edges.}
+
+\item{edge.lty}{a vector of line types.}
+
+\item{split.color}{the colors used to draw edges.}
+
+\item{split.width}{the width used to draw edges.}
+
+\item{split.lty}{a vector of line types.}
+
+\item{font}{an integer specifying the type of font for the labels: 1 (plain
+text), 2 (bold), 3 (italic, the default), or 4 (bold italic).}
+
+\item{cex}{a numeric value giving the factor scaling of the labels.}
+
+\item{cex.node.label}{a numeric value giving the factor scaling of the node
+labels.}
+
+\item{cex.edge.label}{a numeric value giving the factor scaling of the edge
+labels.}
+
+\item{col.node.label}{the colors used for the node labels.}
+
+\item{col.edge.label}{the colors used for the edge labels.}
+
+\item{font.node.label}{the font used for the node labels.}
+
+\item{font.edge.label}{the font used for the edge labels.}
+}
+\description{
+\code{as.networx} convert \code{splits} objects into a \code{networx}
+object. And most important there exists a generic \code{plot} function to plot 
+phylogenetic network or split graphs.
+}
+\details{
+A \code{networx} object hold the information for a phylogenetic network and
+extends the \code{phylo} object. Therefore some generic function for
+\code{phylo} objects will also work for \code{networx} objects.  The
+argument \code{planar = TRUE} will create a planar split graph based on a cyclic
+ordering. These objects can be nicely plotted in \code{"2D"}. So far not all
+parameters behave the same on the the \code{rgl} \code{"3D"} and basic graphic \code{"2D"}
+device.
+
+Often it is easier and safer to supply vectors of graphical parameters for
+splits (e.g. splits.color) than for edges. These overwrite values edge.color.
+}
+\note{
+The internal representation is likely to change.
+}
+\examples{
+
+set.seed(1)
+tree1 = rtree(20, rooted=FALSE)
+sp = as.splits(rNNI(tree1, n=10))
+net = as.networx(sp)
+plot(net, "2D")
+\dontrun{
+# also see example in consensusNet 
+example(consensusNet)
+}
+
+}
+\references{
+Dress, A.W.M. and Huson, D.H. (2004) Constructing Splits Graphs
+\emph{IEEE/ACM Transactions on Computational Biology and Bioinformatics
+(TCBB)}, \bold{1(3)}, 109--115
+}
+\seealso{
+\code{\link{consensusNet}}, \code{\link{neighborNet}},
+\code{\link{splitsNetwork}}, \code{\link{hadamard}},
+\code{\link{distanceHadamard}}, \code{\link{layout_with_kk}},
+\code{\link[ape]{evonet}}, \code{\link[ape]{as.igraph}},
+\code{\link{densiTree}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{plot}
diff --git a/man/as.splits.Rd b/man/as.splits.Rd
index 93041a0..eaa8027 100644
--- a/man/as.splits.Rd
+++ b/man/as.splits.Rd
@@ -1,89 +1,110 @@
-\name{as.splits}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/networx.R, R/splits.R
+\name{allSplits}
+\alias{allSplits}
+\alias{allCircularSplits}
 \alias{as.splits}
-\alias{as.prop.part.splits}
-\alias{as.splits.phylo}
-\alias{as.splits.multiPhylo}
-\alias{as.splits.networx}
-\alias{as.matrix.splits}
+\alias{splits}
 \alias{as.Matrix}
-\alias{as.Matrix.splits}
-\alias{c.splits}
 \alias{distinct.splits}
-\alias{print.splits}
-\alias{write.splits}
-\alias{allSplits}
-\alias{allCircularSplits}
-\alias{compatible}
-\alias{write.nexus.splits}
-\alias{read.nexus.splits}
 \alias{as.phylo.splits}
-\alias{countCycles}
 \alias{addTrivialSplits}
+\alias{removeTrivialSplits}
 \alias{matchSplits}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Splits representation of graphs and trees.
-}
-\description{
-\code{as.splits} produces a list of splits or bipartitions. 
-}
+\alias{as.matrix.splits}
+\alias{as.Matrix.splits}
+\alias{print.splits}
+\alias{c.splits}
+\alias{unique.splits}
+\alias{as.splits.phylo}
+\alias{as.splits.multiPhylo}
+\alias{as.splits.networx}
+\alias{as.prop.part.splits}
+\alias{as.bitsplits.splits}
+\alias{compatible}
+\title{Splits representation of graphs and trees.}
 \usage{
+allSplits(k, labels = NULL)
+
+allCircularSplits(k, labels = NULL)
+
 as.splits(x, ...)
+
+\method{as.matrix}{splits}(x, zero.print = 0L, one.print = 1L, ...)
+
+\method{as.Matrix}{splits}(x, ...)
+
+\method{print}{splits}(x, maxp = getOption("max.print"), zero.print = ".",
+  one.print = "|", ...)
+
+\method{c}{splits}(..., recursive = FALSE)
+
+\method{unique}{splits}(x, incomparables = FALSE, unrooted = TRUE, ...)
+
 \method{as.splits}{phylo}(x, ...)
+
 \method{as.splits}{multiPhylo}(x, ...)
-\method{print}{splits}(x, maxp = getOption("max.print"), zero.print = ".", 
-    one.print = "|", ...)
-\method{as.prop.part}{splits}(x, ...)    
+
+\method{as.splits}{networx}(x, ...)
+
+\method{as.prop.part}{splits}(x, ...)
+
+\method{as.bitsplits}{splits}(x)
+
 compatible(obj)
-allSplits(k, labels = NULL)
-allCircularSplits(k, labels = NULL)
-write.nexus.splits(obj, file = "", weights=NULL, taxa=TRUE, append=FALSE)
-read.nexus.splits(file)
-addTrivialSplits(obj)
-distinct.splits(...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{x}{An object of class phylo or multiPhylo.}
-  \item{maxp}{integer, default from \code{options(max.print)}, influences how many entries of large matrices are printed at all.} 
-  \item{zero.print}{character which should be printed for zeros.} 
-  \item{one.print}{character which should be printed for ones.} 
-  \item{\dots}{Further arguments passed to or from other methods.}
-  \item{obj}{an object of class splits.} 
-  \item{k}{number of taxa.}
-  \item{labels}{names of taxa.}   
-  \item{file}{ a file name.}
-  \item{weights}{ Edge weights.}
-  \item{taxa}{logical. If TRUE a taxa block is added}
-  \item{append}{logical. If TRUE the nexus blocks will be added to a file.}
+\item{k}{number of taxa.}
+
+\item{labels}{names of taxa.}
+
+\item{x}{An object of class phylo or multiPhylo.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+
+\item{zero.print}{character which should be printed for zeros.}
+
+\item{one.print}{character which should be printed for ones.}
+
+\item{maxp}{integer, default from \code{options(max.print)}, influences how
+many entries of large matrices are printed at all.}
+
+\item{recursive}{logical. If recursive = TRUE, the function recursively descends 
+through lists (and pairlists) combining all their elements into a vector.}
+
+\item{incomparables}{only for compatibility so far.}
+
+\item{unrooted}{todo.}
+
+\item{obj}{an object of class splits.}
 }
 \value{
-\code{as.splits} returns an object of class splits, which is mainly a list of splits and some attributes.
-Often a \code{splits} object will contain attributes \code{confidences} for bootstrap or Bayesian support values and 
-\code{weight} storing edge weights. \code{read.nexus.splits} and \code{write.nexus.splits} allow to exchange a
-\code{splits} object with other software like Splitstree.
-
-\code{compatible} return a lower triangular matrix where an 1 indicates that two splits are incompatible.   
+\code{as.splits} returns an object of class splits, which is mainly
+a list of splits and some attributes. Often a \code{splits} object will
+contain attributes \code{confidences} for bootstrap or Bayesian support
+values and \code{weight} storing edge weights.  
+\code{compatible} return a lower triangular matrix where an 1 indicates that
+two splits are incompatible.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\note{
-The internal representation is likely to change. 
-\code{read.nexus.splits} reads in the splits block of a nexus file. It assumes that different co-variables are tab delimited and the bipartition are separated with white-space. Comments in square brackets are ignored. 
+\description{
+\code{as.splits} produces a list of splits or bipartitions.
 }
-
-%% ~Make other sections like Warning with \section{Warning }{....} ~
-
-\seealso{
-\code{\link{prop.part}}, \code{\link{lento}}, \code{\link{distanceHadamard}}, \code{\link{as.networx}}
+\note{
+The internal representation is likely to change.
 }
-%% as.phylo.splits
 \examples{
+
 (sp <- as.splits(rtree(5)))
 write.nexus.splits(sp)
 spl <- allCircularSplits(5)
 plot(as.networx(spl), "2D")
-}
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
 
+}
+\seealso{
+\code{\link{prop.part}}, \code{\link{lento}}, \code{\link{as.networx}}, 
+\code{\link{distanceHadamard}}, \code{\link{read.nexus.splits}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/bab.Rd b/man/bab.Rd
index 136ad84..efb7b8f 100644
--- a/man/bab.Rd
+++ b/man/bab.Rd
@@ -1,64 +1,66 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/fitch.R
 \name{bab}
 \alias{bab}
 \alias{BranchAndBound}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Branch and bound for finding all most parsimonious trees 
-}
-\description{
-\code{bab} finds all most parsimonious trees. 
-}
+\title{Branch and bound for finding all most parsimonious trees}
 \usage{
 bab(data, tree = NULL, trace = 1, ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{data}{
-an object of class phyDat.
-}
-  \item{tree}{
-a phylogenetic tree an object of class phylo, otherwise a pratchet search is performed.
-}
-  \item{trace}{
-defines how much information is printed during optimisation.
+\item{data}{an object of class phyDat.}
+
+\item{tree}{a phylogenetic tree an object of class phylo, otherwise a
+pratchet search is performed.}
+
+\item{trace}{defines how much information is printed during optimisation.}
+
+\item{\dots}{Further arguments passed to or from other methods}
 }
-  \item{\dots}{
-Further arguments passed to or from other methods
+\value{
+\code{bab} returns all most parsimonious trees in an object of class
+\code{multiPhylo}.
 }
+\description{
+\code{bab} finds all most parsimonious trees.
 }
 \details{
-This implementation is very slow and depending on the data may take very long time.
-In the worst case all (2n-5)!! possible trees have to be examined. For 10 species 
-there are already 2027025 tip-labelled unrooted trees.
-It only uses some basic strategies to find a lower and upper bounds similar to penny from phylip.
-It uses a very basic heuristic approach of MinMax Squeeze (Holland et al. 2005) to improve the lower bound.  
-On the positive side \code{bab} is not like many other implementations restricted to binary or nucleotide data. 
+This implementation is very slow and depending on the data may take very
+long time. In the worst case all (2n-5)!! possible trees have to be
+examined. For 10 species there are already 2027025 tip-labelled unrooted
+trees. It only uses some basic strategies to find a lower and upper bounds
+similar to penny from phylip. It uses a very basic heuristic approach of
+MinMax Squeeze (Holland et al. 2005) to improve the lower bound.  On the
+positive side \code{bab} is not like many other implementations restricted
+to binary or nucleotide data.
 }
-\value{
-\code{bab} returns all most parsimonious trees in an object of class \code{multiPhylo}. 
+\examples{
+
+data(yeast)
+dfactorial(11)
+# choose only the first two genes
+gene12 <- subset(yeast, , 1:3158, site.pattern=FALSE) 
+trees <- bab(gene12)
+
 }
 \references{
-Hendy, M.D. and Penny D. (1982) Branch and bound algorithms to determine minimal evolutionary trees. 
-\emph{Math. Biosc.} \bold{59}, 277-290 
+Hendy, M.D. and Penny D. (1982) Branch and bound algorithms to
+determine minimal evolutionary trees.  \emph{Math. Biosc.} \bold{59},
+277-290
 
-Holland, B.R., Huber, K.T. Penny, D. and Moulton, V. (2005) The MinMax Squeeze: Guaranteeing a Minimal Tree for Population Data, \emph{Molecular Biology and Evolution}, \bold{22}, 235--242  
+Holland, B.R., Huber, K.T. Penny, D. and Moulton, V. (2005) The MinMax
+Squeeze: Guaranteeing a Minimal Tree for Population Data, \emph{Molecular
+Biology and Evolution}, \bold{22}, 235--242
 
-White, W.T. and Holland, B.R. (2011) Faster exact maximum parsimony search with XMP. \emph{Bioinformatics}, \bold{27(10)},1359--1367  
-}
-\author{
-Klaus Schliep \email{klaus.schliep at gmail.com} based on work on Liam Revell
+White, W.T. and Holland, B.R. (2011) Faster exact maximum parsimony search
+with XMP. \emph{Bioinformatics}, \bold{27(10)},1359--1367
 }
 \seealso{
 \code{\link{pratchet}}, \code{\link{dfactorial}}
 }
-\examples{
-data(yeast)
-dfactorial(11)
-# choose only the first two genes
-gene12 <- subset(yeast, , 1:3158, site.pattern=FALSE) 
-trees <- bab(gene12)
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com} based on work on Liam
+Revell
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
-\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
+\keyword{cluster}
+\keyword{~kwd2}
diff --git a/man/bootstrap.pml.Rd b/man/bootstrap.pml.Rd
index b4ef2ec..cdf0e58 100644
--- a/man/bootstrap.pml.Rd
+++ b/man/bootstrap.pml.Rd
@@ -1,87 +1,79 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/bootstrap.R
 \name{bootstrap.pml}
-%\Rdversion{1.1}
 \alias{bootstrap.pml}
 \alias{bootstrap.phyDat}
 \alias{plotBS}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Bootstrap }
-\description{
-\code{bootstrap.pml} performs (non-parametric) bootstrap analysis and \code{bootstrap.phyDat} produces a list of bootstrapped data sets. \code{plotBS} plots a phylogenetic tree with the with the bootstrap values assigned to the (internal) edges.}
+\title{Bootstrap}
 \usage{
-bootstrap.pml(x, bs = 100, trees = TRUE, multicore=FALSE, mc.cores = NULL, ...)
-bootstrap.phyDat(x, FUN, bs = 100, multicore=FALSE, mc.cores = NULL, jumble = TRUE, ...)
-plotBS(tree, BStrees, type="unrooted", bs.col="black", bs.adj=NULL, p=50, frame=none, ...)
+bootstrap.pml(x, bs = 100, trees = TRUE, multicore = FALSE,
+  mc.cores = NULL, ...)
+
+bootstrap.phyDat(x, FUN, bs = 100, multicore = FALSE, mc.cores = NULL,
+  jumble = TRUE, ...)
+
+plotBS(tree, BStrees, type = "unrooted", bs.col = "black", bs.adj = NULL,
+  p = 50, frame = "none", ...)
 }
 \arguments{
-  \item{x}{
-an object of class \code{pml} or \code{phyDat}.
-}
-  \item{bs}{
-number of bootstrap samples.
-}
-  \item{trees}{
-return trees only (default) or whole \code{pml} objects.  
-}
-%  \item{multicore}{
-%logical, if TRUE analysis is performed in parallel (see details).
-%}
+\item{x}{an object of class \code{pml} or \code{phyDat}.}
+
+\item{bs}{number of bootstrap samples.}
+
+\item{trees}{return trees only (default) or whole \code{pml} objects.}
+
 \item{multicore}{logical, whether models should estimated in parallel.}
-  \item{mc.cores}{
-The number of cores to use during bootstrap. Only supported on UNIX-alike systems.
-}
+
+\item{mc.cores}{The number of cores to use during bootstrap. Only supported
+on UNIX-alike systems.}
+
+\item{\dots}{further parameters used by \code{optim.pml} or
+\code{plot.phylo}.}
+
+\item{FUN}{the function to estimate the trees.}
+
 \item{jumble}{logical, jumble the order of the sequences.}
-  \item{\dots}{
-further parameters used by \code{optim.pml} or \code{plot.phylo}.
-}
-  \item{FUN}{ 
-the function to estimate the trees.
-}
-  \item{tree}{ 
-The tree on which edges the bootstrap values are plotted.
-}
-  \item{BStrees}{ 
-a list of trees (object of class "multiPhylo"). 
-}
-  \item{type}{ 
-the type of tree to plot, so far "cladogram", "phylogram" and "unrooted" are supported.
-}
-  \item{bs.col}{ 
-color of bootstrap support labels.
-}
-  \item{bs.adj}{ 
-one or two numeric values specifying the horizontal and vertical justification of the bootstrap labels.
-}
-  \item{p}{ 
-only plot support values higher than this percentage number (default is 80).
-}
-  \item{frame}{
-     a character string specifying the kind of frame to be printed around the bootstrap values. This must be one of "none" (the default), "rect" or "circle".
-  }
-}
-\details{
-It is possible that the bootstrap is performed in parallel, with help of the multicore package.
-Unfortunately the  multicore package does not work under windows or with GUI interfaces ("aqua" on a mac).
-However it will speed up nicely from the command line ("X11"). 
-}
-\value{
-\code{bootstrap.pml} returns an object of class \code{multi.phylo} or a list where each 
-element is an object of class \code{pml}. \code{plotBS} returns silently a tree, i.e. an object of class \code{phylo} with the bootstrap values as node labels. The argument \code{BStrees} is optional and if not supplied the tree with labels supplied in the \code{node.label} slot. 
-}
-\references{
-Felsenstein J. (1985) Confidence limits on phylogenies. An approach using the bootstrap. \emph{Evolution} \bold{39}, 783--791
 
-Penny D. and Hendy M.D. (1985) Testing methods evolutionary tree construction. \emph{Cladistics} \bold{1}, 266--278
+\item{tree}{The tree on which edges the bootstrap values are plotted.}
+
+\item{BStrees}{a list of trees (object of class "multiPhylo").}
+
+\item{type}{the type of tree to plot, so far "cladogram", "phylogram" and
+"unrooted" are supported.}
+
+\item{bs.col}{color of bootstrap support labels.}
+
+\item{bs.adj}{one or two numeric values specifying the horizontal and
+vertical justification of the bootstrap labels.}
+
+\item{p}{only plot support values higher than this percentage number
+(default is 80).}
 
-Penny D. and Hendy M.D. (1986) Estimating the reliability of evolutionary trees. \emph{Molecular Biology and Evolution} \bold{3}, 403--417
+\item{frame}{a character string specifying the kind of frame to be printed
+around the bootstrap values. This must be one of "none" (the default),
+"rect" or "circle".}
 }
-\author{
-Klaus Schliep \email{klaus.schliep at gmail.com}
+\value{
+\code{bootstrap.pml} returns an object of class \code{multi.phylo}
+or a list where each element is an object of class \code{pml}. \code{plotBS}
+returns silently a tree, i.e. an object of class \code{phylo} with the
+bootstrap values as node labels. The argument \code{BStrees} is optional and
+if not supplied the tree with labels supplied in the \code{node.label} slot.
 }
-\seealso{
-\code{\link{optim.pml}}, \code{\link{pml}}, \code{\link{plot.phylo}}, \code{\link{nodelabels}},\code{\link{consensusNet}} and \code{\link{SOWH.test}} for parametric bootstrap
+\description{
+\code{bootstrap.pml} performs (non-parametric) bootstrap analysis and
+\code{bootstrap.phyDat} produces a list of bootstrapped data sets.
+\code{plotBS} plots a phylogenetic tree with the with the bootstrap values
+assigned to the (internal) edges.
+}
+\details{
+It is possible that the bootstrap is performed in parallel, with help of the
+multicore package. Unfortunately the multicore package does not work under
+windows or with GUI interfaces ("aqua" on a mac). However it will speed up
+nicely from the command line ("X11").
 }
 \examples{
+
 \dontrun{
 data(Laurasiatherian)
 dm <- dist.logDet(Laurasiatherian)
@@ -109,9 +101,25 @@ add.scale.bar()
 # export tree with bootstrap values as node labels
 # write.tree(treeBS)
 }
+
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{cluster}
+\references{
+Felsenstein J. (1985) Confidence limits on phylogenies. An
+approach using the bootstrap. \emph{Evolution} \bold{39}, 783--791
 
+Penny D. and Hendy M.D. (1985) Testing methods evolutionary tree
+construction. \emph{Cladistics} \bold{1}, 266--278
 
+Penny D. and Hendy M.D. (1986) Estimating the reliability of evolutionary
+trees. \emph{Molecular Biology and Evolution} \bold{3}, 403--417
+}
+\seealso{
+\code{\link{optim.pml}}, \code{\link{pml}},
+\code{\link{plot.phylo}},
+\code{\link{nodelabels}},\code{\link{consensusNet}} and
+\code{\link{SOWH.test}} for parametric bootstrap
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/chloroplast.Rd b/man/chloroplast.Rd
index a95638b..77525e0 100644
--- a/man/chloroplast.Rd
+++ b/man/chloroplast.Rd
@@ -1,19 +1,16 @@
-\name{chloroplast}
-\alias{chloroplast}
-\docType{data}
-\title{ Chloroplast alignment }
-\description{
-Amino acid alignment of 15 genes of 19 different chloroplast.}
-\usage{data(yeast)}
-
-%\references{
-%Nisbet R.E.R, Schliep K., Steel M.A., Knapp M. Howe C.J. and Lockhart P.J. (2009)
-%The slop of rocks and clocks
-%\emph{Potato growers weekly}, \bold{425}(6960): 798--804
-%}    
-
-\examples{
-data(chloroplast)
-chloroplast
-}
-\keyword{datasets}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/phangorn-package.R
+\docType{data}
+\name{chloroplast}
+\alias{chloroplast}
+\title{Chloroplast alignment}
+\description{
+Amino acid alignment of 15 genes of 19 different chloroplast.
+}
+\examples{
+
+data(chloroplast)
+chloroplast
+
+}
+\keyword{datasets}
diff --git a/man/cladePar.Rd b/man/cladePar.Rd
index c771e88..40cee59 100644
--- a/man/cladePar.Rd
+++ b/man/cladePar.Rd
@@ -1,63 +1,50 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/cladePar.R
 \name{cladePar}
 \alias{cladePar}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Utility function to plot.phylo 
-}
-\description{
-cladePar can help you coloring (choosing edge width/type) of clades. 
-}
+\title{Utility function to plot.phylo}
 \usage{
-cladePar(tree, node, edge.color = "red", tip.color = edge.color, edge.width = 1,
-    edge.lty = 1, x = NULL, plot = FALSE, ...)
+cladePar(tree, node, edge.color = "red", tip.color = edge.color,
+  edge.width = 1, edge.lty = 1, x = NULL, plot = FALSE, ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{tree}{
-an object of class phylo.
-}
-  \item{node}{
-the node which is the common ancestor of the clade. 
-}
-  \item{edge.color}{
-see plot.phylo.
-}
-  \item{tip.color}{
-see plot.phylo.
-}
-  \item{edge.width}{
-see plot.phylo.
-}
-  \item{edge.lty}{
-see plot.phylo.
-}
-  \item{x}{
-the result of a previous call to cladeInfo.
-}
-  \item{plot}{
-logical, if TRUE the tree is plotted.   
-}
-  \item{\dots}{
-Further arguments passed to or from other methods.
-}
+\item{tree}{an object of class phylo.}
+
+\item{node}{the node which is the common ancestor of the clade.}
+
+\item{edge.color}{see plot.phylo.}
+
+\item{tip.color}{see plot.phylo.}
+
+\item{edge.width}{see plot.phylo.}
+
+\item{edge.lty}{see plot.phylo.}
+
+\item{x}{the result of a previous call to cladeInfo.}
+
+\item{plot}{logical, if TRUE the tree is plotted.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
 }
 \value{
-A list containing the information about the edges and tips. 
-}
-\author{
-Klaus Schliep \email{klaus.schliep at gmail.com}
+A list containing the information about the edges and tips.
 }
-\seealso{
-\code{\link{plot.phylo}}
+\description{
+cladePar can help you coloring (choosing edge width/type) of clades.
 }
 \examples{
+
 tree = rtree(10)
 plot(tree)
 nodelabels()
 x = cladePar(tree, 12)
 cladePar(tree, 18, "blue", "blue", x=x, plot=TRUE)
+
+}
+\seealso{
+\code{\link{plot.phylo}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
 \keyword{plot}
-
diff --git a/man/coalSpeciesTree.Rd b/man/coalSpeciesTree.Rd
new file mode 100644
index 0000000..39847a2
--- /dev/null
+++ b/man/coalSpeciesTree.Rd
@@ -0,0 +1,41 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/Coalescent.R
+\name{coalSpeciesTree}
+\alias{coalSpeciesTree}
+\title{Species Tree}
+\usage{
+coalSpeciesTree(tree, X, sTree = NULL)
+}
+\arguments{
+\item{tree}{an object of class \code{multiPhylo}}
+
+\item{X}{A \code{phyDat} object to define which individual belongs to which
+species.}
+
+\item{sTree}{A species tree which fixes the topology.}
+}
+\value{
+The function returns an object of class \code{phylo}.
+}
+\description{
+\code{coalSpeciesTree} estimates species trees and can handle multiple
+individuals per species.
+}
+\details{
+\code{coalSpeciesTree} estimates a single linkage tree as suggested by Liu
+et al. (2010) from the element wise minima of the cophenetic matrices of the
+gene trees. It extends \code{speciesTree} in ape as it allows that have
+several individuals per gene tree.
+}
+\references{
+Liu, L., Yu, L. and Pearl, D. K. (2010) Maximum tree: a
+consistent estimator of the species tree. \emph{Journal of Mathematical
+Biology}, \bold{60}, 95--106.
+}
+\seealso{
+\code{\link{speciesTree}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com} Emmanuel Paradies
+}
+\keyword{cluster}
diff --git a/man/consensusNet.Rd b/man/consensusNet.Rd
index 9bdaed1..afcf37f 100644
--- a/man/consensusNet.Rd
+++ b/man/consensusNet.Rd
@@ -1,41 +1,31 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/networx.R
 \name{consensusNet}
 \alias{consensusNet}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Computes a consensusNetwork from a list of trees
-Computes a \code{networx} object from a collection of splits.
-}
-\description{
-Computes a consensusNetwork, i.e. an object of class \code{networx} from a list of trees,  i.e. an class of class \code{multiPhylo}.
-Computes a \code{networx} object from a collection of splits.
-}
+\title{Computes a consensusNetwork from a list of trees Computes a \code{networx}
+object from a collection of splits.}
 \usage{
-consensusNet(obj, prob=.3, ...)
-
+consensusNet(obj, prob = 0.3, ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{obj}{An object of class multiPhylo.} 
-  \item{prob}{the proportion a split has to be present in all trees to be represented in the network.} 
-  \item{\dots}{Further arguments passed to or from other methods.}
-}
-\value{
-\code{consensusNet} returns an object of class networx. 
-This is just an intermediate to plot phylogenetic networks with igraph.   
-}
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-
+\item{obj}{An object of class multiPhylo.}
 
+\item{prob}{the proportion a split has to be present in all trees to be
+represented in the network.}
 
-%% ~Make other sections like Warning with \section{Warning }{....} ~
-
-\references{ 
-Holland B.R., Huber K.T., Moulton V., Lockhart P.J. (2004) Using consensus networks to visualize contradictory evidence for species phylogeny. \emph{Molecular Biology and Evolution}, \bold{21}, 1459--61
+\item{\dots}{Further arguments passed to or from other methods.}
 }
-\seealso{
-\code{\link{splitsNetwork}}, \code{\link{neighborNet}}, \code{\link{lento}}, \code{\link{distanceHadamard}}, \code{\link{plot.networx}}, \code{\link{maxCladeCred}}
+\value{
+\code{consensusNet} returns an object of class networx.  This is
+just an intermediate to plot phylogenetic networks with igraph.
+}
+\description{
+Computes a consensusNetwork, i.e. an object of class \code{networx} from a
+list of trees, i.e. an class of class \code{multiPhylo}. Computes a
+\code{networx} object from a collection of splits.
 }
 \examples{
+
 data(Laurasiatherian)
 set.seed(1)
 bs <- bootstrap.phyDat(Laurasiatherian, FUN = function(x)nj(dist.hamming(x)), 
@@ -54,8 +44,19 @@ trees <- read.tree(tmpfile)
 cnet_woodmouse = consensusNet(trees, .3)
 plot(cnet_woodmouse, type = "2D", show.edge.label=TRUE)
 }
-}
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ hplot }
 
+}
+\references{
+Holland B.R., Huber K.T., Moulton V., Lockhart P.J. (2004) Using
+consensus networks to visualize contradictory evidence for species
+phylogeny. \emph{Molecular Biology and Evolution}, \bold{21}, 1459--61
+}
+\seealso{
+\code{\link{splitsNetwork}}, \code{\link{neighborNet}},
+\code{\link{lento}}, \code{\link{distanceHadamard}},
+\code{\link{plot.networx}}, \code{\link{maxCladeCred}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{hplot}
diff --git a/man/cophenetic.networx.Rd b/man/cophenetic.networx.Rd
index 09fb985..1adc540 100644
--- a/man/cophenetic.networx.Rd
+++ b/man/cophenetic.networx.Rd
@@ -1,25 +1,28 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/treedist.R
 \name{cophenetic.networx}
 \alias{cophenetic.networx}
 \alias{cophenetic.splits}
 \title{Pairwise Distances from a Phylogenetic Network}
 \usage{
 \method{cophenetic}{networx}(x)
-\method{cophenetic}{splits}(x)
 }
 \arguments{
-  \item{x}{an object of class \code{"networx"}.}
-}
-\description{
-  \code{cophenetic.networx} computes the pairwise distances between the 
-  pairs of tips from a phylogenetic network using its branch lengths.
+\item{x}{an object of class \code{networx}.}
 }
 \value{
-  an object of class \code{dist}, names are set according to the 
-  tip labels (as given by the element \code{tip.label} of the argument \code{x}).
+an object of class \code{dist}, names are set according to the tip
+labels (as given by the element \code{tip.label} of the argument \code{x}).
+}
+\description{
+\code{cophenetic.networx} computes the pairwise distances between the pairs
+of tips from a phylogenetic network using its branch lengths.
 }
-\author{Klaus Schliep}
 \seealso{
-  \code{\link[stats]{cophenetic}} for the generic function, 
-  \code{neighborNet} to construct a network from a distance matrix
+\code{\link[stats]{cophenetic}} for the generic function,
+\code{neighborNet} to construct a network from a distance matrix
+}
+\author{
+Klaus Schliep
 }
 \keyword{manip}
diff --git a/man/delta.score.Rd b/man/delta.score.Rd
index 0e8f72e..20f13ca 100644
--- a/man/delta.score.Rd
+++ b/man/delta.score.Rd
@@ -1,57 +1,44 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/delta.score.R
 \name{delta.score}
 \alias{delta.score}
-
-\title{
-Computes the \eqn{\delta} score
-}
-\description{
-Computes the treelikeness  
-}
+\title{Computes the \eqn{\delta} score}
 \usage{
 delta.score(x, arg = "mean", ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{x}{
-an object of class \code{phyDat}
-}
-  \item{arg}{
-Specifies the return value, one of "all", "mean" or "sd"
+\item{x}{an object of class \code{phyDat}}
+
+\item{arg}{Specifies the return value, one of "all", "mean" or "sd"}
+
+\item{...}{further arguments passed through \code{dist.hamming}}
 }
-  \item{...}{
-     further arguments passed through \code{dist.hamming}
+\value{
+A vector containing the \eqn{\delta} scores.
 }
+\description{
+Computes the treelikeness
 }
-%\details{
-%%  ~~ If necessary, more details than the description above ~~
-%}
-\value{
-A vector containing the \eqn{\delta} scores. 
+\examples{
+
+data(yeast)
+hist(delta.score(yeast, "all"))
+
 }
 \references{
-BR Holland, KT Huber, A Dress, V Moulton (2002) \eqn{\delta} Plots: a tool for analyzing phylogenetic distance data
-Russell D. Gray, David Bryant, Simon J. Greenhill (2010) On the shape and fabric of human history 
-\emph{Molecular Biology and Evolution}, \bold{19(12)} 2051--2059
+BR Holland, KT Huber, A Dress, V Moulton (2002) \eqn{\delta}
+Plots: a tool for analyzing phylogenetic distance data Russell D. Gray,
+David Bryant, Simon J. Greenhill (2010) On the shape and fabric of human
+history \emph{Molecular Biology and Evolution}, \bold{19(12)} 2051--2059
 
-Russell D. Gray, David Bryant, Simon J. Greenhill (2010) On the shape and fabric of human history 
-\emph{Phil. Trans. R. Soc. B}, \bold{365} 3923--3933; DOI: 10.1098/rstb.2010.0162
+Russell D. Gray, David Bryant, Simon J. Greenhill (2010) On the shape and
+fabric of human history \emph{Phil. Trans. R. Soc. B}, \bold{365}
+3923--3933; DOI: 10.1098/rstb.2010.0162
 }
-\author{
-Alastair Potts and Klaus Schliep 
-}
-%\note{
-%%  ~~further notes~~
-%}
-
-%% ~Make other sections like Warning with \section{Warning }{....} ~
-
 \seealso{
- \code{\link{dist.hamming}}
+\code{\link{dist.hamming}}
 }
-\examples{
-data(yeast)
-hist(delta.score(yeast, "all"))
+\author{
+Alastair Potts and Klaus Schliep
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
+\keyword{cluster}
diff --git a/man/densiTree.Rd b/man/densiTree.Rd
index d9023d9..c55c813 100644
--- a/man/densiTree.Rd
+++ b/man/densiTree.Rd
@@ -1,66 +1,45 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/Densi.R
 \name{densiTree}
 \alias{densiTree}
-\title{
-Plots a densiTree. 
-}
-\description{
-An R function to plot trees similar to those produced by DensiTree. 
-}
+\title{Plots a densiTree.}
 \usage{
-densiTree(x, type = "cladogram", alpha = 1/length(x), consensus = NULL, optim = FALSE, 
-    scaleX = FALSE, col = 1, width = 1, cex = 0.8, ...)
+densiTree(x, type = "cladogram", alpha = 1/length(x), consensus = NULL,
+  optim = FALSE, scaleX = FALSE, col = 1, width = 1, cex = 0.8, ...)
 }
 \arguments{
-\item{x}{
-an object of class \code{multiPhylo}.
-}
-\item{type}{
-a character string specifying the type of phylogeny, so far "cladogram" (default) or "phylogram" (the default) are supported. 
-}
-\item{alpha}{
-parameter for semi-transparent colors. 
-}
-\item{consensus}{
-A tree which is used to define the order of the tip labels.
-}
-\item{optim}{
-not yet used. 
-}
-\item{scaleX}{
-scale trees to have identical heights.
-}
-\item{col}{
-edge color.
-}
-\item{width}{
-edge width. 
-}
-\item{cex}{
-a numeric value giving the factor scaling of the tip labels.
-}
-\item{\dots}{
-further arguments to be passed to plot.
-}
-}
-\details{
-If no consensus tree is provided \code{densiTree} computes a rooted mrp.supertree as a backbone. This should avoid too many unnecessary crossings of edges.  
-Trees should be rooted, other wise the output may not make sense. 
-}
-\references{
-densiTree is inspired from the great \href{www.cs.auckland.ac.nz/~remco/DensiTree}{DensiTree} program of Remco Bouckaert. 
+\item{x}{an object of class \code{multiPhylo}.}
 
-Remco R. Bouckaert (2010) DensiTree: making sense of sets of phylogenetic trees
-\emph{Bioinformatics}, \bold{26 (10)}, 1372-1373. 
-}
-\author{
-Klaus Schliep \email{klaus.schliep at gmail.com}
-}
+\item{type}{a character string specifying the type of phylogeny, so far
+"cladogram" (default) or "phylogram" (the default) are supported.}
 
+\item{alpha}{parameter for semi-transparent colors.}
 
-\seealso{
-\code{\link{plot.phylo}}, \code{\link{plot.networx}}
+\item{consensus}{A tree which is used to define the order of the tip labels.}
+
+\item{optim}{not yet used.}
+
+\item{scaleX}{scale trees to have identical heights.}
+
+\item{col}{edge color.}
+
+\item{width}{edge width.}
+
+\item{cex}{a numeric value giving the factor scaling of the tip labels.}
+
+\item{\dots}{further arguments to be passed to plot.}
+}
+\description{
+An R function to plot trees similar to those produced by DensiTree.
+}
+\details{
+If no consensus tree is provided \code{densiTree} computes a rooted
+mrp.supertree as a backbone. This should avoid too many unnecessary
+crossings of edges.  Trees should be rooted, other wise the output may not
+make sense.
 }
-\examples{  
+\examples{
+  
 data(Laurasiatherian)
 set.seed(1)
 bs <- bootstrap.phyDat(Laurasiatherian, FUN = 
@@ -76,8 +55,20 @@ BinindaEmondsEtAl2007 <- .compressTipLabel(BinindaEmondsEtAl2007)
 densiTree(BinindaEmondsEtAl2007, type="phylogram", col="red")
 }
 
+
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{plot}
+\references{
+densiTree is inspired from the great
+\href{https://www.cs.auckland.ac.nz/~remco/DensiTree}{DensiTree} program of Remco
+Bouckaert.
 
+Remco R. Bouckaert (2010) DensiTree: making sense of sets of phylogenetic
+trees \emph{Bioinformatics}, \bold{26 (10)}, 1372-1373.
+}
+\seealso{
+\code{\link{plot.phylo}}, \code{\link{plot.networx}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{plot}
diff --git a/man/designTree.Rd b/man/designTree.Rd
index 573ad18..cde1ac4 100644
--- a/man/designTree.Rd
+++ b/man/designTree.Rd
@@ -1,47 +1,60 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/distTree.R
 \name{designTree}
 \alias{designTree}
-\alias{designSplits}
 \alias{nnls.tree}
 \alias{nnls.phylo}
 \alias{nnls.splits}
 \alias{nnls.networx}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{Compute a design matrix or non-negative LS }
-\description{
-\code{nnls.tree} estimates the branch length using non-negative least squares given a tree and a distance matrix. 
-\code{designTree} and \code{designSplits} compute design matrices for the 
-estimation of edge length of (phylogenetic) trees using linear models. 
-For larger trees a sparse design matrix can save a lot of memory.
-%\code{designTree} also computes a contrast matrix if the method is "rooted".
-}
+\alias{designSplits}
+\title{Compute a design matrix or non-negative LS}
 \usage{
-designTree(tree, method = "unrooted", sparse=FALSE, ...)
+designTree(tree, method = "unrooted", sparse = FALSE, ...)
+
+nnls.tree(dm, tree, rooted = FALSE, trace = 1)
+
+nnls.phylo(x, dm, rooted = FALSE, trace = 0)
+
+nnls.splits(x, dm, trace = 0)
+
+nnls.networx(x, dm)
+
 designSplits(x, splits = "all", ...)
-nnls.tree(dm, tree, rooted=FALSE, trace=1)
-nnls.phylo(x, dm, rooted=FALSE, trace=0)
-nnls.splits(x, dm, trace = 0) 
-nnls.networx(x, dm) 
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{tree}{an object of class \code{phylo} }
-  \item{method}{design matrix for an "unrooted" or "rooted" ultrametric tree.}
-  \item{sparse}{return a sparse design matrix.}  
-  \item{x}{number of taxa. }
-  \item{splits}{one of "all", "star".}
-  \item{dm}{a distance matrix.} 
-  \item{rooted}{compute a "rooted" or "unrooted" tree.}
-  \item{trace}{defines how much information is printed during optimisation.} 
-  \item{\dots}{further arguments, passed to other methods.}
+\item{tree}{an object of class \code{phylo}}
+
+\item{method}{design matrix for an "unrooted" or "rooted" ultrametric tree.}
+
+\item{sparse}{return a sparse design matrix.}
+
+\item{\dots}{further arguments, passed to other methods.}
+
+\item{dm}{a distance matrix.}
+
+\item{rooted}{compute a "rooted" or "unrooted" tree.}
+
+\item{trace}{defines how much information is printed during optimisation.}
+
+\item{x}{number of taxa.}
+
+\item{splits}{one of "all", "star".}
 }
 \value{
-\code{nnls.tree} return a tree, i.e. an object of class \code{phylo}. 
-\code{designTree} and \code{designSplits} a matrix, possibly sparse. 
+\code{nnls.tree} return a tree, i.e. an object of class
+\code{phylo}.  \code{designTree} and \code{designSplits} a matrix, possibly
+sparse.
+}
+\description{
+\code{nnls.tree} estimates the branch length using non-negative least
+squares given a tree and a distance matrix.  \code{designTree} and
+\code{designSplits} compute design matrices for the estimation of edge
+length of (phylogenetic) trees using linear models.  For larger trees a
+sparse design matrix can save a lot of memory. %\code{designTree} also
+computes a contrast matrix if the method is "rooted".
 }
-\author{ Klaus Schliep \email{klaus.schliep at gmail.com} }
-
-\seealso{ \code{\link[ape]{fastme}}, \code{\link[phangorn]{distanceHadamard}}, \code{\link[phangorn]{splitsNetwork}}, \code{\link[phangorn]{upgma}} }
 \examples{
+
 example(NJ)
 dm <-  as.matrix(dm)
 y <- dm[lower.tri(dm)]
@@ -49,7 +62,14 @@ X <- designTree(tree)
 lm(y~X-1)
 # avoids negative edge weights 
 tree2 = nnls.tree(dm, tree)
+
+}
+\seealso{
+\code{\link[ape]{fastme}},
+\code{\link[phangorn]{distanceHadamard}},
+\code{\link[phangorn]{splitsNetwork}}, \code{\link[phangorn]{upgma}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
+\keyword{cluster}
diff --git a/man/dfactorial.Rd b/man/dfactorial.Rd
index 3948e6e..04e5425 100644
--- a/man/dfactorial.Rd
+++ b/man/dfactorial.Rd
@@ -1,28 +1,35 @@
-\name{dfactorial}
-\alias{dfactorial}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/hadamard.R
+\name{ldfactorial}
 \alias{ldfactorial}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{ Arithmetic Operators }
-\description{
-  double factorial function
-}
+\alias{dfactorial}
+\title{Arithmetic Operators}
 \usage{
-dfactorial(x)
 ldfactorial(x)
+
+dfactorial(x)
 }
 \arguments{
-  \item{x}{ a numeric scalar or vector }
+\item{x}{a numeric scalar or vector}
 }
-
 \value{
-\code{dfactorial(x)} returns the double factorial, that is \eqn{x\!\! = 1 *  3 * 5 *  \ldots * x } 
-and \code{ldfactorial(x)} is the natural logarithm of it. 
+\code{dfactorial(x)} returns the double factorial, that is
+\eqn{x\!\! = 1 * 3 * 5 * \ldots * x } and \code{ldfactorial(x)} is the
+natural logarithm of it.
+}
+\description{
+double factorial function
 }
-
-\author{ Klaus Schliep \email{klaus.schliep at gmail.com}  }
-
-\seealso{ \code{\link[base:Special]{factorial}}, \code{\link[ape]{howmanytrees}} }
 \examples{
+
 dfactorial(1:10)
+
+}
+\seealso{
+\code{\link[base:Special]{factorial}},
+\code{\link[ape]{howmanytrees}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-\keyword{ classif }% at least one, from doc/KEYWORDS
+\keyword{classif}
diff --git a/man/dist.hamming.Rd b/man/dist.hamming.Rd
index 78b9c35..08e01a4 100644
--- a/man/dist.hamming.Rd
+++ b/man/dist.hamming.Rd
@@ -1,55 +1,59 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/distSeq.R
 \name{dist.hamming}
 \alias{dist.hamming}
-\alias{dist.logDet}
 \alias{dist.ml}
-\alias{readDist}
-\alias{writeDist}
-%- Also NEED an '\alias' for EACH other topic documented here.
+\alias{dist.logDet}
 \title{Pairwise Distances from Sequences}
-\description{
-\code{dist.hamming}, \code{dist.ml} and \code{dist.logDet} compute pairwise distances 
-for an object of class \code{phyDat}. 
-\code{dist.ml} uses DNA / AA sequences to compute distances under different substitution models. 
-}
 \usage{
-dist.hamming(x, ratio = TRUE, exclude="none")
+dist.hamming(x, ratio = TRUE, exclude = "none")
+
+dist.ml(x, model = "JC69", exclude = "none", bf = NULL, Q = NULL,
+  k = 1L, shape = 1, ...)
+
 dist.logDet(x)
-dist.ml(x, model="JC69", exclude="none", bf=NULL, Q=NULL, k = 1L, shape = 1, ...)
-readDist(file)
-writeDist(dm, file="")
 }
 \arguments{
-  \item{x}{An object of class \code{phyDat}}
-  \item{ratio}{Compute uncorrected ('p') distance or character difference.}
-  \item{model}{One of "JC69", "F81" or one of 17 amino acid models see details.}
-  \item{exclude}{One of "none", "all", "pairwise" indicating whether to delete the sites with missing data (or ambiguous states). The default is handle missing data as in pml.}
-  \item{bf}{A vector of base frequencies.}
-  \item{Q}{A vector containing the lower triangular part of the rate matrix.} 
-  \item{k}{Number of intervals of the discrete gamma distribution.}
-  \item{shape}{Shape parameter of the gamma distribution.}
-  \item{\dots}{Further arguments passed to or from other methods.}
-  \item{file}{A file name.}
-  \item{dm}{A \code{dist} object.}
+\item{x}{An object of class \code{phyDat}}
+
+\item{ratio}{Compute uncorrected ('p') distance or character difference.}
+
+\item{exclude}{One of "none", "all", "pairwise" indicating whether to delete
+the sites with missing data (or ambiguous states). The default is handle
+missing data as in pml.}
+
+\item{model}{One of "JC69", "F81" or one of 17 amino acid models see
+details.}
+
+\item{bf}{A vector of base frequencies.}
+
+\item{Q}{A vector containing the lower triangular part of the rate matrix.}
+
+\item{k}{Number of intervals of the discrete gamma distribution.}
+
+\item{shape}{Shape parameter of the gamma distribution.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
 }
 \value{
-  an object of class \code{dist}
+an object of class \code{dist}
 }
-\details{
-So far 17 amino acid models are supported ("WAG", "JTT", "LG", "Dayhoff", "cpREV", "mtmam", "mtArt", "MtZoa", "mtREV24", "VT","RtREV", "HIVw", "HIVb", "FLU", "Blossum62", "Dayhoff_DCMut" and "JTT_DCMut") and additional rate matrices and frequencies can be supplied. 
-
-The "F81" model uses empirical base frequencies, the "JC69" equal base frequencies. This is even the case if the data are not nucleotides. 
+\description{
+\code{dist.hamming}, \code{dist.ml} and \code{dist.logDet} compute pairwise
+distances for an object of class \code{phyDat}.  \code{dist.ml} uses DNA /
+AA sequences to compute distances under different substitution models.
 }
-\references{ 
-Lockhart, P. J., Steel, M. A., Hendy, M. D. and Penny, D. (1994)
-Recovering evolutionary trees under a more realistic model of sequence
-evolution. \emph{Molecular Biology and Evolution}, \bold{11}, 605--602.
+\details{
+So far 17 amino acid models are supported ("WAG", "JTT", "LG", "Dayhoff",
+"cpREV", "mtmam", "mtArt", "MtZoa", "mtREV24", "VT","RtREV", "HIVw", "HIVb",
+"FLU", "Blossum62", "Dayhoff_DCMut" and "JTT_DCMut") and additional rate
+matrices and frequencies can be supplied.
 
-Jukes TH and Cantor CR (1969). \emph{Evolution of Protein Molecules}. New York: Academic Press. 21--132.
+The "F81" model uses empirical base frequencies, the "JC69" equal base
+frequencies. This is even the case if the data are not nucleotides.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-
-\seealso{For more distance methods for nucleotide data see \code{\link[ape]{dist.dna}} and \code{\link{dist.p}} for pairwise polymorphism p-distances}
 \examples{
+
 data(Laurasiatherian)
 dm1 <- dist.hamming(Laurasiatherian)
 tree1 <- NJ(dm1)
@@ -65,6 +69,22 @@ dm4 <- dist.ml(Laurasiatherian, model="F81", k=4, shape=.4)
 tree4 <- NJ(dm4)
 treedist(tree1,tree4)
 treedist(tree3,tree4)
+
 }
+\references{
+Lockhart, P. J., Steel, M. A., Hendy, M. D. and Penny, D. (1994)
+Recovering evolutionary trees under a more realistic model of sequence
+evolution. \emph{Molecular Biology and Evolution}, \bold{11}, 605--602.
 
-\keyword{ cluster }
+Jukes TH and Cantor CR (1969). \emph{Evolution of Protein Molecules}. New
+York: Academic Press. 21--132.
+}
+\seealso{
+For more distance methods for nucleotide data see
+\code{\link[ape]{dist.dna}} and \code{\link{dist.p}} for pairwise
+polymorphism p-distances. \code{\link{writeDist}} for export and import distances.
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/dist.p.Rd b/man/dist.p.Rd
index 2b2938c..75f9b85 100644
--- a/man/dist.p.Rd
+++ b/man/dist.p.Rd
@@ -1,53 +1,43 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/dist.p.R
 \name{dist.p}
 \alias{dist.p}
-%- Also NEED an '\alias' for EACH other topic documented here.
 \title{Pairwise Polymorphism P-Distances from DNA Sequences}
-\description{
-This function computes a matrix of pairwise uncorrected polymorphism 
-p-distances. Polymorphism p-distances include intra-individual site 
-polymorphisms (2ISPs; e.g. "R") when calculating genetic distances.
-}
 \usage{
-dist.p(x, cost="polymorphism", ignore.indels=TRUE)
+dist.p(x, cost = "polymorphism", ignore.indels = TRUE)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{x}{a matrix containing DNA sequences; this must be of class
- "phyDat" (use as.phyDat to convert from DNAbin objects).}
- \item{cost}{A cost matrix or "polymorphism" for a predefined one.} 
- \item{ignore.indels}{a logical indicating whether gaps are treated
-as fifth state or not. Warning, each gap site is treated as a 
-characters, so an an indel that spans a number of base positions 
-would be treated as multiple character states.}
+\item{x}{a matrix containing DNA sequences; this must be of class "phyDat"
+(use as.phyDat to convert from DNAbin objects).}
+
+\item{cost}{A cost matrix or "polymorphism" for a predefined one.}
+
+\item{ignore.indels}{a logical indicating whether gaps are treated as fifth
+state or not. Warning, each gap site is treated as a characters, so an an
+indel that spans a number of base positions would be treated as multiple
+character states.}
+}
+\value{
+an object of class \code{dist}.
+}
+\description{
+This function computes a matrix of pairwise uncorrected polymorphism
+p-distances. Polymorphism p-distances include intra-individual site
+polymorphisms (2ISPs; e.g. "R") when calculating genetic distances.
 }
 \details{
-The polymorphism p-distances (Potts et al. 2014) have been 
-developed to analyse intra-individual variant polymorphism. For 
-example, the widely used ribosomal internal transcribed spacer (ITS) 
-region  (e.g. Alvarez and Wendel, 2003) consists of 100's to 1000's 
-of units within array across potentially multiple nucleolus organising 
-regions (Bailey et al., 2003; Goeker and Grimm, 2008). This can give 
-rise to intra-individual site polymorphisms (2ISPs) that can be 
-detected from direct-PCR sequencing or cloning . Clone consensus 
-sequences (see Goeker and Grimm, 2008) can be analysed with this 
+The polymorphism p-distances (Potts et al. 2014) have been developed to
+analyse intra-individual variant polymorphism. For example, the widely used
+ribosomal internal transcribed spacer (ITS) region (e.g. Alvarez and Wendel,
+2003) consists of 100's to 1000's of units within array across potentially
+multiple nucleolus organising regions (Bailey et al., 2003; Goeker and
+Grimm, 2008). This can give rise to intra-individual site polymorphisms
+(2ISPs) that can be detected from direct-PCR sequencing or cloning . Clone
+consensus sequences (see Goeker and Grimm, 2008) can be analysed with this
 function.
 }
-\value{
- an object of class \code{dist}.
-}
-
-\references{Alvarez, I., and J. F. Wendel. (2003) Ribosomal ITS sequences and plant phylogenetic inference. \emph{ Molecular Phylogenetics and Evolution}, \bold{29}, 417--434. 
-
-Bailey, C. D., T. G. Carr, S. A. Harris, and C. E. Hughes. (2003) Characterization of angiosperm nrDNA polymorphism, paralogy, and pseudogenes. \emph{Molecular Phylogenetics and Evolution} \bold{29}, 435--455. 
-
-Goeker, M., and G. Grimm. (2008) General functions to transform associate data to host data, and their use in phylogenetic inference from sequences with intra-individual variability. \emph{BMC Evolutionary Biology}, \bold{8}:86. 
-
-Potts, A.J., T.A. Hedderson, and G.W. Grimm. (2014) Constructing phylogenies in the presence of intra-individual site polymorphisms (2ISPs) with a focus on the nuclear ribosomal cistron. \emph{Systematic Biology}, \bold{63}, 1--16 
-}    
-\author{Klaus Schliep and Alastair Potts}
-
-\seealso{  \code{\link[ape]{dist.dna}}, \code{\link[phangorn]{dist.hamming}}}
 \examples{
+
 data(Laurasiatherian)
 laura = as.DNAbin(Laurasiatherian)
 
@@ -62,10 +52,37 @@ cat("3 5",
     "No305     ATRA-",
     "No304     ATAYX",
     "No306     ATAGA",
-    file = "exdna.txt", sep = "\n")
+    file = "exdna.txt", sep = "\\n")
 (ex.dna <- read.dna("exdna.txt", format = "sequential", as.character=TRUE))
 dat= phyDat(ex.dna, "USER", levels=unique(as.vector(ex.dna)))
 dist.p(dat)
 
+
+}
+\references{
+Alvarez, I., and J. F. Wendel. (2003) Ribosomal ITS sequences
+and plant phylogenetic inference. \emph{ Molecular Phylogenetics and
+Evolution}, \bold{29}, 417--434.
+
+Bailey, C. D., T. G. Carr, S. A. Harris, and C. E. Hughes. (2003)
+Characterization of angiosperm nrDNA polymorphism, paralogy, and
+pseudogenes. \emph{Molecular Phylogenetics and Evolution} \bold{29},
+435--455.
+
+Goeker, M., and G. Grimm. (2008) General functions to transform associate
+data to host data, and their use in phylogenetic inference from sequences
+with intra-individual variability. \emph{BMC Evolutionary Biology},
+\bold{8}:86.
+
+Potts, A.J., T.A. Hedderson, and G.W. Grimm. (2014) Constructing phylogenies
+in the presence of intra-individual site polymorphisms (2ISPs) with a focus
+on the nuclear ribosomal cistron. \emph{Systematic Biology}, \bold{63},
+1--16
+}
+\seealso{
+\code{\link[ape]{dist.dna}}, \code{\link[phangorn]{dist.hamming}}
+}
+\author{
+Klaus Schliep and Alastair Potts
 }
-\keyword{ cluster }% at least one, from doc/KEYWORDS
+\keyword{cluster}
diff --git a/man/distanceHadamard.Rd b/man/distanceHadamard.Rd
index e163a0c..ba2aab7 100644
--- a/man/distanceHadamard.Rd
+++ b/man/distanceHadamard.Rd
@@ -1,39 +1,43 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/hadamard.R
 \name{distanceHadamard}
-
 \alias{distanceHadamard}
 \title{Distance Hadamard}
-\description{
-Distance Hadamard produces spectra of splits from a distance matrix.
-}
 \usage{
-distanceHadamard(dm, eps=0.001)
+distanceHadamard(dm, eps = 0.001)
 }
 \arguments{
-  \item{dm}{A distance matrix.}
-  \item{eps}{Threshold value for splits.}
-}
+\item{dm}{A distance matrix.}
 
-\value{
-\code{distanceHadamard} returns a matrix. The first column 
-contains the distance spectra, the second one the edge-spectra.
-If eps is positive an object of with all splits greater eps is returned.
+\item{eps}{Threshold value for splits.}
 }
-\references{Hendy, M. D. and Penny, D. (1993). Spectral Analysis of Phylogenetic
-Data. \emph{Journal of Classification}, \bold{10}, 5-24.
+\value{
+\code{distanceHadamard} returns a matrix. The first column contains
+the distance spectra, the second one the edge-spectra. If eps is positive an
+object of with all splits greater eps is returned.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}, Tim White}
-\seealso{
-\code{\link{hadamard}}, \code{\link{lento}}, \code{\link{plot.networx}}, \code{\link{neighborNet}}
+\description{
+Distance Hadamard produces spectra of splits from a distance matrix.
 }
-
 \examples{
+
 data(yeast)
 dm = dist.hamming(yeast)
 dm = as.matrix(dm)
 fit = distanceHadamard(dm)
 lento(fit)
 plot(as.networx(fit), "2D")
-}
-\keyword{ cluster }% at least one, from doc/KEYWORDS
-
 
+}
+\references{
+Hendy, M. D. and Penny, D. (1993). Spectral Analysis of
+Phylogenetic Data. \emph{Journal of Classification}, \bold{10}, 5-24.
+}
+\seealso{
+\code{\link{hadamard}}, \code{\link{lento}},
+\code{\link{plot.networx}}, \code{\link{neighborNet}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}, Tim White
+}
+\keyword{cluster}
diff --git a/man/getClans.Rd b/man/getClans.Rd
index 09cc3c1..58b528b 100644
--- a/man/getClans.Rd
+++ b/man/getClans.Rd
@@ -1,107 +1,117 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/clanistic.R
 \name{getClans}
 \alias{getClans}
-\alias{getClips}
 \alias{getSlices}
+\alias{getClips}
 \alias{getDiversity}
 \alias{diversity}
-\title{
-Clans, slices and clips
-}
-\description{
-Functions for clanistics to compute clans, slices, clips for unrooted trees and functions to quantify the fragmentation of trees. 
-}
+\title{Clans, slices and clips}
 \usage{
 getClans(tree)
-getClips(tree, all=TRUE)
+
 getSlices(tree)
-getDiversity(tree, x, norm=TRUE, var.names = NULL, labels="new")
+
+getClips(tree, all = TRUE)
+
+getDiversity(tree, x, norm = TRUE, var.names = NULL, labels = "new")
+
 diversity(tree, X)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
 \item{tree}{An object of class phylo or multiPhylo (getDiversity).}
-\item{all}{A logical, return all or just the largest clip. }
-\item{x}{An object of class phyDat. }
-\item{norm}{A logical, return Equitability Index (default) or Shannon Diversity. }
-\item{var.names}{A vector of variable names. }
-\item{labels}{see details. }
-\item{X}{a data.frame}
-}
-\details{
-Every split in an unrooted tree defines two complementary clans. Thus
-for an unrooted binary tree with \eqn{n} leaves there are \eqn{2n - 3} edges, 
-and therefore \eqn{4n - 6} clans (including \eqn{n} trivial clans containing only
-one leave).
-
-Slices are defined by a pair of splits or tripartitions, which are not 
-clans. The number of distinguishable slices for a binary tree with 
-\eqn{n} tips is \eqn{2n^2 - 10n + 12}. 
-
-%A clip is a different type of partition as it is defined by evolutionary or cophenetic distance and not by the topology. Namely clips are groups of leaves for which the maximum pairwise distance is smaller than threshold. 
-%For a better separation we additionally demand that the maximum pairwise distance within a clip is lower than the distance between any member of the clip and any other tip.
-
-A clip is a different type of partition, defining groups of leaves that are related in terms of evolutionary distances and not only topology. 
-Namely, clips are groups of leaves for which all pairwise path-length distances are smaller than a given threshold value (Lapointe et al. 2010).
-There exists different numbers of clips for different thresholds, the largest (and trivial) one being the whole tree. 
-There is always a clip containing only the two leaves with the smallest pairwise distance. 
-
-Clans, slices and clips can be used to characterize how well a vector of 
-categorial characters (natives/intruders) fit on a tree. We will follow the definitions of Lapointe et al.(2010). 
-A complete clan is a clan that contains all leaves of a given state/color, but can
-also contain leaves of another state/color. A  clan is homogeneous if it  
-only contains leaves of one state/color. 
-
-\code{getDiversity} computes either the \cr
-Shannon Diversity: \eqn{H = -\sum_{i=1}^{k}(N_i/N)  log(N_i/N), N=\sum_{i=1}^{k} N_i}{H = -sum(N_i/N) * log(N_i/N), N=sum(N_i)}  \cr
-or the \cr 
-Equitability Index: \eqn{E = H / log(N)} \cr
-where \eqn{N_i} are the sizes of the \eqn{k} largest homogeneous clans of intruders. 
-If the categories of the data can be separated by an edge of the tree then the E-value will be zero,
-and maximum equitability (E=1) is reached if all intruders are in separate clans.
-getDiversity computes these Intruder indices for the whole tree, complete clans and complete slices.
-Additionally the parsimony scores (p-scores) are reported. The p-score indicates if the leaves contain only one color (p-score=0), if  
-the the leaves can be separated by a single split (perfect clan, p-score=1) or by a pair of splits (perfect slice, p-score=2). 
-
-So far only 2 states are supported (native, intruder), however it is also possible to recode several states 
-into the native or intruder state using contrasts, for details see section 2 in vignette("phangorn-specials").  
-Furthermore unknown character states are coded as ambiguous character, which can act either as native or intruder 
-minimizing the number of clans or changes (in parsimony analysis) needed to describe a tree for given data. 
-
-Set attribute labels to "old" for analysis as in Schliep et al. (2010) or to "new" for names which are more intuitive. 
-
-\code{diversity} returns a data.frame with the parsimony score for each tree and each levels of the variables in \code{X}. \code{X} has to be a \code{data.frame} where each column is a factor and the rownames of \code{X} correspond to the tips of the trees. 
-
- 
-%TODO See also vignette("Clanistic").
-}
-\value{
-getClans, getSlices and getClips return a matrix of partitions, a matrix of ones and zeros where rows correspond to 
-a clan, slice or clip and columns to tips. A one indicates that a tip belongs to a certain partition. \cr  
-getDiversity returns a list with tree object, the first is a data.frame of the equitability index or Shannon divergence and parsimony scores (p-score)
-for all trees and variables. The data.frame has two attributes, the first is a splits object to identify the taxa of each tree and the second
-is a splits object containing all partitions that perfectly fit. 
-}
 
-\references{ 
-Lapointe, F.-J., Lopez, P., Boucher, Y., Koenig, J., Bapteste, E. (2010) Clanistics: a multi-level perspective for harvesting unrooted gene trees. \emph{Trends in Microbiology} 18: 341-347
+\item{all}{A logical, return all or just the largest clip.}
 
-Wilkinson, M., McInerney, J.O., Hirt, R.P., Foster, P.G., Embley, T.M. (2007) Of clades and clans: terms for phylogenetic relationships in unrooted trees. \emph{Trends in Ecology and Evolution} 22: 114-115 
+\item{x}{An object of class phyDat.}
 
-Schliep, K., Lopez, P., Lapointe F.-J., Bapteste E. (2011) Harvesting Evolutionary Signals in a Forest of Prokaryotic Gene Trees, \emph{Molecular Biology and Evolution} 28(4): 1393-1405 
+\item{norm}{A logical, return Equitability Index (default) or Shannon
+Diversity.}
 
-}
-\author{
-Klaus Schliep \email{klaus.schliep at snv.jussieu.fr} 
+\item{var.names}{A vector of variable names.}
 
-Francois-Joseph Lapointe \email{francois-joseph.lapointe at umontreal.ca}
-}
+\item{labels}{see details.}
 
-\seealso{
-\code{\link{parsimony}}, Consistency index \code{\link{CI}}, Retention index \code{\link{RI}}, \code{\link{phyDat}}
+\item{X}{a data.frame}
 }
+\value{
+getClans, getSlices and getClips return a matrix of partitions, a
+matrix of ones and zeros where rows correspond to a clan, slice or clip and
+columns to tips. A one indicates that a tip belongs to a certain partition.
+\cr getDiversity returns a list with tree object, the first is a data.frame
+of the equitability index or Shannon divergence and parsimony scores
+(p-score) for all trees and variables. The data.frame has two attributes,
+the first is a splits object to identify the taxa of each tree and the
+second is a splits object containing all partitions that perfectly fit.
+}
+\description{
+Functions for clanistics to compute clans, slices, clips for unrooted trees
+and functions to quantify the fragmentation of trees.
+}
+\details{
+Every split in an unrooted tree defines two complementary clans. Thus for an
+unrooted binary tree with \eqn{n} leaves there are \eqn{2n - 3} edges, and
+therefore \eqn{4n - 6} clans (including \eqn{n} trivial clans containing
+only one leave).
+
+Slices are defined by a pair of splits or tripartitions, which are not
+clans. The number of distinguishable slices for a binary tree with \eqn{n}
+tips is \eqn{2n^2 - 10n + 12}.
+
+%A clip is a different type of partition as it is defined by evolutionary or
+cophenetic distance and not by the topology. Namely clips are groups of
+leaves for which the maximum pairwise distance is smaller than threshold.
+%For a better separation we additionally demand that the maximum pairwise
+distance within a clip is lower than the distance between any member of the
+clip and any other tip.
+
+A clip is a different type of partition, defining groups of leaves that are
+related in terms of evolutionary distances and not only topology.  Namely,
+clips are groups of leaves for which all pairwise path-length distances are
+smaller than a given threshold value (Lapointe et al. 2010). There exists
+different numbers of clips for different thresholds, the largest (and
+trivial) one being the whole tree.  There is always a clip containing only
+the two leaves with the smallest pairwise distance.
+
+Clans, slices and clips can be used to characterize how well a vector of
+categorial characters (natives/intruders) fit on a tree. We will follow the
+definitions of Lapointe et al.(2010).  A complete clan is a clan that
+contains all leaves of a given state/color, but can also contain leaves of
+another state/color. A clan is homogeneous if it only contains leaves of one
+state/color.
+
+\code{getDiversity} computes either the \cr Shannon Diversity: \eqn{H =
+-\sum_{i=1}^{k}(N_i/N) log(N_i/N), N=\sum_{i=1}^{k} N_i}{H = -sum(N_i/N) *
+log(N_i/N), N=sum(N_i)} \cr or the \cr Equitability Index: \eqn{E = H /
+log(N)} \cr where \eqn{N_i} are the sizes of the \eqn{k} largest homogeneous
+clans of intruders.  If the categories of the data can be separated by an
+edge of the tree then the E-value will be zero, and maximum equitability
+(E=1) is reached if all intruders are in separate clans. getDiversity
+computes these Intruder indices for the whole tree, complete clans and
+complete slices. Additionally the parsimony scores (p-scores) are reported.
+The p-score indicates if the leaves contain only one color (p-score=0), if
+the the leaves can be separated by a single split (perfect clan, p-score=1)
+or by a pair of splits (perfect slice, p-score=2).
+
+So far only 2 states are supported (native, intruder), however it is also
+possible to recode several states into the native or intruder state using
+contrasts, for details see section 2 in vignette("phangorn-specials").
+Furthermore unknown character states are coded as ambiguous character, which
+can act either as native or intruder minimizing the number of clans or
+changes (in parsimony analysis) needed to describe a tree for given data.
+
+Set attribute labels to "old" for analysis as in Schliep et al. (2010) or to
+"new" for names which are more intuitive.
+
+\code{diversity} returns a data.frame with the parsimony score for each tree
+and each levels of the variables in \code{X}. \code{X} has to be a
+\code{data.frame} where each column is a factor and the rownames of \code{X}
+correspond to the tips of the trees.
 
-
+%TODO See also vignette("Clanistic").
+}
 \examples{
+
 set.seed(111)
 tree = rtree(10)
 getClans(tree)
@@ -117,6 +127,28 @@ plot(trees[[1]], "u", tip.color = X[trees[[1]]$tip,1])  # intruders are blue
 
 (divTab <- getDiversity(trees, x, var.names=colnames(X)))
 summary(divTab)
+
 }
-\keyword{ cluster }
+\references{
+Lapointe, F.-J., Lopez, P., Boucher, Y., Koenig, J., Bapteste,
+E. (2010) Clanistics: a multi-level perspective for harvesting unrooted gene
+trees. \emph{Trends in Microbiology} 18: 341-347
+
+Wilkinson, M., McInerney, J.O., Hirt, R.P., Foster, P.G., Embley, T.M.
+(2007) Of clades and clans: terms for phylogenetic relationships in unrooted
+trees. \emph{Trends in Ecology and Evolution} 22: 114-115
+
+Schliep, K., Lopez, P., Lapointe F.-J., Bapteste E. (2011) Harvesting
+Evolutionary Signals in a Forest of Prokaryotic Gene Trees, \emph{Molecular
+Biology and Evolution} 28(4): 1393-1405
+}
+\seealso{
+\code{\link{parsimony}}, Consistency index \code{\link{CI}},
+Retention index \code{\link{RI}}, \code{\link{phyDat}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at snv.jussieu.fr}
 
+Francois-Joseph Lapointe \email{francois-joseph.lapointe at umontreal.ca}
+}
+\keyword{cluster}
diff --git a/man/hadamard.Rd b/man/hadamard.Rd
index 2805370..ea8a748 100644
--- a/man/hadamard.Rd
+++ b/man/hadamard.Rd
@@ -1,58 +1,51 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/hadamard.R
 \name{hadamard}
 \alias{hadamard}
 \alias{fhm}
 \alias{h4st}
 \alias{h2st}
 \title{Hadamard Matrices and Fast Hadamard Multiplication}
-\description{
-A collection of functions to perform Hadamard conjugation. 
-%Hv of a Hadamard matrix H with a vector v using fast Hadamard multiplication.
-}
 \usage{
 hadamard(x)
+
 fhm(v)
-h2st(obj, eps=0.001)
-h4st(obj, levels = c("a","c","g","t"))
-}
-\arguments{
-  \item{x}{ a vector of length \eqn{2^n}, where n is an integer. }
-  \item{v}{ a vector of length \eqn{2^n}, where n is an integer. }
-  \item{obj}{ a data.frame or character matrix, typical a sequence alignment.}
-  \item{eps}{Threshold value for splits.}
-  \item{levels}{ levels of the sequences.}
-}
 
-\details{
-\code{h2st} and \code{h4st} perform Hadamard conjugation 
-for 2-state (binary, RY-coded) or 4-state (DNA/RNA) data.
-\code{write.nexus.splits} writes splits returned from  \code{h2st} or  
-\code{\link[phangorn]{distanceHadamard}} to a nexus file, which can be processed by 
-Spectronet or Splitstree.
-}
+h4st(obj, levels = c("a", "c", "g", "t"))
 
-\value{
-\code{hadamard} returns a Hadamard matrix. \code{fhm} returns the 
-fast Hadamard multiplication. 
+h2st(obj, eps = 0.001)
 }
-\references{Hendy, M.D. (1989). The relationship between simple evolutionary tree
-models and observable sequence data. \emph{Systematic Zoology}, \bold{38} 310--321.
+\arguments{
+\item{x}{a vector of length \eqn{2^n}, where n is an integer.}
 
-Hendy, M. D. and Penny, D. (1993). Spectral Analysis of Phylogenetic
-Data. \emph{Journal of Classification}, \bold{10}, 5--24.
+\item{v}{a vector of length \eqn{2^n}, where n is an integer.}
 
-Hendy, M. D. (2005). Hadamard conjugation: an analytical tool for phylogenetics.
-In O. Gascuel, editor, \emph{Mathematics of evolution and phylogeny}, Oxford University Press, Oxford
+\item{obj}{a data.frame or character matrix, typical a sequence alignment.}
 
-Waddell P. J. (1995). Statistical methods of phylogenetic analysis: Including hadamard conjugation, 
-LogDet transforms, and maximum likelihood. \emph{PhD thesis}.
-}
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\seealso{\code{\link{distanceHadamard}}, \code{\link{lento}}, \code{\link{plot.networx}}}
+\item{levels}{levels of the sequences.}
 
+\item{eps}{Threshold value for splits.}
+}
+\value{
+\code{hadamard} returns a Hadamard matrix. \code{fhm} returns the
+fast Hadamard multiplication.
+}
+\description{
+A collection of functions to perform Hadamard conjugation.  %Hv of a
+Hadamard matrix H with a vector v using fast Hadamard multiplication.
+}
+\details{
+\code{h2st} and \code{h4st} perform Hadamard conjugation for 2-state
+(binary, RY-coded) or 4-state (DNA/RNA) data. \code{write.nexus.splits}
+writes splits returned from \code{h2st} or
+\code{\link[phangorn]{distanceHadamard}} to a nexus file, which can be
+processed by Spectronet or Splitstree.
+}
 \examples{
+
 H <- hadamard(3)
 v <- 1:8
-H%*%v
+H \%*\% v
 fhm(v)
 
 data(yeast)
@@ -74,6 +67,29 @@ lento(fit4[[1]], main="Transversion")
 lento(fit4[[2]], main="Transition 1")
 lento(fit4[[3]], main="Transition 2")
 }
+
 }
-\keyword{ cluster }% at least one, from doc/KEYWORDS
+\references{
+Hendy, M.D. (1989). The relationship between simple evolutionary
+tree models and observable sequence data. \emph{Systematic Zoology},
+\bold{38} 310--321.
+
+Hendy, M. D. and Penny, D. (1993). Spectral Analysis of Phylogenetic Data.
+\emph{Journal of Classification}, \bold{10}, 5--24.
+
+Hendy, M. D. (2005). Hadamard conjugation: an analytical tool for
+phylogenetics. In O. Gascuel, editor, \emph{Mathematics of evolution and
+phylogeny}, Oxford University Press, Oxford
 
+Waddell P. J. (1995). Statistical methods of phylogenetic analysis:
+Including hadamard conjugation, LogDet transforms, and maximum likelihood.
+\emph{PhD thesis}.
+}
+\seealso{
+\code{\link{distanceHadamard}}, \code{\link{lento}},
+\code{\link{plot.networx}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/lento.Rd b/man/lento.Rd
index 49de6ea..73e9fae 100644
--- a/man/lento.Rd
+++ b/man/lento.Rd
@@ -1,48 +1,61 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/lento.R
 \name{lento}
 \alias{lento}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Lento plot
-}
-\description{
-The lento plot represents support and conflict of splits/bipartitions. 
-}
+\title{Lento plot}
 \usage{
-lento(obj, xlim = NULL, ylim = NULL, main = "Lento plot", sub = NULL, xlab = NULL, 
-    ylab = NULL, bipart=TRUE, trivial=FALSE, col = rgb(0, 0, 0, 0.5),...)
+lento(obj, xlim = NULL, ylim = NULL, main = "Lento plot", sub = NULL,
+  xlab = NULL, ylab = NULL, bipart = TRUE, trivial = FALSE,
+  col = rgb(0, 0, 0, 0.5), ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{obj}{an object of class phylo, multiPhylo or splits}
-  \item{xlim}{graphical parameter}
-  \item{ylim}{graphical parameter}
-  \item{main}{graphical parameter}
-  \item{sub}{graphical parameter}
-  \item{xlab}{graphical parameter}
-  \item{ylab}{graphical parameter}
-  \item{bipart}{plot bipartition information.}
-  \item{trivial}{logical, whether to present trivial splits (default is FALSE).}
-  \item{col}{color for the splits / bipartition.}
-  \item{\dots}{Further arguments passed to or from other methods.}
+\item{obj}{an object of class phylo, multiPhylo or splits}
+
+\item{xlim}{graphical parameter}
+
+\item{ylim}{graphical parameter}
+
+\item{main}{graphical parameter}
+
+\item{sub}{graphical parameter}
+
+\item{xlab}{graphical parameter}
+
+\item{ylab}{graphical parameter}
+
+\item{bipart}{plot bipartition information.}
+
+\item{trivial}{logical, whether to present trivial splits (default is
+FALSE).}
+
+\item{col}{color for the splits / bipartition.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
 }
 \value{
 lento returns a plot.
 }
-\references{
-Lento, G.M., Hickson, R.E., Chambers G.K., and Penny, D. (1995) Use of spectral analysis to test hypotheses on the origin of pinninpeds. \emph{Molecular Biology and Evolution}, \bold{12}, 28-52.  
-}
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-
-\seealso{
-\code{\link{as.splits}, \link{hadamard}}
+\description{
+The lento plot represents support and conflict of splits/bipartitions.
 }
 \examples{
+
 data(yeast)
 yeast.ry = acgt2ry(yeast)
 splits.h = h2st(yeast.ry)
 lento(splits.h, trivial=TRUE) 
+
+}
+\references{
+Lento, G.M., Hickson, R.E., Chambers G.K., and Penny, D. (1995)
+Use of spectral analysis to test hypotheses on the origin of pinninpeds.
+\emph{Molecular Biology and Evolution}, \bold{12}, 28-52.
+}
+\seealso{
+\code{\link{as.splits}, \link{hadamard}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
-\keyword{ plot }% __ONLY ONE__ keyword per line
+\keyword{cluster}
+\keyword{plot}
diff --git a/man/maxCladeCred.Rd b/man/maxCladeCred.Rd
index 4aa8ddc..35e2cd6 100644
--- a/man/maxCladeCred.Rd
+++ b/man/maxCladeCred.Rd
@@ -1,51 +1,40 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/bootstrap.R
 \name{maxCladeCred}
 \alias{maxCladeCred}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Maximum clade credibility tree
-}
-\description{
-\code{maxCladeCred} computes the maximum clade credibility tree from a sample of trees. 
-}
+\title{Maximum clade credibility tree}
 \usage{
 maxCladeCred(x, tree = TRUE, part = NULL, rooted = TRUE)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{x}{
-  \code{x} is an object of class \code{multiPhylo} or \code{phylo}
-}
-  \item{tree}{
-logical indicating whether return the tree with the clade credibility (default) or 
-the clade credibility score for all trees.
-}
-  \item{rooted}{
-logical, if FALSE the tree with highest maximum bipartition credibility is returned.
-}
-  \item{part}{a list of partitions as returned by \code{prop.part}}
-}
-\details{
-So far just the best tree is returned. No annotations or transformations of edge length are performed. 
+\item{x}{\code{x} is an object of class \code{multiPhylo} or \code{phylo}}
+
+\item{tree}{logical indicating whether return the tree with the clade
+credibility (default) or the clade credibility score for all trees.}
 
-If a list of partition is provided then the clade credibility is computed for the trees in x.
+\item{part}{a list of partitions as returned by \code{prop.part}}
+
+\item{rooted}{logical, if FALSE the tree with highest maximum bipartition
+credibility is returned.}
 }
 \value{
-a tree (an object of class \code{phylo}) with the highest clade credibility or a numeric vector of clade credibilities for each tree.
+a tree (an object of class \code{phylo}) with the highest clade
+credibility or a numeric vector of clade credibilities for each tree.
 }
-%%\references{
-%% ~put references to the literature/web site here ~
-%%}
-\author{
-Klaus Schliep \email{klaus.schliep at gmail.com} 
+\description{
+\code{maxCladeCred} computes the maximum clade credibility tree from a
+sample of trees.
 }
+\details{
+So far just the best tree is returned. No annotations or transformations of
+edge length are performed.
 
-%% ~Make other sections like Warning with \section{Warning }{....} ~
-
-\seealso{
-\code{\link{consensus}}, \code{\link{consensusNet}}, \code{\link{prop.part}}
+If a list of partition is provided then the clade credibility is computed
+for the trees in x.
 }
 \examples{
 
+
 data(Laurasiatherian)
 set.seed(42)
 bs <- bootstrap.phyDat(Laurasiatherian, FUN = function(x)upgma(dist.hamming(x)), 
@@ -65,8 +54,13 @@ pp <- prop.part(bs)
 tree <- rNNI(bs[[1]], 20)
 maxCladeCred(c(tree, bs[[1]]), tree=FALSE, part = pp)
 # first value likely be -Inf
-}
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
 
+}
+\seealso{
+\code{\link{consensus}}, \code{\link{consensusNet}},
+\code{\link{prop.part}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/midpoint.Rd b/man/midpoint.Rd
index 059e8b9..a09c860 100644
--- a/man/midpoint.Rd
+++ b/man/midpoint.Rd
@@ -1,38 +1,50 @@
-\name{midpoint}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/treeManipulation.R
+\name{getRoot}
+\alias{getRoot}
 \alias{midpoint}
+\alias{midpoint.phylo}
+\alias{midpoint.multiPhylo}
 \alias{pruneTree}
-\alias{getRoot}
-%- Also NEED an '\alias' for EACH other topic documented here.
 \title{Tree manipulation}
-\description{
-\code{midpoint} performs midpoint rooting of a tree. 
-\code{pruneTree} produces a consensus tree.
-}
 \usage{
-midpoint(tree, node.labels = "support")
-pruneTree(tree, ..., FUN = ">=")
 getRoot(tree)
+
+midpoint(tree, node.labels = "support", ...)
+
+\method{midpoint}{phylo}(tree, node.labels = "support", ...)
+
+\method{midpoint}{multiPhylo}(tree, node.labels = "support", ...)
+
+pruneTree(tree, ..., FUN = ">=")
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{tree}{an object of class \code{phylo} }
-  \item{FUN}{a function evaluated on the nodelabels, result must be logical.}
-  \item{node.labels}{are nodel labels 'support' values, 'label' or  should be 'deleted'}
-  \item{\dots}{further arguments, passed to other methods.  }
-}
-\details{
-\code{pruneTree} prunes back a tree and produces a consensus tree, for trees already containing nodelabels. 
-It assumes that nodelabels are numerical or character that allows conversion to numerical, it uses as.numeric(as.character(tree$node.labels)) 
-to convert them. 
-\code{midpoint} so far does not transform node.labels properly.   
+\item{tree}{an object of class \code{phylo}}
+
+\item{node.labels}{are nodel labels 'support' values, 'label' or should be
+'deleted'}
+
+\item{\dots}{further arguments, passed to other methods.}
+
+\item{FUN}{a function evaluated on the nodelabels, result must be logical.}
 }
 \value{
-\code{pruneTree} and \code{midpoint} a tree. \code{getRoot} returns the root node.
+\code{pruneTree} and \code{midpoint} a tree. \code{getRoot} returns
+the root node.
+}
+\description{
+\code{midpoint} performs midpoint rooting of a tree.  \code{pruneTree}
+produces a consensus tree.
+}
+\details{
+\code{pruneTree} prunes back a tree and produces a consensus tree, for trees
+already containing nodelabels.  It assumes that nodelabels are numerical or
+character that allows conversion to numerical, it uses
+as.numeric(as.character(tree$node.labels)) to convert them.  \code{midpoint}
+so far does not transform node.labels properly.
 }
-\author{ Klaus Schliep \email{klaus.schliep at gmail.com} }
-
-\seealso{ \code{\link[ape]{consensus}}, \code{\link[ape]{root}}, \code{\link[ape]{di2multi}} }
 \examples{
+
 tree = unroot(rtree(10))
 tree$node.label = c("", round(runif(tree$Nnode-1), 3))
 
@@ -43,9 +55,13 @@ par(mfrow = c(3,1))
 plot(tree, show.node.label=TRUE)
 plot(tree2, show.node.label=TRUE)
 plot(tree3, show.node.label=TRUE)
-}
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
-
 
+}
+\seealso{
+\code{\link[ape]{consensus}}, \code{\link[ape]{root}},
+\code{\link[ape]{di2multi}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/modelTest.Rd b/man/modelTest.Rd
index 62abb2f..d5bb0f5 100644
--- a/man/modelTest.Rd
+++ b/man/modelTest.Rd
@@ -1,58 +1,58 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/modelTest.R
 \name{modelTest}
 \alias{modelTest}
 \alias{AICc}
-\title{
-ModelTest
-}
-\description{
-Comparison of different nucleotide or amino acid substitution models 
-}
+\title{ModelTest}
 \usage{
-modelTest(object, tree=NULL, model = c("JC", "F81", "K80", "HKY", "SYM", "GTR"), 
-    G = TRUE, I = TRUE, FREQ = FALSE, k = 4, control = pml.control(epsilon = 1e-08, 
-    maxit = 10, trace = 1), multicore = FALSE, mc.cores = NULL)
+modelTest(object, tree = NULL, model = c("JC", "F81", "K80", "HKY", "SYM",
+  "GTR"), G = TRUE, I = TRUE, FREQ = FALSE, k = 4,
+  control = pml.control(epsilon = 1e-08, maxit = 10, trace = 1),
+  multicore = FALSE, mc.cores = NULL)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{object}{an object of class phyDat or pml}
-  \item{tree}{a phylogenetic tree.}
-  \item{model}{a vector containing the substitution models to compare with each other
-  or "all" to test all available models}
-  \item{G}{logical, TRUE (default) if (discrete) Gamma model should be tested}
-  \item{I}{logical, TRUE (default) if invariant sites should be tested}
-  \item{FREQ}{logical, FALSE (default) if TRUE amino acid frequencies will be estimated.}
-  \item{k}{number of rate classes}
-  \item{control}{A list of parameters for controlling the fitting process.}
-  \item{multicore}{logical, whether models should estimated in parallel.}
-  \item{mc.cores}{The number of cores to use, i.e. at most how many child processes will be run simultaneously. Must be at least one, and parallelization requires at least two cores.}
-}
-\details{
-\code{modelTest} estimates all the specified models for a given tree and data. 
-When the mclapply is available, the computations are done in parallel. \code{modelTest} 
-runs each model in one thread. 
-This is may not work within a GUI interface and will not work under Windows.  
-}
-\value{
-A data.frame containing the log-likelihood, number of estimated parameters, AIC, AICc and BIC all tested models. 
-The data.frame has an attributes "env" which is an environment which contains all the trees, the data and the calls to allow get the estimated models, e.g. as a starting point for further analysis (see example).
-}
-\references{
-Burnham, K. P. and Anderson, D. R (2002)  \emph{Model selection and multimodel inference: a practical information-theoretic approach}. 2nd ed. Springer, New York
+\item{object}{an object of class phyDat or pml}
 
-Posada, D. and Crandall, K.A. (1998) MODELTEST: testing the model of DNA substitution. \emph{Bioinformatics} \bold{14(9)}: 817-818
+\item{tree}{a phylogenetic tree.}
 
-Posada, D. (2008) jModelTest: Phylogenetic Model Averaging. \emph{Molecular Biology and Evolution} \bold{25}: 1253-1256
+\item{model}{a vector containing the substitution models to compare with
+each other or "all" to test all available models}
 
-Darriba D., Taboada G.L., Doallo R and Posada D. (2011) ProtTest 3: fast selection of best-fit models of protein evolution. . \emph{Bioinformatics} \bold{27}: 1164-1165
-}
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
+\item{G}{logical, TRUE (default) if (discrete) Gamma model should be tested}
 
-%% ~Make other sections like Warning with \section{Warning }{....} ~
+\item{I}{logical, TRUE (default) if invariant sites should be tested}
 
-\seealso{
-\code{\link{pml}}, \code{\link{anova}}, \code{\link[stats]{AIC}}
+\item{FREQ}{logical, FALSE (default) if TRUE amino acid frequencies will be
+estimated.}
+
+\item{k}{number of rate classes}
+
+\item{control}{A list of parameters for controlling the fitting process.}
+
+\item{multicore}{logical, whether models should estimated in parallel.}
+
+\item{mc.cores}{The number of cores to use, i.e. at most how many child
+processes will be run simultaneously. Must be at least one, and
+parallelization requires at least two cores.}
+}
+\value{
+A data.frame containing the log-likelihood, number of estimated
+parameters, AIC, AICc and BIC all tested models.  The data.frame has an
+attributes "env" which is an environment which contains all the trees, the
+data and the calls to allow get the estimated models, e.g. as a starting
+point for further analysis (see example).
+}
+\description{
+Comparison of different nucleotide or amino acid substitution models
+}
+\details{
+\code{modelTest} estimates all the specified models for a given tree and
+data.  When the mclapply is available, the computations are done in
+parallel. \code{modelTest} runs each model in one thread.  This is may not
+work within a GUI interface and will not work under Windows.
 }
 \examples{
+
 \dontrun{    
 example(NJ)
 (mT <- modelTest(Laurasiatherian, tree))
@@ -69,8 +69,27 @@ data(chloroplast)
 # test all available amino acid models
 (mTAA_all <- modelTest(chloroplast, model="all", multicore=TRUE, mc.cores=2))
 }
+
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{cluster}
+\references{
+Burnham, K. P. and Anderson, D. R (2002) \emph{Model selection
+and multimodel inference: a practical information-theoretic approach}. 2nd
+ed. Springer, New York
 
+Posada, D. and Crandall, K.A. (1998) MODELTEST: testing the model of DNA
+substitution. \emph{Bioinformatics} \bold{14(9)}: 817-818
+
+Posada, D. (2008) jModelTest: Phylogenetic Model Averaging. \emph{Molecular
+Biology and Evolution} \bold{25}: 1253-1256
+
+Darriba D., Taboada G.L., Doallo R and Posada D. (2011) ProtTest 3: fast
+selection of best-fit models of protein evolution. . \emph{Bioinformatics}
+\bold{27}: 1164-1165
+}
+\seealso{
+\code{\link{pml}}, \code{\link{anova}}, \code{\link[stats]{AIC}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/neighborNet.Rd b/man/neighborNet.Rd
index 8354e8f..976da6b 100644
--- a/man/neighborNet.Rd
+++ b/man/neighborNet.Rd
@@ -1,42 +1,47 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/neighborNet.R
 \name{neighborNet}
 \alias{neighborNet}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Computes a neighborNet from a distance matrix
-}
-\description{
-Computes a neighborNet, i.e. an object of class \code{networx} from a distance matrix.
-}
+\title{Computes a neighborNet from a distance matrix}
 \usage{
 neighborNet(x, ord = NULL)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{x}{a distance matrix.} 
-  \item{ord}{a circular ordering.} 
-}
-\details{
-\code{neighborNet} is still experimental. The cyclic ordering sometimes differ from the SplitsTree implementation, the \emph{ord} argument can be used to enforce a certain circular ordering.   
+\item{x}{a distance matrix.}
+
+\item{ord}{a circular ordering.}
 }
 \value{
-\code{neighborNet} returns an object of class networx.   
+\code{neighborNet} returns an object of class networx.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-%% ~Make other sections like Warning with \section{Warning }{....} ~
-
-\references{ 
-Bryant, D. & Moulton, V. (2004) Neighbor-Net: An Agglomerative Method for the Construction of Phylogenetic Networks. \emph{Molecular Biology and Evolution}, 2004, \bold{21}, 255-265
+\description{
+Computes a neighborNet, i.e. an object of class \code{networx} from a
+distance matrix.
 }
-\seealso{
-\code{\link{splitsNetwork}}, \code{\link{consensusNet}}, \code{\link{plot.networx}}, \code{\link{lento}}, \code{\link{cophenetic.networx}}, \code{\link{distanceHadamard}}
+\details{
+\code{neighborNet} is still experimental. The cyclic ordering sometimes
+differ from the SplitsTree implementation, the \emph{ord} argument can be
+used to enforce a certain circular ordering.
 }
 \examples{
+
 data(yeast)
 dm <- dist.ml(yeast)
 nnet <- neighborNet(dm)
 plot(nnet, "2D")
-}
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ hplot }
 
+}
+\references{
+Bryant, D. & Moulton, V. (2004) Neighbor-Net: An Agglomerative
+Method for the Construction of Phylogenetic Networks. \emph{Molecular
+Biology and Evolution}, 2004, \bold{21}, 255-265
+}
+\seealso{
+\code{\link{splitsNetwork}}, \code{\link{consensusNet}},
+\code{\link{plot.networx}}, \code{\link{lento}},
+\code{\link{cophenetic.networx}}, \code{\link{distanceHadamard}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{hplot}
diff --git a/man/nni.Rd b/man/nni.Rd
index e1ae201..28703b7 100644
--- a/man/nni.Rd
+++ b/man/nni.Rd
@@ -1,36 +1,48 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/treeManipulation.R
 \name{nni}
 \alias{nni}
-\alias{rNNI}
 \alias{rSPR}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{ Tree rearrangements.}
-\description{
-\code{nni} returns a list of all trees which are one nearest neighbor interchange away. \code{rNNI} and \code{rSPR} are two methods which simulate random trees which are a specified number of rearrangement apart from the input tree. Both methods assume that the input tree is bifurcating. These methods may be useful in simulation studies.
-}
+\alias{rNNI}
+\title{Tree rearrangements.}
 \usage{
 nni(tree)
-rSPR(tree, moves=1, n=length(moves), k=NULL)
-rNNI(tree, moves=1, n=length(moves))
+
+rSPR(tree, moves = 1, n = length(moves), k = NULL)
+
+rNNI(tree, moves = 1, n = length(moves))
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{tree}{A phylogenetic \code{tree}, object of class \code{phylo}.}
-  \item{moves}{Number of tree rearrangements to be transformed on a tree.
-  Can be a vector}
-  \item{n}{Number of trees to be simulated.}
-  \item{k}{If defined just SPR of distance k are performed.}
+\item{tree}{A phylogenetic \code{tree}, object of class \code{phylo}.}
+
+\item{moves}{Number of tree rearrangements to be transformed on a tree.  Can
+be a vector}
+
+\item{n}{Number of trees to be simulated.}
+
+\item{k}{If defined just SPR of distance k are performed.}
 }
 \value{
-   an object of class multiPhylo. 
+an object of class multiPhylo.
+}
+\description{
+\code{nni} returns a list of all trees which are one nearest neighbor
+interchange away. \code{rNNI} and \code{rSPR} are two methods which simulate
+random trees which are a specified number of rearrangement apart from the
+input tree. Both methods assume that the input tree is bifurcating. These
+methods may be useful in simulation studies.
 }
-\author{ Klaus Schliep \email{klaus.schliep at gmail.com} }
-
-\seealso{\code{\link{allTrees}}, \code{\link{SPR.dist}}}
 \examples{
+
 tree = unroot(rtree(20))
 trees1 <- nni(tree)
 trees2 <- rSPR(tree, 2, 10)
+
+}
+\seealso{
+\code{\link{allTrees}}, \code{\link{SPR.dist}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
+\keyword{cluster}
diff --git a/man/parsimony.Rd b/man/parsimony.Rd
index 5022126..802ac30 100644
--- a/man/parsimony.Rd
+++ b/man/parsimony.Rd
@@ -1,69 +1,84 @@
-\name{parsimony}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/fitch.R, R/parsimony.R
+\name{fitch}
+\alias{fitch}
+\alias{random.addition}
 \alias{parsimony}
-\alias{optim.parsimony}
 \alias{sankoff}
-\alias{fitch}
-\alias{PNJ}
-\title{Parsimony tree.}
-\alias{CI}
-\alias{RI}
+\alias{optim.parsimony}
 \alias{pratchet}
-\alias{random.addition}
 \alias{acctran}
-\description{
-
-\code{parsimony} returns the parsimony score of a tree using either the sankoff or the fitch algorithm.
-\code{optim.parsimony} tries to find the maximum parsimony tree using either Nearest Neighbor Interchange (NNI) 
-rearrangements or sub tree pruning and regrafting (SPR). \code{pratchet} implements the parsimony ratchet (Nixon, 1999) and is the preferred way to search for the best tree. 
-\code{random.addition} can be used to produce starting trees. 
-\code{CI} and \code{RI} computes the consistency and retention index.  
-}
+\title{Parsimony tree.}
 \usage{
-parsimony(tree, data, method="fitch", ...)
-optim.parsimony(tree, data, method="fitch", cost=NULL, trace=1, rearrangements="SPR", ...)
-pratchet(data, start=NULL, method="fitch", maxit=1000, k=10, trace=1, all=FALSE, 
-    rearrangements="SPR", perturbation="ratchet", ...)
 fitch(tree, data, site = "pscore")
+
+random.addition(data, method = "fitch")
+
+parsimony(tree, data, method = "fitch", ...)
+
 sankoff(tree, data, cost = NULL, site = "pscore")
-random.addition(data, method="fitch")
-CI(tree, data, cost = NULL, sitewise=FALSE)
-RI(tree, data, cost = NULL, sitewise=FALSE)
+
+optim.parsimony(tree, data, method = "fitch", cost = NULL, trace = 1,
+  rearrangements = "SPR", ...)
+
+pratchet(data, start = NULL, method = "fitch", maxit = 1000, k = 10,
+  trace = 1, all = FALSE, rearrangements = "SPR",
+  perturbation = "ratchet", ...)
+
 acctran(tree, data)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{data}{A object of class phyDat containing sequences.}
-  \item{tree}{ tree to start the nni search from.}
-  \item{method}{one of 'fitch' or 'sankoff'.}
-  \item{cost}{A cost matrix for the transitions between two states.} 
-  \item{site}{return either 'pscore' or 'site' wise parsimony scores.} 
-  \item{trace}{defines how much information is printed during optimisation.}  
-  \item{rearrangements}{SPR or NNI rearrangements.} 
-  \item{start}{a starting tree can be supplied.}
-  \item{maxit}{maximum number of iterations in the ratchet.}
-  \item{k}{number of rounds ratchet is stopped, when there is no improvement.}
-  \item{all}{return all equally good trees or just one of them.} 
-  \item{perturbation}{whether using a ratchet or stochastic (nni) for shuffling the tree.}
-  \item{...}{Further arguments passed to or from other methods (e.g. model="sankoff" and cost matrix).} 
-  \item{sitewise}{return CI/RI for alignment or sitewise}
-}  
+\item{tree}{tree to start the nni search from.}
+
+\item{data}{A object of class phyDat containing sequences.}
+
+\item{site}{return either 'pscore' or 'site' wise parsimony scores.}
+
+\item{method}{one of 'fitch' or 'sankoff'.}
+
+\item{...}{Further arguments passed to or from other methods (e.g.
+model="sankoff" and cost matrix).}
+
+\item{cost}{A cost matrix for the transitions between two states.}
+
+\item{trace}{defines how much information is printed during optimisation.}
+
+\item{rearrangements}{SPR or NNI rearrangements.}
+
+\item{start}{a starting tree can be supplied.}
+
+\item{maxit}{maximum number of iterations in the ratchet.}
+
+\item{k}{number of rounds ratchet is stopped, when there is no improvement.}
+
+\item{all}{return all equally good trees or just one of them.}
+
+\item{perturbation}{whether using a ratchet or stochastic (nni) for
+shuffling the tree.}
+}
 \value{
-  \code{parsimony} returns the maximum parsimony score (pscore). 
-  \code{optim.parsimony} returns a tree after NNI rearrangements.
-  \code{pratchet} returns a tree or list of trees containing the best tree(s) found during the search.   
-  \code{acctran} returns a tree with edge length according to the ACCTRAN criterion. 
+\code{parsimony} returns the maximum parsimony score (pscore).
+\code{optim.parsimony} returns a tree after NNI rearrangements.
+\code{pratchet} returns a tree or list of trees containing the best tree(s)
+found during the search.  \code{acctran} returns a tree with edge length
+according to the ACCTRAN criterion.
 }
-\details{
-The "SPR" rearrangements are so far only available for the "fitch" method, "sankoff" only uses "NNI". The "fitch" algorithm only works correct for binary trees. 
+\description{
+\code{parsimony} returns the parsimony score of a tree using either the
+sankoff or the fitch algorithm. \code{optim.parsimony} tries to find the
+maximum parsimony tree using either Nearest Neighbor Interchange (NNI)
+rearrangements or sub tree pruning and regrafting (SPR). \code{pratchet}
+implements the parsimony ratchet (Nixon, 1999) and is the preferred way to
+search for the best tree.  \code{random.addition} can be used to produce
+starting trees.
 }
-\references{
-Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer Associates, Sunderland.
-
-Nixon, K. (1999) The Parsimony Ratchet, a New Method for Rapid Parsimony Analysis. \emph{Cladistics} \bold{15}, 407-414
+\details{
+The "SPR" rearrangements are so far only available for the "fitch" method,
+"sankoff" only uses "NNI". The "fitch" algorithm only works correct for
+binary trees.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\seealso{\code{\link{bab}}, \code{\link{ancestral.pml}}, \code{\link{nni}}, \code{\link{NJ}}, \code{\link{pml}}, \code{\link{getClans}} ,\code{\link{ancestral.pars}}, \code{\link{bootstrap.pml}}}
 \examples{
+
 set.seed(3)
 data(Laurasiatherian)
 dm = dist.hamming(Laurasiatherian)
@@ -79,5 +94,21 @@ plot(midpoint(treeRatchet))
 add.scale.bar(0,0, length=100)
 
 parsimony(c(tree,treeNNI, treeRatchet), Laurasiatherian)
+
+}
+\references{
+Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer
+Associates, Sunderland.
+
+Nixon, K. (1999) The Parsimony Ratchet, a New Method for Rapid Parsimony
+Analysis. \emph{Cladistics} \bold{15}, 407-414
+}
+\seealso{
+\code{\link{bab}}, \code{\link{CI}}, \code{\link{RI}}, \code{\link{ancestral.pml}}, 
+\code{\link{nni}}, \code{\link{NJ}}, \code{\link{pml}}, \code{\link{getClans}}
+,\code{\link{ancestral.pars}}, \code{\link{bootstrap.pml}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
 \keyword{cluster}
diff --git a/man/phangorn-package.Rd b/man/phangorn-package.Rd
index 0398123..c7f4e3f 100644
--- a/man/phangorn-package.Rd
+++ b/man/phangorn-package.Rd
@@ -1,43 +1,38 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/phangorn-package.R
+\docType{package}
 \name{phangorn-package}
 \alias{phangorn-package}
 \alias{phangorn}
-\docType{package}
-\title{
-Phylogenetic analysis in R
-}
+\title{Phylogenetic analysis in R}
 \description{
-Phylogenetic analysis in R (Estimation of phylogenetic
-trees and networks using Maximum Likelihood, Maximum Parsimony,
-Distance methods & Hadamard conjugation)
-
-The complete list of functions can be displayed with \code{library(help = phangorn)}. 
-
+Phylogenetic analysis in R (Estimation of phylogenetic trees and networks
+using Maximum Likelihood, Maximum Parsimony, Distance methods & Hadamard
+conjugation)
+}
+\details{
+The complete list of functions can be displayed with \code{library(help =
+phangorn)}.
 
-Further information is available in several vignettes. To show the available 
-vignettes in an HTML browser type \code{browseVignettes("phangorn")}. 
-\tabular{ll}{
-\code{Trees} \tab Constructing phylogenetic trees (source, pdf) \cr
-\code{phangorn-specials} \tab Advanced features (source, pdf) \cr
+Further information is available in several vignettes. To show the available
+vignettes in an HTML browser type \code{browseVignettes("phangorn")}.
+\tabular{ll}{ \code{Trees} \tab Constructing phylogenetic trees (source,
+pdf) \cr \code{phangorn-specials} \tab Advanced features (source, pdf) \cr
 \code{Ancestral} \tab Ancestral sequence reconstruction (source, pdf) \cr
-\code{Networx} \tab Splits and Networx (source, html) \cr
+\code{Networx} \tab Splits and Networx (source, html) \cr } The first
+vignette (to display type \code{vignette('Trees')}) gives an introduction in
+phylogenetic analysis with phangorn. The second vignette (phangorn-special)
+covers more advanced feature like defining special character spaces and
+things which fit nowhere else.  More information on \bold{phangorn} can be
+found on \url{http://www.phangorn.org}.
 }
-The first vignette (to display type \code{vignette('Trees')}) gives an introduction in phylogenetic analysis with phangorn. The second vignette (phangorn-special) covers more advanced feature like defining special character spaces and things which fit nowhere else. 
-More information on \bold{phangorn} can be found on \url{http://www.phangorn.org}. 
+\references{
+Schliep K.P. (2011) phangorn: Phylogenetic analysis in R.
+\emph{Bioinformatics}, 27(4) 592-593
 }
 \author{
 Klaus Schliep
 
 Maintainer: Klaus Schliep <klaus.schliep at gmail.com>
 }
-\references{
-  Schliep K.P. (2011) phangorn: Phylogenetic analysis in R.
-  \emph{Bioinformatics}, 27(4) 592-593
-}
-\keyword{ package }
-%\seealso{
-%~~ Optional links to other man pages, e.g. ~~
-%~~ \code{\link[<pkg>:<pkg>-package]{<pkg>}} ~~
-%}
-%\examples{
-%~~ simple examples of the most important functions ~~
-%}
+\keyword{package}
diff --git a/man/phyDat.Rd b/man/phyDat.Rd
index e75a439..d64cc50 100644
--- a/man/phyDat.Rd
+++ b/man/phyDat.Rd
@@ -1,125 +1,171 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/phyDat.R
 \name{phyDat}
 \alias{phyDat}
-\alias{as.AAbin.phyDat}
-\alias{as.phyDat.DNAbin}
-\alias{as.phyDat.alignment}
 \alias{as.phyDat.character}
 \alias{as.phyDat.data.frame}
-\alias{as.phyDat.factor}
 \alias{as.phyDat.matrix}
-\alias{as.phyDat.MultipleAlignment}
 \alias{as.MultipleAlignment}
 \alias{as.MultipleAlignment.phyDat}
-\alias{as.data.frame.phyDat}
-\alias{as.character.phyDat}
-\alias{as.DNAbin.phyDat}
-\alias{read.phyDat}
-\alias{write.phyDat}
-\alias{allSitePattern}
-\alias{as.phyDat}
-\alias{subset.phyDat}
-\alias{acgt2ry}
-\alias{baseFreq}
 \alias{cbind.phyDat}
 \alias{c.phyDat}
-\alias{unique.phyDat}
+\alias{acgt2ry}
 \alias{removeUndeterminedSites}
-\alias{phyDat2alignment}
 \alias{phyDat2MultipleAlignment}
-\alias{image.phyDat}
 \alias{dna2codon}
 \alias{codon2dna}
+\alias{as.phyDat}
+\alias{as.phyDat.factor}
+\alias{as.phyDat.DNAbin}
+\alias{as.phyDat.alignment}
+\alias{phyDat2alignment}
+\alias{as.phyDat.MultipleAlignment}
+\alias{as.character.phyDat}
+\alias{as.data.frame.phyDat}
+\alias{as.DNAbin.phyDat}
+\alias{as.AAbin.phyDat}
+\alias{write.phyDat}
+\alias{read.phyDat}
+\alias{baseFreq}
+\alias{subset.phyDat}
+\alias{unique.phyDat}
+\alias{allSitePattern}
+\alias{genlight2phyDat}
+\alias{image.phyDat}
 \title{Conversion among Sequence Formats}
-\description{
-These functions transform several DNA formats into the \code{phyDat} format. 
-\code{allSitePattern} generates an alignment of all possible site patterns.
-}
 \usage{
-phyDat(data, type = "DNA", levels = NULL, return.index=TRUE, ...) 
-read.phyDat(file, format="phylip", type="DNA", ...)
-write.phyDat(x, file, format="phylip", colsep = "", nbcol=-1, ...)
-\method{as.phyDat}{DNAbin}(x, ...)
-\method{as.phyDat}{alignment}(x, type="DNA", ...)
-\method{as.phyDat}{character}(x, ...)
-\method{as.phyDat}{data.frame}(x, ...)
+phyDat(data, type = "DNA", levels = NULL, return.index = TRUE, ...)
+
+dna2codon(x)
+
+codon2dna(x)
+
+as.phyDat(x, ...)
+
 \method{as.phyDat}{factor}(x, ...)
-\method{as.phyDat}{matrix}(x, ...)
+
+\method{as.phyDat}{DNAbin}(x, ...)
+
+\method{as.phyDat}{alignment}(x, type = "DNA", ...)
+
+phyDat2alignment(x)
+
 \method{as.phyDat}{MultipleAlignment}(x, ...)
-%\method{as.AAbin}{phyDat}(x, ...)
+
 \method{as.character}{phyDat}(x, allLevels = TRUE, ...)
+
 \method{as.data.frame}{phyDat}(x, ...)
+
 \method{as.DNAbin}{phyDat}(x, ...)
+
+\method{as.AAbin}{phyDat}(x, ...)
+
+write.phyDat(x, file, format = "phylip", colsep = "", nbcol = -1, ...)
+
+read.phyDat(file, format = "phylip", type = "DNA", ...)
+
+baseFreq(obj, freq = FALSE, all = FALSE, drop.unused.levels = FALSE)
+
 \method{subset}{phyDat}(x, subset, select, site.pattern = TRUE, ...)
+
 \method{unique}{phyDat}(x, incomparables = FALSE, identical = TRUE, ...)
-phyDat2alignment(x)
-allSitePattern(n, levels=c("a","c","g","t"), names=NULL)
-acgt2ry(obj)
-baseFreq(obj, freq=FALSE, all=FALSE, drop.unused.levels=FALSE)
-dna2codon(x)
-codon2dna(x)
+
+allSitePattern(n, levels = c("a", "c", "g", "t"), names = NULL)
+
+genlight2phyDat(x, ambiguity = NA)
+
+\method{image}{phyDat}(x, ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{data}{An object containing sequences.}
-  \item{x}{An object containing sequences.}
-  \item{type}{Type of sequences ("DNA", "AA", "CODON" or "USER").}
-  \item{levels}{Level attributes.}
-  \item{return.index}{If TRUE returns a index of the site patterns.}
-  \item{file}{A file name.}
-  \item{format}{File format of the sequence alignment (see details).
-  Several popular formats are supported: "phylip", "interleaved", "sequential", "clustal", "fasta" or "nexus", or any unambiguous abbreviation of these. 
-  }
-  \item{colsep}{a character used to separate the columns (a single space by default).}
-  \item{nbcol}{a numeric specifying the number of columns per row (-1 by default); may be negative implying that the nucleotides are printed on a single line.}
-  \item{n}{Number of sequences.}
-  \item{names}{Names of sequences.}
-  \item{subset}{a subset of taxa.}
-  \item{select}{a subset of characters.}
-  \item{site.pattern}{select site pattern or sites.}
-  \item{allLevels}{return original data.} 
-  \item{obj}{as object of class phyDat}
-  \item{freq}{logical, if 'TRUE', frequencies or counts are returned otherwise proportions}
-  \item{all}{all a logical; if all = TRUE, all counts of bases, ambiguous codes, missing data, and alignment gaps are returned as defined in the contrast.}
-  \item{drop.unused.levels}{logical, drop unused levels}  
-  \item{incomparables}{for compatibility with unique.}
-  \item{identical}{if TRUE (default) sequences have to be identical, if FALSE sequences are considered 
-  duplicates if distance between sequences is zero (happens frequently with ambiguous sites).}
-  \item{...}{further arguments passed to or from other methods.}
-}
-\details{
-If \code{type} "USER" a vector has to be give to \code{levels}.
-For example c("a", "c", "g", "t", "-") would create a data object that  
-can be used in phylogenetic analysis with gaps as fifth state.  
-There is a more detailed example for specifying "USER" defined data 
-formats in the vignette "phangorn-specials".  
-
-\code{allSitePattern} returns all possible site patterns and can
-be useful in simulation studies. For further details see the vignette 
-phangorn-specials.  
-
-\code{write.phyDat} calls the function write.dna or write.nexus.data and  
-\code{read.phyDat} calls the function \code{read.dna}, \code{read.aa} or \code{read.nexus.data}
-see for more details over there.
-  
-You may import data directly with \code{\link[ape]{read.dna}} or \code{\link[ape]{read.nexus.data}}
-and convert the data to class phyDat. 
-
-The generic function \code{c} can be used to to combine sequences and \code{unique} to get 
-all unique sequences or unique haplotypes. 
-
-\code{acgt2ry} converts a \code{phyDat} object of nucleotides into an binary ry-coded dataset.  
+\item{data}{An object containing sequences.}
+
+\item{type}{Type of sequences ("DNA", "AA", "CODON" or "USER").}
+
+\item{levels}{Level attributes.}
+
+\item{return.index}{If TRUE returns a index of the site patterns.}
+
+\item{...}{further arguments passed to or from other methods.}
+
+\item{x}{An object containing sequences.}
+
+\item{allLevels}{return original data.}
+
+\item{file}{A file name.}
+
+\item{format}{File format of the sequence alignment (see details).  Several
+popular formats are supported: "phylip", "interleaved", "sequential",
+"clustal", "fasta" or "nexus", or any unambiguous abbreviation of these.}
+
+\item{colsep}{a character used to separate the columns (a single space by
+default).}
+
+\item{nbcol}{a numeric specifying the number of columns per row (-1 by
+default); may be negative implying that the nucleotides are printed on a
+single line.}
+
+\item{obj}{as object of class phyDat}
+
+\item{freq}{logical, if 'TRUE', frequencies or counts are returned otherwise
+proportions}
+
+\item{all}{all a logical; if all = TRUE, all counts of bases, ambiguous
+codes, missing data, and alignment gaps are returned as defined in the
+contrast.}
+
+\item{drop.unused.levels}{logical, drop unused levels}
+
+\item{subset}{a subset of taxa.}
+
+\item{select}{a subset of characters.}
+
+\item{site.pattern}{select site pattern or sites.}
+
+\item{incomparables}{for compatibility with unique.}
+
+\item{identical}{if TRUE (default) sequences have to be identical, if FALSE
+sequences are considered duplicates if distance between sequences is zero
+(happens frequently with ambiguous sites).}
+
+\item{n}{Number of sequences.}
+
+\item{names}{Names of sequences.}
+
+\item{ambiguity}{character for ambiguous character and no contrast is provided.}
 }
 \value{
-The functions return an object of class \code{phyDat}. 
+The functions return an object of class \code{phyDat}.
+}
+\description{
+These functions transform several DNA formats into the \code{phyDat} format.
+\code{allSitePattern} generates an alignment of all possible site patterns.
 }
+\details{
+If \code{type} "USER" a vector has to be give to \code{levels}. For example
+c("a", "c", "g", "t", "-") would create a data object that can be used in
+phylogenetic analysis with gaps as fifth state.  There is a more detailed
+example for specifying "USER" defined data formats in the vignette
+"phangorn-specials".
+
+\code{allSitePattern} returns all possible site patterns and can be useful
+in simulation studies. For further details see the vignette
+phangorn-specials.
 
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
+\code{write.phyDat} calls the function write.dna or write.nexus.data and
+\code{read.phyDat} calls the function \code{read.dna}, \code{read.aa} or
+\code{read.nexus.data} see for more details over there.
 
-\seealso{ \code{\link{DNAbin}}, \code{\link{as.DNAbin}}, \code{\link{read.dna}},  \code{\link{read.aa}}, \code{\link{read.nexus.data}} 
-and the chapter 1 in the \code{vignette("phangorn-specials", package="phangorn")} 
-and the example of \code{\link{pmlMix}} for the use of \code{allSitePattern}
+You may import data directly with \code{\link[ape]{read.dna}} or
+\code{\link[ape]{read.nexus.data}} and convert the data to class phyDat.
+
+The generic function \code{c} can be used to to combine sequences and
+\code{unique} to get all unique sequences or unique haplotypes.
+
+\code{acgt2ry} converts a \code{phyDat} object of nucleotides into an binary
+ry-coded dataset.
 }
 \examples{
+
 data(Laurasiatherian)
 class(Laurasiatherian)
 Laurasiatherian
@@ -132,5 +178,16 @@ LauraChar <- as.character(Laurasiatherian)
 Laura <- phyDat(LauraChar, return.index=TRUE)
 all.equal(Laurasiatherian, Laura)
 allSitePattern(5)
+
+}
+\seealso{
+\code{\link{DNAbin}}, \code{\link{as.DNAbin}},
+\code{\link{read.dna}}, \code{\link{read.aa}}, \code{\link{read.nexus.data}}
+and the chapter 1 in the \code{vignette("phangorn-specials",
+package="phangorn")} and the example of \code{\link{pmlMix}} for the use of
+\code{allSitePattern}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
 \keyword{cluster}
diff --git a/man/plot.networx.Rd b/man/plot.networx.Rd
deleted file mode 100644
index beb9c4d..0000000
--- a/man/plot.networx.Rd
+++ /dev/null
@@ -1,154 +0,0 @@
-\name{plot.networx}
-\alias{plot.networx}
-\alias{as.networx}
-\alias{as.networx.splits}
-\alias{as.networx.phylo}
-\alias{write.nexus.networx}
-\alias{read.nexus.networx}
-%\alias{reorder.networx}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Phylogenetic networks
-}
-\description{
-\code{as.networx} convert \code{splits} objects into a  \code{networx} object. 
-\code{plot.networx} plot phylogenetic network or split graphs. 
-}
-\usage{
-as.networx(x, ...)
-\method{as.networx}{splits}(x, planar = FALSE, coord = c("none", "2D", "3D"), ...)
-\method{plot}{networx}(x, type="3D", use.edge.length = TRUE, show.tip.label=TRUE, 
-     show.edge.label=FALSE, edge.label = NULL, show.node.label=FALSE, 
-     node.label = NULL, show.nodes=FALSE, tip.color="black", 
-     edge.color="black", edge.width=3, edge.lty=1, 
-     split.color=NULL, split.width=NULL, split.lty=NULL,
-     font = 3, cex = par("cex"), 
-     cex.node.label=cex, cex.edge.label=cex,
-     col.node.label = tip.color, col.edge.label = tip.color, 
-     font.node.label = font, font.edge.label = font,
-     ...)
-}
-%- maybe also 'usage' for other objects documented here.
-\arguments{
-\item{x}{
-an object of class \code{"splits"} (as.networx) or \code{"networx"} (plot)
-}
-\item{planar}{
-logical whether to produce a planar graph from only cyclic splits 
-(may excludes splits). 
-}
-\item{coord}{add coordinates of the nodes, allows to reproduce the plot.}
-\item{type}{
-"3D" to plot using rgl or "2D" in the normal device. 
-}
-\item{use.edge.length}{
-a logical indicating whether to use the edge weights of the network 
-to draw the branches (the default) or not. 
-}
-\item{show.tip.label}{
-a logical indicating whether to show the tip labels on the 
-graph (defaults to \code{TRUE}, i.e. the labels are shown).
-}
-\item{show.edge.label}{
-a logical indicating whether to show the tip labels on the graph.
-}
-\item{edge.label}{
-an additional vector of edge labels (normally not needed).
-}
-\item{show.node.label}{
-a logical indicating whether to show the node labels (see example).
-}
-\item{node.label}{
-an additional vector of node labels (normally not needed).
-}
-\item{show.nodes}{
-a logical indicating whether to show the nodes (see example).
-}
-\item{tip.color}{
-the colors used for the tip labels.
-}
-\item{edge.color}{
-the colors used to draw edges.
-}
-\item{edge.width}{
-the width used to draw edges.
-}
-\item{edge.lty}{
-a vector of line types.
-}
-\item{split.color}{
-the colors used to draw edges.
-}
-\item{split.width}{
-the width used to draw edges.
-}
-\item{split.lty}{
-a vector of line types.
-}
-\item{font}{
-an integer specifying the type of font for the labels: 1 (plain text), 
-2 (bold), 3 (italic, the default), or 4 (bold italic).
-}
-\item{cex}{
-a numeric value giving the factor scaling of the labels.}
-\item{cex.node.label}{
-a numeric value giving the factor scaling of the node labels.}
-\item{cex.edge.label}{
-a numeric value giving the factor scaling of the edge labels.}
-\item{col.node.label}{
-the colors used for the node labels.
-}
-\item{col.edge.label}{
-the colors used for the edge labels.
-}
-\item{font.node.label}{
-the font used for the node labels.
-}
-\item{font.edge.label}{
-the font used for the edge labels.
-}
-\item{\dots}{
-Further arguments passed to or from other methods.
-}
-}
-\details{
-A \code{networx} object hold the information for a phylogenetic network 
-and extends the \code{phylo} object. Therefore some generic function for 
-\code{phylo} objects will also work for \code{networx} objects. 
-The argument planar = FALSE will create a planar split graph based on a 
-cyclic ordering. These objects can be nicely plotted in "2D".
-So far not all parameters behave the same on the the rgl "3D"
-and basic graphic "2D" device. 
-
-Often it is easier (and safer) to supply vectors of graphical parameters for splits (e.g. splits.color). 
-These overwrite values edge.color. 
-}
-\note{
-The internal representation is likely to change. 
-}
-\references{
-Dress, A.W.M. and Huson, D.H. (2004) Constructing Splits Graphs \emph{IEEE/ACM Transactions on Computational Biology and Bioinformatics (TCBB)}, \bold{1(3)}, 109--115
-}
-\author{
-Klaus Schliep \email{klaus.schliep at gmail.com}
-}
-\seealso{
-\code{\link{consensusNet}}, \code{\link{neighborNet}}, \code{\link{splitsNetwork}}, \code{\link{hadamard}}, 
-\code{\link{distanceHadamard}}, \code{\link{layout_with_kk}}, 
-\code{\link[ape]{evonet}}, \code{\link[ape]{as.igraph}}, \code{\link{densiTree}}
-}
-\examples{
-set.seed(1)
-tree1 = rtree(20, rooted=FALSE)
-sp = as.splits(rNNI(tree1, n=10))
-net = as.networx(sp)
-plot(net, "2D")
-\dontrun{
-# also see example in consensusNet 
-example(consensusNet)
-}
-}
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{plot}
-
diff --git a/man/pml.Rd b/man/pml.Rd
index e98fb32..c50beec 100644
--- a/man/pml.Rd
+++ b/man/pml.Rd
@@ -1,145 +1,137 @@
-\name{pml}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/phylo.R
+\name{pml.control}
+\alias{pml.control}
 \alias{pml}
 \alias{optim.pml}
-\alias{pml.control}
 \title{Likelihood of a tree.}
-\description{
-\code{pml} computes the likelihood of a phylogenetic tree 
-given a sequence alignment and a model. \code{optim.pml} optimizes the 
-different model parameters.
-}
 \usage{
-pml(tree, data, bf=NULL, Q=NULL, inv=0, k=1, shape=1, rate=1, model="", ...)     
-optim.pml(object, optNni=FALSE, optBf=FALSE, optQ=FALSE, optInv=FALSE, optGamma=FALSE,
-    optEdge=TRUE, optRate=FALSE, optRooted=FALSE, 
-    control = pml.control(epsilon=1e-08, maxit=10, trace=1), model = NULL, 
-    rearrangement = ifelse(optNni, "NNI","none"), subs = NULL, 
-    ratchet.par = list(iter = 20L, maxit = 100L, prop = 1/3),...)  
 pml.control(epsilon = 1e-08, maxit = 10, trace = 1)
+
+pml(tree, data, bf = NULL, Q = NULL, inv = 0, k = 1, shape = 1,
+  rate = 1, model = NULL, ...)
+
+optim.pml(object, optNni = FALSE, optBf = FALSE, optQ = FALSE,
+  optInv = FALSE, optGamma = FALSE, optEdge = TRUE, optRate = FALSE,
+  optRooted = FALSE, control = pml.control(epsilon = 1e-08, maxit = 10,
+  trace = 1L), model = NULL, rearrangement = ifelse(optNni, "NNI", "none"),
+  subs = NULL, ratchet.par = list(iter = 20L, maxit = 100L, prop = 1/3),
+  ...)
 }
 \arguments{
-  \item{tree}{A phylogenetic \code{tree}, object of class \code{phylo}. }
-  \item{data}{An alignment, object of class \code{phyDat}.}
-  \item{bf}{Base frequencies.}
-  \item{Q}{A vector containing the lower triangular part of the rate matrix.}
-  \item{inv}{Proportion of invariable sites.}
-  \item{k}{Number of intervals of the discrete gamma distribution.}
-  \item{shape}{Shape parameter of the gamma distribution.}
-  \item{rate}{Rate.}
-  \item{model}{allows to choose an amino acid models or nucleotide model, see details.}
-  \item{object}{An object of class \code{pml}.}
-  \item{optNni}{Logical value indicating whether toplogy gets optimized (NNI).}
-  \item{optBf}{Logical value indicating whether base frequencies gets optimized.}
-  \item{optQ}{Logical value indicating whether rate matrix gets optimized.}
-  \item{optInv}{Logical value indicating whether proportion of variable size gets optimized.}
-  \item{optGamma}{Logical value indicating whether gamma rate parameter gets optimized.}
-  \item{optEdge}{Logical value indicating the edge lengths gets optimized.}
-  \item{optRate}{Logical value indicating the overall rate gets optimized.}
-  \item{optRooted}{Logical value indicating if the edge lengths of a rooted tree get optimized.}
-%  \item{optRatchet}{Stochastic tree search.}
-  \item{ratchet.par}{search parameter for stochastic search}
-  \item{rearrangement}{type of tree tree rearrangements to perform, one of
-      "none", "NNI", "stochastic" or "ratchet"}
-  \item{control}{A list of parameters for controlling the fitting process.}
-  \item{subs}{A (integer) vector same length as Q to specify the optimization of Q}
-  \item{\dots}{Further arguments passed to or from other methods.}
-  \item{epsilon}{Stop criterion for optimisation (see details).} 
-  \item{maxit}{Maximum number of iterations (see details).}  
-  \item{trace}{Show output during optimization (see details).}    
-}
-\details{
-The topology search uses a nearest neighbor interchange (NNI) 
-and the implementation is similar to phyML. 
-The option model in pml is only used for amino acid models. 
-The option model defines the nucleotide model which is getting optimised, 
-all models which are included in modeltest can be chosen. Setting this option 
-(e.g. "K81" or "GTR") overrules options optBf and optQ.  
-Here is a overview how to estimate different phylogenetic models 
-with \code{pml}:  
-\tabular{lll}{
-model \tab optBf \tab optQ \cr
-Jukes-Cantor \tab FALSE \tab FALSE \cr
-F81 \tab TRUE \tab FALSE \cr
-symmetric \tab FALSE \tab TRUE \cr
-GTR \tab TRUE \tab TRUE
-}
-Via model in optim.pml the following nucleotide models can be specified:  
-JC, F81, K80, HKY, TrNe, TrN, TPM1, K81, TPM1u, TPM2, TPM2u, TPM3, TPM3u, 
-TIM1e, TIM1, TIM2e, TIM2, TIM3e, TIM3, TVMe, TVM, SYM and GTR. 
-These models are specified as in Posada (2008).
+\item{epsilon}{Stop criterion for optimisation (see details).}
 
-So far 17 amino acid models are supported ("WAG", "JTT", "LG", "Dayhoff", "cpREV", "mtmam", "mtArt", "MtZoa", "mtREV24", "VT","RtREV", "HIVw", "HIVb", "FLU", "Blossum62", "Dayhoff_DCMut" and "JTT_DCMut") and additionally rate matrices and amino acid frequencies can be supplied. 
+\item{maxit}{Maximum number of iterations (see details).}
 
-It is also possible to estimate codon models (e.g. YN98), for details see also the chapter in vignette("phangorn-specials"). 
+\item{trace}{Show output during optimization (see details).}
 
-If the option 'optRooted' is set to TRUE than the edge lengths of rooted tree are optimized.
-The tree has to be rooted and by now ultrametric! Optimising rooted trees is generally much slower.
-  
-\code{pml.control} controls the fitting process. \code{epsilon} and \code{maxit} are only defined 
-for the most outer loop, this affects \code{pmlCluster}, \code{pmlPart} and \code{pmlMix}. 
-\code{epsilon} is defined as (logLik(k)-logLik(k+1))/logLik(k+1), this seems to be a good 
-heuristics which works reasonably for small and large trees or alignments. 
-If \code{trace} is set to zero than no out put is shown, if functions are called internally 
-than the trace is decreased by one, so a higher of trace produces more feedback. 
-
-If \code{rearrangement} is set to \code{stochastic} a stochastic search algorithm similar to Nguyen et al. (2015).
-and for \code{ratchet} the likelihood ratchet as in Vos (2003). 
-This should helps often to find better tree topologies, especially for larger trees.   
-}
-\value{
-\code{pml} or \code{optim.pml} return a list of class \code{pml}, some are useful for further computations like 
-  \item{tree}{the phylogenetic tree.}
-  \item{data}{the alignment.}
-  \item{logLik}{Log-likelihood of the tree.}
-  \item{siteLik}{Site log-likelihoods.}
-  \item{weight}{Weight of the site patterns.}
-}
-\references{ 
-Felsenstein, J. (1981) Evolutionary trees from DNA sequences: a maximum
-likelihood approach. \emph{Journal of Molecular Evolution}, \bold{17}, 368--376. 
+\item{tree}{A phylogenetic \code{tree}, object of class \code{phylo}.}
 
-Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer Associates, Sunderland.
+\item{data}{An alignment, object of class \code{phyDat}.}
 
-Yang, Z. (2006). \emph{Computational Molecular evolution}. Oxford University Press, Oxford.
+\item{bf}{Base frequencies.}
 
-Adachi, J., P. J. Waddell, W. Martin, and M. Hasegawa (2000) 
-Plastid genome phylogeny and a model of amino acid substitution for proteins
-encoded by chloroplast DNA.  \emph{Journal of Molecular Evolution}, \bold{50}, 348--358                             
+\item{Q}{A vector containing the lower triangular part of the rate matrix.}
 
-Rota-Stabelli, O., Z. Yang, and M. Telford. (2009) MtZoa: a general mitochondrial 
-amino acid substitutions model for animal evolutionary studies. \emph{Mol. Phyl. Evol}, \bold{52(1)}, 268--72       
+\item{inv}{Proportion of invariable sites.}
 
-Whelan, S. and Goldman, N. (2001) A general empirical model of 
-protein evolution derived from multiple protein families using 
-a maximum-likelihood approach. \emph{Molecular Biology and Evolution},  \bold{18}, 691--699                       
+\item{k}{Number of intervals of the discrete gamma distribution.}
 
-Le, S.Q. and Gascuel, O. (2008) LG: An Improved, General 
-Amino-Acid Replacement Matrix \emph{Molecular Biology and Evolution}, \bold{25(7)}, 1307--1320                     
+\item{shape}{Shape parameter of the gamma distribution.}
 
-Yang, Z., R. Nielsen, and M. Hasegawa (1998) Models of amino acid                                                
-substitution and applications to Mitochondrial protein evolution. 
-\emph{Molecular Biology and Evolution}, \bold{15}, 1600--1611
+\item{rate}{Rate.}
+
+\item{model}{allows to choose an amino acid models or nucleotide model, see
+details.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+
+\item{object}{An object of class \code{pml}.}
+
+\item{optNni}{Logical value indicating whether toplogy gets optimized (NNI).}
+
+\item{optBf}{Logical value indicating whether base frequencies gets
+optimized.}
 
-Abascal, F., D. Posada, and R. Zardoya (2007) MtArt: A new Model of amino acid 
-replacement for Arthropoda. \emph{Molecular Biology and Evolution}, \bold{24}, 1--5                                          
+\item{optQ}{Logical value indicating whether rate matrix gets optimized.}
 
-Kosiol, C, and Goldman, N (2005) Different versions of the Dayhoff rate matrix -                               
-\emph{Molecular Biology and Evolution}, \bold{22}, 193--199 
+\item{optInv}{Logical value indicating whether proportion of variable size
+gets optimized.}
 
-L.-T. Nguyen, H.A. Schmidt, A. von Haeseler, and B.Q. Minh (2015) IQ-TREE: A fast and effective stochastic algorithm for estimating maximum likelihood phylogenies. \emph{Molecular Biology and Evolution}, \bold{32}, 268--274.
+\item{optGamma}{Logical value indicating whether gamma rate parameter gets
+optimized.}
 
-Vos, R. A. (2003) Accelerated Likelihood Surface Exploration: The Likelihood Ratchet. \emph{Systematic Biology}, \bold{52(3)}, 368--373
+\item{optEdge}{Logical value indicating the edge lengths gets optimized.}
 
-Yang, Z., and R. Nielsen (1998) Synonymous and nonsynonymous rate variation in nuclear genes of mammals. \emph{Journal of Molecular Evolution}, \bold{46}, 409-418.
+\item{optRate}{Logical value indicating the overall rate gets optimized.}
 
-Lewis, P.O. (2001) A likelihood approach to estimating phylogeny from discrete morphological character data. \emph{Systematic Biology} \bold{50}, 913--925. 
+\item{optRooted}{Logical value indicating if the edge lengths of a rooted
+tree get optimized.}
+
+\item{control}{A list of parameters for controlling the fitting process.}
+
+\item{rearrangement}{type of tree tree rearrangements to perform, one of
+"none", "NNI", "stochastic" or "ratchet"}
+
+\item{subs}{A (integer) vector same length as Q to specify the optimization
+of Q}
+
+\item{ratchet.par}{search parameter for stochastic search}
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\seealso{
-\code{\link{bootstrap.pml}}, \code{\link{modelTest}}, \code{\link{pmlPart}}, \code{\link{pmlMix}}, \code{\link{plot.phylo}}, \code{\link{SH.test}}, \code{\link{ancestral.pml}} 
+\value{
+\code{pml} or \code{optim.pml} return a list of class \code{pml},
+some are useful for further computations like \item{tree}{the phylogenetic
+tree.} \item{data}{the alignment.} \item{logLik}{Log-likelihood of the
+tree.} \item{siteLik}{Site log-likelihoods.} \item{weight}{Weight of the
+site patterns.}
+}
+\description{
+\code{pml} computes the likelihood of a phylogenetic tree given a sequence
+alignment and a model. \code{optim.pml} optimizes the different model
+parameters.
+}
+\details{
+The topology search uses a nearest neighbor interchange (NNI) and the
+implementation is similar to phyML.  The option model in pml is only used
+for amino acid models.  The option model defines the nucleotide model which
+is getting optimised, all models which are included in modeltest can be
+chosen. Setting this option (e.g. "K81" or "GTR") overrules options optBf
+and optQ.  Here is a overview how to estimate different phylogenetic models
+with \code{pml}: \tabular{lll}{ model \tab optBf \tab optQ \cr Jukes-Cantor
+\tab FALSE \tab FALSE \cr F81 \tab TRUE \tab FALSE \cr symmetric \tab FALSE
+\tab TRUE \cr GTR \tab TRUE \tab TRUE } Via model in optim.pml the following
+nucleotide models can be specified: JC, F81, K80, HKY, TrNe, TrN, TPM1, K81,
+TPM1u, TPM2, TPM2u, TPM3, TPM3u, TIM1e, TIM1, TIM2e, TIM2, TIM3e, TIM3,
+TVMe, TVM, SYM and GTR.  These models are specified as in Posada (2008).
+
+So far 17 amino acid models are supported ("WAG", "JTT", "LG", "Dayhoff",
+"cpREV", "mtmam", "mtArt", "MtZoa", "mtREV24", "VT","RtREV", "HIVw", "HIVb",
+"FLU", "Blossum62", "Dayhoff_DCMut" and "JTT_DCMut") and additionally rate
+matrices and amino acid frequencies can be supplied.
+
+It is also possible to estimate codon models (e.g. YN98), for details see
+also the chapter in vignette("phangorn-specials").
+
+If the option 'optRooted' is set to TRUE than the edge lengths of rooted
+tree are optimized. The tree has to be rooted and by now ultrametric!
+Optimising rooted trees is generally much slower.
+
+\code{pml.control} controls the fitting process. \code{epsilon} and
+\code{maxit} are only defined for the most outer loop, this affects
+\code{pmlCluster}, \code{pmlPart} and \code{pmlMix}.  \code{epsilon} is
+defined as (logLik(k)-logLik(k+1))/logLik(k+1), this seems to be a good
+heuristics which works reasonably for small and large trees or alignments.
+If \code{trace} is set to zero than no out put is shown, if functions are
+called internally than the trace is decreased by one, so a higher of trace
+produces more feedback.
+
+If \code{rearrangement} is set to \code{stochastic} a stochastic search
+algorithm similar to Nguyen et al. (2015). and for \code{ratchet} the
+likelihood ratchet as in Vos (2003).  This should helps often to find better
+tree topologies, especially for larger trees.
 }
-% \note{For small trees the likelihood seems to be very similar to Paup* or PhyML.}
 \examples{
+
   example(NJ)
 # Jukes-Cantor (starting tree from NJ)  
   fitJC <- pml(tree, Laurasiatherian)  
@@ -170,5 +162,67 @@ Lewis, P.O. (2001) A likelihood approach to estimating phylogeny from discrete m
   fit2ST
 # show some of the methods available for class pml
   methods(class="pml")  
+
+}
+\references{
+Felsenstein, J. (1981) Evolutionary trees from DNA sequences: a
+maximum likelihood approach. \emph{Journal of Molecular Evolution},
+\bold{17}, 368--376.
+
+Felsenstein, J. (2004). \emph{Inferring Phylogenies}. Sinauer Associates,
+Sunderland.
+
+Yang, Z. (2006). \emph{Computational Molecular evolution}. Oxford University
+Press, Oxford.
+
+Adachi, J., P. J. Waddell, W. Martin, and M. Hasegawa (2000) Plastid genome
+phylogeny and a model of amino acid substitution for proteins encoded by
+chloroplast DNA.  \emph{Journal of Molecular Evolution}, \bold{50}, 348--358
+
+Rota-Stabelli, O., Z. Yang, and M. Telford. (2009) MtZoa: a general
+mitochondrial amino acid substitutions model for animal evolutionary
+studies. \emph{Mol. Phyl. Evol}, \bold{52(1)}, 268--72
+
+Whelan, S. and Goldman, N. (2001) A general empirical model of protein
+evolution derived from multiple protein families using a maximum-likelihood
+approach. \emph{Molecular Biology and Evolution}, \bold{18}, 691--699
+
+Le, S.Q. and Gascuel, O. (2008) LG: An Improved, General Amino-Acid
+Replacement Matrix \emph{Molecular Biology and Evolution}, \bold{25(7)},
+1307--1320
+
+Yang, Z., R. Nielsen, and M. Hasegawa (1998) Models of amino acid
+substitution and applications to Mitochondrial protein evolution.
+\emph{Molecular Biology and Evolution}, \bold{15}, 1600--1611
+
+Abascal, F., D. Posada, and R. Zardoya (2007) MtArt: A new Model of amino
+acid replacement for Arthropoda. \emph{Molecular Biology and Evolution},
+\bold{24}, 1--5
+
+Kosiol, C, and Goldman, N (2005) Different versions of the Dayhoff rate
+matrix - \emph{Molecular Biology and Evolution}, \bold{22}, 193--199
+
+L.-T. Nguyen, H.A. Schmidt, A. von Haeseler, and B.Q. Minh (2015) IQ-TREE: A
+fast and effective stochastic algorithm for estimating maximum likelihood
+phylogenies. \emph{Molecular Biology and Evolution}, \bold{32}, 268--274.
+
+Vos, R. A. (2003) Accelerated Likelihood Surface Exploration: The Likelihood
+Ratchet. \emph{Systematic Biology}, \bold{52(3)}, 368--373
+
+Yang, Z., and R. Nielsen (1998) Synonymous and nonsynonymous rate variation
+in nuclear genes of mammals. \emph{Journal of Molecular Evolution},
+\bold{46}, 409-418.
+
+Lewis, P.O. (2001) A likelihood approach to estimating phylogeny from
+discrete morphological character data. \emph{Systematic Biology} \bold{50},
+913--925.
+}
+\seealso{
+\code{\link{bootstrap.pml}}, \code{\link{modelTest}},
+\code{\link{pmlPart}}, \code{\link{pmlMix}}, \code{\link{plot.phylo}},
+\code{\link{SH.test}}, \code{\link{ancestral.pml}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-\keyword{ cluster }% at least one, from doc/KEYWORDS
+\keyword{cluster}
diff --git a/man/pml.fit.Rd b/man/pml.fit.Rd
index ddcc3f4..14d7b72 100644
--- a/man/pml.fit.Rd
+++ b/man/pml.fit.Rd
@@ -1,67 +1,92 @@
-\name{pml.fit}
-\alias{pml.fit}
-\alias{edQt}
-\alias{pml.init}
-\alias{pml.free}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/phylo.R
+\name{discrete.gamma}
 \alias{discrete.gamma}
 \alias{lli}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Internal maximum likelihood functions.   
-}
-\description{
-These functions are internally used for the likelihood computations in \code{pml} or \code{optim.pml}. 
-}
+\alias{edQt}
+\alias{pml.free}
+\alias{pml.init}
+\alias{pml.fit}
+\title{Internal maximum likelihood functions.}
 \usage{
-pml.fit(tree, data, bf=rep(1/length(levels), length(levels)), shape=1, k=1,
-   Q=rep(1, length(levels)*(length(levels)-1)/2), levels=attr(data, "levels"),
-   inv=0, rate=1, g=NULL, w=NULL, eig=NULL, INV=NULL, ll.0=NULL, llMix=NULL, 
-   wMix=0, ..., site=FALSE)
-pml.init(data, k)
-pml.free()   
-edQt(Q = c(1, 1, 1, 1, 1, 1), bf = c(0.25, 0.25, 0.25, 0.25))
-lli(data, tree, ...)
 discrete.gamma(alpha, k)
+
+lli(data, tree = NULL, ...)
+
+edQt(Q = c(1, 1, 1, 1, 1, 1), bf = c(0.25, 0.25, 0.25, 0.25))
+
+pml.free()
+
+pml.init(data, k = 1L)
+
+pml.fit(tree, data, bf = rep(1/length(levels), length(levels)), shape = 1,
+  k = 1, Q = rep(1, length(levels) * (length(levels) - 1)/2),
+  levels = attr(data, "levels"), inv = 0, rate = 1, g = NULL,
+  w = NULL, eig = NULL, INV = NULL, ll.0 = NULL, llMix = NULL,
+  wMix = 0, ..., site = FALSE)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{tree}{A phylogenetic \code{tree}, object of class \code{phylo}. }
-  \item{data}{An alignment, object of class \code{phyDat}.}
-  \item{bf}{Base frequencies.}
-  \item{shape}{Shape parameter of the gamma distribution.}
-  \item{alpha}{Shape parameter of the gamma distribution.}
-  \item{k}{Number of intervals of the discrete gamma distribution.}
-  \item{Q}{A vector containing the lower triangular part of the rate matrix.}
-  \item{levels}{The alphabet used e.g. c("a", "c", "g", "t") for DNA}
-  \item{inv}{Proportion of invariable sites.}
-  \item{rate}{Rate.}
-  \item{g}{vector of quantiles (default is NULL)}
-  \item{w}{vector of probabilities (default is NULL)}
-  \item{eig}{Eigenvalue decomposition of Q}
-  \item{INV}{Sparse representation of invariant sites}
-  \item{ll.0}{default is NULL}
-  \item{llMix}{default is NULL}
-  \item{wMix}{default is NULL}
-  \item{\dots}{Further arguments passed to or from other methods.}
-  \item{site}{return the log-likelihood or vector of sitewise likelihood values}
-}  
-\details{
-These functions are exported to be used in different packages so far only in the package coalescentMCMC, but are not intended for end user. Most of the functions call C code and are far less forgiving if the import is not what they expect than \code{pml}. 
+\item{alpha}{Shape parameter of the gamma distribution.}
+
+\item{k}{Number of intervals of the discrete gamma distribution.}
+
+\item{data}{An alignment, object of class \code{phyDat}.}
+
+\item{tree}{A phylogenetic \code{tree}, object of class \code{phylo}.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+
+\item{Q}{A vector containing the lower triangular part of the rate matrix.}
+
+\item{bf}{Base frequencies.}
+
+\item{shape}{Shape parameter of the gamma distribution.}
+
+\item{levels}{The alphabet used e.g. c("a", "c", "g", "t") for DNA}
+
+\item{inv}{Proportion of invariable sites.}
+
+\item{rate}{Rate.}
+
+\item{g}{vector of quantiles (default is NULL)}
+
+\item{w}{vector of probabilities (default is NULL)}
+
+\item{eig}{Eigenvalue decomposition of Q}
+
+\item{INV}{Sparse representation of invariant sites}
+
+\item{ll.0}{default is NULL}
+
+\item{llMix}{default is NULL}
+
+\item{wMix}{default is NULL}
+
+\item{site}{return the log-likelihood or vector of sitewise likelihood
+values}
 }
 \value{
-\code{pml.fit} returns the log-likelihood. 
+\code{pml.fit} returns the log-likelihood.
 }
-\references{
-Felsenstein, J. (1981) Evolutionary trees from DNA sequences: a maximum
-likelihood approach. \emph{Journal of Molecular Evolution}, \bold{17}, 368--376. 
+\description{
+These functions are internally used for the likelihood computations in
+\code{pml} or \code{optim.pml}.
 }
-\author{
-Klaus Schliep \email{klaus.schliep at gmail.com}
+\details{
+These functions are exported to be used in different packages so far only in
+the package coalescentMCMC, but are not intended for end user. Most of the
+functions call C code and are far less forgiving if the import is not what
+they expect than \code{pml}.
+}
+\references{
+Felsenstein, J. (1981) Evolutionary trees from DNA sequences: a
+maximum likelihood approach. \emph{Journal of Molecular Evolution},
+\bold{17}, 368--376.
 }
 \seealso{
 \code{\link{pml}, \link{pmlPart}, \link{pmlMix}}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
-
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/pmlCluster.Rd b/man/pmlCluster.Rd
index 6784d97..df13033 100644
--- a/man/pmlCluster.Rd
+++ b/man/pmlCluster.Rd
@@ -1,54 +1,53 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/pmlPart.R
 \name{pmlCluster}
 \alias{pmlCluster}
-%\alias{pmlCluster2}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{ Stochastic Partitioning }
-\description{
-  Stochastic Partitioning of genes into p cluster. 
-}
+\title{Stochastic Partitioning}
 \usage{
-pmlCluster(formula, fit, weight, p=1:5, part=NULL, nrep = 10, 
-    control=pml.control(epsilon=1e-8, maxit=10, trace=1),...)
+pmlCluster(formula, fit, weight, p = 1:5, part = NULL, nrep = 10,
+  control = pml.control(epsilon = 1e-08, maxit = 10, trace = 1), ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{formula}{ a formula object (see details).}
-  \item{fit}{ an object of class \code{pml}. }
-  \item{weight}{ \code{weight}  is matrix of frequency of site patterns for all genes. }
-  \item{p}{ number of clusters. }
-  \item{part}{ starting partition, otherwise a random partition is generated. }
-  \item{nrep}{ number of replicates for each p.  }
-  \item{control}{A list of parameters for controlling the fitting process.} 
-  \item{\dots}{ Further arguments passed to or from other methods. }
-}
-\details{
-    The \code{formula} object allows to specify which parameter get     
-    optimized. The formula is generally of the form \code{edge + bf + Q 
-    ~ rate + shape + \dots}, on the left side are the parameters which 
-    get optimized over all cluster, on the right the parameter which
-    are optimized specific to each cluster. The parameters available 
-    are \code{"nni", "bf", "Q", "inv", "shape", "edge", "rate"}.
-    Each parameter can be used only once in the formula. 
-    There are also some restriction on the combinations how parameters 
-    can get used. \code{"rate"} is only available for the right side.  
-    When \code{"rate"} is specified on the left hand side \code{"edge"}
-    has to be specified (on either side), if  \code{"rate"} is specified on 
-    the right hand side it follows directly that \code{edge} is too. 
+\item{formula}{a formula object (see details).}
+
+\item{fit}{an object of class \code{pml}.}
+
+\item{weight}{\code{weight} is matrix of frequency of site patterns for all
+genes.}
+
+\item{p}{number of clusters.}
+
+\item{part}{starting partition, otherwise a random partition is generated.}
+
+\item{nrep}{number of replicates for each p.}
+
+\item{control}{A list of parameters for controlling the fitting process.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
 }
 \value{
-  \code{pmlCluster} returns a list with elements
-  \item{logLik}{log-likelihood of the fit}
-  \item{trees}{a list of all trees during the optimization.} 
-  \item{fits}{fits for the final partitions}
+\code{pmlCluster} returns a list with elements
+\item{logLik}{log-likelihood of the fit} \item{trees}{a list of all trees
+during the optimization.} \item{fits}{fits for the final partitions}
 }
-\references{ 
-K. P. Schliep (2009). Some Applications of statistical phylogenetics (PhD Thesis) 
-
-Lanfear, R., Calcott, B., Ho, S.Y.W. and Guindon, S. (2012) PartitionFinder: Combined Selection of Partitioning Schemes and Substitution Models for Phylogenetic Analyses. \emph{Molecular Biology and Evolution}, \bold{29(6)}, 1695-1701
+\description{
+Stochastic Partitioning of genes into p cluster.
+}
+\details{
+The \code{formula} object allows to specify which parameter get optimized.
+The formula is generally of the form \code{edge + bf + Q ~ rate + shape +
+\dots{}}, on the left side are the parameters which get optimized over all
+cluster, on the right the parameter which are optimized specific to each
+cluster. The parameters available are \code{"nni", "bf", "Q", "inv",
+"shape", "edge", "rate"}.  Each parameter can be used only once in the
+formula.  There are also some restriction on the combinations how parameters
+can get used. \code{"rate"} is only available for the right side.  When
+\code{"rate"} is specified on the left hand side \code{"edge"} has to be
+specified (on either side), if \code{"rate"} is specified on the right hand
+side it follows directly that \code{edge} is too.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\seealso{  \code{\link{pml}},\code{\link{pmlPart}},\code{\link{pmlMix}},\code{\link{SH.test}} }
 \examples{
+
 \dontrun{
 data(yeast)
 dm <- dist.logDet(yeast)
@@ -63,8 +62,21 @@ sp <- pmlCluster(edge~rate, fit, weight, p=1:4)
 sp
 SH.test(sp)
 }
+
+}
+\references{
+K. P. Schliep (2009). Some Applications of statistical
+phylogenetics (PhD Thesis)
+
+Lanfear, R., Calcott, B., Ho, S.Y.W. and Guindon, S. (2012) PartitionFinder:
+Combined Selection of Partitioning Schemes and Substitution Models for
+Phylogenetic Analyses. \emph{Molecular Biology and Evolution}, \bold{29(6)},
+1695-1701
+}
+\seealso{
+\code{\link{pml}},\code{\link{pmlPart}},\code{\link{pmlMix}},\code{\link{SH.test}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
-%\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
+\keyword{cluster}
diff --git a/man/pmlMix.Rd b/man/pmlMix.Rd
index 041c749..b7ddf65 100644
--- a/man/pmlMix.Rd
+++ b/man/pmlMix.Rd
@@ -1,47 +1,48 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/pmlMix.R
 \name{pmlMix}
 \alias{pmlMix}
 \alias{pmlPen}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{ Phylogenetic mixture model }
-\description{
-  Phylogenetic mixture model. 
-}
+\title{Phylogenetic mixture model}
 \usage{
-pmlMix(formula, fit, m=2, omega=rep(1/m, m), control=pml.control(epsilon=1e-08, 
-    maxit=20, trace=1),...)
+pmlMix(formula, fit, m = 2, omega = rep(1/m, m),
+  control = pml.control(epsilon = 1e-08, maxit = 20, trace = 1), ...)
 }
 \arguments{
-  \item{formula}{ a formula object (see details).}
-  \item{fit}{ an object of class \code{pml}. }
-  \item{m}{ number of mixtures. }
-  \item{omega}{ mixing weights.}
-  \item{control}{A list of parameters for controlling the fitting process.}
-  \item{\dots}{ Further arguments passed to or from other methods. }
-}
-\details{
-    The \code{formula} object allows to specify which parameter get     
-    optimized. The formula is generally of the form \code{edge + bf + Q 
-    ~ rate + shape + \dots}, on the left side are the parameters which 
-    get optimized over all mixtures, on the right the parameter which
-    are optimized specific to each mixture. The parameters available 
-    are \code{"nni", "bf", "Q", "inv", "shape", "edge", "rate"}.
-    Each parameters can be used only once in the formula. 
-    \code{"rate"} and \code{"nni"} are only available for the right side
-    of the formula. On the other hand parameters for invariable sites 
-    are only allowed on the left-hand side. 
-    The convergence of the algorithm is very slow and is likely that the
-    algorithm can get stuck in local optima.     
+\item{formula}{a formula object (see details).}
+
+\item{fit}{an object of class \code{pml}.}
+
+\item{m}{number of mixtures.}
+
+\item{omega}{mixing weights.}
+
+\item{control}{A list of parameters for controlling the fitting process.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
 }
 \value{
-  \code{pmlMix} returns a list with elements
-  \item{logLik}{log-likelihood of the fit}
-  \item{omega}{mixing weights.} 
-  \item{fits}{fits for the final mixtures.}
+\code{pmlMix} returns a list with elements
+\item{logLik}{log-likelihood of the fit} \item{omega}{mixing weights.}
+\item{fits}{fits for the final mixtures.}
+}
+\description{
+Phylogenetic mixture model.
+}
+\details{
+The \code{formula} object allows to specify which parameter get optimized.
+The formula is generally of the form \code{edge + bf + Q ~ rate + shape +
+\dots{}}, on the left side are the parameters which get optimized over all
+mixtures, on the right the parameter which are optimized specific to each
+mixture. The parameters available are \code{"nni", "bf", "Q", "inv",
+"shape", "edge", "rate"}.  Each parameters can be used only once in the
+formula.  \code{"rate"} and \code{"nni"} are only available for the right
+side of the formula. On the other hand parameters for invariable sites are
+only allowed on the left-hand side.  The convergence of the algorithm is
+very slow and is likely that the algorithm can get stuck in local optima.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-
-\seealso{  \code{\link{pml}},\code{\link{pmlPart}},\code{\link{pmlCluster}} }
 \examples{
+
 \dontrun{
 X <- allSitePattern(5)
 tree <- read.tree(text = "((t1:0.3,t2:0.3):0.1,(t3:0.3,t4:0.3):0.1,t5:0.5);")
@@ -97,7 +98,12 @@ logLik(fit.p)
 AIC(fit.p, k=log(3000))
 }
 }
+
+}
+\seealso{
+\code{\link{pml}},\code{\link{pmlPart}},\code{\link{pmlCluster}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{ cluster }
+\keyword{cluster}
diff --git a/man/pmlPart.Rd b/man/pmlPart.Rd
index a03c7c0..616c7c6 100644
--- a/man/pmlPart.Rd
+++ b/man/pmlPart.Rd
@@ -1,54 +1,62 @@
-\name{pmlPart}
-\alias{pmlPart}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/pmlPart.R
+\name{multiphyDat2pmlPart}
+\alias{multiphyDat2pmlPart}
 \alias{pmlPart2multiPhylo}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{ Partition model. }
-\description{
-  Model to estimate phylogenies for partitioned data. 
-}
+\alias{pmlPart}
+\title{Partition model.}
 \usage{
-pmlPart(formula, object, control = pml.control(epsilon=1e-8, maxit=10, trace=1), 
-    model=NULL, rooted=FALSE, ...)
-pmlPart2multiPhylo(x)    
+multiphyDat2pmlPart(x, rooted = FALSE, ...)
+
+pmlPart2multiPhylo(x)
+
+pmlPart(formula, object, control = pml.control(epsilon = 1e-08, maxit = 10,
+  trace = 1), model = NULL, rooted = FALSE, ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-  \item{formula}{ a formula object (see details).}
-  \item{object}{ an object of class \code{pml} or a list of objects of class  \code{pml} . }
-  \item{control}{A list of parameters for controlling the fitting process.} 
-  \item{model}{A vector containing the models containing a model for each partition.} 
-  \item{rooted}{Are the gene trees rooted (ultrametric) or unrooted.} 
-  \item{\dots}{Further arguments passed to or from other methods. }
-  \item{x}{an object of class \code{pmlPart} }
-}
-\details{
-    The \code{formula} object allows to specify which parameter get     
-    optimized. The formula is generally of the form \code{edge + bf + Q 
-    ~ rate + shape + \dots}, on the left side are the parameters which 
-    get optimized over all partitions, on the right the parameter which
-    are optimized specific to each partition. The parameters available 
-    are \code{"nni", "bf", "Q", "inv", "shape", "edge", "rate"}.
-    Each parameters can be used only once in the formula. 
-    \code{"rate"} and \code{"nni"} are only available for the right side
-    of the formula.  
-    
-    For partitions with different edge weights, but same topology, \code{pmlPen}
-    can try to find more parsimonious models (see example). 
-    
-    \code{pmlPart2multiPhylo} is a convenience function to extract the trees 
-    out of a \code{pmlPart} object.
+\item{x}{an object of class \code{pmlPart}}
+
+\item{rooted}{Are the gene trees rooted (ultrametric) or unrooted.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+
+\item{formula}{a formula object (see details).}
+
+\item{object}{an object of class \code{pml} or a list of objects of class
+\code{pml} .}
+
+\item{control}{A list of parameters for controlling the fitting process.}
+
+\item{model}{A vector containing the models containing a model for each
+partition.}
 }
 \value{
-  \code{kcluster} returns a list with elements
-  \item{logLik}{log-likelihood of the fit}
-  \item{trees}{a list of all trees during the optimization.} 
-  \item{object}{an object of class \code{"pml"} or \code{"pmlPart"}}
+\code{kcluster} returns a list with elements
+\item{logLik}{log-likelihood of the fit} \item{trees}{a list of all trees
+during the optimization.} \item{object}{an object of class \code{"pml"} or
+\code{"pmlPart"}}
+}
+\description{
+Model to estimate phylogenies for partitioned data.
 }
-%\references{ ~put references to the literature/web site here ~ }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
+\details{
+The \code{formula} object allows to specify which parameter get optimized.
+The formula is generally of the form \code{edge + bf + Q ~ rate + shape +
+\dots{}}, on the left side are the parameters which get optimized over all
+partitions, on the right the parameter which are optimized specific to each
+partition. The parameters available are \code{"nni", "bf", "Q", "inv",
+"shape", "edge", "rate"}.  Each parameters can be used only once in the
+formula.  \code{"rate"} and \code{"nni"} are only available for the right
+side of the formula.
+
+For partitions with different edge weights, but same topology, \code{pmlPen}
+can try to find more parsimonious models (see example).
 
-\seealso{  \code{\link{pml}},\code{\link{pmlCluster}},\code{\link{pmlMix}},\code{\link{SH.test}} }
+\code{pmlPart2multiPhylo} is a convenience function to extract the trees out
+of a \code{pmlPart} object.
+}
 \examples{
+
 data(yeast)
 dm <- dist.logDet(yeast)
 tree <- NJ(dm)
@@ -68,6 +76,12 @@ AIC(sp2)
 sp3 <- pmlPen(sp2, lambda = 2) 
 AIC(sp3)
 }
+
+}
+\seealso{
+\code{\link{pml}},\code{\link{pmlCluster}},\code{\link{pmlMix}},\code{\link{SH.test}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-\keyword{ cluster }
-%\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
+\keyword{cluster}
diff --git a/man/read.aa.Rd b/man/read.aa.Rd
index d746371..39658c6 100644
--- a/man/read.aa.Rd
+++ b/man/read.aa.Rd
@@ -1,43 +1,52 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/phyDat.R
 \name{read.aa}
 \alias{read.aa}
 \title{Read Amino Acid Sequences in a File}
 \usage{
-read.aa(file, format = "interleaved", skip = 0,
-         nlines = 0, comment.char = "#", seq.names = NULL)
+read.aa(file, format = "interleaved", skip = 0, nlines = 0,
+  comment.char = "#", seq.names = NULL)
 }
 \arguments{
-  \item{file}{a file name specified by either a variable of mode character,
-    or a double-quoted string.}
-  \item{format}{a character string specifying the format of the DNA
-    sequences. Three choices are possible: \code{"interleaved"},
-    \code{"sequential"}, or \code{"fasta"}, or any unambiguous
-    abbreviation of these.}
-  \item{skip}{the number of lines of the input file to skip before
-    beginning to read data.}
-  \item{nlines}{the number of lines to be read (by default the file is
-    read until its end).}
-  \item{comment.char}{a single character, the remaining of the line
-    after this character is ignored.}
-  \item{seq.names}{the names to give to each sequence; by default the
-    names read in the file are used.}
+\item{file}{a file name specified by either a variable of mode character, or
+a double-quoted string.}
+
+\item{format}{a character string specifying the format of the DNA sequences.
+Three choices are possible: \code{"interleaved"}, \code{"sequential"}, or
+\code{"fasta"}, or any unambiguous abbreviation of these.}
+
+\item{skip}{the number of lines of the input file to skip before beginning
+to read data.}
+
+\item{nlines}{the number of lines to be read (by default the file is read
+until its end).}
+
+\item{comment.char}{a single character, the remaining of the line after this
+character is ignored.}
+
+\item{seq.names}{the names to give to each sequence; by default the names
+read in the file are used.}
 }
-\description{
-  This function reads amino acid sequences in a file, and returns a matrix 
-  list of DNA sequences with the names of the taxa read in the file as
-  row names.}
 \value{
-  a matrix of amino acid sequences.
+a matrix of amino acid sequences.
+}
+\description{
+This function reads amino acid sequences in a file, and returns a matrix
+list of DNA sequences with the names of the taxa read in the file as row
+names.
 }
 \references{
-%  Anonymous. FASTA format description.
-%  \url{http://www.ncbi.nlm.nih.gov/BLAST/fasta.html}
-  Felsenstein, J. (1993) Phylip (Phylogeny Inference Package) version
-  3.5c. Department of Genetics, University of Washington.
-  \url{http://evolution.genetics.washington.edu/phylip/phylip.html}
+% Anonymous. FASTA format description. %
+\url{https://www.ncbi.nlm.nih.gov/blast/fasta.shtml} Felsenstein, J. (1993)
+Phylip (Phylogeny Inference Package) version 3.5c. Department of Genetics,
+University of Washington.
+\url{http://evolution.genetics.washington.edu/phylip/phylip.html}
 }
 \seealso{
-  \code{\link[ape]{read.dna}}, \code{\link[ape]{read.GenBank}}, 
-  \code{\link[phangorn]{phyDat}}, \code{\link[seqinr]{read.alignment}}
+\code{\link[ape]{read.dna}}, \code{\link[ape]{read.GenBank}},
+\code{\link[phangorn]{phyDat}}, \code{\link[seqinr]{read.alignment}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
 \keyword{IO}
diff --git a/man/read.nexus.splits.Rd b/man/read.nexus.splits.Rd
new file mode 100644
index 0000000..016f6a3
--- /dev/null
+++ b/man/read.nexus.splits.Rd
@@ -0,0 +1,81 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/read.nexus.splits.R
+\name{read.nexus.splits}
+\alias{read.nexus.splits}
+\alias{write.nexus.splits}
+\alias{write.nexus.networx}
+\alias{read.nexus.networx}
+\alias{write.splits}
+\title{Function to import and export splits and networks}
+\usage{
+read.nexus.splits(file)
+
+write.nexus.splits(obj, file = "", weights = NULL, taxa = TRUE,
+  append = FALSE)
+
+write.nexus.networx(obj, file = "", taxa = TRUE, splits = TRUE,
+  append = FALSE)
+
+read.nexus.networx(file, splits = TRUE)
+
+write.splits(x, file = "", zero.print = ".", one.print = "|",
+  print.labels = TRUE, ...)
+}
+\arguments{
+\item{file}{a file name.}
+
+\item{obj}{An object of class splits.}
+
+\item{weights}{Edge weights.}
+
+\item{taxa}{logical. If TRUE a taxa block is added}
+
+\item{append}{logical. If TRUE the nexus blocks will be added to a file.}
+
+\item{splits}{logical. If TRUE the nexus blocks will be added to a file.}
+
+\item{x}{An object of class splits.}
+
+\item{zero.print}{character which should be printed for zeros.}
+
+\item{one.print}{character which should be printed for ones.}
+
+\item{print.labels}{logical. If TRUE labels are printed.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+
+\item{labels}{names of taxa.}
+}
+\value{
+\code{write.nexus.splits} and \code{write.nexus.networx} write out the  \code{splits} and \code{networx} object to read with
+other software like Splitstree.
+\code{read.nexus.splits} and \code{read.nexus.networx} return an \code{splits} and \code{networx} object.
+}
+\description{
+\code{read.nexus.splits}, \code{write.nexus.splits}, \code{read.nexus.networx}, \code{write.nexus.networx} 
+can be used to import and export splits and networks with nexus format
+and allow to exchange these object with other software like Splitstree. 
+\code{write.splits} returns a human readable output.
+}
+\note{
+\code{read.nexus.splits} reads in the splits block of a nexus file. It
+assumes that different co-variables are tab delimited and the bipartition
+are separated with white-space. Comments in square brackets are ignored.
+}
+\examples{
+
+(sp <- as.splits(rtree(5)))
+write.nexus.splits(sp)
+spl <- allCircularSplits(5)
+plot(as.networx(spl), "2D")
+write.splits(spl, print.labels = FALSE)
+
+}
+\seealso{
+\code{\link{prop.part}}, \code{\link{lento}},
+\code{\link{as.splits}}, \code{\link{as.networx}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/simSeq.Rd b/man/simSeq.Rd
index cf8de37..5ce092d 100644
--- a/man/simSeq.Rd
+++ b/man/simSeq.Rd
@@ -1,49 +1,63 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/simSeq.R
 \name{simSeq}
 \alias{simSeq}
 \alias{simSeq.phylo}
 \alias{simSeq.pml}
-\title{ Simulate sequences. }
-\description{
-Simulate sequences for a given evolutionary tree.
-}
+\title{Simulate sequences.}
 \usage{
 simSeq(x, ...)
-\method{simSeq}{phylo}(x, l=1000, Q=NULL, bf=NULL, rootseq=NULL, type="DNA",
-    model="", levels=NULL, rate=1, ancestral=FALSE, ...)
-\method{simSeq}{pml}(x, ancestral = FALSE, ...)    
+
+\method{simSeq}{phylo}(x, l = 1000, Q = NULL, bf = NULL, rootseq = NULL,
+  type = "DNA", model = NULL, levels = NULL, rate = 1,
+  ancestral = FALSE, ...)
+
+\method{simSeq}{pml}(x, ancestral = FALSE, ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-\item{x}{ a phylogenetic tree \code{tree}, i.e. an object of class \code{phylo} or and object of class \code{pml}. }
-\item{l}{  length of the sequence to simulate. }
-\item{Q}{ the rate matrix.  }
-\item{bf}{ base frequencies. }
-\item{rootseq}{a vector of length l containing the root sequence, 
-other root sequence is randomly generated.}
+\item{x}{a phylogenetic tree \code{tree}, i.e. an object of class
+\code{phylo} or and object of class \code{pml}.}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+
+\item{l}{length of the sequence to simulate.}
+
+\item{Q}{the rate matrix.}
+
+\item{bf}{base frequencies.}
+
+\item{rootseq}{a vector of length l containing the root sequence, other root
+sequence is randomly generated.}
+
 \item{type}{Type of sequences ("DNA", "AA" or "USER").}
-\item{model}{Amino acid models: one of "WAG", "JTT", "Dayhoff" or "LG"}
-\item{levels}{ \code{levels} takes a character vector of the different bases,
+
+\item{model}{Amino acid models: e.g. "WAG", "JTT", "Dayhoff" or "LG"}
+
+\item{levels}{\code{levels} takes a character vector of the different bases,
 default is for nucleotide sequences, only used when type = "USER".}
-\item{rate}{mutation rate or scaler for the edge length, 
-a numerical value greater than zero. }
+
+\item{rate}{mutation rate or scaler for the edge length, a numerical value
+greater than zero.}
+
 \item{ancestral}{Return ancestral sequences?}
-\item{\dots}{Further arguments passed to or from other methods.}
-}
-\details{
-\code{simSeq} is now a generic function to simulate sequence alignments. 
-It is quite flexible and allows to generate DNA, RNA, amino acids or binary sequences. 
-It is possible to give a \code{pml} object as input simSeq return a \code{phyDat}
-from these model. 
-There is also a more low level version, which lacks rate variation, but one can combine different alignments having their own rate (see example). The rate parameter acts like a scaler for the edge lengths.  
 }
 \value{
 \code{simSeq} returns an object of class phyDat.
 }
-\author{ Klaus Schliep \email{klaus.schliep at gmail.com}}
-
-\seealso{  \code{\link{phyDat}}, \code{\link{pml}},  \code{\link{SOWH.test}}  
+\description{
+Simulate sequences for a given evolutionary tree.
+}
+\details{
+\code{simSeq} is now a generic function to simulate sequence alignments.  It
+is quite flexible and allows to generate DNA, RNA, amino acids or binary
+sequences.  It is possible to give a \code{pml} object as input simSeq
+return a \code{phyDat} from these model.  There is also a more low level
+version, which lacks rate variation, but one can combine different
+alignments having their own rate (see example). The rate parameter acts like
+a scaler for the edge lengths.
 }
 \examples{
+
 \dontrun{
 data(Laurasiatherian)
 tree = nj(dist.ml(Laurasiatherian))
@@ -70,6 +84,12 @@ data <- c(data1,data2, data3, data4)
 
 write.phyDat(data, file="temp.dat", format="sequential",nbcol = -1, colsep = "")
 unlink("temp.dat") 
-}
-\keyword{ cluster }% at least one, from doc/KEYWORDS
 
+}
+\seealso{
+\code{\link{phyDat}}, \code{\link{pml}}, \code{\link{SOWH.test}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/splitsNetwork.Rd b/man/splitsNetwork.Rd
index 979eca8..dc7fa0c 100644
--- a/man/splitsNetwork.Rd
+++ b/man/splitsNetwork.Rd
@@ -1,56 +1,66 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/networx.R
 \name{splitsNetwork}
-
 \alias{splitsNetwork}
 \title{Phylogenetic Network}
-\description{
-\code{splitsNetwork} estimates weights for a splits graph from a distance matrix.
-}
 \usage{
-splitsNetwork(dm, splits=NULL, gamma=.1, lambda=1e-6, weight=NULL)
+splitsNetwork(dm, splits = NULL, gamma = 0.1, lambda = 1e-06,
+  weight = NULL)
 }
 \arguments{
-  \item{dm}{A distance matrix.}
-  \item{splits}{a splits object, containing all splits to consider, 
-   otherwise all possible splits are used}
-  \item{gamma}{penalty value for the L1 constraint.}
-  \item{lambda}{penalty value for the L2 constraint.}
-  \item{weight}{a vector of weights.}
-}
+\item{dm}{A distance matrix.}
 
-\details{
-\code{splitsNetwork} fits non-negative least-squares phylogenetic networks using L1 (LASSO), L2(ridge regression) constraints.  
-The function minimizes the penalized least squares
-\deqn{\beta = min \sum(dm - X\beta)^2 + \lambda \|\beta \|^2_2 }{%
-beta = sum(dm - X*beta)^2 + lambda |beta|^2_2 }
-with respect to \deqn{\|\beta \|_1 <= \gamma, \beta >= 0}{%
-|beta|_1 = gamma, beta >= 0}
-where X is a design matrix constructed with \code{designSplits}. 
-External edges are fitted without L1 or L2 constraints. 
+\item{splits}{a splits object, containing all splits to consider, otherwise
+all possible splits are used}
+
+\item{gamma}{penalty value for the L1 constraint.}
+
+\item{lambda}{penalty value for the L2 constraint.}
+
+\item{weight}{a vector of weights.}
 }
 \value{
-\code{splitsNetwork} returns a splits object with a matrix added. 
-The first column contains the indices of the splits, the second 
-column an unconstrained fit without penalty terms and the third 
-column the constrained fit.
+\code{splitsNetwork} returns a splits object with a matrix added.
+The first column contains the indices of the splits, the second column an
+unconstrained fit without penalty terms and the third column the constrained
+fit.
 }
-\references{
-Efron, Hastie, Johnstone and Tibshirani (2003) "Least Angle Regression" (with discussion) Annals of Statistics
-
-K. P. Schliep (2009). Some Applications of statistical phylogenetics (PhD Thesis)
+\description{
+\code{splitsNetwork} estimates weights for a splits graph from a distance
+matrix.
 }
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-\seealso{\code{\link[phangorn]{distanceHadamard}}, \code{\link[phangorn]{designTree}}
-\code{\link[phangorn]{consensusNet}}, \code{\link[phangorn]{plot.networx}}  
+\details{
+\code{splitsNetwork} fits non-negative least-squares phylogenetic networks
+using L1 (LASSO), L2(ridge regression) constraints.  The function minimizes
+the penalized least squares 
+\deqn{\beta = min \sum(dm - X\beta)^2 + \lambda \|\beta \|^2_2 }{ beta = sum(dm - X*beta)^2 + lambda |beta|^2_2 } 
+with respect to \deqn{\|\beta \|_1 <= \gamma, \beta >= 0}{ |beta|_1 = gamma, beta >= 0} 
+where \eqn{X} is a design matrix constructed with \code{designSplits}.
+External edges are fitted without L1 or L2 constraints.
 }
-
 \examples{
+
 data(yeast)
 dm = dist.ml(yeast)
 fit = splitsNetwork(dm)
 net = as.networx(fit)
 plot(net, "2D")
 write.nexus.splits(fit)
-}
-\keyword{ cluster }% at least one, from doc/KEYWORDS
 
+}
+\references{
+Efron, Hastie, Johnstone and Tibshirani (2004) Least Angle
+Regression (with discussion) \emph{Annals of Statistics} \bold{32(2)}, 407--499
 
+K. P. Schliep (2009). Some Applications of statistical phylogenetics (PhD
+Thesis)
+}
+\seealso{
+\code{\link[phangorn]{distanceHadamard}},
+\code{\link[phangorn]{designTree}} \code{\link[phangorn]{consensusNet}},
+\code{\link[phangorn]{plot.networx}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/superTree.Rd b/man/superTree.Rd
index 293b279..c2dda2d 100644
--- a/man/superTree.Rd
+++ b/man/superTree.Rd
@@ -1,67 +1,40 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/superTree.R
 \name{superTree}
 \alias{superTree}
-\alias{coalSpeciesTree}
-%- Also NEED an '\alias' for EACH other topic documented here.
-\title{
-Super Tree and Species Tree methods
-}
-\description{
-These function \code{superTree} allows the estimation of a supertree from a set of trees using either Matrix representation parsimony, Robinson-Foulds or SPR as criterion.  \code{coalSpeciesTree} estimates species trees and can multiple individuals per species.}
+\title{Super Tree methods}
 \usage{
-superTree(tree, method = "MRP", rooted=FALSE, trace=0, ...)
-coalSpeciesTree(tree, X, sTree = NULL)
+superTree(tree, method = "MRP", rooted = FALSE, trace = 0, ...)
 }
-%- maybe also 'usage' for other objects documented here.
 \arguments{
-\item{tree}{
-an object of class \code{multiPhylo}
-}
-\item{method}{
-An argument defining which algorithm is used to optimize the tree. 
-Possible are "MRP", "NNI", and "SPR". 
-}
-\item{rooted}{
-should the resulting supertrees be rooted.
-}
-\item{X}{
-A \code{phyDat} object to define which individual belongs to which species. 
-} 
-\item{trace}{
-defines how much information is printed during optimization.
-}
-\item{sTree}{
-A species tree which forces the topology. 
-} 
-\item{\dots}{
-further arguments passed to or from other methods.
-}
-}
-\details{
-The function \code{superTree} extends the function mrp.supertree from Liam Revells, 
-with artificial adding an outgroup on the root of the trees. 
-This allows to root the supertree afterwards. The functions is internally used in DensiTree. The implementation for the RF- and SPR-supertree are very basic so far and assume that all trees share the same set of taxa.  
+\item{tree}{an object of class \code{multiPhylo}}
 
-\code{coalSpeciesTree} estimates a single linkage tree as suggested by Liu et al. (2010) from the element wise minima of the cophenetic matrices of the gene trees. It extends \code{speciesTree} in ape as it allows that have several individuals per gene tree.  
-}
-\value{
-The function returns an object of class \code{phylo}. 
-}
-\references{
-Liu, L., Yu, L. and Pearl, D. K. (2010) Maximum tree: a consistent estimator of the species tree. \emph{Journal of Mathematical Biology}, \bold{60}, 95--106.
+\item{method}{An argument defining which algorithm is used to optimize the
+tree.  Possible are "MRP", "NNI", and "SPR".}
+
+\item{rooted}{should the resulting supertrees be rooted.}
 
+\item{trace}{defines how much information is printed during optimization.}
 
+\item{\dots}{further arguments passed to or from other methods.}
 }
-\author{
-Klaus Schliep \email{klaus.schliep at gmail.com}
-Liam Revell 
-Emmanuel Paradies
+\value{
+The function returns an object of class \code{phylo}.
 }
-%% ~Make other sections like Warning with \section{Warning }{....} ~
-
-\seealso{
-\code{mrp.supertree},  \code{\link{speciesTree}}, \code{\link{densiTree}}, \code{\link{RF.dist}}, \code{\link{SPR.dist}}
+\description{
+These function \code{superTree} allows the estimation of a supertree from a
+set of trees using either Matrix representation parsimony, Robinson-Foulds
+or SPR as criterion.
+}
+\details{
+The function \code{superTree} extends the function mrp.supertree from Liam
+Revells, with artificial adding an outgroup on the root of the trees.  This
+allows to root the supertree afterwards. The functions is internally used in
+DensiTree. The implementation for the RF- and SPR-supertree are very basic
+so far and assume that all trees share the same set of taxa.
 }
 \examples{
+
 data(Laurasiatherian)
 set.seed(1)
 bs <- bootstrap.phyDat(Laurasiatherian, FUN = function(x)upgma(dist.hamming(x)), bs=50)
@@ -73,8 +46,21 @@ plot(superTree(mrp_st))
 rf_st <- superTree(bs, method = "RF")
 spr_st <- superTree(bs, method = "SPR")
 }
+
 }
-% Add one or more standard keywords, see file 'KEYWORDS' in the
-% R documentation directory.
-\keyword{cluster}
+\references{
+Baum, B. R., (1992) Combining trees as a way of combining data
+sets for phylogenetic inference, and the desirability of combining gene
+trees. \emph{Taxon}, \bold{41}, 3-10.
 
+Ragan, M. A. (1992) Phylogenetic inference based on matrix representation of
+trees. \emph{Molecular Phylogenetics and Evolution}, \bold{1}, 53-58.
+}
+\seealso{
+\code{mrp.supertree}, \code{\link{densiTree}},
+\code{\link{RF.dist}}, \code{\link{SPR.dist}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com} Liam Revell
+}
+\keyword{cluster}
diff --git a/man/treedist.Rd b/man/treedist.Rd
index b36fe09..d55a1c7 100644
--- a/man/treedist.Rd
+++ b/man/treedist.Rd
@@ -1,89 +1,84 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/treedist.R
 \name{treedist}
 \alias{treedist}
+\alias{sprdist}
+\alias{SPR.dist}
 \alias{RF.dist}
 \alias{wRF.dist}
 \alias{KF.dist}
 \alias{path.dist}
-\alias{sprdist}
-\alias{SPR.dist}
-%\alias{print.treedist}
-\title{ Distances between trees }
-\description{
-  \code{treedist} computes different tree distance methods and \code{RF.dist} the Robinson-Foulds or symmetric distance. 
-}
+\title{Distances between trees}
 \usage{
 treedist(tree1, tree2, check.labels = TRUE)
-sprdist(tree1, tree2)
-RF.dist(tree1, tree2=NULL, normalize=FALSE, check.labels=TRUE, rooted=FALSE)
-wRF.dist(tree1, tree2=NULL, normalize=FALSE, check.labels=TRUE, rooted=FALSE)
-KF.dist(tree1, tree2=NULL, check.labels=TRUE, rooted=FALSE)
-SPR.dist(tree1, tree2=NULL)
-path.dist(tree1, tree2=NULL, check.labels=TRUE, use.weight=FALSE)
-}
-\arguments{
-  \item{tree1}{ A phylogenetic tree (class \code{phylo})
-  or vector of trees (an object of class \code{multiPhylo}). See details }
-  \item{tree2}{ A phylogenetic tree. }
-  \item{normalize}{compute normalized RF-distance, see details. }
-  \item{check.labels}{compares labels of the trees.}
-  \item{rooted}{take bipartitions for rooted trees into account, default is unrooting the trees.}
-  \item{use.weight}{use edge.length argument or just count number of edges on the path (default)}
-}
-\value{
-  \code{treedist} returns a vector containing the following tree distance methods
-  \item{symmetric.difference}{symmetric.difference or  Robinson-Foulds distance}
-  \item{branch.score.difference}{branch.score.difference}
-  \item{path.difference}{path.difference}
-  \item{weighted.path.difference}{weighted.path.difference}
-}
-\details{
-The Robinson-Foulds distance between two trees \eqn{T_1} and \eqn{T_2} with \eqn{n} tips is defined as (following the notation Steel & Penny 1993): 
-\deqn{d(T_1, T_2) = i(T_1) + i(T_2) - 2v_s(T_1, T_2)}
-where \eqn{i(T_1)} denotes the number of internal edges and \eqn{v_s(T_1, T_2)} denotes the number of internal splits shared by the two trees. The normalized Robinson-Foulds distance is derived by dividing \eqn{d(T_1, T_2)} by the maximal possible distance \eqn{i(T_1) + i(T_2)}. If both trees are unrooted and binary this value is \eqn{2n-6}. 
 
-% The weighted Robinson-Foulds distance makes use of edge weights. Let \eqn{E_1} and \eqn{E_2} the set of edges of \eqn{d(T_1, T_2)} and \eqn{w(e), e \in E_1} the weight of an edge in \eqn{E_1}
-%\deqn{d(T_1, T_2) = \sum_{e \in E \setminus E_1}w(e) + \sum_{e \in E_1\cap E_2}|w(e_1) - w(e_2) + \sum_{e \in E\setminus E_2}w(e) }
-% where \eqn{E = E_1\cup E_2}
-
-%The Kuhner-Felsenstein difference (Kuhner & Felsenstein 1994) is closely related with the weighted Robinson-Foulds distance. 
+sprdist(tree1, tree2)
 
-%Instead of the absolute values between edges are squared 
-% 0-norm RF
-% 1-norm wRF
-% 2-norm KF 
- 
-\code{RF.dist} returns the Robinson-Foulds distance (Robinson & Foulds 1981) between either 2 trees or computes a matrix of all pairwise distances if a \code{multiPhylo} object is given. The Robinson-Foulds distance only depends on the toplogy of the trees. 
-If edge weights should be considered \code{wRF.dist} calculates the weighted RF distance (Robinson & Foulds 1981). and \code{KF.dist} calculates the branch score distance (Kuhner & Felsenstein 1994). 
-\code{path.dist} computes the path difference metric as described in Steel and Penny 1993).
+SPR.dist(tree1, tree2 = NULL)
 
-\code{sprdist} computes the approximate SPR distance (Oliveira Martins et al. 2008, de Oliveira Martins 2016).
+RF.dist(tree1, tree2 = NULL, normalize = FALSE, check.labels = TRUE,
+  rooted = FALSE)
 
-For large number of trees the distance functions can use a lot of memory!
+wRF.dist(tree1, tree2 = NULL, normalize = FALSE, check.labels = TRUE,
+  rooted = FALSE)
 
-% The function used internally is 2 * (nt - m) where nt is the number of tips and 
-% m is the number of shared bipartitions. When there are multifurcations the 
-% distance is therefore increasing!! This may be different to other implementations!
+KF.dist(tree1, tree2 = NULL, check.labels = TRUE, rooted = FALSE)
 
+path.dist(tree1, tree2 = NULL, check.labels = TRUE, use.weight = FALSE)
 }
-\references{
-de Oliveira Martins L., Leal E., Kishino H. (2008) \emph{Phylogenetic Detection of Recombination with a Bayesian Prior on the Distance between Trees}. PLoS ONE \bold{3(7)}. e2651. doi: 10.1371/journal.pone.0002651 
+\arguments{
+\item{tree1}{A phylogenetic tree (class \code{phylo}) or vector of trees (an
+object of class \code{multiPhylo}). See details}
 
-de Oliveira Martins L., Mallo D., Posada D. (2016) \emph{A Bayesian Supertree Model for Genome-Wide Species Tree Reconstruction}. Syst. Biol.  \bold{65(3)}: 397-416, doi:10.1093/sysbio/syu082 
+\item{tree2}{A phylogenetic tree.}
 
-Steel M. A. and Penny P. (1993) \emph{Distributions of tree comparison metrics - some new results}, Syst. Biol., \bold{42(2)}, 126--141
+\item{check.labels}{compares labels of the trees.}
 
-Kuhner, M. K. and Felsenstein, J. (1994) \emph{A simulation comparison of phylogeny algorithms under equal and unequal evolutionary rates}, Molecular Biology and Evolution, \bold{11(3)}, 459--468
+\item{normalize}{compute normalized RF-distance, see details.}
 
-D.F. Robinson and L.R. Foulds (1981) \emph{Comparison of phylogenetic trees}, Mathematical Biosciences, \bold{53(1)}, 131--147
+\item{rooted}{take bipartitions for rooted trees into account, default is
+unrooting the trees.}
 
-D.F. Robinson and L.R. Foulds (1979) Comparison of weighted labelled trees. In Horadam, A. F. and Wallis, W. D. (Eds.), \emph{Combinatorial Mathematics VI: Proceedings of the Sixth Australian Conference on Combinatorial Mathematics, Armidale, Australia}, 119--126
+\item{use.weight}{use edge.length argument or just count number of edges on
+the path (default)}
+}
+\value{
+\code{treedist} returns a vector containing the following tree
+distance methods \item{symmetric.difference}{symmetric.difference or
+Robinson-Foulds distance}
+\item{branch.score.difference}{branch.score.difference}
+\item{path.difference}{path.difference}
+\item{weighted.path.difference}{weighted.path.difference}
 }
-\author{ Klaus P. Schliep \email{klaus.schliep at gmail.com}, 
+\description{
+\code{treedist} computes different tree distance methods and \code{RF.dist}
+the Robinson-Foulds or symmetric distance. The Robinson-Foulds distance only 
+depends on the toplogy of the trees. If edge weights should be considered
+\code{wRF.dist} calculates the weighted RF distance (Robinson & Foulds
+1981). and \code{KF.dist} calculates the branch score distance (Kuhner &
+Felsenstein 1994).  \code{path.dist} computes the path difference metric as
+described in Steel and Penny 1993).
+\code{sprdist} computes the approximate SPR distance (Oliveira Martins et
+al. 2008, de Oliveira Martins 2016).
+}
+\details{
+The Robinson-Foulds distance between two trees \eqn{T_1} and \eqn{T_2} with
+\eqn{n} tips is defined as (following the notation Steel and Penny 1993):
+\deqn{d(T_1, T_2) = i(T_1) + i(T_2) - 2v_s(T_1, T_2)} where \eqn{i(T_1)}
+denotes the number of internal edges and \eqn{v_s(T_1, T_2)} denotes the
+number of internal splits shared by the two trees. The normalized
+Robinson-Foulds distance is derived by dividing \eqn{d(T_1, T_2)} by the
+maximal possible distance \eqn{i(T_1) + i(T_2)}. If both trees are unrooted
+and binary this value is \eqn{2n-6}.
 
-Leonardo de Oliveira Martins
-} 
-\seealso{\code{\link[ape]{dist.topo}}, \code{\link{nni}}, \code{\link{superTree}}}
+Functions like \code{RF.dist} returns the Robinson-Foulds distance (Robinson and Foulds 1981)
+between either 2 trees or computes a matrix of all pairwise distances if a
+\code{multiPhylo} object is given. 
+
+For large number of trees the distance functions can use a lot of memory!
+}
 \examples{
+
 tree1 <- rtree(100, rooted=FALSE)
 tree2 <- rSPR(tree1, 3)
 RF.dist(tree1, tree2)
@@ -91,5 +86,39 @@ treedist(tree1, tree2)
 sprdist(tree1, tree2)
 trees <- rSPR(tree1, 1:5)
 SPR.dist(tree1, trees)
+
+}
+\references{
+de Oliveira Martins L., Leal E., Kishino H. (2008)
+\emph{Phylogenetic Detection of Recombination with a Bayesian Prior on the
+Distance between Trees}. PLoS ONE \bold{3(7)}. e2651. doi:
+10.1371/journal.pone.0002651
+
+de Oliveira Martins L., Mallo D., Posada D. (2016) \emph{A Bayesian
+Supertree Model for Genome-Wide Species Tree Reconstruction}. Syst. Biol.
+\bold{65(3)}: 397-416, doi:10.1093/sysbio/syu082
+
+Steel M. A. and Penny P. (1993) \emph{Distributions of tree comparison
+metrics - some new results}, Syst. Biol., \bold{42(2)}, 126--141
+
+Kuhner, M. K. and Felsenstein, J. (1994) \emph{A simulation comparison of
+phylogeny algorithms under equal and unequal evolutionary rates}, Molecular
+Biology and Evolution, \bold{11(3)}, 459--468
+
+D.F. Robinson and L.R. Foulds (1981) \emph{Comparison of phylogenetic
+trees}, Mathematical Biosciences, \bold{53(1)}, 131--147
+
+D.F. Robinson and L.R. Foulds (1979) Comparison of weighted labelled trees.
+In Horadam, A. F. and Wallis, W. D. (Eds.), \emph{Combinatorial Mathematics
+VI: Proceedings of the Sixth Australian Conference on Combinatorial
+Mathematics, Armidale, Australia}, 119--126
+}
+\seealso{
+\code{\link[ape]{dist.topo}}, \code{\link{nni}},
+\code{\link{superTree}}
+}
+\author{
+Klaus P. Schliep \email{klaus.schliep at gmail.com},
+Leonardo de Oliveira Martins
 }
-\keyword{ classif }% at least one, from doc/KEYWORDS
+\keyword{classif}
diff --git a/man/upgma.Rd b/man/upgma.Rd
index 837d251..6235c19 100644
--- a/man/upgma.Rd
+++ b/man/upgma.Rd
@@ -1,30 +1,43 @@
-\name{upgma}
-\alias{upgma}
-\alias{wpgma}
-\title{ UPGMA and WPGMA }
-\description{
-  UPGMA and WPGMA clustering. Just a wrapper function around \code{\link[stats]{hclust}}.
-}
-\usage{
-upgma(D, method = "average", ...)
-wpgma(D, method = "mcquitty", ...)
-}
-\arguments{
-  \item{D}{A distance matrix.}
-  \item{method}{The agglomeration method to be used. This should be (an unambiguous abbreviation of) one of "ward", "single", "complete", "average", "mcquitty", "median" or "centroid". The default is "average".}
-  \item{\dots}{Further arguments passed to or from other methods.}
-}
-
-\value{
-A phylogenetic tree of class \code{phylo}. 
-}
-\author{Klaus Schliep \email{klaus.schliep at gmail.com}}
-
-\seealso{ \code{\link{hclust}}, \code{\link{dist.hamming}}, \code{\link{NJ}}, \code{\link{as.phylo}}, \code{\link{fastme}}, \code{\link{nnls.tree}} }
-\examples{
-data(Laurasiatherian)
-dm = dist.ml(Laurasiatherian)
-tree = upgma(dm)
-plot(tree)
-}
-\keyword{cluster}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/distTree.R
+\name{upgma}
+\alias{upgma}
+\alias{wpgma}
+\title{UPGMA and WPGMA}
+\usage{
+upgma(D, method = "average", ...)
+
+wpgma(D, method = "mcquitty", ...)
+}
+\arguments{
+\item{D}{A distance matrix.}
+
+\item{method}{The agglomeration method to be used. This should be (an
+unambiguous abbreviation of) one of "ward", "single", "complete", "average",
+"mcquitty", "median" or "centroid". The default is "average".}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+}
+\value{
+A phylogenetic tree of class \code{phylo}.
+}
+\description{
+UPGMA and WPGMA clustering. Just a wrapper function around
+\code{\link[stats]{hclust}}.
+}
+\examples{
+
+data(Laurasiatherian)
+dm = dist.ml(Laurasiatherian)
+tree = upgma(dm)
+plot(tree)
+
+}
+\seealso{
+\code{\link{hclust}}, \code{\link{dist.hamming}}, \code{\link{NJ}},
+\code{\link{as.phylo}}, \code{\link{fastme}}, \code{\link{nnls.tree}}
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/writeDist.Rd b/man/writeDist.Rd
new file mode 100644
index 0000000..145e6db
--- /dev/null
+++ b/man/writeDist.Rd
@@ -0,0 +1,65 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/distSeq.R
+\name{writeDist}
+\alias{writeDist}
+\alias{write.nexus.dist}
+\alias{readDist}
+\title{Writing and reading distances in phylip and nexus format}
+\usage{
+writeDist(x, file = "", format = "phylip", ...)
+
+write.nexus.dist(x, file = "", append = FALSE, upper = FALSE,
+  diag = TRUE, digits = getOption("digits"), taxa = !append)
+
+readDist(file)
+}
+\arguments{
+\item{x}{A \code{dist} object.}
+
+\item{file}{A file name.}
+
+\item{format}{file format, default is "phylip", only other option so far is "nexus".}
+
+\item{\dots}{Further arguments passed to or from other methods.}
+
+\item{append}{logical. If TRUE the nexus blocks will be added to a file.}
+
+\item{upper}{logical value indicating whether the upper triangle of the distance 
+matrix should be printed.}
+
+\item{diag}{logical value indicating whether the diagonal of the distance matrix 
+should be printed.}
+
+\item{digits}{passed to format inside of \code{write.nexus.dist}.}
+
+\item{taxa}{logical. If TRUE a taxa block is added.}
+}
+\value{
+an object of class \code{dist}
+}
+\description{
+\code{readDist}, \code{writeDist} and \code{write.nexus.dist} are useful to 
+exchange distance matrices with other phylogenetic programs.
+}
+\examples{
+
+data(yeast)
+dm <- dist.ml(yeast)
+writeDist(dm)
+write.nexus.dist(dm)
+
+}
+\references{
+Maddison, D. R., Swofford, D. L. and Maddison, W. P. (1997) 
+NEXUS: an extensible file format for systematic information. 
+\emph{Systematic Biology}, \bold{46}, 590--621.
+}
+\seealso{
+To compute distance matrices see \code{\link{dist.ml}}
+\code{\link[ape]{dist.dna}} and \code{\link{dist.p}} for pairwise
+polymorphism p-distances
+}
+\author{
+Klaus Schliep \email{klaus.schliep at gmail.com}
+}
+\keyword{cluster}
diff --git a/man/yeast.Rd b/man/yeast.Rd
index ffb49ec..27d2da9 100644
--- a/man/yeast.Rd
+++ b/man/yeast.Rd
@@ -1,19 +1,21 @@
-\name{yeast}
-\alias{yeast}
-\docType{data}
-\title{ Yeast alignment (Rokas et al.) }
-\description{
-Alignment of 106 genes of 8 different species of yeast.}
-\usage{data(yeast)}
-
-\references{
-Rokas, A., Williams, B. L., King, N., and Carroll, S. B. (2003)
-Genome-scale approaches to resolving incongruence in molecular phylogenies.
-\emph{Nature}, \bold{425}(6960): 798--804
-}    
-
-\examples{
-data(yeast)
-str(yeast)
-}
-\keyword{datasets}
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/phangorn-package.R
+\docType{data}
+\name{yeast}
+\alias{yeast}
+\title{Yeast alignment (Rokas et al.)}
+\description{
+Alignment of 106 genes of 8 different species of yeast.
+}
+\examples{
+
+data(yeast)
+str(yeast)
+
+}
+\references{
+Rokas, A., Williams, B. L., King, N., and Carroll, S. B. (2003)
+Genome-scale approaches to resolving incongruence in molecular phylogenies.
+\emph{Nature}, \bold{425}(6960): 798--804
+}
+\keyword{datasets}
diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp
index c4efb1d..a3fc19a 100644
--- a/src/RcppExports.cpp
+++ b/src/RcppExports.cpp
@@ -17,6 +17,30 @@ BEGIN_RCPP
     return rcpp_result_gen;
 END_RCPP
 }
+// bipartCPP
+List bipartCPP(IntegerMatrix orig, int nTips);
+RcppExport SEXP phangorn_bipartCPP(SEXP origSEXP, SEXP nTipsSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< IntegerMatrix >::type orig(origSEXP);
+    Rcpp::traits::input_parameter< int >::type nTips(nTipsSEXP);
+    rcpp_result_gen = Rcpp::wrap(bipartCPP(orig, nTips));
+    return rcpp_result_gen;
+END_RCPP
+}
+// bipCPP
+List bipCPP(IntegerMatrix orig, int nTips);
+RcppExport SEXP phangorn_bipCPP(SEXP origSEXP, SEXP nTipsSEXP) {
+BEGIN_RCPP
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
+    Rcpp::traits::input_parameter< IntegerMatrix >::type orig(origSEXP);
+    Rcpp::traits::input_parameter< int >::type nTips(nTipsSEXP);
+    rcpp_result_gen = Rcpp::wrap(bipCPP(orig, nTips));
+    return rcpp_result_gen;
+END_RCPP
+}
 // allChildrenCPP
 List allChildrenCPP(IntegerMatrix orig);
 RcppExport SEXP phangorn_allChildrenCPP(SEXP origSEXP) {
diff --git a/src/dist.c b/src/dist.c
index 0217938..19179cc 100644
--- a/src/dist.c
+++ b/src/dist.c
@@ -1,7 +1,7 @@
 /* 
  * dist.c
  *
- * (c) 2008-2016 Klaus Schliep (klaus.schliep at gmail.com)
+ * (c) 2008-2017 Klaus Schliep (klaus.schliep at gmail.com)
  * 
  * 
  * This code may be distributed under the GNU GPL
diff --git a/src/fitch.c b/src/fitch.c
index 5dac621..f47f38b 100644
--- a/src/fitch.c
+++ b/src/fitch.c
@@ -90,7 +90,7 @@ SEXP AddOnes(SEXP edge, SEXP tip, SEXP ind, SEXP l, SEXP m){
     UNPROTECT(1);
     return(res);
 }
-
+ 
 
 void fitch43(int *dat1, int *dat2, int *nr, int *pars, double *weight, double *w){
     int k, tmp;
@@ -120,9 +120,9 @@ void fitch44(int *res, int *dat1, int *dat2, int *nr, int *pars, double *weight,
 }
 
 
-void fitch53(int *dat1, int *dat2, int *nr, double *weight, double *w){
+void fitch53(int *dat1, int *dat2, int nr, double *weight, double *w){
     int k, tmp;
-    for(k = 0; k < (*nr); k++){
+    for(k = 0; k < nr; k++){
         tmp = dat1[k] & dat2[k];
         if(!tmp){
             tmp = dat1[k] | dat2[k];
@@ -133,9 +133,9 @@ void fitch53(int *dat1, int *dat2, int *nr, double *weight, double *w){
 }
 
 
-void fitch54(int *res, int *dat1, int *dat2, int *nr, double *weight, double *w){
+void fitch54(int *res, int *dat1, int *dat2, int nr, double *weight, double *w){
     int k, tmp;
-    for(k = 0; k < (*nr); k++){
+    for(k = 0; k < nr; k++){
         tmp = dat1[k] & dat2[k];
         if(!tmp){
             tmp = dat1[k] | dat2[k];
@@ -145,9 +145,6 @@ void fitch54(int *res, int *dat1, int *dat2, int *nr, double *weight, double *w)
     } 
 }
 
-// FNALL5(SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP mx, SEXP my, SEXP root) 
-// nrx, edge,   score (result von FNALL5) 
-// root berechnen
 SEXP FITCHTRIP3(SEXP DAT3, SEXP nrx, SEXP edge, SEXP score, SEXP PS){ 
     R_len_t i, m = length(edge);  
     int nr=INTEGER(nrx)[0], k, tmp, ei, *edges=INTEGER(edge); 
@@ -160,7 +157,7 @@ SEXP FITCHTRIP3(SEXP DAT3, SEXP nrx, SEXP edge, SEXP score, SEXP PS){
     for(i=0; i<m; i++) pvtmp[i] = REAL(score)[i]; 
     for(i=0; i<m; i++){
         ei = edges[i] - 1L;
-//      pvtmp[i] = REAL(score)[ei]; -1L
+//      pvtmp[i] = REAL(score)[ei]; ???
         for(k = 0; k < nr; k++){
             tmp = data1[k + ei*nr] & data2[k + ei*nr];
             if(!tmp){
@@ -183,16 +180,14 @@ SEXP FITCHTRIP3(SEXP DAT3, SEXP nrx, SEXP edge, SEXP score, SEXP PS){
 
 void fitch8(int *dat, int *nr, int *pars, int *node, int *edge, int *nl, double *weight, double *pvec, double *pscore) 
 {   
-    int i, ni=0L, ri, le;
-    i=0L;
+    int i=0L, ni=0L, ri, le;
     while(i<(*nl - 1L)){
         ni = node[i] - 1L; 
         le = edge[i] - 1L;
         ri = edge[i+1] - 1L; 
         pvec[ni] = pvec[le] + pvec[ri];
-	fitch44(&dat[ni * (*nr)], &dat[le * (*nr)], &dat[ri * (*nr)], nr, pars, weight, &pvec[ni]); 
-        i++;
-        i++;                  
+	    fitch44(&dat[ni * (*nr)], &dat[le * (*nr)], &dat[ri * (*nr)], nr, pars, weight, &pvec[ni]); 
+        i+=2;
     }
     if(i == (*nl-1L)){
         le = edge[i] - 1L;
@@ -203,28 +198,28 @@ void fitch8(int *dat, int *nr, int *pars, int *node, int *edge, int *nl, double
 }
 
 
-void fitch9(int *dat, int *nr, int *node, int *edge, int *nl, double *weight, double *pvec, double *pscore) 
+void fitch9(int *dat, int nr, int *node, int *edge, int nl, double *weight, double *pvec, double *pscore) 
 {   
-    int i, ni=0L, ri, le;
-    i=0L;
-    while(i<(*nl - 1L)){
+    int i=0L, ni=0L, ri, le;
+    while(i<(nl - 1L)){
         ni = node[i] - 1L; 
         le = edge[i] - 1L;
         ri = edge[i+1] - 1L; 
         pvec[ni] = pvec[le] + pvec[ri];
-	fitch54(&dat[ni * (*nr)], &dat[le * (*nr)], &dat[ri * (*nr)], nr, weight, &pvec[ni]); 
-        i++;
-        i++;                  
+        fitch54(&dat[ni * nr], &dat[le * nr], &dat[ri * nr], nr, weight, &pvec[ni]); 
+        i+=2;
     }
-    if(i == (*nl-1L)){
+    if(i == (nl-1L)){
         le = edge[i] - 1L;
         pvec[ni] += pvec[le]; 
-        fitch53(&dat[ni * (*nr)], &dat[le * (*nr)], nr, weight, &pvec[ni]); 
+        fitch53(&dat[ni * nr], &dat[le * nr], nr, weight, &pvec[ni]); 
     } 
     pscore[0]=pvec[ni];
 }
 
 
+
+
 // in fitch
 SEXP FITCH(SEXP dat, SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP weight, SEXP mx, SEXP q){   
     int *data, *nr=INTEGER(nrx), m=INTEGER(mx)[0], i, n=INTEGER(q)[0];   
@@ -290,31 +285,6 @@ void fitchT3(int *dat1, int *dat2, int *nr, double *pars, double *weight, double
 }
 
 
-// return lower and upper bound for the number of changes 
-// upper bound very conservative 
-/*
-void countMPR(double *res, int *dat1, int *dat2, int *nr, double *weight, int *external){
-    int k;
-    int tmp;
-    for(k = 0; k < (*nr); k++){
-        tmp = dat1[k] & dat2[k];
-
-        if(tmp==0){
-            res[0] += weight[k];
-            res[1] += weight[k];
-        }
-        else{ 
-            if( external[0]==0L){ 
-                 if( bitcount(dat1[k] | dat2[k])>1L ) res[1] += weight[k]; // dat1[k] != dat2[k]
-            }   
-            else{ 
-                 if( tmp  < dat2[k] ) res[1] += weight[k];
-            }
-        }
-    } 
-}
-*/
-
 //void ACCTRAN2(int *dat, int *nr, double *pars, int *node, int *edge, int *nl, double *weight, double *pvec, int *nTips) 
 void ACCTRAN2(int *dat, int *nr, int *node, int *edge, int *nl, int *nTips)
 {   
@@ -530,29 +500,26 @@ SEXP FITCH345(SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP mx, SEXP ps){
     for(i=0; i<*nr; i++) INTEGER(pars)[i] = 0L;
     REAL(pscore)[0]=0.0;
     fitch8(data1, nr, INTEGER(pars), INTEGER(node), INTEGER(edge), INTEGER(l), weight, pvtmp, REAL(pscore));
-    
     UNPROTECT(2);
     if(INTEGER(ps)[0]==1)return(pscore);
     else return(pars); 
 }
 
-
-void FN4(int *dat, int *res, int *nr, int *node, int *edge, int *nl, int *pc, double *weight, double *tmpvec, double *pvec) { 
+void FN4(int *dat, int *res, int nr, int *node, int *edge, int nl, int *pc, double *weight, double *tmpvec, double *pvec) { 
     int i=0L, ni, le, ri;
-    while(i< *nl) {
+    while(i < nl) {
         ni = node[i] - 1L;
         le = edge[i] - 1L;
         ri = edge[i+1L] - 1L;
         if(pc[i+1L]==0L){
-	        pvec[ni] = tmpvec[le] + tmpvec[ri];
-	        fitch54(&res[ni * (*nr)], &dat[(edge[i]-1L) * (*nr)], &dat[ri * (*nr)], nr, weight, &pvec[ni]);              
+            pvec[ni] = tmpvec[le] + tmpvec[ri];
+            fitch54(&res[ni * nr], &dat[(edge[i]-1L) * nr], &dat[ri * nr], nr, weight, &pvec[ni]);              
         }    
         else{ 
             pvec[ni] = tmpvec[le] + pvec[ri];
-	          fitch54(&res[ni * (*nr)], &dat[le * (*nr)], &res[ri * (*nr)], nr, weight, &pvec[ni]);   
+            fitch54(&res[ni * nr], &dat[le * nr], &res[ri * nr], nr, weight, &pvec[ni]);   
         }
-        i++;
-        i++;
+        i+=2;
     }
 }
 
@@ -614,7 +581,7 @@ void fnhelp(int *node, int * edge, int *n, int *m, int *root, int *edge2, int *n
 
 
 SEXP FNALL_NNI(SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP mx, SEXP my, SEXP root){   
-    int *nr=INTEGER(nrx), m=INTEGER(mx)[0], i,  *n=INTEGER(l);  //*pars,
+    int nr=INTEGER(nrx)[0], m=INTEGER(mx)[0], i,  *n=INTEGER(l);  //*pars,
     double *pvtmp, *pvtmp2, pscore=0.0;  
     SEXP pvec1, pvec2, res; 
     int *pc, *edge2, *node2;
@@ -635,8 +602,8 @@ SEXP FNALL_NNI(SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP mx, SEXP my, SEXP ro
         pvtmp2[i] = 0.0;
     }
     fnhelp(INTEGER(node), INTEGER(edge),  n, &m, INTEGER(root), edge2, node2, pc); 
-    fitch9(data1, nr, INTEGER(node), INTEGER(edge), INTEGER(l), weight, pvtmp, &pscore); 
-    FN4(data1, data2, nr, node2, edge2, INTEGER(my), pc, weight, pvtmp, pvtmp2); // pars,
+    fitch9(data1, nr, INTEGER(node), INTEGER(edge), INTEGER(l)[0], weight, pvtmp, &pscore); 
+    FN4(data1, data2, nr, node2, edge2, INTEGER(my)[0], pc, weight, pvtmp, pvtmp2); // pars,
 //  fitchQuartet(int *index, int *n, nr, double *psc1, double *psc2, weight, double *res);  
     SET_VECTOR_ELT(res, 0, pvec1);
     SET_VECTOR_ELT(res, 1, pvec2);    
@@ -646,7 +613,7 @@ SEXP FNALL_NNI(SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP mx, SEXP my, SEXP ro
 
 // mpr2 fnodesNew5  , my = 2*n, n=length(node), root=node-1L
 SEXP FNALL5(SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP mx, SEXP my, SEXP root){   
-    int *nr=INTEGER(nrx), m=INTEGER(mx)[0], i,  *n=INTEGER(l);  //*pars,
+    int nr=INTEGER(nrx)[0], m=INTEGER(mx)[0], i,  *n=INTEGER(l);  //*pars,
     double *pvtmp, *pvtmp2, pscore=0.0;  
     SEXP pvec; 
     // fnhelp
@@ -666,9 +633,9 @@ SEXP FNALL5(SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP mx, SEXP my, SEXP root)
     }
     fnhelp(INTEGER(node), INTEGER(edge),  n, &m, INTEGER(root), edge2, node2, pc);
 //    fitch8(data1, nr, pars, INTEGER(node), INTEGER(edge), INTEGER(l), weight, pvtmp, &pscore);  
-    fitch9(data1, nr, INTEGER(node), INTEGER(edge), INTEGER(l), weight, pvtmp, &pscore); 
+    fitch9(data1, nr, INTEGER(node), INTEGER(edge), INTEGER(l)[0], weight, pvtmp, &pscore); 
 //    FN3(data1, data2, nr, pars, node2, edge2, INTEGER(my), pc, weight, pvtmp, pvtmp2);
-    FN4(data1, data2, nr, node2, edge2, INTEGER(my), pc, weight, pvtmp, pvtmp2); // pars,
+    FN4(data1, data2, nr, node2, edge2, INTEGER(my)[0], pc, weight, pvtmp, pvtmp2); // pars,
     for(i=0; i<m; i++) pvtmp[i] += pvtmp2[i];
 // return(pvtmp[edge])??    
     UNPROTECT(1);
@@ -678,7 +645,7 @@ SEXP FNALL5(SEXP nrx, SEXP node, SEXP edge, SEXP l, SEXP mx, SEXP my, SEXP root)
 // .Call("FNALL5", as.integer(nr), node, edge, as.integer(n), as.integer(m), 
 //      as.integer(m2), as.integer(root0), PACKAGE="phangorn")
 SEXP FNALL6(SEXP nrx, SEXP node, SEXP edge, SEXP mx){   
-    int *nr=INTEGER(nrx), m=INTEGER(mx)[0], i;  //*pars,
+    int nr=INTEGER(nrx)[0], m=INTEGER(mx)[0], i;  //*pars,
     int n =length(node);
     int root=INTEGER(node)[n-1L], my=2L*n;
     double *pvtmp, *pvtmp2, pscore=0.0;  
@@ -698,8 +665,8 @@ SEXP FNALL6(SEXP nrx, SEXP node, SEXP edge, SEXP mx){
         pvtmp2[i] = 0.0;
     }
     fnhelp(INTEGER(node), INTEGER(edge), &n, &m, &root, edge2, node2, pc);
-    fitch9(data1, nr, INTEGER(node), INTEGER(edge), &n, weight, pvtmp, &pscore); 
-    FN4(data1, data2, nr, node2, edge2, &my, pc, weight, pvtmp, pvtmp2); 
+    fitch9(data1, nr, INTEGER(node), INTEGER(edge), n, weight, pvtmp, &pscore); 
+    FN4(data1, data2, nr, node2, edge2, my, pc, weight, pvtmp, pvtmp2); 
     for(i=0; i<m; i++) pvtmp[i] += pvtmp2[i];
     // return(pvtmp[edge])??    
     UNPROTECT(1);
diff --git a/src/ml.c b/src/ml.c
index 9769923..0bf9306 100644
--- a/src/ml.c
+++ b/src/ml.c
@@ -1,7 +1,7 @@
 /* 
  * ml.c
  *
- * (c) 2008-2016  Klaus Schliep (klaus.schliep at gmail.com)
+ * (c) 2008-2017  Klaus Schliep (klaus.schliep at gmail.com)
  * 
  * 
  * This code may be distributed under the GNU GPL
@@ -126,7 +126,9 @@ void scaleMatrix(double *X, int *nr, int *nc, int *result){
 }
 
 
-// contrast to full
+// contrast to full dense matrix 
+// double *tmp und malloc rausziehen
+// zwei Versionen *= und new
 void matp(int *x, double *contrast, double *P, int *nr, int *nc, int *nrs, double *result){
     int i, j;
     double *tmp; 
@@ -149,13 +151,15 @@ void rowMinScale(int *dat, int n,  int k, int *res){
     }        
 }
 
-
-static R_INLINE void getP(double *eva, double *ev, double *evi, int m, double el, double w, double *result){
+// Ziel etwas schneller
+void getP(double *eva, double *ev, double *evi, int m, double el, double w, double *result){
     int i, j, h;
     double res; //tmp[m],
     double *tmp;
     tmp = malloc(m * sizeof(double));
+// el = 0 return identity    
     for(i = 0; i < m; i++) tmp[i] = exp(eva[i] * w * el);
+// eva *= tmp???
     for(i = 0; i < m; i++){    
         for(j = 0; j < m; j++){
             res = 0.0;    
@@ -163,10 +167,30 @@ static R_INLINE void getP(double *eva, double *ev, double *evi, int m, double el
             result[i+j*m] = res;    
         }
     }
-    free(tmp);
+    free(tmp);  // ausserhalb
+}
+
+
+void getP00(const double *eva, const double *ev, const double *evi, int m, double el, double w, 
+  double *tmp_kxk, double *result){
+    signed int  i, j, h;
+    double tmp, res; // ,res, tmp2
+    for(i = 0; i < m; i++){
+        tmp = exp(eva[i] * w * el);
+        for(j=0; j<m; j++)  tmp_kxk[i + j*m] = evi[i + j*m] * tmp; // evi[i + j*m] *= tmp; 
+    }    
+    for(i = 0; i < m; i++){    
+        for(j = 0; j < m; j++){
+        res = 0.0; 
+        for(h = 0; h < m; h++) res += ev[i + h*m] * tmp_kxk[h + j*m]; // evi[h + j*m];
+        result[i+j*m] = res;
+        }
+    }
 }
 
 
+
+
 SEXP getPM(SEXP eig, SEXP nc, SEXP el, SEXP w){
     R_len_t i, j, nel, nw, k;
     int m=INTEGER(nc)[0], l=0;
@@ -199,6 +223,117 @@ SEXP getPM(SEXP eig, SEXP nc, SEXP el, SEXP w){
 } 
 
 
+
+SEXP getPM00(SEXP eig, SEXP nc, SEXP el, SEXP w){
+    R_len_t i, j, nel, nw, k;
+    int m=INTEGER(nc)[0], l=0;
+    double *ws=REAL(w);
+    double *edgelen=REAL(el);
+    double *eva, *eve, *evei;
+    double *tmp_kxk;
+    SEXP P, RESULT;
+    tmp_kxk = (double *) R_alloc(m*m, sizeof(double));
+    nel = length(el);
+    nw = length(w);
+    if(!isNewList(eig)) error("'eig' must be a list");    
+    eva = REAL(VECTOR_ELT(eig, 0));
+    eve = REAL(VECTOR_ELT(eig, 1));
+    evei = REAL(VECTOR_ELT(eig, 2));
+    PROTECT(RESULT = allocVector(VECSXP, nel*nw));       
+    for(j=0; j<nel; j++){ 
+        for(i=0; i<nw; i++){
+            PROTECT(P = allocMatrix(REALSXP, m, m));
+            if(edgelen[j]==0.0 || ws[i]==0.0){
+                for(k=0; k<(m*m);k++)REAL(P)[k]=0.0;
+                for(k=0; k<m; k++)REAL(P)[k+k*m]=1.0;
+            }
+            else getP00(eva, eve, evei, m, edgelen[j], ws[i], tmp_kxk, REAL(P));
+            SET_VECTOR_ELT(RESULT, l, P);
+            UNPROTECT(1); 
+            l++;
+        }
+    }
+//    free(tmp_kxk);
+    UNPROTECT(1);//RESULT
+    return(RESULT);
+} 
+
+
+
+// some testing code: getP00 may be slightly faster than getP (5-10%)
+SEXP getPM001(SEXP eig, SEXP nc, SEXP el, SEXP w){
+    R_len_t i, j, nel, nw, k;
+    int m=INTEGER(nc)[0], l=0;
+    double *ws=REAL(w);
+    double *edgelen=REAL(el);
+    double *eva, *eve, *evei;
+    double *tmp_kxk, *P;
+//    SEXP P, RESULT;
+    tmp_kxk = (double *) R_alloc(m*m, sizeof(double));
+    P = (double *) R_alloc(m*m, sizeof(double));
+    nel = length(el);
+    nw = length(w);
+    if(!isNewList(eig)) error("'eig' must be a list");    
+    eva = REAL(VECTOR_ELT(eig, 0));
+    eve = REAL(VECTOR_ELT(eig, 1));
+    evei = REAL(VECTOR_ELT(eig, 2));
+//    PROTECT(RESULT = allocVector(VECSXP, nel*nw));       
+    for(j=0; j<nel; j++){ 
+        for(i=0; i<nw; i++){
+//            PROTECT(P = allocMatrix(REALSXP, m, m));
+            if(edgelen[j]==0.0 || ws[i]==0.0){
+                for(k=0; k<(m*m);k++)REAL(P)[k]=0.0;
+                for(k=0; k<m; k++)REAL(P)[k+k*m]=1.0;
+            }
+            else getP00(eva, eve, evei, m, edgelen[j], ws[i], tmp_kxk, P);
+//            SET_VECTOR_ELT(RESULT, l, P);
+//            UNPROTECT(1); 
+            l++;
+        }
+    }
+    //    free(tmp_kxk);
+//    UNPROTECT(1);//RESULT
+    return(ScalarReal(1.0));
+} 
+
+
+SEXP getPM002(SEXP eig, SEXP nc, SEXP el, SEXP w){
+    R_len_t i, j, nel, nw, k;
+    int m=INTEGER(nc)[0], l=0;
+    double *ws=REAL(w);
+    double *edgelen=REAL(el);
+    double *eva, *eve, *evei;
+    double  *P;
+    //    SEXP P, RESULT; *tmp_kxk,
+//    tmp_kxk = (double *) R_alloc(m*m, sizeof(double));
+    P = (double *) R_alloc(m*m, sizeof(double));
+    nel = length(el);
+    nw = length(w);
+    if(!isNewList(eig)) error("'eig' must be a list");    
+    eva = REAL(VECTOR_ELT(eig, 0));
+    eve = REAL(VECTOR_ELT(eig, 1));
+    evei = REAL(VECTOR_ELT(eig, 2));
+    //    PROTECT(RESULT = allocVector(VECSXP, nel*nw));       
+    for(j=0; j<nel; j++){ 
+        for(i=0; i<nw; i++){
+            //            PROTECT(P = allocMatrix(REALSXP, m, m));
+            if(edgelen[j]==0.0 || ws[i]==0.0){
+                for(k=0; k<(m*m);k++)REAL(P)[k]=0.0;
+                for(k=0; k<m; k++)REAL(P)[k+k*m]=1.0;
+            }
+            else getP(eva, eve, evei, m, edgelen[j], ws[i], P);
+            //            SET_VECTOR_ELT(RESULT, l, P);
+            //            UNPROTECT(1); 
+            l++;
+        }
+    }
+    //    free(tmp_kxk);
+    //    UNPROTECT(1);//RESULT
+    return(ScalarReal(1.0));
+} 
+
+
+
 void lll(SEXP dlist, double *eva, double *eve, double *evei, double *el, double g, int *nr, int *nc, int *node, int *edge, int nTips, double *contrast, int nco, int n, int *scaleTmp, double *bf, double *TMP, double *ans){
     int  ni, ei, j, i, rc; //    R_len_t i, n = length(node);
     double *rtmp, *P;
@@ -275,9 +410,13 @@ void lll3(SEXP dlist, double *eva, double *eve, double *evei, double *el, double
     P = (double *) R_alloc(*nc * *nc, sizeof(double));
     for(j=0; j < *nr; j++) scaleTmp[j] = 0L;
     for(i = 0; i < n; i++) {
+// entweder P matrix erstellen, openMP ??
+// temp Vectoren vermeiden 
         getP(eva, eve, evei, *nc, el[i], g, P); 
         ei = edge[i]; 
         if(ni != node[i]){
+// test for node[i+1]     
+// temp Vectoren vermeiden 
             if(ni>0)scaleMatrix(&ans[ni * rc], nr, nc, &SC[ni * *nr]); // (ni-nTips)
             ni = node[i];
             for(j=0; j < *nr; j++) SC[j + ni * *nr] = 0L;
@@ -605,13 +744,14 @@ void ExtractScale(int ch, int k, int *nr, int *ntips, double *res){
 }
 
 
-// dad / child * P 
+// in getDad 
+// dad / child * P  
 void helpDAD(double *dad, double *child, double *P, int nr, int nc, double *res){
     F77_CALL(dgemm)(transa, transb, &nr, &nc, &nc, &one, child, &nr, P, &nc, &zero, res, &nr);
     for(int j=0; j<(nc * nr); j++) res[j]=dad[j]/res[j];               
 } 
 
-
+// 
 SEXP getDAD(SEXP dad, SEXP child, SEXP P, SEXP nr, SEXP nc){
     R_len_t i, n=length(P);
     int ncx=INTEGER(nc)[0], nrx=INTEGER(nr)[0]; //, j
@@ -674,7 +814,7 @@ void NR555(double *eva, int nc, double el, double *w, double *g, SEXP X, int ld,
     for(i=0; i<nr ;i++) res[i]/=f[i];                
 } 
 
- 
+// tmp ausserhalb 
 void NR66(double *eva, int nc, double el, double *w, double *g, SEXP X, int ld, int nr, double *res){
     int i, j;   
     double *tmp; //*res,  *dF,
@@ -688,7 +828,7 @@ void NR66(double *eva, int nc, double el, double *w, double *g, SEXP X, int ld,
     }               
 } 
 
-
+// ohne dgemv probieren
 void NR77(double *eva, int nc, double el, double *w, double *g, double *X, int ld, int nr, double *f, double *res){
     int i, j, k; 
     double *tmp;  
@@ -700,10 +840,10 @@ void NR77(double *eva, int nc, double el, double *w, double *g, double *X, int l
         F77_CALL(dgemv)(transa, &nr, &nc, &w[j], &X[j*nrc], &nr, tmp, &ONE, &one, res, &ONE); 
         }
     for(i=0; i<nr ;i++) res[i]/=f[i];  
-    
 } 
 
 
+// tmp ausserhalb?
 void NR88(double *eva, int nc, double el, double *w, double *g, double *X, int ld, int nr, double *res){
     int i, j;   
     double *tmp; //*res,  *dF,
@@ -758,8 +898,8 @@ SEXP LogLik2(SEXP dlist, SEXP P, SEXP nr, SEXP nc, SEXP node, SEXP edge, SEXP nT
     return(ans);
 }
 
-
-static R_INLINE void matprod(double *x, int nrx, int ncx, double *y, int nry, int ncy, double *z)
+// raus
+void matprod(double *x, int nrx, int ncx, double *y, int nry, int ncy, double *z)
 {
     F77_CALL(dgemm)(transa, transb, &nrx, &ncy, &ncx, &one, x, &nrx, y, &nry, &zero, z, &nrx);
 }
@@ -973,13 +1113,14 @@ void fs3(double *eva, int nc, double el, double *w, double *g, double *X, int ld
         l0 = l1; 
         k ++;
     }   
-// variance 
- //   NR555(eva, ncx-1L, edle, ws, gs, X, INTEGER(ld)[0], nrx, f, tmp);  
- //   lll=0.0;        
- //   for(i=0; i<nrx ;i++) lll+=wgt[i]*tmp[i]*tmp[i]; 
+// variance n
+//   NR555(eva, ncx-1L, edle, ws, gs, X, INTEGER(ld)[0], nrx, f, tmp);  
+//   lll=0.0;        
+//   for(i=0; i<nrx ;i++) lll+=wgt[i]*tmp[i]*tmp[i]; 
     res[0] = edle;
     res[1] = ll; 
     res[2] = l0; //l0
+// return res[3] = 1 or 0 for success     
 }
 
 
diff --git a/src/phangorn.c b/src/phangorn.c
index 34035eb..cf94a5f 100644
--- a/src/phangorn.c
+++ b/src/phangorn.c
@@ -1,7 +1,7 @@
 /* 
  * phangorn.c
  *
- * (c) 2008-2016  Klaus Schliep (klaus.schliep at gmail.com)
+ * (c) 2008-2017  Klaus Schliep (klaus.schliep at gmail.com)
  * 
  * 
  * This code may be distributed under the GNU GPL
@@ -399,7 +399,7 @@ void C_reorder(int *from, int *to, int *n, int *sumNode,  int *neworder, int *ro
 }
 
 
-
+/*
 SEXP AllChildren(SEXP children, SEXP parent, SEXP M){
     int i, j, k, l=0L, m=INTEGER(M)[0], *tab, p;   
     R_len_t n=length(parent); 
@@ -434,7 +434,7 @@ SEXP AllChildren(SEXP children, SEXP parent, SEXP M){
     UNPROTECT(1);
     return(RESULT);
 }
-
+*/
 
 void AllKids(int *children, int *parents, int *nTips, int *nNode, int *lp, int *kids, int *lkids, int *pkids){
     int i, k, m=nNode[0], p; // l=0L, *tab , j 
@@ -479,7 +479,7 @@ allDesc = function(x, node){
 }
 
 allDesc(tree, 14)
- */
+ 
  
 SEXP AllDesc(SEXP child, SEXP parent, SEXP M, SEXP NODE){
     int i, m=INTEGER(M)[0]+1, *tab, *res, p, node=INTEGER(NODE)[0];   
@@ -503,7 +503,7 @@ SEXP AllDesc(SEXP child, SEXP parent, SEXP M, SEXP NODE){
     UNPROTECT(1);
     return(RESULT);
 }
-
+ */
 
 // std::merge
 void cisort(int *x, int *y, int a, int b, int *res){
diff --git a/src/phangorn_help.cpp b/src/phangorn_help.cpp
index c4a299d..8555cb1 100644
--- a/src/phangorn_help.cpp
+++ b/src/phangorn_help.cpp
@@ -13,7 +13,6 @@ List allDescCPP(IntegerMatrix orig, int nTips) {
     for(int i = 0; i<nTips; i++){
         out[i].push_back(i + 1L);
     }
-    std::vector<int> x;
     std::vector<int> y;
     for(int i = 0; i<parent.size(); i++){
         out[parent[i]-1L].push_back(children[i]);
@@ -27,6 +26,59 @@ List allDescCPP(IntegerMatrix orig, int nTips) {
 }
 
 
+// replacement for bipart maybe more error tolerant and slightly slower
+// import: edge matrix, number of tips
+// export: Descendants(x, 1:max(x$edge), "all")
+// [[Rcpp::export]]
+List bipartCPP(IntegerMatrix orig, int nTips) {
+    IntegerVector parent = orig( _, 0);
+    IntegerVector children = orig( _, 1);
+    int m = max(parent), j=0;
+    int nnode = m - nTips;
+    // create list for results
+    std::vector< std::vector<int> > out(nnode) ;
+    std::vector<int> y;
+    for(int i = 0; i<parent.size(); i++){
+        j = parent[i] - nTips - 1L;
+        if(children[i] > nTips){ 
+            y = out[children[i] - nTips -1L];
+            out[j].insert( out[j].end(), y.begin(), y.end() );
+        }
+        else out[j].push_back(children[i]);
+    }
+    for(int i=0; i<nnode; ++i){
+        sort(out[i].begin(), out[i].end());
+    }
+    return wrap(out);    // return the list
+}
+
+
+// replacement for bip maybe more error tolerant slightly slower
+// import: edge matrix, number of tips
+// export: Descendants(x, 1:max(x$edge), "all")
+// [[Rcpp::export]]
+List bipCPP(IntegerMatrix orig, int nTips) {
+    IntegerVector parent = orig( _, 0);
+    IntegerVector children = orig( _, 1);
+    int m = max(parent), j=0;
+    // create list for results
+    std::vector< std::vector<int> > out(m) ;
+    std::vector<int> y;
+    for(int i = 0; i<parent.size(); i++){
+        j = parent[i] - 1L;
+        if(children[i] > nTips){ 
+            y = out[children[i] - 1L];
+            out[j].insert( out[j].end(), y.begin(), y.end() );
+        }
+        else out[j].push_back(children[i]);
+    }
+    for(int i=0; i<m; ++i){
+        sort(out[i].begin(), out[i].end());
+    }
+    return wrap(out);    // return the list
+}
+
+
 // shorter and easier to understand replacement of C function 
 // import: edge matrix
 // export: list of children 
diff --git a/src/registerDynamicSymbol.c b/src/registerDynamicSymbol.c
new file mode 100644
index 0000000..e1a2080
--- /dev/null
+++ b/src/registerDynamicSymbol.c
@@ -0,0 +1,154 @@
+#include <R.h>
+#include <Rinternals.h>
+#include <stdlib.h> // for NULL
+#include <R_ext/Rdynload.h>
+
+/* FIXME: 
+Check these declarations against the C/Fortran source code.
+*/
+
+/* .C calls */
+extern void ACCTRAN2(void *, void *, void *, void *, void *, void *);
+extern void ACCTRAN3(void *, void *, void *, void *, void *, void *, void *, void *);
+extern void AllKids(void *, void *, void *, void *, void *, void *, void *, void *);
+extern void C_cophenetic(void *, void *, void *, void *, void *, void *, void *, void *);
+extern void C_fhm(void *, void *);
+extern void countCycle(void *, void *, void *, void *);
+extern void countCycle2(void *, void *, void *, void *);
+extern void C_reorder(void *, void *, void *, void *, void *, void *);
+extern void distHamming(void *, void *, void *, void *, void *);
+extern void fitch_free();
+extern void fitch_init(void *, void *, void *, void *, void *);
+extern void fitchQuartet(void *, void *, void *, void *, void *, void *, void *);
+extern void fitchTriplet(void *, void *, void *, void *, void *);
+extern void fitchTripletACC4(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *);
+extern void giveIndex(void *, void *, void *, void *, void *, void *);
+extern void ll_free();
+extern void ll_free2();
+extern void ll_init(void *, void *, void *, void *);
+extern void ll_init2(void *, void *, void *, void *, void *, void *);
+extern void nodeH(void *, void *, void *, void *, void *);
+extern void out(void *, void *, void *, void *, void *);
+
+/* .Call calls */
+extern SEXP AddOne(SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP AddOnes(SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP C_bip(SEXP, SEXP, SEXP, SEXP);
+extern SEXP C_bipart(SEXP, SEXP, SEXP, SEXP);
+extern SEXP C_rowMin(SEXP, SEXP, SEXP);
+extern SEXP C_sprdist(SEXP, SEXP, SEXP);
+extern SEXP dist2spectra(SEXP, SEXP, SEXP);
+extern SEXP FITCH(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP FITCH345(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP FITCHTRIP3(SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP FNALL5(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP FNALL6(SEXP, SEXP, SEXP, SEXP);
+extern SEXP FNALL_NNI(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP FS4(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP FS5(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP getd2PM(SEXP, SEXP, SEXP, SEXP);
+extern SEXP getd2PM2(SEXP, SEXP, SEXP, SEXP);
+extern SEXP getDAD(SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP getDAD2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP getdPM(SEXP, SEXP, SEXP, SEXP);
+extern SEXP getdPM2(SEXP, SEXP, SEXP, SEXP);
+extern SEXP getPM(SEXP, SEXP, SEXP, SEXP);
+extern SEXP getPrep(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP getPrep2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP invSites(SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP LogLik2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP optE(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP optQrtt(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP phangorn_allChildrenCPP(SEXP);
+extern SEXP phangorn_allDescCPP(SEXP, SEXP);
+extern SEXP phangorn_bipartCPP(SEXP, SEXP);
+extern SEXP phangorn_bipCPP(SEXP, SEXP);
+extern SEXP PML0(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP PML3(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP PML4(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP pNodes(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP PWI(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP rawStream2phyDat(SEXP);
+extern SEXP rowMax(SEXP, SEXP, SEXP);
+extern SEXP sankoff3(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP sankoff3B(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP sankoffMPR(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
+extern SEXP sankoffQuartet(SEXP, SEXP, SEXP, SEXP);
+
+static const R_CMethodDef CEntries[] = {
+    {"ACCTRAN2",         (DL_FUNC) &ACCTRAN2,          6},
+    {"ACCTRAN3",         (DL_FUNC) &ACCTRAN3,          8},
+    {"AllKids",          (DL_FUNC) &AllKids,           8},
+    {"C_cophenetic",     (DL_FUNC) &C_cophenetic,      8},
+    {"C_fhm",            (DL_FUNC) &C_fhm,             2},
+    {"countCycle",       (DL_FUNC) &countCycle,        4},
+    {"countCycle2",      (DL_FUNC) &countCycle2,       4},
+    {"C_reorder",        (DL_FUNC) &C_reorder,         6},
+    {"distHamming",      (DL_FUNC) &distHamming,       5},
+    {"fitch_free",       (DL_FUNC) &fitch_free,        0},
+    {"fitch_init",       (DL_FUNC) &fitch_init,        5},
+    {"fitchQuartet",     (DL_FUNC) &fitchQuartet,      7},
+    {"fitchTriplet",     (DL_FUNC) &fitchTriplet,      5},
+    {"fitchTripletACC4", (DL_FUNC) &fitchTripletACC4, 11},
+    {"giveIndex",        (DL_FUNC) &giveIndex,         6},
+    {"ll_free",          (DL_FUNC) &ll_free,           0},
+    {"ll_free2",         (DL_FUNC) &ll_free2,          0},
+    {"ll_init",          (DL_FUNC) &ll_init,           4},
+    {"ll_init2",         (DL_FUNC) &ll_init2,          6},
+    {"nodeH",            (DL_FUNC) &nodeH,             5},
+    {"out",              (DL_FUNC) &out,               5},
+    {NULL, NULL, 0}
+};
+
+static const R_CallMethodDef CallEntries[] = {
+    {"AddOne",                  (DL_FUNC) &AddOne,                   5},
+    {"AddOnes",                 (DL_FUNC) &AddOnes,                  5},
+    {"C_bip",                   (DL_FUNC) &C_bip,                    4},
+    {"C_bipart",                (DL_FUNC) &C_bipart,                 4},
+    {"C_rowMin",                (DL_FUNC) &C_rowMin,                 3},
+    {"C_sprdist",               (DL_FUNC) &C_sprdist,                3},
+    {"dist2spectra",            (DL_FUNC) &dist2spectra,             3},
+    {"FITCH",                   (DL_FUNC) &FITCH,                    8},
+    {"FITCH345",                (DL_FUNC) &FITCH345,                 6},
+    {"FITCHTRIP3",              (DL_FUNC) &FITCHTRIP3,               5},
+    {"FNALL5",                  (DL_FUNC) &FNALL5,                   7},
+    {"FNALL6",                  (DL_FUNC) &FNALL6,                   4},
+    {"FNALL_NNI",               (DL_FUNC) &FNALL_NNI,                7},
+    {"FS4",                     (DL_FUNC) &FS4,                     14},
+    {"FS5",                     (DL_FUNC) &FS5,                     10},
+    {"getd2PM",                 (DL_FUNC) &getd2PM,                  4},
+    {"getd2PM2",                (DL_FUNC) &getd2PM2,                 4},
+    {"getDAD",                  (DL_FUNC) &getDAD,                   5},
+    {"getDAD2",                 (DL_FUNC) &getDAD2,                  7},
+    {"getdPM",                  (DL_FUNC) &getdPM,                   4},
+    {"getdPM2",                 (DL_FUNC) &getdPM2,                  4},
+    {"getPM",                   (DL_FUNC) &getPM,                    4},
+    {"getPrep",                 (DL_FUNC) &getPrep,                  6},
+    {"getPrep2",                (DL_FUNC) &getPrep2,                 7},
+    {"invSites",                (DL_FUNC) &invSites,                 5},
+    {"LogLik2",                 (DL_FUNC) &LogLik2,                 10},
+    {"optE",                    (DL_FUNC) &optE,                    17},
+    {"optQrtt",                 (DL_FUNC) &optQrtt,                 16},
+    {"phangorn_allChildrenCPP", (DL_FUNC) &phangorn_allChildrenCPP,  1},
+    {"phangorn_allDescCPP",     (DL_FUNC) &phangorn_allDescCPP,      2},
+    {"phangorn_bipCPP",         (DL_FUNC) &phangorn_bipCPP,          2},
+    {"phangorn_bipartCPP",      (DL_FUNC) &phangorn_bipartCPP,       2},    
+    {"PML0",                    (DL_FUNC) &PML0,                    14},
+    {"PML3",                    (DL_FUNC) &PML3,                    14},
+    {"PML4",                    (DL_FUNC) &PML4,                    15},
+    {"pNodes",                  (DL_FUNC) &pNodes,                   6},
+    {"PWI",                     (DL_FUNC) &PWI,                      6},
+    {"rawStream2phyDat",        (DL_FUNC) &rawStream2phyDat,         1},
+    {"rowMax",                  (DL_FUNC) &rowMax,                   3},
+    {"sankoff3",                (DL_FUNC) &sankoff3,                 8},
+    {"sankoff3B",               (DL_FUNC) &sankoff3B,               10},
+    {"sankoffMPR",              (DL_FUNC) &sankoffMPR,               7},
+    {"sankoffQuartet",          (DL_FUNC) &sankoffQuartet,           4},
+    {NULL, NULL, 0}
+};
+
+void R_init_phangorn(DllInfo *dll)
+{
+    R_registerRoutines(dll, CEntries, CallEntries, NULL, NULL);
+    R_useDynamicSymbols(dll, FALSE);
+}
diff --git a/src/sankoff.c b/src/sankoff.c
index 68b0076..a1873f3 100644
--- a/src/sankoff.c
+++ b/src/sankoff.c
@@ -1,7 +1,7 @@
 /* 
  * dist.c
  *
- * (c) 2008-2016  Klaus Schliep (klaus.schliep at gmail.com)
+ * (c) 2008-2017  Klaus Schliep (klaus.schliep at gmail.com)
  * 
  * 
  * This code may be distributed under the GNU GPL
diff --git a/src/sprdist.c b/src/sprdist.c
index 082f413..30a9297 100644
--- a/src/sprdist.c
+++ b/src/sprdist.c
@@ -1,7 +1,7 @@
 /* 
  * sprdist.c
  *
- * (c) 2016 Leonardo de Oliveira Martins (leomrtns at gmail.com) 
+ * (c) 2016-2017 Leonardo de Oliveira Martins (leomrtns at gmail.com) 
  * 
  * 
  * This code may be distributed under the GNU GPL
@@ -14,7 +14,7 @@
 #include <math.h>
 #include <R.h> 
 #include <Rinternals.h>
-//#include <stdint.h>     /* standard integer types (int32_t typedef etc.) [C99]*/
+#include <stdint.h>     /* standard integer types (int32_t typedef etc.) [C99]*/
 
 
 #define true  1U /*!< Boolean TRUE  */
@@ -702,7 +702,7 @@ new_bipartition (int size)
   bip->ref_counter = 1;
 
   bip->bs = (unsigned long long*) malloc (bip->n->ints * sizeof (unsigned long long));
-  for (i=0; i < bip->n->ints; i++) bip->bs[i] = 0LL;
+  for (i=0; i < bip->n->ints; i++) bip->bs[i] = 0ULL;
 
   return bip;
 }
@@ -717,8 +717,8 @@ new_bipsize (int size)
   n->bits = n->original_size = size;
   n->ref_counter = 1;
   n->ints = size/BitStringSize + 1;
-  n->mask = 0LL;
-  for (i=0; i < n->bits%BitStringSize; i++) n->mask |= (1LL << i); /* disregard other bits */
+  n->mask = 0ULL;
+  for (i=0; i < n->bits%BitStringSize; i++) n->mask |= (1ULL << i); /* disregard other bits */
 
   return n;
 }
@@ -753,7 +753,7 @@ new_bipartition_from_bipsize (bipsize n)
   bip->ref_counter = 1;
 
   bip->bs = (unsigned long long*) malloc (bip->n->ints * sizeof (unsigned long long));
-  for (i=0; i < bip->n->ints; i++) bip->bs[i] = 0LL;
+  for (i=0; i < bip->n->ints; i++) bip->bs[i] = 0ULL;
 
   return bip;
 }
@@ -784,19 +784,19 @@ bipsize_resize (bipsize n, int nbits)
   int i;
   n->bits = nbits;
   n->ints = nbits/BitStringSize + 1; // might be smaller than original bs size 
-  n->mask = 0LL;
-  for (i=0; i < nbits%BitStringSize; i++) n->mask |= (1LL << i); /* disregard other bits */
+  n->mask = 0ULL;
+  for (i=0; i < nbits%BitStringSize; i++) n->mask |= (1ULL << i); /* disregard other bits */
 }
 
 void
 bipartition_initialize (bipartition bip, int position)
 {
   int i, j;
-  for (i=0; i < bip->n->ints; i++) bip->bs[i] = 0LL;
+  for (i=0; i < bip->n->ints; i++) bip->bs[i] = 0ULL;
   j = position%BitStringSize; 
   i = position/BitStringSize;
 
-  bip->bs[i] = (1LL << j);
+  bip->bs[i] = (1ULL << j);
   bip->n_ones = 1;
 }
 
@@ -804,7 +804,7 @@ void
 bipartition_zero (bipartition bip)
 {
   int i;
-  for (i=0; i < bip->n->ints; i++) bip->bs[i] = 0LL;
+  for (i=0; i < bip->n->ints; i++) bip->bs[i] = 0ULL;
   bip->n_ones = 0;
 }
 
@@ -817,8 +817,8 @@ bipartition_set (bipartition bip, int position)
 void
 bipartition_set_lowlevel (bipartition bip, int i, int j)
 {
-  if (bip->bs[i] & (1LL << j)) return; // bit already set
-  bip->bs[i] |= (1LL << j);
+  if (bip->bs[i] & (1ULL << j)) return; // bit already set
+  bip->bs[i] |= (1ULL << j);
   bip->n_ones++; /* doesn't work if we reduce space later (check replace_int_in_vector() ) */
 }
 
@@ -831,8 +831,8 @@ bipartition_unset (bipartition bip, int position)
 void
 bipartition_unset_lowlevel (bipartition bip, int i, int j)
 {
-  if (!(bip->bs[i] & (1LL << j))) return; // bit already unset
-  bip->bs[i] &= ~(1LL << j);
+  if (!(bip->bs[i] & (1ULL << j))) return; // bit already unset
+  bip->bs[i] &= ~(1ULL << j);
   bip->n_ones--;
 }
 
@@ -910,11 +910,11 @@ bipartition_count_n_ones (const bipartition bip)
   unsigned long long j;
   bip->n_ones = 0;
 /* // Naive approach 
-  for (i=0; i < bip->n_ints - 1; i++) for (j=0; j < BitStringSize; j++) bip->n_ones += ((bip->bs[i] >> j) & 1LL);
-  for (j=0; j < bip->n_bits%BitStringSize; j++) bip->n_ones += ((bip->bs[i] >> j) & 1LL);
+  for (i=0; i < bip->n_ints - 1; i++) for (j=0; j < BitStringSize; j++) bip->n_ones += ((bip->bs[i] >> j) & 1ULL);
+  for (j=0; j < bip->n_bits%BitStringSize; j++) bip->n_ones += ((bip->bs[i] >> j) & 1ULL);
  */
   // clear the least significant bit set per iteration (Peter Wegner in CACM 3 (1960), 322, mentioned in K&R)
-  for (i=0; i < bip->n->ints; i++) for (j = bip->bs[i]; j; bip->n_ones++) j &= j - 1LL;
+  for (i=0; i < bip->n->ints; i++) for (j = bip->bs[i]; j; bip->n_ones++) j &= j - 1ULL;
 }
 
 bool
@@ -965,7 +965,7 @@ bipartition_flip_to_smaller_set (bipartition bip)
   /* OLD always x is different from ~x, so we just look at last element ("largest digits of number") */
   // if (((2 * bip->n_ones) == bip->n->bits) && (bip->bs[i] < (bip->n->mask & ~bip->bs[i]))) return;
   /* NEW: resolve ties by always showing the same "side" of bipartition, that is, the one having an arbitrary leaf (first one, in our case) */
-  if (((2 * bip->n_ones) == bip->n->bits) && (bip->bs[0] & 1LL)) return;
+  if (((2 * bip->n_ones) == bip->n->bits) && (bip->bs[0] & 1ULL)) return;
 
   for (i=0; i < bip->n->ints; i++) bip->bs[i] = ~bip->bs[i]; /* like bipartition_NOT() */
   bip->bs[i-1] &= bip->n->mask; /* do not invert last bits (do not belong to bipartition) */
@@ -976,7 +976,7 @@ bipartition_flip_to_smaller_set (bipartition bip)
 bool
 bipartition_is_bit_set (const bipartition bip, int position)
 {
-  if (bip->bs[(int)(position/BitStringSize)] & (1LL << (int)(position%BitStringSize))) return true; 
+  if (bip->bs[(int)(position/BitStringSize)] & (1ULL << (int)(position%BitStringSize))) return true; 
   return false;
 }
 
@@ -993,7 +993,7 @@ void
 bipartition_to_int_vector (const bipartition b, int *id, int vecsize)
 {
   int i, j, k = 0;
-  for (i=0; i < b->n->ints; i++) for (j=0; (j < BitStringSize) && (k < vecsize); j++) if ( ((b->bs[i] >> j) & 1LL) ) id[k++] = i * BitStringSize + j;
+  for (i=0; i < b->n->ints; i++) for (j=0; (j < BitStringSize) && (k < vecsize); j++) if ( ((b->bs[i] >> j) & 1ULL) ) id[k++] = i * BitStringSize + j;
 }
 
 /*
@@ -1002,10 +1002,10 @@ bipartition_print_to_stdout (const bipartition b1)
 {
   int i, j;
   for (i = 0; i < b1->n->ints - 1; i++) {
-    for (j = 0; j < BitStringSize; j++) printf ("%d", (int)((b1->bs[i] >> j) & 1LL));
+    for (j = 0; j < BitStringSize; j++) printf ("%d", (int)((b1->bs[i] >> j) & 1ULL));
     printf (".");
   }
-  for (j = 0; j < b1->n->bits%BitStringSize; j++) printf ("%d", (int)((b1->bs[i] >> j) & 1LL));
+  for (j = 0; j < b1->n->bits%BitStringSize; j++) printf ("%d", (int)((b1->bs[i] >> j) & 1ULL));
   printf ("[%d] ", b1->n_ones);
 }
 */
@@ -1025,14 +1025,14 @@ bipartition_replace_bit_in_vector (bipartition *bvec, int n_b, int to, int from,
    * 1    -> 1  |     0               | -1  (in fact one of the two "1"s dissapeared after reducing the bitstring 
    * (the above description is outdated since I rewrote by hand the bit functions -- observe how we must erase 1 values from "from") */
   if (reduce) for (k = 0; k < n_b; k++) { // copy 0 or 1 values, erasing "from" values to avoid problems after reducing space (hanging 1s out of range)
-    if      ( ((bvec[k]->bs[i] >> j) & 1LL) && ((bvec[k]->bs[i2] >> j2) & 1LL) )  { bvec[k]->n_ones--; bvec[k]->bs[i] &= ~(1LL << j); }
-    else if ( ((bvec[k]->bs[i] >> j) & 1LL) && !((bvec[k]->bs[i2] >> j2) & 1LL) ) { bvec[k]->bs[i2] |=  (1LL << j2); bvec[k]->bs[i] &= ~(1LL << j); }
-    else if ( !((bvec[k]->bs[i] >> j) & 1LL) && ((bvec[k]->bs[i2] >> j2) & 1LL) ) { bvec[k]->bs[i2] &= ~(1LL << j2); bvec[k]->n_ones--; }
+    if      ( ((bvec[k]->bs[i] >> j) & 1ULL) && ((bvec[k]->bs[i2] >> j2) & 1ULL) )  { bvec[k]->n_ones--; bvec[k]->bs[i] &= ~(1ULL << j); }
+    else if ( ((bvec[k]->bs[i] >> j) & 1ULL) && !((bvec[k]->bs[i2] >> j2) & 1ULL) ) { bvec[k]->bs[i2] |=  (1ULL << j2); bvec[k]->bs[i] &= ~(1ULL << j); }
+    else if ( !((bvec[k]->bs[i] >> j) & 1ULL) && ((bvec[k]->bs[i2] >> j2) & 1ULL) ) { bvec[k]->bs[i2] &= ~(1ULL << j2); bvec[k]->n_ones--; }
     /* else do nothing (from zero to zero) */
   }
 
   else for (k = 0; k < n_b; k++) { // copy 0 or 1 values 
-    if ( ((bvec[k]->bs[i] >> j) & 1LL) ) bipartition_set_lowlevel   (bvec[k], i2, j2); // will check if n_ones change or not 
+    if ( ((bvec[k]->bs[i] >> j) & 1ULL) ) bipartition_set_lowlevel   (bvec[k], i2, j2); // will check if n_ones change or not 
     else                                 bipartition_unset_lowlevel (bvec[k], i2, j2);
   }
 }
diff --git a/tests/testthat/test_pmlPart.R b/tests/testthat/test_pmlPart.R
new file mode 100644
index 0000000..d4365d4
--- /dev/null
+++ b/tests/testthat/test_pmlPart.R
@@ -0,0 +1,167 @@
+context("Partitioned likelihood models")
+
+X <- allSitePattern(5)
+tree <- read.tree(text = "((t1:0.3,t2:0.3):0.1,(t3:0.3,t4:0.3):0.1,t5:0.5);")
+fit0 <- pml(tree, X, k=4)
+
+fit1 <- update(fit0, rate=.5)
+fit2 <- update(fit0, rate=2)
+
+weights0 <- 1000*exp(fit0$site) 
+weights1 <- 1000*exp(fit1$site) 
+weights2 <- 1000*exp(fit2$site) 
+
+
+W = cbind(weights0, weights1, weights2) 
+colnames(W) = c("g1", "g2", "g3")
+
+
+# rate
+test_that("rate optimisation works properly", {
+    skip_on_cran()
+    sp <- pmlPart(edge ~ rate, fit0, weight=W)
+    expect_equal( sp$fits[[1]]$rate  / sp$fits[[2]]$rate , 2, tolerance = 1e-5)
+    expect_equal( sp$fits[[1]]$rate  / sp$fits[[3]]$rate , 0.5, tolerance = 1e-5)
+})    
+
+# nni
+
+# Q
+test_that("transition rate optimisation works properly", {
+    skip_on_cran()
+
+    Q <- c(6:1)
+    
+    fit0 <- pml(tree, X, k=4)
+    fit1 <- pml(tree, X, k=4, Q=Q)
+    weights1 <- 1000*exp(fit1$site) 
+    Y <- X 
+    attr(Y, "weight") <- weights1
+    fit1 <- pml(tree, Y, k=4, Q=Q)
+    
+    weights0 <- weights1
+    weights2 <- weights1
+
+    W = cbind(weights0, weights1, weights2) 
+    colnames(W) = c("g1", "g2", "g3")
+    
+    # linked parameter
+    
+    sp <- pmlPart(edge + Q ~ ., fit0, weight=W)    
+    expect_equal(logLik(sp)[1], logLik(fit1)[1]*3, tolerance=5e-4 )
+    expect_equal(Q, sp$fits[[1]]$Q, tolerance=5e-4)
+    
+    # unlinked parameter
+    # TODO more complicated models
+    # weights0 <- 1000*exp(fit0$site)
+    sp <- pmlPart( ~ Q, fit0, weight=W)   
+    expect_equal(logLik(sp)[1], logLik(fit1)[1]*3, tolerance=5e-4 )
+    expect_equal(Q, sp$fits[[1]]$Q, tolerance=5e-4)
+})
+
+
+# bf
+test_that("base frequency optimisation works properly", {
+    skip_on_cran()
+    
+    bf <- (1:4)/10 
+    
+    fit0 <- pml(tree, X, k=4)
+    fit1 <- pml(tree, X, k=4, bf=bf)
+    weights1 <- 1000*exp(fit1$site) 
+    Y <- X 
+    attr(Y, "weight") <- weights1
+    fit1 <- pml(tree, Y, k=4, bf=bf)
+    
+    weights0 <- weights1
+    weights2 <- weights1
+    
+    W = cbind(weights0, weights1, weights2) 
+    colnames(W) = c("g1", "g2", "g3")
+    
+    # linked parameter
+    
+    sp <- pmlPart(edge + bf ~ ., fit0, weight=W)    
+    expect_equal(logLik(sp)[1], logLik(fit1)[1]*3, tolerance=5e-4 )
+    expect_equal(bf, sp$fits[[1]]$bf, tolerance=5e-4)
+    
+    # unlinked parameter
+    # TODO more complicated models
+    # weights0 <- 1000*exp(fit0$site)
+    sp <- pmlPart( ~ bf, fit0, weight=W)   
+    expect_equal(logLik(sp)[1], logLik(fit1)[1]*3, tolerance=5e-4 )
+    expect_equal(bf, sp$fits[[1]]$bf, tolerance=5e-4)
+})
+
+# Gamma
+test_that("shape parameter optimisation works properly", {
+    skip_on_cran()
+    
+    shape=2
+    
+    fit0 <- pml(tree, X, k=4)
+    fit1 <- pml(tree, X, k=4, shape=shape)
+    weights1 <- 1000*exp(fit1$site) 
+    Y <- X 
+    attr(Y, "weight") <- weights1
+    fit1 <- pml(tree, Y, k=4, shape=shape)
+    
+    weights0 <- weights1
+    weights2 <- weights1
+    
+    W = cbind(weights0, weights1, weights2) 
+    colnames(W) = c("g1", "g2", "g3")
+    
+    # linked parameter
+  
+    sp <- pmlPart(edge + shape ~ ., fit0, weight=W)    
+    expect_equal(logLik(sp)[1], logLik(fit1)[1]*3, tolerance=5e-4 )
+    expect_equal(shape, sp$fits[[1]]$shape, tolerance=5e-3)
+    
+    # unlinked parameter
+    # TODO more complicated models
+    # weights0 <- 1000*exp(fit0$site)
+    sp <- pmlPart( ~ shape, fit0, weight=W)   
+    expect_equal(logLik(sp)[1], logLik(fit1)[1]*3, tolerance=5e-4 )
+    expect_equal(shape, sp$fits[[1]]$shape, tolerance=5e-4)
+})
+
+# Invariant sites
+test_that("Invariant sites optimisation works properly", {
+    skip_on_cran()
+    
+    inv=.2
+    
+    fit0 <- pml(tree, X, k=4)
+    fit1 <- pml(tree, X, k=4, inv=inv)
+    weights1 <- 1000*exp(fit1$site) 
+    Y <- X 
+    attr(Y, "weight") <- weights1
+    fit1 <- pml(tree, Y, k=4, inv=inv)
+    
+    weights0 <- weights1
+    weights2 <- weights1
+    
+    W = cbind(weights0, weights1, weights2) 
+    colnames(W) = c("g1", "g2", "g3")
+    
+    # linked parameter
+    
+    sp <- pmlPart(edge + inv ~ ., fit0, weight=W)    
+    expect_equal(logLik(sp)[1], logLik(fit1)[1]*3, tolerance=5e-4 )
+    expect_equal(inv, sp$fits[[1]]$inv, tolerance=5e-5)
+    
+    # unlinked parameter
+    # TODO more complicated models
+    # weights0 <- 1000*exp(fit0$site)
+    sp <- pmlPart( ~ inv, fit0, weight=W)   
+    expect_equal(logLik(sp)[1], logLik(fit1)[1]*3, tolerance=5e-4 )
+    expect_equal(inv, sp$fits[[1]]$inv, tolerance=5e-5)
+})
+
+
+# model
+
+
+
+
diff --git a/tests/testthat/test_treeManipulation.R b/tests/testthat/test_treeManipulation.R
index f3aadff..54ed731 100644
--- a/tests/testthat/test_treeManipulation.R
+++ b/tests/testthat/test_treeManipulation.R
@@ -2,7 +2,7 @@ context("treeManipulation")
 
 set.seed(42)
 tree <- rtree(100, rooted=FALSE)
-
+tree2 <- root(tree, 1, resolve.root = TRUE)
 
 
 trees <- lapply(sample(10:500,50), function(x)tree <- rtree(x, rooted=FALSE) )
@@ -20,12 +20,13 @@ desc_108 <- Descendants(tree, 108)[[1]]
 node_108 <- mrca.phylo(tree, node=desc_108)
 
 test_that("ancestor, mrca, descendants", {
-    ## check RF.dist and tree dist
+    ## ancestor, mrca, descendants
     expect_equal(mrca.phylo(tree, node=desc_108), 108L)
     kids_108 <- Descendants(tree, 108, "children")
+    expect_equal(length(Descendants(tree, 101L, "all")), 197L)
+    expect_equal(lengths(Descendants(tree2, 101L:199, "all")), 2 * lengths(prop.part(tree2)) - 2L)
     expect_equal(Ancestors(tree, kids_108, "parent"), rep(108L, length(kids_108)))
     expect_equal(Siblings(tree, kids_108[1], include.self=TRUE), kids_108)
-    
 })
 
 test_that("allTrees", {
diff --git a/vignettes/Ancestral.Rnw b/vignettes/Ancestral.Rnw
index 8b29ab7..824bbe6 100644
--- a/vignettes/Ancestral.Rnw
+++ b/vignettes/Ancestral.Rnw
@@ -56,14 +56,15 @@ foo <- packageDescription("phangorn")
 \nocite{Paradis2006}
 \section{Introduction}
 
-These notes describe the ancestral sequence reconstruction using the \phangorn{} package \cite{Schliep2011}. \phangorn{} provides several methods to estimate ancestral character states with either Maximum Parsimony (MP) or Maximum Likelihood (ML). %For more background on all the methods see e.g. \cite{Felsenstein2004, Yang2006}. 
+These notes describe the ancestral sequence reconstruction using the \phangorn{} package \cite{Schliep2011}. \phangorn{} provides several methods to estimatea ancestral character states with either Maximum Parsimony (MP) or Maximum Likelihood (ML). %For more background on all the methods see e.g. \cite{Felsenstein2004, Yang2006}. 
 \section{Parsimony reconstructions}
 To reconstruct ancestral sequences we first load some data and reconstruct a tree:
 <<echo=TRUE>>=
 library(phangorn)
-primates = read.phyDat("primates.dna", format = "phylip", type = "DNA")
-tree = pratchet(primates, trace=0)
-tree = acctran(tree, primates) 
+library(magrittr)
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip", type = "DNA")
+tree <- pratchet(primates, trace=0) %>% acctran(primates) 
 parsimony(tree, primates)
 @
 
diff --git a/vignettes/IntertwiningTreesAndNetworks.Rmd b/vignettes/IntertwiningTreesAndNetworks.Rmd
index 53a147a..a69dd60 100644
--- a/vignettes/IntertwiningTreesAndNetworks.Rmd
+++ b/vignettes/IntertwiningTreesAndNetworks.Rmd
@@ -2,21 +2,28 @@
 title: 'Intertwining phylogenetic trees and networks: R Example Script'
 author: "Klaus Schliep, Alastair Potts, David Morrison and Guido Grimm"
 date: "`r format(Sys.time(), '%B %d, %Y')`"
+bibliography: phangorn.bib
 output: rmarkdown::html_vignette
 vignette: >
    %\VignetteIndexEntry{IntertwiningTreesAndNetworks}
    %\VignetteEngine{knitr::rmarkdown}
    %\usepackage[utf8]{inputenc}
 ---
-
+[comment]: # (output: html_document)
 
 ```{r setup, echo=FALSE}
 # set global chunk options: images will be bigger
-knitr::opts_chunk$set(fig.width=7, fig.height=7) 
+  knitr::opts_chunk$set(fig.width=6, fig.height=6)
+#, global.par=TRUE
 options(digits = 4)
+
+knitr::knit_hooks$set(small.mar=function(before, options, envir){
+   if (before && options$fig.show!='none') par(mar=c(.5,.5,.5,.5))
+})
 ```
 
 
+
 *Description:* This script provides examples of the new functions available in the phangorn library to 'intertwine' trees and networks, i.e. compare trees and networks and data transferrance. It also provides a step-by-step guide for users new to R. 
 
 *Methodological advancement:* The major advancement in this phangorn update is the introduction of a generic network object with a wide range of related transfer and analysis functions. These new functions provide the first means to directly transfer information amongst a wide range of phylogenetic trees and networks, as well as means to visualise and further analyse this information. This should provide a platform for individuals to easily conduct tree-network comparisons and stimulate  [...]
@@ -45,12 +52,13 @@ install_github("KlausVigo/phangorn")
 ### Getting started                                                  
 ```{r}
 library(phangorn)    # load the phangorn library
+library(magrittr)  
 ```
 
 ### Set the working directory
 This is often a major stumbling block for new R users. You need to specify where in your folder structure you wish to work. i.e, where are the files stored that you wish to input?
 
-This is done using the setwd() function, e.g. setwd("C:/TreesNetworks/Example Files").
+This is done using the `setwd()` function, e.g. `setwd("C:/TreesNetworks/Example Files")`.
 
 We now set it to the folder of the phangorn package, which contains the files we want to load for this example.
 
@@ -90,7 +98,7 @@ All example files read into R.
 
 ### Viewing the data   
 ```{r}
-par(mfrow=c(1,2), mar=c(2,2,2,2)) # Setting plot parameters
+par(mfrow=c(1,2), mar=c(1,1,1,1)) # Setting plot parameters
 ### Plotting trees with support values:
 ##  RAxML
 plot(raxml.tree)
@@ -101,7 +109,7 @@ nodelabels(mrbayes.tree$node.label, adj = c(1, 0), frame = "none")
 
 par(mfrow=c(1,1)) # Setting plot parameters
 # NeighbourNet
-plot.networx(Nnet,"2D")
+plot(Nnet,"2D")
 ## alternatively,
 # plot(Nnet,"2D")
 
@@ -111,16 +119,15 @@ plot.networx(Nnet,"2D")
 ### 1A: 
 Identification of edge bundles (in black) in a neighbour-net (NN) network that correspond to branches (labelled 1-12) in a tree (a maximum likelihood tree, in this case). 
 
-```{r} 
+```{r, fig.width=7, fig.height=4, small.mar=TRUE} 
 # create a vector of labels for the network corresponding to edges in the tree
 edge.lab <- createLabel(Nnet, raxml.tree, raxml.tree$edge[,2], "edge")
 # could be also 1:27 instead of raxml.tree$edge[,2]
 
 # Show the correspondingly labelled tree and network in R
-par(mfrow=c(1,2), mar=c(1,1,1,1))
-#plotBS(raxml.tree, rotate.tree = 180) 
-plot(raxml.tree, "u", rotate.tree = 180) 
-edgelabels(raxml.tree$edge[,2],col="blue", frame="none")
+par(mfrow=c(1,2))  
+plot(raxml.tree, "u", rotate.tree = 180, cex=.7) 
+edgelabels(raxml.tree$edge[,2],col="blue", frame="none", cex=.7)
 
 # find edges that are in the network but not in the tree
 edge.col <- rep("black", nrow(Nnet$edge))
@@ -128,8 +135,8 @@ edge.col[ is.na(edge.lab) ] <- "red"
 # or a simpler alternative...
 edge.col <- createLabel(Nnet, raxml.tree, "black", nomatch="red")
 
-x <- plot.networx(Nnet, edge.label = edge.lab, show.edge.label = T, "2D", edge.color = edge.col,
-                  col.edge.label = "blue")
+x <- plot(Nnet, edge.label = edge.lab, show.edge.label = T, "2D", edge.color = edge.col,
+                  col.edge.label = "blue", cex=.7)
 # the above plot function returns an invisible networx object and this object also  
 # contains the colors for the edges.
 
@@ -138,8 +145,10 @@ x <- plot.networx(Nnet, edge.label = edge.lab, show.edge.label = T, "2D", edge.c
 
 ### 1B: 
 Bootstrap support for all branches (branch labels) in the ML tree mapped on the corresponding edge bundles of the NN network. The edges in the network which are not found as ML tree branches are highlighted in red.
-```{r}   
-x <- addConfidences(Nnet,raxml.tree)
+```{r, small.mar=TRUE}   
+# the scaler argument multiplies the confidence values. This is useful to switch
+# confidences values between total, percentage or ratios.   
+x <- addConfidences(Nnet,raxml.tree, scaler = .01)
 # find splits that are in the network but not in the tree
 split.col <- rep("black", length(x$splits))
 split.col[ !matchSplits(as.splits(x), as.splits(raxml.tree)) ] <- "red"
@@ -148,9 +157,9 @@ split.col[ !matchSplits(as.splits(x), as.splits(raxml.tree)) ] <- "red"
 split.col2 <- createLabel(x, raxml.tree, label="black", "split", nomatch="red")
 
 # Plotting in R
-par(mfrow=c(1,1))
-out.x <- plot.networx(x,"2D",show.edge.label=TRUE, split.color=split.col, col.edge.label = "blue")
+out.x <- plot(x,"2D",show.edge.label=TRUE, split.color=split.col, col.edge.label = "blue")
 ```
+
 Again we can write to SplitsTree for viewing...
 ```{r}
 # write.nexus.networx(out.x,"woodmouse.tree.support.nxs")
@@ -162,7 +171,7 @@ Again we can write to SplitsTree for viewing...
 Frequencies of bipartitions found in the bootstrap pseudoreplicates mapped on the corresponding edge bundles of the NN network using a threshold of 10% (i.e. any edge is labelled that occurs in at least 
 100 of the 1000 ML-BS pseudoreplicates). Edge bundles not found in the ML tree are labelled using grey edges.
 
-```{r}
+```{r, small.mar=TRUE}
 y <- addConfidences(Nnet, as.splits(raxml.bootstrap))
 edge.col <- createLabel(y, raxml.tree, label="black", "edge", nomatch="grey")
 
@@ -174,17 +183,110 @@ y <- plot(y,"2D",show.edge.label=TRUE, edge.color=edge.col)
 
 ### Extras...
 We can also compare the neighborNet with a consensusNet (Holland BR, Huber KT, Moulton V, Lockhart PJ,2004, Using consensus networks to visualize contradictory evidence for species phylogeny. Molecular Biology and Evolution, 21, 1459-1461). Furthermore, we can extract the support values from the consensus network, and place these on to the NeighbourNet (this is similar to the process explained in 1C above).
-```{r}
+```{r, small.mar=TRUE}
 cnet <- consensusNet(raxml.bootstrap,prob=0.10)
 edge.col <- createLabel(cnet, Nnet, label="black", "edge", nomatch="grey")
-cnet <- plot.networx(cnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
+cnet <- plot(cnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
 
 edge.col <- createLabel(Nnet, cnet, label="black", "edge", nomatch="grey")
-z <- plot.networx(Nnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
+z <- plot(Nnet, "2D", show.edge.label = TRUE, edge.color=edge.col)
 
 obj <- addConfidences(Nnet,cnet)
-plot.networx(obj,"2D",show.edge.label=T, edge.color=edge.col, col.edge.label = "blue")
+plot(obj,"2D",show.edge.label=T, edge.color=edge.col, col.edge.label = "blue")
 
 ## Write to SplitsTree for viewing
 # write.nexus.networx(obj,"Nnet.with.ML.Cnet.Bootstrap.nxs")
 ```
+
+
+### 
+There are four possible data patterns in phylogenetic reconstruction: (1) patterns that are well supported in the network and appear in the bootstapped trees; (2) patterns that are well supported by (part of) the data/network but do not appear in the optimised trees, i.e. they are incompatible with the tree; (3) patterns that are weakly supported by the network but appear in the optimised trees anyway, i.e. they are compatible with the tree. 
+
+Here we demonstrate these patterns by showing the relationships between splits weights, from a NeighborNet splits graph, bootstrap bipartitions support and bootstrap percentages plotted on the optimised tree for a dataset of @Wang2012. 
+
+(An advanced user figure...)
+```{r, fig.width=7, fig.height=6}
+Nnet <- read.nexus.networx(file.path(fdir,"RAxML_distances.Wang.nxs"))
+raxml.tree <- read.tree(file.path(fdir,"RAxML_bestTree.Wang.out")) %>% unroot
+raxml.bootstrap <- read.tree(file.path(fdir,"RAxML_bootstrap.Wang.out"))
+
+bs_splits <- as.splits(raxml.bootstrap)
+tree_splits <- as.splits(raxml.tree) %>% unique %>% removeTrivialSplits
+# we overwrite bootstrap values and set the weights 
+# to 1e-6 (almost zero), as we plot them on a log scale later on
+attr(bs_splits, "weights")[] <- 1e-6
+# combine the splits from the bootstrap and neighbor net
+# and delete duplicates and add the confidence values
+# we get rid of trivial splits
+all_splits <- c(Nnet$splits, bs_splits) %>% unique %>% removeTrivialSplits %>% addConfidences(bs_splits, scaler=100)
+
+# For easier plotting we create a matrix with the confidences and 
+# weights as columns
+tab <- data.frame(SplitWeight = attr(all_splits, "weights"), Bootstrap=attr(all_splits, "confidences"), Tree=FALSE)
+# we add a logical variable pto indicate which splits are in the RAxML tree
+tab$Tree[matchSplits(tree_splits, all_splits, FALSE)] = TRUE
+
+tab[is.na(tab[,"Bootstrap"]),"Bootstrap"] <- 0
+tab[,"Bootstrap"] <- round(tab[,"Bootstrap"])
+rownames(tab) <- apply(as.matrix(all_splits, zero.print = ".", one.print = "|"), 1, paste0, collapse="")
+tab[1:10,]
+
+col <- rep("blue", nrow(tab))
+col[tab[,"Bootstrap"]==0] <- "green"
+col[tab[,"SplitWeight"]==1e-6] <- "red"
+
+pch = rep(19, nrow(tab))
+pch[tab$Tree] <- 17
+
+par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)
+plot(tab[,"SplitWeight"], tab[,"Bootstrap"], log="x", col=col, pch=pch,  
+     xlab="Split weight (log scale)", ylab="Bootstrap (%)")
+legend("topright", inset=c(-0.35,0), c("Pattern 1", "Pattern 2", "Pattern 3", "Pattern in the\nbest tree"), pch=c(19,19,19,17), col=c("blue", "green", "red", "black"), bty="n")
+```
+
+### Figure 4
+
+```{r} 
+YCh <- read.tree(file.path(fdir, "RAxML_bestTree.YCh")) 
+mtG <- read.tree(file.path(fdir, "RAxML_bestTree.mtG")) 
+ncAI <- read.tree(file.path(fdir, "RAxML_bestTree.AIs")) 
+all_data <- read.tree(file.path(fdir, "RAxML_bestTree.3moles")) 
+YCh_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.YCh")) 
+mtG_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.mtG")) 
+ncAI_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.AIs")) 
+all_data_boot <- read.tree(file.path(fdir, "RAxML_bootstrap.3moles")) 
+```
+
+There are several option plotting a co-phylogeny. In the following we use the 
+`cophylo` function of the `phytools` package. 
+
+[comment]: # ({r cophylo, fig.width=7, fig.height=7})
+```
+library(phytools)
+par(mfrow=c(2,1))
+obj <- cophylo(YCh, mtG) 
+plot(obj, mar=c(.1,.1,2,.1),scale.bar=c(.005,.05), ylim=c(-.2,1))  
+title("A. YCh                                    B. mtG")
+obj <-  cophylo(ncAI, all_data)
+plot(obj, mar=c(.1,.1,2,.1),scale.bar=c(.005,.05), ylim=c(-.2,1))
+title("C. ncAI                              D. All data")
+```
+![](cophylo.png)
+Unfortunately this function does not (yet) offer to add confidences 
+to some splits, but we can do this easily with more basic plot functions. 
+```{r}
+par(mfrow=c(2,2), mar = c(2,2,4,2))
+YCh <- plotBS(midpoint(YCh), YCh_boot, "phylogram", p=0, main = "YCh")
+mtG <- plotBS(midpoint(mtG), mtG_boot, "phylogram", p=0, main = "mtG")
+ncAI <- plotBS(midpoint(ncAI), ncAI_boot, "phylogram", p=0, main = "ncAI")
+all_data <- plotBS(midpoint(all_data), all_data_boot, "phylogram", p=0, main = "All data")
+```
+
+We can compare this with consensus network with the different bootstrap values for the different genes. 
+```{r, small.mar=TRUE}
+par(mfrow=c(1,1))
+cn <- consensusNet(c(YCh, mtG, ncAI))
+cn <- addConfidences(cn, YCh_boot) %>% addConfidences(mtG_boot, add=TRUE) %>% addConfidences(ncAI_boot, add=TRUE) %>% addConfidences(all_data_boot, add=TRUE)
+plot(cn, "2D", show.edge.label=TRUE)
+```
+
diff --git a/vignettes/Trees.Rnw b/vignettes/Trees.Rnw
index a77f5d4..7449492 100644
--- a/vignettes/Trees.Rnw
+++ b/vignettes/Trees.Rnw
@@ -67,8 +67,8 @@ The first thing we have to do is to read in an alignment. Unfortunately there ex
 We start our analysis loading the \phangorn{} package and then reading in an alignment.  
 <<echo=TRUE>>=
 library(phangorn)
-primates <- read.phyDat("primates.dna", format="phylip", 
-    type="DNA")
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip")
 @
 \section{Distance based methods}
 After reading in the alignment we can build a first tree with distance based methods. The function dist.dna from the ape package computes distances for many DNA substitution models. To use the function dist.dna we have to transform the data to class DNAbin. For amino acids the function \Rfunction{dist.ml} offers common substitution models (for example "WAG", "JTT", "LG", "Dayhoff", "cpREV", "mtmam", "mtArt", "MtZoa" or "mtREV24").  
diff --git a/vignettes/cophylo.png b/vignettes/cophylo.png
new file mode 100644
index 0000000..ab696fa
Binary files /dev/null and b/vignettes/cophylo.png differ
diff --git a/vignettes/phangorn-specials.Rnw b/vignettes/phangorn-specials.Rnw
index 53b99b4..8d36b50 100644
--- a/vignettes/phangorn-specials.Rnw
+++ b/vignettes/phangorn-specials.Rnw
@@ -232,7 +232,8 @@ There are four models available:
 We compute the $d_N/d_S$ for some sequences given a tree using the ML functions \Rfunction{pml} and \Rfunction{optim.pml}. First we have to transform the the nucleotide sequences into codons (so far the algorithms always takes triplets). 
 <<echo=TRUE>>=
 library(phangorn)
-primates = read.phyDat("primates.dna", format="phylip", type="DNA")
+fdir <- system.file("extdata/trees", package = "phangorn")
+primates <- read.phyDat(file.path(fdir, "primates.dna"), format = "phylip", type = "DNA")
 tree <- NJ(dist.ml(primates))
 dat <- phyDat(as.character(primates), "CODON")
 fit <- pml(tree, dat)
diff --git a/vignettes/phangorn.bib b/vignettes/phangorn.bib
index 5523152..adea656 100644
--- a/vignettes/phangorn.bib
+++ b/vignettes/phangorn.bib
@@ -715,6 +715,24 @@ journal = {Bioinformatics}
 	Year = "2014"
 }
 
+
+ at article {Michaux2003,
+    author = {Michaux, J. R. and Magnanou, E. and Paradis, E. and Nieberding, C. and Libois, R.},
+    title = {Mitochondrial phylogeography of the Woodmouse (Apodemus sylvaticus) in the Western Palearctic region},
+    journal = {Molecular Ecology},
+    volume = {12},
+    number = {3},
+    publisher = {Blackwell Science Ltd},
+    issn = {1365-294X}, 
+    url = {http://dx.doi.org/10.1046/j.1365-294X.2003.01752.x},
+    doi = {10.1046/j.1365-294X.2003.01752.x},
+    pages = {685--697},
+    keywords = {Apodemus sylvaticus, glacial refuge, mtDNA, North Africa, phylogeography, postglacial colonization, Western Palearctic region },
+    year = {2003},
+}
+
+
+
 @Article{ Paradis2004,
 	Author = "E. Paradis and J. Claude and K. Strimmer",
 	Title = "{APE}: Analyses of Phylogenetics and Evolution in {R} language",
@@ -766,6 +784,19 @@ journal = {Bioinformatics}
 	Year = "2010"
 }
 
+
+ at article {Schliep2017,
+    author = "Schliep, Klaus and Potts, Alastair J. and Morrison, David A. and Grimm, Guido W.",
+    title = "Intertwining phylogenetic trees and networks",
+    journal = "Methods in Ecology and Evolution",
+    url = "http://dx.doi.org/10.1111/2041-210X.12760",
+    doi = "10.1111/2041-210X.12760",
+    pages = "n/a--n/a",
+    keywords = "Exploratory Data Analysis, Networks, PHANGORN, R, Trees",   
+    year = "2017"
+}
+
+
 @Article{ Schliep2011,
 	title = "phangorn: Phylogenetic analysis in {R}",
 	author = "Klaus Peter Schliep",
@@ -956,3 +987,16 @@ journal = {Bioinformatics}
 }
 
 
+ at article{Wang2012,
+    author = {Wang, Ning and Braun, Edward L. and Kimball, Rebecca T.}, 
+    title = {Testing Hypotheses about the Sister Group of the Passeriformes Using an Independent 30-Locus Data Set},
+    volume = {29}, 
+    number = {2}, 
+    pages = {737-750}, 
+    year = {2012}, 
+    doi = {10.1093/molbev/msr230}, 
+    URL = {http://mbe.oxfordjournals.org/content/29/2/737.abstract}, 
+    eprint = {http://mbe.oxfordjournals.org/content/29/2/737.full.pdf+html}, 
+    journal = {Molecular Biology and Evolution} 
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-phangorn.git



More information about the debian-med-commit mailing list