kcleal / pywfa

Python wrapper for wavefront alignment using WFA2-lib
MIT License
35 stars 2 forks source link

cigar_print_pretty to print to string instead of stdout #1

Closed wongs2 closed 1 year ago

wongs2 commented 2 years ago

It will be more convenient to allow the option for cigar_print_pretty to print to string instead of stdout.

kcleal commented 2 years ago

Hi @wongs2

I agree. Unfortunately, the original WFA2-lib function only has an option to write to a file (rather than send to stdout), so Ive added that functionality instead. You can send the output to a file using:

a.cigar_print_pretty("hello.txt")

Hope that helps,

Kez

wongs2 commented 2 years ago

Thanks. Is it possible to have the call return the alignment as a string, in addition to the stdout?

Midnighter commented 1 year ago

I run into all the same issues it seems. A method to return the gapped pattern and likewise for the text would be extremely helpful. I can monkey patch that for now but it seems worth having in the package.

kcleal commented 1 year ago

I have added a new property to the results object, so the pretty string can now be accessed:

from pywfa.align import WavefrontAligner

pattern = "TCTTTACTCGCGCGTTGGAGAAATACAATAGT"
text =    "TCTATACTGCGCGTTTGGAGAAATAAAATAGT"
a = WavefrontAligner(pattern)

res = a(text)

print(res.pretty)

>>> 
    3M1X4M1D7M1I9M1X6M      ALIGNMENT
    1X1D1I1X      ALIGNMENT.COMPACT
          PATTERN    TCTTTACTCGCGCGTT-GGAGAAATACAATAGT
                     |||*|||| ||||||| |||||||||*||||||
          TEXT       TCTATACT-GCGCGTTTGGAGAAATAAAATAGT