mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 10:47:25 +01:00
neural: Always use position data
This commit is contained in:
parent
4b1ab9fc9a
commit
1af138bf6f
2 changed files with 14 additions and 27 deletions
|
|
@ -41,10 +41,7 @@ analyze <- function(preset, progress = NULL) {
|
||||||
correlation(..., use_positions = TRUE)
|
correlation(..., use_positions = TRUE)
|
||||||
},
|
},
|
||||||
"proximity" = proximity,
|
"proximity" = proximity,
|
||||||
"neural" = neural,
|
"neural" = neural
|
||||||
"neural_positions" = function(...) {
|
|
||||||
neural(..., use_positions = TRUE)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
results <- cached("analysis", preset, {
|
results <- cached("analysis", preset, {
|
||||||
|
|
|
||||||
36
R/neural.R
36
R/neural.R
|
|
@ -1,17 +1,14 @@
|
||||||
# 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(preset,
|
neural <- function(preset, progress = NULL, seed = 448077) {
|
||||||
use_positions = FALSE,
|
|
||||||
progress = NULL,
|
|
||||||
seed = 448077) {
|
|
||||||
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
|
||||||
|
|
||||||
cached(
|
cached(
|
||||||
"neural",
|
"neural",
|
||||||
c(species_ids, gene_ids, reference_gene_ids, use_positions),
|
c(species_ids, gene_ids, reference_gene_ids),
|
||||||
{ # nolint
|
{ # nolint
|
||||||
set.seed(seed)
|
set.seed(seed)
|
||||||
gene_count <- length(gene_ids)
|
gene_count <- length(gene_ids)
|
||||||
|
|
@ -29,27 +26,20 @@ neural <- function(preset,
|
||||||
# enough data.
|
# enough data.
|
||||||
species_ids_included <- NULL
|
species_ids_included <- NULL
|
||||||
|
|
||||||
# Make a column containing distance data for each species.
|
# Make a column containing positions for each species.
|
||||||
for (species_id in species_ids) {
|
for (species_id in species_ids) {
|
||||||
species_data <- if (use_positions) {
|
species_data <- distances[
|
||||||
setnames(distances[
|
species == species_id,
|
||||||
species == species_id,
|
.(gene, position)
|
||||||
.(gene, position)
|
]
|
||||||
], "position", "distance")
|
|
||||||
} else {
|
|
||||||
distances[
|
|
||||||
species == species_id,
|
|
||||||
.(gene, distance)
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Only include species with at least 25% known values.
|
# Only include species with at least 25% known values.
|
||||||
|
|
||||||
species_distances <- stats::na.omit(species_data)
|
species_data <- stats::na.omit(species_data)
|
||||||
|
|
||||||
if (nrow(species_distances) >= 0.25 * gene_count) {
|
if (nrow(species_data) >= 0.25 * gene_count) {
|
||||||
species_ids_included <- c(species_ids_included, species_id)
|
species_ids_included <- c(species_ids_included, species_id)
|
||||||
data <- merge(data, species_distances, all.x = TRUE)
|
data <- merge(data, species_data, all.x = TRUE)
|
||||||
|
|
||||||
# Replace missing data with mean values. The neural network
|
# Replace missing data with mean values. The neural network
|
||||||
# can't handle NAs in a meaningful way. Choosing extreme
|
# can't handle NAs in a meaningful way. Choosing extreme
|
||||||
|
|
@ -58,11 +48,11 @@ neural <- function(preset,
|
||||||
# However, this will of course lessen the significance of
|
# However, this will of course lessen the significance of
|
||||||
# the results.
|
# the results.
|
||||||
|
|
||||||
mean_distance <- round(species_distances[, mean(distance)])
|
mean_position <- round(species_data[, mean(position)])
|
||||||
data[is.na(distance), distance := mean_distance]
|
data[is.na(position), position := mean_position]
|
||||||
|
|
||||||
# Name the new column after the species.
|
# Name the new column after the species.
|
||||||
setnames(data, "distance", species_id)
|
setnames(data, "position", species_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue