Skip to content

Commit

Permalink
add function
Browse files Browse the repository at this point in the history
  • Loading branch information
reedliu committed Nov 8, 2021
1 parent 177978c commit 978c034
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions R/genGO.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ genGO <- function(id,
stopifnot(is.character(id))
if (missing(universe)) universe <- NULL

bioc_org <- mapBiocOrg(tolower(org))
bioc_org <- mapBiocOrg(org)
org <- mapEnsOrg(org)
pkg <- paste0("org.", bioc_org, ".eg.db")
keyType <- gentype(id, org)

Expand All @@ -72,7 +73,7 @@ genGO <- function(id,
}

if (use_symbol) {
info <- genInfo(id, org, unique = T) %>% na.omit()
info <- genInfo(id, org, unique = T)
new_geneID <- stringr::str_split(ego$geneID, "\\/") %>%
lapply(., function(x) {
info %>%
Expand Down
9 changes: 5 additions & 4 deletions R/genInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ genInfo <- function(id,
rm(list = paste0(org, "_anno"), envir = .GlobalEnv)

tmp1 <- data.frame(input_id = id)
tmp2 <- all %>% dplyr::filter(eval(parse(text = keytype)) %in% id)

if(any(c("symbol", "uniprot") %in% colnames(all))){
tmp2 <- all %>% dplyr::filter(eval(parse(text = keytype)) %in% id)
tmp3 <- tmp2 %>%
dplyr::select(-c("symbol", "uniprot")) %>%
apply(., 1, is.na)
apply(., 1, is.na) %>%
as.data.frame()
}

## keep each id even has no info
# only symbol id needs to consider alias
if (keytype != "symbol") {
gene_info <- merge(tmp1, tmp2, by.x = "input_id", by.y = keytype, all.x = T)
} else if (any(apply(tmp3, 2, sum) == nrow(tmp3))) {
# if only symbol and uniprot are not NA
tmp2 <- tmp2 %>% dplyr::filter_at(dplyr::vars(-symbol, -uniprot), dplyr::all_vars(!is.na(.)))
# only symbol and uniprot are not NA <= import gene from uniprot
tmp2 <- tmp2[-which(apply(tmp3, 2, sum) == nrow(tmp3)),]
gene_info <- merge(tmp1, tmp2, by.x = "input_id", by.y = keytype, all.x = T) %>%
dplyr::arrange(id) %>%
dplyr::mutate(symbol = dplyr::case_when(input_id %in% tmp2$symbol ~ input_id)) %>%
Expand Down
7 changes: 4 additions & 3 deletions R/genKEGG.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ genKEGG <- function(id,
stopifnot(is.character(id))
if (missing(universe)) universe <- NULL

kegg_org <- mapKeggOrg(tolower(org))
kegg_org <- mapKeggOrg(org)
org <- mapEnsOrg(org)
keyType <- gentype(id, org)

if (!keyType %in% c("ENTREZID")) {
message(paste0(keyType), " gene will be mapped to entrez id")
trans_id <- suppressMessages(transId(id, "entrezid", kegg_org)) %>% stringi::stri_remove_na()
trans_id <- suppressMessages(transId(id, "entrezid", org)) %>% stringi::stri_remove_na()
} else {
trans_id <- id
}
Expand All @@ -61,7 +62,7 @@ genKEGG <- function(id,
#--- codes ---#
keg <- suppressMessages(
clusterProfiler::enrichKEGG(
gene = trans_id, organism = org, keyType = "kegg",
gene = trans_id, organism = kegg_org, keyType = "kegg",
pvalueCutoff = pvalueCutoff,
pAdjustMethod = pAdjustMethod,
qvalueCutoff = qvalueCutoff,
Expand Down
4 changes: 2 additions & 2 deletions R/transID.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#' @param id Gene ids.
#' @param trans_to Transform to which type, one of "symbol", "entrezid",
#' "ensembl" and "uniprot."
#' @param org Organism name from `biocOrg_name`, both full name and short name are fine.
#' @param unique Logical to keep only one unique mapped ID, default is FALSE.
#' @param org Short latin name from `ensOrg_name_data`.
#' @param unique If keep only one unique mapped ID when one-to-many gene occurs, default is FALSE.
#' @importFrom dplyr %>% filter pull select distinct arrange all_of
#' @importFrom tibble add_row
#' @importFrom stats na.omit
Expand Down
4 changes: 2 additions & 2 deletions man/transId.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 978c034

Please sign in to comment.