Skip to content

Commit 7d07601

Browse files
committed
change the calculation of functional spectrua to Rcpp
1 parent a05942e commit 7d07601

17 files changed

+125
-33
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Description: DeepCC is versatile and robust cancer subtyping framework, based on
99
License: MIT
1010
LazyData: TRUE
1111
RoxygenNote: 5.0.1
12-
Imports: h2o, parallel, doParallel, foreach
12+
Imports: h2o, parallel, doParallel, foreach,
13+
Rcpp
1314
URL: http://github.com/CityUHK-CompBio/DeepCC
1415
BugReports: http://github.com/CityUHK-CompBio/DeepCC/issues
15-
16+
LinkingTo: Rcpp

NAMESPACE

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# Generated by roxygen2 (4.1.1): do not edit by hand
1+
# Generated by roxygen2: do not edit by hand
22

33
export(calcEnrichmentScore)
44
export(cross_validataion)
55
export(getDeepCCFeatures)
66
export(getDeepCCLabels)
77
export(getFunctionalSpectra)
88
export(getFunctionalSpectrum)
9+
export(get_gene_sets)
910
export(trainDeepCCModel)
11+
import(Rcpp)
1012
importFrom(foreach,"%dopar%")
1113
importFrom(foreach,foreach)
14+
useDynLib(DeepCC)

R/FunctionalSpectra.R

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,14 @@ preprocessGeneList <- function(geneList) {
1919
#' @param geneList a named vector containing the values of gene expression
2020
#' @param geneSet a vector containing genes to represent a gene set
2121
#' @return a numeric indicating enrichment score
22+
#' @useDynLib DeepCC
23+
#' @import Rcpp
2224
#' @export
2325
#' @examples
2426
#' calcEnrichmentScore(geneList, geneSet)
2527
calcEnrichmentScore <- function (geneList, geneSet)
2628
{
27-
hits <- (names(geneList) %in% geneSet)
28-
nh <- sum(hits)
29-
N <- length(geneList)
30-
ES <- 0
31-
runningES <- rep(0, N)
32-
if (nh > N) {
33-
stop("Gene Set is larger than Gene List")
34-
}
35-
else {
36-
if (nh) {
37-
tmp <- rep(0, N)
38-
NR = sum(abs(geneList[hits]))
39-
tmp[hits] <- abs(geneList[hits])/NR
40-
tmp[!hits] <- -1/(N - nh)
41-
runningES <- cumsum(tmp)
42-
43-
ESmax <- max(runningES)
44-
ESmin <- min(runningES)
45-
ES <- ifelse(abs(ESmin) > abs(ESmax), ESmin, ESmax)
46-
}
47-
}
48-
ES
29+
calcEnrichmentScoreCPP((names(geneList) %in% geneSet), geneList, 1)
4930
}
5031

5132
#' Generate Functional Spectra

R/RcppExports.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
calcEnrichmentScoreCPP <- function(Set, Eso, exponent) {
5+
.Call('DeepCC_calcEnrichmentScoreCPP', PACKAGE = 'DeepCC', Set, Eso, exponent)
6+
}
7+

R/utils.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,18 @@ cross_validataion <- function(fs, labels, fold = 5) {
2828
error_rate <- 1-mean(as.character(testData.labels) == as.character(pred.lables))
2929
error_rate
3030
}
31+
32+
#' Get Gene Sets
33+
#'
34+
#' This function extract a list of gene sets from gmt file.
35+
#'
36+
#' @param file filename of the gmt file
37+
#' @return a list containing gene sets by EntrezID
38+
#' @export
39+
#' @examples
40+
#' msigdbv51 <- get_gene_sets("msigdb.v5.1.entrez.gmt")
41+
42+
get_gene_sets <- function(file) {
43+
msig <- GSEABase::getGmt(file, geneIdType=EntrezIdentifier())
44+
MSigDBv5.1 <- GSEABase::geneIds(msig)
45+
}

man/calcEnrichmentScore.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/cross_validataion.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/getDeepCCFeatures.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/getDeepCCLabels.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/getFunctionalSpectra.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)