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.



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

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



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

def end
  @end
end

#startObject

start position



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

def start
  @start
end

#strandObject

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



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

def strand
  @strand
end

#target_idObject

target ID



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

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.



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

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.



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

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



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

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