-
Notifications
You must be signed in to change notification settings - Fork 2
/
BA1_C - find reverse complement of string.py
54 lines (37 loc) · 1.3 KB
/
BA1_C - find reverse complement of string.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 19 19:13:56 2019
@author: jasonmoggridge
Find the Reverse Complement of a String
←→:
In DNA strings, symbols 'A' and 'T' are complements of each other,
as are 'C' and 'G'. Given a nucleotide p, we denote its complementary
nucleotide as p. The reverse complement of a DNA string (Pattern = p1…pn)
is the string Pattern = pn … p1 formed by taking the complement of each
nucleotide in Pattern, then reversing the resulting string.
For example, the reverse complement of Pattern = "GTCA" is Pattern = "TGAC".
Reverse Complement Problem
Find the reverse complement of a DNA string.
Given: A DNA string Pattern.
Return: Pattern, the reverse complement of Pattern.
Sample Dataset
AAAACCCGGT
Sample Output
ACCGGGTTTT
"""
# Reads seqs -> and builds reverse complement rc <-backwards from
def ReverseComp(read):
complement = {'A':'T','C':'G','G':'C','T':'A'}
read_rc = ''
for base in read:
read_rc = complement[base] + read_rc
return read_rc
###
print("\nInput your DNA string:\n\t")
DNA = input()
RC = ReverseComp(DNA)
print('\n\nReverse Complement of input DNA:\n\n', RC)
with open("/Users/jasonmoggridge/Desktop/rosalind_ba1c_out.txt",'w') as op:
op.write(RC)
op.close()