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.2.11 lib/lederhosen/tasks/otu_table.rb
lederhosen-0.2.10 lib/lederhosen/tasks/otu_table.rb