The Mendelian Separation Law model

Source: Internet
Author: User

Law of segregation separation theorem

Segregation separation

Algorithm:

Simulating Mendelian separation theorem

#coding =utf-8
#law of segregation Mendelian separation theorem

Import Math,random,pylab

#试验次数
n=1000

#三类实验对象
#显性遗传因子
Dominant_hereditary_factor= ' D '
#隐性遗传因子
Recessive_hereditary_factor= ' d '
#遗传因子列表
List_hereditary_factor=[dominant_hereditary_factor,recessive_hereditary_factor]

#纯种高茎
High_pure=[dominant_hereditary_factor,dominant_hereditary_factor]
#纯种矮茎
Low_pure=[recessive_hereditary_factor,recessive_hereditary_factor]
#杂种高茎
Cross_high=[dominant_hereditary_factor,recessive_hereditary_factor]


#配子时, randomly selected a genetic factor

def random_hereditary_factor (List_hereditary_factor):
#真随机数
R=random. Systemrandom ()
#随机抽出一个遗传因子
Random_hereditary_factor=r.choice (List_hereditary_factor)
Return Random_hereditary_factor


#配子过程
def Son (LIST1,LIST2):
Son=[]
#纯高茎中抽取一个遗传因子
Factor1=random_hereditary_factor (List1)
Son.append (Factor1)
#纯矮茎中抽取一个遗传因子
Factor2=random_hereditary_factor (LIST2)
Son.append (Factor2)
return son


#配子性状判断, for example, high or short
def character_analysis (LIST1,LIST2):
Son=son (LIST1,LIST2)
#print ' son: ' son
#如果线性遗传因子在配子中, return to dominant traits
If Dominant_hereditary_factor in Son:
Character= "Dominant_character"

#否则返回隐性性状
Else
Character= "Recessive_character"

return character


#实验n次, the ratio of high stem to dwarf stem was observed.
def count_test (N,LIST1,LIST2):
Count_dominant=0
Count_recessive=0
For I in range (n):
Analysis1=character_analysis (LIST1,LIST2)
If analysis1== "Dominant_character":
Count_dominant+=1
If analysis1== "Recessive_character":
Count_recessive+=1

Ration=count_recessive*1.0/count_dominant
return ration


def Print (N,ratio_purehigh_purelow,ratio_crosshigh_crosshigh,ratio_crosshigh_purelow):
print ' N: ', n
print ' Ratio_purehigh_purelow: ', Ratio_purehigh_purelow
print ' Ratio_crosshigh_crosshigh: ', Ratio_crosshigh_crosshigh
print ' Ratio_crosshigh_purelow: ', Ratio_crosshigh_purelow


#绘图前准备, get a set of proportional coefficients for multiple experiments
def list_ratio (N,LIST1,LIST2):
List_ration=[]
For I in range (n):
Ration=count_test (N,LIST1,LIST2)
List_ration.append (Ration)

Return list_ration


#实验1: The ratio of purebred tall stems to purebred dwarf stems
#list_ratio1 =list_ratio (n,high_pure,low_pure)
#实验2: The ratio of high stem to hybrid high stem
#list_ratio2 =list_ratio (N,cross_high,cross_high)
#实验3: The number of hybrids with high stems and purebred dwarf stems
#list_ratio3 =list_ratio (n,cross_high,low_pure)


#实验1: The ratio of purebred tall stems to purebred dwarf stems
Ratio_purehigh_purelow=count_test (N,high_pure,low_pure)

#实验2: The ratio of high stem to hybrid high stem
#ratio_crossHigh_crossHigh =count_test (N,cross_high,cross_high)

#实验3: The number of hybrids with high stems and purebred dwarf stems
#ratio_crossHigh_pureLow =count_test (n,cross_high,low_pure)


#Print (N,ratio_purehigh_purelow,ratio_crosshigh_crosshigh,ratio_crosshigh_purelow)

Description of the Mendelian separation theorem of statistics

Hybrid high stems and hybrid high stems

Purebred tall stems and thoroughbred dwarf stems

Hybrid high stem and thoroughbred dwarf stem

#coding =utf-8
# There is a problem with the mode function
Import Math,numpy,pylab,distribution_status,statistics_functions,quartile,law_of_segregation
#list1 =[2.96,2.84,3.01,3.15,2.95,2.82,3.14]
#list1 =[19,15,29,25,24,23,21,38,22,18,30,20,19,19,16,23,27,22,34,24,41,20,31,17,23]
#list1 =[5.5,6.5,6.7,6.8,7.1,7.3,7.4,7.8,7.8]
#list1 =[164,167,168,165,170,165,164,168,164,162,163,166,167,166,165]
#list1 =[129,130,129,130,131,130,129,127,128,128,127,128,128,125,132]
#list1 =[125,126,126,127,126,128,127,126,127,127,125,126,116,126,125]
List1=law_of_segregation.list_ratio1
N=len (List1)
Mean=statistics_functions. Mean (List1)
Median=statistics_functions. Median (List1)
Mode=statistics_functions. Mode (List1)
Deviation=statistics_functions. Deviation (List1)
Standarderror=statistics_functions. Standard_error_of_the_mean (List1)
Coefficient_of_variation=statistics_functions. Coefficient_of_variation (List1)

Max1=max (List1)
Min1=min (List1)

Q_l=quartile. Quartile (List1, ' q_l ')
Q_u=quartile. Quartile (List1, ' Q_u ')
Quartile_deviation=quartile. Quartile_deviation (List1)

Skew=distribution_status. Skew (List1)
Kurtosis=distribution_status. Kurtosis (List1)

Print "Central tendency:"
Print "N:", n
Print "range[%d:%d]"% (MIN1,MAX1)
Print "mean:", mean
Print "median:", median
Print "mode:", mode
Print "Quartile 1/4:", q_l
Print "Quartile 3/4:", Q_u
Print "Quartile_deviation:", quartile_deviation

Print "-" *20
Print "Dispersion:"
print "deviation:", deviation
Print "Standard Error:", StandardError
print "Coefficient of variation:", coefficient_of_variation

Print "-" *20
Print "Distribution Status:"
Print "Skew:", skew
Print "Kurtosis:", kurtosis

#绘图
def Draw (List1):
For I in List1:
X=I[0]
Y=I[1]
Pylab.plot (x, y, ' r--')
Pylab.xlabel (' x ')
Pylab.ylabel (' y ')
Pylab.title ("Descriptive statistics")
Pylab.grid (True)
# Pad margins so this markers don ' t get clipped by the axes, let dot not coincide with axis
Pylab.margins (0.05)
Pylab.show ()

def draw_hist (List1):
#facecolor表面颜色
Pylab.hist (list1,bins=100,normed=1,facecolor= ' green ', alpha=0.5)
Pylab.xlabel (' x ')
Pylab.ylabel (' frenquency ')
Pylab.title (' hist ')
Pylab.margins (0.01)
Pylab.show ()

#数组中不重复数字
#list_noneRepeat =statistics_functions. List_nonerepeat (List1)
#不重复数字频率
#frequency =statistics_functions. Frequence (List1)

#dict_mean_frequency =dict (Zip (list_nonerepeat,frequency))

#list_mean_frequency =dict_mean_frequency.items ()

#Draw (list_mean_frequency)

Draw_hist (List1)

The Mendelian Separation Law model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.