Python如何计算特定氨基酸在蛋白序列中的比例?

2026-06-10 21:303阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计263个文字,预计阅读时间需要2分钟。

Python如何计算特定氨基酸在蛋白序列中的比例?

pythonfrom __future__ import division

Python如何计算特定氨基酸在蛋白序列中的比例?

def get_aa_percentage(protein, aa_list=['A', 'I', 'L', 'M', 'F', 'W', 'Y', 'V']): protein=protein.upper() protein_length=len(protein) total=0 for aa in aa_list: aa_count=protein.count(aa) total +=aa_count return total / protein_length

编码

from__future__importdivision

defget_aa_percentage(protein,aa_list=['A','I','L','M','F','W','Y','V']):
protein=protein.upper()
protein_length=len(protein)
total=0
foraainaa_list:
aa=aa.upper()
aa_count=protein.count(aa)
total+=aa_count
percentage=total*100/protein_length
returnpercentage

assertget_aa_percentage("MSRSLLLRFLLFLLLLPPLP",["M"])==5
assertget_aa_percentage("MSRSLLLRFLLFLLLLPPLP",['M','L'])==55
assertget_aa_percentage("MSRSLLLRFLLFLLLLPPLP",['F','S','L'])==70
assertget_aa_percentage("MSRSLLLRFLLFLLLLPPLP")==65

解析

Python assert(断言)用于判断一个表达式,在表达式条件为 False 的时候触发异常。
断言可以在条件不满足程序运行的情况下直接返回错误,而不必等待程序运行后出现崩溃的情况。

assertexpression

#等价于
ifnotexpression:
raiseAssertionError


Ref:​​www.runoob.com/python3/python3-assert.html​​



作者:Bioinfarmer

若要及时了解动态信息,请关注同名微信公众号:Bioinfarmer。


本文共计263个文字,预计阅读时间需要2分钟。

Python如何计算特定氨基酸在蛋白序列中的比例?

pythonfrom __future__ import division

Python如何计算特定氨基酸在蛋白序列中的比例?

def get_aa_percentage(protein, aa_list=['A', 'I', 'L', 'M', 'F', 'W', 'Y', 'V']): protein=protein.upper() protein_length=len(protein) total=0 for aa in aa_list: aa_count=protein.count(aa) total +=aa_count return total / protein_length

编码

from__future__importdivision

defget_aa_percentage(protein,aa_list=['A','I','L','M','F','W','Y','V']):
protein=protein.upper()
protein_length=len(protein)
total=0
foraainaa_list:
aa=aa.upper()
aa_count=protein.count(aa)
total+=aa_count
percentage=total*100/protein_length
returnpercentage

assertget_aa_percentage("MSRSLLLRFLLFLLLLPPLP",["M"])==5
assertget_aa_percentage("MSRSLLLRFLLFLLLLPPLP",['M','L'])==55
assertget_aa_percentage("MSRSLLLRFLLFLLLLPPLP",['F','S','L'])==70
assertget_aa_percentage("MSRSLLLRFLLFLLLLPPLP")==65

解析

Python assert(断言)用于判断一个表达式,在表达式条件为 False 的时候触发异常。
断言可以在条件不满足程序运行的情况下直接返回错误,而不必等待程序运行后出现崩溃的情况。

assertexpression

#等价于
ifnotexpression:
raiseAssertionError


Ref:​​www.runoob.com/python3/python3-assert.html​​



作者:Bioinfarmer

若要及时了解动态信息,请关注同名微信公众号:Bioinfarmer。