class BioInterchange::Phylogenetics::NewickReader

Public Class Methods

new(date = nil, batch_size = nil) click to toggle source

Creates a new instance of a Newick file format reader.

The reader supports batch processing.

date

Optional date of when the Newick file was produced, annotated, etc.

batch_size

Optional integer that determines that number of features that

should be processed in one go.

# File lib/biointerchange/phylogenetics/newick_reader.rb, line 27
def initialize(date = nil, batch_size = nil)
  @date = date
  @batch_size = batch_size
end

Public Instance Methods

deserialize(inputstream) click to toggle source

Reads a Newick file from the input stream and returns an associated model.

If this method is called when postponed? returns true, then the reading will continue from where it has been interrupted beforehand.

inputstream

an instance of class IO or String that holds the contents of a Newick file

# File lib/biointerchange/phylogenetics/newick_reader.rb, line 38
def deserialize(inputstream)
  if inputstream.kind_of?(IO)
    create_model(inputstream)
  elsif inputstream.kind_of?(String) then
    create_model(StringIO.new(inputstream))
  else
    raise BioInterchange::Exceptions::ImplementationReaderError, 'The provided input stream needs to be either of type IO or String.'
  end
end
postponed?() click to toggle source

Returns true if the reading of the input was postponed due to a full batch.

# File lib/biointerchange/phylogenetics/newick_reader.rb, line 49
def postponed?
  @postponed
end

Protected Instance Methods

create_model(newick) click to toggle source
# File lib/biointerchange/phylogenetics/newick_reader.rb, line 55
def create_model(newick)
  if @postponed then
    @postponed = false
    @trees.prune
  else
    @trees = BioInterchange::Phylogenetics::TreeSet.new()
    @trees.set_date(Date.parse(@date)) if @date
  end

  tree_io = Bio::FlatFile.open(Bio::Newick, newick)
  while newick_tree = tree_io.next_entry
    newick_tree.options[:bootstrap_style] = :disabled
    @trees.add(newick_tree.tree)

    if @batch_size and feature_no >= @batch_size then
      @postponed = true
      break
    end
  end

  @trees
end