alexyermanos / Platypus

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

VDJ_diversity grouping.column doesn't accept seurat_clusters as a factor #56

Open jianwu1 opened 1 year ago

jianwu1 commented 1 year ago

Hi,

I'm interested seeing if TCR from different seurat clusters have different antigen specificity by doing:

VDJ_diversity(
  VDJ = vgm$VDJ,
  feature.columns = c("VDJ_cdr3s_aa", "VJ_cdr3s_aa"),
  grouping.column = "seurat_clusters",
  metric = c("jaccard"), 
  VDJ.VJ.1chain = T,
  subsample.to.same.n = T)

However my seurat_clusters is a factor rather than character and it gives error:

Screen Shot 2023-07-08 at 10 47 16 am

The error goes away when I convert seurat_clusters to character, but the ordering of clusters are not in accordance with its numerical order.

VDJ_diversity(
  VDJ = vgm$VDJ %>% mutate(seurat_clusters = as.character(seurat_clusters)) ,
  feature.columns = c("VDJ_cdr3s_aa", "VJ_cdr3s_aa"),
  grouping.column = "seurat_clusters",
  metric = c("jaccard"), 
  VDJ.VJ.1chain = T,
  subsample.to.same.n = T
  )

image

I tried to edit plot_beta_diversity function in VDJ_diversity.R with fct_reorder():

Screen Shot 2023-07-08 at 11 02 00 am

and it worked: image but this would be a problem when group_column is a character that can't be converted to numeric.

Alternatively, I tried to inspect why VDJ_diversity gives an error when group.column is a factor: It might be that a comma at the location highlighted by ??? is missing (in VDJ_abundances.R), but adding that led to a few other errors which I can't resolve.

Screen Shot 2023-07-08 at 11 10 50 am