Class: JgiGenesIterator

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

Instance Method Summary collapse

Constructor Details

#initialize(jgiGenesGffObj) ⇒ JgiGenesIterator

Returns a new instance of JgiGenesIterator.



242
243
244
245
246
247
248
249
# File 'lib/jgi_genes.rb', line 242

def initialize(jgiGenesGffObj)
  @genbank = jgiGenesGffObj
  
  # Setup cycle for iterator
  @cur_gene = @genbank.next_gene
  @next_gene = @genbank.next_gene
  @next_is_first = true
end

Instance Method Details

#has_next_distanceObject



251
252
253
# File 'lib/jgi_genes.rb', line 251

def has_next_distance
  return !@next_gene.nil?
end

#next_distanceObject

Return the upstream distance between one gene and another



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/jgi_genes.rb', line 261

def next_distance
  # if the first gene in the list
  if @next_is_first
    # cycle has already been setup in initialisation
    @next_is_first = false;
  else
    #cycle through things
    if !@cur_gene #if nothing is found
      raise Exception, 'Unexpected nil cur_gene - a software coding error?'
    end
    @prev_gene = @cur_gene
    @cur_gene = @next_gene
    @next_gene = @genbank.next_gene
  end
  
  if !@cur_gene
    raise Exception, 'Overrun iterator - no more genes available. Use has_next_distance'
  end
  
  
  
  # We look at the current gene, and return its upstream distance
  if @cur_gene.positive_strand?
    # so we want the distance between cur and last then
    
    # if last gene undefined or on a different scaffold, return nothing
    if !@prev_gene or @prev_gene.seqname != @cur_gene.seqname
      return nil
    end
    return @cur_gene.cds_start.to_i - @prev_gene.cds_end.to_i
  else
    if !@next_gene or @next_gene.seqname != @cur_gene.seqname
      return nil
    end
    return @next_gene.cds_start.to_i - @cur_gene.cds_end.to_i
  end
  
end

#next_geneObject

Return the next gene to be worked on



256
257
258
# File 'lib/jgi_genes.rb', line 256

def next_gene
  return @cur_gene
end