diff --git a/NAMESPACE b/NAMESPACE index 22449fb..841e328 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,6 +22,7 @@ export(plot_positions) export(plot_rankings) export(plot_scores) export(preset) +export(proximity) export(ranking) export(result) export(species_adjacency) diff --git a/R/method.R b/R/method.R index d1a0a84..cff0f61 100644 --- a/R/method.R +++ b/R/method.R @@ -37,7 +37,8 @@ all_methods <- function() { correlation(), neural(), adjacency(), - species_adjacency() + species_adjacency(), + proximity() ) } diff --git a/R/proximity.R b/R/proximity.R new file mode 100644 index 0000000..70c6d92 --- /dev/null +++ b/R/proximity.R @@ -0,0 +1,39 @@ +#' Score the mean distance of genes to the telomeres across species. +#' +#' A score will be given to each gene such that 0.0 corresponds to the maximal +#' mean distance across all genes and 1.0 corresponds to a distance of 0. +#' +#' @return An object of class `geposan_method`. +#' +#' @export +proximity <- function() { + method( + id = "proximity", + name = "Proximity", + description = "Proximity to telomeres", + function(preset, progress) { + species_ids <- preset$species_ids + gene_ids <- preset$gene_ids + + cached("proximity", c(species_ids, gene_ids), { + # Prefilter distances by species and gene. + data <- geposan::distances[ + species %chin% preset$species_ids & + gene %chin% preset$gene_ids + ] + + # Compute the score as described above. + data <- data[, .(mean_distance = mean(distance)), by = "gene"] + max_distance <- data[, max(mean_distance)] + data[, score := 1 - mean_distance / max_distance] + + progress(1.0) + + result( + method = "proximity", + scores = data[, .(gene, score)] + ) + }) + } + ) +} diff --git a/man/proximity.Rd b/man/proximity.Rd new file mode 100644 index 0000000..fa8d822 --- /dev/null +++ b/man/proximity.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/proximity.R +\name{proximity} +\alias{proximity} +\title{Score the mean distance of genes to the telomeres across species.} +\usage{ +proximity() +} +\value{ +An object of class \code{geposan_method}. +} +\description{ +A score will be given to each gene such that 0.0 corresponds to the maximal +mean distance across all genes and 1.0 corresponds to a distance of 0. +}