#!/usr/bin/perl #####going from diploid individuals to half-sib families##### #######returns hash containing individuals sub Mate(){ ##### each individual needs to be mated with x other individuals # loop as many times as pollen parents needed per mother plant %eachPPUnique = (); %gen2 = (); @halfSibId = (); foreach $id (keys %population){ print "id: $id\n"; # to hold hash of array of individuals %halfSibFamily = (); # count how many times loop is gone through $countNoPP = 0; #starting at 1 means counts always 1 more than expected # start a hash to make sure each pollen donor drawn is not self, and has not already pollinated this mother plant %eachPPUnique = (); # put the id of the mother plant in hash # hash {$key} = [value]; $eachPPUnique{$id}=1; while($countNoPP < $noCrosses){ # Grab random $value = $genOne{idGI} $rangePP = $noIndividuals; $randomNoPP = int(rand($rangePP)); ### check if already in %eachPollenUnique # if (exists($hash{$key})) if (exists ($eachPPUnique{$randomNoPP})) { } ### if new else { # keep track of how many pollen parents (PP) for this mother plant (MP) $countNoPP++; # keep track of how many new individuals are made of from this mating # re-initialize because new mating pair $countNoCrossesPerPP = 0; while ($countNoCrossesPerPP < $noIndividualsPerCross){ # empty arrays for creation of new individual @gameteReturned = (); @gameteMP = (); @gametePP = (); @individualGen2 = (); # add to hash (add $randomNoPP to %eachPPUnique) $eachPPUnique{$randomNoPP} = 1; # send mother plant (MP) to be crossed over, and gamete selected $MP = $id; #mother plant require "./switchgrass CrossOverMP.pl"; CrossOverMP (\%population); @gameteMP = @gameteReturned; # call up pollen parent (PP) $PP = $randomNoPP; #pollen parent # send PP to be crossed require "./switchgrass CrossOverPP.pl"; CrossOverPP (\%population); # return array holding gamete from mother plant @gametePP = @gameteReturned; # create new individual from 2 gametes foreach $locusGameteMP (@gameteMP){ $locusGametePP = shift(@gametePP); $locusGen2 = $locusGameteMP._.$locusGametePP; push(@individualGen2, $locusGen2); } # note that have done another instance of this mating $countNoCrossesPerPP++; ### add arrays (individuals)to hash (families) # hash key is MP id concatenated to PP id $indId = MP.$MP._.PP.$PP._.$countNoCrossesPerPP; # create hash of arrays to give individuals ids (keys in hash) # hash {$key} = [value]; $halfSibFamily{$indId}=[@individualGen2]; }#while }#else }#while $gen2{$MP} = \%halfSibFamily; } # sub end } 1;