hdng / clonevol

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

Error : “attempt to select less than one element in get1index” #9

Closed Tn00 closed 6 years ago

Tn00 commented 7 years ago

I'm a beginner in R and I'm trying to use the package ClonEvol, however the documentation on the github webpage is very limited. So for now I'm using their example code and trying to adapt it to my data called ce.

ce <- data.frame(
  cluster = c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7),
  gene = c("geneA","geneB","geneC","geneD","geneA","geneB","geneC","geneD","geneA","geneB","geneC","geneD","geneA","geneB","geneC",
 "geneD","geneA","geneB","geneC","geneD","geneA","geneB","geneC","geneD","geneA","geneB","geneC","geneD"),
  prim.vaf = c(0.5,0,0,0,0.5,0.5,0,0,1,0.5,0,0,1,0.5,0,0.5,0.5,0.5,0,0.5,0.5,0.5,0,1,0.5,0.5,0.5,0)
        )

    cluster <- ce$cluster
    gene <- ce$gene
    prim.vaf <- ce$prim.vaf

    x <- ce

    vaf.col.names <- grep('prim.vaf', colnames(x), value=T)
    sample.names <- gsub('prim.vaf', '', vaf.col.names)
    x[, sample.names] <- x[, vaf.col.names]
    vaf.col.names <- sample.names
    sample.groups <- c('P', 'R');
    names(sample.groups) <- vaf.col.names
    x <- x[order(x$cluster),]

    pdf('box.pdf', width = 3, height = 5, useDingbats = FALSE, title='')
    pp <- variant.box.plot(x,
   cluster.col.name = ce$cluster,
   show.cluster.size = FALSE,
   cluster.size.text.color = 'blue',
   vaf.col.names = vaf.col.names,
   vaf.limits = 70,
   sample.title.size = 20,
   violin = FALSE,
   box = FALSE,
   jitter = TRUE,
   jitter.shape = 1,
   jitter.color = clone.colors,
   jitter.size = 3,
   jitter.alpha = 1,
   jitter.center.method = 'median',
   jitter.center.size = 1,
   jitter.center.color = 'darkgray',
   jitter.center.display.value = 'none',
   highlight = 'is.driver',
   highlight.note.col.name = 'gene',
   highlight.note.size = 2,
   highlight.shape =16,
   order.by.total.vaf = FALSE
    )
    dev.off()

However, I get the following error : Error in .subset2(x, i, exact = exact) : recursive indexing failed at level 2

And if I delete cluster.col.name=ce$cluster and vaf.col.names=vaf.col.names, the error becomes the following :

    Error in .subset2(x, i, exact = exact) : attempt to select less than one     
    element in get1index

Has someone any idea of what went wrong ?

hdng commented 7 years ago

Sorry that the document is brief. I am working on a more comprehensive document and will update shortly.

Regarding the errors, several things were not right:

1) vaf.col.names should be a vector/string of the names of the columns where vaf is held in the data frame x. Your code created an empty string for vaf.col.names, due to this command:

sample.names <- gsub('prim.vaf', '', vaf.col.names)

that should better be:

sample.names <- gsub('.vaf', '', vaf.col.names)

2) Cluster column name should be a string, (eg. cluster.col.name = "cluster" ).

There is also a running bug on one sample analysis. The trick to overcome this is to create a second sample that is exactly the same as the sample you have but with different name/vaf column name, and trick ClonEvol to think that there are two samples. See also https://github.com/hdng/clonevol/issues/8.

Tn00 commented 7 years ago

Thank you for your help ! It is indeed better.