Class: Bio::GFF::GFF3::Record::Target

Inherits:
Object
  • Object
show all
Extended by:
Escape
Includes:
Escape
Defined in:
lib/bio/db/gff.rb

Overview

Bio:GFF::GFF3::Record::Target is a class to store data of “Target” attribute.

Constant Summary

Constants included from Escape

Escape::UNSAFE, Escape::UNSAFE_ATTRIBUTE, Escape::UNSAFE_SEQID

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_id, start, endpos, strand = nil) ⇒ Target

Creates a new Target object.



1198
1199
1200
1201
1202
1203
# File 'lib/bio/db/gff.rb', line 1198

def initialize(target_id, start, endpos, strand = nil)
  @target_id = target_id
  @start = start ? start.to_i : nil
  @end = endpos ? endpos.to_i : nil
  @strand = strand
end

Instance Attribute Details

#endObject

end position



1212
1213
1214
# File 'lib/bio/db/gff.rb', line 1212

def end
  @end
end

#startObject

start position



1209
1210
1211
# File 'lib/bio/db/gff.rb', line 1209

def start
  @start
end

#strandObject

strand (optional). Normally, “+” or “-”, or nil.



1215
1216
1217
# File 'lib/bio/db/gff.rb', line 1215

def strand
  @strand
end

#target_idObject

target ID



1206
1207
1208
# File 'lib/bio/db/gff.rb', line 1206

def target_id
  @target_id
end

Class Method Details

.parse(str) ⇒ Object

parses “target_id start end [strand]”-style string (for example, “ABC789 123 456 +”) and creates a new Target object.



1221
1222
1223
1224
1225
# File 'lib/bio/db/gff.rb', line 1221

def self.parse(str)
  target_id, start, endpos, strand =
    str.split(/ +/, 4).collect { |x| unescape(x) }
  self.new(target_id, start, endpos, strand)
end

Instance Method Details

#==(other) ⇒ Object

Returns true if self == other. Otherwise, returns false.



1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
# File 'lib/bio/db/gff.rb', line 1238

def ==(other)
  if other.class == self.class and
      other.target_id == self.target_id and
      other.start == self.start and
      other.end == self.end and
      other.strand == self.strand then
    true
  else
    false
  end
end

#to_sObject

returns a string



1228
1229
1230
1231
1232
1233
1234
1235
# File 'lib/bio/db/gff.rb', line 1228

def to_s
  i = escape_seqid(column_to_s(@target_id))
  s = escape_attribute(column_to_s(@start))
  e = escape_attribute(column_to_s(@end))
  strnd = escape_attribute(@strand.to_s)
  strnd = " " + strnd unless strnd.empty?
  "#{i} #{s} #{e}#{strnd}"
end