Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: type: apply: expected Function, got PyObject #51

Closed
diegozea opened this issue Dec 5, 2013 · 2 comments
Closed

ERROR: type: apply: expected Function, got PyObject #51

diegozea opened this issue Dec 5, 2013 · 2 comments

Comments

@diegozea
Copy link
Contributor

diegozea commented Dec 5, 2013

What is wrong here?

In Python:

>>> import Bio.pairwise2 as py_aln
>>> import Bio.SubsMat.MatrixInfo as py_mat
>>> py_aln.align.globalds
<Bio.pairwise2.alignment_function instance at 0x7f0db3da7998>
>>> py_aln.align.globalds("AHHH","HHHA",py_mat.ident,-0.25,-0.5)
[('AHHH-', '-HHHA', 17.5, 0, 5)]

In Julia:

julia> using PyCall
julia> @pyimport Bio.pairwise2 as py_aln
julia> @pyimport Bio.SubsMat.MatrixInfo as py_mat
julia> py_aln.align[:globalds]
PyObject <Bio.pairwise2.alignment_function instance at 0xaf48560>
julia> py_aln.align[:globalds]("AHHH","HHHA",py_mat.ident,-0.25,-0.5)
ERROR: type: apply: expected Function, got PyObject
@diegozea
Copy link
Contributor Author

diegozea commented Dec 5, 2013

PyObject can be converted to Function. This works :) I don't close the issue because maybe is a real issue...

julia> a = py_aln.align[:globalds]
PyObject <Bio.pairwise2.alignment_function instance at 0xaf48680>

julia> aa = convert(Function,a)
fn (generic function with 1 method)

julia> aa("AHHH","HHHA",py_mat.ident,-0.25,-0.5)
1-element Array{Any,1}:
 ("AHHH-","-HHHA",17.5,0,5)

@stevengj
Copy link
Member

stevengj commented Dec 5, 2013

You can also call pycall(a, PyAny, "AHHH","HHHA",py_mat.ident,-0.25,-0.5).

The problem is that PyCall is not automatically able to detect that alignment_function is a function type (and Julia doesn't allow one to overload apply (JuliaLang/julia#2403), because alignment_function is a BioPython-specific type that is not a subclass of types.FunctionType. I could check whether it is callable, but the problem is that a lot of objects are callable and I don't necessarily want to autoconvert all callable objects into opaque anonymous functions.

@stevengj stevengj closed this as completed Dec 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants