python中四则运算用字典实现_用字典实现算法

我必须实现以下算法:equation其中“I”包含R、K、H和Nterm,“j”包含D、E、C、Y和返回净电荷的正字符m。这种方法被另一种方法用来计算pI,它基本上是产生最低电荷的pH值。在

以下是我目前所掌握的情况:class ProteinParam :

aa2mw = {

'A': 89.093, 'G': 75.067, 'M': 149.211, 'S': 105.093, 'C': 121.158,

'H': 155.155, 'N': 132.118, 'T': 119.119, 'D': 133.103, 'I': 131.173,

'P': 115.131, 'V': 117.146, 'E': 147.129, 'K': 146.188, 'Q': 146.145,

'W': 204.225, 'F': 165.189, 'L': 131.173, 'R': 174.201, 'Y': 181.189

}

mwH2O = 18.015

aa2abs280= {'Y':1490, 'W': 5500, 'C': 125}

aacomp = {}

aa2chargePos = {'K': 10.5, 'R':12.4, 'H':6}

aa2chargeNeg = {'D': 3.86, 'E': 4.25, 'C': 8.33, 'Y': 10}

aaNterm = 9.69

aaCterm = 2.34

def __init__ (self, protein):

l = ''.join(protein).split()

l = ''.join(l).upper()

clean_prot = ""

for aa in l:

if aa in ProteinParam.aa2mw:

clean_prot += aa

else:

pass

self.protString = clean_prot

for i in ProteinParam.aa2mw:

ProteinParam.aacomp[i] = 0

for aa in self.protString:

if aa in ProteinParam.aacomp:

ProteinParam.aacomp[aa] += 1

def aaCount (self):

return(len(self.protString))

def pI (self):

best_charge = 100000000

for test_pH in range (14000):

test_pH += 1

test_pH = (test_pH / 100)

new_charge = self.charge(test_pH)

if new_charge < best_charge:

best_charge = new_charge

return best_charge

def aaComposition (self) :

return ProteinParam.aacomp

def charge (self, pH):

self.pH = pH

negative = 0

positive = 0

for pos in ['R', 'K', 'H']:

positive += ((ProteinParam.aacomp[pos]) * ((10 ** ProteinParam.aa2chargePos[pos]) / (((10 ** ProteinParam.aa2chargePos[pos])) + (10 ** self.pH))))

positive += ProteinParam.aaNterm

for neg in ['D', 'E', 'C', 'Y']:

negative += ((ProteinParam.aacomp[neg]) * ((10 ** self.pH) / (((10 ** ProteinParam.aa2chargeNeg[neg])) + (10 ** self.pH))))

negative += ProteinParam.aaCterm

total = positive - negative

return total

prot_in = input("Enter a protein: ")

prot_obj = ProteinParam(prot_in)

x = prot_obj.pI()

print(x)

问题是,无论我输入什么,当我调用pI()时,我总是返回6.35,我不知道问题出在哪里。我怀疑它在charge()方法中,因为我不知道它在哪里,而且缺少错误并不能缩小它的范围。输入“vlspaktnvkaaw”应给出9.88的pI。有什么想法吗?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值