Skip to content

Commit

Permalink
Small speed improvement (1.2x) of tsum_test() using a more suitable s…
Browse files Browse the repository at this point in the history
…orting algorithm (shell).

Former-commit-id: 37f5075
  • Loading branch information
Rick Tankard committed Sep 2, 2018
1 parent c31f9c8 commit edbfc17
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: exSTRa
Type: Package
Title: Expanded STR algorithm: detecting expansions in Illumina sequencing data
Version: 0.88.0
Date: 2018-08-31
Version: 0.88.2
Date: 2018-09-02
Author: Rick Tankard
Maintainer: Rick Tankard <[email protected]>
Description: Detecting expansions with paired-end Illumina sequencing data.
Expand Down
8 changes: 4 additions & 4 deletions R/private_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ make_quantiles_matrix <- function(strscore, loc = TRUE, sample = NULL, read_coun
}
assert("Cannot set both probs and n.quantiles", is.null(probs) || is.null(n.quantiles))
if(is.null(probs) && is.null(n.quantiles)) {
n.quantiles <- loc_data[, .N, by = sample][, quantile(N, read_count_quant, names = FALSE)] %>% round
n.quantiles <- round(loc_data[, .N, by = sample][, quantile(N, read_count_quant, names = FALSE)])
}
method <- tolower(method)
if(method == "al1" || method == "al1_all") {
Expand All @@ -403,7 +403,7 @@ make_quantiles_matrix <- function(strscore, loc = TRUE, sample = NULL, read_coun
stop('"Please choose type for quantile with method = "quantile#"')
}
if(grepl("^quantile\\d", method)) {
quantile_type <- sub("quantile", "", method) %>% as.numeric()
quantile_type <- as.numeric(sub("quantile", "", method))
method <- "quantile"
}
assert("samples is not the key of strscore$samples", key(strscore$samples)[1] == "sample")
Expand Down Expand Up @@ -440,15 +440,15 @@ make_quantiles_matrix <- function(strscore, loc = TRUE, sample = NULL, read_coun
}
v <- sort(v)
} else if(method == "al1_all") {
v <- munoz_rueda_al1(y, n.quantiles) %>% sort
v <- sort(munoz_rueda_al1(y, n.quantiles))
} else {
stop("Undefined method ", method)
}
quant.matrix[sampi, ] <- v
}
rownames(quant.matrix) <- sample
# remove NA rows
low.count.samples <- apply(quant.matrix, 1, function(x) { is.na(x) %>% all })
low.count.samples <- apply(quant.matrix, 1, function(x) { all(is.na(x)) })
quant.matrix <- quant.matrix[!low.count.samples, ]
list(x = probs, y.mat = quant.matrix, low.count = names(low.count.samples[low.count.samples]))
}
Expand Down
2 changes: 1 addition & 1 deletion R/tsum_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ tsum_statistic_1locus <- function(
sqm <- t (replicate(N, rnorm(M, mu_vec, se_vec)))
# as this means the quantiles of a sample are no longer ordered, we sort
for(i in seq_len(N)) {
sqm[i, ] <- sort.int(sqm[i, ])
sqm[i, ] <- sort.int(sqm[i, ], method = "shell")
}
sqm
}
Expand Down

0 comments on commit edbfc17

Please sign in to comment.