Skip to content

Commit

Permalink
When 'replace = FALSE' is set in
Browse files Browse the repository at this point in the history
extract_random_seqs_from_genome(), the command will still hold 'replace = TRUE' for the chromosome and strand to be sampled, but the sequence that
was sampled will be removed #2
  • Loading branch information
HajkD committed Sep 5, 2019
1 parent f3ff53f commit 2ea0ca4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
10 changes: 7 additions & 3 deletions R/extract_random_seqs_from_genome.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ extract_random_seqs_from_genome <-
res <- vector("list", length(size))

for (i in seq_len(size)) {
sample_chromsome <- sample.int(length(chr_names), 1, replace = replace, prob = prob)
sample_chromsome <- sample.int(length(chr_names), 1, replace = TRUE, prob = NULL)
sample_strand <- sample.int(2, 1, replace = replace, prob = c(0.5, 0.5))

if (sample_strand == 1){
sample_i <- sample_chromosome_intervals(
chr_size = imported_genome_i[chr_names[sample_chromsome]]@ranges@width,
interval_width = interval_width,
strand = "plus",
size = 1
size = 1,
replace = replace,
prob = prob
)

sample_i <- dplyr::mutate(sample_i, chr = chr_names[sample_chromsome])
Expand All @@ -99,7 +101,9 @@ extract_random_seqs_from_genome <-
chr_size = imported_genome_i[chr_names[sample_chromsome]]@ranges@width,
interval_width = interval_width,
strand = "minus",
size = 1
size = 1,
replace = replace,
prob = prob
)

sample_i <-
Expand Down
18 changes: 15 additions & 3 deletions R/sample_chromosome_intervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
#' \item \code{strand = "minus"}
#' }
#' @param size a non-negative integer giving the number of sequences that shall be sampled from random genomic loci.
#' @param replace logical value indicating whether sampling should be with replacement. Default: \code{replace = TRUE}.
#' @param prob a vector of probability weights for obtaining the elements of the vector being sampled. Default is \code{prob = NULL}.
#' @author Hajk-Georg Drost
sample_chromosome_intervals <- function(chr_size, interval_width, strand, size) {

sample_chromosome_intervals <-
function(chr_size,
interval_width,
strand,
size,
replace = TRUE,
prob = NULL) {

if (!is.element(strand, c("plus", "minus")))
stop("The 'strand' argument can only be specified as strand = 'plus' or strand = 'minus'.", call. = FALSE)

Expand All @@ -27,7 +35,11 @@ sample_chromosome_intervals <- function(chr_size, interval_width, strand, size)
}

# random start position in chromosome
random_start <- sample.int(ifelse((chr_size - interval_width) == 0,1, chr_size - interval_width), size)
random_start <-
sample.int(ifelse((chr_size - interval_width) == 0, 1, chr_size - interval_width),
size,
replace = replace,
prob = prob)
# compute random end position in chromosome given interval width
random_end <- random_start + interval_width - 1

Expand Down
7 changes: 6 additions & 1 deletion man/sample_chromosome_intervals.Rd

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

0 comments on commit 2ea0ca4

Please sign in to comment.