go term下的所有通路bp go.db

rna_msc_match <- list()
i=1
for (eachterm in a) {
  # Check if GOBPOFFSPRING has the term, otherwise use GOMFOFFSPRING
  if ( eachterm %in% (union(as.list(GOBPOFFSPRING[[eachterm]]) %>% unlist() %>% unname(), eachterm)) ) {
    target_terms <- union(as.list(GOBPOFFSPRING[[eachterm]]) %>% unlist() %>% unname(), eachterm)
    print(paste0(eachterm,"___第几个::",i, "-========================GO============================================="))
  } else {
    target_terms <- union(as.list(GOMFOFFSPRING[[eachterm]]) %>% unlist() %>% unname(), eachterm)
    print(paste0(eachterm,"___第几个::",i, "-========================MF============================================="))
  }
  
  # Filter rna_msc based on target_terms
  rna_msc_match[[eachterm]] <- rna_msc[rna_msc_id %in% target_terms,]
  
 i=i+1
}
a
rna_msc_match %>%names()
rna_msc_match

a_list=rna_msc_match
do.call(cbind, lapply(lapply(a_list, unlist), `length<-`, max(lengths(a_list))))
#       cat  months dog 
my_list=a_list
# Step 1: 合并数据框
combined_df <- do.call(rbind, my_list)
# Step 2: 添加列表名
combined_df$List_Name <- unlist(lapply(seq_along(my_list), function(i) rep(names(my_list)[i], nrow(my_list[[i]]))))
a
combined_df=combined_df[!duplicated(combined_df$Description),]
combined_df


combined_df$Enrichment= -log2(combined_df$p.adjust) %>%as.numeric()
combined_df$"-log2(combined_df$pvalue)"=-log2(combined_df$pvalue)
combined_df$"-log2(combined_df$p.adjust)"=-log2(combined_df$p.adjust)
combined_df$Percentage=DOSE::parse_ratio(combined_df$GeneRatio) /DOSE::parse_ratio(combined_df$BgRatio)
combined_df
#library(tibble)

terms_for_heatmap=data.frame(row.names =combined_df$Description,
                                Enrichment=combined_df$Enrichment)
terms_for_heatmap



pheatmap(terms_for_heatmap,cluster_cols = FALSE,
         scale = "none",
         color = colorRampPalette(c( "pink","red"))(50), 
         cluster_rows = FALSE,gaps_row = seq(1,length(rownames(terms_for_heatmap)))
          )
#蛋白组

猜你喜欢

转载自blog.csdn.net/qq_52813185/article/details/131981685
go