Problem with Newick format - ggtree in R
1
1
Entering edit mode
7 months ago
Toupaie ▴ 10

Hello everyone,

I have a rookie question but unfortunately I am unable to find an answer myself. I would like to generate a cladrogram using ggtree package based on the taxonomy of my strains.

As I know the taxonomic classification of he strains I thought that I could use that to generate a tree in Newick format, for that I used the makeNewick function from the Taxonomizr package.

setwd("D:/R/phylogeny/Jemime_collection")
taxofile<-"cladotest.tab" 
Taxo <-  read.table (taxofile, check.names = FALSE, header = TRUE, dec = ".", sep = "\t", comment.char = "")

which got me this, so far so good:

Taxo

     family         genus                         species
     1  Actinomycetaceae Actinobaculum Actinobaculum_sp_oral_taxon_183
     2  Actinomycetaceae   Actinomyces  Actinomyces_bouchesdurhonensis
     3  Actinomycetaceae   Actinomyces            Actinomyces_dentalis
     4  Actinomycetaceae   Actinomyces        Actinomyces_gerencseriae
     5  Actinomycetaceae   Actinomyces        Actinomyces_graevenitzii
     6  Actinomycetaceae   Actinomyces            Actinomyces_israelii
     7  Actinomycetaceae   Actinomyces           Actinomyces_johnsonii
     8  Actinomycetaceae   Actinomyces        Actinomyces_massiliensis
     9  Actinomycetaceae   Actinomyces          Actinomyces_naeslundii
    10 Actinomycetaceae   Actinomyces                Actinomyces_oris
    11 Actinomycetaceae   Actinomyces            Actinomyces_SGB17154
    12 Actinomycetaceae   Actinomyces            Actinomyces_SGB17168
    13 Actinomycetaceae   Actinomyces            Actinomyces_sp_ICM47

After that I tried to generate a newick tree from this using the makenewick function, which seemed to work :

tree <- makeNewick(Taxo)
tree
      [1] "(((Actinobaculum_sp_oral_taxon_183)Actinobaculum,(Actinomyces_bouchesdurhonensis,Actinomyces_dentalis,Actinomyces_gerencseriae,Actinomyces_graevenitzii,Actinomyces_israelii,Actinomyces_johnsonii,Actinomyces_massiliensis,Actinomyces_naeslundii,Actinomyces_oris,Actinomyces_SGB17154,Actinomyces_SGB17168,Actinomyces_sp_ICM47)Actinomyces)Actinomycetaceae);"

However, when I tried to use this newick tree to generate the tree I got an error message:

ggtree(tree)

 > Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, not the string "(((Actinobaculum_sp_oral_ta...".
Run `rlang::last_trace()` to see where the error occurred.

I ran line indicated and got this:

<error/rlang_error>
Error in `fortify()`:
! `data` must be a <data.frame>, or an object coercible by `fortify()`, not the string "(((Actinobaculum_sp_oral_ta...".
---
Backtrace:
Run rlang::last_trace(drop = FALSE) to see 2 hidden frames.

Which did not help me understand how and why my tree was not data.frame and how to convert it into a data.frame.

Has anyone an idea on how to solve this problem?

R ggtree makeNewick taxonomizr • 703 views
ADD COMMENT
0
Entering edit mode

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or use one of (a) the option highlighted in the image below/ (b) fenced code blocks for multi-line code. Fenced code blocks are useful in syntax highlighting. If your code has long lines with a single command, break those lines into multiple lines with proper escape sequences so they're easier to read and still run when copy-pasted. I've done it for you this time.
code_formatting

ADD REPLY
0
Entering edit mode

Thank you, my apologies for the improper formating.

ADD REPLY
1
Entering edit mode
7 months ago
cfos4698 ★ 1.1k

The output of makeNewick() is a character string. It needs to be a data.frame or phylo class to work with ggtree. You have some options:

# Option 1: convert string to phylo within R
tree_string <- "(((Actinobaculum_sp_oral_taxon_183)Actinobaculum,(Actinomyces_bouchesdurhonensis,Actinomyces_dentalis,Actinomyces_gerencseriae,Actinomyces_graevenitzii,Actinomyces_israelii,Actinomyces_johnsonii,Actinomyces_massiliensis,Actinomyces_naeslundii,Actinomyces_oris,Actinomyces_SGB17154,Actinomyces_SGB17168,Actinomyces_sp_ICM47)Actinomyces)Actinomycetaceae);"
phylo_tree <- ape::read.tree(text = tree_string)
ggtree(phylo_tree)
# Option 2: write string to file, read in as tree
tree_string <- "(((Actinobaculum_sp_oral_taxon_183)Actinobaculum,(Actinomyces_bouchesdurhonensis,Actinomyces_dentalis,Actinomyces_gerencseriae,Actinomyces_graevenitzii,Actinomyces_israelii,Actinomyces_johnsonii,Actinomyces_massiliensis,Actinomyces_naeslundii,Actinomyces_oris,Actinomyces_SGB17154,Actinomyces_SGB17168,Actinomyces_sp_ICM47)Actinomyces)Actinomycetaceae);"
writeLines(tree_string, "tree.nwk")
tree_in <- treeio::read.newick("tree.nwk")
ggtree(tree_in)
ADD COMMENT
0
Entering edit mode

I just tried Option 1 and it worked perfectly, thank you so much ! Overal I understood the format problem but was unable to find the ape::read.tree() function myself, thank you again !

ADD REPLY

Login before adding your answer.

Traffic: 888 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6