<p>Martineau可能对特定领域的语言有正确的想法。我没有这方面的经验,但这是我在半小时内想到的。你知道吗</p>
<p>我没有运行,调试或测试这个,但如果你有任何问题,让我知道。这段代码还假设片段长度不够长,以至于在内存中保存它们时出现问题。如果这个假设不成立,这种方法就不会非常有效。你知道吗</p>
<p>我也懒得设计碎片字典。它不应该是一个全局变量,整个代码应该在一个类中。你知道吗</p>
<pre><code>def head(seq, count):
return seq[count:]
def tail(seq, count):
return seq[:count]
def reverse(nt):
if nt in 'Gg':
return 'C'
elif nt in 'Cc':
return 'G'
elif nt in 'Aa':
return 'T'
elift nt in 'Tt':
return 'A'
raise Exception('invalid nucleotide')
def complement(seq):
return (reverse(i) for i in seq)
def identity(seq):
return seq
fragments = {}
def register(fragment, name):
if name not in fragments:
fragments[name] = fragment
else:
raise Exception('a fragment of that name is already registered!')
def make_combination(portions):
""" Each entry in portions should be a tuple consisting of:
(sequence name, count, accessor function, complement function)"""
output = []
for entry in portions:
name, count, select, order = entry
section = order(select(fragments[name], count))
output.append(str(section))
# return a string, not a list
return ''.join(output)
def example()
a = 'gattaca'
b = 'tagacat'
c = 'gagatac'
register(a, 'a')
register(b, 'b')
register(c, 'c')
# the last 20 nucleotides (n.t.) of C with the first 40 n.t. of A
first = (('c', 20, tail, identity),
('a', 40, head, identity))
# RC of the first 20 n.t. of B with the RC of the last n.t. of A,
second = (('b', 20, head, complement),
('a', 1, tail, identity))
</code></pre>