diff --git a/DESCRIPTION b/DESCRIPTION index 92fbbcc..727b4fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: DOSE Type: Package Title: Disease Ontology Semantic and Enrichment analysis -Version: 3.27.3 +Version: 3.29.1 Authors@R: c( person(given = "Guangchuang", family = "Yu", email = "guangchuangyu@gmail.com", role = c("aut", "cre")), person(given = "Li-Gen", family = "Wang", email = "reeganwang020@gmail.com", role = "ctb"), person(given = "Vladislav", family = "Petyuk", email = "petyuk@gmail.com", role = "ctb"), @@ -29,8 +29,7 @@ Imports: reshape2, stats, utils, - MPO.db, - HPO.db + yulab.utils Suggests: prettydoc, clusterProfiler, @@ -38,6 +37,8 @@ Suggests: knitr, rmarkdown, org.Hs.eg.db, + HPO.db, + MPO.db, testthat VignetteBuilder: knitr ByteCompile: true diff --git a/Makefile b/Makefile index 1ffbade..e45e357 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PKGNAME := $(shell sed -n "s/Package: *\([^ ]*\)/\1/p" DESCRIPTION) PKGVERS := $(shell sed -n "s/Version: *\([^ ]*\)/\1/p" DESCRIPTION) PKGSRC := $(shell basename `pwd`) -BIOCVER := RELEASE_3_17 +BIOCVER := RELEASE_3_18 all: rd check clean diff --git a/NAMESPACE b/NAMESPACE index e32f091..e1a8258 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -62,20 +62,8 @@ importFrom(GOSemSim,combineScores) importFrom(GOSemSim,load_OrgDb) importFrom(GOSemSim,termSim) importFrom(HDO.db,HDOANCESTOR) -importFrom(HDO.db,HDOOFFSPRING) importFrom(HDO.db,HDOPARENTS) importFrom(HDO.db,HDOTERM) -importFrom(HPO.db,HPOANCESTOR) -importFrom(HPO.db,HPOGENE) -importFrom(HPO.db,HPOOFFSPRING) -importFrom(HPO.db,HPOPARENTS) -importFrom(HPO.db,HPOTERM) -importFrom(MPO.db,MPOANCESTOR) -importFrom(MPO.db,MPOMGIDO) -importFrom(MPO.db,MPOMPMGI) -importFrom(MPO.db,MPOOFFSPRING) -importFrom(MPO.db,MPOPARENTS) -importFrom(MPO.db,MPOTERM) importFrom(fgsea,fgsea) importFrom(ggplot2,aes) importFrom(ggplot2,element_blank) @@ -104,9 +92,12 @@ importFrom(utils,head) importFrom(utils,packageDescription) importFrom(utils,read.delim) importFrom(utils,setTxtProgressBar) +importFrom(utils,stack) importFrom(utils,str) importFrom(utils,tail) importFrom(utils,txtProgressBar) +importFrom(yulab.utils,check_pkg) +importFrom(yulab.utils,get_fun_from_pkg) importMethodsFrom(AnnotationDbi,columns) importMethodsFrom(AnnotationDbi,exists) importMethodsFrom(AnnotationDbi,get) diff --git a/NEWS.md b/NEWS.md index 42e389a..c266078 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# DOSE 3.29.1 + ++ mv 'MPO.db' and 'HPO.db' from 'Imports' to 'Suggests' and fixed bugs (2023-11-18, Sat) + +# DOSE 3.28.0 + ++ Bioconductor RELEASE_3_18 (2023-10-25, Wed) + # DOSE 3.27.3 + update `TERM2NAME()` to return term if corresponding name not found. (2023-10-09, Mon) diff --git a/R/enrichDisease.R b/R/enrichDisease.R index cd5e399..9af5149 100644 --- a/R/enrichDisease.R +++ b/R/enrichDisease.R @@ -55,3 +55,83 @@ enrichDisease <- function(gene, } return(res) } + +##' @importFrom yulab.utils check_pkg +##' @importFrom yulab.utils get_fun_from_pkg +##' @importFrom utils stack +get_ont_info <- function(ontology) { + ## selected columns of `genemap` + cols <- c(2, 1) + if (ontology == "HDO" || ontology == "DO") { + check_pkg("HDO.db") + # not used in current version + } else if (ontology == "HPO") { + check_pkg("HPO.db") + genemap <- get_fun_from_pkg("HPO.db", "HPOGENE") + ancmap <- get_fun_from_pkg("HPO.db", "HPOANCESTOR") + termmap <- get_fun_from_pkg("HPO.db", "HPOTERM") + } else if (ontology == "MPO") { + check_pkg("MPO.db") + genemap <- get_fun_from_pkg("MPO.db", "MPOMPMGI") + ancmap <- get_fun_from_pkg("MPO.db", "MPOANCESTOR") + termmap <- get_fun_from_pkg("MPO.db", "MPOTERM") + } else if (ontology == "MDO") { + check_pkg("MPO.db") + genemap <- get_fun_from_pkg("MPO.db", "MPGMGIDO") + cols <- c(1, 2) + + check_pkg("HPO.db") + ancmap <- get_fun_from_pkg("HPO.db", "HPOANCESTOR") + termmap <- get_fun_from_pkg("HPO.db", "HPOTERM") + } + # toTable(genemap)[, cols] + res <- list(genemap = genemap, + cols = cols, + ancmap = ancmap, + termmap = termmap + ) +} + +get_dose_data <- function(ontology = "HPO") { + if (!exists(".DOSEenv")) .initial() + .DOSEEnv <- get(".DOSEEnv", envir = .GlobalEnv) + .env <- sprintf(".%s_DOSE_Env", ontology) + if (exists(.env, envir=.DOSEEnv)) { + res <- get(.env, envir = .DOSEEnv) + return(res) + } + + assign(.env, new.env(), envir = .DOSEEnv) + ret_env <- get(.env, envir = .DOSEEnv) + + ont_info <- get_ont_info(ontology) + eg2term <- toTable(ont_info$genemap)[, ont_info$cols] + + TERMS <- names(as.list(ont_info$ancmap)) + i <- eg2term[,2] %in% TERMS + eg2term <- eg2term[i,] + # TERM2EG <- split(eg2term[,1], eg2term[,2]) + EG2TERM <- split(eg2term[,2], eg2term[,1]) + + EG2ALLTERM <- lapply(EG2TERM, + function(i) { + ans <- unlist(mget(i, ont_info$ancmap)) + ans <- ans[ !is.na(ans) ] + ans <- c(i, ans) + ans <- unique(ans) + return(ans) + }) + + EG2ALLTERM.df <- unique(stack(EG2ALLTERM)[, c(2,1)]) + TERM2ALLEG <- split(EG2ALLTERM.df[,1], EG2ALLTERM.df[,2]) + + PATH2NAME.df <- unique(toTable(ont_info$termmap)) + PATH2NAME <- setNames(PATH2NAME.df[,2], PATH2NAME.df[,1]) + + assign("EXTID2PATHID", EG2ALLTERM, envir = ret_env) + assign("PATHID2EXTID", TERM2ALLEG, envir = ret_env) + assign("PATHID2NAME", PATH2NAME, envir = ret_env) + + return(ret_env) +} + diff --git a/R/enrichHPO.r b/R/enrichHPO.r index 790dcff..6af3603 100644 --- a/R/enrichHPO.r +++ b/R/enrichHPO.r @@ -34,56 +34,8 @@ enrichHPO <- function(gene, #' Get HPO data -#' @importFrom HPO.db HPOANCESTOR -#' @importFrom HPO.db HPOPARENTS -#' @importFrom HPO.db HPOTERM -#' @importFrom HPO.db HPOGENE #' @noRd get_HPO_data <- function() { - if (!exists(".DOSEenv")) .initial() - .DOSEEnv <- get(".DOSEEnv", envir = .GlobalEnv) - if (!exists(".HPO_DOSE_Env", envir=.DOSEEnv)) { - assign(".HPO_DOSE_Env", new.env(), envir = .DOSEEnv) - .HPO_DOSE_Env <- get(".HPO_DOSE_Env", envir = .DOSEEnv) - ## get EXTID2PATHID gene_doid - # (1) get eg.do - # colnames(anno_old) <- c("eg", "doid") - eg.do <- toTable(HPOGENE)[, c(2,1)] - colnames(eg.do) <- c("eg", "doid") - # (2) DOSE:::rebuildAnnoData.internal(eg.do) - DO2EG <- with(eg.do, split(as.character(eg), as.character(doid))) - DOTERMs <- names(as.list(HPOANCESTOR)) - idx <- names(DO2EG) %in% DOTERMs - DO2EG <- DO2EG[idx] - DO2EG <- lapply(DO2EG, function(i) unique(i)) - EG2DO <- with(eg.do, split(as.character(doid), as.character(eg))) - EG2DO <- lapply(EG2DO, function(i) unique(i[ i %in% DOTERMs ])) - i <- unlist(lapply(EG2DO, function(i) length(i) != 0)) - EG2DO <- EG2DO[i] - EG2ALLDO <- lapply(EG2DO, - function(i) { - ans <- unlist(mget(i, HPOANCESTOR)) - ans <- ans[ !is.na(ans) ] - ans <- c(i, ans) - ans <- unique(ans) - return(ans) - }) - len <- lapply(EG2ALLDO,length) - EG2ALLDO.df <- data.frame(EG=rep(names(EG2ALLDO), times=len), - DO=unlist(EG2ALLDO)) - DO <- NULL ## satisfy code tools - DO2ALLEG <- with(EG2ALLDO.df, split(as.character(EG), as.character(DO))) - DO2ALLEG <- lapply(DO2ALLEG, unique) - PATH2NAME.df <- toTable(HPOTERM) - colnames(PATH2NAME.df) <- c("doid", "term") - PATH2NAME.df <- unique(PATH2NAME.df) - PATH2NAME <- PATH2NAME.df[,2] - names(PATH2NAME) <- PATH2NAME.df[,1] - } - assign("EXTID2PATHID", EG2ALLDO, envir = .HPO_DOSE_Env) - assign("PATHID2EXTID", DO2ALLEG, envir = .HPO_DOSE_Env) - assign("PATHID2NAME", PATH2NAME, envir = .HPO_DOSE_Env) - - get(".HPO_DOSE_Env", envir = .DOSEEnv) + get_dose_data("HPO") } diff --git a/R/enrichMPO.r b/R/enrichMPO.r index c914f2b..071bda4 100644 --- a/R/enrichMPO.r +++ b/R/enrichMPO.r @@ -35,96 +35,9 @@ enrichMPO <- function(gene, #' Get MPO data #' @param ont one of "DO" and "MPO". -#' @importFrom MPO.db MPOMGIDO -#' @importFrom MPO.db MPOANCESTOR -#' @importFrom MPO.db MPOPARENTS -#' @importFrom MPO.db MPOMPMGI -#' @importFrom MPO.db MPOTERM #' @noRd get_MPO_data <- function(ont = "DO") { - if (!exists(".DOSEenv")) .initial() - .DOSEEnv <- get(".DOSEEnv", envir = .GlobalEnv) - if (!exists(".MPO_DOSE_Env", envir=.DOSEEnv)) { - assign(".MPO_DOSE_Env", new.env(), envir = .DOSEEnv) - .MPO_DOSE_Env <- get(".MPO_DOSE_Env", envir = .DOSEEnv) - if (ont == "DO") { - ## get EXTID2PATHID gene_doid - # (1) get eg.do - # colnames(anno_old) <- c("eg", "doid") - eg.do <- toTable(MPOMGIDO) - colnames(eg.do) <- c("eg", "doid") - # (2) DOSE:::rebuildAnnoData.internal(eg.do) - DO2EG <- with(eg.do, split(as.character(eg), as.character(doid))) - DOTERMs <- names(as.list(HDOANCESTOR)) - idx <- names(DO2EG) %in% DOTERMs - DO2EG <- DO2EG[idx] - DO2EG <- lapply(DO2EG, function(i) unique(i)) - EG2DO <- with(eg.do, split(as.character(doid), as.character(eg))) - EG2DO <- lapply(EG2DO, function(i) unique(i[ i %in% DOTERMs ])) - i <- unlist(lapply(EG2DO, function(i) length(i) != 0)) - EG2DO <- EG2DO[i] - EG2ALLDO <- lapply(EG2DO, - function(i) { - ans <- unlist(mget(i, HDOANCESTOR)) - ans <- ans[ !is.na(ans) ] - ans <- c(i, ans) - ans <- unique(ans) - return(ans) - }) - len <- lapply(EG2ALLDO,length) - EG2ALLDO.df <- data.frame(EG=rep(names(EG2ALLDO), times=len), - DO=unlist(EG2ALLDO)) - DO <- NULL ## satisfy code tools - DO2ALLEG <- with(EG2ALLDO.df, split(as.character(EG), as.character(DO))) - DO2ALLEG <- lapply(DO2ALLEG, unique) - - PATH2NAME.df <- toTable(HDOTERM) - # PATH2NAME.df <- PATH2NAME.df[, c("do_id", "Term")] - PATH2NAME.df <- PATH2NAME.df[, c("doid", "term")] - PATH2NAME.df <- unique(PATH2NAME.df) - PATH2NAME <- PATH2NAME.df[,2] - names(PATH2NAME) <- PATH2NAME.df[,1] - - } else { - ## get EXTID2PATHID gene_doid - # (1) get eg.do - # colnames(anno_old) <- c("eg", "doid") - eg.do <- toTable(MPOMPMGI)[, c(2,1)] - colnames(eg.do) <- c("eg", "doid") - # (2) DOSE:::rebuildAnnoData.internal(eg.do) - DO2EG <- with(eg.do, split(as.character(eg), as.character(doid))) - DOTERMs <- names(as.list(MPOANCESTOR)) - idx <- names(DO2EG) %in% DOTERMs - DO2EG <- DO2EG[idx] - DO2EG <- lapply(DO2EG, function(i) unique(i)) - EG2DO <- with(eg.do, split(as.character(doid), as.character(eg))) - EG2DO <- lapply(EG2DO, function(i) unique(i[ i %in% DOTERMs ])) - i <- unlist(lapply(EG2DO, function(i) length(i) != 0)) - EG2DO <- EG2DO[i] - EG2ALLDO <- lapply(EG2DO, - function(i) { - ans <- unlist(mget(i, MPOANCESTOR)) - ans <- ans[ !is.na(ans) ] - ans <- c(i, ans) - ans <- unique(ans) - return(ans) - }) - len <- lapply(EG2ALLDO,length) - EG2ALLDO.df <- data.frame(EG=rep(names(EG2ALLDO), times=len), - DO=unlist(EG2ALLDO)) - DO <- NULL ## satisfy code tools - DO2ALLEG <- with(EG2ALLDO.df, split(as.character(EG), as.character(DO))) - DO2ALLEG <- lapply(DO2ALLEG, unique) - PATH2NAME.df <- toTable(MPOTERM) - colnames(PATH2NAME.df) <- c("doid", "term") - PATH2NAME.df <- unique(PATH2NAME.df) - PATH2NAME <- PATH2NAME.df[,2] - names(PATH2NAME) <- PATH2NAME.df[,1] - } - assign("EXTID2PATHID", EG2ALLDO, envir = .MPO_DOSE_Env) - assign("PATHID2EXTID", DO2ALLEG, envir = .MPO_DOSE_Env) - assign("PATHID2NAME", PATH2NAME, envir = .MPO_DOSE_Env) - } - get(".MPO_DOSE_Env", envir = .DOSEEnv) + if (ont == "DO") ont = "MDO" + get_dose_data(ont) } diff --git a/R/utilities.R b/R/utilities.R index bbef981..752b415 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -144,17 +144,8 @@ calculate_qvalue <- function(pvals) { ##' @title compute information content ##' @param ont one of "DO" and "MPO" ##' @return NULL -##' @importFrom HDO.db HDOTERM -##' @importFrom HDO.db HDOOFFSPRING -##' @importFrom MPO.db MPOMGIDO -##' @importFrom MPO.db MPOANCESTOR -##' @importFrom MPO.db MPOPARENTS -##' @importFrom MPO.db MPOMPMGI -##' @importFrom MPO.db MPOOFFSPRING -##' @importFrom HPO.db HPOGENE -##' @importFrom HPO.db HPOOFFSPRING ##' @importMethodsFrom AnnotationDbi toTable -##' @author Guangchuang Yu \url{http://guangchuangyu.github.io} +##' @author Guangchuang Yu \url{https://yulab-smu.top} computeIC <- function(ont="DO"){ if (!exists(".DOSEEnv")) { .initial() @@ -169,17 +160,17 @@ computeIC <- function(ont="DO"){ rm(DO2EG, envir = .GlobalEnv) } DO2EG <- get("DO2EG", envir = DOSEEnv) - Offsprings <- AnnotationDbi::as.list(HDOOFFSPRING) + Offsprings <- AnnotationDbi::as.list(HDO.db::HDOOFFSPRING) } else if (ont == "MPO") { - eg.do <- toTable(MPOMPMGI)[, c(2,1)] + eg.do <- toTable(MPO.db::MPOMPMGI)[, c(2,1)] colnames(eg.do) <- c("eg", "doid") DO2EG <- with(eg.do, split(as.character(eg), as.character(doid))) - Offsprings <- AnnotationDbi::as.list(MPOOFFSPRING) + Offsprings <- AnnotationDbi::as.list(MPO.db::MPOOFFSPRING) } else if (ont == "HPO") { - eg.do <- toTable(HPOGENE)[, c(2,1)] + eg.do <- toTable(HPO.db::HPOGENE)[, c(2,1)] colnames(eg.do) <- c("eg", "doid") DO2EG <- with(eg.do, split(as.character(eg), as.character(doid))) - Offsprings <- AnnotationDbi::as.list(HPOOFFSPRING) + Offsprings <- AnnotationDbi::as.list(HPO.db::HPOOFFSPRING) } docount <- unlist(lapply(DO2EG, length)) doids <- names(docount) @@ -205,7 +196,7 @@ computeIC <- function(ont="DO"){ ##' @importMethodsFrom AnnotationDbi get ##' @importMethodsFrom AnnotationDbi exists ##' @export -##' @author Guangchuang Yu \url{http://guangchuangyu.github.io} +##' @author Guangchuang Yu \url{https://yulab-smu.top} gene2DO <- function(gene, organism = "hsa", ont = "DO") { gene <- as.character(gene) if (organism == "hsa") { @@ -220,13 +211,13 @@ gene2DO <- function(gene, organism = "hsa", ont = "DO") { EG2DO <- get("EG2DO", envir=.DOSEEnv) } else { if (ont == "DO") { - eg.do <- toTable(MPOMGIDO) + eg.do <- toTable(MPO.db::MPOMGIDO) colnames(eg.do) <- c("eg", "doid") MPOTERMs <- names(as.list(HDOANCESTOR)) } else { - eg.do <- toTable(MPOMPMGI)[, c(2,1)] + eg.do <- toTable(MPO.db::MPOMPMGI)[, c(2,1)] colnames(eg.do) <- c("eg", "doid") - MPOTERMs <- names(as.list(MPOANCESTOR)) + MPOTERMs <- names(as.list(MPO.db::MPOANCESTOR)) } EG2DO <- with(eg.do, split(as.character(doid), as.character(eg))) EG2DO <- lapply(EG2DO, function(i) unique(i[ i %in% MPOTERMs ])) @@ -306,7 +297,7 @@ build_dodata <- function() { ##' @param file do_rif.human.txt ##' @return NULL ##' @importFrom utils read.delim -##' @author Guangchuang Yu \url{http://guangchuangyu.github.io} +##' @author Guangchuang Yu \url{https://yulab-smu.top} rebuildAnnoData <- function(file) { ## ## do_rif.human.txt was downloaded from @@ -411,7 +402,7 @@ rebuildAnnoData.internal <- function(eg.do) { ##' @importMethodsFrom AnnotationDbi keytypes ##' @importFrom GOSemSim load_OrgDb ##' @export -##' @author Guangchuang Yu \url{http://guangchuangyu.github.io} +##' @author Guangchuang Yu \url{https://yulab-smu.top} EXTID2NAME <- function(OrgDb, geneID, keytype) { OrgDb <- load_OrgDb(OrgDb) kt <- keytypes(OrgDb) diff --git a/man/EXTID2NAME.Rd b/man/EXTID2NAME.Rd index c74b006..75c6133 100644 --- a/man/EXTID2NAME.Rd +++ b/man/EXTID2NAME.Rd @@ -20,5 +20,5 @@ gene symbol mapping gene ID to gene Symbol } \author{ -Guangchuang Yu \url{http://guangchuangyu.github.io} +Guangchuang Yu \url{https://yulab-smu.top} } diff --git a/man/computeIC.Rd b/man/computeIC.Rd index 2078f82..554eb90 100644 --- a/man/computeIC.Rd +++ b/man/computeIC.Rd @@ -13,5 +13,5 @@ computeIC(ont = "DO") compute information content } \author{ -Guangchuang Yu \url{http://guangchuangyu.github.io} +Guangchuang Yu \url{https://yulab-smu.top} } diff --git a/man/gene2DO.Rd b/man/gene2DO.Rd index c3e7ec2..398409f 100644 --- a/man/gene2DO.Rd +++ b/man/gene2DO.Rd @@ -20,5 +20,5 @@ DO Terms provide gene ID, this function will convert to the corresponding DO Terms } \author{ -Guangchuang Yu \url{http://guangchuangyu.github.io} +Guangchuang Yu \url{https://yulab-smu.top} } diff --git a/man/rebuildAnnoData.Rd b/man/rebuildAnnoData.Rd index f2d479e..7d505d7 100644 --- a/man/rebuildAnnoData.Rd +++ b/man/rebuildAnnoData.Rd @@ -13,5 +13,5 @@ rebuildAnnoData(file) rebuilding entrez and DO mapping datasets } \author{ -Guangchuang Yu \url{http://guangchuangyu.github.io} +Guangchuang Yu \url{https://yulab-smu.top} }