UCSC BLAT输出python

2024-09-29 23:29:38 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法用Python从下面的BLAT结果中得到不匹配的位置号?在

00000001 taaaagatgaagtttctatcatccaaaaaatgggctacagaaacc 00000045
<<<<<<<< |||||||||||||||||||||||||||  |||||||||||||||| <<<<<<<<
41629392 taaaagatgaagtttctatcatccaaagtatgggctacagaaacc 41629348

我们可以看到,上面的输出有两个不匹配。我们可以用Python得到不匹配/变异的位置号吗。这也是它在源代码中的显示方式。所以我有点搞不清该怎么办。 非常感谢。在


Tags: 源代码变异办法blattaaaagatgaagtttctatcatccaaaaaatgggctacagaaacctaaaagatgaagtttctatcatccaaagtatgggctacagaaacc
1条回答
网友
1楼 · 发布于 2024-09-29 23:29:38

可以使用字符串的.find方法找到不匹配项。不匹配用空格('')表示,所以我们在blat输出的中间行中查找它。我个人不了解blat,所以我不确定输出是否总是以三元组行的形式出现,但是假设是这样,下面的函数将返回一个位置不匹配的列表,每个位置在顶部序列中表示为不匹配位置的元组,而在底部序列中则是相同的。在

blat_src = """00000001 taaaagatgaagtttctatcatccaaaaaatgggctacagaaacc 00000045
<<<<<<<< |||||||||||||||||||||||||||  |||||||||||||||| <<<<<<<<
41629392 taaaagatgaagtttctatcatccaaagtatgggctacagaaacc 41629348"""

def find_mismatch(blat):
    #break the blat input into lines
    lines = blat.split("\n")

    #give some firendly names to the different lines
    seq_a = lines[0]
    seq_b = lines[2]

    #We're not interested in the '<' and '>' so we strip them out with a slice
    matchstr = lines[1][9:-9]

    #Get the integer values of the starts of each sequence segment
    pos_a = int(seq_a[:8])
    pos_b = int(seq_b[:8])

    results = []

    #find the index of first space character, mmpos = mismatch position
    mmpos = matchstr.find(" ")
    #if a space exists (-1 if none found)
    while mmpos != -1:
        #the position of the mismatch is the start position of the
        #sequence plus the index within the segment
        results.append((posa+mmpos, posb+mmpos))
        #search the rest of the string (from mmpos+1 onwards)
        mmpos = matchstr.find(" ", mmpos+1)
    return results

print find_mismatch(blat_src)

产生

^{pr2}$

告诉我们位置28和29(根据顶部序列索引)或位置41629419和41629420(根据底部序列索引)不匹配。在

相关问题 更多 >

    热门问题