Mendel's free combinatorial theorem--computer simulation

Source: Internet
Author: User

#coding =utf-8
#孟德尔自由组合定理

Import Copy

#大写字母表示显性基因, lowercase letters indicate recessive genes.
#gene, such as D or D
#基因型genotype
genotype11=[' y ', ' y ']
genotype12=[' y ', ' y ']
genotype13=[' y ', ' y ']
genotype21=[' R ', ' R ']
genotype22=[' R ', ' R ']
genotype23=[' R ', ' R ']
DNA1=[GENOTYPE13,GENOTYPE23]
DNA2=[GENOTYPE12,GENOTYPE22]
DNA3=[GENOTYPE11,GENOTYPE21]
DNA4=[GENOTYPE12,GENOTYPE22]
DNA_GROUP=[DNA3,DNA4]

#基因表现型character
#字母大小写判断a. Islower (), A.isupper ()
def Character (genotype1):
For I in Genotype1:
If I.isupper () ==true:
Return "dominant"

Return "recessive"


#Phenotype输入基因型, return it to the representative gene
def phenotype (Genotype1):
For I in Genotype1:
If I.isupper () ==true:
return I

return genotype1[0]


#配子后, the possible number of genotype genotype
def assort (genotype1,genotype2):
Genotype_list=[]

For gene1 in Genotype1:
For Gene2 in Genotype2:
Genotype=[gene1,gene2]
Genotype_list.append (genotype)

Return genotype_list


#返回不重复列表
def none_repeat_list (List1):
None_repeat_list=[]
For I in List1:
#print ' I: ', I
If I not in none_repeat_list:
None_repeat_list.append (i)
Return none_repeat_list

#计算各个基因类型比例
def count_list (none_repeat_list,dna_sort_list,n):
Count_list=[]
For I in None_repeat_list:
Count=dna_sort_list.count (i)
count=count*1.0/n
Count_list.append (count)

Return count_list

#返回各个基因类型比例
def ratio_genotype (none_repeat_list,count_list):
Ratio_genotype=zip (None_repeat_list,count_list)
Return Ratio_genotype


#多个基因型的自由组合
def independent_assort (DNA1,DNA2):
GENOTYPE00=DNA1[0]
GENOTYPE01=DNA2[0]
Assortment1=assort (GENOTYPE00,GENOTYPE01)

GENOTYPE10=DNA1[1]
GENOTYPE11=DNA2[1]
Assortment2=assort (GENOTYPE10,GENOTYPE11)

Result=assort (Assortment1,assortment2)

return result

#排序函数, capital letters (linear genes) are in front. For example [r,r] after sorting [r,r]
def Sort (List1):
K=0
N=len (List1[0])
#print "N:", n
For I in range (len (list1)):
#print ' i ', I
While K<n:
#print ' K ', K
#print ' list1[i][k] ', list1[i][k]
List1[i][k].sort ()
K+=1
K=0
Return List1

#DNA所有性状结果
">>> Character_dna (dna_nonerepeat_assortment)
[[' Y ', ' R '], [' Y ', ' R '], [' Y ', ' R '], [' Y ', ' R '], [' Y ', ' R '], [' Y ', ' R '], [' Y ', ' R. '], [' Y ', ' R '], [' Y ', ' r ']] '


def Character_dna (dna_nonerepeat_assortment):
Character_dna=copy.deepcopy (dna_nonerepeat_assortment)
k=0
Nonerepeat_num=len (dna_nonerepeat_assortment)
Element_num=len (dna_nonerepeat_assortment[0])
# Print "N:", n
for I in Range (nonerepeat_num):
#print ' i ', I
while k<element_num:
#print ' K ', K
#print ' List1[i][k] ', List1[i][k]
Character_dna[i][k]=phenotype (character_dna[i][k])
K+=1
K=0
Return Character_dna


#最终性状和对应数量比
def nonerepeat_character_ratio (Ratio_character,nonerepeat_character_dna):
Num=len (Ratio_character)
List1=copy.deepcopy (Ratio_character)
List_num=[]
Count=0
For I in Nonerepeat_character_dna:
For K in List1:
If k[0]==i:
COUNT+=K[1]
#print "Count", Count
List_num.append (count)
Count=0
Return List_num



def analysis (Dna_group,ratio_character_result):
Print "Dna_group:", Dna_group
print ' Ratio_character_result: ', Ratio_character_result

#多个基因型的自由组合结果 (with Duplicates)
Dna_assortment=independent_assort (DNA3,DNA4)

#多基因自由组合后的排序, capital letters (linear genes) are in front. For example [r,r] after sorting [r,r]
Dna_sort=sort (dna_assortment)
#自由组合个数
N=len (Dna_sort)


#多个基因型的自由组合结果 (No Duplicates)
Dna_nonerepeat_assortment=none_repeat_list (Dna_sort)
#排序结果数量统计
Count_list=count_list (Dna_nonerepeat_assortment,dna_sort,n)
#排序后基因类型对应的数量统计
Ratio_genotype=ratio_genotype (Dna_nonerepeat_assortment,count_list)

#DNA性状结果 (repeat)
Character_dna=character_dna (dna_nonerepeat_assortment)
#数量统计
Ratio_character=ratio_genotype (Character_dna,count_list)

#DNA性状结果 (Go repeat)
Nonerepeat_character_dna=none_repeat_list (Character_dna)

#DNA性状和数量比 (No Duplicates)
Count_nonerepeat_character=nonerepeat_character_ratio (Ratio_character,nonerepeat_character_dna)

#DNA性状和数量比, the final integration
Ratio_character_result=ratio_genotype (Nonerepeat_character_dna,count_nonerepeat_character)

#分析结果
Analysis (Dna_group,ratio_character_result)

Mendel's free combinatorial theorem--computer simulation

Related Article

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.