geposan/R/preset.R

76 lines
2.2 KiB
R
Raw Normal View History

2021-11-03 14:17:39 +01:00
#' Create a new preset.
#'
#' A preset is used to specify which methods and inputs should be used for an
#' analysis. Note that the genes to process should normally include the
#' reference genes to be able to assess the results later.
#'
#' Available methods are:
#'
#' - `clusteriness` How much the gene distances cluster across species.
#' - `correlation` The mean correlation with the reference genes.
#' - `proximity` Mean proximity to telomeres.
#' - `neural` Assessment by neural network.
#'
#' @param methods Methods to apply.
#' @param species_ids IDs of species to include.
#' @param gene_ids IDs of genes to screen.
2021-11-17 22:57:31 +01:00
#' @param min_n_species Minimum number of orthologs that a gene should have to
#' be included in the analysis.
2021-11-03 14:17:39 +01:00
#' @param reference_gene_ids IDs of reference genes to compare to.
#'
#' @return The preset to use with [analyze()].
#'
#' @export
preset <- function(methods = c(
"clusteriness",
"correlation",
"neural",
"proximity"
),
species_ids = NULL,
gene_ids = NULL,
2021-11-17 22:57:31 +01:00
min_n_species = 10,
2021-11-03 14:17:39 +01:00
reference_gene_ids = NULL) {
# The included data gets sorted to be able to produce predictable hashes
# for the object later.
structure(
list(
methods = sort(methods),
species_ids = sort(species_ids),
gene_ids = sort(gene_ids),
2021-11-17 22:57:31 +01:00
min_n_species = as.numeric(min_n_species),
2021-11-03 14:17:39 +01:00
reference_gene_ids = sort(reference_gene_ids)
),
class = "geposan_preset"
)
}
#' S3 method to print a preset object.
#'
2021-11-06 13:22:57 +01:00
#' @param x The preset to print.
#' @param ... Other parameters.
#'
2021-11-03 14:17:39 +01:00
#' @seealso [preset()]
#'
#' @export
2021-11-06 13:22:57 +01:00
print.geposan_preset <- function(x, ...) {
2021-11-03 14:17:39 +01:00
cat("geposan preset:")
cat("\n Included methods: ")
2021-11-12 18:22:22 +01:00
cat(x$methods, sep = ", ")
2021-11-03 14:17:39 +01:00
cat(sprintf(
"\n Input data: %i species, %i genes",
2021-11-06 13:22:57 +01:00
length(x$species_ids),
length(x$gene_ids)
2021-11-03 14:17:39 +01:00
))
2021-11-17 22:57:31 +01:00
cat(sprintf("\n Species per gene: \u2265 %i", x$min_n_species))
2021-11-03 14:17:39 +01:00
cat(sprintf(
"\n Comparison data: %i reference genes\n",
2021-11-06 13:22:57 +01:00
length(x$reference_gene_ids)
2021-11-03 14:17:39 +01:00
))
2021-11-06 13:22:57 +01:00
invisible(x)
2021-11-03 14:17:39 +01:00
}