Class: JgiGffRecord

Inherits:
Bio::GFF::Record
  • Object
show all
Defined in:
lib/jgi_genes.rb

Overview

Fixes up JGI to GFF problems. I don’t mean to blame anyone but they just don’t seem to go together

Direct Known Subclasses

EupathDBGFFRecord

Constant Summary collapse

SEQNAME_COL =
0
SOURCE_COL =
1
FEATURE_COL =
2
START_COL =
3
END_COL =
4
SCORE_COL =
5
STRAND_COL =
6
FRAME_COL =
7
ATTRIBUTES_COL =
8

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ JgiGffRecord

Returns a new instance of JgiGffRecord.



179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/jgi_genes.rb', line 179

def initialize(line)
  @line = line
  
  parts = line.split("\t");
  if parts.length != 9 and parts.length != 8
    raise Exception, "Badly formatted GFF line - doesn't have correct number of components '#{line}"
  end

  
  parse_mandatory_columns(parts)
  
  parse_attributes(parts[ATTRIBUTES_COL])
  
end

Instance Method Details

#parse_attributes(attribute_string) ⇒ Object

parse the last part of a line into a hash contained in attributes global variable



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/jgi_genes.rb', line 211

def parse_attributes(attribute_string)
  @attributes = Hash.new #define empty attributes even if there are none
  
  if attribute_string
    #let the fancy parsing begin
    aparts = attribute_string.split '; '
    
    aparts.each do |bit|
      hbits = bit.split ' '
      if !hbits or hbits.length != 2
        raise Exception, "Failed to parse attributes in line: #{line}"
      end
      str = hbits[1].gsub(/\"/, '').rstrip.lstrip
      @attributes[hbits[0]] = str
    end
  end
end

#parse_mandatory_columns(parts) ⇒ Object

Given an array of 8 strings, parse the columns into something that can be understood by this object



197
198
199
200
201
202
203
204
205
206
# File 'lib/jgi_genes.rb', line 197

def parse_mandatory_columns(parts)
  @seqname = parts[SEQNAME_COL]
  @source = parts[SOURCE_COL]
  @feature = parts[FEATURE_COL]
  @start = parts[START_COL]
  @end = parts[END_COL]
  @score = parts[SCORE_COL]
  @strand = parts[STRAND_COL]
  @frame = parts[FRAME_COL]
end

#to_sObject



230
231
232
# File 'lib/jgi_genes.rb', line 230

def to_s
  @line
end