我尝试制作函数图或我的前 20 个基因。这就是为什么我创建了一个数据框列表,这些数据框存在或不同的列包含值和名称。数据框中的这些列之一是基因列。我的代码将前 20 个基因变成了函数图。但是现在我在一些存在少于 20 个基因的数据框中遇到了问题。这会导致我的代码中止。
因为我希望每页最多 5 个函数图,所以我不能只定义一个计数器。
谢谢你的反馈。
我的列表或数据框 listGroups 示例
group1_2: 'data.frame': 68 obs. of 7 variables:
..$ p_val: num [1:68] 1.15 1.43 ...
..$ score: num [1:68] 15.5 27.14 ...
..$ gene: Factor w/ 68 levels "BRA1", "NED",...: 41 52 ...
group2_3: 'data.frame': 3 obs. of 7 variables:
..$ p_val: num [1:3] 1.15 1.43 ...
..$ score: num [1:3] 15.5 27.14 ...
..$ gene: Factor w/ 3 levels "BCL12", "DEF1",...: 41 52 ...
代码
groupNames <- c("cluster1_2","cluster2_3","cluster3_4","cluster4_5","cluster5_6")
for (i in 1:length(listGroups)) {
Grouplist <- listGroups[[i]]
genesList <- Grouplist['gene']
lengths(geneList)
print(groupNames[i])
# Make Featureplots for top20 DE genes per cluster_group
pdf(file=paste0(sampleFolder,"/Featureplots_cluster_",groupNames[i],"_",sampleName,".pdf"))
print(FeaturePlot(object = seuratObj, features = c(as.character(genesList[1:5,]))))
print(FeaturePlot(object = seuratObj, features = c(as.character(genesList[6:10,]))))
print(FeaturePlot(object = seuratObj, features = c(as.character(genesList[11:15,]))))
print(FeaturePlot(object = seuratObj, features = c(as.character(genesList[16:20,]))))
dev.off()
}