Write a Python script that computes the complement
of a DNA sequence. In other words, your script should convert all
A's to T's, C's to G's, G's to C's, and T's to A's.
The input is one sequence in FASTA format in a file called "dna.txt".
For example if the file contains
>human
ACCGT
then the output of the program should be TGGCA. Note that your program should work for
any sequence in this format and not just the given example.
----------------------------------------------------------
ive been trying to figure out how to do this, and its really starting to bother me. i cant figure out what code to write to input ACCGT and receive an output of TGGCA. this is not a code to reverse the input, i need to tell the program to look for A's and replace them with T's and replace C's with G's. this is what ive tried so far, but still havent gotten it
of a DNA sequence. In other words, your script should convert all
A's to T's, C's to G's, G's to C's, and T's to A's.
The input is one sequence in FASTA format in a file called "dna.txt".
For example if the file contains
>human
ACCGT
then the output of the program should be TGGCA. Note that your program should work for
any sequence in this format and not just the given example.
----------------------------------------------------------
ive been trying to figure out how to do this, and its really starting to bother me. i cant figure out what code to write to input ACCGT and receive an output of TGGCA. this is not a code to reverse the input, i need to tell the program to look for A's and replace them with T's and replace C's with G's. this is what ive tried so far, but still havent gotten it
Code:
with open("/Users/homemac/classes/bnfo135/dna.txt", "r") as myfile: seq = myfile.readlines() str(seq) str.replace("A", "T") str.replace("C", "G") print(seq) "['>human\\n', 'ACCGT\\n']" Traceback (most recent call last): File "<pyshell#8>", line 4, in <module> str.replace("A", "T") TypeError: replace() takes at least 2 arguments (1 given) >>> with open("/Users/homemac/classes/bnfo135/dna.txt", "r") as myfile: seq = myfile.readlines() str(seq) str.replace("A", "T" + "C","G") print(seq) "['>human\\n', 'ACCGT\\n']" 'A' ['>human\n', 'ACCGT\n'] >>> with open("/Users/homemac/classes/bnfo135/dna.txt", "r") as myfile: seq = myfile.readlines() str(seq) str.replace("A", "T" + "C","G") print(str()) "['>human\\n', 'ACCGT\\n']" 'A'
Comment