Turorial for SegAnalysis

SegAnalysis is a multiresponse nonlinear regression analysis packages of Mathematica.

In this tutorial we will illustrate the use of SegAnalysis packages while analyzing a real data set.  We have provided these data sets, please followe along with this turorial on your computer.  
Note that throughout this turorial, we indicate  Mathematica session in box.  Crick input cell and press  ⇧|⏎  or enter kye to tell Mathematica to evaluate the input.

Starting SegAnalysis

Loading Data

Data files are three text files of lists of marker position and each allele frequency, {position, frequency}. Marker positions are expressed in Morgan of the Kosambi map function that should be calculated by other programs (e.g. MAPMAKER ) using genotypes in the F2 population to be analyzed.  Sample data (chr01A, chr01B, and chr01H) are allele frequencies of A homozygote, B homozygote, and heterozygote, respectively.  Make the folder "Sample data" on the mathematica path, or make alias of the folder which contains these data, copy it on the mathematica path and named "Sample data".

Loading regression analysis package

We have developed 7 regression analysis packages depending on mathematical models to explain observed data set.  SegregAnalysis package was developed for simple mathematical models, Single, OneOne, Two, TwoOne, Three, TwoTwo, ThreeOne, ThreeTwo, ThreeThree, ZOne, and ZTwo.  For the Three model, only mathematical equations are available, and regression analysis cannot execute.  The regression analysis packages for OneOneZOne, TwoOneZOne, SingleZTwo, OneOneZTwo, TwoZTwo, and ZThree are independent packages.  When you load another package, you have to quit  Kernel for initializing variables and load data sets.

Load SegregAnalysis and plot observed data.

g1=MultipleListPlot[AHomo, BHomo,Hetero, \(SymbolStyle\  -> 

              \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
                \ \ {RGBColor[0, \ 0, \ 1]}}\),  PlotRange  ->  {{0,  2},  {0, 0.6}}, Frame -> True];

If you find disconnected marker allele frequencies from others, you should check the marker genotypes.  The disconnected frequencies would be due to lack of scored progeny or genotyping error.   You should remove or rescored the marker, and re-calculate the genetic linkage map.

Choosing models

In applying mathematical models to the regression analysis, deviation of heterozygous frequency and coincidence of peak locations of allele frequencies are important.  A flow chart for choosing a model was showed below.

Execute regression analysis from a simple model to complicated one

A simple model

Execute regression analysis for the most pronounced deviation

In sample data, there are mainly three regions showing deviation from Mendelian segregation ratios, ~50, ~80, and ~150 cM.  Firstly, we try to analyze the most pronounced deviation at ~80 cM where the heterozygous frequency is lower than 50% and the peak locationos of the both homozygote are same.  We apply a zygotic barrier to this deviation.

Initial guess

?ZOneA

Guess adequate initial values, barrier location, the viabilities of the B homozygote and the heterozygote relative to the A homozygote are 85 cM, 2, and 1.25, respectively.

\(g2 = 
      Plot[{ZOneA[x, \ 0.85, 2, \ 1.25], \ ZOneB[x, \ 0.85, 2, \ 1.25], 
          ZOneH[x, \ 0.85, 2, \ 1.25]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

Execute regression analysis for ZOne model

?SegregAnalysis

?ZOne

SegregAnalysis[AHomo,  BHomo,  Hetero,  {0, 2},  ZOne, 
       {0.85,  2,  1.25}]

Superimpose the regression curves on the observed data.

\(g2 = 
      Plot[{ZOneA[x, \ 0.931341, 1.66434, \ 1.05912], \ 
          ZOneB[x, \ 0.931341, 1.66434, \ 1.05912], 
          ZOneH[x, \ 0.931341, 1.66434, \ 1.05912]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

Execute regression analysis in a limited range {0.6, 1.3}.

SegregAnalysis[AHomo,  BHomo,  Hetero,  {0.6, 1.3},  ZOne, 
       {0.85,  2,  1.25}]

\(g2 = 
      Plot[{ZOneA[x, \ 0.894626, 1.80765, \ 1.07412], \ 
          ZOneB[x, \ 0.894626, 1.80765, \ 1.07412], 
          ZOneH[x, \ 0.894626, 1.80765, \ 1.07412]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

Execute regression analysis with fixed values.

SegregAnalysis[AHomo,  BHomo,  Hetero,  {0, 2},  ZOne, 
       {0.89,  2,  1.25},  FixedParameters -> {"xv1"}]

\(g2 = 
      Plot[{ZOneA[x, \ 0.89, 1.66008, \ 1.02254], \ 
          ZOneB[x, \ 0.89, 1.66008, \ 1.02254], 
          ZOneH[x, \ 0.89, 1.66008, \ 1.02254]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

Execute regression analysis taking into account of ~50 cM  deviation

The both homozygous allele frequencies in the region ~50 cM deviate from the expected curves that estimated by the zygotic barrier at ~90 cM.  The heterozygous frequencies are lower than the expected values.  Since concordance of the peak locations of the allele frequencies is ambiguous, there are two possible models (a zygotic barrier or two gametophytic barriers with the same effect on the different gametophyte) to explain ~50 cM deviation.  Try ZTwo and OneOneZOne model.

ZTwo model

\(g2 = 
      Plot[{ZTwoA[x, \ 0.5, \ 0.6, \ 0.7, 0.9, 1.9, \ 1.2], \ 
          ZTwoB[x, \ 0.5, \ 0.6, \ 0.7, 0.9, 1.9, \ 1.2], 
          ZTwoH[x, \ 0.5, \ 0.6, \ 0.7, 0.9, 1.9, \ 1.2]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

SegregAnalysis[AHomo,  BHomo,  Hetero,  {0, 2},  ZTwo, 
       {{0.5,  0.6,  0.7}, {0.9, 1.9,  1.2}}]

\(g2 = 
      Plot[{ZTwoA[x, \ 0.504437, \ 0.487584, \ 0.67647, 0.822515, 2.8207, \ 
            1.30609], \ 
          ZTwoB[x, \ 0.504437, \ 0.487584, \ 0.67647, 0.822515, 2.8207, \ 
            1.30609], 
          ZTwoH[x, \ 0.504437, \ 0.487584, \ 0.67647, 0.822515, 2.8207, \ 
            1.30609]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

OneOneZOne model

\(SetDirectory["Sample data"]; 
AHomo\  = \ N[Read["chr01A"]]; 

    BHomo\  = \ N[Read["chr01B"]]; 
Hetero\  = \ N[Read["chr01H"]]; 
    
<< \ SegAnalysis`OneOneZOne`; \)

g1=MultipleListPlot[AHomo, BHomo,Hetero, \(SymbolStyle\  -> 

              \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
                \ \ {RGBColor[0, \ 0, \ 1]}}\),  PlotRange  ->  {{0,  2},  {0, 0.6}}, Frame -> True];

\(g2 = 
      Plot[{OneOneZOneA[x, \ 0.49, \ 0.6, \ 0.51, \ 0.6, \ 0.85, 2.5, \ 1.2], 
          \ OneOneZOneB[x, \ 0.49, \ 0.6, \ 0.51, \ 0.6, \ 0.85, 2.5, \ 1.2], 
          OneOneZOneH[x, \ 0.49, \ 0.6, \ 0.51, \ 0.6, \ 0.85, 2.5, \ 1.2]}, 
        \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

?OneOneZOne

OneOneZOne[AHomo,  BHomo,  Hetero,  {0, 2}, 
       {{0.49,  0.6}, {0.51,  0.6}, {0.85, 2.5,  1.2}}]

\(g2 = 
      Plot[{OneOneZOneA[x, \ 0.515015, \ 0.587361, \ 0.519126, \ 0.585176, \ 
            0.812004, 2.71006, \ 1.25177], \ 
          OneOneZOneB[x, \ 0.515015, \ 0.587361, \ 0.519126, \ 0.585176, \ 
            0.812004, 2.71006, \ 1.25177], 
          OneOneZOneH[x, \ 0.515015, \ 0.587361, \ 0.519126, \ 0.585176, \ 
            0.812004, 2.71006, \ 1.25177]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

Because the RMS of the ZTwo model (0.0206843), is lower than that of the OneOneZOne model (0.020839), a zygotic barrier is a better explanation for the ~50 cM deviation than two gametophtic barriers.

Execute regression analysis of a whole chromosome

The heterozygous frequencies at ~150 cM are higher than the expected values that calculated on the ZTwo model, and concordance of the peak locations of the three allele frequencies is ambiguous.  There are two possible cases to explain ~150 cM deviation, a zygotic barrier or two gametophyte barriers with the different effects on the different gender.  Try ZThree and OneOneZTwo models.

ZThree model

\(SetDirectory["Sample data"]; 
AHomo\  = \ N[Read["chr01A"]]; 

    BHomo\  = \ N[Read["chr01B"]]; 
Hetero\  = \ N[Read["chr01H"]]; 
    
<< \ SegAnalysis`ZThree`; \)

g1=MultipleListPlot[AHomo, BHomo,Hetero, \(SymbolStyle\  -> 

              \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
                \ \ {RGBColor[0, \ 0, \ 1]}}\),  PlotRange  ->  {{0,  2},  {0, 0.6}}, Frame -> True];

\(g2 = 
      Plot[{ZThreeA[x, \ 0.5, \ 0.5, \ 0.7, 0.82, 2.8, \ 1.3, \ 1.55, \ 1, \ 
            1.3], \ ZThreeB[x, \ 0.5, \ 0.5, \ 0.7, 0.82, 2.8, \ 1.3, \ 1.55, 
            \ 1, \ 1.3], 
          ZThreeH[x, \ 0.5, \ 0.5, \ 0.7, 0.82, 2.8, \ 1.3, \ 1.55, \ 1, \ 
            1.3]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

ZThree[AHomo,  BHomo,  Hetero,  {0, 2}, 
       {{0.5,  0.5,  0.7}, {0.82, 2.8,  1.3},  {1.55,  1,  1.3}}]

\(g2 = 
      Plot[{ZThreeA[x, \ 0.49703, \ 0.508974, \ 0.69698, 0.829948, 2.65693, \ 
            1.22472, \ 1.53964, \ 1.02751, \ 1.25696], \ 
          ZThreeB[x, \ 0.49703, \ 0.508974, \ 0.69698, 0.829948, 2.65693, \ 
            1.22472, \ 1.53964, \ 1.02751, \ 1.25696], 
          ZThreeH[x, \ 0.49703, \ 0.508974, \ 0.69698, 0.829948, 2.65693, \ 
            1.22472, \ 1.53964, \ 1.02751, \ 1.25696]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

OneOneZTwo model

\(SetDirectory["Sample data"]; 
AHomo\  = \ N[Read["chr01A"]]; 

    BHomo\  = \ N[Read["chr01B"]]; 
Hetero\  = \ N[Read["chr01H"]]; 
    
<< \ SegAnalysis`OneOneZTwo`; \)

g1=MultipleListPlot[AHomo, BHomo,Hetero, \(SymbolStyle\  -> 

              \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
                \ \ {RGBColor[0, \ 0, \ 1]}}\),  PlotRange  ->  {{0,  2},  {0, 0.6}}, Frame -> True];

\(g2 = 
      Plot[{OneOneZTwoA[x, \ 1.55, 0.33, \ 1.53, \ 0.66, \ 0.5, \ 0.5, \ 0.7, 
            0.83, 2.8, \ 1.3], \ 
          OneOneZTwoB[x, \ 1.55, 0.33, \ 1.53, \ 0.66, \ 0.5, \ 0.5, \ 0.7, 
            0.83, 2.8, \ 1.3], 
          OneOneZTwoH[x, \ 1.55, 0.33, \ 1.53, \ 0.66, \ 0.5, \ 0.5, \ 0.7, 
            0.83, 2.8, \ 1.3]}, \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

OneOneZTwo[AHomo,  BHomo,  Hetero,  {0, 2}, 
       {{1.55, 0.33},  {1.53,  0.66}, 
         {0.5,  0.5,  0.7}, {0.82, 2.8,  1.3}}]

\(g2 = 
      Plot[{OneOneZTwoA[x, \ 1.54725, 0.333043, \ 1.53244, \ 0.66006, \ 
            0.49728, \ 0.508486, \ 0.695745, 0.831635, 2.68322, \ 1.23329], \ 
          OneOneZTwoB[x, \ 1.54725, 0.333043, \ 1.53244, \ 0.66006, \ 
            0.49728, \ 0.508486, \ 0.695745, 0.831635, 2.68322, \ 1.23329], 
          OneOneZTwoH[x, \ 1.54725, 0.333043, \ 1.53244, \ 0.66006, \ 
            0.49728, \ 0.508486, \ 0.695745, 0.831635, 2.68322, \ 1.23329]}, 
        \ {x, \ 0, \ 2}, \ 
        PlotStyle\  -> 

          \ \ \ \ \ {{RGBColor[1, \ 0, \ 0]}, \ {RGBColor[0, \ 1, \ 0]}, 
            \ {RGBColor[0, 0, 1]}}, \ \ 
        PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}, \ PlotPoints\ \  -> \ 250]; 
    
Show[g1, g2, \ PlotRange\  -> \ {{0, \ 2}, \ {0, 0.6}}]; \)

Because the RMS of the OneOneZTwo model (0.0150716), is lower than that of the ZThree model (0.0150802), two gametophtic barriers is a better explanation for the ~150 cM deviation than a zygotic barrier.  The allele frequency deviation on the sample chromosome were well explained by two gametophytic barriers and two zygotic barriers.