2017-04-08 55 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版本。 –