我有这个rev_comp()
功能
>>> def rev_comp(sequence):
... def reverse(s):
... letters = list(s)
... letters.reverse()
... return ''.join(letters)
... def complement(s):
... basecomplement = {'A': 'T', 'C': 'G', 'T': 'A', 'G': 'C', 'a': 't', 'c': 'g', 't': 'a', 'g': 'c'}
... letters = list(s)
... letters = [basecomplement[base] for base in letters]
... return ''.join(letters)
... reverse(sequence)
... complement(sequence)
... return sequence
...
exon 是我想要反转和赞美的字符串。
本质上它应该将外显子反转为' gtacgtgtacgt
',然后替换以下每个实例:
g -> c, t -> a, c -> g, and a ->t
rev_comp(exon)
应该返回 '<code>catgcacatgca'</p>
>>> exon = "tgcatgtgcatg"
>>> rev_comp(exon)
'tgcatgtgcatg'
我用 pdb 运行它,它吐出了所有这些:
>>> pdb.run(rev_comp(exon))
> <string>(1)<module>()->None
(Pdb) n
NameError: "name 'tgcatgtgcatg' is not defined"
> <string>(1)<module>()->None
(Pdb) n
--Return--
> <string>(1)<module>()->None
(Pdb) >>> def rev_comp(sequence):
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... def reverse(s):
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... letters = list(s)
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... letters.reverse()
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... return ''.join(letters)
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... def complement(s):
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... basecomplement = {'A': 'T', 'C': 'G', 'T': 'A', 'G': 'C', 'a': 't', 'c': 'g', 't': 'a', 'g': 'c'}
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... letters = list(s)
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... letters = [basecomplement[base] for base in letters]
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... return ''.join(letters)
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... reverse(sequence)
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... complement(sequence)
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ... return sequence
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) ...
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) >>> exon = "tgcatgtgcatg"
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) >>> rev_comp(exon)
*** SyntaxError: invalid syntax (<stdin>, line 1)
(Pdb) 'tgcatgtgcatg'
'tgcatgtgcatg'
(Pdb) n
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/pdb.py", line 1238, in run
Pdb().run(statement, globals, locals)
File "/usr/lib/python2.7/bdb.py", line 387, in run
exec cmd in globals, locals
File "<string>", line 1, in <module>
NameError: name 'tgcatgtgcatg' is not defined
这对我来说意义不大。
谁能帮我弄清楚为什么它认为我传入的序列没有定义?