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.



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

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



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

def end
  @end
end

#startObject

start position



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

def start
  @start
end

#strandObject

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



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

def strand
  @strand
end

#target_idObject

target ID



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

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.



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

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.



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

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



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

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