Class: BioDSL::WriteTree

Inherits:
Object
  • Object
show all
Includes:
AuxHelper
Defined in:
lib/BioDSL/commands/write_tree.rb

Overview

Write aligned sequences from stream as a tree.

Description

write_tree takes aligned sequences from the stream and uses FastTree to to create a distance tree between the sequences. The tree is in Newick format. FastTree must be installed.

For more about the FastTree here:

www.microbesonline.org/fasttree/

Usage

write_tree([, output: <file>[, force: <bool>[, type: <string>]]])

Options

  • output <file> - Output file.

  • force <bool> - Force overwrite existing output file.

  • type <string> - Sequence type :dna|:rna|:protein (default=:dna).

Examples

To create a tree from aligned FASTA sequences in the file ‘align.fna` do:

BD.new.
read_fasta(input: "align.fna").
write_tree(output: "align.tree").
run

Constant Summary collapse

STATS =
%i(records_in records_out sequences_in residues_in)

Instance Method Summary collapse

Methods included from AuxHelper

#aux_exist

Constructor Details

#initialize(options) ⇒ WriteTree

Constructor for WriteTree.

Parameters:

  • options (Hash)

    Options hash.

Options Hash (options):

  • :output (String)
  • :force (Boolean)
  • :type (Symbol)


73
74
75
76
77
78
79
80
# File 'lib/BioDSL/commands/write_tree.rb', line 73

def initialize(options)
  @options = options

  aux_exist('FastTree')
  check_options

  @cmd = compile_command
end

Instance Method Details

#lmbProc

Return command lambda for write_tree.

Returns:

  • (Proc)

    Command lambda.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/BioDSL/commands/write_tree.rb', line 87

def lmb
  lambda do |input, output, status|
    status_init(status, STATS)

    Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
      input.each_with_index do |record, i|
        @status[:records_in] += 1

        write_seq(stdin, record, i) if record[:SEQ]

        output << record && @status[:records_out] += 1 if output
      end

      stdin.close

      tree_data = stdout.read.chomp

      stdout.close

      exit_status = wait_thr.value

      fail stderr.read unless exit_status.success?

      write_tree(tree_data)
    end
  end
end