The code I'm writing is supposed to find all the open reading frames (orfs) of a genetic sequence on the forward and reverse complement strands of DNA. To make the reverse strand of DNA, I intended to use str.maketrans()
to map complementary bases to each other.
#!/usr/bin/env python3.3
import re
import sys
from argparse import ArgumentParser
pattern = re.compile(r'(?=(ATG(?:...)*?)(?=TAG|TGA|TAA))')
dna_seq = 'ATGACGGCTTGTTTCTTTTCTGTGGCTGCGTGA'
def find_orfs(dna_seq):
"""
finds all possible open reading frames (orfs)
:param dna_seq: str, dna sequence
:return: list, possible open reading frames
"""
r_comp = dna_seq[::-1].translate(str.maketrans("ATGC","TACG"))
return list(pattern.findall(dna) + pattern.findall(r_comp))
When I run this in the interpreter it works! It returns the correct answer:
['ATGACGGCTTGTTTCTTTTCTGTGGCTGCG']
When I run this as a script (version 3.3) I get AttributeError!
AttributeError: type object 'str' has no attribute 'maketrans'
But when I dir(str)
in the interpreter (version 3.3), I see maketrans! What gives!?
After reading about the change to bytes.maketrans()
, I tried this to no avail. What can I do to get the same functionality of maketrans()
in python3.3?