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

Phylo.to.map Error in res[edge[i, 2]] <- res[edge[i, 1]] + el[i] : replacement has length zero #83

Open
Kelzor opened this issue Jan 18, 2021 · 2 comments

Comments

@Kelzor
Copy link

Kelzor commented Jan 18, 2021

I am trying to create a plot with phylo.to.map using the following code.

library(phytools)
library(phylotools)
library(mapdata)

tree <- read.newick("barebones_MP_500BS.nwk")
tipdat <- read.csv("tip_names.csv", header = FALSE)
coord1 <- read.csv("coordinates.csv", header = TRUE)
coord1 <- coord1[ -c(1)]
coord2 <- coord1[,-1]
coord2 <- data.matrix(coord2)
rownames(coord2) <- coord1[,1]

labeledtree <- sub.taxa.label(tree, tipdat)
rootedtree <- root(labeledtree, outgroup= "M. canetti", resolve.root = TRUE)

rootedtree

Phylogenetic tree with 18 tips and 17 internal nodes.

Tip labels:
  L3, L2, L4, L7, L1, L5, ...
Node labels:
  Root, 1.0000, 0.9960, 1.0000, 1.0000, 1.0000, ...

Rooted; no branch lengths.

obj<-phylo.to.map(rootedtree, coord2, plot=FALSE)

objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 46
objective: 26

plot(obj, ftype="i")

Error in res[edge[i, 2]] <- res[edge[i, 1]] + el[i] : 
  replacement has length zero

Everything seems to work as expected until plot(). I can't figure out why a 0 value is being returned. Is it a problem with my tree file? Any help would be greatly appreciated!

tree file:
barebones_MP_500BS.txt

tip names file:
tip_names.txt

coordinate file:
coordinates.txt

@twooldridge
Copy link

twooldridge commented Mar 25, 2021

Hi Kelzor, I'm having an identical issue, and I believe it's because there are no edge lengths in the tree. I would prefer to plot this as a cladogram, as in my case I have a tree generated by ASTRAL (https://github.com/smirarab/ASTRAL/blob/master/astral-tutorial.md#branch-length-and-support) where some terminal branches don't have lengths by design. So I'm unsure how to proceed here. Let me know if you've arrived at a solution, I'll keep troubleshooting

@twooldridge
Copy link

Just minutes after posting this, I think I found a quick and dirty solution. I 'reset' my branch lengths with ape using compute.brlen. It will automatically calculate branch lengths for display as a cladogram (where branch lengths are meaningless):

rooted$branch.length = NULL
rooted_cladogram = ape::compute.brlen(rooted)

And then if you use rooted_cladogram, the rest should work, hopefully!

Brock

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

2 participants