Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Computing GC Content
#1
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.

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)) 
Would someone be able to provide suggestions as to what might be the problem and how to fix this in the above code?
Reply


Messages In This Thread
Computing GC Content - by uwl - Jun-25-2023, 10:04 PM
RE: Computing GC Content - by Pedroski55 - Jun-26-2023, 12:03 AM
RE: Computing GC Content - by bowlofred - Jun-26-2023, 04:09 PM
RE: Computing GC Content - by Pedroski55 - Jun-26-2023, 09:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Matlab to Python -- Parallel Computing zistambo 1 2,046 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  Computing correlation in audio files ryanblumenow 0 2,840 Jan-15-2020, 06:11 PM
Last Post: ryanblumenow
  computing entropy using pickle files baran01 2 2,517 Dec-30-2019, 09:45 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020