Python 3.x python 3清理程序代码,从字典计算值

Python 3.x python 3清理程序代码,从字典计算值,python-3.x,dictionary,Python 3.x,Dictionary,目前,我的代码可以使用,但我认为有几行代码是我不需要的。我正在输入一个序列(DNA),让代码计算一些值并返回给我。我输入序列,然后输入浓度,熔化温度,dH,dS和dG返回给我。只是张贴,看看是否有任何方法,我可以有代码清理,或者如果你们认为它是好的。这也是python3的。谢谢你的帮助 import math sequence1 = input("Enter DNA Sequence: ") sequence2 = [i for i in sequence1[0::1]] sequenceR =

目前,我的代码可以使用,但我认为有几行代码是我不需要的。我正在输入一个序列(DNA),让代码计算一些值并返回给我。我输入序列,然后输入浓度,熔化温度,dH,dS和dG返回给我。只是张贴,看看是否有任何方法,我可以有代码清理,或者如果你们认为它是好的。这也是python3的。谢谢你的帮助

import math
sequence1 = input("Enter DNA Sequence: ")
sequence2 = [i for i in sequence1[0::1]]
sequenceR = [i for i in sequence2[::-1]]
dnac = input("Enter DNA Concentration (M): ") #Effectively Ct
dnac = float(dnac)
#assume 1M NaOH, though this adjustment is easy to establish if necessary.
first = sequence1[0]
last = sequence1[-1]
sequence = [i+j for i,j in zip(sequence1[0::1], sequence1[1::1])]

navbles={       "AA": (-7.9     ,-22.2  ,-1.0),
                        "TT": (-7.9     ,-22.2  ,-1.0),
                        "AT": (-7.2     ,-20.4  ,-0.88),
                        "TA": (-7.2     ,-21.3  ,-0.58),
                        "CA": (-8.5     ,-22.7  ,-1.45),
                        "TG": (-8.5     ,-22.7  ,-1.45),
                        "GT": (-8.4     ,-22.4  ,-1.44),
                        "AC": (-8.4     ,-22.4  ,-1.44),
                        "CT": (-7.8     ,-21.0  ,-1.28),
                        "AG": (-7.8     ,-21.0  ,-1.28),
                        "GA": (-8.2     ,-22.2  ,-1.30),
                        "TC": (-8.2     ,-22.2 ,-1.30),
                        "CG": (-10.6 ,-27.2     ,-2.17),
                        "GC": (-9.8     ,-24.4  ,-2.24),
                        "GG": (-8.0     ,-19.9  ,-1.84),
                        "CC": (-8.0     ,-19.9  ,-1.84),
                        "A" : (0        , 0     ,               0),
                        "C" : (0        , 0     ,               0),
                        "G" : (0        , 0     ,               0),
                        "T" : (0        , 0 ,           0),     }
initiator={     "G": (0.1 ,-2.8,        0.98),
                        "C": (0.1 ,-2.8,        0.98),
                        "A": (2.3, 4.1, 1.03),
                        "T": (2.3, 4.1, 1.03) }

complement = {'A' : 'T', 'T' : 'A', 'G' : 'C', 'C' : 'G'}

#First and last terms, to start off
F1 = initiator[first]
L1 = initiator[last]
dH1 = F1[0]
dH2 = L1[0]
dS1 = F1[1]
dS2 = L1[1]
dG1 = F1[2]
dG2 = L1[2]

R = 1.987 #cal mol K
#answer = (dH1/(dS1 + R*C))+(dH2/(dS2 + R*C))
answerH = dH1 + dH2
answerS = dS1 + dS2
answerG = dG1 + dG2
#the iterative meat
for na in range(len(sequence)):
        n = navbles[sequence[na]]
        H = n[0]
        S = n[1]
        G = n[2]
        #answer = answer + (H/(S + R*C))
        answerG = answerG + G
        answerH = answerH + H
        answerS = answerS + S

#symmetry check
if sequenceR == sequence2:
        symm = "y"
else:
        symm = "n"
if symm == "y":
        answerS = answerS + -1.4
else:
        pass
#complementary check
sequenceC = []
for i in range(len(sequenceR)):
        sequenceC.append(complement[sequenceR[i]])

if sequenceC == sequence2:
        comp = "y"
else:
        comp = "n"

if comp == "n":
        C = math.log(dnac / 4)
else:
        C = math.log(dnac)
#print(C)
answerT = (1000*answerH)/(answerS + R*C)
print('Tm =', answerT)
print('dH(kcal) = ', answerH)
print('dS(cal) = ', answerS)
print('dG(kcal) = ', answerG)

#print(sequence1)

我觉得这个看起来不错。如果您计划在将来将其应用于真正的大型数据库,那么您可以随时进行重构以提高性能,但有时只需要一种直接的方法就可以完成这项工作

感谢您的检查,我不需要为课程中的作业检查,如果我只是输入一个序列就可以了,但我知道如果代码不干净,我的老师会扣分。