Skip to content

Commit

Permalink
lint for code factor
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbrazeau committed Dec 20, 2024
1 parent 4c7e7e0 commit a8ebac9
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 39 deletions.
24 changes: 11 additions & 13 deletions data-raw/IBD_simulation_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ sim_IBDIBD <- function(demesize, distmat, rate, Ft) {
) %>%
magrittr::set_colnames(c("deme1", "deme2", "geodist"))
# individuals to long
inds <- 1:cumsum(demesize)[length(demesize)]
inds <- seq_len(cumsum(demesize)[length(demesize)])
# trackers for demes
d1 <- tibble::tibble(smpl1 = inds, deme1 = as.factor(rep(1:length(demesize), demesize)),
d1 <- tibble::tibble(smpl1 = inds, deme1 = as.factor(rep(seq_len(length(demesize)), demesize)),
demesize1 = rep(demesize, demesize))
d2 <- tibble::tibble(smpl2 = inds, deme2 = as.factor(rep(1:length(demesize), demesize)),
d2 <- tibble::tibble(smpl2 = inds, deme2 = as.factor(rep(seq_len(length(demesize)), demesize)),
demesize2 = rep(demesize, demesize))
# combinations and joins
combinds <- tibble::as_tibble(t(combn(inds, 2)), .name_repair = "minimal") %>%
Expand All @@ -77,35 +77,33 @@ sim_IBDIBD <- function(demesize, distmat, rate, Ft) {

# function for drawing mean IBD based iso by dist
draw_mean_Ftibd <- function(demesize1, demesize2, geodist, rate, Ft) {
ret <- 1/(demesize1 + demesize2) * (1 - pexp(geodist, rate)) +
1/(demesize1 + demesize2) * (1 - pexp(geodist, rate)) +
( (1 - 1/(demesize1 + demesize2)) * (1 - pexp(geodist, rate)) * Ft )
return(ret)
}
combinds$mft <- purrr::pmap_dbl(combinds[,c("demesize1", "demesize2", "geodist")],
draw_mean_Ftibd,
rate = rate, Ft = Ft)

# draw value of realized IBD from mean distribution
draw_realized_ibdibd <- function(mft) {
ribdibd <- rnorm_interval(mean = mft, sd = mft * (1-mft),
a = 0, b = 1)
return(ribdibd)
rnorm_interval(mean = mft, sd = mft * (1-mft),
a = 0, b = 1)
}

# tidy up and out
combinds <- combinds %>%
combinds %>%
dplyr::mutate(gendist = purrr::map_dbl(mft, draw_realized_ibdibd)) %>%
dplyr::select(c("smpl1", "smpl2", "deme1", "deme2", "gendist", "geodist"))
return(combinds)


}

# Deme A and B are close but A is very far from C, while B is closer (eg a right triangle)
set.seed(48)
IBD_simulation_data <- sim_IBDIBD(demesize = c(3,3,4), distmat = matrix(c(0,500,1000,
500,0,750,
100,750,0), nrow = 3),
rate = 1e-3, Ft = 0.3)
500,0,750,
100,750,0), nrow = 3),
rate = 1e-3, Ft = 0.3)

# drop within deme
IBD_simulation_data <- IBD_simulation_data[IBD_simulation_data$geodist > 0, ]
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

4 changes: 2 additions & 2 deletions docs/articles/index.html

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

2 changes: 1 addition & 1 deletion docs/articles/installation.html

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

6 changes: 3 additions & 3 deletions docs/authors.html

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

7 changes: 3 additions & 4 deletions docs/index.html

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

6 changes: 3 additions & 3 deletions docs/news/index.html

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

8 changes: 4 additions & 4 deletions docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pandoc: '2.18'
pkgdown: 2.0.5
pandoc: 2.19.2
pkgdown: 2.0.7
pkgdown_sha: ~
articles:
installation: installation.html
runmod: runmod.html
last_built: 2022-08-10T05:33Z
runvanillamod: runvanillamod.html
last_built: 2024-12-20T01:15Z

30 changes: 25 additions & 5 deletions docs/reference/index.html

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

2 changes: 1 addition & 1 deletion docs/reference/pipe.html

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

27 changes: 27 additions & 0 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,52 @@
<url>
<loc>/articles/runmod.html</loc>
</url>
<url>
<loc>/articles/runvanillamod.html</loc>
</url>
<url>
<loc>/authors.html</loc>
</url>
<url>
<loc>/design_engineering.html</loc>
</url>
<url>
<loc>/index.html</loc>
</url>
<url>
<loc>/news/index.html</loc>
</url>
<url>
<loc>/reference/IBD_simulation_data.html</loc>
</url>
<url>
<loc>/reference/deme_inbreeding_spcoef.html</loc>
</url>
<url>
<loc>/reference/deme_inbreeding_spcoef_vanilla.html</loc>
</url>
<url>
<loc>/reference/discent_sim_dat.html</loc>
</url>
<url>
<loc>/reference/index.html</loc>
</url>
<url>
<loc>/reference/is.vanillaDISCresult.html</loc>
</url>
<url>
<loc>/reference/pipe.html</loc>
</url>
<url>
<loc>/reference/print.vanillaDISCresult.html</loc>
</url>
<url>
<loc>/reference/summary.vanillaDISCresult.html</loc>
</url>
<url>
<loc>/reference/tidyout.html</loc>
</url>
<url>
<loc>/reference/tidyout.vanillaDISCresult.html</loc>
</url>
</urlset>

0 comments on commit a8ebac9

Please sign in to comment.