mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 10:47:25 +01:00
Reindent code to use just two spaces
This commit is contained in:
parent
a1e6147466
commit
c04b6337e9
17 changed files with 1583 additions and 1582 deletions
|
|
@ -12,14 +12,14 @@
|
|||
#'
|
||||
#' @export
|
||||
densest <- function(data) {
|
||||
as.numeric(if (length(data) <= 0) {
|
||||
NULL
|
||||
} else if (length(data) == 1) {
|
||||
data
|
||||
} else {
|
||||
density <- stats::density(data)
|
||||
mean(density$x[density$y == max(density$y)])
|
||||
})
|
||||
as.numeric(if (length(data) <= 0) {
|
||||
NULL
|
||||
} else if (length(data) == 1) {
|
||||
data
|
||||
} else {
|
||||
density <- stats::density(data)
|
||||
mean(density$x[density$y == max(density$y)])
|
||||
})
|
||||
}
|
||||
|
||||
#' Score genes based on their proximity to the reference genes.
|
||||
|
|
@ -40,80 +40,80 @@ densest <- function(data) {
|
|||
#'
|
||||
#' @export
|
||||
adjacency <- function(distance_estimate = densest, summarize = stats::median) {
|
||||
method(
|
||||
id = "adjacency",
|
||||
name = "Adjacency",
|
||||
description = "Adjacency to reference genes",
|
||||
function(preset, progress) {
|
||||
species_ids <- preset$species_ids
|
||||
gene_ids <- preset$gene_ids
|
||||
reference_gene_ids <- preset$reference_gene_ids
|
||||
method(
|
||||
id = "adjacency",
|
||||
name = "Adjacency",
|
||||
description = "Adjacency to reference genes",
|
||||
function(preset, progress) {
|
||||
species_ids <- preset$species_ids
|
||||
gene_ids <- preset$gene_ids
|
||||
reference_gene_ids <- preset$reference_gene_ids
|
||||
|
||||
cached(
|
||||
"adjacency",
|
||||
c(
|
||||
species_ids,
|
||||
gene_ids,
|
||||
reference_gene_ids,
|
||||
distance_estimate,
|
||||
summarize
|
||||
),
|
||||
{ # nolint
|
||||
# Filter distances by species and gene and summarize each
|
||||
# gene's distance values using the estimation function.
|
||||
data <- geposan::distances[
|
||||
species %chin% species_ids & gene %chin% gene_ids,
|
||||
.(distance = as.numeric(distance_estimate(distance))),
|
||||
by = gene
|
||||
]
|
||||
cached(
|
||||
"adjacency",
|
||||
c(
|
||||
species_ids,
|
||||
gene_ids,
|
||||
reference_gene_ids,
|
||||
distance_estimate,
|
||||
summarize
|
||||
),
|
||||
{ # nolint
|
||||
# Filter distances by species and gene and summarize each
|
||||
# gene's distance values using the estimation function.
|
||||
data <- geposan::distances[
|
||||
species %chin% species_ids & gene %chin% gene_ids,
|
||||
.(distance = as.numeric(distance_estimate(distance))),
|
||||
by = gene
|
||||
]
|
||||
|
||||
# Compute the absolute value of the difference between the
|
||||
# estimated distances of each gene to the reference genes.
|
||||
compute_difference <- function(distance_value,
|
||||
comparison_ids) {
|
||||
differences <- data[
|
||||
gene %chin% comparison_ids,
|
||||
.(difference = abs(distance_value - distance))
|
||||
]
|
||||
# Compute the absolute value of the difference between the
|
||||
# estimated distances of each gene to the reference genes.
|
||||
compute_difference <- function(distance_value,
|
||||
comparison_ids) {
|
||||
differences <- data[
|
||||
gene %chin% comparison_ids,
|
||||
.(difference = abs(distance_value - distance))
|
||||
]
|
||||
|
||||
summarize(differences$difference)
|
||||
}
|
||||
summarize(differences$difference)
|
||||
}
|
||||
|
||||
# Compute the differences to the reference genes.
|
||||
data[
|
||||
!gene %chin% reference_gene_ids,
|
||||
difference := compute_difference(
|
||||
distance,
|
||||
reference_gene_ids
|
||||
),
|
||||
by = gene
|
||||
]
|
||||
# Compute the differences to the reference genes.
|
||||
data[
|
||||
!gene %chin% reference_gene_ids,
|
||||
difference := compute_difference(
|
||||
distance,
|
||||
reference_gene_ids
|
||||
),
|
||||
by = gene
|
||||
]
|
||||
|
||||
progress(0.5)
|
||||
progress(0.5)
|
||||
|
||||
# Exclude the reference gene itself when computing its
|
||||
# difference.
|
||||
data[
|
||||
gene %chin% reference_gene_ids,
|
||||
difference := compute_difference(
|
||||
distance,
|
||||
reference_gene_ids[reference_gene_ids != gene]
|
||||
),
|
||||
by = gene
|
||||
]
|
||||
# Exclude the reference gene itself when computing its
|
||||
# difference.
|
||||
data[
|
||||
gene %chin% reference_gene_ids,
|
||||
difference := compute_difference(
|
||||
distance,
|
||||
reference_gene_ids[reference_gene_ids != gene]
|
||||
),
|
||||
by = gene
|
||||
]
|
||||
|
||||
# Compute the final score by normalizing the difference.
|
||||
data[, score := 1 - difference / max(difference)]
|
||||
# Compute the final score by normalizing the difference.
|
||||
data[, score := 1 - difference / max(difference)]
|
||||
|
||||
progress(1.0)
|
||||
progress(1.0)
|
||||
|
||||
result(
|
||||
method = "adjacency",
|
||||
scores = data[, .(gene, score)],
|
||||
details = list(data = data)
|
||||
)
|
||||
}
|
||||
)
|
||||
result(
|
||||
method = "adjacency",
|
||||
scores = data[, .(gene, score)],
|
||||
details = list(data = data)
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue