Question: I need to write a python code. These are the instructions: Write a module, complement.py, with a function, complement, that returns the complement of a

I need to write a python code. These are the instructions:

"Write a module, complement.py, with a function, complement, that returns the complement of a DNA string. Also provide a function, revComplement that takes a DNA sequence as string input and returns the reverse complement of the sequence as a string. Recall that the valid alphabet is {A, C, T, G} and that A-T and G-C are complements. A reverse complement is found by reversing the input string and replacing every nucleotide with its complement. This means that your revComplement method should use your complement method internally rather than duplicating code. Your methods should do appropriate error checking and return an error message as appropriate. Test your functions with input from the user. For example, if your input is ACTG, your complement should be TGAC and your reverse complement should be CAGT."

This is what I have so far but my understanding of functions is severely limited and this is not including the reverse complement function yet bc I was trying to just get the complement one done first:

def complement(dna): complement_dna = {'A':'T','C':'G','G':'C','T':'A'} #convert to uppercase dna = dna.upper() bases = list(dna) letters = '' for x in bases: if x in complement_dna: letters = letters + dna[x] return ''.join(letters) dna = str(input("Enter the DNA string: ")) print("The complement is",complement(dna),".")

Of course, my code can be completely ignored if it is not on the right track what so ever. Any help would be appreciated!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!