ylab = 'Individuals')
foo <- 1
while(foo < (counter)){
for(i in 1:census){
lines(c(foo,(foo+1)), history[i,foo:(foo+1)])
foo <- foo + 2
}
}
plot(0, 0, col = 'white', ylim = c(1,census),
xlim = c(1, counter),
main='Coalesence Simulation',
xlab = 'Generation',
ylab = 'Individuals')
foo <- 1
i<-1
foo <- 1
while(foo < (counter)){
for(i in 1:census){
lines(c(foo,(foo+1)), history[i,foo:(foo+1)])
}
foo <- foo + 2
}
census <- 10
history <- as.data.frame(1:census)
lineages <- census
counter <- 1
counter <- counter + 1
history[1:census, counter] <- sample(1:census, length(unique(history[, (counter - 1)])), replace = T)
while(lineages > 1){
lineages <- sum(!is.na(unique(history[1:10, counter])))
history[1:lineages, (counter + 1)] <- sort(unique(history[1:10, counter]))
counter <- counter + 1
history[1:lineages, (counter + 1)] <- sort(sample(1:census, length(unique(history[, (counter)])) - 1, replace = T))
counter <- counter + 1
}
## now plot it
plot(0, 0, col = 'white', ylim = c(1,census),
xlim = c(1, counter),
main='Coalesence Simulation',
xlab = 'Generation',
ylab = 'Individuals')
foo <- 1
foox <- 1
while(foo < (counter)){
for(i in 1:census){
lines(c(foox,(foox + 1)), history[i,foo:(foo + 1)])
}
foo <- foo + 2
foox <- foox + 1
}
plot(0, 0, col = 'white', ylim = c(1,census),
xlim = c(1, counter/2 + 1),
main='Coalesence Simulation',
xlab = 'Generation',
ylab = 'Individuals')
foo <- 1
foox <- 1
while(foo < (counter)){
for(i in 1:census){
lines(c(foox,(foox + 1)), history[i,foo:(foo + 1)])
}
foo <- foo + 2
foox <- foox + 1
}
census <- 50
history <- as.data.frame(1:census)
lineages <- census
counter <- 1
counter <- counter + 1
history[1:census, counter] <- sample(1:census, length(unique(history[, (counter - 1)])), replace = T)
while(lineages > 1){
lineages <- sum(!is.na(unique(history[1:10, counter])))
history[1:lineages, (counter + 1)] <- sort(unique(history[1:10, counter]))
counter <- counter + 1
history[1:lineages, (counter + 1)] <- sort(sample(1:census, length(unique(history[, (counter)])) - 1, replace = T))
counter <- counter + 1
}
## now plot it
plot(0, 0, col = 'white', ylim = c(1,census),
xlim = c(1, counter/2 + 1),
main='Coalesence Simulation',
xlab = 'Generation',
ylab = 'Individuals')
foo <- 1
foox <- 1
while(foo < (counter)){
for(i in 1:census){
lines(c(foox,(foox + 1)), history[i,foo:(foo + 1)])
}
foo <- foo + 2
foox <- foox + 1
}
census <- 40
history <- as.data.frame(1:census)
lineages <- census
counter <- 1
counter <- counter + 1
history[1:census, counter] <- sample(1:census, length(unique(history[, (counter - 1)])), replace = T)
while(lineages > 1){
lineages <- sum(!is.na(unique(history[1:10, counter])))
history[1:lineages, (counter + 1)] <- sort(unique(history[1:10, counter]))
counter <- counter + 1
history[1:lineages, (counter + 1)] <- sort(sample(1:census, length(unique(history[, (counter)])) - 1, replace = T))
counter <- counter + 1
}
## now plot it
plot(0, 0, col = 'white', ylim = c(1,census),
xlim = c(1, counter/2 + 1),
main='Coalesence Simulation',
xlab = 'Generation',
ylab = 'Individuals')
foo <- 1
foox <- 1
while(foo < (counter)){
for(i in 1:census){
lines(c(foox,(foox + 1)), history[i,foo:(foo + 1)])
}
foo <- foo + 2
foox <- foox + 1
}
census <- 20
history <- as.data.frame(1:census)
lineages <- census
counter <- 1
counter <- counter + 1
history[1:census, counter] <- sample(1:census, length(unique(history[, (counter - 1)])), replace = T)
while(lineages > 1){
lineages <- sum(!is.na(unique(history[1:10, counter])))
history[1:lineages, (counter + 1)] <- sort(unique(history[1:10, counter]))
counter <- counter + 1
history[1:lineages, (counter + 1)] <- sort(sample(1:census, length(unique(history[, (counter)])) - 1, replace = T))
counter <- counter + 1
}
## now plot it
plot(0, 0, col = 'white', ylim = c(1,census),
xlim = c(1, counter/2 + 1),
main='Coalesence Simulation',
xlab = 'Generation',
ylab = 'Individuals')
foo <- 1
foox <- 1
while(foo < (counter)){
for(i in 1:census){
lines(c(foox,(foox + 1)), history[i,foo:(foo + 1)])
}
foo <- foo + 2
foox <- foox + 1
}
library(devtools)
install.packages("devtools")
library(devtools)
install_github("evobiR")
help(install_github)
install_github("evobiR", username='coleoguy')
install_git("evobiR", username='coleoguy')
install.packages('evobiR_1.0.tgz', repo='https://github.com/coleoguy/evobir/blob/master/', type='source')
help(install.packages)
install.packages('evobiR_1.0.tgz', repo='https://github.com/coleoguy/evobir/blob/master/', type='mac.binary')
help(install_github)
library(devtools)
install_github("evobir", username='coleoguy')
install_github("evobir", username='coleoguy')
setwd("~/Desktop/mypack/GIT/evobir/R")
generations <- 100
census <- 10
reporting <- 'xy'
source('functions.R')
source('GenomeSym.R')
setwd("~/Desktop/mypack/evobir/R")
source('GenomeSym.R')
generations <- 100
census <- 10
reporting <- 'xy'
genome <- DesignLife(loci.a)            # This creates the matrix for an individual genome
population <- Populate(census)          # This creates a population 1:1 sex ration of size=census
if(reporting != "None") {               # activate any in simulation visualization
if(reporting == 'all.loci'){
y.chrom <- matrix(, loci.s, generations)
layout(matrix(c(1,2),2,1))
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Locus Mean Fitness', xlab = 'Gen.', ylab = 'Abs. Fitness')
p1 <- par(no.readonly=T)
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Locus Mean Fitness', xlab = 'Gen.', ylab = 'Abs. Fitness')
p2 <- par(no.readonly=T)
loci.col <- rainbow(100)
}
if(reporting == 'xy'){
y.chrom <- matrix(, loci.s, generations)
layout(matrix(c(1,2),1,2))
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'X Chromosome', xlab = 'Gen.', ylab = 'Abs. Fitness')
text(0, .61, 'FEMALE', col='red', pos=4, font=2)
text(0, .50, 'MALE', col='blue', pos=4, font=2)
p1 <- par(no.readonly=T)
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Y Chromosome', xlab = 'Gen.', ylab = 'Abs. Fitness')
p2 <- par(no.readonly=T)
Sys.sleep(.1)
}
if(reporting == "PAR")
plot(0,0,ylim=c(0,50),xlim=c(0,generations),col="white",pch=19,main="XY Recombination", ylab="Number of Loci Isolated", xlab="Generations")
if(reporting == "XY.fitness")
plot(0,0,ylim=c(0,50),xlim=c(0,generations),col="green",pch=19,main="XY Recombination", ylab="Number of Loci Isolated", xlab="Generations")
}
for(k in 1:generations){                ## THIS BEGINS THE GENERATION SIMULATION PROCESS
cat("Generation: ",k," has been born.\n",sep="")
evaluation <- Ranking(population)       #This sexes and evaluates the fitness of all individuals
if(reporting != "None") {        # update any in simulation visualization
if(reporting == "PAR") {
foo <- vector()
for(j in 1:census){
foo[j] <- which.min(population[[j]][11,] == 0) - 1
}
points(k,mean(foo),col="darkgreen",pch=19,cex=.5)
Sys.sleep(.1)
}
if(reporting == 'all.loci'){
par(p1)
par(mfg=c(1,1))
foo <- matrix(,length(population),loci.a)
for(i in 1:length(population)){
foo[i,] <- population[[i]][1,]
}
points(rep(k,loci.a),colMeans(foo), cex = .2, col = loci.col)
par(p2)
par(mfg=c(2,1))
points(rep(k,loci.a),colMeans(foo), cex = .2, col = loci.col)
Sys.sleep(.25)
}
if(reporting == 'xy'){
sires <- which(evaluation[,1] == 'Male')
dams <- which(evaluation[,1] == 'Female')
par(p1)
par(mfg=c(1,1))
# lets do average X in a female first
fooxd <- fooxs <- vector()
for(i in 1:length(dams)){
fooxs[i] <- mean(population[[dams[i]]][5, 1:loci.s])
fooxd[i] <- mean(population[[dams[i]]][6, 1:loci.s])
}
points(rep(k, length(fooxd)), fooxd, cex = .2, col = 'red')
points(rep(k, length(fooxs)), fooxs, cex = .2, col = 'blue')
fooy <- vector()
for(i in 1:length(sires)){
fooy[i] <- mean(population[[sires[i]]][9, 1:loci.s])
}
par(p2)
par(mfg=c(1,2))
points(rep(k, length(fooy)), fooy, cex = .2, col = 'blue')
}
#Sys.sleep(.3)
}
# Premiotic Mutations -----
#if(sample(1:100,1) > 1) {
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
#}
if(sample(1:100,1) > 50) {
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- CeaseRecomb(population, sport)       # Mutations that extend the SLR(sex limited region)
}
#if(sample(1:100,1) > 95) {
#  sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
#  population <- ChangeHaploSuff(population, sport)   # Mutations that change halposufficiency
#}
# Meiosis and Fertilization -----
gamete.pool <- GametoGenesis(population)           # This creates the number of gametes specified
population <- NextGen(gamete.pool, evaluation)     # This creates the population for generation i+1
}
generations <- 100
census <- 100
reporting <- 'xy'
genome <- DesignLife(loci.a)            # This creates the matrix for an individual genome
population <- Populate(census)          # This creates a population 1:1 sex ration of size=census
if(reporting != "None") {               # activate any in simulation visualization
if(reporting == 'all.loci'){
y.chrom <- matrix(, loci.s, generations)
layout(matrix(c(1,2),2,1))
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Locus Mean Fitness', xlab = 'Gen.', ylab = 'Abs. Fitness')
p1 <- par(no.readonly=T)
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Locus Mean Fitness', xlab = 'Gen.', ylab = 'Abs. Fitness')
p2 <- par(no.readonly=T)
loci.col <- rainbow(100)
}
if(reporting == 'xy'){
y.chrom <- matrix(, loci.s, generations)
layout(matrix(c(1,2),1,2))
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'X Chromosome', xlab = 'Gen.', ylab = 'Abs. Fitness')
text(0, .61, 'FEMALE', col='red', pos=4, font=2)
text(0, .50, 'MALE', col='blue', pos=4, font=2)
p1 <- par(no.readonly=T)
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Y Chromosome', xlab = 'Gen.', ylab = 'Abs. Fitness')
p2 <- par(no.readonly=T)
Sys.sleep(.1)
}
if(reporting == "PAR")
plot(0,0,ylim=c(0,50),xlim=c(0,generations),col="white",pch=19,main="XY Recombination", ylab="Number of Loci Isolated", xlab="Generations")
if(reporting == "XY.fitness")
plot(0,0,ylim=c(0,50),xlim=c(0,generations),col="green",pch=19,main="XY Recombination", ylab="Number of Loci Isolated", xlab="Generations")
}
for(k in 1:generations){                ## THIS BEGINS THE GENERATION SIMULATION PROCESS
cat("Generation: ",k," has been born.\n",sep="")
evaluation <- Ranking(population)       #This sexes and evaluates the fitness of all individuals
if(reporting != "None") {        # update any in simulation visualization
if(reporting == "PAR") {
foo <- vector()
for(j in 1:census){
foo[j] <- which.min(population[[j]][11,] == 0) - 1
}
points(k,mean(foo),col="darkgreen",pch=19,cex=.5)
Sys.sleep(.1)
}
if(reporting == 'all.loci'){
par(p1)
par(mfg=c(1,1))
foo <- matrix(,length(population),loci.a)
for(i in 1:length(population)){
foo[i,] <- population[[i]][1,]
}
points(rep(k,loci.a),colMeans(foo), cex = .2, col = loci.col)
par(p2)
par(mfg=c(2,1))
points(rep(k,loci.a),colMeans(foo), cex = .2, col = loci.col)
Sys.sleep(.25)
}
if(reporting == 'xy'){
sires <- which(evaluation[,1] == 'Male')
dams <- which(evaluation[,1] == 'Female')
par(p1)
par(mfg=c(1,1))
# lets do average X in a female first
fooxd <- fooxs <- vector()
for(i in 1:length(dams)){
fooxs[i] <- mean(population[[dams[i]]][5, 1:loci.s])
fooxd[i] <- mean(population[[dams[i]]][6, 1:loci.s])
}
points(rep(k, length(fooxd)), fooxd, cex = .2, col = 'red')
points(rep(k, length(fooxs)), fooxs, cex = .2, col = 'blue')
fooy <- vector()
for(i in 1:length(sires)){
fooy[i] <- mean(population[[sires[i]]][9, 1:loci.s])
}
par(p2)
par(mfg=c(1,2))
points(rep(k, length(fooy)), fooy, cex = .2, col = 'blue')
}
#Sys.sleep(.3)
}
# Premiotic Mutations -----
#if(sample(1:100,1) > 1) {
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
#}
if(sample(1:100,1) > 50) {
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- CeaseRecomb(population, sport)       # Mutations that extend the SLR(sex limited region)
}
#if(sample(1:100,1) > 95) {
#  sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
#  population <- ChangeHaploSuff(population, sport)   # Mutations that change halposufficiency
#}
# Meiosis and Fertilization -----
gamete.pool <- GametoGenesis(population)           # This creates the number of gametes specified
population <- NextGen(gamete.pool, evaluation)     # This creates the population for generation i+1
}
generations <- 100
census <- 20
reporting <- 'xy'
genome <- DesignLife(loci.a)            # This creates the matrix for an individual genome
population <- Populate(census)          # This creates a population 1:1 sex ration of size=census
if(reporting != "None") {               # activate any in simulation visualization
if(reporting == 'all.loci'){
y.chrom <- matrix(, loci.s, generations)
layout(matrix(c(1,2),2,1))
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Locus Mean Fitness', xlab = 'Gen.', ylab = 'Abs. Fitness')
p1 <- par(no.readonly=T)
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Locus Mean Fitness', xlab = 'Gen.', ylab = 'Abs. Fitness')
p2 <- par(no.readonly=T)
loci.col <- rainbow(100)
}
if(reporting == 'xy'){
y.chrom <- matrix(, loci.s, generations)
layout(matrix(c(1,2),1,2))
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'X Chromosome', xlab = 'Gen.', ylab = 'Abs. Fitness')
text(0, .61, 'FEMALE', col='red', pos=4, font=2)
text(0, .50, 'MALE', col='blue', pos=4, font=2)
p1 <- par(no.readonly=T)
plot(0.1,0.1, xlim = c(0,generations), ylim = c(.5,2), cex = .05, main = 'Y Chromosome', xlab = 'Gen.', ylab = 'Abs. Fitness')
p2 <- par(no.readonly=T)
Sys.sleep(.1)
}
if(reporting == "PAR")
plot(0,0,ylim=c(0,50),xlim=c(0,generations),col="white",pch=19,main="XY Recombination", ylab="Number of Loci Isolated", xlab="Generations")
if(reporting == "XY.fitness")
plot(0,0,ylim=c(0,50),xlim=c(0,generations),col="green",pch=19,main="XY Recombination", ylab="Number of Loci Isolated", xlab="Generations")
}
for(k in 1:generations){                ## THIS BEGINS THE GENERATION SIMULATION PROCESS
cat("Generation: ",k," has been born.\n",sep="")
evaluation <- Ranking(population)       #This sexes and evaluates the fitness of all individuals
if(reporting != "None") {        # update any in simulation visualization
if(reporting == "PAR") {
foo <- vector()
for(j in 1:census){
foo[j] <- which.min(population[[j]][11,] == 0) - 1
}
points(k,mean(foo),col="darkgreen",pch=19,cex=.5)
Sys.sleep(.1)
}
if(reporting == 'all.loci'){
par(p1)
par(mfg=c(1,1))
foo <- matrix(,length(population),loci.a)
for(i in 1:length(population)){
foo[i,] <- population[[i]][1,]
}
points(rep(k,loci.a),colMeans(foo), cex = .2, col = loci.col)
par(p2)
par(mfg=c(2,1))
points(rep(k,loci.a),colMeans(foo), cex = .2, col = loci.col)
Sys.sleep(.25)
}
if(reporting == 'xy'){
sires <- which(evaluation[,1] == 'Male')
dams <- which(evaluation[,1] == 'Female')
par(p1)
par(mfg=c(1,1))
# lets do average X in a female first
fooxd <- fooxs <- vector()
for(i in 1:length(dams)){
fooxs[i] <- mean(population[[dams[i]]][5, 1:loci.s])
fooxd[i] <- mean(population[[dams[i]]][6, 1:loci.s])
}
points(rep(k, length(fooxd)), fooxd, cex = .2, col = 'red')
points(rep(k, length(fooxs)), fooxs, cex = .2, col = 'blue')
fooy <- vector()
for(i in 1:length(sires)){
fooy[i] <- mean(population[[sires[i]]][9, 1:loci.s])
}
par(p2)
par(mfg=c(1,2))
points(rep(k, length(fooy)), fooy, cex = .2, col = 'blue')
}
#Sys.sleep(.3)
}
# Premiotic Mutations -----
#if(sample(1:100,1) > 1) {
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- AlleleMutate(population, sport)      # This performs a mutation ceating a new allele
#}
if(sample(1:100,1) > 50) {
sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
population <- CeaseRecomb(population, sport)       # Mutations that extend the SLR(sex limited region)
}
#if(sample(1:100,1) > 95) {
#  sport <- RadDose(evaluation)                       # This picks an individual from the population to be mutated
#  population <- ChangeHaploSuff(population, sport)   # Mutations that change halposufficiency
#}
# Meiosis and Fertilization -----
gamete.pool <- GametoGenesis(population)           # This creates the number of gametes specified
population <- NextGen(gamete.pool, evaluation)     # This creates the population for generation i+1
}
getwd()
source('GenomeSym.R')
source('GenomeSym.R')
source('GenomeSym.R')
GenomeSym(census = 20)
foo <- GenomeSym(census = 20)
foo <- GenomeSym(census = 20, reporting = 'A.fitness')
foo <- GenomeSym(census = 20, reporting = 'all.loci')
fix(foo)
source('GenomeSym.R')
foo <- GenomeSym(census = 20, generations = 20, reporting = 'all.loci')
fix(foo)
