I am trying to get a printed output which would be everything from the beginning of the string, to the end, which is until it reaches a certain series of characters like "TAA", "TAG", or "TGA". I can't get it to work and was wondering if anyone here can help me??
def get_orf(dna):
'''Function should take an argument (string) and find an ORF'''
stopVar = "TAA" or "TGA" or "TAG"
if argument[0:3] == "ATG":
return
else:
return ""
if stopVar in argument:
return argument[:argument.find(stopVar)]
else:
return argument
return
# Test Cases
#
# You may wish to add more test cases here
argument = 'ATGTGAA'
computed_result = get_orf( argument )
expected_result = 'ATG'
if ( computed_result == expected_result ):
print ("Test Case 1: Passed")
else:
print ("Test Case 1: Failed")
print ("Expected Result:", expected_result)
print ("Computed Result:", computed_result)
This works although I am not sure whether you want to return
something if the case 'ATG'
is found, it is good practice that if one of your return
s in a function returns something, then they all should even if it is None
:
def get_orf(dna):
"""Function should take an argument (string) and find an ORF."""
stopVar = "TAA" or "TGA" or "TAG"
if dna[0:3] == "ATG":
return "ATG"
elif stopVar in dna:
return dna[:dna.find(stopVar)]
else:
return dna
# Test Cases
#
# You may wish to add more test cases here
argument = 'ATGTGAA'
computed_result = get_orf(argument)
expected_result = 'ATG'
if (computed_result == expected_result):
print ("Test Case 1: Passed")
else:
print ("Test Case 1: Failed")
print ("Expected Result:", expected_result)
print ("Computed Result:", computed_result)
With argument = 'ATGTGAA'
:
Test Case 1: Passed
With argument = 'GATGTGAA'
:
Test Case 1: Failed
Expected Result: ATG
Computed Result: GATGTGAA
The docstring
for functions is with """Text."""
rather then single quotes too so I changed that.