Skip to content

Commit

Permalink
Update documentation (and indentation)
Browse files Browse the repository at this point in the history
  • Loading branch information
llrs committed Sep 27, 2023
1 parent 0aec4ab commit 6c8c0c6
Show file tree
Hide file tree
Showing 21 changed files with 1,270 additions and 1,253 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ Suggests:
rmarkdown,
spelling,
targetscan.Hs.eg.db,
testthat,
testthat (>= 3.0.0),
WGCNA
VignetteBuilder:
knitr
biocViews: StatisticalMethod, Clustering, GeneExpression, Network,
Pathways, NetworkEnrichment, SystemsBiology
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# BioCor 1.26

* Added support for plots of similarities
* Added support for plots of similarities with `plot_data()` and
`plot_similarity()`.
* Removed internal data accidentally exposed (It was only used for testing).
* Fix problem with documenting the package via roxygen2.
* Remove the `\describe{}` macro used in some pages.

# Changes in version 1.19.1

Expand Down
40 changes: 20 additions & 20 deletions R/AintoB.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@
#' AintoB(A, B)
#' @export
AintoB <- function(A, B) {
if (!is.matrix(A) || !is.matrix(B)) {
stop("Input should be matrices")
}
# Select the order for columns
if (ncol(A) <= ncol(B) && nrow(A) <= nrow(B)) {
mc <- match(colnames(A), colnames(B))
mr <- match(rownames(A), rownames(B))
} else {
stop(
"Impossible to insert matrix A into matrix B\n",
"Matrix A is bigger than matrix B."
)
}
# Omit those with NA
nar <- is.na(mr)
nac <- is.na(mc)
mr <- mr[!nar]
mc <- mc[!nac]
if (!is.matrix(A) || !is.matrix(B)) {
stop("Input should be matrices")
}
# Select the order for columns
if (ncol(A) <= ncol(B) && nrow(A) <= nrow(B)) {
mc <- match(colnames(A), colnames(B))
mr <- match(rownames(A), rownames(B))
} else {
stop(
"Impossible to insert matrix A into matrix B\n",
"Matrix A is bigger than matrix B."
)
}
# Omit those with NA
nar <- is.na(mr)
nac <- is.na(mc)
mr <- mr[!nar]
mc <- mc[!nac]

B[mr, mc] <- A[!nar, !nac]
B
B[mr, mc] <- A[!nar, !nac]
B
}
78 changes: 39 additions & 39 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#' @export pathSim
setGeneric("pathSim", function(pathway1, pathway2, info, ...)
standardGeneric("pathSim")
)

#' @export mpathSim
setGeneric("mpathSim", function(pathways, info, method, ...)
standardGeneric("mpathSim")
)

#' @export geneSim
setGeneric("geneSim", function(gene1, gene2, info, method, ...)
standardGeneric("geneSim")
)

#' @export mgeneSim
setGeneric("mgeneSim", function(genes, info, method, ....)
standardGeneric("mgeneSim")
)

#' @export clusterSim
setGeneric("clusterSim", function(cluster1, cluster2, info, method, ...)
standardGeneric("clusterSim")
)

#' @export mclusterSim
setGeneric("mclusterSim", function(clusters, info, method, ....)
standardGeneric("mclusterSim")
)

#' @export clusterGeneSim
setGeneric("clusterGeneSim", function(cluster1, cluster2, info, method, ...)
standardGeneric("clusterGeneSim")
)

#' @export mclusterGeneSim
setGeneric("mclusterGeneSim", function(clusters, info, method, ....)
standardGeneric("mclusterGeneSim")
)
#' @export pathSim
setGeneric("pathSim", function(pathway1, pathway2, info, ...)
standardGeneric("pathSim")
)

#' @export mpathSim
setGeneric("mpathSim", function(pathways, info, method, ...)
standardGeneric("mpathSim")
)

#' @export geneSim
setGeneric("geneSim", function(gene1, gene2, info, method, ...)
standardGeneric("geneSim")
)

#' @export mgeneSim
setGeneric("mgeneSim", function(genes, info, method, ....)
standardGeneric("mgeneSim")
)

#' @export clusterSim
setGeneric("clusterSim", function(cluster1, cluster2, info, method, ...)
standardGeneric("clusterSim")
)

#' @export mclusterSim
setGeneric("mclusterSim", function(clusters, info, method, ....)
standardGeneric("mclusterSim")
)

#' @export clusterGeneSim
setGeneric("clusterGeneSim", function(cluster1, cluster2, info, method, ...)
standardGeneric("clusterGeneSim")
)

#' @export mclusterGeneSim
setGeneric("mclusterGeneSim", function(clusters, info, method, ....)
standardGeneric("mclusterGeneSim")
)
44 changes: 19 additions & 25 deletions R/BioCor-package.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
#' BioCor: A package to calculate functional similarities
#'
#' Calculates a functional similarity measure between gene identifiers
#' based on the pathways described on KEGG and REACTOME.
#'
#' @section Important functions:
#' \describe{
#' \item{[pathSim()]}{Calculates the similarity between two pathways}
#' \item{[geneSim()]}{Calculates the similarity (based on pathSim)
#' between two genes}
#' \item{[clusterSim()]}{Calculates the similarity between two
#' clusters of genes by joining pathways of each gene.}
#' \item{[clusterGeneSim()]}{Calculates the similarity between two
#' clusters of genes by comparing the similarity between the genes of a cluster
#' }
#' \item{[similarities()]}{Allows to combine the value of matrices of
#' similarities}
#' \item{[conversions()]}{Two functions to convert similarity
#' measures}
#' \item{[weighted()]}{Functions provided to combine similarities}
#' }
#' @name BioCor-package
#' @aliases BioCor
#' @docType package
NULL
#' BioCor: A package to calculate functional similarities
#'
#' Calculates a functional similarity measure between gene identifiers
#' based on the pathways described on KEGG and REACTOME.
#'
#' @section Important functions:
#' - **[pathSim()]**: Calculates the similarity between two pathways.
#' - **[geneSim()]**: Calculates the similarity (based on pathSim)
#' between two genes.
#' - **[clusterSim()]**: Calculates the similarity between two
#' clusters of genes by joining pathways of each gene.
#' - **[clusterGeneSim()]**: Calculates the similarity between two
#' clusters of genes by comparing the similarity between the genes of a cluster.
#' - **[similarities()]**: Allows to combine the value of matrices of
#' similarities.
#' - **[conversions()]**: Two functions to convert similarity
#' measures.
#' - **[weighted()]**: Functions provided to combine similarities.
'_PACKAGE'
122 changes: 61 additions & 61 deletions R/auxiliar.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@
#' 4494469/2886003](http://stackoverflow.com/a/4494469/2886003)
combinadic <- function(n, r, i) {

# http://msdn.microsoft.com/en-us/library/aa289166(VS.71).aspx
# http://en.wikipedia.org/wiki/Combinadic
n0 <- length(n)
if (i < 1L || i > choose(n0, r)) {
stop("'i' must be 0 < i <= n0!/(n0-r)!")
}
largestV <- function(n, r, i) {
v <- n # Adjusted for one-based indexing
while (choose(v, r) >= i) { # Adjusted for one-based indexing
v <- v - 1L
}
return(v)
# http://msdn.microsoft.com/en-us/library/aa289166(VS.71).aspx
# http://en.wikipedia.org/wiki/Combinadic
n0 <- length(n)
if (i < 1L || i > choose(n0, r)) {
stop("'i' must be 0 < i <= n0!/(n0-r)!")
}
largestV <- function(n, r, i) {
v <- n # Adjusted for one-based indexing
while (choose(v, r) >= i) { # Adjusted for one-based indexing
v <- v - 1L
}
return(v)
}

res <- rep(NA, r)
for (j in 1L:r) {
res[j] <- largestV(n0, r, i)
i <- i - choose(res[j], r)
n0 <- res[j]
r <- r - 1L
}
res <- res + 1L
res <- n[res]
return(res)
res <- rep(NA, r)
for (j in 1L:r) {
res[j] <- largestV(n0, r, i)
i <- i - choose(res[j], r)
n0 <- res[j]
r <- r - 1L
}
res <- res + 1L
res <- n[res]
return(res)
}

# seq2mat ####
Expand All @@ -68,15 +68,15 @@ combinadic <- function(n, r, i) {
#' @seealso [upper.tri()] and [lower.tri()]
#' @author Lluís Revilla
seq2mat <- function(x, dat) {
if (length(dat) != choose(length(x), 2L)) {
stop("Data is not enough big to populate the matrix")
}
out <- matrix(ncol = length(x), nrow = length(x))
out[upper.tri(out)] <- unlist(dat, use.names = TRUE)
out[lower.tri(out)] <- t(out)[lower.tri(t(out))]
diag(out) <- 1L
rownames(out) <- colnames(out) <- x
return(out)
if (length(dat) != choose(length(x), 2L)) {
stop("Data is not enough big to populate the matrix")
}
out <- matrix(ncol = length(x), nrow = length(x))
out[upper.tri(out)] <- unlist(dat, use.names = TRUE)
out[lower.tri(out)] <- t(out)[lower.tri(t(out))]
diag(out) <- 1L
rownames(out) <- colnames(out) <- x
return(out)
}

# duplicateIndices ####
Expand All @@ -96,13 +96,13 @@ seq2mat <- function(x, dat) {
#' duplicateIndices(c("52", "52", "53", "55", "55")) # Repeated elements
#' duplicateIndices(c("52", "55", "53", "55", "52")) # Mixed repeated elements
duplicateIndices <- function(vec) {
if (!is.character(vec)) {
stop("Expected a list of characters to find duplicates on it")
}
sapply(unique(vec[duplicated(vec)]), function(x) {
b <- seq_len(length(vec))
b[vec == x]
}, simplify = FALSE)
if (!is.character(vec)) {
stop("Expected a list of characters to find duplicates on it")
}
sapply(unique(vec[duplicated(vec)]), function(x) {
b <- seq_len(length(vec))
b[vec == x]
}, simplify = FALSE)
}

# removeDup ####
Expand All @@ -128,23 +128,23 @@ duplicateIndices <- function(vec) {
#' remat <- removeDup(mat, dupli)
#' remat
removeDup <- function(cor_mat, dupli) {
if (!all(sapply(cor_mat, isSymmetric))) {
stop(
"All the matrices of mat should be symmetric and with the same ",
"column names and rownames"
)
}
cor_mat <- Map(function(mat, x = dupli) {
rem.colum <- sapply(x, function(y, m) {
mean.column <- apply(m[, y], 2L, mean, na.rm = TRUE)
i <- which.max(abs(mean.column))
# Select those who don't bring more information
setdiff(y, y[i])
}, m = mat)
if (!all(sapply(cor_mat, isSymmetric))) {
stop(
"All the matrices of mat should be symmetric and with the same ",
"column names and rownames"
)
}
cor_mat <- Map(function(mat, x = dupli) {
rem.colum <- sapply(x, function(y, m) {
mean.column <- apply(m[, y], 2L, mean, na.rm = TRUE)
i <- which.max(abs(mean.column))
# Select those who don't bring more information
setdiff(y, y[i])
}, m = mat)

mat[-rem.colum, -rem.colum]
}, cor_mat)
return(cor_mat)
mat[-rem.colum, -rem.colum]
}, cor_mat)
return(cor_mat)
}

#' Invert a list
Expand All @@ -157,11 +157,11 @@ removeDup <- function(cor_mat, dupli) {
#' @author Lluís Revilla
#' @export
inverseList <- function(x) {
stopifnot(length(names(x)) == length(x))
stopifnot(all(sapply(x, function(x) {
is.character(x) || is.na(x)
})))
genes <- unlist(x, use.names = FALSE)
pathways <- rep(names(x), lengths(x))
split(pathways, genes)
stopifnot(length(names(x)) == length(x))
stopifnot(all(sapply(x, function(x) {
is.character(x) || is.na(x)
})))
genes <- unlist(x, use.names = FALSE)
pathways <- rep(names(x), lengths(x))
split(pathways, genes)
}
Loading

0 comments on commit 6c8c0c6

Please sign in to comment.