I have been trying to find the solution to a programming problem which asks me to find the GC content. The example online displays:
Sample Dataset
>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT
Sample Output
Rosalind_0808
60.919540
My code runs properly and I already tried entering the solutions I find with the correct amount of decimal place values.
Would someone be able to provide suggestions as to what might be the problem and how to fix this in the above code?
Sample Dataset
>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT
Sample Output
Rosalind_0808
60.919540
My code runs properly and I already tried entering the solutions I find with the correct amount of decimal place values.
1 2 3 4 5 6 7 8 9 10 |
from collections import Counter myDna = '' with open ( 'rosalind_gc.txt' , 'r' ) as data: for line in data: if '>' in line: continue myDna + = line.strip() myNucleotideCounts = Counter(myDna) myGC = (myNucleotideCounts[ 'G' ] + myNucleotideCounts[ 'C' ]) / float ( len (myDna)) print ( 'Dna GC Content = {0}' . format (myGC)) |