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



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

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”.



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

def gff_version
  @gff_version
end

#metadataObject

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



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

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



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

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.



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

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