Skip to content

Commit

Permalink
Adding conditional statements to all functions using reticulate
Browse files Browse the repository at this point in the history
  • Loading branch information
ncborcherding committed Dec 31, 2024
1 parent 1ab0abb commit 48f1be3
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 164 deletions.
4 changes: 3 additions & 1 deletion R/onehotEncoder.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#' number.of.sequences = 100,
#' min.length = 8,
#' max.length = 16)
#'
#'
#' if(reticulate::py_module_available("numpy")) {
#' sequence.matrix <- onehotEncoder(new.sequences,
#' convert.to.matrix = TRUE)
#' }
#'
#' @param input.sequences The amino acid or nucleotide sequences to use
#' @param max.length Additional length to pad, NULL will pad sequences
Expand Down
4 changes: 3 additions & 1 deletion R/propertyEncoder.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#' number.of.sequences = 100,
#' min.length = 8,
#' max.length = 16)
#'
#'
#' if(reticulate::py_module_available("numpy")) {
#' sequence.matrix <- propertyEncoder(new.sequences,
#' method.to.use = "VHSE",
#' convert.to.matrix = TRUE)
#' }
#'
#' @param input.sequences The amino acid sequences to use
#' @param max.length Additional length to pad, NULL will pad sequences
Expand Down
3 changes: 2 additions & 1 deletion R/sequenceDecoder.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#' number.of.sequences = 100,
#' min.length = 8,
#' max.length = 16)
#'
#' if(reticulate::py_module_available("numpy")) {
#' sequence.matrix <- onehotEncoder(new.sequences,
#' convert.to.matrix = TRUE)
#'
#' decoded.sequences <- sequenceDecoder(sequence.matrix,
#' padding.symbol = ".")
#' }
#'
#' @param sequence.matrix The encoded sequences to decode in an array or matrix
#' @param encoder The method to prepare the sequencing information -
Expand Down
6 changes: 3 additions & 3 deletions R/variationalSequences.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
#' autoencoder (VAE) and perturbation of the probability distributions.
#'
#' @examples
#' \dontrun{
#' sequences <- generateSequences(prefix.motif = "CAS",
#' suffix.motif = "YF",
#' number.of.sequences = 100,
#' min.length = 8,
#' max.length = 16)
#'
#'
#' if(reticulate::py_module_available("keras")) {
#' new.sequences <- variationalSequences(sequences,
#' encoder = "onehotEncoder",
#' encoder.hidden.dim = c(256, 128),
#' latent.dim = 16,
#' batch.size = 16)
#' }
#'}
#'
#' @param input.sequences The amino acid or nucleotide sequences to use
#' @param encoder.function The method to prepare the sequencing information -
Expand Down
4 changes: 3 additions & 1 deletion man/onehotEncoder.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/propertyEncoder.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/sequenceDecoder.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/variationalSequences.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 51 additions & 51 deletions tests/testthat/test-onehotEncoder.R
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
# test script for onehotEncoder.R - testcases are NOT comprehensive!

test_that("onehotEncoder works", {

sequences <- getdata("generateSequences", "generateSequences_T1")

ohe.default <- onehotEncoder(sequences)

expect_equal(
ohe.default,
getdata("ohe.encoder", "onehotEncoder_matrix")
)

ohe.2mer <- onehotEncoder(sequences,
motif.length = 2)
expect_equal(
ohe.2mer,
getdata("ohe.encoder", "onehotEncoder_2mer.matrix")
)

ohe.padded <- onehotEncoder(sequences,
max.length = 40)

expect_equal(
ohe.padded,
getdata("ohe.encoder", "onehotEncoder_padded.matrix")
)

ohe.array <- onehotEncoder(sequences,
convert.to.matrix = FALSE)

expect_equal(
ohe.array,
getdata("ohe.encoder", "onehotEncoder_array")
)

ohe.padded.array <- onehotEncoder(sequences,
max.length = 40,
convert.to.matrix = FALSE)

expect_equal(
ohe.padded.array,
getdata("ohe.encoder", "onehotEncoder_padded.array")
)

nt.sequences <- getdata("generateSequences", "generateSequences_T2")

ohe.nt <- onehotEncoder(nt.sequences,
sequence.dictionary = c("A", "C", "T", "G"))

expect_equal(
ohe.nt,
getdata("ohe.encoder", "onehotEncoder_nucleotide.matrix")
)

if(reticulate::py_module_available("numpy")) {
ohe.default <- onehotEncoder(sequences)
expect_equal(
ohe.default,
getdata("ohe.encoder", "onehotEncoder_matrix")
)
ohe.2mer <- onehotEncoder(sequences,
motif.length = 2)
expect_equal(
ohe.2mer,
getdata("ohe.encoder", "onehotEncoder_2mer.matrix")
)
ohe.padded <- onehotEncoder(sequences,
max.length = 40)
expect_equal(
ohe.padded,
getdata("ohe.encoder", "onehotEncoder_padded.matrix")
)
ohe.array <- onehotEncoder(sequences,
convert.to.matrix = FALSE)
expect_equal(
ohe.array,
getdata("ohe.encoder", "onehotEncoder_array")
)
ohe.padded.array <- onehotEncoder(sequences,
max.length = 40,
convert.to.matrix = FALSE)
expect_equal(
ohe.padded.array,
getdata("ohe.encoder", "onehotEncoder_padded.array")
)
nt.sequences <- getdata("generateSequences", "generateSequences_T2")
ohe.nt <- onehotEncoder(nt.sequences,
sequence.dictionary = c("A", "C", "T", "G"))
expect_equal(
ohe.nt,
getdata("ohe.encoder", "onehotEncoder_nucleotide.matrix")
)
}
})
140 changes: 70 additions & 70 deletions tests/testthat/test-propertyEncoder.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,75 @@
test_that("propertyEncoder works", {

sequences <- getdata("generateSequences", "generateSequences_T1")

#Return Matrix
af.matrix <- propertyEncoder(sequences,
method.to.use = "atchleyFactors",
convert.to.matrix = TRUE)

expect_equal(
af.matrix,
getdata("propertyEncoder", "propertyEncoder_AtchleyFactors_matrix")
)

#Return Array
kf.array <- propertyEncoder(sequences,
method.to.use = "kideraFactors",
convert.to.matrix = FALSE)

expect_equal(
kf.array,
getdata("propertyEncoder", "propertyEncoder_KideraFactors_array")
)

#Padded Matrix
fasgai.matrix <- propertyEncoder(sequences,
max.length = 40,
method.to.use = "FASGAI",
convert.to.matrix = FALSE)

expect_equal(
fasgai.matrix,
getdata("propertyEncoder", "propertyEncoder_FASGAI_matrix")
)

#Padded Array
vhse.array <- propertyEncoder(sequences,
max.length = 40,
method.to.use = "VHSE",
if(reticulate::py_module_available("numpy")) {
#Return Matrix
af.matrix <- propertyEncoder(sequences,
method.to.use = "atchleyFactors",
convert.to.matrix = TRUE)

expect_equal(
af.matrix,
getdata("propertyEncoder", "propertyEncoder_AtchleyFactors_matrix")
)

#Return Array
kf.array <- propertyEncoder(sequences,
method.to.use = "kideraFactors",
convert.to.matrix = FALSE)

expect_equal(
vhse.array,
getdata("propertyEncoder", "propertyEncoder_VSHE_array")
)

#Return Summary Matrix
median.matrix <- propertyEncoder(sequences,
method.to.use = "atchleyFactors",
summary.function = "median")

expect_equal(
median.matrix,
getdata("propertyEncoder", "propertyEncoder_AtchleyFactors_median.matrix")
)

#Return multiple properties
multi.matrix <- propertyEncoder(sequences,
method.to.use = c("atchleyFactors", "kideraFactors"))

expect_equal(
multi.matrix,
getdata("propertyEncoder", "propertyEncoder_multi_matrix")
)

multi.array <- propertyEncoder(sequences,
method.to.use = c("VHSE", "tScales"),
convert.to.matrix = FALSE)

expect_equal(
multi.array,
getdata("propertyEncoder", "propertyEncoder_multi_array")
)


expect_equal(
kf.array,
getdata("propertyEncoder", "propertyEncoder_KideraFactors_array")
)

#Padded Matrix
fasgai.matrix <- propertyEncoder(sequences,
max.length = 40,
method.to.use = "FASGAI",
convert.to.matrix = FALSE)

expect_equal(
fasgai.matrix,
getdata("propertyEncoder", "propertyEncoder_FASGAI_matrix")
)

#Padded Array
vhse.array <- propertyEncoder(sequences,
max.length = 40,
method.to.use = "VHSE",
convert.to.matrix = FALSE)

expect_equal(
vhse.array,
getdata("propertyEncoder", "propertyEncoder_VSHE_array")
)

#Return Summary Matrix
median.matrix <- propertyEncoder(sequences,
method.to.use = "atchleyFactors",
summary.function = "median")

expect_equal(
median.matrix,
getdata("propertyEncoder", "propertyEncoder_AtchleyFactors_median.matrix")
)

#Return multiple properties
multi.matrix <- propertyEncoder(sequences,
method.to.use = c("atchleyFactors", "kideraFactors"))

expect_equal(
multi.matrix,
getdata("propertyEncoder", "propertyEncoder_multi_matrix")
)

multi.array <- propertyEncoder(sequences,
method.to.use = c("VHSE", "tScales"),
convert.to.matrix = FALSE)

expect_equal(
multi.array,
getdata("propertyEncoder", "propertyEncoder_multi_array")
)
}
})
Loading

0 comments on commit 48f1be3

Please sign in to comment.