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.
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/ezgff/gffsqlitedb.rb', line 226 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.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def attributes @attributes end |
#end ⇒ Object
Returns the value of attribute end.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def end @end end |
#gffline ⇒ Object
Returns the value of attribute gffline.
243 244 245 |
# File 'lib/ezgff/gffsqlitedb.rb', line 243 def gffline @gffline end |
#id ⇒ Object
Returns the value of attribute id.
243 244 245 |
# File 'lib/ezgff/gffsqlitedb.rb', line 243 def id @id end |
#line_num ⇒ Object
Returns the value of attribute line_num.
243 244 245 |
# File 'lib/ezgff/gffsqlitedb.rb', line 243 def line_num @line_num end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
243 244 245 |
# File 'lib/ezgff/gffsqlitedb.rb', line 243 def parent_id @parent_id end |
#phase ⇒ Object
Returns the value of attribute phase.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def phase @phase end |
#score ⇒ Object
Returns the value of attribute score.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def score @score end |
#seqid ⇒ Object
Returns the value of attribute seqid.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def seqid @seqid end |
#source ⇒ Object
Returns the value of attribute source.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def source @source end |
#start ⇒ Object
Returns the value of attribute start.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def start @start end |
#strand ⇒ Object
Returns the value of attribute strand.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def strand @strand end |
#type ⇒ Object
Returns the value of attribute type.
242 243 244 |
# File 'lib/ezgff/gffsqlitedb.rb', line 242 def type @type end |
Instance Method Details
#ancestors ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/ezgff/gffsqlitedb.rb', line 333 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
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/ezgff/gffsqlitedb.rb', line 272 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
303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/ezgff/gffsqlitedb.rb', line 303 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
358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/ezgff/gffsqlitedb.rb', line 358 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
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/ezgff/gffsqlitedb.rb', line 316 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
352 353 354 355 356 |
# File 'lib/ezgff/gffsqlitedb.rb', line 352 def length len = @end - @start + 1 raise unless len > 0 return len end |
#parent ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/ezgff/gffsqlitedb.rb', line 290 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
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/ezgff/gffsqlitedb.rb', line 249 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
268 269 270 |
# File 'lib/ezgff/gffsqlitedb.rb', line 268 def to_json self.to_hash.to_json end |
#to_s ⇒ Object
245 246 247 |
# File 'lib/ezgff/gffsqlitedb.rb', line 245 def to_s gffline end |