问题描述
我想计算每个组织类别(肿瘤和基质)中每种表型(Ki67、cPARP、阴性)细胞的数量。我已经成功地制作了 2 个名为 Tumor 和 Stroma 的额外列,它将两个组织类别从之前的一个(组织类别)分为两列。
我想要总共 6 个新列,它们是 Tumor Ki67、Stroma Ki67、Tumor cPARP、Stroma
cPARP、Tumor Negative、Stroma Negative,这些将具有唯一的细胞 ID,然后我可以使用函数计数来计算这些列中的每一列中的单个细胞。我附上了我到目前为止所做的事情的图片。
这是我目前拥有的
library(tidyverse)
library(phenoptr)
mydata <- read_cell_seg_data(choose.files())
mydatabackup <- mydata
#what are the unique phenotypes?
unique_phenotypes(mydata)
colnames(mydata)
#what are the unique tissue categories?
TissueCategory_Column <- mydata$`Tissue Category`
length(TissueCategory_Column)
TissueCategory_unique <- unique(TissueCategory_Column)
length(TissueCategory_unique)
#how do you filter on tumour and stroma to remove cells identified in necrosis and background?
filter_tc <- mydata %>% filter(`Tissue Category`!="Background",`Tissue Category`!= "Necrosis")
#how many of each phenotype are there in the tumour and the stroma?
count(filter_tc,'Tissue Category',Phenotype)
library(tidyverse)
data_wide <- spread(filter_tc,Phenotype)
data_wide
how many of each phenotype are there in the tumour and the stroma?
lapply(unique(filter_tc$Phenotype),function(x){ sum(filter_tc$Phenotype==x) })
原表:
解决方法
当您尝试使用 count 时,它不起作用,因为 'Tissue Category'
周围有引号。改用反引号:
count(tissue_tc,`Tissue Category`,Phenotype)
当您使用引号时,您指的是字符串 'Tissue Category'
而不是列 Tissue Category
。