R/getNumPaths.R

Defines functions getNumPaths

Documented in getNumPaths

#' get the number of metabolic pathways for the given group
#' @param microbeNames Vector of strings which contains the names of the microbial groups in the system e.g. c('Bacteroides','Acetogens')
#' @return a named vector of the number of paths for each group
#' if numPathways is not in dataframe then it is set to 1.
#' @export
#' 
getNumPaths = function(microbeNames) {
    
    L = length(microbeNames)
    numPaths = NA * seq(1, L)
    names(numPaths) = microbeNames
    for (gname in microbeNames) {
        data = get(gname)
        if (any(colnames(data) == "units") | any(colnames(data) == "Units")) {
            n = as.numeric(data["numPathways", ][[2]])
        } else {
            n = as.numeric(data["numPathways", ][[1]])
        }
        if (!is.na(n)) {
            numPaths[gname] = n
        } else {
            numPaths[gname] = 1
        }
    }
    return(numPaths)
}

Try the microPop package in your browser

Any scripts or data that you put into this service are public.

microPop documentation built on Feb. 3, 2022, 5:07 p.m.