Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- determineGenderYDom <- function(chromosone1,chromosone2)
- {
- ## Function to determine the gender of a child based on the
- ## child's two chromosones.
- ##
- ## This assumes that Y is dominant with respect to both X and Z
- ## X is dominant with respect to Z
- if((chromosone1=="Y") | (chromosone2=="Y"))
- {
- return("M")
- }
- else if ((chromosone1=="X") | (chromosone2=="X"))
- {
- return("F")
- }
- return("V")
- }
- determineGenderZDom <- function(chromosone1,chromosone2)
- {
- ## Function to determine the gender of a child based on the
- ## child's two chromosones.
- ##
- ## This assumes that Z is dominant with respect to both X and Y
- ## Y is dominant with respect to X
- if((chromosone1=="Z") | (chromosone2=="Z"))
- {
- return("V")
- }
- else if ((chromosone1=="Y") | (chromosone2=="Y"))
- {
- return("M")
- }
- return("F")
- }
- ## Change the right hand of this assignment to change the way the
- ## script calculates dominance. The right hand side should be one of
- ## the functions above.
- determineGender <- determineGenderZDom
- addGenders <- function(leftChromosone1, leftChromosone2, # chromosones of parent 1
- rightChromosone1,rightChromosone2) # chromosones of parent 2
- {
- ## Function to determine the chromosones and genders of all possible
- ## children based on the chromosones of both parents.
- if(determineGender(leftChromosone1,leftChromosone2) !=
- determineGender(rightChromosone1,rightChromosone2))
- {
- ## The parents are of two different genders. Assume that they
- ## can have offspring. Return all possible permutations and
- ## the gender for each permutation.
- return(data.frame(
- chromosone1=c(leftChromosone1,leftChromosone2,leftChromosone1,leftChromosone2),
- chromosone2=c(rightChromosone1,rightChromosone2,rightChromosone2,rightChromosone1),
- gender=c(determineGender(leftChromosone1,rightChromosone1),
- determineGender(leftChromosone2,rightChromosone2),
- determineGender(leftChromosone1,rightChromosone2),
- determineGender(leftChromosone2,rightChromosone1))))
- }
- return(NA)
- }
- ## Define the possible chromosones
- chromosones = c("X","Y","Z")
- ## Define an empty data frame that will contain all the possible children.
- gender = data.frame(chromosone1=character(0),chromosone1=character(0),gender=character(0))
- ## Loop through all possible permutations for parent 1.
- for (leftChromosone1 in chromosones)
- {
- for (leftChromosone2 in chromosones)
- {
- if((leftChromosone1!="Y") || (leftChromosone2!="Y"))
- {
- ## Assume up front that there are no YY males. This
- ## assumes no males give birth.
- ## Now loop through all possible permutations for parent 2.
- for (rightChromosone1 in chromosones)
- {
- for (rightChromosone2 in chromosones)
- {
- if((rightChromosone1!="Y") || (rightChromosone2!="Y"))
- {
- ## Assume up front that there are no YY males. This
- ## assumes no males give birth.
- babies <- addGenders(leftChromosone1, leftChromosone2,
- rightChromosone1,rightChromosone2)
- if(length(babies)>1)
- {
- gender <- rbind(gender,babies)
- }
- }
- }
- }
- }
- }
- }
- ## At this point we have a data frame which has the permutations for
- ## children assuming that males cannot give birth. The data frame also
- ## has the gender of each child, and it assumes that all combinations
- ## are equally likely.
- if (length(gender$gender[(gender$chromosone1 == "Y") & (gender$chromosone2 == "Y")])>0)
- {
- ## uh-oh.... it is possible to get YY males with this
- ## ordering. Need to go back and add those possibilities
- for (rightChromosone1 in chromosones)
- {
- for (rightChromosone2 in chromosones)
- {
- ## Add the possibilities when parent 1 is a YY diploid.
- babies <- addGenders("Y","Y",rightChromosone1,rightChromosone2)
- if(length(babies)>1)
- {
- gender <- rbind(gender,babies)
- }
- if((rightChromosone1!="Y") || (rightChromosone2!="Y"))
- {
- ## If the chromosones are not both Y then gotta add
- ## them when parent 2 is both.
- babies <- addGenders(rightChromosone1,rightChromosone2,"Y","Y")
- if(length(babies)>1)
- {
- gender <- rbind(gender,babies)
- }
- }
- }
- }
- }
- gender$chromosone1 = as.factor(gender$chromosone1) # convert everything to factors
- gender$chromosone2 = as.factor(gender$chromosone2)
- gender$gender = as.factor(gender$gender)
- print(table(gender$gender))
- plot(gender$gender)
- children <- table(gender$chromosone1,gender$chromosone2)
- print(children)
- mosaicplot(children)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement