class Bio::GFF::GFF3::Record

Represents a single line of a GFF3-formatted file. See Bio::GFF::GFF3 for more information.

Public Class Methods

new(*arg) click to toggle source

Creates a Bio::GFF::GFF3::Record object. Is typically not called directly, but is called automatically when creating a Bio::GFF::GFF3 object.


Arguments:

  • str: a tab-delimited line in GFF3 format

Arguments:

  • seqid: sequence ID (String or nil)

  • source: source (String or nil)

  • feature_type: type of feature (String)

  • start_position: start (Integer)

  • end_position: end (Integer)

  • score: score (Float or nil)

  • strand: strand (String or nil)

  • phase: phase (Integer or nil)

  • attributes: attributes (Array or nil)

Calls superclass method Bio::GFF::GFF2::Record.new
# File lib/bio/db/gff.rb, line 1157
def initialize(*arg)
  super(*arg)
end
parse(str) click to toggle source

Parses a GFF3-formatted line and returns a new Bio::GFF::GFF3::Record object.

# File lib/bio/db/gff.rb, line 1136
def self.parse(str)
  self.new.parse(str)
end

Public Instance Methods

id() click to toggle source

shortcut to the ID attribute

# File lib/bio/db/gff.rb, line 1110
def id
  get_attribute('ID')
end
id=(str) click to toggle source

set ID attribute

# File lib/bio/db/gff.rb, line 1115
def id=(str)
  set_attribute('ID', str)
end
parse(string) click to toggle source

Parses a GFF3-formatted line and stores data from the string. Note that all existing data is wiped out.

Calls superclass method Bio::GFF::GFF2::Record.parse
# File lib/bio/db/gff.rb, line 1163
def parse(string)
  super
end
to_s() click to toggle source

Return the record as a GFF3 compatible string

# File lib/bio/db/gff.rb, line 1168
def to_s
  cmnt = if defined?(@comment) and @comment and
             !@comment.to_s.strip.empty? then
           @comment.gsub(/[\r\n]+/, ' ')
         else
           false
         end
  return "\##{cmnt}\n" if self.comment_only? and cmnt
  [
   escape_seqid(column_to_s(@seqname)),
   escape(column_to_s(@source)),
   escape(column_to_s(@feature)),
   escape(column_to_s(@start)),
   escape(column_to_s(@end)),
   escape(column_to_s(@score)),
   escape(column_to_s(@strand)),
   escape(column_to_s(@frame)),
   attributes_to_s(@attributes)
  ].join("\t") + 
    (cmnt ? "\t\##{cmnt}\n" : "\n")
end

Private Instance Methods

attributes_to_s(attr) click to toggle source

Return the attributes as a string as it appears at the end of a GFF3 line

# File lib/bio/db/gff.rb, line 1794
def attributes_to_s(attr)
  return '.' if !attr or attr.empty?
  keys = []
  hash = {}
  attr.each do |pair|
    key = pair[0]
    val = pair[1]
    keys.push key unless hash[key]
    hash[key] ||= []
    hash[key].push val
  end
  keys.collect do |key|
    values = hash[key]
    val = values.collect do |v|
      if v.kind_of?(Target) then
        v.to_s
      else
        escape_attribute(v.to_s)
      end
    end.join(',')
    "#{escape_attribute(key)}=#{val}"
  end.join(';')
end
parse_attributes(string) click to toggle source
# File lib/bio/db/gff.rb, line 1772
def parse_attributes(string)
  return [] if !string or string == '.'
  attr_pairs = []
  string.split(';').each do |pair|
    key, value = pair.split('=', 2)
    key = unescape(key)
    values = value.to_s.split(',')
    case key
    when 'Target'
      values.collect! { |v| Target.parse(v) }
    when 'Gap'
      values.collect! { |v| Gap.parse(v) }
    else
      values.collect! { |v| unescape(v) }
    end
    attr_pairs.concat values.collect { |v| [ key, v ] }
  end
  return attr_pairs
end