That is, if given the sequence GGCCAATT, the program would return AATTGGCC? And the program must also work regardless of whitespace (spaces or tabs), case, and line breaks.
Asked
Active
Viewed 70 times
0
-
I think this [post](https://stackoverflow.com/questions/25188968/reverse-complement-of-dna-strand-using-python) answers your question – rachelyw Sep 28 '21 at 18:45
3 Answers
0
Assuming the sequence is a string replace
should do the trick:
sequence = 'GGCCAATT'
swap_A_G = sequence.replace('G', 'X').replace('A', 'G').replace('X', 'A')
swap_T_C = swap_A_G.replace('T', 'X').replace('C', 'T').replace('X', 'C')
It's ugly, but stringmethods are pretty fast.

mapf
- 1,906
- 1
- 14
- 40
0
Try this:
import re
my_dna='G g \t C cA\n A t T'
def my_func(dna_seq):
Output=(re.sub('\s*','', dna_seq)[4:]+re.sub('\s*','', dna_seq)[:4]).upper()
return Output
my_dna:
print(my_dna)
G g C cA
A t T
Output:
my_func(my_dna)
'AATTGGCC'

j__carlson
- 1,346
- 3
- 12
- 20
0
If you are trying to deal with dna sequencing Biopython is a module in python you are searching for. you can easily get the reverse complement as follows.
from Bio.Seq import Seq
seq=Seq('GGCCAATT')
dna=seq.reverse_complement()
print(dna)//AATTGGCC

Nishani Kasineshan
- 632
- 6
- 14