Skip to content
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

read.nextstrain.json fails on divergence trees #126

Open
CecileTK opened this issue Jul 9, 2024 · 0 comments
Open

read.nextstrain.json fails on divergence trees #126

CecileTK opened this issue Jul 9, 2024 · 0 comments

Comments

@CecileTK
Copy link

CecileTK commented Jul 9, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant