Sha256: 0814202c9a45955bcbe841ab91bee4c19df02acffb56bc002e19b02b2df079f8

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

module Lederhosen
  class CLI

    desc 'otu_filter', 'works like uc_filter but uses an OTU table as input'

    method_option :input, :type   =>  :string, :required => true
    method_option :output, :type  =>  :string, :required => true
    method_option :reads, :type   => :numeric, :required => true
    method_option :samples, :type => :numeric, :required => true

    def otu_filter
      input   = options[:input]
      output  = options[:output]
      reads   = options[:reads]
      samples = options[:samples]

      ##
      # Iterate over otu table line by line.
      # Only print if cluster meets criteria
      #
      kept = 0
      File.open(input) do |handle|
        header  = handle.gets.strip
        header  = header.split(',')
        samples = header[1..-1]

        puts header.join(',')

        handle.each do |line|
          line       = line.strip.split(',')
          cluster_no = line[0]
          counts     = line[1..-1].collect { |x| x.to_i }

          # should be the same as uc_filter
          if counts.reject { |x| x < reads }.length > samples
            puts line.join(',')
            kept += 1
          end
        end
      end
      ohai "kept #{kept} clusters."
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lederhosen-0.2.9 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.8 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.7 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.6 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.5 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.4 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.3 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.2 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.1 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.2.0 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.1.9 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.1.8 lib/lederhosen/tasks/otu_filter.rb
lederhosen-0.1.7 lib/lederhosen/tasks/otu_filter.rb