hdng / clonevol

Inferring and visualizing clonal evolution in multi-sample cancer sequencing
GNU General Public License v3.0
141 stars 45 forks source link

plot.all.trees.clone.as.branch -bug with branches name #41

Open qingjian1991 opened 4 years ago

qingjian1991 commented 4 years ago

Hi, I find a bug within the plot.all.trees.clone.as.branch(). When the founding clone is not 1, then there is a bug when plot the tree.

My code is as following:

#The default founding clone is 7, rather than 1 
y = infer.clonal.models(variants = mutdata,
   cluster.col.name = cluster.col.name,
   ccf.col.names = vaf.col.names,
   cancer.initiation.model="monoclonal",
   subclonal.test = "bootstrap",
   subclonal.test.model = "non-parametric",
   num.boots = 2000,
   founding.cluster = 7)

plot.all.trees.clone.as.branch(y, branch.width = 0.5,
    node.size = 1, node.label.size = 0.5)

leading to this error.

Error in x0[i] <- x1[which(x$branches == parent)] 

Solution is here:

The sub-fucntion germinate from plot.all.trees.clone.as.branch removed the "Y" branch with the code below. Your original code assumes the first branches is "Y", in some case, the "Y" brance is not the the first one.

#The first branch is not "Y"
y$matched$merged.trees[[1]]$branches
[1] "1"   "2"   "3"   "20"  "200" "Y"  

#your original code of germinate()
    x <- list(trunk.height=x$length[1],
              branches=x$branches[-1],
              lengths=x$lengths[-1],
              branch.colors=x$branch.colors[-1],
              branch.border.colors=x$branch.border.colors[-1],
              branch.border.linetypes=x$branch.border.linetypes[-1],
              branch.border.widths=x$branch.border.widths[-1],
              node.colors=x$node.colors[-1],
              node.border.colors=x$node.border.colors[-1],
              node.border.widths=x$node.border.widths[-1],
              node.labels=x$node.labels[-1],
              node.texts=x$node.texts[-1],
              branch.texts=x$branch.texts[-1])

The follwing code will solve this error.

 #update code in germinate()   
id = which(x$branches == "Y")

    x <- list(trunk.height=x$length[1],
              branches=x$branches[-id],
              lengths=x$lengths[-id],
              branch.colors=x$branch.colors[-id],
              branch.border.colors=x$branch.border.colors[-id],
              branch.border.linetypes=x$branch.border.linetypes[-id],
              branch.border.widths=x$branch.border.widths[-id],
              node.colors=x$node.colors[-id],
              node.border.colors=x$node.border.colors[-id],
              node.border.widths=x$node.border.widths[-id],
              node.labels=x$node.labels[-id],
              node.texts=x$node.texts[-id],
              branch.texts=x$branch.texts[-id])

Thanks for a very useful package!

Qingjian Chen

Sun Yat-Sen University Cancer Center (SYSUCC)

daisyyr commented 2 years ago

Thanks for your answer! It's really useful. I've encountered the same problem. BTW, where can I find the source code for germinate() function ? I could not find it under the clonovol R package.

eidamama commented 1 year ago

Hi qingjiang Thank you so much for the bug fixing code. I replaced the part in "trees.package.r" with your code but still the same error message came out. Which file did you modify?

Thank you and best