mcanouil / analysis-scripts-templates

Script Templates To Work With Omics Datasets
MIT License
0 stars 1 forks source link

to add genes not in core enrichment #1

Closed Ning-L closed 3 years ago

Ning-L commented 3 years ago

https://github.com/mcanouil/analysis_templates/blob/67dce67de0a67f46261ad323209868894822285f/R/12-ora_gsea.R#L342-L347

write_xlsx(
  x = setNames(lapply(enrich_sets, FUN = function(.enrich) {
    if (!is.null(.enrich)) {
      tmp <- .enrich@result
      tmp[["peripheral_enrichment"]] <- unlist(lapply(seq_along(tmp$ID), function(i) {
        enriched <- names(.enrich@geneList)[names(.enrich@geneList) %in% .enrich@geneSets[[tmp$ID[i]]]]
        paste0(setdiff(
          enriched, unlist(strsplit(tmp$core_enrichment[i], split = "/"))
        ), collapse = "/")
      }))
      return(tmp)
    } else data.frame()
  }), gsub("Gene Ontology", "GO", names(enrich_sets))), 
  path = file.path(output_directory, "gene_set_enrichment.xlsx")
)
mcanouil commented 3 years ago

Thanks, I'll update the code with a slight modification of your proposal. Those "R templates" are more likely to be part of an R package or something else to allow easier access/use.