我知道这可能非常简单,但我只需要在此代码中添加一些东西来计算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))
答案 0 :(得分:0)
试试这个:
gCount = DNASeq.count('G')
cCount = DNASeq.count('C')
gcContent = round((gCount + cCount) / SeqLength, 4)
print(gcContent)