Sha256: 9702d270fac57191b9a5f7fb2b89f45a0bca74a2cd799f79914533d4af306e80

Contents?: true

Size: 952 Bytes

Versions: 2

Compression:

Stored size: 952 Bytes

Contents

module Lederhosen
  class CLI

    ##
    # PAIRED-END READ WORK-AROUND (JOIN THEM)
    #
    desc "join",
         "--trimmed=trimmed/*.fasta --output=joined.fasta"

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

    def join

      trimmed = Dir[options[:trimmed]]
      output = options[:output]

      fail "no reads in #{trimmed}" if trimmed.length == 0

      output = File.open(output, 'w')

      pbar = ProgressBar.new "joining", trimmed.length

      trimmed.each do |fasta_file|
        pbar.inc

        begin
          records = Dna.new File.open(fasta_file)
        rescue
          ohai "skipping #{fasta_file} (empty?)"
          next
        end

        records.each_slice(2) do |l, r|
          output.puts ">#{r.name}:#{File.basename(fasta_file, '.fasta')}\n#{r.sequence.reverse+l.sequence}"
        end
      end
      pbar.finish
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lederhosen-0.1.4 lib/lederhosen/tasks/join.rb
lederhosen-0.1.3 lib/lederhosen/tasks/join.rb