孟德尔分离定律建模

孟德尔(Gregor Johann Mendel)

阿基米德会思考如何用这粒豌豆做支点来翘起地球;英国人希望次日醒来能顺着它的茎爬上天空;而游戏玩家们则会把豌豆种在家门口阻挡一大波僵尸的进攻……

大约150多年前,有一名修道士却将它玩出了风格,玩出了水平,一不小心就奠定了现代生物学的三大基石之一。

孟德尔(Gregor Johann Mendel)

他就是“现代遗传学之父”——格雷戈尔·约翰·孟德尔。

 

孟德尔在揭示了由一对遗传因子(或一对等位基因)控制的一对相对性状杂交的遗传规律——分离规律之后,这位才思敏捷的科学工作者,又接连进行了两对、三对甚至更多对相对性状杂交的遗传试验,进而又发现了第二条重要的遗传学规律,即自由组合规律,也有人称它为独立分配规律。这里我们仅介绍所进行的两对相对性状的杂交试验。(通过假说演绎法论证)

算法:

 

模拟孟德尔分离定理

#原创公众号pythonEducation
#law of segregation 孟德尔分离定理

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]


#配子时,随机选出一个遗传因子

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


#配子性状判断,例如是高还是矮
def Character_analysis(list1,list2):
son=Son(list1,list2)
#print 'son:',son
#如果线性遗传因子在配子中,返回显性性状
if dominant_hereditary_factor in son:
character="dominant_character"
#否则返回隐性性状
else:
character="recessive_character"
return character


#实验n次,观察高茎与矮茎数量比
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


#绘图前准备,得到多次实验的比例系数集合
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:纯种高茎与纯种矮茎的数量比
#list_ratio1=List_ratio(n,high_pure,low_pure)
#实验2:杂种高茎与杂种高茎的数量比
#list_ratio2=List_ratio(n,cross_high,cross_high)
#实验3:杂种高茎和纯种矮茎的数量比
#list_ratio3=List_ratio(n,cross_high,low_pure)


#实验1:纯种高茎与纯种矮茎的数量比
ratio_pureHigh_pureLow=Count_test(n,high_pure,low_pure)

#实验2:杂种高茎与杂种高茎的数量比
#ratio_crossHigh_crossHigh=Count_test(n,cross_high,cross_high)

#实验3:杂种高茎和纯种矮茎的数量比
#ratio_crossHigh_pureLow=Count_test(n,cross_high,low_pure)


#Print(n,ratio_pureHigh_pureLow,ratio_crossHigh_crossHigh,ratio_crossHigh_pureLow)

描述统计孟德尔分离定理

杂种高茎与杂种高茎

纯种高茎与纯种矮茎

杂种高茎与纯种矮茎

 

#原创公众号pythonEducation
# mode 函数有问题
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 that markers don't get clipped by the axes,让点不与坐标轴重合
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)

备注

law of segregation 分离定理

segregation分离

欢迎各位同学学习更多相关知识《python机器学习生物信息学》

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

python机器学习建模

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值