| 1 |
# This file contains an alternative implementation |
| 2 |
# to call samtools functions. These are direct calls. |
| 3 |
# Plus: less overhead |
| 4 |
# Minus: more trouble in maintaining |
| 5 |
|
| 6 |
#in csamtools.pxd |
| 7 |
# samtools toolkit functions |
| 8 |
ctypedef int (*pysam_samtools_f)(int argc, char *argv[]) |
| 9 |
|
| 10 |
int bam_taf2baf(int argc, char *argv[]) |
| 11 |
int bam_pileup(int argc, char *argv[]) |
| 12 |
int bam_merge(int argc, char *argv[]) |
| 13 |
int bam_index(int argc, char *argv[]) |
| 14 |
int bam_sort(int argc, char *argv[]) |
| 15 |
int bam_tview_main(int argc, char *argv[]) |
| 16 |
int bam_mating(int argc, char *argv[]) |
| 17 |
int bam_rmdup(int argc, char *argv[]) |
| 18 |
int bam_rmdupse(int argc, char *argv[]) |
| 19 |
int bam_flagstat(int argc, char *argv[]) |
| 20 |
int bam_fillmd(int argc, char *argv[]) |
| 21 |
int main_samview(int argc, char *argv[]) |
| 22 |
int main_import(int argc, char *argv[]) |
| 23 |
int faidx_main(int argc, char *argv[]) |
| 24 |
int glf3_view_main(int argc, char *argv[]) |
| 25 |
|
| 26 |
|
| 27 |
## Alternative code in csamtools.pyx |
| 28 |
cdef class SamtoolsWrapper: |
| 29 |
'''generic wrapper around samtools functions''' |
| 30 |
cdef pysam_samtools_f f |
| 31 |
|
| 32 |
def __init__(self): self.f = NULL |
| 33 |
|
| 34 |
def call(self, *args ): |
| 35 |
|
| 36 |
if self.f == NULL: raise NotImplementedError("invalid call to base class" ) |
| 37 |
|
| 38 |
cdef char ** cargs |
| 39 |
cdef int i, n, retval |
| 40 |
n = len(args) |
| 41 |
# allocate one more for first (dummy) argument (contains command) |
| 42 |
cargs = <char**>calloc( n+1, sizeof( char *) ) |
| 43 |
cargs[0] = "method" |
| 44 |
for i from 0 <= i < n: |
| 45 |
cargs[i+1] = args[i] |
| 46 |
for i from 0 <= i < n+1: |
| 47 |
print cargs[i] |
| 48 |
retval = self.f(n+1, cargs) |
| 49 |
free( cargs ) |
| 50 |
return retval |
| 51 |
|
| 52 |
cdef class SamtoolsWrapperImport( SamtoolsWrapper ): |
| 53 |
def __init__(self): self.f = main_import |
| 54 |
cdef class SamtoolsWrapperPileup( SamtoolsWrapper ): |
| 55 |
def __init__(self): self.f = bam_pileup |
| 56 |
cdef class SamtoolsWrapperMerge( SamtoolsWrapper ): |
| 57 |
def __init__(self): self.f = bam_merge |
| 58 |
cdef class SamtoolsWrapperSort( SamtoolsWrapper ): |
| 59 |
def __init__(self): self.f = bam_sort |
| 60 |
cdef class SamtoolsWrapperIndex( SamtoolsWrapper ): |
| 61 |
def __init__(self): self.f = bam_index |
| 62 |
cdef class SamtoolsWrapperFaidx( SamtoolsWrapper ): |
| 63 |
def __init__(self): self.f = faidx_main |
| 64 |
cdef class SamtoolsWrapperFixMate( SamtoolsWrapper ): |
| 65 |
def __init__(self): self.f = bam_mating |
| 66 |
cdef class SamtoolsWrapperRmDup( SamtoolsWrapper ): |
| 67 |
def __init__(self): self.f = bam_rmdup |
| 68 |
cdef class SamtoolsWrapperRmDupSe( SamtoolsWrapper ): |
| 69 |
def __init__(self): self.f = bam_rmdupse |
| 70 |
cdef class SamtoolsWrapperGlf3Viwen( SamtoolsWrapper ): |
| 71 |
def __init__(self): self.f = glf3_view_main |
| 72 |
cdef class SamtoolsWrapperFlagStat( SamtoolsWrapper ): |
| 73 |
def __init__(self): self.f = bam_flagstat |
| 74 |
cdef class SamtoolsWrapperFillMd( SamtoolsWrapper ): |
| 75 |
def __init__(self): self.f = bam_fillmd |
| 76 |
cdef class SamtoolsWrapperCalMd( SamtoolsWrapper ): |
| 77 |
def __init__(self): self.f = bam_fillmd |
| 78 |
|
| 79 |
automatic creation of these functions does not work |
| 80 |
due to pyrex/cython |
| 81 |
|
| 82 |
def sort( *args, **kwargs ): return SamtoolsWrapperSort().call(*args, **kwargs) |