class Ezgff::GffDb::Annotation
Attributes
attributes[RW]
end[RW]
gffline[RW]
id[RW]
line_num[RW]
parent_id[RW]
phase[RW]
score[RW]
seqid[RW]
source[RW]
start[RW]
strand[RW]
type[RW]
Public Class Methods
new(db = nil)
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 244 def initialize(db = nil) @db = db @seqid @source @type @start @end @score @strand @phase @attributes @id @parent_id @gffline end
Public Instance Methods
ancestors()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 351 def ancestors ary = [] sql = %Q{WITH RECURSIVE ancestor AS ( SELECT * FROM gff_records WHERE id=="#{id}" UNION ALL SELECT gff_records.* FROM gff_records, ancestor WHERE ancestor.parent = gff_records.id ) SELECT * FROM ancestor;} res = @db.execute(sql) res.each do |r| an = Annotation.new(@db) an.build_from_db_record(r) ary << an end ary end
build_from_db_record(sql_result)
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 290 def build_from_db_record(sql_result) ## sql_result: Array returned by @db.execute(sql) v = sql_result @seqid = v[4] @source = v[5] @type = v[6] @start = v[7] @end = v[8] @score = v[9] @strand = v[10] @phase = v[11] @line_num = v[0] @gffline = v[1] @id = v[2] @parent_id = v[3] @attributes = JSON.parse(v[13]) end
children()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 321 def children ary = [] sql = %Q{SELECT * FROM gff_records WHERE parent=="#{id}";} # puts sql res = @db.execute(sql) res.each do |r| an = Annotation.new(@db) an.build_from_db_record(r) ary << an end ary end
dbxrefs()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 376 def dbxrefs h = Hash.new if attributes["Dbxref"] attributes["Dbxref"].split(/,/).each do |x| m = /(.+?):/.match(x) key = m[1] val = m.post_match h.update({key => val}) end end h end
descendants()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 334 def descendants ary = [] sql = %Q{WITH RECURSIVE r AS ( SELECT * FROM gff_records WHERE id=="#{id}" UNION ALL SELECT gff_records.* FROM gff_records, r WHERE gff_records.parent == r.id ) SELECT * FROM r} res = @db.execute(sql) res.each do |r| an = Annotation.new(@db) an.build_from_db_record(r) ary << an end ary end
length()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 370 def length len = @end - @start + 1 raise unless len > 0 return len end
parent()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 308 def parent if parent_id sql = %Q{SELECT * FROM gff_records WHERE id=="#{parent_id}";} # puts sql res = @db.execute(sql) an = Annotation.new(@db) an.build_from_db_record(res[0]) return an else return nil end end
to_hash()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 267 def to_hash h = { 'seqid' => seqid, 'source' => source, 'type' => type, 'start' => start, 'end' => self.end, 'score' => score, 'strand' => strand, 'phase' => phase, 'line_num' => line_num, 'id' => id, 'parent_id' => parent_id, 'attributes' => attributes } end
Also aliased as: to_h
to_json()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 286 def to_json self.to_hash.to_json end
to_s()
click to toggle source
# File lib/ezgff/gffsqlitedb.rb, line 263 def to_s gffline end