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??
JavaScript
x
27
27
1
def get_orf(dna):
2
'''Function should take an argument (string) and find an ORF'''
3
stopVar = "TAA" or "TGA" or "TAG"
4
if argument[0:3] == "ATG":
5
return
6
else:
7
return ""
8
if stopVar in argument:
9
return argument[:argument.find(stopVar)]
10
else:
11
return argument
12
13
return
14
15
# Test Cases
16
#
17
# You may wish to add more test cases here
18
argument = 'ATGTGAA'
19
computed_result = get_orf( argument )
20
expected_result = 'ATG'
21
if ( computed_result == expected_result ):
22
print ("Test Case 1: Passed")
23
else:
24
print ("Test Case 1: Failed")
25
print ("Expected Result:", expected_result)
26
print ("Computed Result:", computed_result)
27
Advertisement
Answer
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
:
JavaScript
1
23
23
1
def get_orf(dna):
2
"""Function should take an argument (string) and find an ORF."""
3
stopVar = "TAA" or "TGA" or "TAG"
4
if dna[0:3] == "ATG":
5
return "ATG"
6
elif stopVar in dna:
7
return dna[:dna.find(stopVar)]
8
else:
9
return dna
10
11
# Test Cases
12
#
13
# You may wish to add more test cases here
14
argument = 'ATGTGAA'
15
computed_result = get_orf(argument)
16
expected_result = 'ATG'
17
if (computed_result == expected_result):
18
print ("Test Case 1: Passed")
19
else:
20
print ("Test Case 1: Failed")
21
print ("Expected Result:", expected_result)
22
print ("Computed Result:", computed_result)
23
With argument = 'ATGTGAA'
:
JavaScript
1
2
1
Test Case 1: Passed
2
With argument = 'GATGTGAA'
:
JavaScript
1
4
1
Test Case 1: Failed
2
Expected Result: ATG
3
Computed Result: GATGTGAA
4
The docstring
for functions is with """Text."""
rather then single quotes too so I changed that.