Skip to content

Commit

Permalink
docs: update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stefpeschel committed Nov 2, 2024
1 parent b2d9225 commit 9935439
Show file tree
Hide file tree
Showing 51 changed files with 456 additions and 2,076 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Description: NetCoMi offers functions for constructing, analyzing, and comparing
microbial compositional data. It also includes functionality for
constructing differential association networks.
License: GPL-3 + file LICENSE
URL: https://stefpeschel.github.io/NetCoMi, https://github.com/stefpeschel/NetCoMi
BugReports: https://github.com/stefpeschel/NetCoMi/issues
Depends: SpiecEasi (>= 1.0.6)
Imports:
Biobase,
Expand Down Expand Up @@ -70,5 +72,4 @@ Suggests:
RdMacros: Rdpack
Encoding: UTF-8
RoxygenNote: 7.3.2
URL: https://stefpeschel.github.io/NetCoMi/
VignetteBuilder: knitr
1 change: 1 addition & 0 deletions R/NetCoMi-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
#' (inspiration and theoretical background)
#' \item Anastasiia Holovchak (package testing and editing)
#' }
#' @keywords internal
"_PACKAGE"
1 change: 1 addition & 0 deletions R/dot-boottest.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' @return \tabular{ll}{ \code{pvals}\tab calculated p-values\cr
#' \code{corrMat}\tab estimated correlation matrix}
#' @references{\insertRef{friedman2012inferring}{NetCoMi}}
#' @keywords internal

.boottest <- function(countMat, assoMat, nboot = 1000, measure, measurePar,
cores = 4, logFile = NULL, verbose = TRUE, seed = NULL,
Expand Down
1 change: 1 addition & 0 deletions R/dot-calcAssociation.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' @importFrom SPRING SPRING
#' @importFrom vegan vegdist
#' @import mixedCCA
#' @keywords internal

.calcAssociation <- function(countMat, measure, measurePar, verbose) {

Expand Down
1 change: 1 addition & 0 deletions R/dot-calcDiffProps.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @keywords internal
.calcDiffProps <- function(adja1,
adja2,
dissMat1,
Expand Down
1 change: 1 addition & 0 deletions R/dot-calcJaccard.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @keywords internal
.calcJaccard <- function(group1, group2, sigTest, greater) {
N <- length(union(group1, group2))
C <- length(intersect(group1, group2))
Expand Down
2 changes: 1 addition & 1 deletion R/dot-calcProps.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#' @importFrom igraph graph_from_adjacency_matrix decompose.graph
#' @importFrom stats hclust as.dist cutree qlnorm quantile
#' @importFrom pulsar natural.connectivity

#' @keywords internal

.calcProps <- function(adjaMat,
dissMat,
Expand Down
2 changes: 1 addition & 1 deletion R/dot-checkArgsPlotDiff.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Argument checking for function plot.diffnet()

#' @keywords internal
.checkArgsPlotDiff<- function(args) {

# Variable for collecting error messages
Expand Down
1 change: 1 addition & 0 deletions R/dot-checkPackNetConst.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @keywords internal
# Check whether packages needed for the current netConstruct() run
# are available.

Expand Down
1 change: 1 addition & 0 deletions R/dot-checkPlausNetConst.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @keywords internal
# Plausibility checking for arguments of netConstruct()

.checkPlausNetConst <- function(dataType,
Expand Down
29 changes: 0 additions & 29 deletions R/dot-filterEdges.R

This file was deleted.

276 changes: 276 additions & 0 deletions R/dot-filterFunctions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
#' @keywords internal
.filterEdges <- function(adja, assoEst, dissEst, edgeFilter, edgeFilterPar) {
if (edgeFilter == "threshold") {

if (is.null(dissEst)) { # if association network
assoEst <- assoEst[rownames(adja), colnames(adja)]

adja[abs(assoEst) < edgeFilterPar] <- 0

} else { # if dissimilarity network
dissEst <- dissEst[rownames(adja), colnames(adja)]

adja[dissEst > edgeFilterPar] <- 0
}

} else if (edgeFilter == "highestWeight") {

adjaSort <- sort(adja[lower.tri(adja)], decreasing = TRUE)

if (edgeFilterPar > length(adjaSort)) {
stop(paste0("'edgeFilterPar' must be smaller than maximum number ",
"of edges (", length(adjaSort), ")."))
}

adja[adja < adjaSort[edgeFilterPar]] <- 0
}

return(adja)
}

#' @keywords internal
.filterNodes <- function(adja, nodeFilter, nodeFilterPar, layout,
degree, between, close, eigen, cluster) {

adja.alltax <- adja

if (!is.null(layout) & is.matrix(layout)) {
keep <- colnames(adja)[which(colnames(adja) %in% rownames(layout))]

} else if (nodeFilter != "none") {

if (nodeFilter == "highestConnect") {
adja.tmp <- adja

diag(adja.tmp) <- 0
conct <- Matrix::rowSums(abs(adja.tmp))

conct <- names(sort(conct))[1:nodeFilterPar]
keep <- colnames(adja)[which(colnames(adja) %in% conct)]

} else if (nodeFilter == "highestDegree") {
sel <- names(sort(degree, decreasing = TRUE)[1:nodeFilterPar])
keep <- colnames(adja)[which(colnames(adja) %in% sel)]

} else if (nodeFilter == "highestBetween") {
sel <- names(sort(between, decreasing = TRUE)[1:nodeFilterPar])

keep <- colnames(adja)[which(colnames(adja) %in% sel)]

} else if (nodeFilter == "highestClose") {
sel <- names(sort(close, decreasing = TRUE)[1:nodeFilterPar])

keep <- colnames(adja)[which(colnames(adja) %in% sel)]

} else if (nodeFilter == "highestEigen") {
sel <- names(sort(eigen, decreasing = TRUE)[1:nodeFilterPar])

keep <- colnames(adja)[which(colnames(adja) %in% sel)]

} else if (nodeFilter == "clustTaxon") {
stopifnot(all(nodeFilterPar %in% colnames(adja)))

selClust <- cluster[nodeFilterPar]
keep <- names(cluster[cluster %in% selClust])
#keep <- names(cluster) %in% selnodes

} else if (nodeFilter == "clustMin") {
clusttab <- table(cluster)
selclust <- names(clusttab[clusttab >= nodeFilterPar &
names(clusttab) != 0])

keep <- names(cluster[cluster %in% selclust])

} else if (nodeFilter == "names") {
stopifnot(all(nodeFilterPar %in% colnames(adja)))
keep <- colnames(adja)[which(colnames(adja) %in% nodeFilterPar)]
}

} else {
keep <- colnames(adja)
}

# names_alltaxa <- matrix(NA, nrow = ncol(adja.alltax1), ncol = 2)
# names_alltaxa[, 1] <- colnames(adja.alltax1)
# names_alltaxa[, 2] <- colnames(x$input$adja1)
# rownames(names_alltaxa) <- names_alltaxa[,1]
#
# unitnames <- union(colnames(adja), colnames(adja2))
# names_selected_taxa <- matrix(NA, nrow = length(unitnames), ncol = 2)
# names_selected_taxa[, 1] <- unitnames
# names_selected_taxa[, 2] <- names_alltaxa[unitnames, 2]
# rownames(names_alltaxa) <- NULL
#
# if (labelsToFile == "all") {
# write.matrix(names_alltaxa, file="taxalabels.txt")
# } else if (labelsToFile == "selected") {
# write.matrix(names_selected_taxa, file="taxalabels.txt")
# }
#
#
# colnames(names_alltaxa) <- colnames(names_selected_taxa) <- c("shortened",
# "original")
#
# taxalabels <- list(all_taxa = names_alltaxa,
# selected_taxa = names_selected_taxa)

rm(adja.alltax)

return(keep = keep)

}


#' @keywords internal
.filterSamples <- function(countMat, filter, filterParam) {

countMat_orig <- countMat

if ("highestFreq" %in% filter) {
highestFreq <-
ifelse(is.null(filterParam$highestFreq),
100,
filterParam$highestFreq)
highestFreq <- min(nrow(countMat), highestFreq)

if (length(filter) > 1) {
stop('Filter method "highestFreq" not comparable with other ',
'filter methods.')
}
names_highFreq <- names(sort(Matrix::rowSums(countMat),
decreasing = TRUE)[1:highestFreq])
#rmRows <- which(!rownames(countMat) %in% names_highFreq)
keepRows <- names_highFreq

} else {

if ("totalReads" %in% filter) {
totalReads <-
ifelse(is.null(filterParam$totalReads),
1000,
filterParam$totalReads)
idx_totalreads <- which(Matrix::rowSums(countMat) >= totalReads)
} else {
idx_totalreads <- 1:nrow(countMat)
}

if ("numbTaxa" %in% filter) {
numbTaxa <- ifelse(is.null(filterParam$numbTaxa),
0.1,
filterParam$numbTaxa)
stopifnot(numbTaxa > 0)
if (numbTaxa < 1) {
numbTaxa <- round(numbTaxa * nrow(countMat))
}

idx_numbTaxa = numeric(0)

for (i in 1:nrow(countMat)) {
if (length(which(!countMat[i,] == 0)) >= numbTaxa) {
idx_numbTaxa <- append(idx_numbTaxa, i)
}
}
} else {
idx_numbTaxa <- 1:nrow(countMat)
}

keepRows <- rownames(countMat[intersect(idx_totalreads, idx_numbTaxa), ])
}

return(keepRows)
}


#' @keywords internal
.filterTaxa <- function(countMat, filter, filterParam) {

countMat_orig <- countMat
#---------------------------------------------------------------------------
# filter taxa of interest

if ("highestVar" %in% filter) {
highestVar <-
ifelse(is.null(filterParam$highestVar),
100,
filterParam$highestVar)

highestVar <- min(ncol(countMat), highestVar)

if (length(filter) > 1) {
stop('Filter method "highestVar" not comparable with other ',
'filter methods.')
}
var_taxa <- apply(countMat, 2, var)
keepCols <- names(sort(var_taxa, decreasing = TRUE)[1:highestVar])

#countMat <- countMat[, names_highvar]

} else if ("highestFreq" %in% filter) {
highestFreq <-
ifelse(is.null(filterParam$highestFreq),
100,
filterParam$highestFreq)

highestFreq <- min(ncol(countMat), highestFreq)

if (length(filter) > 1) {
stop('Filter method "highestFreq" not comparable with other ',
'filter methods.')
}
keepCols <- names(sort(Matrix::colSums(countMat),
decreasing = TRUE)[1:highestFreq])
#countMat <- countMat[, names_highFreq]

} else {
if ("relFreq" %in% filter) {
relFreq <-
ifelse(is.null(filterParam$relFreq),
0.01,
filterParam$relFreq)
idx_relfreq <- which(Matrix::colSums(countMat) >=
sum(Matrix::colSums(countMat)) * relFreq)
} else {
idx_relfreq <- 1:ncol(countMat)
}


if ("totalReads" %in% filter) {
totalReads <-
ifelse(is.null(filterParam$totalReads),
1000,
filterParam$totalReads)
idx_totalreads <- which(Matrix::colSums(countMat) >= totalReads)
} else {
idx_totalreads <- 1:ncol(countMat)
}

if ("numbSamp" %in% filter) {
numbSamp <- ifelse(is.null(filterParam$numbSamp), 0.1,
filterParam$numbSamp)

stopifnot(numbSamp > 0)

if (numbSamp < 1) {
numbSamp <- round(numbSamp * nrow(countMat))
}

idx_numbSamp = numeric(0)

for (i in 1:ncol(countMat)) {
if (length(which(!countMat[, i] == 0)) >= numbSamp) {
idx_numbSamp <- append(idx_numbSamp, i)
}
}
} else {
idx_numbSamp <- 1:ncol(countMat)
}

keepCols <- colnames(countMat[, intersect(intersect(idx_relfreq,
idx_totalreads),
idx_numbSamp)])
}

#rmCols <- which(!colnames(countMat_orig) %in% colnames(countMat))

return(keepCols)
}
Loading

0 comments on commit 9935439

Please sign in to comment.