Class: Ezgff::GffDb::Annotation
- Inherits:
-
Object
- Object
- Ezgff::GffDb::Annotation
- Defined in:
- lib/ezgff/gffsqlitedb.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#end ⇒ Object
Returns the value of attribute end.
-
#gffline ⇒ Object
Returns the value of attribute gffline.
-
#id ⇒ Object
Returns the value of attribute id.
-
#line_num ⇒ Object
Returns the value of attribute line_num.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#phase ⇒ Object
Returns the value of attribute phase.
-
#score ⇒ Object
Returns the value of attribute score.
-
#seqid ⇒ Object
Returns the value of attribute seqid.
-
#source ⇒ Object
Returns the value of attribute source.
-
#start ⇒ Object
Returns the value of attribute start.
-
#strand ⇒ Object
Returns the value of attribute strand.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #build_from_db_record(sql_result) ⇒ Object
- #children ⇒ Object
- #dbxrefs ⇒ Object
- #descendants ⇒ Object
-
#initialize(db = nil) ⇒ Annotation
constructor
A new instance of Annotation.
- #length ⇒ Object
- #parent ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(db = nil) ⇒ Annotation
Returns a new instance of Annotation.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# 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 |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def attributes @attributes end |
#end ⇒ Object
Returns the value of attribute end.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def end @end end |
#gffline ⇒ Object
Returns the value of attribute gffline.
261 262 263 |
# File 'lib/ezgff/gffsqlitedb.rb', line 261 def gffline @gffline end |
#id ⇒ Object
Returns the value of attribute id.
261 262 263 |
# File 'lib/ezgff/gffsqlitedb.rb', line 261 def id @id end |
#line_num ⇒ Object
Returns the value of attribute line_num.
261 262 263 |
# File 'lib/ezgff/gffsqlitedb.rb', line 261 def line_num @line_num end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
261 262 263 |
# File 'lib/ezgff/gffsqlitedb.rb', line 261 def parent_id @parent_id end |
#phase ⇒ Object
Returns the value of attribute phase.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def phase @phase end |
#score ⇒ Object
Returns the value of attribute score.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def score @score end |
#seqid ⇒ Object
Returns the value of attribute seqid.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def seqid @seqid end |
#source ⇒ Object
Returns the value of attribute source.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def source @source end |
#start ⇒ Object
Returns the value of attribute start.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def start @start end |
#strand ⇒ Object
Returns the value of attribute strand.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def strand @strand end |
#type ⇒ Object
Returns the value of attribute type.
260 261 262 |
# File 'lib/ezgff/gffsqlitedb.rb', line 260 def type @type end |
Instance Method Details
#ancestors ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# 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) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# 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 ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 |
# 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 ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 |
# 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 ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# 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 ⇒ Object
370 371 372 373 374 |
# File 'lib/ezgff/gffsqlitedb.rb', line 370 def length len = @end - @start + 1 raise unless len > 0 return len end |
#parent ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 |
# 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 ⇒ Object Also known as: to_h
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# 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 |
#to_json ⇒ Object
286 287 288 |
# File 'lib/ezgff/gffsqlitedb.rb', line 286 def to_json self.to_hash.to_json end |
#to_s ⇒ Object
263 264 265 |
# File 'lib/ezgff/gffsqlitedb.rb', line 263 def to_s gffline end |