2017-04-08 53 views
0

當我運行下面的腳本時,輸出被分成單個字符。任何想法爲什麼?它看起來像第二個參數分成單個字符。如何使用biopython配對來對齊單詞列表

我想對齊單詞序列。

我會有很多單詞,因此無法將它們映射到僅字母。

from Bio.Seq import Seq 
from Bio.pairwise2 import format_alignment 


fruits = ["orange","pear", "apple","pear","orange"] 
fruits1 = ["pear","apple"] 


from Bio import pairwise2 
alignments = pairwise2.align.localms(fruits,fruits1,2,-1,-0.5,-0.1, gap_char=["-"]) 

for a in alignments: 
    print(format_alignment(*a)) 

輸出:

['orange', 'r', 'a', 'e', 'p', 'e', 'l', 'p', 'p', 'a', 'pear', 'orange'] 
||||||||| 
['-', 'r', 'a', 'e', 'p', 'e', 'l', 'p', 'p', 'a', '-', '-'] 
    Score=4 
+0

對不起,你的原則的例子應該工作。 '''pairwise2'''接受列表作爲輸入。很明顯,我在'''pairwise2'''的最後一次更新期間弄壞了一些東西。如果您可以訪問Biopython 1.67,那麼您可以在那裏嘗試一下嗎? – Markus

回答

0

你傳遞一個列表localms一個希望將stringSeq對象,也gap_char應該是一個字符串不是列表。

試試下面的代碼片段:

import Bio.pairwise2 as pairwise2 
fruits = ["orange", "pear", "apple", "pear", "orange"] 
fruits1 = ["pear", "apple"] 
for f0 in fruits: 
    for f1 in fruits1: 
     print('Aligning {0} and {1}'.format(f0, f1)) 
     alignments = pairwise2.align.localms(f0, f1, 2, -1, -0.5, -0.1, gap_char="-") 
     for a in alignments: 
      print(pairwise2.format_alignment(*a)) 

輸出

Aligning orange and pear 
orange 
    | 
pear-- 
    Score=2 

Aligning orange and apple 
orange 
    | 
-apple 
    Score=2 

orange- 
    | 
--apple 
    Score=2 

Aligning pear and pear 
pear 
|||| 
pear 
    Score=8 

[...]

+0

不,'''pairwise2'''也應該接受列表。原因是你可以使用帶有多個字母的包含符號的序列。這可能會有幫助,如果你有修改鹼基或氨基酸,就像在這個SO問題(http://stackoverflow.com/questions/36142371/nucleotides-separator-in-the-pairwise-sequence-alignment-bio-python/36158674 #36158674)。不幸的是,這個功能在Biopython 1.68和1.69中被破壞了。 – Markus

+0

@Markus:謝謝你的澄清!看來我正在使用你提到的一個BioPython版本。 –