Zettelkasten

source("_preloader.r", verbose=T)
source("../GLUCOLD.mirna.identifiers.r", verbose=T)

# load
psychTable <- readr::read_csv(
    file.path(resultsDir, "results.03 - 2", "meta.psych.csv")
)



######
# GSEA
######
# RNK files for GSEA
out.dir <- file.path(resultsDir, "results.gsea")
dir.create(out.dir)

for (miRNA in unique(psychTable$g.miRNA.id)) {
  if (is.na(miRNA)) {
    next
  }
  miRNA <- get.new.mir.id(miRNA)

  rnkTable = psychTable %>%
    dplyr::arrange(
      meta.p
    ) %>%
    dplyr::filter(
      miRNA.id == miRNA &
      !is.na(gene.symbol) &
      gene.symbol != "",
      !is.na(meta.p.adj.bh)
    ) %>%
    dplyr::select(
      gene.symbol,
      g.t,
      g.r,
      meta.p.adj.bh
    )

  readr::write_delim(
    x = rnkTable %>%
      dplyr::select(-g.r, -meta.p.adj.bh),
    path = file.path(out.dir, paste0(miRNA, ".rnk")),
    delim = "\t"
  )

  readr::write_delim(
    x = rnkTable %>%
      dplyr::filter(g.r < 0, meta.p.adj.bh <= significantPValue) %>%
      dplyr::select(-g.r, -meta.p.adj.bh),
    path = file.path(out.dir, paste0(miRNA, "_fdr-sign_neg.rnk")),
    delim = "\t"
  )
}