R/mdat_get_quantitative_variable.R

Defines functions get_quantitative_variable

Documented in get_quantitative_variable

#' Get a quantititative variable from microbe directory
#'
#' This function returns a dataframe of one of the quantitative
#' variable from the microbe directory for each of the test_set
#' and background set
#'
#' @param database test_set background_set
#' @export
#' @examples
#' get_quantitative_variable(microbe_directory=microbe_directory, test_set=test_set, background_set=background_set, variable="optimal_ph")

get_quantitative_variable <- function(microbe_directory=microbe_directory,
                                      test_set=test_set,
				      background_set=background_set,
				      variable="optimal_ph"){

    if (!(variable %in% c("optimal_ph", "optimal_temperature"))){
        stop(paste0("There is no quantitative variable '", variable, "' in The Microbe Directory"))
    }

    test_set_ids <- intersect(rownames(microbe_directory), test_set)
    
    test_set_variable <- data.frame(microbe_directory[test_set_ids, variable])
    test_set_variable$type <- "test_set"
    colnames(test_set_variable) <- c(variable, "type")

    background_set_ids <- intersect(rownames(microbe_directory), background_set)
    background_set_variable <- data.frame(microbe_directory[background_set_ids, variable])
    background_set_variable$type <- "background_set"
    colnames(background_set_variable) <- c(variable, "type")

    dat <- data.frame(rbind(test_set_variable, background_set_variable))
    rownames(dat) <- append(test_set_ids, background_set_ids)

    cat("Removing rows with no data...\n")
    dat <- na.omit(dat)

    return(dat)
    }
nickilott/MDAT documentation built on Sept. 7, 2020, 7:03 a.m.