python - Key error in dna complement -
python - Key error in dna complement -
import string import os,sys file=open("c:\python27\\new text document.txt",'r')\ seq =file.readlines() basecomplement = {'a': 't', 'c': 'g', 'g': 'c', 't': 'a'} def translate(seq): aaseq = [] str in seq: aaseq.append(basecomplement[str]) homecoming aaseq frame in range(1): rseqn= (''.join(item.split('|')[0] item in translate(seq[frame:]))) rseqn = rseqn[::-1] print(rseqn) print(seq)
error here file
"c:\users\ram\desktop\pythonhw\dnacomp.py", line 13, in <module> rseqn= (''.join(item.split('|')[0] item in translate(seq[frame:]))) file "c:\users\ram\desktop\pythonhw\dnacomp.py", line 10, in translate aaseq.append(basecomplement[str]) keyerror: 'agtctggcataccagtacagactatca'
if utilize simple string getting sequence tried read file input shows next error
if understand trying at
def translate(seq): basecomplement = {'a': 't', 'c': 'g', 'g': 'c', 't': 'a'} homecoming ''.join(basecomplement[letter] letter in seq)
testing
s = 'atcggcataatac' >>> translate(s) 'tagccgtattatg'
for translating file, like
with open('file.txt', 'r') f: line in f: print(translate(line))
python python-2.7 python-3.x bioinformatics dna-sequence
Comments
Post a Comment