I am learning bioinformatics and i was solving a problem on rosalind.info. Input is a string consist of multiple DNA strand names and the DNA sequences, and Output is the name of the sequence that has the highest GC percentage and the GC percentage. this is the input:
>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT
this is the correct output:
Rosalind_0808
60.919540
This is my code (sorry for this filthy mess):
DNA = input()
wholeRosalind_DNA = DNA.splitlines()
Rosalind = []
Rosalind_DNA = []
for i in wholeRosalind_DNA:
if "Rosalind" in i:
Rosalind.append(i)
Countstring = []
maxGCcontent = []
GCcontent = []
def eachRosalind_DNA(DNA):
for i in range(0,len(Rosalind)):
if Rosalind[i] in wholeRosalind_DNA:
a = wholeRosalind_DNA.index(Rosalind[i])
if a == wholeRosalind_DNA.index(Rosalind[-1]):
b = len(wholeRosalind_DNA)+1
else:
b = wholeRosalind_DNA.index(Rosalind[i+1])
Rosalind_DNA.append(wholeRosalind_DNA[a:b])
for i in Rosalind_DNA:
Countstring.append(''.join(i))
for i in Countstring:
bases = len(i)-14
CG = i.count("C") + i.count("G")
GCcontent.append([i[1:14],(100*(CG/bases))])
for i in GCcontent:
maxGCcontent.append(i[1])
result = max(maxGCcontent)
for i in GCcontent:
if i[1] == result:
return (i[0]),(round(i[1],6))
print(eachRosalind_DNA(DNA)[0])
print(eachRosalind_DNA(DNA)[1])
but i get this instead:
File "GC_Content.py", line 26, in eachRosalind_DNA
GCcontent.append([i[1:14],(100*(CG/bases))])
ZeroDivisionError: division by zero
i will get the desired output if i just paste the input into the variabe "DNA" without using user input. Please help me fix the code and distinguish those two ways of getting input
i
). This will help you and others spotting potential bugs. $\endgroup$