jeffdaily / parasail-python

Python bindings for the parasail C library.
Other
87 stars 17 forks source link

PSSM support in Python #69

Open shenker opened 1 year ago

shenker commented 1 year ago

Can you align a PSSM using parasail-python?

Thanks!

jeffdaily commented 1 year ago

You can with C parasail library. I hadn't updated the python bindings yet. I started toying with it, but even the C API wasn't pretty. For the C library, it was important to me to keep the function signature the same whether it was a normal substitution matrix versus pssm. Keeping the signature the same allowed me to not need to create pssm-specific APIs and essentially double the number of functions. So in the C library, you pass NULL for the first sequence since it is encapsulated by the pssm matrix. And to make it worse, if you want to use any of the "stats" functions, you still have to pass in a representative sequence for s1. It's awkward and clunky but it works.

I don't know how to make the python bindings better or more pythonic. Suddenly the first argument to the alignment functions becomes optional.

# the current alignment signature
def sw(s1, s2, open, extend, matrix):
    pass

# keeping names the same, but allowing s1 to be optional
def sw(*args):
   if len(args) == 4:
       pass  # call PSSM
   elif len(args) == 5:
       pass  # call normal
   else:
       raise TypeError("Wrong number of arguments!")

# or going the clunk way I did it in C
def sw(s1, s2, open, extend, matrix):
    # s1 is None, and make this okay
    # currently, the wrapper just passes s1 and len(s1) down to the C API, 
    # so I'd need to add a check for None

Your thoughts? Help me design the python PSSM API.