From 1ac54301a60d71a7fa52bdfe265f0811a2f3bc58 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Thu, 30 Jan 2020 17:19:10 +0100 Subject: [PATCH] Adde basic elements of simulateAllFreqs --- NAMESPACE | 1 + R/admix1.R | 29 +---------------------------- R/simulateAllFreqs.R | 28 ++++++++++++++++++++++++++++ man/simulateAllFreqs.Rd | 17 +++++++++++++++++ 4 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 R/simulateAllFreqs.R create mode 100644 man/simulateAllFreqs.Rd diff --git a/NAMESPACE b/NAMESPACE index f49f1d9..673ff82 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,7 @@ export(proportion2str) export(rand) export(randdir) export(repmat) +export(simulateAllFreqs) export(simulateIndividuals) export(simuloiAlleeli) export(suoritaMuutos) diff --git a/R/admix1.R b/R/admix1.R index 8251e22..28ce731 100644 --- a/R/admix1.R +++ b/R/admix1.R @@ -426,31 +426,4 @@ admix1 <- function(tietue) { # end # prioriAlleelit = repmat(prioriAlleelit, [1,1,npops]); # counts = COUNTS + prioriAlleelit; -# allFreqs = counts./sumCounts; - - -# function allfreqs = simulateAllFreqs(noalle) -# % Lisää jokaista alleelia joka populaation joka lokukseen j 1/noalle(j) -# % verran. Näin saatuja counts:eja vastaavista Dirichlet-jakaumista -# % simuloidaan arvot populaatioiden alleelifrekvensseille. - -# global COUNTS; - -# max_noalle = size(COUNTS,1); -# nloci = size(COUNTS,2); -# npops = size(COUNTS,3); - -# prioriAlleelit = zeros(max_noalle,nloci); -# for j=1:nloci -# prioriAlleelit(1:noalle(j),j) = 1/noalle(j); -# end -# prioriAlleelit = repmat(prioriAlleelit, [1,1,npops]); -# counts = COUNTS + prioriAlleelit; -# allfreqs = zeros(size(counts)); - -# for i=1:npops -# for j=1:nloci -# simuloidut = randdir(counts(1:noalle(j),j,i) , noalle(j)); -# allfreqs(1:noalle(j),j,i) = simuloidut; -# end -# end \ No newline at end of file +# allFreqs = counts./sumCounts; \ No newline at end of file diff --git a/R/simulateAllFreqs.R b/R/simulateAllFreqs.R new file mode 100644 index 0000000..3a747e5 --- /dev/null +++ b/R/simulateAllFreqs.R @@ -0,0 +1,28 @@ +#' @title Simulate All Frequencies +#' @description Lisää jokaista alleelia joka populaation joka lokukseen j1/noalle(j) verran. Näin saatuja counts:eja vastaavista Dirichlet-jakaumista simuloidaan arvot populaatioiden alleelifrekvensseille. +#' Add each allele to each locus in each population by j 1 / noalle(j). The Dirichlet distributions corresponding to the counts thus obtained simulate values for the allele frequencies of the populations. +#' @param noalle noalle +#' @param COUNTS COUNTS +#' @export + +simulateAllFreqs <- function(noalle, COUNTS = matrix(0)) { + max_noalle <- size(COUNTS, 1) + nloci <- size(COUNTS, 2) + npops <- size(COUNTS, 3) + + prioriAlleelit <- zeros(max_noalle, nloci) + for (j in 1:nloci) { + prioriAlleelit[1:noalle[j], j] <- 1 / noalle[j] + } + prioriAlleelit <- repmat(prioriAlleelit, matrix(c(1, 1, npops), ncol = 1)) + counts <- COUNTS + prioriAlleelit + allfreqs <- zeros(size(counts)) + + for (i in 1:npops) { + for (j in 1:nloci) { + simuloidut <- randdir(counts[1:noalle[j], j, i] , noalle[j]) + allfreqs[1:noalle[j], j, i] <- simuloidut + } + } + return(allfreqs) +} \ No newline at end of file diff --git a/man/simulateAllFreqs.Rd b/man/simulateAllFreqs.Rd new file mode 100644 index 0000000..463ef80 --- /dev/null +++ b/man/simulateAllFreqs.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/simulateAllFreqs.R +\name{simulateAllFreqs} +\alias{simulateAllFreqs} +\title{Simulate All Frequencies} +\usage{ +simulateAllFreqs(noalle, COUNTS = matrix(0)) +} +\arguments{ +\item{noalle}{noalle} + +\item{COUNTS}{COUNTS} +} +\description{ +Lisää jokaista alleelia joka populaation joka lokukseen j1/noalle(j) verran. Näin saatuja counts:eja vastaavista Dirichlet-jakaumista simuloidaan arvot populaatioiden alleelifrekvensseille. +Add each allele to each locus in each population by j 1 / noalle(j). The Dirichlet distributions corresponding to the counts thus obtained simulate values for the allele frequencies of the populations. +}