When I run the script below, output is getting split into single chars. Any idea why? It looks like the second argument gets split into single chars. I am trying to align the word sequences. I will have many words hence cannot map them to letters only.

Thx Ercan

    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))

Output:

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


BioPython allows for performing an alignment on sequences' symbols (not words). I can't think of any program that would do the words' alignment. I suggest you search the Web for Python modules/functions that perform string character alignments and then modify the existing code to handle words.

For example, I tweaked [some code from GitHub][1] to do local (*water*) and global (*needle*) alignments of words.

Filename: `alignment.py`:

<p>https://gist.github.com/aziele/6192a38862ce569fe1b9cbe377339fbe</p>

**Usage:**

    import alignment
    fruits1 = ["orange", "pear", "apple", "pear", "orange"]
    fruits2 = ["pear", "apple"]
    aln = alignment.needle(fruits1, fruits2)
    identity = aln[0]
    score = aln[1]
    print(identity, score)
    print(aln[2])
    print(aln[3])

Output:

    (0.4, 25)
    ['-', 'pear', 'apple', '-', '-']
    ['orange', 'pear', 'apple', 'pear', 'orange']
    


  [1]: https://github.com/alevchuk/pairwise-alignment-in-python/blob/master/alignment.py