Last change
on this file was
8848,
checked in by epruesse, 12 years ago
|
Added Python bindings using SWIG
Build and clean targets are "bindings" and "bindings_clean"; they
are not added to all and clean yet. The "test.py" shows a bit of
the python usage of the interface. You need to have swig installed,
of course.
The bindings are not build from arb_prot.h like the perl bindings.
Rather, ARB.i defines the exported functions. This is to make the
interface smaller and have an avenue of keeping it stable in case
the library interface needs to be changed. It also cuts down on
compile time a lot.
The idea is to eventually build the perl bindings with SWIG as well.
I haven't figured out how to provide the BIO:: module with the
ARB module yet, though, which would be required for backwards
compatability with pre-existing amc scripts.
|
File size:
1.3 KB
|
Line | |
---|
1 | %module ARB |
---|
2 | |
---|
3 | %exception open { |
---|
4 | $action |
---|
5 | if (!result) { |
---|
6 | PyErr_SetString(PyExc_Exception, await_error()); |
---|
7 | return NULL; |
---|
8 | } |
---|
9 | } |
---|
10 | |
---|
11 | %include ../ARB.i |
---|
12 | |
---|
13 | ########## Python side interface code ######## |
---|
14 | # |
---|
15 | # These are just some wrappers that make the ARB API more |
---|
16 | # easily accessible within the typical object oriented python |
---|
17 | # style |
---|
18 | |
---|
19 | %pythoncode %{ |
---|
20 | |
---|
21 | class Species(object): |
---|
22 | """Wraps GBDATA to make accesssing data fields easier""" |
---|
23 | def __init__(self, gbd): |
---|
24 | self.gbd=gbd |
---|
25 | def __getattr__(self, field): |
---|
26 | return read_as_string(self.gbd, field) |
---|
27 | |
---|
28 | class ArbDB(object): |
---|
29 | """Wraps "GBMAIN" """ |
---|
30 | def __init__(self, gbd): |
---|
31 | self.gbmain=gbd |
---|
32 | def close(self): |
---|
33 | return close(self.gbmain) |
---|
34 | def save_as(filename, mode="b"): |
---|
35 | return save_as(self.gbmain, filename, mode) |
---|
36 | def marked_species(self): |
---|
37 | """Iterates through all marked species""" |
---|
38 | curr = first_marked_species(self.gbmain) |
---|
39 | while curr: |
---|
40 | yield curr |
---|
41 | curr = next_marked_species(curr) |
---|
42 | def all_species(self): |
---|
43 | """Iterates through all species""" |
---|
44 | curr = first_species(self.gbmain) |
---|
45 | while curr: |
---|
46 | yield Species(curr) |
---|
47 | curr = next_species(curr) |
---|
48 | |
---|
49 | def open(filename, mode="rw"): |
---|
50 | return ArbDB(_ARB.open(filename, mode)) |
---|
51 | |
---|
52 | %} |
---|
53 | |
---|
54 | ######## End of Python side interface code ###### |
---|
55 | |
---|
Note: See
TracBrowser
for help on using the repository browser.