Python 3.x 需要帮助计算DNA序列中GC含量的百分比吗

Python 3.x 需要帮助计算DNA序列中GC含量的百分比吗,python-3.x,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 a

我知道这可能非常简单,但我只需要在代码中添加一些东西来计算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))
试试这个:

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