-
Notifications
You must be signed in to change notification settings - Fork 26
as.treedata is not compatible with merge manipulation? #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
tbl_tree attribute was lost when using merge. It would be OK if you use
full_join, or using the following code:
class(Tre_tb_t) <- c("tbl_tree", class(Tre_tb_t))
Tre_tb_t %>% as.treedata()
|
@GuangchuangYu Thank you! I tried to make it work by using full_join and it is good to know that the class can be assigned. It seems that without the "tbl_tree" attribute, check_edgelist <- function(edgelist) {
if (dim(edgelist)[2] < 2)
stop("input should be a matrix of edge list that holds the relationships in the first two columns")
if (length(unique(edgelist[[1]])) > length(unique(edgelist[[2]]))) {
children <- edgelist[[1]]
parents <- edgelist[[2]]
} else {
children <- edgelist[[2]]
parents <- edgelist[[1]]
}
root <- unique(parents[!(parents %in% children)])
if (length(root) != 1)
stop("Cannot find root. network is not a tree!")
matrix(c(parents, children), ncol=2)
} The line Thanks! |
I noticed this either. I think a better solution is to implemented a If you install the github version of # This is a tree I created using the taxonomy info of several genera, the branch length is fake
Tre = "(((((D_5_-G1:20)D_4_Enterobacteriaceae:20)D_3_Enterobacteriales:20)D_2_Gammaproteobacteria:20)D_1_Proteobacteria:20,((((D_5_Agathobacter-G2:20,D_5_CAG.56-G3:20)D_4_Lachnospiraceae:20,(D_5_Ruminococcaceae.UCG.010-G10:20)D_4_Ruminococcaceae:20)D_3_Clostridiales:20)D_2_Clostridia:20,(((D_5_Asteroleplasma-G4:20)D_4_Erysipelotrichaceae:20)D_3_Erysipelotrichales:20)D_2_Erysipelotrichia:20,(((D_5_Dialister-G9:20)D_4_Veillonellaceae:20)D_3_Selenomonadales:20)D_2_Negativicutes:20)D_1_Firmicutes:20,((((D_5_Bacteroides-G5:20)D_4_Bacteroidaceae:20)D_3_Bacteroidales:20)D_2_Bacteroidia:20)D_1_Bacteroidetes:20,((((D_5_Candidatus.Lumbricincola-G6:20)D_4_Mycoplasmataceae:20)D_3_Mycoplasmatales:20,((D_5_uncultured.bacterium-G7:20)D_4_uncultured.bacterium:20,(D_5_-G8:20)D_4_:20)D_3_Mollicutes.RF39:20)D_2_Mollicutes:20)D_1_Tenericutes:20)D_0_Bacteria:1;"
# convert to treeio tree object
Tre_td <- as.treedata(ape::read.tree(text = Tre))
# convert to tibble
Tre_tb <- as_tibble(Tre_td)
str(Tre_tb)
# test manipulation
#############################
## now merge(tbl_tree, ...) output tbl_tree object
##############################
Tre_tb_t <- merge(Tre_tb, Tre_tb %>% select(4) %>% mutate(Test = "AAA"), by.x = 4, by.y =1)
str(Tre_tb_t)
Tre_tb_t %>% as.treedata() |
Thanks for the quick fix. |
Prerequisites
Describe you issue
I was having trouble with "the manipulating tree data using tidy interface". Briefly, I have a tree file created and converted to a tibble using
as_tibble
, but after some manipulation, this tibble cannot be converted back by as.treedata.After doing some digging, I think the problem is due to
merge
is not compatible withtreeio
. The output ofstr(Tre_tb)
shows(S3: tbl_tree/tbl_df/tbl/data.frame)
; however, the output ofstr(Tre_tb_t)
shows(S3: tbl_df/tbl/data.frame)
. This won't happen if the manipulation is performed usingdplyr
. I guess this is where the problem arises.A side note, for some reason, the
as_tibble(Tre_td)
will generate a warning message:not sure why?
Thank you!
Jincheng
Session Info
The text was updated successfully, but these errors were encountered: