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)
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)
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)
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)
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
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)
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_)
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)
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
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
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
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'))
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
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)
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
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))
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
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
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)
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)
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
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)
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)
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
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')
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
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
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)
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_)
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)
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
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
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)
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)
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
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)
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)
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)
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
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
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)