Class: BioDSL::CollapseOtus

Inherits:
Object
  • Object
show all
Defined in:
lib/BioDSL/commands/collapse_otus.rb

Overview

Collapse OTUs based on identicial taxonomy strings.

collapse_otus collapses OTUs in OTU style records if the TAXONOMY string is redundant. At the same time the sample counts (_COUNT) is incremented the collapsed OTUs.

Usage

collapse_otus

Options

Examples

Here is an OTU table with four rows, one of which has a redundant Taxonomy string:

BD.new.read_table(input: "otu_table.txt").dump.run

{:OTU=>"OTU_1",
 :CM1_COUNT=>881,
 :CM10_COUNT=>234,
 :TAXONOMY=>
  "Bacteria(100);Firmicutes(100);Bacilli(100);Lactobacillales(100); \
  Leuconostocaceae(100);Leuconostoc(100)"}
{:OTU=>"OTU_0",
 :CM1_COUNT=>3352,
 :CM10_COUNT=>4329,
 :TAXONOMY=>
  "Bacteria(100);Firmicutes(100);Bacilli(100);Lactobacillales(100); \
  Streptococcaceae(100);Lactococcus(100)"}
{:OTU=>"OTU_5",
 :CM1_COUNT=>5,
 :CM10_COUNT=>0,
 :TAXONOMY=>
  "Bacteria(100);Proteobacteria(100);Gammaproteobacteria(100); \
  Pseudomonadales(100);Pseudomonadaceae(100);Pseudomonas(100)"}
{:OTU=>"OTU_3",
 :CM1_COUNT=>228,
 :CM10_COUNT=>200,
 :TAXONOMY=>
  "Bacteria(100);Firmicutes(100);Bacilli(100);Lactobacillales(100); \
  Streptococcaceae(100);Lactococcus(100)"}

In order to collapse the redudant OTU simply run the stream through collapse_otus:

BD.new.read_table(input: "otu_table.txt").collapse_otus.dump.run

{:OTU=>"OTU_1",
 :CM1_COUNT=>881,
 :CM10_COUNT=>234,
 :TAXONOMY=>
  "Bacteria(100);Firmicutes(100);Bacilli(100);Lactobacillales(100); \
  Leuconostocaceae(100);Leuconostoc(100)"}
{:OTU=>"OTU_0",
 :CM1_COUNT=>3580,
 :CM10_COUNT=>4529,
 :TAXONOMY=>
  "Bacteria(100);Firmicutes(100);Bacilli(100);Lactobacillales(100); \
  Streptococcaceae(100);Lactococcus(100)"}
{:OTU=>"OTU_5",
 :CM1_COUNT=>5,
 :CM10_COUNT=>0,
 :TAXONOMY=>
  "Bacteria(100);Proteobacteria(100);Gammaproteobacteria(100); \
  Pseudomonadales(100);Pseudomonadaceae(100);Pseudomonas(100)"}

Constant Summary collapse

STATS =
%i(records_in records_out otus_in otus_out)

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CollapseOtus

Constructor for CollapseOtus.

Parameters:

  • options (Hash)

    Options Hash.



102
103
104
105
106
# File 'lib/BioDSL/commands/collapse_otus.rb', line 102

def initialize(options)
  @options = options

  check_options
end

Instance Method Details

#lmbProc

Return the CollapseOtus command lambda.

Returns:

  • (Proc)

    Lambda for the command.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/BioDSL/commands/collapse_otus.rb', line 111

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

    hash = {}

    input.each do |record|
      @status[:records_in] += 1

      if record[:TAXONOMY]
        @status[:otus_in] += 1

        collapse_tax(hash, record)
      else
        output << record
        @status[:records_out] += 1
      end
    end

    write_tax(hash, output)
  end
end