alexyermanos / Platypus

R package for the analysis of single-cell immune repertoires
GNU General Public License v3.0
36 stars 16 forks source link

Error in VDJ_clonal_expansion #22

Closed meaksu closed 1 year ago

meaksu commented 1 year ago

Hi again,

I am getting an error now when I run VDJ_clonal_expansion using Bcells. This only occurs when I change the group.by value to "group_id". It runs normally when grouping by "sample_id", however the group_id plots would be more useful for me. I'm not sure what would be causing this.

> clonal_out_BCR <- VDJ_clonal_expansion(VDJ = vgmBCR[[1]], celltype = "Bcells", clones = "30", group.by = "group_id", color.by = "isotype", isotypes.to.plot = "all")
Error in `$<-.data.frame`(`*tmp*`, "isotype", value = c("IGHA1", "IGHA1",  : 
  replacement has 9 rows, data has 10

Thanks!

vickreiner commented 1 year ago

Hi,

I tried to, but as not able to reproduce this with data that I have at hand. Could you run: table(vgmBCR[[1]]$group_id)

and: clonal_out_BCR <- VDJ_clonal_expansion(VDJ = vgmBCR[[1]], celltype = "Bcells", clones = "30", group.by = "group_id", color.by = "isotype", isotypes.to.plot = c("IGHG","IGHM","IGHA","IGHD","IGHE"))

It may have to do with an extra factor level in the group_id column which results in an empty or very small number of cells being subsetted for plotting.

Thanks!

meaksu commented 1 year ago

Running the first gives me this:

> table(vgmBCR[[1]]$group_id)

   1    2    3    7    8    9 
5407 3396 1828 5709 2465 2356 

The second line also produces the same error:

> clonal_out_BCR <- VDJ_clonal_expansion(VDJ = vgmBCR[[1]], celltype = "Bcells", clones = "30", group.by = "group_id", color.by = "isotype", isotypes.to.plot = c("IGHG","IGHM","IGHA","IGHD","IGHE"))
New ranking based only on selected isotypes: 
clonotype1clonotype2clonotype3clonotype4clonotype5clonotype6clonotype7clonotype8clonotype10clonotype11clonotype9clonotype12clonotype13clonotype14clonotype15clonotype16clonotype17clonotype18clonotype19clonotype20clonotype21clonotype22clonotype23clonotype24clonotype25clonotype26clonotype27clonotype28clonotype29clonotype30
Error in `$<-.data.frame`(`*tmp*`, "isotype", value = c("IGHA1", "IGHA1",  : 
  replacement has 9 rows, data has 10
meaksu commented 1 year ago

I may have figured this out, the problem seems to be in group 2, since removing this group gets rid of the error. Using group 2 alone the error shows up when the "clones" parameter is greater than 16, setting this parameter to 16 or less gets rid of the error. If I'm interpreting this right, it seems like for group 2 there is only 16 uniquely expanded clones. But I'm still not sure why it would run when using sample_id instead of group_id.

vickreiner commented 1 year ago

Hi! Thanks a lot for following up on this. I will try to replicate this scenario and if possible push a fix for it

vickreiner commented 1 year ago

Hi! Again I tried to replicate this error with some of my own data but was not able to. Could you pull the newest version of this function from Github, to see if this is possibly a version issue.

devtools::source_url("https://raw.githubusercontent.com/alexyermanos/Platypus/master/R/VDJ_clonal_expansion.R")

Thanks!