Class: Bio::GFF::GFF2

Inherits:
Bio::GFF show all
Defined in:
lib/bio/db/gff.rb

Overview

DESCRIPTION

Represents version 2 of GFF specification. Its behavior is somehow different from Bio::GFF, especially for attributes.

Defined Under Namespace

Modules: Escape Classes: MetaData, Record

Constant Summary collapse

VERSION =
2

Instance Attribute Summary collapse

Attributes inherited from Bio::GFF

#records

Instance Method Summary collapse

Constructor Details

#initialize(str = nil) ⇒ GFF2

Creates a Bio::GFF::GFF2 object by building a collection of Bio::GFF::GFF2::Record (and metadata) objects.


Arguments:

  • str: string in GFF format

Returns

Bio::GFF::GFF2 object


823
824
825
826
827
828
# File 'lib/bio/db/gff.rb', line 823

def initialize(str = nil)
  @gff_version = nil
  @records = []
  @metadata = []
  parse(str) if str
end

Instance Attribute Details

#gff_versionObject (readonly)

GFF2 version string (String or nil). nil means “2”.


831
832
833
# File 'lib/bio/db/gff.rb', line 831

def gff_version
  @gff_version
end

#metadataObject

Metadata (except “##gff-version”). Must be an array of Bio::GFF::GFF2::MetaData objects.


835
836
837
# File 'lib/bio/db/gff.rb', line 835

def 
  @metadata
end

Instance Method Details

#parse(str) ⇒ Object

Parses a GFF2 entries, and concatenated the parsed data.


Arguments:

  • str: string in GFF format

Returns

self


843
844
845
846
847
848
849
850
851
852
853
# File 'lib/bio/db/gff.rb', line 843

def parse(str)
  # parses GFF lines
  str.each_line do |line|
    if /^\#\#([^\s]+)/ =~ line then
      ($1, line)
    else
      @records << GFF2::Record.new(line)
    end
  end
  self
end

#to_sObject

string representation of the whole entry.


194
195
196
197
198
199
200
# File 'lib/bio/db/gff.rb', line 194

def to_s
  ver = @gff_version || VERSION.to_s
  ver = ver.gsub(/[\r\n]+/, ' ')
  ([ "##gff-version #{ver}\n" ] +
   @metadata.collect { |m| m.to_s } +
   @records.collect{ |r| r.to_s }).join('')
end