【发布时间】:2015-07-02 18:16:59
【问题描述】:
所以我有一个氨基酸文件,我正在尝试阅读 mdvfmkglskakegvvaaaektkqgvaeaagktkegvlyvgsktkegvvhgvatvaektk
eqvtnvggavvtgvtavaqktvegagsiaaatgfvkkdqlgkneegapqegiledmpvdp
dneayempseegyqdyepea
我有一个称为氨基酸的大写字母列表。问题是我无法阅读序列,因为字母是小写的。我一直在尝试将其设为大写。读取文件没有问题,我认为我已成功将其内容转换为字符串(但也许我没有?)。
aminoacids = ['A','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y']
content1 = fh.readline() #first line, which is not the sequence
#print content1
charline1 = len(content1)-1 #number of characters in the first line
#print charline1
contentall = fh.readlines() #each line is converted into a string and put into a list
#print contentall
numlines = len(contentall) #number of elements in list = number of lines, not the first one
#print numlines
contentjoined = ''.join(contentall) #list elements are combined, but this includes new lines as characters
contentjoined = contentjoined.translate(None, "\n")
contentjoined = contentjoined.translate(None,''.join([i for i in contentjoined if i not in aminoacids]))
contentjoined = contentjoined.upper()
print contentjoined
numaa = len(contentjoined)
print numaa #this shouldn't be zero but it is
为什么这不起作用?我能做些什么来修复它?我现在在with 中……以前这不是问题,但现在是吗? Numaa 是 0,而它不应该是。我意识到我可以在列表中添加小写字母,但应该有一种更“pythonic”的方式来解决这个问题。
【问题讨论】: