""" CSCI146 Test Project 1 Name: Section: """ # TODO: Implement your functions here def read_fasta(filename): """ Read a single DNA sequence from a FASTA-formatted file For example, to read the sequence from a file named "X73525.fasta.txt" >>> sequence = read_fasta("X73525.fasta.txt") Args: filename: Filename as a string Returns: Upper case DNA sequence as a string """ with open(filename, "r") as file: # Read (and ignore) header line header = file.readline() # Read sequence lines sequence = "" for line in file: sequence += line.strip() return sequence.upper() def filter_orfs(orfs, min_length): """ Filter ORFs to have a minimum length Args: orfs: List of candidate ORF sequences min_length: Minimum length for an ORF Returns: A new list containing only ORF strings longer than min_length bases """ filtered_orfs = [] for orf in orfs: if len(orf) > min_length: filtered_orfs.append(orf) return filtered_orfs def write_fasta(filename, orfs): """ Write list of ORFs to a FASTA formatted text file. For example, to save a list of orfs assigned to the variable my_orfs to a file named "genes.txt" >>> write_fasta("genes.txt", my_orfs) Args: filename: Filename as a string. Note that any existing file with this name will be overwritten. orfs: List of ORF sequences to write to the file """ with open(filename, "w") as file: for i in range(len(orfs)): # A FASTA entry is a header line that begins with a '>', and then the sequence on the next line(s) print(">seq" + str(i), file=file) print(orfs[i], file=file) if __name__ == "__main__": # If you want perform the steps for creating genes.txt as part of your # program, implement that code here. It will run every time you click the # green arrow, but will be ignored by Gradescope. pass