*这是一个简短的介绍,具体问题在最后一段用粗体字表示。在
我正在尝试生成所有具有给定Hamming距离的字符串,以有效地解决生物信息分配问题。在
我们的想法是,给定一个字符串(即'acgttgcatcgcatgagct')、要搜索的单词的长度(即4)以及在字符串中搜索该单词时可接受的不匹配(即1),返回最频繁的单词或“变种”单词。在
明确地说,给定字符串中长度为4的单词可以是(在“[]”之间):
[ACGT]TGCATGTCGCATGATGCATGAGAGCT #ACGT
这个
^{pr2}$或者这个
ACGTTGCATGTCGCATGATGCATGAG[AGCT] #AGCT
我所做的是(它非常低效,而且当单词需要有10个字符时非常慢)在给定的距离内生成所有可能的单词:
itertools.imap(''.join, itertools.product('ATCG', repeat=wordSize))
然后搜索并比较给定字符串中的每个单词,如果生成的单词(或其变体)出现在循环中:
wordFromString = givenString[i:i+wordSize]
mismatches = sum(ch1 != ch2 for ch1, ch2 in zip(wordFromString, generatedWord))
if mismatches <= d:
#count that generated word in a list for future use
#(only need the most repeated)
我想做的是,不是生成所有可能的单词,而是只生成出现在给定字符串中的单词的突变,具有给定数量的不匹配,换句话说,给定一个Hamming距离和一个单词,返回具有该距离(或更少)的所有可能的变异单词,然后使用它们进行搜索给定的字符串。在
我希望我是清楚的。谢谢您。在
设给定的汉明距离为D,设w为“word”子串。从w,您可以通过深度限制depth-first search生成距离≤D的所有单词:
(这绝不会很快,但可能会给人以启发。)
如果我正确地理解了你的问题,你想确定基因组中得分最高的k-mers。k-mer的得分是它在基因组中出现的次数加上汉明距离小于
m
的任何k-mer在基因组中出现的次数。请注意,这假设您只对出现在您的基因组中的k-mer感兴趣(正如@j_random_hacker所指出的)。在您可以通过四个基本步骤来解决此问题:
G
中出现的次数。在K1
,K2
),如果K1
和{m
,则增加它们的计数。在max
k-mer及其计数。在下面是Python代码示例:
此函数生成汉明距离小于或等于给定数字的单词的所有突变。它是相对有效的,并且不检查无效的单词。然而,有效突变可以出现多次。如果希望每个元素都是唯一的,请使用集合。在
相关问题 更多 >
编程相关推荐