Compile kent source as dynamic library: Difference between revisions

From genomewiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:
   gcc -shared -o kent.so *.o font/*.o -lz -lpng
   gcc -shared -o kent.so *.o font/*.o -lz -lpng


Now you can do this to generate a python stub (wrapper) for any kent source library:
Now you can create a stub for all functions in the kent source library:
   ctypesgen.py ../inc/psl.h -lkent.so -o psl.py
  python --version # make sure we have python >2.5 installed, usually the case except old Redhat versions
  pip install ctypesgen
   ctypesgen.py ../inc/*.h -lkent.so -o kent.py
    
    
And then call kent source functions in your python script:
And then call kent source functions in your python script:
   import psl
   import kent
   p = psl.pslLoadAll("test.psl")
   p = kent.pslLoadAll("test.psl")
   print p.contents.blockCount
   print p.contents.blockCount
  kent.freeMem(p) # remember that all objects we get back have to be freed, these are normal C structs, not python objects


Remember to specify the dependencies when you create these stubs, so for pslTransMap.h you need psl.h. Maybe easier to specify all .h files?
Most functions return pointers to structs, not data directly, so you will usually have to use the .contents attribute to get the data.
  ctypesgen.py ~/kent/src/inc/*.h -lkent.so -o pslTransMap.py -I ~/kent/src/inc/ -I ~/kent/src/hg/inc

Latest revision as of 20:31, 20 May 2013

To run kent src functions from python, you need to compile the tree with -fPIC. It's easier to deactivate the various libraries:

 cd src/lib
 make USE_SAMTABIX=0 USE_TABIX=0 USE_BAM=0 CFLAGS=-fPIC USE_SSL=0
 gcc -shared -o kent.so *.o font/*.o -lz -lpng

Now you can create a stub for all functions in the kent source library:

 python --version # make sure we have python >2.5 installed, usually the case except old Redhat versions
 pip install ctypesgen
 ctypesgen.py ../inc/*.h -lkent.so -o kent.py
 

And then call kent source functions in your python script:

 import kent
 p = kent.pslLoadAll("test.psl")
 print p.contents.blockCount
 kent.freeMem(p) # remember that all objects we get back have to be freed, these are normal C structs, not python objects

Most functions return pointers to structs, not data directly, so you will usually have to use the .contents attribute to get the data.