neural: Readd distances as input data

This commit is contained in:
Elias Projahn 2021-11-16 16:23:03 +01:00
parent 88d6837fee
commit f84d37dd30
2 changed files with 24 additions and 11 deletions

View file

@ -40,8 +40,11 @@ analyze <- function(preset, progress = NULL) {
"correlation_positions" = function(...) { "correlation_positions" = function(...) {
correlation(..., use_positions = TRUE) correlation(..., use_positions = TRUE)
}, },
"proximity" = proximity, "neural" = neural,
"neural" = neural "neural_positions" = function(...) {
neural(..., use_positions = TRUE)
},
"proximity" = proximity
) )
results <- cached("analysis", preset, { results <- cached("analysis", preset, {

View file

@ -1,14 +1,17 @@
# 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, progress = NULL, seed = 448077) { neural <- function(preset,
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), c(species_ids, gene_ids, reference_gene_ids, use_positions),
{ # nolint { # nolint
set.seed(seed) set.seed(seed)
gene_count <- length(gene_ids) gene_count <- length(gene_ids)
@ -28,10 +31,17 @@ neural <- function(preset, progress = NULL, seed = 448077) {
# Make a column containing positions 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 <- distances[ species_data <- if (use_positions) {
species == species_id, setnames(distances[
.(gene, position) species == species_id,
] .(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.
@ -48,11 +58,11 @@ neural <- function(preset, progress = NULL, seed = 448077) {
# However, this will of course lessen the significance of # However, this will of course lessen the significance of
# the results. # the results.
mean_position <- round(species_data[, mean(position)]) mean_distance <- round(species_data[, mean(distance)])
data[is.na(position), position := mean_position] data[is.na(distance), distance := mean_distance]
# Name the new column after the species. # Name the new column after the species.
setnames(data, "position", species_id) setnames(data, "distance", species_id)
} }
} }