1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2009-2012 Sascha Steinbiss <steinbiss@zbh.uni-hamburg.de>
# Copyright (c) 2009-2012 Center for Bioinformatics, University of Hamburg
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
from gt.dlload import gtlib
from gt.extended.node_visitor import NodeVisitor
from ctypes import CFUNCTYPE, c_void_p, c_int, POINTER
from gt.extended.feature_node import FeatureNode
from gt.extended.region_node import RegionNode
from gt.extended.sequence_node import SequenceNode
from gt.extended.comment_node import CommentNode
from gt.extended.eof_node import EOFNode
from gt.extended.meta_node import MetaNode
from gt.core.error import Error, GTError
CommentNodeFunc = CFUNCTYPE(c_int, c_void_p, c_void_p)
FeatureNodeFunc = CFUNCTYPE(c_int, c_void_p, c_void_p)
RegionNodeFunc = CFUNCTYPE(c_int, c_void_p, c_void_p)
SequenceNodeFunc = CFUNCTYPE(c_int, c_void_p, c_void_p)
MetaNodeFunc = CFUNCTYPE(c_int, c_void_p, c_void_p)
EOFNodeFunc = CFUNCTYPE(c_int, c_void_p, c_void_p)
FreeFunc = CFUNCTYPE(c_void_p, c_void_p)
class CustomVisitor(NodeVisitor):
def __init__(self):
def feature_node_w(fn_p, err_p):
fn = FeatureNode.create_from_ptr(fn_p)
err = Error(err_p)
try:
try:
self.visit_feature_node(fn)
except AttributeError:
pass
return 0
except GTError:
import sys
errmsg = sys.exc_info()[1]
err.set(str(errmsg))
return -1
self.feature_node_cb = FeatureNodeFunc(feature_node_w)
def sequence_node_w(sn_p, err_p):
sn = SequenceNode.create_from_ptr(sn_p)
err = Error(err_p)
try:
try:
self.visit_sequence_node(sn)
except AttributeError:
pass
return 0
except GTError:
import sys
errmsg = sys.exc_info()[1]
err.set(str(errmsg))
return -1
self.sequence_node_cb = SequenceNodeFunc(sequence_node_w)
def region_node_w(rn_p, err_p):
rn = RegionNode.create_from_ptr(rn_p)
err = Error(err_p)
try:
try:
self.visit_region_node(rn)
except AttributeError:
pass
return 0
except GTError:
import sys
errmsg = sys.exc_info()[1]
err.set(str(errmsg))
return -1
self.region_node_cb = RegionNodeFunc(region_node_w)
def comment_node_w(cn_p, err_p):
cn = CommentNode.create_from_ptr(cn_p)
err = Error(err_p)
try:
try:
self.visit_comment_node(cn)
except AttributeError:
pass
return 0
except GTError:
import sys
errmsg = sys.exc_info()[1]
err.set(str(errmsg))
return -1
self.comment_node_cb = CommentNodeFunc(comment_node_w)
def eof_node_w(en_p, err_p):
en = EOFNode.create_from_ptr(en_p)
err = Error(err_p)
try:
try:
self.visit_eof_node(en)
except AttributeError:
pass
return 0
except GTError:
import sys
errmsg = sys.exc_info()[1]
err.set(str(errmsg))
return -1
self.eof_node_cb = EOFNodeFunc(eof_node_w)
def meta_node_w(mn_p, err_p):
mn = EOFNode.create_from_ptr(mn_p)
err = Error(err_p)
try:
try:
self.visit_meta_node(mn)
except AttributeError:
pass
return 0
except GTError:
import sys
errmsg = sys.exc_info()[1]
err.set(str(errmsg))
return -1
self.meta_node_cb = MetaNodeFunc(meta_node_w)
self.gv = gtlib.gt_script_wrapper_visitor_new(self.comment_node_cb,
self.feature_node_cb,
self.region_node_cb,
self.sequence_node_cb,
self.meta_node_cb,
self.eof_node_cb,
None)
self._as_parameter_ = self.gv
def register(cls, gtlib):
from ctypes import c_void_p
gtlib.gt_script_wrapper_visitor_new.argtypes = [c_void_p,
c_void_p, c_void_p, c_void_p, c_void_p,
c_void_p, c_void_p]
gtlib.gt_script_wrapper_visitor_new.restype = c_void_p
register = classmethod(register)
|