Description of the issue
I've recently faced issues when using the function read.nextstrain.json on divergence trees (with divergence units in number of mutations). When using it on a json file (zika-divergence.json) obtained from a modified version of the Zika Nextstrain workflow,, I obtain the following error:
Session Info
library(treeio)
read.nextstrain.json("zika-divergence.json")
Error in `dplyr::bind_rows()`:
! Can't combine `..1$div` <integer> and `..2$div` <character>.
Run `rlang::last_trace()` to see where the error occurred.
Proposed solution
Playing with the source code, it looks like the error comes from the following line of code, with some nodes being loaded with a div variable as an integer and some as a character:
|
dat <- dplyr::bind_rows(as.list(id[["data"]])) %>% dplyr::mutate_if(check_num, as.numeric) |
Locally, I've managed to solve this by replacing:
|
if ('div' %in% colnames(id[['data']][[id[['id']]]])){ |
|
parent.index <- id[['data']][[id[['id']]]][['parentID']] |
|
id[['data']][[id[['id']]]][['branch.length']] <- as.numeric(id[['data']][[id[['id']]]][['div']]) - |
|
as.numeric(id[['data']][[parent.index]][['div']]) |
|
} |
by:
if ('div' %in% colnames(id[['data']][[id[['id']]]])){
parent.index <- id[['data']][[id[['id']]]][['parentID']]
# Systematically converting div to a numeric value
id[["data"]][[id[["id"]]]][["div"]] <- as.numeric(id[["data"]][[id[["id"]]]][["div"]])
id[['data']][[id[['id']]]][['branch.length']] <- id[['data']][[id[['id']]]][['div']] -
as.numeric(id[['data']][[parent.index]][['div']])
}
I'd be happy to submit a pull request regarding this. Would you have a preference regarding how to do this and whether it might be valuable to also add the json file (zika-divergence.json) ? I also noticed that read.nextstrain.json does not have a testing file. Would it make sense to include all of this as part of a testing file? If so, do you have suggestions on what the testing should check?
Thank you!
Description of the issue
I've recently faced issues when using the function
read.nextstrain.jsonon divergence trees (with divergence units in number of mutations). When using it on a json file (zika-divergence.json) obtained from a modified version of the Zika Nextstrain workflow,, I obtain the following error:Session Info
Proposed solution
Playing with the source code, it looks like the error comes from the following line of code, with some nodes being loaded with a
divvariable as an integer and some as a character:treeio/R/nextstrain.json.R
Line 53 in 9504617
Locally, I've managed to solve this by replacing:
treeio/R/nextstrain.json.R
Lines 39 to 43 in 9504617
by:
I'd be happy to submit a pull request regarding this. Would you have a preference regarding how to do this and whether it might be valuable to also add the json file (
zika-divergence.json) ? I also noticed thatread.nextstrain.jsondoes not have a testing file. Would it make sense to include all of this as part of a testing file? If so, do you have suggestions on what the testing should check?Thank you!