mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 18:57:25 +01:00
Properly access distance data
This commit is contained in:
parent
c0a1d965d7
commit
21a5817988
5 changed files with 12 additions and 18 deletions
14
R/analyze.R
14
R/analyze.R
|
|
@ -45,9 +45,8 @@ analyze <- function(preset, progress = NULL) {
|
||||||
#
|
#
|
||||||
# A method describes a way to perform a computation on gene distance data
|
# A method describes a way to perform a computation on gene distance data
|
||||||
# that results in a single score per gene. The function should accept the
|
# that results in a single score per gene. The function should accept the
|
||||||
# distances data, the preset to apply (see [preset()]) and an optional
|
# preset to apply (see [preset()]) and an optional progress function (that
|
||||||
# progress function (that may be called with a number between 0.0 and 1.0)
|
# may be called with a number between 0.0 and 1.0) as its parameters.
|
||||||
# as its parameters.
|
|
||||||
#
|
#
|
||||||
# The function should return a [data.table] with the following columns:
|
# The function should return a [data.table] with the following columns:
|
||||||
#
|
#
|
||||||
|
|
@ -62,19 +61,14 @@ analyze <- function(preset, progress = NULL) {
|
||||||
|
|
||||||
total_progress <- 0.0
|
total_progress <- 0.0
|
||||||
method_count <- length(preset$method_ids)
|
method_count <- length(preset$method_ids)
|
||||||
results <- data.table(gene = genes$id)
|
results <- data.table(gene = preset$gene_ids)
|
||||||
|
|
||||||
for (method_id in preset$method_ids) {
|
for (method_id in preset$method_ids) {
|
||||||
method_progress <- if (!is.null(progress)) function(p) {
|
method_progress <- if (!is.null(progress)) function(p) {
|
||||||
progress(total_progress + p / method_count)
|
progress(total_progress + p / method_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
method_results <- methods[[method_id]](
|
method_results <- methods[[method_id]](preset, method_progress)
|
||||||
distances,
|
|
||||||
preset,
|
|
||||||
method_progress
|
|
||||||
)
|
|
||||||
|
|
||||||
setnames(method_results, "score", method_id)
|
setnames(method_results, "score", method_id)
|
||||||
|
|
||||||
results <- merge(
|
results <- merge(
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,11 @@ clusteriness_priv <- function(data, height = 1000000) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Process genes clustering their distance to telomeres.
|
# Process genes clustering their distance to telomeres.
|
||||||
clusteriness <- function(distances, preset, progress = NULL) {
|
clusteriness <- function(preset, progress = NULL) {
|
||||||
results <- data.table(gene = preset$gene_ids)
|
results <- data.table(gene = preset$gene_ids)
|
||||||
|
|
||||||
# Prefilter the input data by species.
|
# Prefilter the input data by species.
|
||||||
distances <- distances[species %chin% preset$species_ids]
|
distances <- geposan::distances[species %chin% preset$species_ids]
|
||||||
|
|
||||||
# Add an index for quickly accessing data per gene.
|
# Add an index for quickly accessing data per gene.
|
||||||
setkey(distances, gene)
|
setkey(distances, gene)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
# Compute the mean correlation coefficient comparing gene distances with a set
|
# Compute the mean correlation coefficient comparing gene distances with a set
|
||||||
# of reference genes.
|
# of reference genes.
|
||||||
correlation <- function(distances, preset, progress = NULL) {
|
correlation <- function(preset, progress = NULL) {
|
||||||
species_ids <- preset$species_ids
|
species_ids <- preset$species_ids
|
||||||
gene_ids <- preset$gene_ids
|
gene_ids <- preset$gene_ids
|
||||||
reference_gene_ids <- preset$reference_gene_ids
|
reference_gene_ids <- preset$reference_gene_ids
|
||||||
|
|
||||||
# Prefilter distances by species.
|
# Prefilter distances by species.
|
||||||
distances <- distances[species %chin% species_ids]
|
distances <- geposan::distances[species %chin% species_ids]
|
||||||
|
|
||||||
# Tranform data to get species as rows and genes as columns. We construct
|
# Tranform data to get species as rows and genes as columns. We construct
|
||||||
# columns per species, because it requires fewer iterations, and transpose
|
# columns per species, because it requires fewer iterations, and transpose
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Find genes by training a neural network on reference position data.
|
# Find genes by training a neural network on reference position data.
|
||||||
#
|
#
|
||||||
# @param seed A seed to get reproducible results.
|
# @param seed A seed to get reproducible results.
|
||||||
neural <- function(distances, preset, progress = NULL, seed = 448077) {
|
neural <- function(preset, progress = NULL, seed = 448077) {
|
||||||
species_ids <- preset$species_ids
|
species_ids <- preset$species_ids
|
||||||
reference_gene_ids <- preset$reference_gene_ids
|
reference_gene_ids <- preset$reference_gene_ids
|
||||||
|
|
||||||
|
|
@ -9,7 +9,7 @@ neural <- function(distances, preset, progress = NULL, seed = 448077) {
|
||||||
gene_count <- length(preset$gene_ids)
|
gene_count <- length(preset$gene_ids)
|
||||||
|
|
||||||
# Prefilter distances by species.
|
# Prefilter distances by species.
|
||||||
distances <- distances[species %chin% species_ids]
|
distances <- geposan::distances[species %chin% species_ids]
|
||||||
|
|
||||||
# Input data for the network. This contains the gene ID as an identifier
|
# Input data for the network. This contains the gene ID as an identifier
|
||||||
# as well as the per-species gene distances as input variables.
|
# as well as the per-species gene distances as input variables.
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
#
|
#
|
||||||
# A score will be given to each gene such that 0.0 corresponds to the maximal
|
# 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.
|
# mean distance across all genes and 1.0 corresponds to a distance of 0.
|
||||||
proximity <- function(distances, preset, progress = NULL) {
|
proximity <- function(preset, progress = NULL) {
|
||||||
# Prefilter distances by species and gene.
|
# Prefilter distances by species and gene.
|
||||||
distances <- distances[
|
distances <- geposan::distances[
|
||||||
species %chin% preset$species_ids & gene %chin% preset$gene_ids
|
species %chin% preset$species_ids & gene %chin% preset$gene_ids
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue