Added newick import/export

Issue #68 resolved
Jason Vander Heiden created an issue

Using the data.tree package seems the easiest path from igraph to newick format:

library(igraph)
library(data.tree)
tree <- FromDataFrameNetwork(as_data_frame(graph))
ToNewick(tree, heightAttribute=NULL)

Not sure what you want to do with the heightAttribute, but you could base it of the "weight" column instead of excluding it.

Comments (10)

  1. ssnn

    Using the data.tree package seems the easiest path from igraph to newick format:

    library(igraph)
    library(data.tree)
    tree <- FromDataFrameNetwork(as_data_frame(graph))
    ToNewick(tree, heightAttribute=NULL)
    

    Not sure what you want to do with the heightAttribute, but you could base it of the "weight" column instead of excluding it.

  2. Kenneth Hoehn

    I wrote a function for converting from R phylo objects to igraph to work with igphyml trees. I can add a more general function to do this though.

  3. Kenneth Hoehn

    Added phyloToGraph and graphToPhylo to allow for interconversion between phylo, igraph, and newick formats. Example:

    library(ape)
    library(igraph)
    library(phangorn)
    library(alakazam)
    library(shazam)
    library(dplyr)
    
    clone <- makeChangeoClone(subset(ExampleDb,CLONE == 3163))
    
    graph <- buildPhylipLineage(clone,
        "/home/kenneth/Programs/phylip-3.697/exe/dnapars",
        rm_temp=TRUE)
    
    #plot lineage tree
    plot(graph,layout=layout_as_tree)
    
    # convert to phylo
    phylo = graphToPhylo(graph)
    
    #plot using ape
    plot(phylo,show.node.label=TRUE)
    
    #store as newick tree
    write.tree(phylo,file="3163.newick")
    
    #read in tree
    phylo_r = read.tree("3163.newick")
    
    #convert to igraph
    graph_r = phyloToGraph(phylo_r,germline="Germline")
    
    #plot converted form - same as before
    plot(graph_r,layout=layout_as_tree)
    
    #convert back to phylo
    phylo_rr = graphToPhylo(graph_r)
    
    #tree topologies are the same
    phangorn::RF.dist(phylo,phylo_rr)
    
  4. Jason Vander Heiden reporter

    Awesome. Thanks. How do you feel about polishing this example a little and dropping into the end of the lineage vignette (vignettes/Lineage-Vignette.Rmd)?

  5. Jason Vander Heiden reporter

    Not much.

    Put some short section header text in explaining the point. Style fixes. Consistency with the rest of vignette (eg, there’s already an example of running phylip in the vignette, so no need to repeat). Make sure it passes check when in the vignette.

    Just make it jive with the rest of the vignette.

  6. Log in to comment