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

Error in draw.clade: invalid subscript type 'list' #31

Closed
ArtPoon opened this issue May 8, 2023 · 2 comments
Closed

Error in draw.clade: invalid subscript type 'list' #31

ArtPoon opened this issue May 8, 2023 · 2 comments

Comments

@ArtPoon
Copy link
Owner

ArtPoon commented May 8, 2023

Attempting to color branches in very large tree:

> # all sequences
> phy <- read.tree("~/git/flu/data/removeX.ft2.nwk")
> phy <- midpoint(phy)
> phy <- ladderize(phy)
> pal <- gg.rainbow(18)
> # it takes a couple of minutes to generate this layout
> L <- tree.layout(phy)
> res <- 300
> png("~/git/flu/test.png", width=5*res, height=8*res, res=res)
> plot(L, label='n')
> for (i in 1:18) {
+   print(i)
+   # note phy$tip.label == L2$nodes$label[1:Ntip(phy)]
+   idx <- which(grepl(paste("\\(H", i, "[N)]", sep=""), phy$tip.label))
+   draw.clade(L, tips=phy$tip.label[idx], col=pal[i])
+   # label clades using tip farthest from origin
+   #last.tip <- idx[which.max(L2$nodes$r[idx])]
+ }
[1] 1
Error in obj$edges$y0[parents] : invalid subscript type 'list'
@ArtPoon
Copy link
Owner Author

ArtPoon commented May 8, 2023

Looks like the problem is there:

ggfree/R/tree.R

Lines 1106 to 1109 in a9717ae

if (obj$layout == 'rectangular') {
parents <- sapply(e$parent, function(p) which(obj$edges$child==p))
segments(x0=e$x0, y0=e$y0, y1=obj$edges$y0[parents], col=col, ...)
}

This returns parents as a list, not an integer vector as expected:

> head(parents)
[[1]]
[1] 4

[[2]]
[1] 5

[[3]]
[1] 6

[[4]]
[1] 7

[[5]]
[1] 8

[[6]]
[1] 9
> table(sapply(parents, length))

    0     1 
    1 45598 
> which.min(sapply(parents, length))
[1] 45519
> parents[45519]
[[1]]
integer(0)
> e[45519,]
      parent child    length isTip x0        x1       y0       y1
86210  67061 84808 0.3695876 FALSE  0 0.3695876 65882.59 65882.59
> which(obj$edges$child == 67061)
integer(0)
> Ntip(phy)
[1] 67060

The node in question is the root.

@ArtPoon
Copy link
Owner Author

ArtPoon commented May 8, 2023

Potential fix:

@@ -1105,6 +1107,8 @@ draw.clade <- function(obj, tips, col='red', is.mono=TRUE, max.tips=100, ...) {
 
   if (obj$layout == 'rectangular') {
     parents <- sapply(e$parent, function(p) which(obj$edges$child==p))
+    # exclude root node
+    parents <- unlist(parents)
     segments(x0=e$x0, y0=e$y0, y1=obj$edges$y0[parents], col=col, ...)
   }
   else if (obj$layout == 'radial') {

But there are extra lines being drawn:
test

@ArtPoon ArtPoon closed this as completed in a0fc610 May 8, 2023
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