【发布时间】:2014-12-24 15:30:52
【问题描述】:
我正在尝试解决这个生物信息学问题:https://stepic.org/lesson/An-Explosion-of-Hidden-Messages-4/step/1?course=Bioinformatics-Algorithms-2&unit=8
具体问题在上面链接的第5个窗口,问题是:大肠杆菌基因组中有多少个不同的9-mers形成(500,3)-clumps? (换句话说,不要多次计算 9-mer。)
我的代码如下。这是错误的,我很想解释为什么,以及如何改进它(显然 O 效率很糟糕,但我几天前开始编写 Python ......)非常感谢!
genome = '' #insert e. Coli genome here
k = 4 #length of k-mer
L = 50 #size of sliding window
t = 3 #k-mer appears t times
counter = 0
Count = []
for i in range(0,len(genome)-L): #slide window down the genome
pattern = genome[i:i+k] #given this k-mer
for j in range(i,i+L): #calculate k-mer frequency in window of len(L)
if genome[j:j+k] == pattern:
counter = counter + 1
Count.append(counter)
counter = 0 #IMPORTANT: reset counter after each i
Clump = []
for i in range(0,len(Count)):
if Count[i] == t: #figure out the window that has k-mers of frequency t
Clump.append(i)
Output = []
for i in range(0,len(Clump)):
Output.append(genome[Clump[i]:Clump[i]+k])
print " ".join(list(set(Output))) #remove duplicates if a particular k-mer is found more than once
print len(Output)
print len(list(set(Output))) #total number of Clump(k,L,t)
【问题讨论】:
-
错误 403:未订阅课程的人无法使用问题链接。
-
什么是 (500,3)-团块?
-
你的代码有什么问题?错误信息? (然后复制它)或错误的输出? (然后复制它,以及预期的输出)
-
我看到很多索引、计数器和 for 循环。 Python 不是 Matlab 或 C。请查看 Python 教程!
-
对不起,这里是问题的解释:dropbox.com/s/qcb8mrc7fab2ra5/…
标签: python bioinformatics sliding-window