Sha256: c8a2853ec352283b8169ace08ca8d8cac1dedcdc68a33f653403f8287b7a1678

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 KB

Contents

##
# MAKE TABLES
#

SEP = ','

module Lederhosen
  class CLI

    desc "otu_table",
         "create an OTU abundance matrix from UCLUST output"

    method_option :clusters, :type => :string, :required => true
    method_option :output,   :type => :string, :required => true

    def otu_table
      input        = options[:clusters]
      output       = options[:output]

      ohai "generating otu table from #{input}, saving to #{output}"

      # Load cluster table

      clstr_info      = Helpers.load_uc_file input
      clstr_counts    = clstr_info[:clstr_counts] # clstr_counts[:clstr][sample.to_i] = reads
      clstrnr_to_seed = clstr_info[:clstrnr_to_seed]
      samples         = clstr_info[:samples]

      # print OTU abundance matrix
      # clusters as columns
      # samples as rows

      File.open("#{output}", 'w') do |h|
        samples  = samples.sort
        clusters = clstr_counts.keys

        # print header (cluster names)
        h.puts '-' + SEP + clusters.map { |x| "cluster-#{x}" }.join(SEP)

        samples.each do |sample|
          h.print sample
          clusters.each do |cluster|
            h.print "#{SEP}#{clstr_counts[cluster][sample]}"
          end
          h.print "\n"
        end
      end
    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
lederhosen-0.5.7 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.5.6 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.5.5 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.5.4 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.5.2 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.5.1 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.5.0 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.4.0 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.9 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.8 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.7 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.6 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.5 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.4 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.3 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.2 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.1 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.3.0 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.2.13 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.2.12 lib/lederhosen/tasks/otu_table.rb