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

Inherits:
Object
  • Object
show all
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.


1168
1169
1170
1171
1172
1173
# File 'lib/bio/db/gff.rb', line 1168

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


1182
1183
1184
# File 'lib/bio/db/gff.rb', line 1182

def end
  @end
end

#startObject

start position


1179
1180
1181
# File 'lib/bio/db/gff.rb', line 1179

def start
  @start
end

#strandObject

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


1185
1186
1187
# File 'lib/bio/db/gff.rb', line 1185

def strand
  @strand
end

#target_idObject

target ID


1176
1177
1178
# File 'lib/bio/db/gff.rb', line 1176

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.


1191
1192
1193
1194
1195
# File 'lib/bio/db/gff.rb', line 1191

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

Instance Method Details

#==(other) ⇒ Object

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


1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
# File 'lib/bio/db/gff.rb', line 1208

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


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

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