bcgsc / btllib

Bioinformatics Technology Lab common code library
Other
21 stars 5 forks source link

SWIG seems to ignore Python constructors with std::vector<std::string> parameters #48

Open parham-k opened 2 years ago

parham-k commented 2 years ago

Python wrapper tests on branch python-wrapper-tests are failing due to a TypeError when passing a list of strings in Python to a std::vector<std::string> parameter in C++. For example, instantiating a SeedNtHash with btllib.SeedNtHash("AGCTCAGATC", ["11011"], 1, len(seed[0])) raises:

Traceback (most recent call last):
  File "/Users/runner/work/1/s/tests/test_wrappers.py", line 54, in test_rolling
    nthash = btllib.SeedNtHash(seq, seed, 1, len(seed[0]))
TypeError: in method 'new_SeedNtHash', argument 2 of type 'std::vector< btllib::SpacedSeed,std::allocator< btllib::SpacedSeed > > const &'
Additional information:
Wrong number or type of arguments for overloaded function 'new_SeedNtHash'.
  Possible C/C++ prototypes are:
    btllib::SeedNtHash::SeedNtHash(std::string,std::vector< btllib::SpacedSeed,std::allocator< btllib::SpacedSeed > > const &,unsigned int,unsigned int,size_t)
    btllib::SeedNtHash::SeedNtHash(std::string,std::vector< btllib::SpacedSeed,std::allocator< btllib::SpacedSeed > > const &,unsigned int,unsigned int)

Maybe SWIG is not aware of a vector-of-strings type, in spite of having %template(VectorString) std::vector<std::string>;, %include <std_vector.i>, and %include <stl.i> in btllib.i and extra_common.i.

vlad0x00 commented 2 years ago

It looks like SWIG is trying to call the constructor that accepts vector of SpacedSeed, which is a vector of unsigned.

On this line: https://github.com/bcgsc/btllib/blob/master/wrappers/extra_common.i#L88 The SeedNtHash constructor is ignored, so perhaps try playing around with removing lines that ignore constructors. I vaguely remember adding those to remove warnings.