细胞与免疫免疫组库单细胞免疫组库

免疫组库多样性(Richness/Diversity/Clona

2022-02-25  本文已影响0人  不会生信

Calculation of repertoire metrics

VDJTOOLS的CalcDiversityStats函数提供了直接计算功能,详情参考免疫组库分析实战/mixcr+vdjtools+R实现使用vdjtools进行免疫组库分析.
本文以TRUST4的结果为例(基本都大同小异),展示如何计算免疫组库的Richness/Diversity/Clonality

trust4.report

代码实现(R)

Shannon_index <- function(list_p){
  sum=0
  for (p in list_p){
    sum <- p*log(p) + sum
  }
  H <- -sum
  return(H)
}
clonality <- function(diversity,richness){
  E<- diversity/log(richness)
  C <- 1-E
  return(C)
}

sample_id <- c(paste0("sample",1:10))
results <- data.frame(sample_id)

for (i in 1:length(sample_id)){
  df <- read.csv(file = paste0(sample_id[i],".txt"),
                    stringsAsFactors = F,sep = "\t")
  list_p <- df[,"frequency"]
  results[i,"richness"] <- nrow(df)
  results[i,"diversity"] <- Shannon_index(list_p)
  results[i,"clonality"] <- 1-clonality(Shannon_index(list_p),nrow(df))
}
write.table(results,filename,sep = "\t",row.names = F,quote = F)
上一篇下一篇

猜你喜欢

热点阅读