This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Given a parent individual, get one of their Alleles in the gamete | |
getGamete <- function(indiv) { | |
if (indiv == 1) return(1) #AA | |
if (indiv == 3) return(0) #aa | |
#if Parent is Aa, the gamete is one binomial trial with prob.big.A | |
if (indiv == 2) return(rbinom(1, size=1, prob.big.A)) #Aa | |
} | |
#Two parental Gametes combine to form a zygote | |
combineGametes <- function(mg,dg) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getNextGen <- function(x) { | |
nextgen <- list() | |
for(i in seq(1, kStartPop, by=2)) { | |
firstborn <- getOffspring(x[i], x[i+1]) | |
secondborn <- getOffspring(x[i], x[i+1]) | |
nextgen[i] <- firstborn | |
nextgen[i+1] <- secondborn | |
} | |
return(unlist(nextgen)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simulationOneTrial <- function(start.pop, knumGenerations, trial.index) { | |
df.allele <- NULL | |
df.gen <- NULL | |
#Keep track of the individuals in each generation | |
df.gen <- rbind(df.gen, start.pop) | |
x <- start.pop | |
for ( gen in 1:knumGenerations) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Bookkeeping | |
calcAllelesInGeneration <- function(x) { | |
AA = sum(x==1) | |
AB = sum(x==2) | |
BB = sum(x==3) | |
#print(unlist(x)) | |
#print(c(AA, AB, BB)) | |
num.A <- (2 * AA) + AB | |
num.B <- (2 * BB) + AB | |
return(c(num.A, num.B)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list=ls()) | |
library(ggplot2) | |
library(reshape2) | |
#Function Definition | |
#Bookkeeping | |
calcAllelesInGeneration <- function(x) { | |
AA = sum(x==1) | |
AB = sum(x==2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<catalog> | |
<book id="bk101"> | |
<author>Gambardella, Matthew</author> | |
<title>XML Developer's Guide</title> | |
<genre>Computer</genre> | |
<price>44.95</price> | |
<publish_date>2000-10-01</publish_date> | |
<description>An in-depth look at creating applications | |
with XML.</description> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(XML) | |
#Recursive Function to visit the XML tree (depth first) | |
visitNode <- function(node) { | |
if (is.null(node)) { | |
#leaf node reached. Turn back | |
return() | |
} | |
print(paste("Node: ", xmlName(node))) | |
num.children = xmlSize(node) | |
if(num.children == 0 ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set up a coloring scheme using colorRampPalette | |
red=rgb(1,0,0); green=rgb(0,1,0); blue=rgb(0,0,1); white=rgb(1,1,1) | |
RtoWrange<-colorRampPalette(c(red, white ) ) | |
WtoGrange<-colorRampPalette(c(white, green) ) | |
p <- p + scale_fill_gradient2(low=RtoWrange(100), mid=WtoGrange(100), high="gray") | |
p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set up a coloring scheme using colorRampPalette | |
red=rgb(1,0,0); green=rgb(0,1,0); blue=rgb(0,0,1); white=rgb(1,1,1) | |
RtoWrange<-colorRampPalette(c(red, white ) ) | |
WtoGrange<-colorRampPalette(c(white, green) ) | |
p <- p + scale_fill_gradient2(low=RtoWrange(100), mid=WtoGrange(100), high="gray") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(reshape2) | |
data(movies) | |
movieGenres <- movies[c(18:23)] #subset to 6 genres | |
cor(movieGenres) # 6x6 cor matrix | |
#ggplot likes the data 'melted' one value per row | |
m <-melt(cor(movieGenres)) | |
p <- ggplot(data=m, aes(x=Var1, y=Var2, fill=value)) + geom_tile() |