Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
pyOpenMS (Python bindings)

Introduction

PyOpenMS offers Python bindings to a large part of the OpenMS API.

Build Instructions

In order to configure and build pyOpenMS successfully, you will need to install the following :

  1. Install python (preferably, 2.7 but it may run also run with Python 2.6)

  2. On windows: you need the 64 bit C++ compiler from Visual Studio 2008. This is important, else you get a different clib than python 2.7 is built with, and pyopenms will crash on import.

  3. Install setuptools, see: https://pypi.python.org/pypi/setuptools

  4. Install pip and using it, install other required Python modules

    $ easy_install pip
    $ pip install autowrap
    $ pip install nose

    If Cython doesn't get installed, install it with

    $ easy_install cython

    Note that when using pip without root permissions, you have to add a path prefix: –install-option="--prefix=/path/to/local/python/"

  5. Install numpy:

  6. Configure OpenMS with pyOpenMS: execute cmake as usual, but with parameters "-D PYOPENMS=ON".

    On windows add: "-D CMAKE_BUILD_TYPE=Release" as the standard python27.dll is built in release mode.

  7. Build pyOpenMS (now there should be pyopenms specific build targets):

    $ make pyopenms

    on linux: ensure that the libOpenMS.so is in your $LD_LIBRARY_PATH (it needs to be accessible for Python)

  8. Run the Python specific tests to make sure that everything went well

    $ cd pyOpenMS
    $ run_nose.py

    run mem leak test:

    $ run_memleaks.py

  9. Optionally: if you want to install locally:

    $ python setup.py install

    If you want to build Python installers:

    $ make pyopenms_bdist_egg

    or

    $ make pyopenms_bdist

    you find the built installer files in pyOpenMS/dist

Wrapping Workflow and wrapping new Classes

How pyOpenMS wraps Python classes

General concept of how the wrapping is done:

Maintaining existing wrappers: If the C++ API is changed, then pyOpenMS will not build any more. Thus, find the corresponding file in the pyOpenMS/pxds/ folder and adjust the function declaration accordingly.

How to wrap new classes

To wrap a new OpenMS class: Create a new "pxd" file in the folder "./pxds". As a small example, look at the CVTerm.pxd to get you started. Start with the following structure:

from xxx cimport *
cdef extern from "<OpenMS/path/to/header.h>" namespace "OpenMS":
cdef cppclass ClassName(DefaultParamHandler):
# wrap-inherits:
# DefaultParamHandler
ClassName() nogil except +
ClassName(ClassName) nogil except +

Further considerations and limitations:

These hints can be given to autowrap (also check the autowrap documentation):

Wrapping code yourself in ./addons

Not all code can be wrapped automatically (yet). Place a file with the same (!) name in the addons folder (e.g. myClass.px in pxds/ and myClass.pyx in addons) and leave two lines empty on the top (this is important). Start with 4 spaces of indent and write your additional wrapper functions, adding a wrap-ignore comment to the pxd file. For some examples, look into the addons folder:

Make sure that you _always_ declare your objects (all C++ and all Cython objects need to be declared) using cdef Type name. Otherwise you get "Cannot convert ... to Python object" errors.


OpenMS / TOPP release 2.0.0 Documentation generated on Tue Nov 1 2016 16:34:46 using doxygen 1.8.11