Skip to content

Commit

Permalink
fixed R check, #613
Browse files Browse the repository at this point in the history
  • Loading branch information
GuangchuangYu committed Aug 2, 2023
1 parent cade1b7 commit 39dec42
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: clusterProfiler
Type: Package
Title: A universal enrichment tool for interpreting omics data
Version: 4.9.2.001
Version: 4.9.2.002
Authors@R: c(
person(given = "Guangchuang", family = "Yu", email = "guangchuangyu@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-6485-8781")),
person(given = "Li-Gen", family = "Wang", email = "reeganwang020@gmail.com", role = "ctb"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TODO:
- e.g. independent test for different omics data and then combine results
-->

# clusterProfiler 4.9.2.001
# clusterProfiler 4.9.2.002

+ supports Pathways Common (2023-08-02, Wed, #613)

Expand Down
48 changes: 28 additions & 20 deletions R/pathwayCommons.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
##'
##' This function performs over-representation analysis using Pathway Commons
##' @title enrichPC
##' @param gene a vector of entrez gene id
##' @param organism supported organisms, which can be accessed via the get_pc_organisms() function
##' @param gene a vector of genes (either hgnc symbols or uniprot IDs)
##' @param source Data source of Pathway Commons, e.g., 'reactome', 'kegg', 'pathbank', 'netpath', 'panther', etc.
##' @param keyType specify the type of input 'gene' (one of 'hgnc' or 'uniprot')
##' @param ... additional parameters, see also the parameters supported by the enricher() function
##' @return A \code{enrichResult} instance
##' @export

enrichPC <- function(gene, source, keyType = "hgnc", ...) {
keyType <- match.arg(keyType, c("hgnc", "uniprot"))

source <- match.arg(source, get_pc_source())

pcdata <- get_pc_data(source, keyType, output = 'gson')
res <- enricher(gene, gson = pcdata, ...)

Expand All @@ -27,13 +28,15 @@ enrichPC <- function(gene, source, keyType = "hgnc", ...) {
##'
##' This function performs GSEA using Pathway Commons
##' @title gsePC
##' @param geneList ranked gene list
##' @param organism supported organisms, which can be accessed via the get_pc_organisms() function
##' @param geneList a ranked gene list
##' @param source Data source of Pathway Commons, e.g., 'reactome', 'kegg', 'pathbank', 'netpath', 'panther', etc.
##' @param keyType specify the type of input 'gene' (one of 'hgnc' or 'uniprot')
##' @param ... additional parameters, see also the parameters supported by the GSEA() function
##' @return A \code{gseaResult} instance
##' @export
gsePC <- function(geneList, source, keyType, ...) {
keyType <- match.arg(keyType, c("hgnc", "uniprot"))
source <- match.arg(source, get_pc_source())

pcdata <- get_pc_data(source, keyType, output = 'gson')
res <- GSEA(geneList, gson = pcdata, ...)
Expand All @@ -47,22 +50,22 @@ gsePC <- function(geneList, source, keyType, ...) {
return(res)
}

##' @importFrom rlang .data
prepare_PC_data <- function(source, keyType) {
pc2gene <- get_pc_data(source, keyType)
##TERM2GENE
pcid2gene <- pc2gene %>% dplyr::select(pcid, gene)
##TERM2NAME
pcid2name <- pc2gene %>% dplyr::select(pcid, name)
list(PCID2GENE = pcid2gene,
PCID2NAME = pcid2name)
prepare_pc_data <- function(source, keyType) {
pc2gene <- get_pc_data(source, keyType, output = 'data.frame')
##TERM2GENE
pcid2gene <- pc2gene[, c("id", "gene")]
##TERM2NAME
pcid2name <- unique(pc2gene[, c("id", "name")])

list(PCID2GENE = pcid2gene,
PCID2NAME = pcid2name)
}

get_pc_gmtfile <- function() {
pcurl <- 'https://www.pathwaycommons.org/archives/PC2/v12/'
x <- readLines(pcurl)
y <- x[grep('\\.gmt.gz',x)]
sub(".*(PathwayCommons.*\\.gmt.gz).*", "\\1", y)
pcurl <- 'https://www.pathwaycommons.org/archives/PC2/v12/'
x <- readLines(pcurl)
y <- x[grep('\\.gmt.gz',x)]
sub(".*(PathwayCommons.*\\.gmt.gz).*", "\\1", y)
}

#list supported data sources of Pathway Commons
Expand Down Expand Up @@ -94,8 +97,13 @@ read.gmt.pc_internal <- function(gmtfile) {
# return(res)
}


##' Parse gmt file from Pathway Common
##'
##' This function parse gmt file downloaded from Pathway common
##' @title read.gmt.pc
##' @param gmtfile A gmt file
##' @param output one of 'data.frame' or 'GSON'
##' @return A data.frame or A GSON object depends on the value of 'output'
##' @importFrom rlang .data
##' @importFrom tidyr separate
##' @export
Expand Down
9 changes: 9 additions & 0 deletions R/taxa.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,12 @@ getTaxID <- function(species) {
res <- getTaxInfo(species)
return(res$id)
}



taxID2name <- function(taxID) {
kegg_taxa <- readRDS(system.file("extdata/kegg_taxa.rds",
package = "clusterProfiler"))
kegg_taxa$kegg.name[kegg_taxa$kegg.taxa == taxID]
}

7 changes: 0 additions & 7 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ GI2EG <- function(GI, organism="D39") {
return(gi.eg)
}

taxID2name <- function(taxID) {
kegg_taxa <- readRDS(system.file("extdata/kegg_taxa.rds",
package = "clusterProfiler"))
kegg_taxa$kegg.name[kegg_taxa$kegg.taxa == taxID]
}


removeEmptyEntry.list <- function(x) {
notNA.idx <- unlist(lapply(x, function(i) !is.null(i) && !all(is.na(i))))
x[notNA.idx]
Expand Down
8 changes: 5 additions & 3 deletions man/enrichPC.Rd

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

8 changes: 5 additions & 3 deletions man/gsePC.Rd

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

22 changes: 22 additions & 0 deletions man/read.gmt.pc.Rd

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

0 comments on commit 39dec42

Please sign in to comment.