python 3.x - Need help calculating a percentage of GC content in a DNA sequence -
i know simple need add code calculate percent of gc content in sequence of dna. easiest way add this?
#!/cygdrive/c/python34/python #this program takes dna sequence (without checking) , shows length, #individual base composition (the percent of each kind of base), , gc content #(also percent) of user supplied sequence. dnaseq = "acgt" dnaseq = input ("enter dna sequence: ") dnaseq = dnaseq.upper() #convert uppercase .count() function dnaseq = dnaseq.replace(" ","") #remove spaces print("sequence:", dnaseq) seqlength = float(len(dnaseq)) print("sequence length:", seqlength) baselist = "acgt" base in baselist: percent = 100 * dnaseq.count(base) / seqlength print("%s: %4.1f" % (base,percent))
try this:
gcount = dnaseq.count('g') ccount = dnaseq.count('c') gccontent = round((gcount + ccount) / seqlength, 4) print(gccontent)