Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions R/evolution.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ plot.coalescent.plot<-function(x,...){
drift.selection<-function(p0=0.5,Ne=100,w=c(1,1,1),ngen=400,nrep=10,
colors=NULL,...){
if(is.null(colors)) colors<-rainbow(nrep)
if(hasArg(xlabel)) xlabel=list(...)$xlabel
else xlabel<-"Time (generations)"
if(hasArg(ylabel)) ylabel=list(...)$ylabel
else ylabel<-"f(A)"
w<-(w/max(w))[3:1]
gametes<-rep(0,2*Ne)
if(p0>0) gametes[1:round(p0*2*Ne)]<-1
Expand All @@ -324,7 +328,7 @@ drift.selection<-function(p0=0.5,Ne=100,w=c(1,1,1),ngen=400,nrep=10,
for(j in 1:nrep) p[[j]][i+1]<-mean(gametes[[j]])
}
plot(0:ngen,p[[1]],type="l",col=colors[1],lwd=2,ylim=c(0,1),
xlab="time (generations)",ylab="f(A)")
xlab=xlabel,ylab=ylabel)
if(nrep>1)
nulo<-mapply(lines,x=replicate(nrep-1,0:ngen,simplify=FALSE),
y=p[2:nrep],col=colors[2:nrep],lwd=2)
Expand Down Expand Up @@ -356,8 +360,12 @@ plot.drift.selection<-function(x,...){
else type<-"l"
if(hasArg(lwd)) lwd<-list(...)$lwd
else lwd<-2
if(hasArg(xlabel)) xlabel=list(...)$xlabel
else xlabel<-"Time (generations)"
if(hasArg(ylabel)) ylabel=list(...)$ylabel
else ylabel<-"f(A)"
plot(0:ngen,x[[1]],type=type,col=colors[1],lwd=lwd,ylim=c(0,1),
xlab="time (generations)",ylab="f(A)")
xlab=xlabel,ylab=ylabel)
if(nrep>1)
nulo<-mapply(lines,x=replicate(nrep-1,0:ngen,simplify=FALSE),
y=x[2:nrep],col=colors[2:nrep],type=type,lwd=lwd)
Expand All @@ -370,6 +378,10 @@ msd<-function(p0=c(0.5,0.5),Ne=c(100,100),
colors=c("red","blue"),...){
if(hasArg(show.legend)) show.legend=list(...)$show.legend
else show.legend<-TRUE
if(hasArg(xlabel)) xlabel=list(...)$xlabel
else xlabel<-"Time (generations)"
if(hasArg(ylabel)) ylabel=list(...)$ylabel
else ylabel<-"f(A)"
w<-lapply(w,function(w) (w/max(w))[3:1])
gametes<-lapply(Ne,function(Ne) rep(0,2*Ne))
gametes<-mapply(function(p0,g,N){
Expand Down Expand Up @@ -404,7 +416,7 @@ msd<-function(p0=c(0.5,0.5),Ne=c(100,100),
for(j in 1:2) p[[j]][i+1]<-mean(gametes[[j]])
}
plot(0:ngen,p[[1]],type="l",col=colors[1],lwd=2,ylim=c(0,1),
xlab="time (generations)",ylab="f(A)")
xlab=xlabel,ylab=ylabel)
lines(x=0:ngen,y=p[[2]],col=colors[2],lwd=2)
if(show.legend) legend(x="topright",legend=1:2,lty=1,col=colors,
lwd=2,bg=make.transparent("white",0.8))
Expand Down
2 changes: 1 addition & 1 deletion man/drift.selection.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
\item{nrep}{number of replicate simulations.}
\item{ngen}{total time, in number of generations, for the simulation.}
\item{colors}{colors to use for plotting.}
\item{...}{optional arguments. Presently the only arguments are \code{type} (e.g., \code{"l"}, \code{"s"}) and \code{lwd} in the \code{plot} method.}
\item{...}{optional arguments. Presently the only arguments are \code{type} (e.g., \code{"l"}, \code{"s"}) and \code{lwd} in the \code{plot} method. \code{xlabel} and \code{ylabel} sets the labels for the x and y axes, respectively.)}
}
\description{
Simulates drift and natural selection at a single biallelic locus within one or various populations.
Expand Down
2 changes: 1 addition & 1 deletion man/genetic.drift.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
\item{time}{Total time, in number of generations, for the simulation.}
\item{show}{Various options for plotting. \code{"p"} shows the frequency of the A allele through time; \code{"genotypes"} creates an animated histogram with the frequencies of each of the three genotypes through time; \code{"fixed"} shows the fraction of populations that have fixed for each allele, a or A; \code{"heterozygosity"} plots the mean heterozygosity and the expected heterozygosity through time. The default is \code{show="p"}.}
\item{pause}{Pause between generations. \code{pause=0.01} (for instance) might smooth animation.}
\item{...}{optional arguments. In \code{genetic.drift} the optional arguments are presently: \code{colors} (a vector giving the colors to be used to graph the various simulations); and \code{lwd}. The \code{plot} method of the object class adds the optional argument \code{type} (e.g., \code{"l"} or \code{"s"}.)}
\item{...}{optional arguments. In \code{genetic.drift} the optional arguments are presently: \code{colors} (a vector giving the colors to be used to graph the various simulations); and \code{lwd}. The \code{plot} method of the object class adds the optional argument \code{type} (e.g., \code{"l"} or \code{"s"}. \code{xlabel} and \code{ylabel} sets the labels for the x and y axes, respectively.)}
}
\description{
This function simulates genetic drift at a biallelic genetic locus with no selection and no mutation in a sexually reproducing diploid population or set of populations. It is essentially redundant with \code{\link{drift.selection}}, but in which there is no difference in relative fitness among genotypes; however, it also allows the user to visualize heterozygosity or genetic variation through time - options that are not yet implemented in \code{\link{drift.selection}}.
Expand Down