-
Notifications
You must be signed in to change notification settings - Fork 1
/
FUN_GSEA_ForOFFL.R
49 lines (39 loc) · 1.62 KB
/
FUN_GSEA_ForOFFL.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## Build files for GSEA official input
FUN_GSEA_ForOFFL = function(GeneExp.df,
Group1 = Group1.set, Group2 = Group2.set,
Group1Name = Group1_Name,Group2Name = Group2_Name,
SavePath = SavePath, ExportName = ExportName,
AnnoName = "AvB"
){
##### Build Expression matrix for GSEA #####
GeneExp_GSEA.df <- cbind(
NAME=row.names(GeneExp.df),
Description = rep("na", nrow(GeneExp.df)),
GeneExp.df[,c(Group1, Group2)]
)
GSEA_SampleCol.df <- data.frame(t(colnames(GeneExp_GSEA.df)), stringsAsFactors=FALSE)
colnames(GSEA_SampleCol.df) <- GSEA_SampleCol.df
GeneExp_GSEA.df <- rbind(GSEA_SampleCol.df,GeneExp_GSEA.df)
GeneExp_GSEA.df <- data.frame(
"NAME" = c("#1.2",nrow(GeneExp.df)),
"Description" = c('',length(c(Group1, Group2)))
) %>%
rbind.fill(GeneExp_GSEA.df)
rm(GSEA_SampleCol.df)
##### Build Group Files #####
## Set the group array
Pheno_sum.df <- c(ncol(GeneExp_GSEA.df)-2,2,1) %>% t() %>% data.frame() %>%
rbind.fill(c(paste0("#",Group1Name),paste0(Group2Name)) %>% t() %>% data.frame(stringsAsFactors=FALSE)) %>%
rbind.fill(c(rep(0,length(Group1)),rep(1,length(Group2))) %>% t() %>% data.frame())
##### Export Result #####
write.table(
GeneExp_GSEA.df,
file=paste0(SavePath,"/OFFL_GSEA_",ExportName,AnnoName,"_collapsed.gct"),
quote = FALSE,row.names = FALSE,col.names = FALSE, na = "",sep = '\t'
)
write.table(
Pheno_sum.df,
file=paste0(SavePath,"/OFFL_GSEA_",ExportName,AnnoName,".cls"),
quote = FALSE,row.names = FALSE, na = "",col.names = FALSE
)
}