Skip to content

Commit

Permalink
update simulate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmollina committed Aug 29, 2023
1 parent cbe5e7b commit cd64aad
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
7 changes: 5 additions & 2 deletions R/cross_simulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#'
#' @param file name of the output file. It is ignored if
#' \code{draw = TRUE}
#'
#' @param prefix prefix used in all marker names.
#'
#' @param seed random number generator seed (default = NULL)
#'
Expand All @@ -42,8 +44,7 @@
#'
#' @examples
#' h.temp <- sim_homologous(ploidy = 6, n.mrk = 20)
#' fake.poly.dat <- cross_simulate(ploidy = 6, map.length = .05, n.mrk = 20,
#' n.ind = 200, h.temp, seed = 123)
#' fake.poly.dat <- cross_simulate(h.temp, map.length = 100, n.ind = 200)
#' plot(fake.poly.dat)
#'
#'
Expand All @@ -62,6 +63,7 @@ cross_simulate <- function(parental.phases,
n.ind,
draw = FALSE,
file = "output.pdf",
prefix = NULL,
seed = NULL,
width = 12,
height = 6,
Expand All @@ -87,6 +89,7 @@ cross_simulate <- function(parental.phases,
parental.phases$hom.allele.q,
file = file, width = width, height = height)
geno <- t(x[[1]])
rownames(geno) <- paste0(prefix, rownames(geno))
ind.names <- colnames(geno)
mrk.names <- rownames(geno)
res<-structure(list(ploidy = ploidy,
Expand Down
62 changes: 30 additions & 32 deletions R/est_map_hmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,20 @@ est_rf_hmm <- function(input.seq, input.ph = NULL,
#' @importFrom cli rule
#' @export est_rf_hmm_sequential
est_rf_hmm_sequential <- function(input.seq,
twopt,
start.set = 4,
thres.twopt = 5,
thres.hmm = 50,
extend.tail = NULL,
phase.number.limit = 20,
sub.map.size.diff.limit = Inf,
info.tail = TRUE,
reestimate.single.ph.configuration = FALSE,
tol = 10e-2,
tol.final = 10e-4,
verbose = TRUE,
detailed.verbose = FALSE,
high.prec = FALSE)
twopt,
start.set = 4,
thres.twopt = 5,
thres.hmm = 50,
extend.tail = NULL,
phase.number.limit = 20,
sub.map.size.diff.limit = Inf,
info.tail = TRUE,
reestimate.single.ph.configuration = FALSE,
tol = 10e-2,
tol.final = 10e-4,
verbose = TRUE,
detailed.verbose = FALSE,
high.prec = FALSE)
{## checking for correct object
input_classes <- c("mappoly.sequence", "mappoly.twopt")
if (!inherits(input.seq, input_classes[1])) {
Expand Down Expand Up @@ -566,11 +566,11 @@ est_rf_hmm_sequential <- function(input.seq,
## Gathering linkage phases of the current map, excluding the marker inserted
## in the current round
ph.new <- lapply(cur.map.temp$maps, function(x) list(P = head(x$seq.ph$P, -1),
Q = head(x$seq.ph$Q, -1)))
Q = head(x$seq.ph$Q, -1)))
## Gathering linkage phases of the previous map, excluding the marker inserted
## in the current round
ph.old <- lapply(cur.map$maps, function(x, id) list(P = x$seq.ph$P[id],
Q = x$seq.ph$Q[id]), id = names(ph.new[[1]]$P))
Q = x$seq.ph$Q[id]), id = names(ph.new[[1]]$P))
## Check in which whole phase configurations the new
## HMM tail should be appended
MQ <- MP <- matrix(NA, length(ph.old), length(ph.new))
Expand Down Expand Up @@ -819,12 +819,10 @@ plot.mappoly.map <- function(x, left.lim = 0, right.lim = Inf,
pal <- var.col[pp[id.left:id.right,i]]
rect(xleft = x1 - x.control, ybottom = y1 -.05, xright = x1 + x.control, ytop = y1 +.05, col = pal, border = NA)
}
if(ploidy != 2){
points(x = x1,
y = zy[ploidy]+0.05+dp[id.left:id.right]/20,
col = d.col[as.character(dp[id.left:id.right])],
pch = 19, cex = .7)
}
points(x = x1,
y = zy[ploidy]+0.05+dp[id.left:id.right]/20,
col = d.col[as.character(dp[id.left:id.right])],
pch = 19, cex = .7)
if(mrk.names)
text(x = x1,
y = rep(zy[ploidy]+0.05+.3, length(curx)),
Expand Down Expand Up @@ -1045,17 +1043,17 @@ check_ls_phase <- function(ph){
#' @keywords internal
print_ph <- function(input.ph){
phs.P <- lapply(input.ph$config.to.test,
function(x, ploidy) {
M <- matrix("|", nrow = 1, ncol = ploidy)
M[unlist(tail(x$P, 1))] <- crayon::red(cli::symbol$bullet)
paste(M, collapse = "")},
ploidy = input.ph$ploidy)
function(x, ploidy) {
M <- matrix("|", nrow = 1, ncol = ploidy)
M[unlist(tail(x$P, 1))] <- crayon::red(cli::symbol$bullet)
paste(M, collapse = "")},
ploidy = input.ph$ploidy)
phs.Q <- lapply(input.ph$config.to.test,
function(x, ploidy) {
M <- matrix("|", nrow = 1, ncol = ploidy)
M[unlist(tail(x$Q, 1))] <- crayon::cyan(cli::symbol$bullet)
paste(M, collapse = "")},
ploidy = input.ph$ploidy)
function(x, ploidy) {
M <- matrix("|", nrow = 1, ncol = ploidy)
M[unlist(tail(x$Q, 1))] <- crayon::cyan(cli::symbol$bullet)
paste(M, collapse = "")},
ploidy = input.ph$ploidy)
if(length(phs.P) == 1)
return(paste(unlist(phs.P)[1], unlist(phs.Q)[1], " "))
if(length(phs.P) == 2)
Expand Down
2 changes: 1 addition & 1 deletion R/filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ rf_snp_filter <- function(input.twopt,
#' comparing to another set order
#'
#' @param input.seq object of class mappoly.sequence with alternative order (not genomic order)
#' @param dat object of class mappoly.data
#' @param input.data object of class mappoly.data
#'
#' @author Cristiane Taniguti, \email{[email protected]}
#'
Expand Down
12 changes: 6 additions & 6 deletions man/cross_simulate.Rd

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

2 changes: 1 addition & 1 deletion man/draw_cross.Rd

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

2 changes: 1 addition & 1 deletion man/edit_order.Rd

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

3 changes: 1 addition & 2 deletions tests/testthat/test-simulation.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
context("Simulate datasets")
test_that("simulate datasets correctly", {
h.temp<-sim_homologous(ploidy=6, n.mrk=20)
dat<-cross_simulate(ploidy=6, rf.vec=.05, n.mrk=20,
n.ind=20, h.temp, seed=123)
dat<-cross_simulate(h.temp, 100, n.ind = 100)
expect_is(dat, "mappoly.data")
})

0 comments on commit cd64aad

Please sign in to comment.