Attribute VB_Name = "Module1" Option Explicit ' Forces the declaration of all variables. Option Base 1 ' Declares the default lower bound for array subscripts. Public colonyArray() As Variant ' syntax: colonyArray(number). Public lociArray() As Variant ' : lociArray(number). Public queenArray() As Variant ' : queenArray(lociNum,alleleNum). Public fatherArray() As Variant ' : fatherArray(lociNum,alleleNum). Public endColony() As Integer ' : endColony(number). Public numOfOffspringPerFather() As Double ' : numOfOffspringPerFather(number). Public sizeOfAlleleSet As Integer ' Value corresponding to the size of an AlleleSet. Public numOfFathers As Integer ' Number of required for mating of a colony. Public condense As Variant ' Boolean result to user prompt. Public inputRequired As Boolean ' Boolean value based on complete or incomplete state of the data set. Public pivotRange As String ' Defines range for pivot-table. Public sortedArray() As Variant ' Array that stores the sorted father genotypes. ' Subroutine Name: Main() ' Description: Main subroutine. Calls all other subroutines and functions. ' EzyMate executes using the following hierarchy (biggest to smallest respectively): Colony -> Locus -> Allele. Public Sub Main() Attribute Main.VB_Description = "EzyMate - A Microsoft Excel macro to aid in the analysis of polyanrous social insect colonies." Attribute Main.VB_ProcData.VB_Invoke_Func = "E\n14" ' [DECLARE VARIABLES] Dim numberOfLoci As Integer, currentLocusNum As Integer, columnShift As Integer Dim leftColumn As Integer, rightColumn As Integer, row As Integer Dim dimension As Integer, colonyNum As Integer, alleleStartColumn As Integer Dim continue As Boolean ' [INITIALISE VARIABLES] dimension = 2 columnShift = 2 row = 2 inputRequired = True Call Module2.FindColony(row) ' Identifies the name, number and size of colonies in the data set. alleleStartColumn = Module2.FindLoci(Module2.GetStartAllele) If (alleleStartColumn = -1) Then GoTo ProgramQuit ' alleleStartColumn is assigned an integer value, which points to the first column in the ' data set that is to be analysed. continue = Module2.EvenNumOfLoci(alleleStartColumn) If (continue = False) Then GoTo ProgramQuit leftColumn = alleleStartColumn ' leftColumn & rightColumn are the two alleles (ie: current locus) being rightColumn = leftColumn + 1 ' investiaged by EzyMate. numberOfLoci = UBound(lociArray) ' Number of loci in the data set. ReDim queenArray(numberOfLoci, dimension) ' Sets the size of the array which stores the Queen's genotype, now that the number of loci in the data set is known. For colonyNum = 1 To UBound(colonyArray) ' Loops through every colony in the data set, based on the findings from FindColony(). For currentLocusNum = 1 To numberOfLoci ' Loops through each locus. ' Select case < 2, is only executed if the Queen's genotype cannot be directly inferred. Select Case Module3.NumOfHomozygotes(row, leftColumn, rightColumn, currentLocusNum) Case Is < 2: If (Module4.IsHomozygousQueen(row, leftColumn, rightColumn, colonyNum)) Then queenArray(currentLocusNum, 2) = queenArray(currentLocusNum, 1) Else Call Module5.OneOfTwoAlleles(Combinations(AlleleSet(row, leftColumn, rightColumn)), row, leftColumn, rightColumn, colonyNum, currentLocusNum) End If End Select leftColumn = leftColumn + columnShift ' The columnShift variable forces EzyMate to jump to the next locus rightColumn = rightColumn + columnShift ' to be analysed - within the same colony. Next currentLocusNum ' The Queen's genotype (for a single colony) is known at the completion of the currentLocusNum For-Loop. ' [RE-INITIALISE VARIABLES] leftColumn = alleleStartColumn rightColumn = leftColumn + 1 If (colonyNum = 1) Then ' Ie: EzyMate is currently analysing the first colony in the data set. ReDim fatherArray(numberOfLoci, endColony(colonyNum) - 1) Else ReDim fatherArray(numberOfLoci, (endColony(colonyNum) - row + 1)) End If ' The For-Loop functions to determine the father's genotypic contribution to each worker sampled. For currentLocusNum = 1 To numberOfLoci Call Module6.FindFather(row, leftColumn, rightColumn, currentLocusNum) leftColumn = leftColumn + columnShift rightColumn = rightColumn + columnShift Next currentLocusNum ' The subroutines below function to print the results in a new spreadsheet. Call Module7.PrintColumnHeadings(numberOfLoci, colonyNum) Call Module6.PrintQueenGenotype(numberOfLoci) Call Module8.PrintFathers(SortedFatherArray(numberOfLoci), numberOfLoci) Call Module7.PrintTable(numberOfLoci) Call Module8.AlleleFreq(numberOfLoci, colonyNum) Worksheets(colonyNum + 1).Select ' [RE-INITIALISE VARIABLES] leftColumn = alleleStartColumn rightColumn = leftColumn + 1 If (colonyNum <= (UBound(colonyArray) - 1)) Then row = endColony(colonyNum) + 1 Next colonyNum ' Jumps to the next colony in the data set. ProgramQuit: ' Used to check if there is an even number of alleles in the data set. End Sub