forked from justinbois/bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
na_utils.py
50 lines (38 loc) · 958 Bytes
/
na_utils.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
"""
Utilities for parsing nucleic acid sequences.
"""
def rna(seq):
"""
Convert a DNA sequence to RNA.
"""
# Determine if original sequence was uppercase
seq_upper = seq.isupper()
# Convert to lowercase
seq = seq.lower()
# Swap out 't' for 'u'
seq = seq.replace('t', 'u')
# Return upper or lower case RNA sequence
if seq_upper:
return seq.upper()
else:
return seq
def reverse_rna_complement(seq):
"""
Convert a DNA sequence into its reverse complement as RNA.
"""
# Determine if original was uppercase
seq_upper = seq.isupper()
# Reverse sequence
seq = seq[::-1]
# Convert to upper
seq = seq.upper()
# Compute complement
seq = seq.replace('A', 'u')
seq = seq.replace('T', 'a')
seq = seq.replace('G', 'c')
seq = seq.replace('C', 'g')
# Return result
if seq_upper:
return seq.upper()
else:
return seq