//DD_BS_Calc_means_from_trial //RAM, Nov 3, 2015 //Assumes a current trial record - usually apply this method to a selection of trials generated by DD_BS_Distribute? methods // calculates all the values in the population based on the trials Allele positions // record mean value for trial, as well as min and max for error checking C_INTEGER($i;$N) //counter for loops C_REAL($Mean;$SumOfMeans;$Min;$Max) //place to tally values ARRAY REAL($aAlleles;24) //place to hold all the names of the Alleles in the new order C_TEXT($IndivType) //for doing the adults or kids - could record fields for each type C_INTEGER($New1;$New2;$New3;$New4) //assign trial positions to old positions $aAlleles{1}:=[Trials]Old1 $aAlleles{2}:=[Trials]Old2 $aAlleles{3}:=[Trials]Old3 $aAlleles{4}:=[Trials]Old4 $aAlleles{5}:=[Trials]Old5 $aAlleles{6}:=[Trials]Old6 $aAlleles{7}:=[Trials]Old7 $aAlleles{8}:=[Trials]Old8 $aAlleles{9}:=[Trials]Old9 $aAlleles{10}:=[Trials]Old10 $aAlleles{11}:=[Trials]Old11 $aAlleles{12}:=[Trials]Old12 $aAlleles{13}:=[Trials]Old13 $aAlleles{14}:=[Trials]Old14 $aAlleles{15}:=[Trials]Old15 $aAlleles{16}:=[Trials]Old16 $aAlleles{17}:=[Trials]Old17 $aAlleles{18}:=[Trials]Old18 $aAlleles{19}:=[Trials]Old19 $aAlleles{20}:=[Trials]Old20 $aAlleles{21}:=[Trials]Old21 $aAlleles{22}:=[Trials]Old22 $aAlleles{23}:=[Trials]Old23 $aAlleles{24}:=[Trials]Old24 //to find the position of any one allele, you search the $aAlleles array for the name of an allele //the integer value of the result is the postion in the topography //Now, get all the individuals and put into arrays //$IndivType:=Request("Individual type?";"Big_A or Big K") $IndivType:="Big_A"+"@" QUERY([Individuals];[Individuals]Phase=$IndivType) //put into selection SELECTION TO ARRAY([Individuals]ID;aIndID;[Individuals]L1A1;aL1a1;[Individuals]L1A2;aL1a2;[Individuals]L2A1;aL2a1;[Individuals]L2A2;aL2a2;[Individuals]Mean;aIndMean) $N:=Size of array(aIndID) //initialize to zero $SumOfMeans:=0 $Min:=20 //reporter data $Max:=0 //reporter data //now, step through each individual in focal population and calculate its mean MHC distance For ($i;1;$N) //first, find the new position for all 4 alleles $New1:=Find in array($aAlleles;aL1a1{$i}) $New2:=Find in array($aAlleles;aL1a2{$i}) $New3:=Find in array($aAlleles;aL2a1{$i}) $New4:=Find in array($aAlleles;aL2a2{$i}) aIndMean{$i}:=DD_Rtn_Mean_Dist ($New1;$New2;$New3;$New4) $SumOfMeans:=$SumOfMeans+aIndMean{$i} If (aIndMean{$i}>$Max) $Max:=aIndMean{$i} End if If (aIndMean{$i}<$Min) $Min:=aIndMean{$i} End if End for //calc mean of mean MHC from all means in population $Mean:=$SumOfMeans/$N //return this to calling method $Min:=$Min $Max:=$Max //assign to proper fields [Trials]Dist_Mean:=Round($Mean;3) //this is what we want [Trials]Dist_Min:=Round($Min;3) //this is for error checking [Trials]Dist_Max:=Round($Max;3) //this is for error checking // SAVE this Trial Record by the call to Apply to Selection of Trials