Exemplo n.º 1
0
 def to_str(self):
     err = Error()
     string = Str()
     if gtlib.gt_style_to_str(self.style, string, err) == 0:
         return str(string)
     else:
         gterror(err)
Exemplo n.º 2
0
 def add_gff3file(self, filename):
     err = Error()
     rval = gtlib.gt_feature_index_add_gff3file(self.fi,
                                                filename.encode('UTF-8'),
                                                err)
     if rval != 0:
         gterror(err)
Exemplo n.º 3
0
 def trackselector(block_ptr, string_ptr, data_ptr):
     b = Block(block_ptr)
     string = Str(string_ptr)
     ret = func(b)
     if not ret:
         gterror("Track selector callback function must return a string!")
     string.append_cstr(ret)
Exemplo n.º 4
0
 def to_file(self, filename):
     err = Error()
     rval = gtlib.gt_canvas_cairo_file_to_file(
         self.canvas,
         str(filename).encode('UTF-8'), err)
     if rval != 0:
         gterror(err)
Exemplo n.º 5
0
 def __init__(self):
     err = Error()
     ads = gtlib.gt_anno_db_gfflike_new()
     if ads == None:
         gterror(err)
     self.ads = ads
     self._as_parameter_ = self.ads
Exemplo n.º 6
0
 def extract_decoded(self, start, end):
     if start < 0 or end >= self.total_length():
         gterror("invalid coordinates: %d-%d (allowed: %d-%d)" %
                 (start, end, 0, self.total_length() - 1))
     buf = (c_char * (end - start + 1))()
     gtlib.gt_encseq_extract_decoded(self.encseq, buf, start, end)
     return string_at(buf, end - start + 1)
Exemplo n.º 7
0
 def add_child(self, node):
     ownid = str(self.get_seqid())
     newid = str(node.get_seqid())
     if (ownid != newid):
         gterror("cannot add node with sequence region '%s' to node with sequence region '%s'" % (ownid, newid))
     else:
         gtlib.gt_feature_node_add_child(self.gn, node._as_parameter_)
Exemplo n.º 8
0
 def trackselector(block_ptr, string_ptr, data_ptr):
     b = Block(block_ptr)
     string = Str(string_ptr)
     ret = func(b)
     if not ret:
         gterror("Track selector callback function must return a string!")
     string.append_cstr(ret)
Exemplo n.º 9
0
 def mirror(self):
     if self.is_mirrored():
         gterror("encoded sequence is already mirrored")
     err = Error()
     ret = gtlib.gt_encseq_mirror(self.encseq, err.error)
     if ret != 0:
         gterror(err)
Exemplo n.º 10
0
    def __init__(self):

        try:
            self.next
        except AttributeError:
            gterror("%s does not implement mandatory method 'next'!" \
                      % self.__class__.__name__)

        def next_w(nodepp, err):
            error = Error(err)
            try:
                nextnode = self.next()
                if nextnode:
                    nodepp[0] = nextnode.gn
                else:
                    nodepp[0] = None
                return 0
            except GTError as errmsg:
                error.set(str(errmsg))
                return -1

        self.next_cb = NextFunc(next_w)

        def free_w(ptr):
            self.free()

        self.free_cb = FreeFunc(free_w)
        self.gs = gtlib.gt_script_wrapper_stream_new(self.next_cb,
                                                     self.free_cb)
        self._as_parameter_ = self.gs
Exemplo n.º 11
0
    def __init__(self):

        try:
            self.next
        except AttributeError:
            gterror("%s does not implement mandatory method 'next'!" %
                    self.__class__.__name__)

        def next_w(nodepp, err):
            error = Error(err)
            try:
                nextnode = self.next()
                if nextnode:
                    nodepp[0] = nextnode.gn
                else:
                    nodepp[0] = None
                return 0
            except Error:
                import sys
                errmsg = sys.exc_info()[1]
                error.set(str(errmsg))
                return -1

        self.next_cb = NextFunc(next_w)

        def free_w(ptr):
            try:
                self.free()
            except AttributeError:
                pass

        self.free_cb = FreeFunc(free_w)
        self.gs = gtlib.gt_script_wrapper_stream_new(self.next_cb,
                                                     self.free_cb)
        self._as_parameter_ = self.gs
Exemplo n.º 12
0
Arquivo: rdb.py Projeto: pythseq/EDTA
 def __init__(self, filename):
     err = Error()
     rdb = gtlib.gt_rdb_sqlite_new(filename, err._as_parameter_)
     if rdb == None:
         gterror(err)
     self.rdb = rdb
     self._as_parameter_ = self.rdb
Exemplo n.º 13
0
 def description(self, num):
     if not num < self.num_of_sequences():
         gterror("invalid sequence number %d" % num)
     desclen = c_ulong()
     str_addr = gtlib.gt_encseq_description(
         self.encseq, byref(desclen), num)
     return str(string_at(str_addr, desclen.value).decode('UTF-8'))
Exemplo n.º 14
0
 def get_height(self):
     err = Error()
     height = c_ulong()
     gtlib.gt_layout_get_height(self.layout, byref(height), err)
     if err.is_set():
         gterror(err)
     return height.value
Exemplo n.º 15
0
 def load_str(self, string):
     err = Error()
     strg = Str(str(string.encode("utf-8")))
     rval = gtlib.gt_style_load_str(self.style, strg._as_parameter_,
             err._as_parameter_)
     if rval != 0:
         gterror(err)
Exemplo n.º 16
0
 def get_first_seqid(self):
     err = Error()
     str = gtlib.gt_feature_index_get_first_seqid(self.fi, err)
     if str == None:
         if err.is_set():
             gterror(err)
     return str
Exemplo n.º 17
0
 def description(self, num):
     if not num < self.num_of_sequences():
         gterror("invalid sequence number %d" % num)
     desclen = c_ulong()
     str_addr = gtlib.gt_encseq_description(self.encseq, byref(desclen),
                                            num)
     return str(string_at(str_addr, desclen.value))
Exemplo n.º 18
0
 def __init__(self, diagram, width, style):
     err = Error()
     self.layout = gtlib.gt_layout_new(diagram._as_parameter_, width,
                                       style._as_parameter_, err._as_parameter_)
     if err.is_set():
         gterror(err)
     self._as_parameter_ = self.layout
Exemplo n.º 19
0
 def get_first_seqid(self):
     err = Error()
     str = gtlib.gt_feature_index_get_first_seqid(self.fi, err._as_parameter_)
     if str == None:
         if err.is_set():
             gterror(err)
     return str
Exemplo n.º 20
0
 def __init__(self, filename):
     err = Error()
     rdb = gtlib.gt_rdb_sqlite_new(filename, err._as_parameter_)
     if rdb == None:
         gterror(err)
     self.rdb = rdb
     self._as_parameter_ = self.rdb
Exemplo n.º 21
0
 def __init__(self):
     err = Error()
     ads = gtlib.gt_anno_db_gfflike_new()
     if ads == None:
         gterror(err)
     self.ads = ads
     self._as_parameter_ = self.ads
Exemplo n.º 22
0
 def to_str(self):
     err = Error()
     string = Str()
     if gtlib.gt_style_to_str(self.style, string, err) == 0:
         return str(string)
     else:
         gterror(err)
Exemplo n.º 23
0
 def extract_decoded(self, start, end):
     if start < 0 or end >= self.total_length():
         gterror("invalid coordinates: %d-%d (allowed: %d-%d)" % (start, end,
                                                   0, self.total_length()-1))
     buf = (c_char * (end-start+1))()
     gtlib.gt_encseq_extract_decoded(self.encseq, buf, start, end)
     return string_at(buf, end-start+1)
Exemplo n.º 24
0
 def mirror(self):
     if self.is_mirrored():
         gterror("encoded sequence is already mirrored")
     err = Error()
     ret = gtlib.gt_encseq_mirror(self.encseq, err.error)
     if ret != 0:
         gterror(err)
Exemplo n.º 25
0
 def get_height(self):
     err = Error()
     height = c_ulong()
     gtlib.gt_layout_get_height(self.layout, byref(height), err)
     if err.is_set():
         gterror(err)
     return height.value
Exemplo n.º 26
0
 def load_str(self, string):
     err = Error()
     strg = Str(str(string.encode("utf-8")))
     rval = gtlib.gt_style_load_str(self.style, strg._as_parameter_,
                                    err._as_parameter_)
     if rval != 0:
         gterror(err)
Exemplo n.º 27
0
 def get_feature_index(self, rdb):
     err = Error()
     fi = gtlib.gt_anno_db_schema_get_feature_index(self.ads, rdb._as_parameter_,
             err._as_parameter_)
     if fi == None:
         gterror(err)
     return FeatureIndexFromPtr(fi)
Exemplo n.º 28
0
 def get_feature_index(self, rdb):
     err = Error()
     fi = gtlib.gt_anno_db_schema_get_feature_index(self.ads,
                                                    rdb._as_parameter_,
                                                    err._as_parameter_)
     if fi == None:
         gterror(err)
     return FeatureIndexFromPtr(fi)
Exemplo n.º 29
0
 def __init__(self, diagram, width, style):
     err = Error()
     self.layout = gtlib.gt_layout_new(diagram._as_parameter_, width,
                                       style._as_parameter_,
                                       err._as_parameter_)
     if err.is_set():
         gterror(err)
     self._as_parameter_ = self.layout
Exemplo n.º 30
0
 def __init__(self, style, width, height, ii=None):
     err = Error()
     canvas = gtlib.gt_canvas_cairo_file_new(style, GRAPHICS_PNG, width,
             height, ii, err)
     if canvas == None:
         gterror(err)
     self.canvas = canvas
     self._as_parameter_ = self.canvas
Exemplo n.º 31
0
 def to_str(self):
     err = Error()
     string = Str()
     if gtlib.gt_style_to_str(self.style, string._as_parameter_,
                              err._as_parameter_) == 0:
         return str(string)
     else:
         gterror(err)
Exemplo n.º 32
0
 def to_file(self, filename):
     err = Error()
     rval = gtlib.gt_canvas_cairo_file_to_file(self.canvas,
                                               str(filename).encode(
                                                   'UTF-8'),
                                               err)
     if rval != 0:
         gterror(err)
Exemplo n.º 33
0
 def __init__(self, style, width, height, ii=None):
     err = Error()
     canvas = gtlib.gt_canvas_cairo_file_new(style, GRAPHICS_PNG, width,
                                             height, ii, err)
     if canvas == None:
         gterror(err)
     self.canvas = canvas
     self._as_parameter_ = self.canvas
Exemplo n.º 34
0
 def to_str(self):
     err = Error()
     string = Str()
     if gtlib.gt_style_to_str(self.style, string._as_parameter_,
                              err._as_parameter_) == 0:
         return str(string)
     else:
         gterror(err)
Exemplo n.º 35
0
 def get_range_for_seqid(self, seqid):
     from ctypes import byref
     if gtlib.gt_feature_index_has_seqid(self.fi, seqid) == 0:
         gterror("feature_index does not contain seqid")
     range = Range()
     gtlib.gt_feature_index_get_range_for_seqid(self.fi, byref(range),
             seqid)
     return range
Exemplo n.º 36
0
 def get_first_seqid(self):
     err = Error()
     str = gtlib.gt_feature_index_get_first_seqid(self.fi,
                                                  err._as_parameter_)
     if str == None:
         if err.is_set():
             gterror(err)
     return str.decode('UTF-8')
Exemplo n.º 37
0
 def get_seqids(self):
     result = []
     err = Error()
     stra = StrArray(gtlib.gt_feature_index_get_seqids(self.fi, err))
     if stra == None:
         gterror(err)
     for i in range(stra.size()):
         result.append(stra.get(i))
     return result
Exemplo n.º 38
0
 def create_new(cls, seqid, type, start, end, strand):
     from gt.extended.strand import strandchars
     if not strand in strandchars:
         gterror("Invalid strand '%s' -- must be one of %s" % (strand,
                 strandchars))
     s = Str(seqid)
     fn = gtlib.gt_feature_node_new(s, type, start, end, strandchars.index(strand))
     n = cls.create_from_ptr(fn, True)
     return n
Exemplo n.º 39
0
 def has_seqid(self, seqid):
     from ctypes import c_int, byref
     val = c_int()
     err = Error()
     ret = gtlib.gt_feature_index_has_seqid(self.fi, byref(val), seqid, err)
     if ret != 0:
         gterror(err)
     else:
         return (val.value > 0)
Exemplo n.º 40
0
 def add_child(self, node):
     ownid = str(self.get_seqid())
     newid = str(node.get_seqid())
     if (ownid != newid):
         gterror(
             "cannot add node with sequence region '%s' to node with sequence region '%s'"
             % (ownid, newid))
     else:
         gtlib.gt_feature_node_add_child(self.gn, node._as_parameter_)
Exemplo n.º 41
0
 def create_reader_with_readmode(self, readmode, startpos):
     if readmode < 0 or readmode > 3:
         gterror("invalid readmode!")
     if startpos < 0 or startpos >= self.total_length():
         gterror("invalid startposition: %d (allowed: %d-%d)" %
                 (startpos, 0, self.total_length() - 1))
     er = gtlib.gt_encseq_create_reader_with_readmode(
         self.encseq, readmode, startpos)
     return EncseqReader(er, True)
Exemplo n.º 42
0
 def get_seqids(self):
     result = []
     err = Error()
     stra = StrArray(gtlib.gt_feature_index_get_seqids(self.fi, err))
     if stra == None:
         gterror(err)
     for i in range(stra.size()):
         result.append(stra.get(i))
     return result
Exemplo n.º 43
0
 def __init__(self, filename):
     try:
         p = open(filename)
         tmp = p.readline()
         p.close()
     except:
         gterror("File " + filename + " not readable!")
     self.gs = gtlib.gt_gff3_in_stream_new_sorted(filename)
     self._as_parameter_ = self.gs
Exemplo n.º 44
0
 def __init__(self, filename):
     try:
         p = open(filename)
         tmp = p.readline()
         p.close()
     except:
         gterror("File " + filename + " not readable!")
     self.gs = gtlib.gt_gff3_in_stream_new_sorted(filename)
     self._as_parameter_ = self.gs
Exemplo n.º 45
0
 def create_from_file(indexname):
     if not os.path.exists(indexname + ".al1"):
         raise IOError, ("file not found: %s" % (indexname + ".al1"))
     e = Error()
     a_ptr = gtlib.gt_alphabet_new_from_file(str(indexname), e)
     a = Alphabet(a_ptr, True)
     if a == None:
       gterror(e)
     else:
       return a
Exemplo n.º 46
0
 def has_seqid(self, seqid):
     from ctypes import c_int, byref
     val = c_int()
     err = Error()
     ret = gtlib.gt_feature_index_has_seqid(self.fi, byref(val),
                                            seqid.encode('UTF-8'), err._as_parameter_)
     if ret != 0:
         gterror(err)
     else:
         return (val.value > 0)
Exemplo n.º 47
0
 def from_index(feature_index, seqid, rng, style):
     from ctypes import byref
     err = Error()
     if rng.start > rng.end:
         gterror("range.start > range.end")
     diagram = gtlib.gt_diagram_new(feature_index, seqid, byref(rng),
             style, err)
     if err.is_set():
         gterror(err)
     return Diagram(diagram)
Exemplo n.º 48
0
 def trackorderer(s1, s2, data_ptr):
     ret = func(s1, s2)
     try:
         if ret is None:
             raise ValueError
         else:
             ret = int(ret)
     except ValueError:
         gterror("Track ordering function must return a number!")
     return ret
Exemplo n.º 49
0
 def create_reader_with_readmode(self, readmode, startpos):
     if readmode < 0 or readmode > 3:
         gterror("invalid readmode!")
     if startpos < 0 or startpos >= self.total_length():
         gterror("invalid startposition: %d (allowed: %d-%d)" % (startpos,
                                                                 0,
                                                                 self.total_length()-1))
     er = gtlib.gt_encseq_create_reader_with_readmode(self.encseq, readmode,
                                                      startpos)
     return EncseqReader(er, True)
Exemplo n.º 50
0
 def next_tree(self):
     err = Error()
     genome_node = c_void_p()
     rval = gtlib.gt_node_stream_next(self.gs, byref(genome_node), err)
     if rval != 0:
         gterror(err)
     if genome_node.value == None:
         return None
     else:
         return GenomeNode.create_from_ptr(genome_node.value)
Exemplo n.º 51
0
 def get_cstr(self, section, key, gn=None):
     string = Str()
     err = Error()
     rval = gtlib.gt_style_get_str(self.style, section, key, string, gn, err)
     if rval == STYLE_OK:
         return str(string)
     elif rval == STYLE_NOT_SET:
         return None
     elif rval == STYLE_ERROR:
         gterror(err)
Exemplo n.º 52
0
 def trackorderer(s1, s2, data_ptr):
     ret = func(s1, s2)
     try:
         if ret is None:
             raise ValueError
         else:
             ret = int(ret)
     except ValueError:
         gterror("Track ordering function must return a number!")
     return ret
Exemplo n.º 53
0
 def from_index(feature_index, seqid, rng, style):
     from ctypes import byref
     err = Error()
     if rng.start > rng.end:
         gterror("range.start > range.end")
     diagram = gtlib.gt_diagram_new(feature_index, seqid, byref(rng), style,
                                    err)
     if err.is_set():
         gterror(err)
     return Diagram(diagram)
Exemplo n.º 54
0
 def has_seqid(self, seqid):
     from ctypes import c_int, byref
     val = c_int()
     err = Error()
     ret = gtlib.gt_feature_index_has_seqid(self.fi, byref(val),
             seqid, err)
     if ret != 0:
         gterror(err)
     else:
       return (val.value > 0)
Exemplo n.º 55
0
 def create_from_file(indexname):
     if not os.path.exists(indexname + ".al1"):
         raise IOError, ("file not found: %s" % (indexname + ".al1"))
     e = Error()
     a_ptr = gtlib.gt_alphabet_new_from_file(str(indexname), e)
     a = Alphabet(a_ptr, True)
     if a == None:
         gterror(e)
     else:
         return a
Exemplo n.º 56
0
 def get_range_for_seqid(self, seqid):
     from ctypes import byref
     err = Error()
     if self.has_seqid(seqid) == 0:
         gterror("feature_index does not contain seqid")
     range = Range()
     rval = gtlib.gt_feature_index_get_range_for_seqid(self.fi, byref(range),
             seqid, err)
     if rval != 0:
         gterror(err)
     return range
Exemplo n.º 57
0
 def has_seqid(self, seqid):
     from ctypes import c_int, byref
     val = c_int()
     err = Error()
     ret = gtlib.gt_feature_index_has_seqid(self.fi, byref(val),
                                            seqid.encode('UTF-8'),
                                            err._as_parameter_)
     if ret != 0:
         gterror(err)
     else:
         return (val.value > 0)
Exemplo n.º 58
0
 def __init__(self, ptr=None):
     if ptr:
         self.style = ptr
         self.own = False
     else:
         e = Error()
         self.style = gtlib.gt_style_new(e)
         if self.style == 0 or self.style == None:
             gterror(e)
         self.own = True
     self._as_parameter_ = self.style
Exemplo n.º 59
0
 def get_cstr(self, section, key, gn=None):
     string = Str()
     err = Error()
     rval = gtlib.gt_style_get_str(self.style, section, key, string, gn,
                                   err)
     if rval == STYLE_OK:
         return str(string)
     elif rval == STYLE_NOT_SET:
         return None
     elif rval == STYLE_ERROR:
         gterror(err)
Exemplo n.º 60
0
 def next_tree(self):
     err = Error()
     genome_node = c_void_p()
     rval = gtlib.gt_node_stream_next(self.gs, byref(genome_node),
                                      err._as_parameter_)
     if rval != 0:
         gterror(err)
     if genome_node.value == None:
         return None
     else:
         return GenomeNode.create_from_ptr(genome_node.value)