
正文
R 动态定义变量名 assign
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
rm(list=ls()) library(GSVA)
library(GSEABase)
library(GSVAdata)
library(msigdbr)
library(org.Hs.eg.db)
library(Seurat)
library(Rtsne)
setwd("/heartdata8t_A/zhangpeng/Final.results/Final_Project_III/GSVA") ### Merging the cannicalc2BroadSets
data(c2BroadSets)
canonicalC2BroadSets <- c2BroadSets[c(grep("^KEGG", names(c2BroadSets)),
grep("^REACTOME", names(c2BroadSets)),
grep("^BIOCARTA", names(c2BroadSets)))]
## Adding Hallmark genesets
m_df = msigdbr(species = "Homo sapiens", category = "H")
gset.all <- unique(m_df$gs_name) for(geneset_i in :length(gset.all)){
names_geneset_i <- gset.all[geneset_i]
entrez_gene_geneset_i <- as.character(unique(m_df$entrez_gene[which(m_df$gs_name == gset.all[geneset_i])]))
HallMarks <- GeneSet(entrez_gene_geneset_i, geneIdType=EntrezIdentifier(),
collectionType=BroadCollection(category="c2"), setName=names_geneset_i)
canonicalC2BroadSets <- GeneSetCollection(c(canonicalC2BroadSets, HallMarks))
} ## Adding human-curated genesets (GEO/Cancer)
load("GC.signature.Rdata")
GC.signature <- as.character(mapIds(org.Hs.eg.db, GC.signature, 'ENTREZID', 'SYMBOL'))
GC.signature <- GeneSet(GC.signature, geneIdType=EntrezIdentifier(),
collectionType=BroadCollection(category="c2"), setName="GC.signature")
canonicalC2BroadSets <- GeneSetCollection(c(canonicalC2BroadSets, GC.signature)) load("GC.signature.literature.Rdata")
GC.signature.literature <- as.character(mapIds(org.Hs.eg.db, GC.signature.literature, 'ENTREZID', 'SYMBOL'))
GC.signature.literature <- GeneSet(GC.signature.literature, geneIdType=EntrezIdentifier(),
collectionType=BroadCollection(category="c2"), setName="GC.signature.literature")
canonicalC2BroadSets <- GeneSetCollection(c(canonicalC2BroadSets, GC.signature.literature)) # Computing the GSVA score based the above curated datasets
load("subset.epithelial.cells.gc.signature.Rdata")
processed.data <- as.matrix(epithelial.cells.re.subset.GC.signature@assays$SCT@counts) rownames.processed.data <- rownames(processed.data)
entrez.rownames.processed.data <- as.character(mapIds(org.Hs.eg.db, rownames.processed.data , 'ENTREZID', 'SYMBOL')) invalid.index <- which(is.na(entrez.rownames.processed.data))
processed.data <- processed.data[-invalid.index,]
rownames(processed.data) <- entrez.rownames.processed.data[-invalid.index] esmicro.processed <- gsva(processed.data, canonicalC2BroadSets, min.sz=, max.sz=,
mx.diff=TRUE, verbose=FALSE, parallel.sz=, kcdf = "Poisson")
## Results
# library(pheatmap)
# esmicro.processed <- esmicro.processed[grep("KEGG",rownames(esmicro.processed)),]
# pheatmap(esmicro.processed) save(esmicro.processed,file = "esmicro.processed.Rdata")
tsne <- Rtsne(esmicro.processed,dims = )
plot(tsne$Y) epi<-epithelial.cells.re@meta.data
bb<-epi$SCT_snn_res.[which(epi$SCT_snn_res. ==)] bb<-epi[which(epi[,]==),]
cc<-epi[which(epi[,]==),]
aa<-rbind(bb,cc)
g1.index<-rownames(aa)
pro<- esmicro.processed
g1<-pro[ , which(colnames(pro) %in% g1.index )]
g2<-pro[ , -which(colnames(pro) %in% g1.index )] heatmap(pro) pathway_name = rownames(g1)
tm <- list('P-value' = c(), 'Pathway_name' = c()) cell.types <- unique(Idents(epithelial.cells.re)) library(pryr)
#setClass("All_results", slots = list(C0_results = "data.frame"))
#all_results <- new("All_results", C0_results = tm) cell.types #for(i in :length(cell.types)){
# print((as.numeric(cell.types[i])))
#name = paste0("tm_",as.numeric(cell.types[i]))
#eval(parse( name ) )<- list('P-value' = c(), 'Pathway_name' = c())
#append(all_ans,list(name = c())) #} for(j in cell.types){
cc<-epi[which(epi[,]==j),]
index<-rownames(cc)
g1<-pro[ , which(colnames(pro) %in% index )]
pathway_name = rownames(g1)
g2<-pro[ , -which(colnames(pro) %in% index )]
tm <- list('P-value' = c(), 'Pathway_name' = c())
## t.test
for(i in :dim(g1)[]){
results<- t.test(g1[i,],g2[i,])$p.value
tm$`P-value`<-append(tm$`P-value`,results)
tm$Pathway_name<- append(tm$Pathway_name,pathway_name[i])
}
assign(paste("tm_",j,sep = ""),tm)
} print(results) data.frame()
p.val,pathway_name result[[celltype_i]] <- data.frame dftm<- data.frame(tm)
dftm <- dftm[sort(dftm$P.value,index.return=TRUE)$ix,] down <- sample(colnames(pro),round(nrow(pro)/))
a<-pro[,down]
heatmap(a) raw.data result <- list() cell.types <- unique(Idents(epithelial.cells.re)) for(celltype_i in cell.types){ ## t.test data.frame()
p.val,pathway_name result[[celltype_i]] <- data.frame }
主要部分“
for(j in cell.types){
cc<-epi[which(epi[,]==j),]
index<-rownames(cc)
g1<-pro[ , which(colnames(pro) %in% index )]
pathway_name = rownames(g1)
g2<-pro[ , -which(colnames(pro) %in% index )]
tm <- list('P-value' = c(), 'Pathway_name' = c())
## t.test
for(i in :dim(g1)[]){
results<- t.test(g1[i,],g2[i,])$p.value
tm$`P-value`<-append(tm$`P-value`,results)
tm$Pathway_name<- append(tm$Pathway_name,pathway_name[i])
}
assign(paste("tm_",j,sep = ""),tm)
}
print(results)







