Giter Site home page Giter Site logo

Comments (6)

kingaa avatar kingaa commented on July 21, 2024

The ouchtree format is designed for internal use and not with a view to outside examination. That is, it is designed solely to make the internal ouch algorithms efficient. My advice would be to convert an ouchtree into a data frame using as.data.frame() and then to perform analysis on that.

The resulting data frame is pretty self-explanatory. Each node (internal or terminal) gets a line. That line contains the following information: the name of the node, the name of its immediate ancestor, its time (the positive direction being the future), and an optional label.

from ouch.

mbutler808 avatar mbutler808 commented on July 21, 2024

Aloha @soungalo As Aaron says ouchtree does not have accessor functions for returning descendants, etc. But if you want to see the internal components, you can use the attributes function:

require(ouch)
x <- with(
   bimac,
   ouchtree(nodes=node,times=time/max(time),ancestors=ancestor,labels=species)
 )
attributes(x)
attributes(x)$nterm

and access the elements by name (or other standard methods) on the return object of attributes().

However, there are other packages that have treewalking functions such as tidytree and ape. Lately Iʻve been using tidytree (to work with the treedata object) and treeio (to read in the phylogenetic tree in many formats into treedata), which has functions for ancestors, descendants, MRCA, etc. https://yulab-smu.top/treedata-book/chapter2.html#accesor-tidytree

Marguerite

from ouch.

mbutler808 avatar mbutler808 commented on July 21, 2024

I an not sure what youʻre doing, but if you want to get it your tree back into ouchtree after editing it, you can get it into phylo format and then use ape2ouch()

require(treeio)
require(tidytree)
require(ouch)
td_tree  <- read.newick("mytree.tree")  # or read.iqtree, read.nexus, read.beast, etc.
#  ... some tree manipulations ...
phylo_tree <- td_tree %>% as.phylo 
ouch_tree <- ape2ouch(phylo_tree)

from ouch.

soungalo avatar soungalo commented on July 21, 2024

Thank you both!
@kingaa - for some reason I couldn't convert the ouch tree to a data frame:

> as.data.frame(otree)
Error in as.data.frame.default(otree): cannot coerce class ‘structure("ouchtree", package = "ouch")’ to a data.frame
Traceback:

1. as.data.frame(otree)
2. as.data.frame.default(otree)
3. stop(gettextf("cannot coerce class %s to a data.frame", sQuote(deparse(class(x))[1L])), 
 .     domain = NA)

I should have probably mentioned that the ouch tree was created using the convertTreeData function from SURFACE, so there might be something weird with the object I'm working with. In any case, it sounds like the easy way would be to go back to the original tree (phylo class) and work with it.

from ouch.

mbutler808 avatar mbutler808 commented on July 21, 2024

from ouch.

kingaa avatar kingaa commented on July 21, 2024

How about as(otree,"data.frame")?

from ouch.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.