需要帮助计算DNA序列中GC含量的百分比

时间:2015-04-09 23:20:37

标签: python-3.x

我知道这可能非常简单,但我只需要在此代码中添加一些东西来计算DNA序列中GC含量的百分比。添加此内容的最简单方法是什么?

#!/cygdrive/c/Python34/Python
#This program takes a DNA sequence (without checking) and shows its length,
#individual base composition (the percent of each kind of base), and GC content
#(also as a percent) of the user supplied sequence.

DNASeq = "ACGT"
DNASeq = input ("Enter a DNA sequence: ")
DNASeq = DNASeq.upper() #Convert to uppercase for .count() function
DNASeq = DNASeq.replace(" ","") #Remove spaces

print("Sequence:", DNASeq)

SeqLength = float(len(DNASeq))

print("Sequence Length:", SeqLength)
BaseList = "ACGT"
for Base in BaseList:
    Percent = 100 * DNASeq.count(Base) / SeqLength
    print("%s: %4.1f" % (Base,Percent))

1 个答案:

答案 0 :(得分:0)

试试这个:

gCount = DNASeq.count('G')
cCount = DNASeq.count('C')
gcContent = round((gCount + cCount) / SeqLength, 4)
print(gcContent)