Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make file non-parsable #4

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

calculate_log_probability <- function(kmer_genus_count, word_specific_priors, genus_counts) {
.Call(`_phylotypr_calculate_log_probability`, kmer_genus_count, word_specific_priors, genus_counts)
.Call(`_phylotypr_calculate_log_probability`, kmer_genus_count, word_specific_priors, genus_counts)
}

54 changes: 28 additions & 26 deletions benchmarking/benchmark_str.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ n_kmers <- stringi::stri_length(sequence) - 8 + 1

b_substr <- function() {
seq_kmers <- character(length = n_kmers)
for(i in seq_along(1:n_kmers)){
for (i in seq_along(1:n_kmers)) {
seq_kmers[i] <- substr(sequence, i, i + 8 - 1)
}
}

b_substring <- function() {
substring(sequence, 1:n_kmers, 8:1500)
}
i_substring <- function(){
i_substring <- function() {
stringi::stri_sub(sequence, 1:n_kmers, 8:1500)
}
r_substring <- function(){
r_substring <- function() {
stringr::str_sub(sequence, 1:n_kmers, 8:1500)
}

microbenchmark(b_substr(), b_substring(), i_substring(), r_substrin)

#toupper and tolower
#seq_to_base4
# toupper and tolower
# seq_to_base4
sequence_upper <- sequence
sequence_lower <- tolower(sequence)

Expand All @@ -69,44 +69,46 @@ r_toupper <- function(x) {
stringr::str_to_upper(x)
}

microbenchmark(b_toupper(sequence_upper),
b_toupper(sequence_lower),
b_tolower(sequence_upper),
b_tolower(sequence_lower),

i_toupper(sequence_upper),
i_toupper(sequence_lower),
i_tolower(sequence_upper),
i_tolower(sequence_lower),

r_toupper(sequence_upper),
r_toupper(sequence_lower),
r_tolower(sequence_upper),
r_tolower(sequence_lower))
microbenchmark(
b_toupper(sequence_upper),
b_toupper(sequence_lower),
b_tolower(sequence_upper),
b_tolower(sequence_lower),
i_toupper(sequence_upper),
i_toupper(sequence_lower),
i_tolower(sequence_upper),
i_tolower(sequence_lower),
r_toupper(sequence_upper),
r_toupper(sequence_lower),
r_tolower(sequence_upper),
r_tolower(sequence_lower)
)


# want to replace non-atgc with a n character
sequence_good <- sequence
sequence_bad <- paste0(sequence_good, "R")

b_gsub <- function(x){
b_gsub <- function(x) {
gsub(pattern = "[^ACGT]", replacement = "N", x = x)
}
i_replace <- function(x){
i_replace <- function(x) {
stringi::stri_replace_all_charclass(x, "[^ATGC]", "N")
}
r_replace <- function(x){
r_replace <- function(x) {
stringr::str_replace_all(x, "[^ATGC]", "N")
}

microbenchmark(b_gsub(sequence_good), b_gsub(sequence_bad),
i_replace(sequence_good), i_replace(sequence_bad),
r_replace(sequence_good), r_replace(sequence_bad))
microbenchmark(
b_gsub(sequence_good), b_gsub(sequence_bad),
i_replace(sequence_good), i_replace(sequence_bad),
r_replace(sequence_good), r_replace(sequence_bad)
)


# need to convert A C G T to 0 1 2 3

b_chartr <- function(){
b_chartr <- function() {
chartr("ACGT", "0123", sequence)
}
i_chartr <- function() {
Expand Down
4 changes: 2 additions & 2 deletions benchmarking/benchmark_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set.seed(19760620)
fake_kmers <- sample(1:10, size = 50, replace = TRUE) + 20
n_kmers <- 64

k_table <- function(){
k_table <- function() {
kmer_table <- table(fake_kmers)
kmer_values <- names(kmer_table) |> as.numeric()
kmer_counts <- as.numeric(kmer_table)
Expand All @@ -13,7 +13,7 @@ k_table <- function(){
kmer_vector
}

k_tabulate <- function(){
k_tabulate <- function() {
tabulate(fake_kmers, nbins = n_kmers)
}

Expand Down
Loading
Loading