Reputation: 1
I'm trying to help my partner with his Python class, but I don't know much about Python. Here's the problem he has been stuck for hours, any help would be appreciated!
Question: The program will accept a text file of DNA sequences (1 sequence per line in the file) and determine if the sequence is valid when the following criteria is met: 1. length is a multiple of 3. 2. starts with ATG. 3. ends with TAG. The program will then write the DNA sequence followed by ‘True’ or ‘False’ to a new file (each output on a separate line). Example: Input sequence: ‘ATGCGCCTGCGTCTGTACTAG’ from input file. Output: ‘ATGCGCCTGCGTCTGTACTAG True’ to the output file.
Upvotes: 0
Views: 64
Reputation: 4781
def check_sequence(sequence):
if len(sequence) % 3:
return False
if sequence[:3] != 'ATG':
return False
if sequence[-3:] != 'TAG':
return False
def process_file(input_file_path, output_file_path):
with open(input_file_path) as input_file:
with open(output_file_path, 'w') as output_file:
for map(str.rstrip, input_file):
output_file.write(line)
output_file.write(' ')
output_file.write(str(check_sequence(line)))
output_file.write('\n')
Upvotes: 3